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