Annotation of parser3/src/main/pa_dir.C, revision 1.3
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.3 ! parser 8: $Id: pa_dir.C,v 1.2 2001/04/09 08:55:30 paf Exp $
1.1 paf 9: */
10:
11: #include "pa_dir.h"
12: #include "pa_common.h"
13:
14: #ifdef WIN32
15:
16: bool findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib) {
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:
33: bool findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib) {
34: strncpy(_ffblk->filePath, _pathname, MAXPATH);
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;
48: strncpy(_ffblk->ff_name, entry->d_name, maxsize);
49: _ffblk->ff_name[maxsize]=0;
50:
51: char fileSpec[MAXPATH];
52: snprintf(fileSpec, MAXPATH, "%s/%s",
53: _ffblk->filePath,
54: _ffblk->ff_name);
55:
56: struct stat st;
57:
58: _ffblk->ff_attrib =
59: stat(fileSpec, &st) < 0 ? 0/*would fail later*/ : st.st_mode;
60: return false;
61: }
62: }
63:
64: void findclose(struct ffblk *_ffblk) {
65: closedir(_ffblk->dir);
66: }
67:
68: #endif
E-mail: