home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / wildf113.zip / WILDFILE.H < prev    next >
C/C++ Source or Header  |  1991-04-20  |  11KB  |  252 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: wildfile.h
  5.    Author: J. Kercheval
  6.    Created: Thu, 03/14/1991  20:10:16
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Thu, 03/14/1991  21:15:57  ifdef attribute constants
  12.    J. Kercheval  Sat, 03/16/1991  15:03:54  add FileInfo structure
  13.    J. Kercheval  Sat, 03/16/1991  20:08:41  add status byte
  14.    J. Kercheval  Sun, 03/31/1991  16:15:06  rename time and date defines
  15. */
  16.  
  17. #ifndef BOOLEAN
  18. # define BOOLEAN int
  19. # define TRUE 1
  20. # define FALSE 0
  21. #endif
  22.  
  23. /*
  24.  
  25.     Dedicated to the Public Domain.  Use this for any purpose for any
  26.     reason with no restrictions, warranties, suitability for fitness
  27.     etc.
  28.  
  29.     Wild File is a module designed to aid the developer in producing
  30.     programs which use a *sensible* wildcard scheme.  For instance
  31.     using this module your command line could specify any SH style
  32.     regular expression which produced a valid file name as input for
  33.     file names.  The only limitation is that since DOS uses the
  34.     literal escape character '\' as a delimiter to specifying a
  35.     directory follow you may not use this character in the command
  36.     line in this routine.
  37.  
  38.     This module assumes compilation on MSC or Borland C (Turbo C, TCC, BCC)
  39. */
  40.  
  41.  
  42. /*----------------------------------------------------------------------------
  43. *
  44. *
  45. *  These routines allow the use of  multiple search threads.  Simply
  46. *  declare a variable to be of type FileInfo (perhaps called ff), fill
  47. *  in the file_pattern and the file_attributes fields (ie.
  48. *  ff.file_pattern and ff.file_attributes), initiate the search with
  49. *  find_firstfile() and continue the search with find_nextfile().  There
  50. *  is no reason why you could not conduct more than one search
  51. *  simultaneously using several different variables.
  52. *
  53. *  In general you should not alter any element of the FileInfo structure
  54. *  once find_firstfile() has been called.  You should never alter any
  55. *  element of the file field in the FileInfo structure.  Doing so may
  56. *  make it impossible to continue the search.
  57. *
  58. *  The elements of the FileInfo structure are defined as follows:
  59. *
  60. *      file_pattern      A string representing the search expression
  61. *                        filled in by the caller before the call to
  62. *                        find_firstfile()
  63. *
  64. *      file_attributes   An 8 bit flag representing the file attributes
  65. *                        you are interested in.  This should be created
  66. *                        by using the | operator and the defined
  67. *                        constants below (ie. _FA_HIDDEN | _FA_NORMAL |
  68. *                        _FA_SYSTEM would obtain all files that were
  69. *                        hidden, system or normal (no attribute) files).
  70. *                        This should be filled before the call to
  71. *                        find_firstfile()
  72. *
  73. *      file_path         Derived from the file_pattern feild in
  74. *                        find_firstfile(), this feild represents the
  75. *                        path required to locate the file whose name is
  76. *                        found in file.name as described below
  77. *
  78. *      file              This is a structure defined by most compilers
  79. *                        and its contents are DOS defined.  It is filled
  80. *                        on a call to find_firstfile() or find_nextfile()
  81. *                        and contains specific information about each
  82. *                        file found.  If find_firstfile() or
  83. *                        find_nextfile() return FALSE then this
  84. *                        structure has undefined fields.
  85. *                        The structures elements are defined as:
  86. *
  87. *                            file.name       The name and extension of
  88. *                                            the last file found. Is of
  89. *                                            type char[13].
  90. *
  91. *                            file.size       The size in bytes of the
  92. *                                            last file found. Is of type
  93. *                                            long.
  94. *
  95. *                            file.attributes The ORed attributes of the
  96. *                                            last found file. Is of type
  97. *                                            char.
  98. *
  99. *                            file.datestamp  The data of last modification
  100. *                                            for the last found file. Is
  101. *                                            of type int with bits defined
  102. *                                            as follows:
  103. *                                                bits 0-4    day
  104. *                                                bits 5-8    month
  105. *                                                bits 9-15   years since 1980
  106. *
  107. *                            file.timestamp  The time of last modification
  108. *                                            for the last found file.  Is
  109. *                                            if type int with bits defined
  110. *                                            as follows:
  111. *                                                bits 0-4    seconds div 2
  112. *                                                bits 5-10   minutes
  113. *                                                bits 11-15  hours
  114. *
  115. *      status            Information flags used internally by this module.
  116. *                        There is no user interesting information and this
  117. *                        status byte should not be altered.  Changing this
  118. *                        feild may result in incorrect file matching behavior
  119. *                        by find_nextfile().
  120. *
  121. *  As an example use of these routines refer to the main() function at
  122. *  the end of wildfile.c
  123. *
  124. ----------------------------------------------------------------------------*/
  125.  
  126. #ifdef __TURBOC__
  127. # include <dir.h>
  128. # define info ffblk
  129. # define attributes ff_attrib
  130. # define timestamp ff_ftime
  131. # define datestamp ff_fdate
  132. # define size ff_fsize
  133. # define name ff_name
  134. #else
  135. # include <dos.h>
  136. # define info find_t
  137. # define attributes attrib
  138. # define timestamp wr_time
  139. # define datestamp wr_date
  140. # define size size
  141. # define name name 
  142. # define MAXPATH   80
  143. #endif
  144.  
  145. struct file_info_struct {
  146.  
  147.     /* thest elements should be set before the call to find_firstfile() */
  148.     char file_pattern[2*MAXPATH+1];     /* the original file pattern */
  149.     char file_attributes;               /* the wanted file attributes */
  150.  
  151.     /* these elements are filled by find_firstfile() and find_nextfile() */
  152.     char file_path[MAXPATH+1];          /* the lead portion of the path */
  153.     struct info file;                   /* the file block */
  154.     unsigned char status;               /* internal status information */
  155. };
  156.  
  157. typedef struct file_info_struct FileInfo;
  158.  
  159.  
  160. /*----------------------------------------------------------------------------
  161. *
  162. *  In behavior regarding attributes, these routines differ a bit from the
  163. *  standard DOS calls to findfile and findnext.  These routines will only
  164. *  return files with those attributes you explicitly set.  The
  165. *  standard DOS call will return all normal files in addition to the
  166. *  attributes wanted.  This is a little silly since the behavior is true
  167. *  for only certian attribute bits.  The Volume bit set will not result
  168. *  in the return of normal files.  One side effect of this design
  169. *  decision is that you must explicitly ask for files with normal or
  170. *  *no* attributes.  Believe me this is NOT a hardship.
  171. *
  172. *  To obtain a combination of attributes just or the attribute constants
  173. *  as needed (ie. _FA_NORMAL | _FA_READONLY).  Only those files with a wanted
  174. *  attribute will be returned.  If files without any attributes are wanted
  175. *  then you must or the A_NORMAL constant into the attr parameter (This is
  176. *  different behavior than the standard findfirst, findnext call behavior).
  177. *
  178. *  Note: These constants are defined internally for portability.  The
  179. *  constant used does not change but the various compilers sure have
  180. *  invented enough names for them.  I assume BC (Turbo C) or MSC.
  181. *
  182. *  The file attribute definitions are as follows:
  183. *
  184. *    _FA_READONLY   Search for readonly files
  185. *    _FA_HIDDEN     Search for hidden files
  186. *    _FA_SYSTEM     Search for system files
  187. *    _FA_VOLUME     Search for Volume label
  188. *    _FA_DIRECTORY  Search for Directory
  189. *    _FA_ARCHIVE    Search for non backup up files
  190. *    _FA_NORMAL     Search for all normal files
  191. *
  192. ----------------------------------------------------------------------------*/
  193.  
  194. /* if not using Borland C then assume MSC */
  195.  
  196. #ifdef __TURBOC__
  197. # define _FA_READONLY  FA_READONLY
  198. # define _FA_HIDDEN    FA_HIDDEN
  199. # define _FA_SYSTEM    FA_SYSTEM
  200. # define _FA_VOLUME    FA_VOLUME
  201. # define _FA_DIRECTORY FA_DIRECTORY
  202. # define _FA_ARCHIVE   FA_ARCHIVE
  203. # define _FA_NORMAL    0x40
  204. #else
  205. # define _FA_READONLY  _A_RDONLY
  206. # define _FA_HIDDEN    _A_HIDDEN
  207. # define _FA_SYSTEM    _A_SYSTEM
  208. # define _FA_VOLUME    _A_VOLID
  209. # define _FA_DIRECTORY _A_SUBDIR
  210. # define _FA_ARCHIVE   _A_ARCH
  211. # define _FA_NORMAL    0x40
  212. #endif
  213.  
  214.  
  215. /*----------------------------------------------------------------------------
  216. *
  217. *  find_firstfile() will find the first file matching file_pattern.
  218. *  find_nextfile() will find the next file matching the name specified
  219. *  by find_firstfile().  The routines will return the BOOLEAN value FALSE
  220. *  if the file is not found in the call to  find_firstfile() or if there are
  221. *  no more files found in a call to find_nextfile.  If a file is found then
  222. *  both routines will return the BOOLEAN value TRUE.
  223. *
  224. *  file_pattern may be SH style regular expressions.  The regular expression
  225. *  symbols allowed are:
  226. *
  227. *       '*' -- Matches any set of zero or more characters
  228. *       '?' -- Matches any single character
  229. *       [SET] matches any character in the specified set,
  230. *       [!SET] or [^SET] matches any character not in the specified set.
  231. *       \ is allowed within a set to escape a character like ']' or '-'
  232. *
  233. *  A set is composed of characters or ranges; a range looks like
  234. *  character hyphen character (as in 0-9 or A-Z).  [0-9a-zA-Z_] is the
  235. *  minimal set of characters allowed in the [..] pattern construct.
  236. *  Other characters are allowed (ie. 8 bit characters) if your system
  237. *  will support them.
  238. *
  239. *  To suppress the special syntactic significance of any of
  240. *  `[]*?!^-\' within an [..] construct and match the character exactly,
  241. *  precede it with a `\'.
  242. *
  243. *  Parameters:
  244. *       ff - a pointer to a FileInfo structure already allocated or
  245. *            declared.
  246. *
  247. ----------------------------------------------------------------------------*/
  248.  
  249. BOOLEAN find_firstfile( FileInfo *ff );
  250. BOOLEAN find_nextfile( FileInfo *ff );
  251.  
  252.