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