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