lglob.h revision 330571
159632Swollman/* 259632Swollman * Copyright (C) 1984-2017 Mark Nudelman 359632Swollman * 459632Swollman * You may distribute under the terms of either the GNU General Public 559632Swollman * License or the Less License, as specified in the README file. 659632Swollman * 759632Swollman * For more information, see the README file. 859632Swollman */ 959632Swollman 1059632Swollman 1159632Swollman/* 1259632Swollman * Macros to define the method of doing filename "globbing". 1359632Swollman * There are three possible mechanisms: 1459632Swollman * 1. GLOB_LIST 1559632Swollman * This defines a function that returns a list of matching filenames. 1659632Swollman * 2. GLOB_NAME 1759632Swollman * This defines a function that steps thru the list of matching 1859632Swollman * filenames, returning one name each time it is called. 1959632Swollman * 3. GLOB_STRING 2059632Swollman * This defines a function that returns the complete list of 2159632Swollman * matching filenames as a single space-separated string. 2259632Swollman */ 2359632Swollman 2459632Swollman#if OS2 2559632Swollman 2659632Swollman#define DECL_GLOB_LIST(list) char **list; char **pp; 2759632Swollman#define GLOB_LIST(filename,list) list = _fnexplode(filename) 2859632Swollman#define GLOB_LIST_FAILED(list) list == NULL 2959632Swollman#define SCAN_GLOB_LIST(list,p) pp = list; *pp != NULL; pp++ 3059632Swollman#define INIT_GLOB_LIST(list,p) p = *pp 31324124Sjhb#define GLOB_LIST_DONE(list) _fnexplodefree(list) 3259632Swollman 3359632Swollman#else 3459632Swollman#if MSDOS_COMPILER==DJGPPC 3559632Swollman 3659632Swollman#define DECL_GLOB_LIST(list) glob_t list; int i; 3759632Swollman#define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list) 3868963Sru#define GLOB_LIST_FAILED(list) 0 39324124Sjhb#define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++ 40324124Sjhb#define INIT_GLOB_LIST(list,p) p = list.gl_pathv[i] 41324124Sjhb#define GLOB_LIST_DONE(list) globfree(&list) 4259632Swollman 4359632Swollman#else 4459632Swollman#if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC 4568963Sru 4659632Swollman#define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp) 4759632Swollman#define GLOB_FIRST_FAILED(handle) ((handle) != 0) 4859632Swollman#define GLOB_NEXT_NAME(handle,fndp) _dos_findnext(fndp) 4959632Swollman#define GLOB_NAME_DONE(handle) 5068963Sru#define GLOB_NAME name 51324124Sjhb#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 5259632Swollman struct find_t fnd; \ 5359632Swollman char drive[_MAX_DRIVE]; \ 5459632Swollman char dir[_MAX_DIR]; \ 55324124Sjhb char fname[_MAX_FNAME]; \ 56324124Sjhb char ext[_MAX_EXT]; \ 5759632Swollman int handle; 5859632Swollman#else 5959632Swollman#if MSDOS_COMPILER==WIN32C && defined(_MSC_VER) 60324124Sjhb 61324124Sjhb#define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp) 62324124Sjhb#define GLOB_FIRST_FAILED(handle) ((handle) == -1) 63324124Sjhb#define GLOB_NEXT_NAME(handle,fndp) _findnext(handle, fndp) 64324124Sjhb#define GLOB_NAME_DONE(handle) _findclose(handle) 65324124Sjhb#define GLOB_NAME name 66324124Sjhb#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 67324124Sjhb struct _finddata_t fnd; \ 68324124Sjhb char drive[_MAX_DRIVE]; \ 69324124Sjhb char dir[_MAX_DIR]; \ 70324124Sjhb char fname[_MAX_FNAME]; \ 71324124Sjhb char ext[_MAX_EXT]; \ 72324124Sjhb long handle; 73324124Sjhb 74324124Sjhb#else 75324124Sjhb#if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */ 76107788Sru 7759632Swollman#define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL) 7859632Swollman#define GLOB_FIRST_FAILED(handle) ((handle) != 0) 79324124Sjhb#define GLOB_NEXT_NAME(handle,fndp) findnext(fndp) 8059632Swollman#define GLOB_NAME_DONE(handle) 8159632Swollman#define GLOB_NAME ff_name 8259632Swollman#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 8359632Swollman struct ffblk fnd; \ 8459632Swollman char drive[MAXDRIVE]; \ 85103591Swollman char dir[MAXDIR]; \ 86119893Sru char fname[MAXFILE]; \ 8759632Swollman char ext[MAXEXT]; \ 88103591Swollman int handle; 89103591Swollman 90103591Swollman#endif 91103591Swollman#endif 92103591Swollman#endif 9359632Swollman#endif 9459632Swollman#endif 9559632Swollman