home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / global.h < prev    next >
C/C++ Source or Header  |  1991-01-31  |  6KB  |  224 lines

  1. #ifndef    _GLOBAL_H
  2. #define    _GLOBAL_H
  3.  
  4. /* Global definitions used by every source file.
  5.  * Some may be compiler dependent.
  6.  */
  7.  
  8. #if    defined(__TURBOC__) || defined(__STDC__) || defined(LATTICE)
  9. #define    ANSIPROTO    1
  10. #endif
  11.  
  12. #ifndef    __ARGS
  13. #ifdef    ANSIPROTO
  14. #define    __ARGS(x)    x
  15. #else
  16. #define    __ARGS(x)    ()
  17. #endif
  18. #endif
  19.  
  20.  
  21. #if    !defined(AMIGA) && (defined(LATTICE) || defined(MAC) || defined(__TURBOC__))
  22. /* These compilers require special open modes when reading binary files.
  23.  * 
  24.  * "The single most brilliant design decision in all of UNIX was the
  25.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  26.  *
  27.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  28.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  29.  */
  30. #define    READ_BINARY    "rb"
  31. #define    WRITE_BINARY    "wb"
  32. #define    APPEND_BINARY    "ab+"
  33. #define    READ_TEXT    "rt"
  34. #define    WRITE_TEXT    "wt"
  35. #define    APPEND_TEXT    "at+"
  36.  
  37. #else
  38.  
  39. #define    READ_BINARY    "r"
  40. #define    WRITE_BINARY    "w"
  41. #define    APPEND_BINARY    "a+"
  42. #define    READ_TEXT    "r"
  43. #define    WRITE_TEXT    "w"
  44. #define    APPEND_TEXT    "a+"
  45.  
  46. #endif
  47.  
  48. /* These two lines assume that your compiler's longs are 32 bits and
  49.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  50.  * but it doesn't matter if they're signed or unsigned.
  51.  */
  52. typedef long int32;        /* 32-bit signed integer */
  53. typedef unsigned short int16;    /* 16-bit unsigned integer */
  54. #define    uchar(x) ((unsigned char)(x))
  55. #define    MAXINT16 65535        /* Largest 16-bit integer */
  56. #define    MAXINT32 4294967295L    /* Largest 32-bit integer */
  57.  
  58. #define    HASHMOD    7        /* Modulus used by hash_ip() function */
  59.  
  60. /* The "interrupt" keyword is non-standard, so make it configurable */
  61. #if    defined(__TURBOC__) && defined(MSDOS)
  62. #define    INTERRUPT    void interrupt
  63. #else
  64. #define    INTERRUPT    void
  65. #endif
  66.  
  67. /* Note that these definitions are on by default if none of the Turbo-C style
  68.  * memory model definitions are on; this avoids having to change them when
  69.  * porting to 68K environments.
  70.  */
  71. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__)
  72. #define    LARGEDATA    1
  73. #endif
  74.  
  75. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__)
  76. #define    LARGECODE    1
  77. #endif
  78.  
  79. /* Since not all compilers support structure assignment, the ASSIGN()
  80.  * macro is used. This controls how it's actually implemented.
  81.  */
  82. #ifdef    NOSTRUCTASSIGN    /* Version for old compilers that don't support it */
  83. #define    ASSIGN(a,b)    memcpy((char *)&(a),(char *)&(b),sizeof(b));
  84. #else            /* Version for compilers that do */
  85. #define    ASSIGN(a,b)    ((a) = (b))
  86. #endif
  87.  
  88. /* Define null object pointer in case stdio.h isn't included */
  89. #ifndef    NULL
  90. /* General purpose NULL pointer */
  91. #define    NULL (void *)0
  92. #endif
  93. #define    NULLCHAR (char *)0    /* Null character pointer */
  94. #define    NULLCHARP (char **)0    /* Null character pointer pointer */
  95. #define    NULLINT    (int *)0    /* Null integer pointer */
  96. #define    NULLFP     (int (*)())0    /* Null pointer to function returning int */
  97. #define    NULLVFP     (void (*)())0    /* Null pointer to function returning void */
  98. #define    NULLVIFP (INTERRUPT (*)())0
  99. #define    NULLFILE (FILE *)0    /* Null file pointer */
  100.  
  101. /* standard boolean constants */
  102. #define FALSE 0
  103. #define TRUE 1
  104. #define NO 0
  105. #define YES 1
  106.  
  107. /* string equality shorthand */
  108. #define STREQ(x,y) (strcmp(x,y) == 0)
  109.  
  110. /* Extract a short from a long */
  111. #define    hiword(x)    ((int16)((x) >> 16))
  112. #define    loword(x)    ((int16)(x))
  113.  
  114. /* Extract a byte from a short */
  115. #define    hibyte(x)    ((unsigned char)((x) >> 8))
  116. #define    lobyte(x)    ((unsigned char)(x))
  117.  
  118. /* Extract nibbles from a byte */
  119. #define    hinibble(x)    (((x) >> 4) & 0xf)
  120. #define    lonibble(x)    ((x) & 0xf)
  121.  
  122. /* Various low-level and miscellaneous functions */
  123. unsigned long availmem __ARGS((void));
  124. void *callocw __ARGS((unsigned nelem,unsigned size));
  125. int dirps __ARGS((void));
  126. int getopt __ARGS((int argc,char *argv[],char *opts));
  127. int htoi __ARGS((char *));
  128. long htol __ARGS((char *));
  129. char *inbuf __ARGS((int16 port,char *buf,int16 cnt));
  130. int16 hash_ip __ARGS((int32 addr));
  131. int istate __ARGS((void));
  132. void log __ARGS((int s,char *fmt, ...));
  133. void *ltop __ARGS((long));
  134. void *mallocw __ARGS((unsigned nb));
  135. char *outbuf __ARGS((int16 port,char *buf,int16 cnt));
  136. long ptol __ARGS((void *));
  137. void restore __ARGS((int));
  138. void rflush __ARGS((void));
  139. void rip __ARGS((char *));
  140. char *smsg __ARGS((char *msgs[],unsigned nmsgs,unsigned n));
  141. int tprintf __ARGS((char *fmt,...));
  142. #if    !defined __TURBOC__
  143. char *strdup __ARGS((const char *));
  144. #endif
  145. int wildmat __ARGS((char *s,char *p,char **argv));
  146.  
  147. #include <stdlib.h>
  148. #include <string.h>
  149.  
  150. #ifdef    AZTEC
  151. #define    rewind(fp)    fseek(fp,0L,0);
  152. #endif
  153.  
  154. #if     defined(__TURBOC__) && defined(MSDOS)
  155. #define movblock(so,ss,do,ds,c)    movedata(ss,so,ds,do,c)
  156. #define outportw outport
  157. #define inportw inport
  158.  
  159. #else
  160.  
  161. /* General purpose function macros already defined in turbo C */
  162. #ifndef    min
  163. #define    min(x,y)    ((x)<(y)?(x):(y))    /* Lesser of two args */
  164. #endif
  165. #ifndef max
  166. #define    max(x,y)    ((x)>(y)?(x):(y))    /* Greater of two args */
  167. #endif
  168. #ifdef    MSDOS
  169. #define MK_FP(seg,ofs)    ((void far *) \
  170.                (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  171. #endif
  172. #endif    /* __TURBOC __ */
  173.  
  174. #ifdef    AMIGA
  175. /* super kludge de WA3YMH */
  176. #ifndef    fileno
  177. #include <stdio.h>
  178. #endif
  179. #define fclose(fp)    amiga_fclose(fp)
  180. extern int amiga_fclose __ARGS((FILE *));
  181. extern FILE *tmpfile __ARGS((void));
  182.  
  183. extern char *sys_errlist[];
  184. extern int errno;
  185. #endif
  186.  
  187. /* Externals used by getopt */
  188. extern int optind;
  189. extern char *optarg;
  190.  
  191. /* Threshold setting on available memory */
  192. extern int32 Memthresh;
  193.  
  194. /* System clock - count of ticks since startup */
  195. extern int32 Clock;
  196.  
  197. /* Various useful standard error messages */
  198. extern char Badhost[];
  199. extern char Nospace[];
  200. extern char Notval[];
  201. extern char *Hostname;
  202. extern char Version[];
  203.  
  204. /* Your system's end-of-line convention */
  205. extern char Eol[];
  206.  
  207. extern void (*Gcollect[])();
  208.  
  209. /*
  210.  * The following extern statements are to allow compilation by
  211.  *  Turbo C++ 1.00
  212.  */
  213. extern struct ax25_cb;
  214. extern struct dirsort;
  215. extern struct iface;
  216. extern struct ip;
  217. extern struct mbx;
  218. extern struct mbuf;
  219. extern struct nr4cb;
  220. extern struct session;
  221. extern struct slip;
  222.  
  223. #endif    /* _GLOBAL_H */
  224.