home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / util2src / util.h32 < prev    next >
Encoding:
Text File  |  1992-09-21  |  10.6 KB  |  241 lines

  1. /*============================================================================*
  2.  * util.h - Definitions for functions in util.lib      OS/2 2.0 and C Set/2
  3.  *
  4.  * (C)Copyright IBM Corporation, 1991, 1992.  All rights reserved. Brian Yoder
  5.  *
  6.  * 01/26/90 - Created.
  7.  * 01/26/90 - Initial version (PS/2 AIX).
  8.  * 04/03/91 - Ported to DOS, C/2, and added stuff from AIX's <sys/types.h>.
  9.  * 04/29/91 - Ported to OS/2 - Includes all of <os2.h>, so you don't have to
  10.  *            include it (and shouldn't!).
  11.  * 05/06/91 - Added support for recursive directory descent by slmatch().
  12.  * 05/09/91 - Added support for directory name expansion by slmake().
  13.  * 05/21/91 - Changed Ftime/Fdate to LastWrite instead of LastAccess!!!!!
  14.  * 11/20/91 - Added function prototype for cfisapp() subroutine.
  15.  * 04/13/92 - Added prototype for ishpfs() and added hpfs field to SLPATH.
  16.  * 06/09/92 - Added function prototype for crcfile32() subroutine.
  17.  * 07/22/92 - The file information buffer is FILEFINDBUF3, for 32-bit code.
  18.  * 07/24/92 - Added SetFileMode for use by 32-bit code.
  19.  * 09/19/92 - Added makepath() prototype, and added bpathlen field to SLPATH.
  20.  *============================================================================*/
  21.  
  22. #ifndef _h_UTIL /* else we've already been included */
  23. #define _h_UTIL
  24.  
  25. #define INCL_BASE                   /* Include all of os2.h */
  26. #include <os2.h>
  27.  
  28. #ifndef TRUE
  29.  
  30. #define FALSE    0
  31. #define TRUE     1
  32.  
  33. #endif
  34.  
  35. /*============================================================================*
  36.  * Some typedefs from AIX's <sys/types.h> that are nice to have around
  37.  *============================================================================*/
  38.  
  39. #ifndef uint
  40.  
  41. /* Abbreviations for basic 'C' types with otherwise long names */
  42. typedef unsigned char   u_char;
  43. typedef unsigned short  u_short;
  44. typedef unsigned int    u_int;
  45. typedef unsigned long   u_long;
  46.  
  47. /* System 5 compatability constants */
  48. typedef unsigned char   uchar;
  49. typedef unsigned short  ushort;
  50. typedef unsigned int    uint;
  51. typedef unsigned long   ulong;
  52.  
  53. #endif
  54.  
  55. /*----------------------------------------------------------------------------*
  56.  * Labels from AIX's <unistd.h>, modified to be meaningful for DOS
  57.  *----------------------------------------------------------------------------*/
  58.  
  59. /* Symbolic constants for the "access" function: */
  60. #define R_OK 4          /* Test for "Read" Permission */
  61. #define W_OK 2          /* Test for "Write" Permission */
  62. #define F_OK 0          /* Test for existence of file */
  63.  
  64. /*============================================================================*
  65.  * Return values from rexpand() and rcompile() subroutines
  66.  *============================================================================*/
  67.  
  68. #define REGX_OK             0       /* Successful */
  69. #define REGX_ENDP          11       /* Range endpoint too large */
  70. #define REGX_NUM           16       /* Bad number */
  71. #define REGX_DIGIT         25       /* \digit out of range */
  72. #define REGX_BADDELIM      36       /* Illegal or missing delimiter */
  73. #define REGX_NOSTR         41       /* No remembered search string */
  74. #define REGX_PARENS        42       /* () imbalance */
  75. #define REGX_LPARENS       43       /* Too many ( */
  76. #define REGX_NUMCNT        44       /* More than two numbers given in {} */
  77. #define REGX_BRACE         45       /* } expected after \ */
  78. #define REGX_NUMSIZE       46       /* First number exceeds second in {} */
  79. #define REGX_BRKT          49       /* [] imbalance */
  80. #define REGX_FULL          50       /* Regular expression expansion overflow */
  81. #define REGX_MEMORY        51       /* Out of memory */
  82.  
  83.  /*----------------------------------------------------------------------------*
  84.  * Return values from rmatch() and rscan() subroutines
  85.  *----------------------------------------------------------------------------*/
  86.  
  87. #define RMATCH     0
  88. #define NO_RMATCH  1
  89.  
  90.  
  91. /*============================================================================*
  92.  * Structure type used to hold information from the decompose() subroutine.
  93.  * A pathname consists of '[d:path]name'.  This structure holds pointers and
  94.  * lengths to the 'path' [d:path] and 'name' portions.
  95.  *============================================================================*/
  96.  
  97. typedef struct {
  98.  
  99.      char      *path;               /* d:path portion, if any: Pointer */
  100.      int        pathlen;            /*                         Length  */
  101.  
  102.      char      *name;               /* name portion:           Pointer */
  103.      int        namelen;            /*                         Length  */
  104.  
  105. } PATH_NAME;
  106.  
  107. /*----------------------------------------------------------------------------*
  108.  * Structure type used by cvftime() to store expanded version
  109.  * of a file's date and time
  110.  *----------------------------------------------------------------------------*/
  111.  
  112. typedef struct {
  113.  
  114.      int        ftm_sec;            /* seconds (always even!) */
  115.      int        ftm_min;            /* minutes (0-59) */
  116.      int        ftm_hr;             /* hours (0-23) */
  117.      int        ftm_day;            /* day (1-31) */
  118.      int        ftm_mon;            /* month (1-12) */
  119.      int        ftm_year;           /* year (1980-2099) */
  120.  
  121. } FTM;
  122.  
  123. /*============================================================================*
  124.  * Definitions for a specification list
  125.  *
  126.  * A specification list consists of a singly-linked list of SLPATH structures.
  127.  * Each structure defines a unique drive:pathname, and points to a list of
  128.  * SLNAME structures for that pathname.  See the slmake() subroutine
  129.  * for information on how to make this list.
  130.  *
  131.  * The path field points to the (path) directory name. The bpathlen field
  132.  * contains the length of the base path that was originally specified.
  133.  * If the path was inserted (inserted==TRUE), then bpathlen contains the
  134.  * length of the portion of the path name that wasn't inserted.
  135.  *============================================================================*/
  136.  
  137. typedef struct slname {
  138.  
  139.      struct slname *next;           /* Pointer to next structure in list */
  140.      char      *name;               /* Pointer to name specification */
  141.      char      *ecname;             /* Expanded/compiled name spec: Pointer */
  142.      int        eclen;              /*                              Length */
  143.      long       fcount;             /* Count of no. of filename matches */
  144.  
  145. } SLNAME;
  146.  
  147. typedef struct slpath {
  148.  
  149.      struct slpath *next;           /* Pointer to next structure in list */
  150.      SLNAME    *firstname;          /* Pointer to list of name specifications */
  151.      SLNAME    *lastname;           /* Pointer to end of list of name specifications */
  152.      char      *path;               /* Pointer to pathname */
  153.      uint       bpathlen;           /* Length of pathname base */
  154.      ushort     inserted;           /* Inserted by slmatch()? TRUE or FALSE */
  155.      ushort     hpfs;               /* Is on HPFS filesystem? TRUE or FALSE */
  156.  
  157. } SLPATH;
  158.  
  159. /*----------------------------------------------------------------------------*
  160.  * Attribute (mode) flags for slrewind().  The HIDDEN - DIR flags are the
  161.  * same as their _A_ counterparts from <dos.h>.  The NORMAL and DOTDIR are
  162.  * needed to complete the pattern.
  163.  *----------------------------------------------------------------------------*/
  164.  
  165. #define SL_HIDDEN               0x02    /* Hidden file */
  166. #define SL_SYSTEM               0x04    /* System file */
  167. #define SL_VOLID                0x08    /* Volume ID file (not used by OS/2) */
  168. #define SL_DIR                  0x10    /* Subdirectory, except . and ..  */
  169.  
  170. #define SL_NORMAL               0x40    /* Normal file (incl. readonly) */
  171. #define SL_DOTDIR               0x80    /* Directories . and .. */
  172.  
  173. /*----------------------------------------------------------------------------*
  174.  * _A_ labels that are in dos.h but aren't supported by C Set/2.  They're
  175.  * defined here to maintain source code compatibility with C/2 and MSC.
  176.  *----------------------------------------------------------------------------*/
  177.  
  178. #define _A_NORMAL     FILE_NORMAL       /* Normal file - No read/write restrictions */
  179. #define _A_RDONLY     FILE_READONLY     /* Read only file */
  180. #define _A_HIDDEN     FILE_HIDDEN       /* Hidden file */
  181. #define _A_SYSTEM     FILE_SYSTEM       /* System file */
  182. #define _A_VOLID              0x0008    /* Volume ID file (not used by OS/2) */
  183. #define _A_SUBDIR     FILE_DIRECTORY    /* Subdirectory */
  184. #define _A_ARCH       FILE_ARCHIVED     /* Archive file */
  185.  
  186. /*----------------------------------------------------------------------------*
  187.  * Define common labels for DOS and OS/2.  These labels can be used to access
  188.  * the file information data structure returned by findfirst/findnext calls.
  189.  *----------------------------------------------------------------------------*/
  190.  
  191. #define FINFO FILEFINDBUF3          /* Shorter name, for convenience */
  192.  
  193. #define Fname achName
  194. #define Fsize cbFile
  195. #define Ftime ftimeLastWrite
  196. #define Fdate fdateLastWrite
  197. #define Fmode attrFile
  198.  
  199. /*============================================================================*
  200.  * Function prototypes for library, for strong type-checking
  201.  *============================================================================*/
  202.  
  203. int        makepath     ( char * );
  204. int        crcfile      ( char *fname, ushort *crc, ulong *flen );
  205. int        crcfile32    ( char *fname, ulong *crc, ulong *flen );
  206.  
  207. int        cfopen       ( char * );
  208. int        cfsetfile    ( FILE * );
  209. ulong      cfline       ( void );
  210. int        cfisapp      ( void );
  211. int        cfread       ( char *** );
  212. char      *cfreadfile   ( void );
  213. int        cfclose      ( void );
  214. int        cfgetbyname  ( char *, char *, char ***, char ** );
  215. int        cfstrcmpi    ( char *, char * );
  216.  
  217. int        rexpand      ( char *, char *, char *, char ** );
  218. int        rcompile     ( char *, char *, char *, char, char ** );
  219. int        rmatch       ( char *, char * );
  220. int        rscan        ( char *, char *, char **, char ** );
  221. char      *rcmpmsg      ( int );
  222.  
  223. int        text2bm      ( char *, FILE * );
  224.  
  225. int        cvtftime     ( unsigned, unsigned, FTM * );
  226. char      *pathcat      ( char *, char * );
  227. PATH_NAME *decompose    ( char * );
  228. int        isdir        ( char * );
  229. int        hasdrive     ( char * );
  230. int        ishpfs       ( char * );
  231. int        SetFileMode  ( char *, uint );
  232.  
  233. int        slmake       ( SLPATH **, int, int, int, char** );
  234. void       slrewind     ( SLPATH * , ushort, ushort );
  235. FINFO     *slmatch      ( SLPATH **, SLNAME ** );
  236. void       sldump       ( SLPATH * );
  237. char      *slerrspec    ( void );
  238. long       slnotfound   ( SLPATH * );
  239.  
  240. #endif /* _h_UTIL */
  241.