File:  [parser3project] / parser3 / src / main / pa_dir.C
Revision 1.19.14.1: download - view: text, annotated - select for diffs - revision graph
Fri Aug 5 13:03:01 2005 UTC (20 years, 11 months ago) by paf
Branches: release_3_1_5
CVS tags: release_3_1_6
Diff to: branchpoint 1.19: preferred, unified
. 2005 ;)

/** @file
	Parser: directory scanning for different OS-es.

	Copyright (c) 2000,2001-2005 ArtLebedev Group (http://www.artlebedev.com)
	Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
*/

static const char * const IDENT_DIR_C="$Date: 2005/08/05 13:03:01 $";

#include "pa_common.h"
#include "pa_dir.h"

#ifdef WIN32

bool findfirst(const char* _pathname, struct ffblk *_ffblk, int /*_attrib*/) {
	char mask[MAXPATH];
	snprintf(mask, MAXPATH, "%s/*.*", _pathname);

	_ffblk->handle=FindFirstFile(mask, (_WIN32_FIND_DATAA *)_ffblk);
	return _ffblk->handle==INVALID_HANDLE_VALUE;
}

bool findnext(struct ffblk *_ffblk) {
	return !FindNextFile(_ffblk->handle, (_WIN32_FIND_DATAA *)_ffblk);}

void findclose(struct ffblk *_ffblk) {
	FindClose(_ffblk->handle);
}

#else

bool findfirst(const char* _pathname, struct ffblk *_ffblk, int /*_attrib*/) {
    strncpy(_ffblk->filePath, _pathname, MAXPATH-1); _ffblk->filePath[MAXPATH-1]=0;
	if(!(_ffblk->dir=opendir(_ffblk->filePath)))
        return true;

	return findnext(_ffblk);
}

bool findnext(struct ffblk *_ffblk) {
    while(true) {
        struct dirent *entry=readdir(_ffblk->dir);
        if(!entry)
            return true;

		int maxsize=sizeof(_ffblk->ff_name)-1;
		strncpy(_ffblk->ff_name, entry->d_name, maxsize-1); _ffblk->ff_name[maxsize]=0;
		
		char fileSpec[MAXPATH];
		snprintf(fileSpec, MAXPATH, "%s/%s",
			_ffblk->filePath,
			_ffblk->ff_name);
		
		struct stat st;
		
		_ffblk->ff_attrib =
			stat(fileSpec, &st) < 0 ? 0/*would fail later*/ : st.st_mode;
		return false;
    }
}

void findclose(struct ffblk *_ffblk) {
	closedir(_ffblk->dir);
}

#endif

E-mail: