Annotation of parser3/src/include/pa_dir.h, revision 1.22

1.1       paf         1: /** @file
                      2:        Parser: directory scanning for different OS-es decls.
                      3: 
1.20      moko        4:        Copyright (c) 2000-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.10      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_DIR_H
                      9: #define PA_DIR_H
1.11      paf        10: 
1.22    ! moko       11: #define IDENT_PA_DIR_H "$Id: pa_dir.h,v 1.21 2012/06/20 20:54:25 moko Exp $"
1.4       parser     12: 
                     13: #include "pa_config_includes.h"
1.1       paf        14: 
1.3       paf        15: /** @struct ffblk 
                     16:        win32/unix unified directory entry structure name
                     17:        for findfirst/next/close interface
                     18: */
                     19: 
1.1       paf        20: #ifdef WIN32
                     21: 
                     22: #include <windows.h>
                     23: 
                     24: #define MAXPATH MAX_PATH
                     25: #define FA_DIREC FILE_ATTRIBUTE_DIRECTORY
                     26: 
                     27: struct ffblk {
                     28:     DWORD ff_attrib;/*dwFileAttributes;*/
                     29:     FILETIME ftCreationTime;
                     30:     FILETIME ftLastAccessTime;
                     31:     FILETIME ftLastWriteTime;
                     32:     DWORD nFileSizeHigh;
                     33:     DWORD nFileSizeLow;
                     34:     DWORD dwReserved0;
                     35:     DWORD dwReserved1;
                     36:     CHAR   ff_name[ MAX_PATH ];/*cFileName[ MAX_PATH ];*/
                     37:     CHAR   cAlternateFileName[ 14 ];
                     38:        /*helper*/
                     39:        HANDLE handle;
                     40: 
                     41: /*     
                     42:        unsigned char  ff_attrib __attribute__((packed));
                     43:   unsigned short ff_ftime __attribute__((packed));
                     44:   unsigned short ff_fdate __attribute__((packed));
                     45:   unsigned long  ff_fsize __attribute__((packed));
                     46:   char ff_name[260] __attribute__((packed));
                     47:  */
1.22    ! moko       48:        void stat_file();
        !            49:        bool is_dir();
        !            50:        double size();
        !            51:        time_t c_timestamp();
        !            52:        time_t m_timestamp();
        !            53:        time_t a_timestamp();
1.1       paf        54: };
                     55: 
                     56: #else
                     57: 
                     58: #include <strings.h>   
                     59: #include <sys/types.h>
                     60: #include <dirent.h>
                     61: #include <sys/stat.h>
                     62: 
                     63: #define MAXPATH 1000 /*NAME_MAX*/
                     64: #define FA_DIREC S_IFDIR
                     65: 
                     66: struct ffblk {
                     67:        /*as if in windows :)*/
                     68:     char ff_name[ MAXPATH ];
                     69:        /*helpers*/
                     70:        DIR *dir;
                     71:        char filePath[MAXPATH];
1.22    ! moko       72:        struct stat _st;
        !            73: 
        !            74: #ifdef HAVE_STRUCT_DIRENT_D_TYPE
        !            75:        unsigned char _d_type;
        !            76:        void stat_file();
        !            77: #else
        !            78:        void stat_file(){}
        !            79:        void real_stat_file();
        !            80: #endif
        !            81:        bool is_dir();
        !            82:        double size();
        !            83:        time_t c_timestamp();
        !            84:        time_t m_timestamp();
        !            85:        time_t a_timestamp();
1.1       paf        86: };
                     87: 
                     88: #endif
                     89: 
1.14      paf        90: bool findfirst(const char* _pathname, struct ffblk *_ffblk, int _attrib);
1.1       paf        91: bool findnext(struct ffblk *_ffblk);
                     92: void findclose(struct ffblk *_ffblk);
                     93: 
1.18      paf        94: /// main dir workhorse: calles win32/unix unified functions findfirst/next/close [skip . and ..]
1.1       paf        95: #define LOAD_DIR(dir,action) {\
                     96:     ffblk ffblk; \
1.7       paf        97:     if(!findfirst(dir, &ffblk, 0)) { \
1.6       paf        98:                do \
1.18      paf        99:                        if(*ffblk.ff_name && !(ffblk.ff_name[0]=='.' && (ffblk.ff_name[1]==0 || ffblk.ff_name[1]=='.' && ffblk.ff_name[2]==0)  )) {\
1.6       paf       100:                                action; \
                    101:                        } \
1.7       paf       102:                while(!findnext(&ffblk)); \
1.6       paf       103:                findclose(&ffblk); \
                    104:        } \
1.1       paf       105: } 
                    106: 
                    107: #endif

E-mail: