lglob.h revision 240121
1127915Skientzle/*
2265420Simp * Copyright (C) 1984-2012  Mark Nudelman
3127915Skientzle *
4319186Sngie * You may distribute under the terms of either the GNU General Public
5228797Smm * License or the Less License, as specified in the README file.
6127915Skientzle *
7368984Smm * For more information, see the README file.
8368984Smm */
9228797Smm
10291620Sbdrewery
11203559Skientzle/*
12203559Skientzle * Macros to define the method of doing filename "globbing".
13248616Smm * There are three possible mechanisms:
14203559Skientzle *   1.	GLOB_LIST
15203559Skientzle *	This defines a function that returns a list of matching filenames.
16203559Skientzle *   2. GLOB_NAME
17203559Skientzle *	This defines a function that steps thru the list of matching
18224153Smm *	filenames, returning one name each time it is called.
19291620Sbdrewery *   3. GLOB_STRING
20224153Smm *	This defines a function that returns the complete list of
21299529Smm *	matching filenames as a single space-separated string.
22299529Smm */
23224153Smm
24275042Sbapt#if OS2
25224566Smm
26232153Smm#define	DECL_GLOB_LIST(list)		char **list;  char **pp;
27232153Smm#define	GLOB_LIST(filename,list)	list = _fnexplode(filename)
28232153Smm#define	GLOB_LIST_FAILED(list)		list == NULL
29232153Smm#define	SCAN_GLOB_LIST(list,p)		pp = list;  *pp != NULL;  pp++
30175051Skientzle#define	INIT_GLOB_LIST(list,p)		p = *pp
31319186Sngie#define	GLOB_LIST_DONE(list)		_fnexplodefree(list)
32291620Sbdrewery
33291620Sbdrewery#else
34137616Sru#if MSDOS_COMPILER==DJGPPC
35128446Skientzle
36128446Skientzle#define	DECL_GLOB_LIST(list)		glob_t list;  int i;
37289195Sngie#define	GLOB_LIST(filename,list)	glob(filename,GLOB_NOCHECK,0,&list)
38289195Sngie#define	GLOB_LIST_FAILED(list)		0
39289195Sngie#define	SCAN_GLOB_LIST(list,p)		i = 0;  i < list.gl_pathc;  i++
40175051Skientzle#define	INIT_GLOB_LIST(list,p)		p = list.gl_pathv[i]
41127915Skientzle#define	GLOB_LIST_DONE(list)		globfree(&list)
42
43#else
44#if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC
45
46#define	GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp)
47#define	GLOB_FIRST_FAILED(handle)	((handle) != 0)
48#define	GLOB_NEXT_NAME(handle,fndp)		_dos_findnext(fndp)
49#define	GLOB_NAME_DONE(handle)
50#define	GLOB_NAME			name
51#define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
52					struct find_t fnd;	\
53					char drive[_MAX_DRIVE];	\
54					char dir[_MAX_DIR];	\
55					char fname[_MAX_FNAME];	\
56					char ext[_MAX_EXT];	\
57					int handle;
58#else
59#if MSDOS_COMPILER==WIN32C && defined(_MSC_VER)
60
61#define	GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp)
62#define	GLOB_FIRST_FAILED(handle)	((handle) == -1)
63#define	GLOB_NEXT_NAME(handle,fndp)	_findnext(handle, fndp)
64#define	GLOB_NAME_DONE(handle)		_findclose(handle)
65#define	GLOB_NAME			name
66#define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
67					struct _finddata_t fnd;	\
68					char drive[_MAX_DRIVE];	\
69					char dir[_MAX_DIR];	\
70					char fname[_MAX_FNAME];	\
71					char ext[_MAX_EXT];	\
72					long handle;
73
74#else
75#if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */
76
77#define	GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL)
78#define	GLOB_FIRST_FAILED(handle)	((handle) != 0)
79#define	GLOB_NEXT_NAME(handle,fndp)	findnext(fndp)
80#define	GLOB_NAME_DONE(handle)
81#define	GLOB_NAME			ff_name
82#define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
83					struct ffblk fnd;	\
84					char drive[MAXDRIVE];	\
85					char dir[MAXDIR];	\
86					char fname[MAXFILE];	\
87					char ext[MAXEXT];	\
88					int handle;
89
90#endif
91#endif
92#endif
93#endif
94#endif
95