--- parser3/src/include/pa_dir.h 2001/04/09 08:55:28 1.2 +++ parser3/src/include/pa_dir.h 2023/11/18 15:55:21 1.32 @@ -1,83 +1,83 @@ /** @file Parser: directory scanning for different OS-es decls. - Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_dir.h,v 1.2 2001/04/09 08:55:28 paf Exp $ + Copyright (c) 2000-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_DIR_H #define PA_DIR_H -#ifdef WIN32 +#define IDENT_PA_DIR_H "$Id: pa_dir.h,v 1.32 2023/11/18 15:55:21 moko Exp $" -#include +#include "pa_config_includes.h" -#define MAXPATH MAX_PATH -#define FA_DIREC FILE_ATTRIBUTE_DIRECTORY +/** @struct ffblk + win32/unix unified directory entry structure name + for findfirst/next/close interface +*/ + +#ifdef _MSC_VER +#include + +#define MAXPATH ((MAX_PATH)*2) /*UTF-16*/ struct ffblk { - DWORD ff_attrib;/*dwFileAttributes;*/ - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - DWORD nFileSizeHigh; - DWORD nFileSizeLow; - DWORD dwReserved0; - DWORD dwReserved1; - CHAR ff_name[ MAX_PATH ];/*cFileName[ MAX_PATH ];*/ - CHAR cAlternateFileName[ 14 ]; - /*helper*/ + struct _WIN32_FIND_DATAW stat; HANDLE handle; -/* - - unsigned char ff_attrib __attribute__((packed)); - unsigned short ff_ftime __attribute__((packed)); - unsigned short ff_fdate __attribute__((packed)); - unsigned long ff_fsize __attribute__((packed)); - char ff_name[260] __attribute__((packed)); - */ + const char *name(); + bool is_dir(bool); + double size(); + time_t c_timestamp(); + time_t m_timestamp(); + time_t a_timestamp(); }; #else -#include -#include -#include -#include - #define MAXPATH 1000 /*NAME_MAX*/ -#define FA_DIREC S_IFDIR struct ffblk { /*as if in windows :)*/ - unsigned char ff_attrib; - char ff_name[ MAXPATH ]; + char ff_name[ MAXPATH ]; /*helpers*/ DIR *dir; - char filePath[MAXPATH]; + const char *filePath; + struct stat _st; + +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + unsigned char _d_type; +#endif + + const char *name(){ return ff_name; } + bool is_dir(bool); + void stat_file(); + double size(); + time_t c_timestamp(); + time_t m_timestamp(); + time_t a_timestamp(); }; #endif -bool findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib); +bool findfirst(const char* _pathname, struct ffblk *_ffblk, int _attrib); bool findnext(struct ffblk *_ffblk); void findclose(struct ffblk *_ffblk); -#define LOAD_DIR(dir,action) {\ - ffblk ffblk; \ - bool done=findfirst(dir, &ffblk, 0); \ - while(!done) { \ - if(*ffblk.ff_name && ffblk.ff_name[0]!='.') {\ - action; \ - } \ - done=findnext(&ffblk); \ - } \ - findclose(&ffblk); \ -} +/// main dir workhorse: calles win32/unix unified functions findfirst/next/close [skip . and ..] +#define LOAD_DIR(dir,action) { \ + ffblk ffblk; \ + if(!findfirst(dir, &ffblk, 0)) { \ + do { \ + const char *file_name=ffblk.name(); \ + if(*file_name && !(file_name[0]=='.' && (file_name[1]==0 || file_name[1]=='.' && file_name[2]==0) )) { \ + action; \ + } \ + } while(!findnext(&ffblk)); \ + findclose(&ffblk); \ + } \ +} #endif