home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Xconq 7.1.0 / src / xconq-7.1.0 / kernel / misc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  3.8 KB  |  159 lines  |  [TEXT/R*ch]

  1. /* Random definitions used everywhere in Xconq.
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996
  3.    Stanley T. Shebs.
  4.  
  5. Xconq is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.  See the file COPYING.  */
  9.  
  10. #ifndef TRUE
  11. #define TRUE (1)
  12. #endif
  13. #ifndef FALSE
  14. #define FALSE (0)
  15. #endif
  16.  
  17. /* This is how we do optional prototypes and const decls. */
  18.  
  19. #ifdef MSDOS
  20. #define PARAMS(ARGS) ARGS
  21. #define CONST const
  22. #endif
  23.  
  24. #ifndef PARAMS
  25. #ifdef ANSI_PROTOTYPES
  26. #define PARAMS(ARGS) ARGS
  27. #else
  28. #define PARAMS(ARGS) ()
  29. #endif /* ANSI_PROTOTYPES */
  30. #endif /* PARAMS */
  31.  
  32. #ifndef CONST
  33. #ifdef __STDC__
  34. #define CONST const
  35. #else
  36. #define CONST
  37. #endif /* __STDC__ */
  38. #endif /* CONST */
  39.  
  40. #ifndef ABS
  41. #define ABS(x) (((x) < 0) ? (0 - (x)) : (x))
  42. #endif
  43.  
  44. #ifndef min
  45. #define min(x,y) (((x) < (y)) ? (x) : (y))
  46. #endif
  47.  
  48. #ifndef max
  49. #define max(x,y) (((x) > (y)) ? (x) : (y))
  50. #endif
  51.  
  52. #define between(lo,n,hi) ((lo) <= (n) && (n) <= (hi))
  53.  
  54. #define flip_coin() (xrandom(257) % 2)
  55.  
  56. #define avg(a,b) (((a) + (b)) / 2)
  57.  
  58. #ifndef isspace
  59. #define isspace(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
  60. #endif
  61.  
  62. #define lowercase(c) (isupper(c) ? tolower(c) : (c))
  63.  
  64. #define uppercase(c) (islower(c) ? toupper(c) : (c))
  65.  
  66. /* This tests a string to see if it has anything in it. */
  67.  
  68. #define empty_string(s) ((s) == NULL || s[0] == '\0')
  69.  
  70. extern char spbuf[];
  71. extern char tmpbuf[];
  72.  
  73. #ifdef DEBUGGING
  74.  
  75. /* Debugging definitions. */
  76.  
  77. #define Dprintf if (Debug && dfp) debug_printf
  78. #define DMprintf if (DebugM && dmfp) debugm_printf
  79. #define DGprintf if (DebugG && dgfp) debugg_printf
  80.  
  81. #define Dprintlisp(X) if (Debug && dfp) fprintlisp(dfp, (X))
  82. #define DMprintlisp(X) if (DebugM && dmfp) fprintlisp(dmfp, (X))
  83. #define DGprintlisp(X) if (DebugG && dgfp) fprintlisp(dgfp, (X))
  84.  
  85. /* If the debug flags are not macros, then declare them as globals. */
  86.  
  87. #ifndef Debug
  88. extern int Debug;
  89. #endif
  90. #ifndef DebugM
  91. extern int DebugM;
  92. #endif
  93. #ifndef DebugG
  94. extern int DebugG;
  95. #endif
  96.  
  97. extern FILE *dfp;
  98. extern FILE *dmfp;
  99. extern FILE *dgfp;
  100.  
  101. #else /* DEBUGGING */
  102.  
  103. /* Make defns and calls vanish if possible. */
  104.  
  105. #define Dprintf if (0) debug_printf
  106. #define DMprintf if (0) debugm_printf
  107. #define DGprintf if (0) debugg_printf
  108.  
  109. #define Dprintlisp(X)
  110. #define DMprintlisp(X)
  111. #define DGprintlisp(X)
  112.  
  113. #define Debug (0)
  114. #define DebugM (0)
  115. #define DebugG (0)
  116.  
  117. #define dfp stdout
  118. #define dmfp stdout
  119. #define dgfp stdout
  120.  
  121. #endif /* DEBUGGING */
  122.  
  123. typedef struct a_library_path {
  124.     char *path;
  125.     struct a_library_path *next;
  126. } LibraryPath;
  127.  
  128. #define for_all_library_paths(p)  \
  129.   for (p = xconq_libs; p != NULL; p = p->next)
  130.  
  131. extern LibraryPath *xconq_libs;
  132. extern LibraryPath *last_user_xconq_lib;
  133.  
  134. extern char *getenv();
  135.  
  136. extern void init_xrandom PARAMS ((int seed));
  137. extern int xrandom PARAMS ((int m));
  138. extern int probability PARAMS ((int prob));
  139. extern int roll_dice PARAMS ((int n));
  140. extern int multiply_dice PARAMS ((int dice, int mult));
  141. extern int prob_fraction PARAMS ((int n));
  142.  
  143. extern char *xmalloc PARAMS ((int amt));
  144. extern void report_malloc PARAMS ((void));
  145. extern void tprintf PARAMS ((char *buf, char *str, ...));
  146. extern void tnprintf PARAMS ((char *buf, int n, char *str, ...));
  147. extern char *copy_string PARAMS ((char *str));
  148. extern char *pad_blanks PARAMS ((char *str, int n));
  149. extern int iindex PARAMS ((int ch, char *str));
  150. extern long idifftime PARAMS ((time_t t1, time_t t0));
  151. extern void case_panic PARAMS ((char *str, int var));
  152. extern int isqrt PARAMS ((int i));
  153. extern void init_debug_to_stdout PARAMS ((void));
  154. extern void debug_printf PARAMS ((char *str, ...));
  155. extern void debugm_printf PARAMS ((char *str, ...));
  156. extern void debugg_printf PARAMS ((char *str, ...));
  157.  
  158. extern void vtprintf PARAMS ((char *buf, char *str, va_list ap));
  159.