home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / text_cla / memincs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  6.8 KB  |  327 lines

  1. /***********************************************************************
  2. **+
  3. **  Module Name:  memincs.h
  4. **
  5. **  Description:  MEM specific defines
  6. **
  7. **  Include Modules Referenced:  None.
  8. **
  9. **  Written by:  John Tal
  10. **
  11. **
  12. **  Modification history:
  13. **
  14. **  Date         Engineer     Mod #          Modification Description
  15. **
  16. **  23-May-1991  Tal          v 1.0-001      Initial release
  17. **  01-May-1992  Tal          v 1.0-002      Windows compatible
  18. **-
  19. ***********************************************************************/
  20.  
  21.  
  22. #ifdef MEMINCS_H                 /* Allow compiler one copy */
  23. #else
  24. #define MEMINCS_H
  25.  
  26. /*
  27. **   APIENTRY is used by Microsoft Windows and OS/2
  28. **   just make null if not already defined
  29. */
  30.  
  31. #ifndef APIENTRY
  32. #define APIENTRY
  33. #endif
  34.  
  35.  
  36. /*
  37. **  Take care of our friend NULL
  38. */
  39.  
  40.  
  41. #ifndef NULL
  42. #define NULL  0
  43. #endif
  44.  
  45.  
  46. /*  
  47. **   Implementation independent types
  48. **   From OS/2, Windows, use SHORT in code instead of short
  49. */
  50.  
  51. #ifndef SHORT
  52. typedef  short    SHORT;
  53. #endif
  54. typedef  SHORT *  PSHORT;
  55. #ifndef LONG
  56. typedef  long     LONG;
  57. #endif
  58. #ifndef PLONG
  59. #ifndef _INC_WINDOWS
  60. typedef  LONG  *  PLONG;
  61. #endif
  62. #endif
  63. #ifndef INT
  64. typedef  int      INT;
  65. #endif
  66. #ifndef PINT
  67. #ifndef _INC_WINDOWS
  68. typedef  INT   *  PINT;
  69. #endif
  70. #endif
  71. #ifndef USHORT
  72. typedef  unsigned short  USHORT;
  73. #endif
  74. #ifndef PUSHORT
  75. typedef  USHORT * PUSHORT;
  76. #endif
  77. #ifndef ULONG
  78. typedef  unsigned long   ULONG;
  79. #endif
  80. #ifndef PULONG
  81. typedef  ULONG *  PULONG;
  82. #endif
  83. #ifndef CHAR
  84. typedef  char     CHAR;
  85. #endif
  86. #ifndef PCHAR
  87. typedef  char *   PCHAR;
  88. #endif
  89. #ifndef UCHAR
  90. typedef  unsigned char  UCHAR;
  91. #endif
  92. #ifndef FLOAT
  93. typedef  float    FLOAT;
  94. #endif
  95. #ifndef DOUBLE
  96. typedef  double   DOUBLE;
  97. #endif
  98. #ifndef BYTE
  99. typedef  unsigned char  BYTE;
  100. #endif
  101. #ifndef PBYTE
  102. #ifndef _INC_WINDOWS
  103. typedef  unsigned char * PBYTE;
  104. #endif
  105. #endif
  106. #ifndef VOID
  107. typedef  void     VOID;
  108. #endif
  109. #ifndef PVOID
  110. typedef  void *   PVOID;
  111. #endif
  112. #ifndef PPVOID
  113. typedef  void **  PPVOID;
  114. #endif
  115. #ifndef BOOL
  116. #ifndef _INC_WINDOWS
  117. typedef  unsigned char  BOOL;
  118. #endif
  119. #endif
  120.  
  121.  
  122.  
  123. /*
  124. **  EVERYTHING below this point should start with C_
  125. */
  126.  
  127. /*
  128. **  Standard function return codes
  129. */
  130.  
  131.  
  132. #define C_OK              0               /* Good condition code */
  133. #define C_NOTOK           -1              /* Bad condition code  */
  134. #define C_PARTIAL_RESP    1               /* Partial Response    */
  135.  
  136. /*
  137. **  Logical types
  138. */
  139.  
  140. #define  C_NOTHING (0)          /*  Initialization value */
  141. #define  C_TRUE (1)             /*  Boolean TRUE */
  142. #define  C_FALSE (0)            /*  Boolean FALSE */
  143.  
  144. #define  C_ZERO (0)     
  145.  
  146. #define  C_HIGHER (1)           /*  memcmp, strcmp results */
  147. #define  C_EQUAL  (0)           /*   "   */
  148. #define  C_LOWER  (-1)          /*   "   */
  149.  
  150.  
  151. #define  C_PRE_ORDER  -1
  152. #define  C_IN_ORDER    0
  153. #define  C_POST_ORDER  1
  154.  
  155.  
  156. /*
  157. **  Generic object or action codes 
  158. */
  159.  
  160. #define  C_PARENT   1
  161. #define  C_CHILD    2
  162. #define  C_CLONE    3
  163.  
  164. /*
  165. **  Procedural commands, state change requests
  166. */
  167.  
  168. #define  C_START    4
  169. #define  C_STOP     5
  170. #define  C_CREATE   7
  171. #define  C_DESTROY  8
  172. #define  C_INIT     9
  173. #define  C_SHUTDOWN  (4321)
  174.  
  175. /*
  176. **  States   (of processes, communication lines, sessions, data, etc.)
  177. */
  178.  
  179.  
  180. #define  C_UNKNOWN  12
  181. #define  C_ERROR    13
  182. #define  C_LOST     14
  183. #define  C_MIA      15   /* data missing in action */
  184. #define  C_RETRY    16
  185. #define  C_LIVE     17
  186. #define  C_DEAD     18
  187.  
  188. #define  C_COMPLETE    19
  189. #define  C_INCOMPLETE  20
  190.  
  191. #define  C_NULL_CHAR  '\0'     /*  NULL character */
  192.  
  193. /*
  194. **   Heap 
  195. */
  196.  
  197. #define C_HEAP_EMPTY  -1
  198. #define C_HEAP_TOP    0
  199.  
  200.  
  201. #define C_FREE(ptr) \
  202. { \
  203. if((ptr) != NULL) \
  204. { \
  205.    free(ptr); \
  206.    (ptr) = NULL; \
  207. } \
  208. }
  209.  
  210.  
  211. #define C_CNVT_NULLS_TO_SPCS(pointer, bufsize) \
  212. { \
  213. PCHAR pcharIndex; \
  214. USHORT ushortCount; \
  215. for (pcharIndex = (PCHAR)pointer,  \
  216.      ushortCount = 0;              \
  217.      ushortCount < bufsize;        \
  218.      ushortCount++,                \
  219.      pcharIndex++                  \
  220.     )                              \
  221.   if (*pcharIndex == '\0')    \
  222.     *pcharIndex = ' ';     \
  223. }
  224.  
  225.  
  226. /*
  227. ** Macro to trim out all leading and trailing blanks in a string.
  228. ** Usage C_TRIM_SPCS(pointer)
  229. ** Where pointer = buffer to be trimmed
  230. **
  231. **  Note that the string is shortened by the number of blanks removed
  232. */
  233.  
  234. #define C_TRIM_SPCS(pointer) \
  235. { \
  236. SHORT shortStrlen; \
  237. while (pointer[0] == ' ') \
  238. { \
  239.   shortStrlen = strlen(pointer); \
  240.   memmove (&pointer[0], &pointer[1], shortStrlen-1); \
  241.   pointer[shortStrlen-1] = ' '; \
  242. }  \
  243. shortStrlen = strlen(pointer); \
  244. while (pointer[shortStrlen-1] == ' ') \
  245. { \
  246.   pointer[shortStrlen-1] = '\0'; \
  247.   shortStrlen--; \
  248. } \
  249. }
  250.  
  251.  
  252.  
  253.  
  254. /*
  255. **   The following macro, C_LEAVE is used when you want to leave the
  256. **   current module.   It does a goto to the label in your module
  257. **   C_MODULE_EXIT.
  258. **
  259. **   Yes, gotos have been abused but to say you aren't going to use
  260. **   a single one is overly-idealistic.   With no goto, you end up 
  261. **   with code with high cyclomatic complexit (cf. McCabe and Software 
  262. **   Metrics) and which is difficult to maintain.  (Not to mention 
  263. **   having to document    and try and match all those close } brackets 
  264. **   which appear together.
  265. **                                   }
  266. **                                 }
  267. **                              }
  268. **                           }
  269. **
  270. **   What you want to do is try an operation, if it fails and you have
  271. **   no reason to continue processing in that module, GET OUT!
  272. **   
  273. **   The goto is masked in the C_LEAVE macro so you can still have a
  274. **   coding standard that says "do not use 'goto'".   Having a goto
  275. **   is much easier than trying and operation and nesting to another
  276. **   level of if()  ad infinitum.
  277. **
  278. **
  279. */
  280.  
  281. #define  C_LEAVE(stat)  {C_STATUS = stat; goto C_MODULE_EXIT;}
  282.  
  283. #define  C_CHECK_STATUS(stat) {if(stat) goto C_MODULE_EXIT;}
  284. #define  C_IF_STATUS {if(C_STATUS) goto C_MODULE_EXIT;}
  285.  
  286. /*
  287. **   Return function from module
  288. */
  289.  
  290. #define   C_RETURN  return(C_STATUS);
  291.  
  292. #define   C_SET_STATUS(stat) C_STATUS = stat;
  293.  
  294. /*
  295. **   C_DEF_MODULE = Module Initialization, sets name of current module
  296. **
  297. **   Provided for debugging and logging
  298. **  
  299. **
  300. **   usage
  301. **
  302. **   SHORT APIENTRY
  303. **   SomeModule(APP_WORK_AREA_P  pstWorkArea, other parms)
  304. **   {
  305. **       C_DEF_MODULE("SomeModule  SM.C")
  306. **
  307. **       variable definitions
  308. **
  309. **       module code
  310. **
  311. **       if(error)
  312. **         C_LEAVE(errorcode)
  313. **
  314. **       more module code
  315. **
  316. **    C_MODULE_EXIT:   (* <-  label you provide *)
  317. **
  318. **       C_RETURN
  319. **   }
  320. */
  321.  
  322. #define   C_DEF_MODULE(modn)  static CHAR C_MODULE[] = modn; SHORT C_STATUS = C_OK;
  323.  
  324. #define   C_MODULE_NAME  C_MODULE
  325.  
  326. #endif /* MEMINCS_H */
  327.