Annotation of parser3/src/main/pa_dir.C, revision 1.19

1.1       paf         1: /** @file
                      2:        Parser: directory scanning for different OS-es.
                      3: 
1.19    ! paf         4:        Copyright (c) 2000,2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.11      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.12      paf         6: */
1.1       paf         7: 
1.19    ! paf         8: static const char * const IDENT_DIR_C="$Date: 2003/11/20 17:48:28 $";
1.1       paf         9: 
1.9       paf        10: #include "pa_common.h"
1.1       paf        11: #include "pa_dir.h"
                     12: 
                     13: #ifdef WIN32
                     14: 
1.16      paf        15: bool findfirst(const char* _pathname, struct ffblk *_ffblk, int /*_attrib*/) {
1.1       paf        16:        char mask[MAXPATH];
                     17:        snprintf(mask, MAXPATH, "%s/*.*", _pathname);
                     18: 
                     19:        _ffblk->handle=FindFirstFile(mask, (_WIN32_FIND_DATAA *)_ffblk);
                     20:        return _ffblk->handle==INVALID_HANDLE_VALUE;
                     21: }
                     22: 
                     23: bool findnext(struct ffblk *_ffblk) {
                     24:        return !FindNextFile(_ffblk->handle, (_WIN32_FIND_DATAA *)_ffblk);}
                     25: 
                     26: void findclose(struct ffblk *_ffblk) {
                     27:        FindClose(_ffblk->handle);
                     28: }
                     29: 
                     30: #else
                     31: 
1.18      paf        32: bool findfirst(const char* _pathname, struct ffblk *_ffblk, int /*_attrib*/) {
1.6       parser     33:     strncpy(_ffblk->filePath, _pathname, MAXPATH-1); _ffblk->filePath[MAXPATH-1]=0;
1.1       paf        34:        if(!(_ffblk->dir=opendir(_ffblk->filePath)))
                     35:         return true;
                     36: 
                     37:        return findnext(_ffblk);
                     38: }
                     39: 
                     40: bool findnext(struct ffblk *_ffblk) {
                     41:     while(true) {
                     42:         struct dirent *entry=readdir(_ffblk->dir);
                     43:         if(!entry)
                     44:             return true;
                     45: 
                     46:                int maxsize=sizeof(_ffblk->ff_name)-1;
1.6       parser     47:                strncpy(_ffblk->ff_name, entry->d_name, maxsize-1); _ffblk->ff_name[maxsize]=0;
1.1       paf        48:                
                     49:                char fileSpec[MAXPATH];
                     50:                snprintf(fileSpec, MAXPATH, "%s/%s",
                     51:                        _ffblk->filePath,
                     52:                        _ffblk->ff_name);
                     53:                
                     54:                struct stat st;
                     55:                
                     56:                _ffblk->ff_attrib =
                     57:                        stat(fileSpec, &st) < 0 ? 0/*would fail later*/ : st.st_mode;
                     58:                return false;
                     59:     }
                     60: }
                     61: 
                     62: void findclose(struct ffblk *_ffblk) {
                     63:        closedir(_ffblk->dir);
                     64: }
                     65: 
                     66: #endif

E-mail: