home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / less_332.lzh / less_332 / lglob.h < prev    next >
Text File  |  1998-03-03  |  4KB  |  111 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27. /*
  28.  * Macros to define the method of doing filename "globbing".
  29.  * There are three possible mechanisms:
  30.  *   1.    GLOB_LIST
  31.  *    This defines a function that returns a list of matching filenames.
  32.  *   2. GLOB_NAME
  33.  *    This defines a function that steps thru the list of matching
  34.  *    filenames, returning one name each time it is called.
  35.  *   3. GLOB_STRING
  36.  *    This defines a function that returns the complete list of
  37.  *    matching filenames as a single space-separated string.
  38.  */
  39.  
  40. #if OS2
  41.  
  42. #define    DECL_GLOB_LIST(list)        char **list;  char **pp;
  43. #define    GLOB_LIST(filename,list)    list = _fnexplode(filename)
  44. #define    GLOB_LIST_FAILED(list)        list == NULL
  45. #define    SCAN_GLOB_LIST(list,p)        pp = list;  *pp != NULL;  pp++
  46. #define    INIT_GLOB_LIST(list,p)        p = *pp
  47. #define    GLOB_LIST_DONE(list)        _fnexplodefree(list)
  48.  
  49. #else
  50. #if MSDOS_COMPILER==DJGPPC
  51.  
  52. #define    DECL_GLOB_LIST(list)        glob_t list;  int i;
  53. #define    GLOB_LIST(filename,list)    glob(filename,GLOB_NOCHECK,0,&list)
  54. #define    GLOB_LIST_FAILED(list)        0
  55. #define    SCAN_GLOB_LIST(list,p)        i = 0;  i < list.gl_pathc;  i++
  56. #define    INIT_GLOB_LIST(list,p)        p = list.gl_pathv[i]
  57. #define    GLOB_LIST_DONE(list)        globfree(&list)
  58.  
  59. #else
  60. #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC
  61.  
  62. #define    GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp)
  63. #define    GLOB_FIRST_FAILED(handle)    ((handle) != 0)
  64. #define    GLOB_NEXT_NAME(handle,fndp)        _dos_findnext(fndp)
  65. #define    GLOB_NAME_DONE(handle)
  66. #define    GLOB_NAME            name
  67. #define    DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
  68.                     struct find_t fnd;    \
  69.                     char drive[_MAX_DRIVE];    \
  70.                     char dir[_MAX_DIR];    \
  71.                     char fname[_MAX_FNAME];    \
  72.                     char ext[_MAX_EXT];    \
  73.                     int handle;
  74. #else
  75. #if MSDOS_COMPILER==WIN32C && defined(_MSC_VER)
  76.  
  77. #define    GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp)
  78. #define    GLOB_FIRST_FAILED(handle)    ((handle) == -1)
  79. #define    GLOB_NEXT_NAME(handle,fndp)    _findnext(handle, fndp)
  80. #define    GLOB_NAME_DONE(handle)        _findclose(handle)
  81. #define    GLOB_NAME            name
  82. #define    DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
  83.                     struct _finddata_t fnd;    \
  84.                     char drive[_MAX_DRIVE];    \
  85.                     char dir[_MAX_DIR];    \
  86.                     char fname[_MAX_FNAME];    \
  87.                     char ext[_MAX_EXT];    \
  88.                     long handle;
  89.  
  90. #else
  91. #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */
  92.  
  93. #define    GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL)
  94. #define    GLOB_FIRST_FAILED(handle)    ((handle) != 0)
  95. #define    GLOB_NEXT_NAME(handle,fndp)    findnext(fndp)
  96. #define    GLOB_NAME_DONE(handle)
  97. #define    GLOB_NAME            ff_name
  98. #define    DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
  99.                     struct ffblk fnd;    \
  100.                     char drive[MAXDRIVE];    \
  101.                     char dir[MAXDIR];    \
  102.                     char fname[MAXFILE];    \
  103.                     char ext[MAXEXT];    \
  104.                     int handle;
  105.  
  106. #endif
  107. #endif
  108. #endif
  109. #endif
  110. #endif
  111.