home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / GLOBAL.H < prev    next >
C/C++ Source or Header  |  1994-10-09  |  10KB  |  361 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. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.   
  12. #if     defined(__TURBOC__) || defined(__STDC__) || defined(LATTICE)
  13. #define ANSIPROTO       1
  14. #endif
  15.   
  16. #ifdef UNIX
  17. #define O_BINARY 0
  18. #define cdecl
  19. #define _Cdecl
  20. #define far
  21. #define _FAR
  22. #define near
  23. #define _NEAR
  24. #endif
  25.   
  26. /* Distinguish between Turbo C 2.0, and TC++ v1.0 and Borland C++ 2.0,3.0,3.1 */
  27. #if defined(__TURBOC__) && __TURBOC__ >= 0x0295 && __TURBOC__ < 0x0300
  28. #define __BORLANDC__ 0x0100     /* Pretend we're Borland C */
  29. /* Turbo C++ 1.0x is confused about some structures whose addresses are
  30.     passed as arguments.  We kludge something here to fix it...wa7tas
  31.     We use "-stu" to ignore the Warning: Undefined structure 'xxx' messages.
  32. */
  33. #pragma warn -stu
  34. extern struct ax25_cb;
  35. extern struct iface;
  36. extern struct ip;
  37. extern struct mbx;
  38. extern struct mbuf;
  39. extern struct nr4cb;
  40. extern struct session;
  41. #endif
  42.   
  43. /* Distinguish between Turbo C 2.0, and Borland C++ 2.0,3.0,3.1 */
  44. #if defined(__TURBOC__) && defined(__BORLANDC__)
  45. #define DFAR far
  46. #else
  47. #define DFAR
  48. #endif
  49.   
  50. #ifndef __ARGS
  51. #ifdef  ANSIPROTO
  52. #define __ARGS(x)       x
  53. #else
  54. #define __ARGS(x)       ()
  55. #endif
  56. #endif
  57.   
  58. /* To avoid some problems with the possibility of opening devices
  59.  * that lock up nos (ie. CON etc.)
  60.  * redefine fopen() call.
  61.  * WG7J, 930205
  62.  */
  63. /* Appearantly Turbo-C cannot handle this - WG7J */
  64. #ifdef __BORLANDC__
  65.   
  66. FILE _FAR *_Cdecl newfopen(const char _FAR *__path, const char _FAR *__mode);
  67. #define fopen newfopen
  68.   
  69. #endif /* __BORLANDC__ */
  70.   
  71. #if     !defined(AMIGA) && (defined(LATTICE) || defined(MAC) || defined(__TURBOC__))
  72. /* These compilers require special open modes when reading binary files.
  73.  *
  74.  * "The single most brilliant design decision in all of UNIX was the
  75.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  76.  *
  77.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  78.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  79.  */
  80. #define READ_BINARY     "rb"
  81. #define WRITE_BINARY    "wb"
  82. #define APPEND_BINARY   "ab+"
  83. #define READ_TEXT       "rt"
  84. #define WRITE_TEXT      "wt"
  85. #define APPEND_TEXT     "at+"
  86.   
  87. #else
  88.   
  89. #define READ_BINARY     "r"
  90. #define WRITE_BINARY    "w"
  91. #define APPEND_BINARY   "a+"
  92. #define READ_TEXT       "r"
  93. #define WRITE_TEXT      "w"
  94. #define APPEND_TEXT     "a+"
  95.   
  96. #endif
  97.   
  98. /* These two lines assume that your compiler's longs are 32 bits and
  99.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  100.  * but it doesn't matter if they're signed or unsigned.
  101.  */
  102. typedef long int32;             /* 32-bit signed integer */
  103. typedef unsigned short int16;   /* 16-bit unsigned integer */
  104. typedef unsigned char byte_t;   /*  8-bit unsigned integer */
  105. #define uchar(x) ((unsigned char)(x))
  106. #define MAXINT16 65535U         /* Largest 16-bit integer */
  107. #define MAXINT32 4294967295L    /* Largest 32-bit integer */
  108.   
  109. #define HASHMOD 7               /* Modulus used by hash_ip() function */
  110.   
  111. /* The "interrupt" keyword is non-standard, so make it configurable */
  112. #if     defined(__TURBOC__) && defined(MSDOS)
  113. #define INTERRUPT       void interrupt
  114. #else
  115. #define INTERRUPT       void
  116. #endif
  117.   
  118. /* Note that these definitions are on by default if none of the Turbo-C style
  119.  * memory model definitions are on; this avoids having to change them when
  120.  * porting to 68K environments.
  121.  */
  122. #if     !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__)
  123. #define LARGEDATA       1
  124. #endif
  125.   
  126. #if     !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__)
  127. #define LARGECODE       1
  128. #endif
  129.   
  130. /* Since not all compilers support structure assignment, the ASSIGN()
  131.  * macro is used. This controls how it's actually implemented.
  132.  */
  133. #ifdef  NOSTRUCTASSIGN  /* Version for old compilers that don't support it */
  134. #define ASSIGN(a,b)     memcpy((char *)&(a),(char *)&(b),sizeof(b));
  135. #else                   /* Version for compilers that do */
  136. #define ASSIGN(a,b)     ((a) = (b))
  137. #endif
  138.   
  139. /* Define null object pointer in case stdio.h isn't included */
  140. #ifndef NULL
  141. /* General purpose NULL pointer */
  142. #define NULL (void *)0
  143. #endif
  144. #define NULLCHAR (char *)0      /* Null character pointer */
  145. #define NULLCHARP (char **)0    /* Null character pointer pointer */
  146. #define NULLINT (int *)0        /* Null integer pointer */
  147. #define NULLFP   (int (*)())0   /* Null pointer to function returning int */
  148. #define NULLVFP  (void (*)())0  /* Null pointer to function returning void */
  149. #define NULLVIFP (INTERRUPT (*)())0
  150. #define NULLFILE (FILE *)0      /* Null file pointer */
  151.   
  152. /* standard boolean constants */
  153. #define FALSE 0
  154. #define TRUE 1
  155. #define NO 0
  156. #define YES 1
  157.   
  158. #ifdef UNIX
  159. #ifdef BSD_RANDOM
  160. #define SRANDOM(n) srandom(n)
  161. #define RANDOM(n) ((int) (random() * (n)))
  162. #else
  163. #define SRANDOM(n) srand48(n)
  164. #define RANDOM(n) ((int) (drand48() * (n)))
  165. #endif
  166. #else
  167. #define RANDOM(n) random(n)
  168. #endif
  169.   
  170. #ifdef UNIX
  171. /* !@#$%&* DOS quote-C-unquote dialects! ++bsa */
  172. #define strcmpi strcasecmp
  173. #define stricmp strcasecmp
  174. #define strncmpi strncasecmp
  175. #define strnicmp strncasecmp
  176. /* and work around a collision which is currently making me drop core... */
  177. #define tputs j_tputs
  178. /* some older systems lack strtoul(); we'll just have to hope this is okay */
  179. #ifdef NO_STRTOUL
  180. #define strtoul(s,cp,b) ((unsigned long) strtol((s),(cp),(b)))
  181. #endif
  182. /* minimal malloc checking is done, so intercept free() */
  183. #define free j_free
  184.   
  185. #endif /* UNIX */
  186.   
  187. /* string equality shorthand */
  188. #define STREQ(x,y) (strcmp(x,y) == 0)
  189.   
  190. /* Extract a short from a long */
  191. #define hiword(x)       ((int16)((x) >> 16))
  192. #define loword(x)       ((int16)(x))
  193.   
  194. /* Extract a byte from a short */
  195. #define hibyte(x)       ((unsigned char)((x) >> 8))
  196. #define lobyte(x)       ((unsigned char)(x))
  197.   
  198. /* Extract nibbles from a byte */
  199. #define hinibble(x)     (((x) >> 4) & 0xf)
  200. #define lonibble(x)     ((x) & 0xf)
  201.   
  202. #ifdef UNIX
  203. /* Unix doesn't need x86 cruft */
  204. #define MK_FP(seg,off) ((void *) (seg))
  205. #define FP_SEG(p) (p)
  206. #endif
  207.   
  208. /* Various low-level and miscellaneous functions */
  209. #ifdef UNIX
  210. /* internal functions that must be hidden */
  211. #define alarm j_alarm
  212. #define pause j_pause
  213. #endif
  214. #ifdef LINUX
  215. int tcmdprintf __ARGS((FILE *,const char *,...));
  216. #endif
  217. unsigned long availmem __ARGS((void));
  218. void *callocw __ARGS((unsigned nelem,unsigned size));
  219. int32 clock __ARGS((void));
  220. int dirps __ARGS((void));
  221. #ifdef LINUX
  222. #define getopt j_getopt
  223. /* not sure how NOS will work with the GNU one... */
  224. #endif
  225. int getopt __ARGS((int argc,char *argv[],char *opts));
  226. int atoip __ARGS((char *));
  227. int htoi __ARGS((char *));
  228. long htol __ARGS((char *));
  229. char *inbuf __ARGS((int16 port,char *buf,int16 cnt));
  230. int16 hash_ip __ARGS((int32 addr));
  231. int istate __ARGS((void));
  232. void log __ARGS((int s,char *fmt, ...));
  233. void mail_error __ARGS((char *fmt, ...));
  234. int log2 __ARGS((int16 x));
  235. #ifdef UNIX
  236. #define ltop(l) ((void *) (l))
  237. #else
  238. void *ltop __ARGS((long));
  239. #endif
  240. void *mallocw __ARGS((unsigned nb));
  241. char *outbuf __ARGS((int16 port,char *buf,int16 cnt));
  242. #ifdef UNIX
  243. #define ptol(p) ((long)(p))
  244. #else
  245. long ptol __ARGS((void *));
  246. #endif
  247. void restore __ARGS((int));
  248. void rflush __ARGS((void));
  249. void rip __ARGS((char *));
  250. char *skipwhite __ARGS((char *));
  251. char *smsg __ARGS((char *msgs[],unsigned nmsgs,unsigned n));
  252. int tprintf __ARGS((char *fmt,...));
  253. int tputs __ARGS((char *s));
  254. int tputc __ARGS((char c));
  255. #if     !defined __TURBOC__
  256. char *strdup __ARGS((const char *));
  257. #endif
  258. int wildmat __ARGS((char *s,char *p,char **argv));
  259.   
  260. #ifdef  AZTEC
  261. #define rewind(fp)      fseek(fp,0L,0);
  262. #endif
  263.   
  264. #if     defined(__TURBOC__) && defined(MSDOS)
  265. #define movblock(so,ss,do,ds,c) movedata(ss,so,ds,do,c)
  266. #ifndef outportw
  267. #define outportw outport
  268. #endif
  269. #ifndef inportw
  270. #define inportw inport
  271. #endif
  272.   
  273. #else
  274.   
  275. /* General purpose function macros already defined in turbo C */
  276. #ifndef min
  277. #define min(x,y)        ((x)<(y)?(x):(y))       /* Lesser of two args */
  278. #endif
  279. #ifndef max
  280. #define max(x,y)        ((x)>(y)?(x):(y))       /* Greater of two args */
  281. #endif
  282. #ifdef  MSDOS
  283. #define MK_FP(seg,ofs)  ((void far *) \
  284. (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  285. #endif
  286. #endif  /* __TURBOC __ */
  287.   
  288. #ifdef  AMIGA
  289. /* super kludge de WA3YMH */
  290. #ifndef fileno
  291. #include <stdio.h>
  292. #endif
  293. #define fclose(fp)      amiga_fclose(fp)
  294. extern int amiga_fclose __ARGS((FILE *));
  295. extern FILE *tmpfile __ARGS((void));
  296.   
  297. extern char *sys_errlist[];
  298. extern int errno;
  299. #endif
  300.   
  301. /* Externals used by getopt */
  302. extern int optind;
  303. extern char *optarg;
  304.   
  305. /* Threshold setting on available memory */
  306. extern int32 Memthresh;
  307.   
  308. /* System clock - count of ticks since startup */
  309. extern int32 Clock;
  310.   
  311. /* Various useful standard error messages */
  312. extern char Badhost[];
  313. extern char Badinterface[];
  314. extern char Existingiface[];
  315. extern char Nospace[];
  316. extern char Notval[];
  317. extern char Version[];
  318. extern char Nosversion[];
  319. extern char TelnetMorePrompt[];
  320. extern char BbsMorePrompt[];
  321. extern char *Hostname;
  322.   
  323. /* Your system's end-of-line convention */
  324. extern char Eol[];
  325.   
  326. #ifndef LINUX
  327. extern void (*Gcollect[]) __ARGS((int));
  328. #endif
  329.   
  330. #ifdef UNIX
  331. /* PCs have a few pseudo-"standard" library functions used by NOS */
  332. extern char *stpcpy __ARGS((char *, const char *));
  333. extern char *strlwr __ARGS((char *));
  334. extern char *strupr __ARGS((char *));
  335. extern char *itoa __ARGS((int, char *, int));
  336. #endif
  337.   
  338. /* I know this is cheating, but it definitely makes sure that
  339.  * each module has config.h included ! - WG7J
  340.  */
  341. #ifndef _CONFIG_H
  342. #include "config.h"
  343. #endif
  344.   
  345. #ifdef LINUX
  346. #ifndef _LXTIME_H
  347. #include "lxtime.h"
  348. #endif
  349. #endif
  350.   
  351. /* in main.c  */
  352. void where_outta_here __ARGS((int resetme));
  353.   
  354. /* Stktrace.c */
  355. void stktrace __ARGS((void));
  356.   
  357. /* In alloc.c */
  358. unsigned long Localheap(void);
  359.   
  360. #endif  /* _GLOBAL_H */
  361.