home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- **+
- ** Module Name: memincs.h
- **
- ** Description: MEM specific defines
- **
- ** Include Modules Referenced: None.
- **
- ** Written by: John Tal
- **
- **
- ** Modification history:
- **
- ** Date Engineer Mod # Modification Description
- **
- ** 23-May-1991 Tal v 1.0-001 Initial release
- ** 01-May-1992 Tal v 1.0-002 Windows compatible
- **-
- ***********************************************************************/
-
-
- #ifdef MEMINCS_H /* Allow compiler one copy */
- #else
- #define MEMINCS_H
-
- /*
- ** APIENTRY is used by Microsoft Windows and OS/2
- ** just make null if not already defined
- */
-
- #ifndef APIENTRY
- #define APIENTRY
- #endif
-
-
- /*
- ** Take care of our friend NULL
- */
-
-
- #ifndef NULL
- #define NULL 0
- #endif
-
-
- /*
- ** Implementation independent types
- ** From OS/2, Windows, use SHORT in code instead of short
- */
-
- #ifndef SHORT
- typedef short SHORT;
- #endif
- typedef SHORT * PSHORT;
- #ifndef LONG
- typedef long LONG;
- #endif
- #ifndef PLONG
- #ifndef _INC_WINDOWS
- typedef LONG * PLONG;
- #endif
- #endif
- #ifndef INT
- typedef int INT;
- #endif
- #ifndef PINT
- #ifndef _INC_WINDOWS
- typedef INT * PINT;
- #endif
- #endif
- #ifndef USHORT
- typedef unsigned short USHORT;
- #endif
- #ifndef PUSHORT
- typedef USHORT * PUSHORT;
- #endif
- #ifndef ULONG
- typedef unsigned long ULONG;
- #endif
- #ifndef PULONG
- typedef ULONG * PULONG;
- #endif
- #ifndef CHAR
- typedef char CHAR;
- #endif
- #ifndef PCHAR
- typedef char * PCHAR;
- #endif
- #ifndef UCHAR
- typedef unsigned char UCHAR;
- #endif
- #ifndef FLOAT
- typedef float FLOAT;
- #endif
- #ifndef DOUBLE
- typedef double DOUBLE;
- #endif
- #ifndef BYTE
- typedef unsigned char BYTE;
- #endif
- #ifndef PBYTE
- #ifndef _INC_WINDOWS
- typedef unsigned char * PBYTE;
- #endif
- #endif
- #ifndef VOID
- typedef void VOID;
- #endif
- #ifndef PVOID
- typedef void * PVOID;
- #endif
- #ifndef PPVOID
- typedef void ** PPVOID;
- #endif
- #ifndef BOOL
- #ifndef _INC_WINDOWS
- typedef unsigned char BOOL;
- #endif
- #endif
-
-
-
- /*
- ** EVERYTHING below this point should start with C_
- */
-
- /*
- ** Standard function return codes
- */
-
-
- #define C_OK 0 /* Good condition code */
- #define C_NOTOK -1 /* Bad condition code */
- #define C_PARTIAL_RESP 1 /* Partial Response */
-
- /*
- ** Logical types
- */
-
- #define C_NOTHING (0) /* Initialization value */
- #define C_TRUE (1) /* Boolean TRUE */
- #define C_FALSE (0) /* Boolean FALSE */
-
- #define C_ZERO (0)
-
- #define C_HIGHER (1) /* memcmp, strcmp results */
- #define C_EQUAL (0) /* " */
- #define C_LOWER (-1) /* " */
-
-
- #define C_PRE_ORDER -1
- #define C_IN_ORDER 0
- #define C_POST_ORDER 1
-
-
- /*
- ** Generic object or action codes
- */
-
- #define C_PARENT 1
- #define C_CHILD 2
- #define C_CLONE 3
-
- /*
- ** Procedural commands, state change requests
- */
-
- #define C_START 4
- #define C_STOP 5
- #define C_CREATE 7
- #define C_DESTROY 8
- #define C_INIT 9
- #define C_SHUTDOWN (4321)
-
- /*
- ** States (of processes, communication lines, sessions, data, etc.)
- */
-
-
- #define C_UNKNOWN 12
- #define C_ERROR 13
- #define C_LOST 14
- #define C_MIA 15 /* data missing in action */
- #define C_RETRY 16
- #define C_LIVE 17
- #define C_DEAD 18
-
- #define C_COMPLETE 19
- #define C_INCOMPLETE 20
-
- #define C_NULL_CHAR '\0' /* NULL character */
-
- /*
- ** Heap
- */
-
- #define C_HEAP_EMPTY -1
- #define C_HEAP_TOP 0
-
-
- #define C_FREE(ptr) \
- { \
- if((ptr) != NULL) \
- { \
- free(ptr); \
- (ptr) = NULL; \
- } \
- }
-
-
- #define C_CNVT_NULLS_TO_SPCS(pointer, bufsize) \
- { \
- PCHAR pcharIndex; \
- USHORT ushortCount; \
- for (pcharIndex = (PCHAR)pointer, \
- ushortCount = 0; \
- ushortCount < bufsize; \
- ushortCount++, \
- pcharIndex++ \
- ) \
- if (*pcharIndex == '\0') \
- *pcharIndex = ' '; \
- }
-
-
- /*
- ** Macro to trim out all leading and trailing blanks in a string.
- ** Usage C_TRIM_SPCS(pointer)
- ** Where pointer = buffer to be trimmed
- **
- ** Note that the string is shortened by the number of blanks removed
- */
-
- #define C_TRIM_SPCS(pointer) \
- { \
- SHORT shortStrlen; \
- while (pointer[0] == ' ') \
- { \
- shortStrlen = strlen(pointer); \
- memmove (&pointer[0], &pointer[1], shortStrlen-1); \
- pointer[shortStrlen-1] = ' '; \
- } \
- shortStrlen = strlen(pointer); \
- while (pointer[shortStrlen-1] == ' ') \
- { \
- pointer[shortStrlen-1] = '\0'; \
- shortStrlen--; \
- } \
- }
-
-
-
-
- /*
- ** The following macro, C_LEAVE is used when you want to leave the
- ** current module. It does a goto to the label in your module
- ** C_MODULE_EXIT.
- **
- ** Yes, gotos have been abused but to say you aren't going to use
- ** a single one is overly-idealistic. With no goto, you end up
- ** with code with high cyclomatic complexit (cf. McCabe and Software
- ** Metrics) and which is difficult to maintain. (Not to mention
- ** having to document and try and match all those close } brackets
- ** which appear together.
- ** }
- ** }
- ** }
- ** }
- **
- ** What you want to do is try an operation, if it fails and you have
- ** no reason to continue processing in that module, GET OUT!
- **
- ** The goto is masked in the C_LEAVE macro so you can still have a
- ** coding standard that says "do not use 'goto'". Having a goto
- ** is much easier than trying and operation and nesting to another
- ** level of if() ad infinitum.
- **
- **
- */
-
- #define C_LEAVE(stat) {C_STATUS = stat; goto C_MODULE_EXIT;}
-
- #define C_CHECK_STATUS(stat) {if(stat) goto C_MODULE_EXIT;}
- #define C_IF_STATUS {if(C_STATUS) goto C_MODULE_EXIT;}
-
- /*
- ** Return function from module
- */
-
- #define C_RETURN return(C_STATUS);
-
- #define C_SET_STATUS(stat) C_STATUS = stat;
-
- /*
- ** C_DEF_MODULE = Module Initialization, sets name of current module
- **
- ** Provided for debugging and logging
- **
- **
- ** usage
- **
- ** SHORT APIENTRY
- ** SomeModule(APP_WORK_AREA_P pstWorkArea, other parms)
- ** {
- ** C_DEF_MODULE("SomeModule SM.C")
- **
- ** variable definitions
- **
- ** module code
- **
- ** if(error)
- ** C_LEAVE(errorcode)
- **
- ** more module code
- **
- ** C_MODULE_EXIT: (* <- label you provide *)
- **
- ** C_RETURN
- ** }
- */
-
- #define C_DEF_MODULE(modn) static CHAR C_MODULE[] = modn; SHORT C_STATUS = C_OK;
-
- #define C_MODULE_NAME C_MODULE
-
- #endif /* MEMINCS_H */