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