home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / util2src / util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-30  |  14.0 KB  |  314 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.  * 11/11/92 - Added DOS16FIND* functions: Use *instead* of DosFind* APIs:
  21.  *            see change history in speclist.c for more information on why.
  22.  * 09/30/93 - Added definitions for lbuf.c functions.
  23.  *============================================================================*/
  24.  
  25. #ifndef _h_UTIL /* else we've already been included */
  26. #define _h_UTIL
  27.  
  28. #define INCL_BASE                   /* Include all of os2.h */
  29. #include <os2.h>
  30.  
  31. #ifndef TRUE
  32.  
  33. #define FALSE    0
  34. #define TRUE     1
  35.  
  36. #endif
  37.  
  38. /*============================================================================*
  39.  * Some typedefs from AIX's <sys/types.h> that are nice to have around
  40.  *============================================================================*/
  41.  
  42. #ifndef uint
  43.  
  44. /* Abbreviations for basic 'C' types with otherwise long names */
  45. typedef unsigned char   u_char;
  46. typedef unsigned short  u_short;
  47. typedef unsigned int    u_int;
  48. typedef unsigned long   u_long;
  49.  
  50. /* System 5 compatability constants */
  51. typedef unsigned char   uchar;
  52. typedef unsigned short  ushort;
  53. typedef unsigned int    uint;
  54. typedef unsigned long   ulong;
  55.  
  56. #endif
  57.  
  58. /*----------------------------------------------------------------------------*
  59.  * Labels from AIX's <unistd.h>, modified to be meaningful for DOS
  60.  *----------------------------------------------------------------------------*/
  61.  
  62. /* Symbolic constants for the "access" function: */
  63. #define R_OK 4          /* Test for "Read" Permission */
  64. #define W_OK 2          /* Test for "Write" Permission */
  65. #define F_OK 0          /* Test for existence of file */
  66.  
  67. /*============================================================================*
  68.  * Return values from rexpand() and rcompile() subroutines
  69.  *============================================================================*/
  70.  
  71. #define REGX_OK             0       /* Successful */
  72. #define REGX_ENDP          11       /* Range endpoint too large */
  73. #define REGX_NUM           16       /* Bad number */
  74. #define REGX_DIGIT         25       /* \digit out of range */
  75. #define REGX_BADDELIM      36       /* Illegal or missing delimiter */
  76. #define REGX_NOSTR         41       /* No remembered search string */
  77. #define REGX_PARENS        42       /* () imbalance */
  78. #define REGX_LPARENS       43       /* Too many ( */
  79. #define REGX_NUMCNT        44       /* More than two numbers given in {} */
  80. #define REGX_BRACE         45       /* } expected after \ */
  81. #define REGX_NUMSIZE       46       /* First number exceeds second in {} */
  82. #define REGX_BRKT          49       /* [] imbalance */
  83. #define REGX_FULL          50       /* Regular expression expansion overflow */
  84. #define REGX_MEMORY        51       /* Out of memory */
  85.  
  86.  /*----------------------------------------------------------------------------*
  87.  * Return values from rmatch() and rscan() subroutines
  88.  *----------------------------------------------------------------------------*/
  89.  
  90. #define RMATCH     0
  91. #define NO_RMATCH  1
  92.  
  93.  
  94. /*============================================================================*
  95.  * Structure type used to hold information from the decompose() subroutine.
  96.  * A pathname consists of '[d:path]name'.  This structure holds pointers and
  97.  * lengths to the 'path' [d:path] and 'name' portions.
  98.  *============================================================================*/
  99.  
  100. typedef struct {
  101.  
  102.      char      *path;               /* d:path portion, if any: Pointer */
  103.      int        pathlen;            /*                         Length  */
  104.  
  105.      char      *name;               /* name portion:           Pointer */
  106.      int        namelen;            /*                         Length  */
  107.  
  108. } PATH_NAME;
  109.  
  110. /*----------------------------------------------------------------------------*
  111.  * Structure type used by cvftime() to store expanded version
  112.  * of a file's date and time
  113.  *----------------------------------------------------------------------------*/
  114.  
  115. typedef struct {
  116.  
  117.      int        ftm_sec;            /* seconds (always even!) */
  118.      int        ftm_min;            /* minutes (0-59) */
  119.      int        ftm_hr;             /* hours (0-23) */
  120.      int        ftm_day;            /* day (1-31) */
  121.      int        ftm_mon;            /* month (1-12) */
  122.      int        ftm_year;           /* year (1980-2099) */
  123.  
  124. } FTM;
  125.  
  126. /*============================================================================*
  127.  * Definitions for a specification list
  128.  *
  129.  * A specification list consists of a singly-linked list of SLPATH structures.
  130.  * Each structure defines a unique drive:pathname, and points to a list of
  131.  * SLNAME structures for that pathname.  See the slmake() subroutine
  132.  * for information on how to make this list.
  133.  *
  134.  * The path field points to the (path) directory name. The bpathlen field
  135.  * contains the length of the base path that was originally specified.
  136.  * If the path was inserted (inserted==TRUE), then bpathlen contains the
  137.  * length of the portion of the path name that wasn't inserted.
  138.  *============================================================================*/
  139.  
  140. typedef struct slname {
  141.  
  142.      struct slname *next;           /* Pointer to next structure in list */
  143.      char      *name;               /* Pointer to name specification */
  144.      char      *ecname;             /* Expanded/compiled name spec: Pointer */
  145.      int        eclen;              /*                              Length */
  146.      long       fcount;             /* Count of no. of filename matches */
  147.  
  148. } SLNAME;
  149.  
  150. typedef struct slpath {
  151.  
  152.      struct slpath *next;           /* Pointer to next structure in list */
  153.      SLNAME    *firstname;          /* Pointer to list of name specifications */
  154.      SLNAME    *lastname;           /* Pointer to end of list of name specifications */
  155.      char      *path;               /* Pointer to pathname */
  156.      uint       bpathlen;           /* Length of pathname base */
  157.      ushort     inserted;           /* Inserted by slmatch()? TRUE or FALSE */
  158.      ushort     hpfs;               /* Is on HPFS filesystem? TRUE or FALSE */
  159.  
  160. } SLPATH;
  161.  
  162. /*----------------------------------------------------------------------------*
  163.  * Attribute (mode) flags for slrewind().  The HIDDEN - DIR flags are the
  164.  * same as their _A_ counterparts from <dos.h>.  The NORMAL and DOTDIR are
  165.  * needed to complete the pattern.
  166.  *----------------------------------------------------------------------------*/
  167.  
  168. #define SL_HIDDEN               0x02    /* Hidden file */
  169. #define SL_SYSTEM               0x04    /* System file */
  170. #define SL_VOLID                0x08    /* Volume ID file (not used by OS/2) */
  171. #define SL_DIR                  0x10    /* Subdirectory, except . and ..  */
  172.  
  173. #define SL_NORMAL               0x40    /* Normal file (incl. readonly) */
  174. #define SL_DOTDIR               0x80    /* Directories . and .. */
  175.  
  176. /*----------------------------------------------------------------------------*
  177.  * _A_ labels that are in dos.h but aren't supported by C Set/2.  They're
  178.  * defined here to maintain source code compatibility with C/2 and MSC.
  179.  *----------------------------------------------------------------------------*/
  180.  
  181. #define _A_NORMAL     FILE_NORMAL       /* Normal file - No read/write restrictions */
  182. #define _A_RDONLY     FILE_READONLY     /* Read only file */
  183. #define _A_HIDDEN     FILE_HIDDEN       /* Hidden file */
  184. #define _A_SYSTEM     FILE_SYSTEM       /* System file */
  185. #define _A_VOLID              0x0008    /* Volume ID file (not used by OS/2) */
  186. #define _A_SUBDIR     FILE_DIRECTORY    /* Subdirectory */
  187. #define _A_ARCH       FILE_ARCHIVED     /* Archive file */
  188.  
  189. /*----------------------------------------------------------------------------*
  190.  * Define common labels for DOS and OS/2.  These labels can be used to access
  191.  * the file information data structure returned by findfirst/findnext calls.
  192.  *----------------------------------------------------------------------------*/
  193.  
  194. #define FINFO FILEFINDBUF3          /* Shorter name, for convenience */
  195.  
  196. #define Fname achName
  197. #define Fsize cbFile
  198. #define Ftime ftimeLastWrite
  199. #define Fdate fdateLastWrite
  200. #define Fmode attrFile
  201.  
  202. /* begin DOS16FIND */
  203. /*============================================================================*
  204.  * Pragmas, prototypes, and structures for calling the 16-bit versions
  205.  * of DosFindFirst/Next/Close: DOS16FINDFIRST/NEXT/CLOSE. See speclist.c
  206.  * for examples of calling these functions. Do *not* use the 32-bit
  207.  * DosFind* functions in OS/2 2.0: see speclist.c for why.
  208.  *============================================================================*/
  209.  
  210. #pragma linkage ( DOS16FINDFIRST, far16 pascal )
  211. #pragma linkage ( DOS16FINDNEXT,  far16 pascal )
  212. #pragma linkage ( DOS16FINDCLOSE, far16 pascal )
  213.  
  214. typedef struct              {   /* from 1.3 toolkit's bsedos.h */
  215.     FDATE  fdateCreation;
  216.     FTIME  ftimeCreation;
  217.     FDATE  fdateLastAccess;
  218.     FTIME  ftimeLastAccess;
  219.     FDATE  fdateLastWrite;
  220.     FTIME  ftimeLastWrite;
  221.     ULONG  cbFile;
  222.     ULONG  cbFileAlloc;
  223.     USHORT attrFile;
  224.     UCHAR  cchName;
  225.     CHAR   achName[CCHMAXPATHCOMP];
  226. } DIRBUFF16;
  227.  
  228. #undef  FINFO                       /* Undo 32-bit definition */
  229. #define FINFO DIRBUFF16             /* Shorter name, for convenience */
  230.  
  231. extern USHORT   DOS16FINDFIRST(
  232.         char *fspec,           /* path name of files to be found              */
  233.         PHDIR phdir,           /* directory handle                            */
  234.         USHORT attr,           /* attribute used to search for the files      */
  235.         DIRBUFF16 *buff,       /* result buffer                               */
  236.         USHORT cbBuf,          /* length of result buffer                     */
  237.         PUSHORT pcSearch,      /* number of matching entries in result buffer */
  238.         ULONG ulReserved);     /* reserved (must be 0)                        */
  239.  
  240. extern USHORT   DOS16FINDNEXT(
  241.         HDIR hdir,                      /* directory handle          */
  242.         DIRBUFF16 *buff,                /* result buffer             */
  243.         USHORT cbBuf,                   /* length of result buffer   */
  244.         PUSHORT pcSearch);              /* number of entries to find */
  245.  
  246. extern USHORT   DOS16FINDCLOSE(
  247.         HDIR hdir);                     /* directory handle */
  248.  
  249. /* end DOS16FIND */
  250.  
  251. /*============================================================================*
  252.  * LBUF buffered stream structure.  This structure (and the buffer that
  253.  * immediately follows it) should be allocated by the newlbuf subroutine.
  254.  *============================================================================*/
  255.  
  256. typedef struct _lbuf {
  257.  
  258.      int        fd;                 /* File descriptor (-1 = none) */
  259.      uint       bufflen;            /* Size of I/O buffer for stream */
  260.      char      *buff;               /* Pointer to the start of the buffer */
  261.      char      *end;                /* Pointer just past end of data in buffer */
  262.      char      *next;               /* Pointer to next location to read */
  263.      int        ferrno;             /* errno from an I/O error (0=no error) */
  264.      int        seof;               /* end-of-stream?  (TRUE/FALSE) */
  265.  
  266. } LBUF;
  267.  
  268. /*============================================================================*
  269.  * Function prototypes for library, for strong type-checking
  270.  *============================================================================*/
  271.  
  272. int        makepath     ( char * );
  273. int        crcfile      ( char *fname, ushort *crc, ulong *flen );
  274. int        crcfile32    ( char *fname, ulong *crc, ulong *flen );
  275.  
  276. int        cfopen       ( char * );
  277. int        cfsetfile    ( FILE * );
  278. ulong      cfline       ( void );
  279. int        cfisapp      ( void );
  280. int        cfread       ( char *** );
  281. char      *cfreadfile   ( void );
  282. int        cfclose      ( void );
  283. int        cfgetbyname  ( char *, char *, char ***, char ** );
  284. int        cfstrcmpi    ( char *, char * );
  285.  
  286. int        rexpand      ( char *, char *, char *, char ** );
  287. int        rcompile     ( char *, char *, char *, char, char ** );
  288. int        rmatch       ( char *, char * );
  289. int        rscan        ( char *, char *, char **, char ** );
  290. char      *rcmpmsg      ( int );
  291.  
  292. int        text2bm      ( char *, FILE * );
  293.  
  294. int        cvtftime     ( unsigned, unsigned, FTM * );
  295. char      *pathcat      ( char *, char * );
  296. PATH_NAME *decompose    ( char * );
  297. int        isdir        ( char * );
  298. int        hasdrive     ( char * );
  299. int        ishpfs       ( char * );
  300. int        SetFileMode  ( char *, uint );
  301.  
  302. int        slmake       ( SLPATH **, int, int, int, char** );
  303. void       slrewind     ( SLPATH * , ushort, ushort );
  304. FINFO     *slmatch      ( SLPATH **, SLNAME ** );
  305. void       sldump       ( SLPATH * );
  306. char      *slerrspec    ( void );
  307. long       slnotfound   ( SLPATH * );
  308.  
  309. LBUF      *newlbuf      ( uint bufflen );
  310. void       setlbuf      ( LBUF *stream , int fd );
  311. char      *lgets        ( char *str, uint n, LBUF *stream );
  312.  
  313. #endif /* _h_UTIL */
  314.