Annotation of parser3/src/main/pa_dir.C, revision 1.5
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.5 ! parser 8: static const char *RCSId="$Id: double.C,v 1.31 2001/06/28 07:41:59 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) {
33: strncpy(_ffblk->filePath, _pathname, MAXPATH);
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;
47: strncpy(_ffblk->ff_name, entry->d_name, maxsize);
48: _ffblk->ff_name[maxsize]=0;
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: