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

1.1       paf         1: /** @file
                      2:        Parser: directory scanning for different OS-es.
                      3: 
1.2       paf         4:        Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com)
1.1       paf         5: 
                      6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: */
1.6     ! parser      8: static const char *RCSId="$Id: pa_dir.C,v 1.5 2001/06/28 07:44:17 parser Exp $"; 
1.1       paf         9: 
                     10: #include "pa_dir.h"
                     11: #include "pa_common.h"
                     12: 
                     13: #ifdef WIN32
                     14: 
                     15: bool findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib) {
                     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: 
                     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: