Home | History | Annotate | Line # | Download | only in dist
lglob.h revision 1.2
      1  1.2  tron /*	$NetBSD: lglob.h,v 1.2 2011/07/03 19:51:26 tron Exp $	*/
      2  1.1  tron 
      3  1.1  tron /*
      4  1.1  tron  * Copyright (C) 1984-2011  Mark Nudelman
      5  1.1  tron  *
      6  1.1  tron  * You may distribute under the terms of either the GNU General Public
      7  1.1  tron  * License or the Less License, as specified in the README file.
      8  1.1  tron  *
      9  1.1  tron  * For more information about less, or for information on how to
     10  1.1  tron  * contact the author, see the README file.
     11  1.1  tron  */
     12  1.1  tron 
     13  1.1  tron 
     14  1.1  tron /*
     15  1.1  tron  * Macros to define the method of doing filename "globbing".
     16  1.1  tron  * There are three possible mechanisms:
     17  1.1  tron  *   1.	GLOB_LIST
     18  1.1  tron  *	This defines a function that returns a list of matching filenames.
     19  1.1  tron  *   2. GLOB_NAME
     20  1.1  tron  *	This defines a function that steps thru the list of matching
     21  1.1  tron  *	filenames, returning one name each time it is called.
     22  1.1  tron  *   3. GLOB_STRING
     23  1.1  tron  *	This defines a function that returns the complete list of
     24  1.1  tron  *	matching filenames as a single space-separated string.
     25  1.1  tron  */
     26  1.1  tron 
     27  1.1  tron #if OS2
     28  1.1  tron 
     29  1.1  tron #define	DECL_GLOB_LIST(list)		char **list;  char **pp;
     30  1.1  tron #define	GLOB_LIST(filename,list)	list = _fnexplode(filename)
     31  1.1  tron #define	GLOB_LIST_FAILED(list)		list == NULL
     32  1.1  tron #define	SCAN_GLOB_LIST(list,p)		pp = list;  *pp != NULL;  pp++
     33  1.1  tron #define	INIT_GLOB_LIST(list,p)		p = *pp
     34  1.1  tron #define	GLOB_LIST_DONE(list)		_fnexplodefree(list)
     35  1.1  tron 
     36  1.1  tron #else
     37  1.1  tron #if MSDOS_COMPILER==DJGPPC
     38  1.1  tron 
     39  1.1  tron #define	DECL_GLOB_LIST(list)		glob_t list;  int i;
     40  1.1  tron #define	GLOB_LIST(filename,list)	glob(filename,GLOB_NOCHECK,0,&list)
     41  1.1  tron #define	GLOB_LIST_FAILED(list)		0
     42  1.1  tron #define	SCAN_GLOB_LIST(list,p)		i = 0;  i < list.gl_pathc;  i++
     43  1.1  tron #define	INIT_GLOB_LIST(list,p)		p = list.gl_pathv[i]
     44  1.1  tron #define	GLOB_LIST_DONE(list)		globfree(&list)
     45  1.1  tron 
     46  1.1  tron #else
     47  1.1  tron #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC
     48  1.1  tron 
     49  1.1  tron #define	GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp)
     50  1.1  tron #define	GLOB_FIRST_FAILED(handle)	((handle) != 0)
     51  1.1  tron #define	GLOB_NEXT_NAME(handle,fndp)		_dos_findnext(fndp)
     52  1.1  tron #define	GLOB_NAME_DONE(handle)
     53  1.1  tron #define	GLOB_NAME			name
     54  1.1  tron #define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
     55  1.1  tron 					struct find_t fnd;	\
     56  1.1  tron 					char drive[_MAX_DRIVE];	\
     57  1.1  tron 					char dir[_MAX_DIR];	\
     58  1.1  tron 					char fname[_MAX_FNAME];	\
     59  1.1  tron 					char ext[_MAX_EXT];	\
     60  1.1  tron 					int handle;
     61  1.1  tron #else
     62  1.1  tron #if MSDOS_COMPILER==WIN32C && defined(_MSC_VER)
     63  1.1  tron 
     64  1.1  tron #define	GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp)
     65  1.1  tron #define	GLOB_FIRST_FAILED(handle)	((handle) == -1)
     66  1.1  tron #define	GLOB_NEXT_NAME(handle,fndp)	_findnext(handle, fndp)
     67  1.1  tron #define	GLOB_NAME_DONE(handle)		_findclose(handle)
     68  1.1  tron #define	GLOB_NAME			name
     69  1.1  tron #define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
     70  1.1  tron 					struct _finddata_t fnd;	\
     71  1.1  tron 					char drive[_MAX_DRIVE];	\
     72  1.1  tron 					char dir[_MAX_DIR];	\
     73  1.1  tron 					char fname[_MAX_FNAME];	\
     74  1.1  tron 					char ext[_MAX_EXT];	\
     75  1.1  tron 					long handle;
     76  1.1  tron 
     77  1.1  tron #else
     78  1.1  tron #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */
     79  1.1  tron 
     80  1.1  tron #define	GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL)
     81  1.1  tron #define	GLOB_FIRST_FAILED(handle)	((handle) != 0)
     82  1.1  tron #define	GLOB_NEXT_NAME(handle,fndp)	findnext(fndp)
     83  1.1  tron #define	GLOB_NAME_DONE(handle)
     84  1.1  tron #define	GLOB_NAME			ff_name
     85  1.1  tron #define	DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
     86  1.1  tron 					struct ffblk fnd;	\
     87  1.1  tron 					char drive[MAXDRIVE];	\
     88  1.1  tron 					char dir[MAXDIR];	\
     89  1.1  tron 					char fname[MAXFILE];	\
     90  1.1  tron 					char ext[MAXEXT];	\
     91  1.1  tron 					int handle;
     92  1.1  tron 
     93  1.1  tron #endif
     94  1.1  tron #endif
     95  1.1  tron #endif
     96  1.1  tron #endif
     97  1.1  tron #endif
     98