home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games (Alt) / INFESPGAMES.iso / os2 / backgam / source / util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-07  |  4.8 KB  |  146 lines

  1. /*************************************************************
  2.  *    ______                                                 *
  3.  *   /     /\  TinyFugue was derived from a client initially *
  4.  *  /   __/  \ written by Anton Rang (Tarrant) and later     *
  5.  *  |  / /\  | modified by Leo Plotkin (Grod).  The early    *
  6.  *  |  |/    | versions of TinyFugue written by Greg Hudson  *
  7.  *  |  X__/  | (Explorer_Bob).  The current version is       *
  8.  *  \ /      / written and maintained by Ken Keys (Hawkeye), *
  9.  *   \______/  who can be reached at kkeys@ucsd.edu.         *
  10.  *                                                           *
  11.  *             No copyright 1992, no rights reserved.        *
  12.  *             Fugue is in the public domain.                *
  13.  *************************************************************/
  14.  
  15. #ifdef STANDARD_C_YES_SIREE
  16. # include <stdarg.h>
  17. #else
  18. # include <varargs.h>
  19. #endif
  20.  
  21. #ifndef BSD
  22. # include <string.h>
  23. # define bcopy(src, dst, len) memcpy((dst), (src), (len))
  24. #else
  25. # ifdef __GNUC__
  26. extern char *strchr(), *strrchr();
  27. # else
  28. #  include <strings.h>
  29. #  ifndef STANDARD_C_YES_SIREE
  30. #   define strchr(x, y) index((x), (y))
  31. #   define strrchr(x, y) rindex((x), (y))
  32. #  endif
  33. # endif
  34. #endif
  35.  
  36. extern int errno;
  37. #ifndef STANDARD_C_YES_SIREE
  38. #define _ERRLIST
  39. #endif
  40. #ifdef __GNUC__
  41. #define _ERRLIST
  42. #endif
  43. #ifdef _ERRLIST
  44. extern int sys_nerr;
  45. extern const char * const sys_errlist[];
  46. #define STRERROR(n) (((n) > 0 && (n) < sys_nerr) ? sys_errlist[(n)] : \
  47.     "unknown error")
  48. #endif
  49.  
  50. #ifdef _STRSTR
  51. #define STRSTR(s1, s2) tf_strstr((s1), (s2))
  52. #else
  53. #define STRSTR(s1, s2) strstr((s1), (s2))
  54. #endif
  55.  
  56. #ifdef DMALLOC
  57. #define MALLOC(size) dmalloc((size), __FILE__, __LINE__)
  58. #define REALLOC(ptr, size) drealloc((ptr), (size), __FILE__, __LINE__)
  59. #define FREE(ptr) dfree((char*)(ptr), __FILE__, __LINE__)
  60. #else
  61. #define MALLOC(size) dmalloc((size))
  62. #define REALLOC(ptr, size) drealloc((ptr), (size))
  63. #define FREE(ptr) free((char*)(ptr))
  64. #endif
  65.  
  66. #ifdef DMALLOC
  67. # define STRDUP(src, file, line) \
  68.     (strcpy(MALLOC(strlen(src) + 1, (file), (line)), (src)))
  69. #else
  70. # define STRDUP(src) (strcpy(MALLOC(strlen(src) + 1), (src)))
  71. #endif
  72.  
  73. extern char lowercase_values[128], uppercase_values[128];
  74. #define lcase(x) (lowercase_values[(x)])
  75. #define ucase(x) (uppercase_values[(x)])
  76.  
  77. typedef struct Aline {
  78.     char *str;
  79.     short links, attrs;
  80. } Aline;                       /* shared line, with attributes */
  81.  
  82. typedef struct TFILE {
  83.     FILE *fp;
  84.     int ispipe;
  85.     char *name;
  86. } TFILE;                       /* file or pipe with standard i/o */
  87.  
  88. #include <errno.h>
  89.  
  90. #define operror(str) (oprintf("%s: %s", str, STRERROR(errno)))
  91. #define equalstr(s, t) (!smatch((s), (t)))
  92. #define tfgetS(S, file) fgetS((S), (file)->fp)
  93. #define tfputs(s, file) fputs((s), (file)->fp)
  94. #define tfputc(c, file) fputc((c), (file)->fp)
  95. #define tfflush(file) fflush((file)->fp)
  96. #define tfjump(file, offset) \
  97.     ((file)->ispipe ? \
  98.         pipejump((file), (offset)) : \
  99.         fseek((file)->fp, (offset), 0))
  100. #define tfclose(file) \
  101.     do { \
  102.         file->ispipe ? pclose(file->fp) : fclose(file->fp);\
  103.         FREE(file->name);\
  104.         FREE(file);\
  105.     } while (0)
  106.  
  107. extern void  NDECL(init_table);
  108. extern TFILE *FDECL(tfopen,(char *fname, char *dname, char *mode));
  109. extern int    FDECL(pipejump,(TFILE *file, long offset));
  110. #ifdef DMALLOC
  111. extern char *FDECL(dmalloc,(long unsigned size, char *file, int line));
  112. extern char *FDECL(drealloc,(char *ptr, long unsigned size, char *file, int line));
  113. extern void  FDECL(dfree,(char *ptr, char *file, int line));
  114. #else
  115. extern char *FDECL(dmalloc,(long unsigned size));
  116. extern char *FDECL(drealloc,(char *ptr, long unsigned size));
  117. #endif
  118. extern char *FDECL(cstrchr,(char *s, int c));
  119. extern char *FDECL(estrchr,(char *s, int c, int e));
  120. extern int   FDECL(cstrcmp,(char *s, char *t));
  121. extern int   FDECL(cstrncmp,(char *s, char *t, int n));
  122. #ifdef _STRSTR
  123. extern char *FDECL(tf_strstr,(char *s1, char *s2));
  124. #endif
  125. extern int   FDECL(numarg,(char **str));
  126. extern int   FDECL(smatch,(char *s, char *t));
  127. extern int   FDECL(smatch_check,(char *s));
  128. extern char *FDECL(stripstr,(char *s));
  129. extern void  FDECL(vSprintf,(Stringp buf, char *fmt, va_list ap));
  130. extern void  VDECL(oprintf,(char *fmt, ...));
  131. extern void  VDECL(Sprintf,(Stringp buf, char *fmt, ...));
  132. extern char  NDECL(getch);
  133. extern void  FDECL(startopt,(char *args, char *opts));
  134. extern char  FDECL(nextopt,(char **arg, int *num));
  135. #ifdef DMALLOC
  136. extern Aline *FDECL(dnew_aline,(char *str, int attrs, char *file, int line));
  137. #else
  138. extern Aline *FDECL(new_aline,(char *str, int attrs));
  139. #endif
  140. extern void  FDECL(free_aline,(Aline *aline));
  141. #ifdef MAILDELAY
  142. extern void  NDECL(check_mail);
  143. #endif
  144. extern void  NDECL(cleanup);
  145. extern void  FDECL(die,(char *why));
  146.