xref: /netbsd-src/external/bsd/less/dist/lglob.h (revision 3ffde583575d77f6c315096bca0eb95a16d90d46)
1*3ffde583Ssimonb /*	$NetBSD: lglob.h,v 1.6 2023/10/06 06:25:22 simonb Exp $	*/
220006a0bStron 
320006a0bStron /*
4838f5788Ssimonb  * Copyright (C) 1984-2023  Mark Nudelman
520006a0bStron  *
620006a0bStron  * You may distribute under the terms of either the GNU General Public
720006a0bStron  * License or the Less License, as specified in the README file.
820006a0bStron  *
9ec18bca0Stron  * For more information, see the README file.
1020006a0bStron  */
1120006a0bStron 
1220006a0bStron 
1320006a0bStron /*
1420006a0bStron  * Macros to define the method of doing filename "globbing".
1520006a0bStron  * There are three possible mechanisms:
1620006a0bStron  *   1. GLOB_LIST
1720006a0bStron  *      This defines a function that returns a list of matching filenames.
1820006a0bStron  *   2. GLOB_NAME
1920006a0bStron  *      This defines a function that steps thru the list of matching
2020006a0bStron  *      filenames, returning one name each time it is called.
2120006a0bStron  *   3. GLOB_STRING
2220006a0bStron  *      This defines a function that returns the complete list of
2320006a0bStron  *      matching filenames as a single space-separated string.
2420006a0bStron  */
2520006a0bStron 
2620006a0bStron #if OS2
2720006a0bStron 
2820006a0bStron #define DECL_GLOB_LIST(list)            char **list;  char **pp;
2920006a0bStron #define GLOB_LIST(filename,list)        list = _fnexplode(filename)
3020006a0bStron #define GLOB_LIST_FAILED(list)          list == NULL
3120006a0bStron #define SCAN_GLOB_LIST(list,p)          pp = list;  *pp != NULL;  pp++
3220006a0bStron #define INIT_GLOB_LIST(list,p)          p = *pp
3320006a0bStron #define GLOB_LIST_DONE(list)            _fnexplodefree(list)
3420006a0bStron 
3520006a0bStron #else
3620006a0bStron #if MSDOS_COMPILER==DJGPPC
3720006a0bStron 
38824a88bbStron #define DECL_GLOB_LIST(list)            glob_t list;  size_t i;
3920006a0bStron #define GLOB_LIST(filename,list)        glob(filename,GLOB_NOCHECK,0,&list)
4020006a0bStron #define GLOB_LIST_FAILED(list)          0
4120006a0bStron #define SCAN_GLOB_LIST(list,p)          i = 0;  i < list.gl_pathc;  i++
4220006a0bStron #define INIT_GLOB_LIST(list,p)          p = list.gl_pathv[i]
4320006a0bStron #define GLOB_LIST_DONE(list)            globfree(&list)
4420006a0bStron 
4520006a0bStron #else
4620006a0bStron #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC
4720006a0bStron 
4820006a0bStron #define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp)
4920006a0bStron #define GLOB_FIRST_FAILED(handle)       ((handle) != 0)
5020006a0bStron #define GLOB_NEXT_NAME(handle,fndp)             _dos_findnext(fndp)
5120006a0bStron #define GLOB_NAME_DONE(handle)
5220006a0bStron #define GLOB_NAME                       name
5320006a0bStron #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
5420006a0bStron                                         struct find_t fnd;      \
5520006a0bStron                                         char drive[_MAX_DRIVE]; \
5620006a0bStron                                         char dir[_MAX_DIR];     \
5720006a0bStron                                         char fname[_MAX_FNAME]; \
5820006a0bStron                                         char ext[_MAX_EXT];     \
5920006a0bStron                                         int handle;
6020006a0bStron #else
61838f5788Ssimonb #if MSDOS_COMPILER==WIN32C && (defined(_MSC_VER) || defined(MINGW))
6220006a0bStron 
6320006a0bStron #define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp)
6420006a0bStron #define GLOB_FIRST_FAILED(handle)       ((handle) == -1)
6520006a0bStron #define GLOB_NEXT_NAME(handle,fndp)     _findnext(handle, fndp)
6620006a0bStron #define GLOB_NAME_DONE(handle)          _findclose(handle)
6720006a0bStron #define GLOB_NAME                       name
6820006a0bStron #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
6920006a0bStron                                         struct _finddata_t fnd; \
7020006a0bStron                                         char drive[_MAX_DRIVE]; \
7120006a0bStron                                         char dir[_MAX_DIR];     \
7220006a0bStron                                         char fname[_MAX_FNAME]; \
7320006a0bStron                                         char ext[_MAX_EXT];     \
74838f5788Ssimonb                                         intptr_t handle;
7520006a0bStron 
7620006a0bStron #else
7720006a0bStron #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */
7820006a0bStron 
7920006a0bStron #define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL)
8020006a0bStron #define GLOB_FIRST_FAILED(handle)       ((handle) != 0)
8120006a0bStron #define GLOB_NEXT_NAME(handle,fndp)     findnext(fndp)
8220006a0bStron #define GLOB_NAME_DONE(handle)
8320006a0bStron #define GLOB_NAME                       ff_name
8420006a0bStron #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
8520006a0bStron                                         struct ffblk fnd;       \
8620006a0bStron                                         char drive[MAXDRIVE];   \
8720006a0bStron                                         char dir[MAXDIR];       \
8820006a0bStron                                         char fname[MAXFILE];    \
8920006a0bStron                                         char ext[MAXEXT];       \
9020006a0bStron                                         int handle;
9120006a0bStron 
9220006a0bStron #endif
9320006a0bStron #endif
9420006a0bStron #endif
9520006a0bStron #endif
9620006a0bStron #endif
97