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