home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / unix / dgrep.arc / SYSTEM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-16  |  3.9 KB  |  173 lines

  1. /**********************************************************************\
  2.  *
  3.  *    SYSTEM.H
  4.  *
  5.  * System dependencies and configurations for dgrep.
  6.  *
  7.  * Conditional compilation:
  8.  *    ECTYPE  - Includes extended ctype instead of original.
  9.  *    UNIX    - Uses '\n' as end of line character, otherwise uses
  10.  *          '\r\n'-pair.
  11.  *    BSD     - Defines from SysV library to Bsd, defines also UNIX.
  12.  *    TEST    - Includes routines to display some internal structures
  13.  *          and defines debug flag 'debug' which controls debug
  14.  *          displaying. Debug can be set to TRUE with -d option.
  15.  *    MANYREG    - Uses more than two register variables. Defined
  16.  *          automatically with UNIX and BSD.
  17.  *    TOUCH    - Touches all files that contain matches. Only for Turbo C
  18.  *          and systems, that contain time(3) and utime(3). Utime(3)
  19.  *          is supposed to be in every UNIX-system.
  20.  *    FAST    - Makes faster dfa but uses more memory. This doesn't really
  21.  *          affect to the state machine but to the way how the
  22.  *          transitions are stored internally.
  23.  *
  24.  * Author: Jarmo Ruuth 17-Mar-1988
  25.  *
  26.  * Copyright (C) 1988-90 by Jarmo Ruuth
  27.  * May be freely copied for any non-commercial usage.
  28. \**********************************************************************/
  29.  
  30. #include <stdio.h>
  31.  
  32. #define assert(exp)    if (!(exp)) assertion_failure(__FILE__,__LINE__)
  33.  
  34. #ifdef ECTYPE
  35.  
  36. #include <ectype.h>
  37. #define    CHCASE(c)    _diffcase[(unsigned char)(c)]
  38.  
  39. #else
  40.  
  41. #include <ctype.h>
  42. #define    CHCASE(c)    (isalpha(c) ? ((c) ^ ('a' ^ 'A')) : (c))
  43.  
  44. #endif    /* ECTYPE */
  45.  
  46. #ifdef BSD
  47.  
  48. #define UNIX 
  49. #define memcpy(dest,src,len)    bcopy(src,dest,len)
  50. #define memcmp(s1,s2,len)    bcmp(s1,s2,len)
  51. extern void* memset(void* b, char ch, unsigned n);
  52. extern void* memchr(void* b, char ch, unsigned n);
  53. extern char* ultoa(unsigned long n, char* s, int radix);
  54. #include <strings.h>
  55.  
  56. #else
  57.  
  58. #include <string.h>
  59. #include <process.h>
  60. #include <io.h>
  61. #include <stdlib.h>
  62.  
  63. #endif    /* BSD */
  64.  
  65. #ifdef __TURBOC__
  66.  
  67. #define TOUCH
  68. #include <alloc.h>
  69.  
  70. #endif    /* TURBOC */
  71.  
  72. #ifdef M_I86    /* MSC */
  73.  
  74. #define TOUCH
  75. #include <malloc.h>
  76. #include <sys\types.h>
  77. #include <sys\utime.h>
  78. #include <time.h>
  79. typedef struct utimbuf    utime_t;
  80.  
  81. #endif    /* MSC */
  82.  
  83. #if defined(__TURBOC__) || (defined(M_I86) && defined(MSDOS))
  84. #define fputs(s,f)    putstr(s)
  85. #endif
  86.  
  87. #ifndef max
  88. #define max(x,y)    ((x) > (y) ? (x) : (y))
  89. #endif
  90.  
  91. #ifndef min
  92. #define min(x,y)    ((x) < (y) ? (x) : (y))
  93. #endif
  94.  
  95. #define ERROR        -1
  96.  
  97. #define CHARBITS    8        /* hardware character bits */
  98. #define NCHARS        (1 << CHARBITS)
  99. #define MAXCHAR        (NCHARS-1)
  100.  
  101. #define MAXBUF        (1024*24)
  102. #define MAXREGMUST    MAXCHAR
  103.  
  104. #define REG1    register
  105. #define REG2    register
  106.  
  107. #ifdef    UNIX
  108.  
  109. #define O_BINARY        0
  110. #define EOL1        '\n'
  111. #define EOL2        '\n'
  112. #define NEOL(_P)    1
  113. #define ALIGN        4096
  114. #define MANYREG
  115. #define TOUCH
  116.  
  117. #include <sys/types.h>
  118. #include <time.h>
  119.  
  120. /* define utime() parameter in MSC style */
  121. typedef struct {
  122.     time_t actime;      /* access time */
  123.     time_t modtime;     /* modification time */
  124. } utime_t;
  125.  
  126. #else
  127.  
  128. #define EOL1        '\r'
  129. #define EOL2        '\n'
  130. #define NEOL(_P)    ((_P)[1] == EOL2 ? 2 : 1)
  131. #define ALIGN        2048
  132.  
  133. #endif
  134.  
  135. #ifdef MANYREG
  136.  
  137. #define REG3    register
  138. #define REG4    register
  139. #define REG5    register
  140. #define REG6    register
  141.  
  142. #else
  143.  
  144. #define REG3
  145. #define REG4
  146. #define REG5
  147. #define REG6
  148.  
  149. #endif
  150.  
  151. /* common typedefs */
  152. typedef unsigned char    uchar;
  153. typedef unsigned int    uint;
  154. typedef unsigned long    ulong;
  155. typedef enum {
  156.     FALSE,
  157.     TRUE
  158. } bool;
  159.  
  160. extern void* malloc(unsigned nbytes);
  161. extern void* calloc(unsigned nelem, unsigned elsize);
  162. extern void* realloc(void* p, unsigned newsize);
  163. extern void  free(void* p);
  164. extern void  d_free(void* ptr);
  165. extern void  error(char* errmsg, int exit_value);
  166. extern void  alloc_buffer(void);
  167. extern bool  set_file_time(char* fname, int h);
  168. extern void  putstr(uchar* str);
  169. extern void  assertion_failure(char* file, int line);
  170.  
  171. extern uchar*    buffer;
  172. extern unsigned    maxbuf;
  173.