home *** CD-ROM | disk | FTP | other *** search
- #ifndef CUTIL_LOADED
- #define CUTIL_LOADED
-
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h>
-
-
- #if !defined (TRUE)
- #define TRUE 1
- #endif
- #if !defined (FALSE)
- #define FALSE 0
- #endif
-
- #if !defined(MIN)
- #define MIN(a,b) (((a)<(b)) ? (a) : (b))
- #endif
- #if !defined(MAX)
- #define MAX(a,b) (((a)>(b)) ? (a) : (b))
- #endif
-
- #if !defined (BYTE)
- #define BYTE unsigned char
- #endif
- #if !defined (WORD)
- #define WORD unsigned int
- #endif
- #if !defined (LWORD)
- #define LWORD unsigned long int
- #endif
-
- #if !defined (BYTE_OF) /*requires Lvalue as operand*/
- #define BYTE_OF *(BYTE far *)&
- #endif
-
- #if !defined (WORD_OF) /*requires Lvalue as operand*/
- #define WORD_OF *(WORD far *)&
- #endif
-
- #if !defined (INT_OF)
- #define INT_OF *(INT far *)&
- #endif
-
- #if !defined (LO) /*returns LSB of variable as BYTE*/
- #define LO(x) *((BYTE *)&x)
- #endif
-
- #if !defined (HI) /*returns 2nd-LSB of variable as BYTE*/
- #define HI(x) *(((BYTE *)&x)+1)
- #endif
-
- #if !defined (LOWRD) /*returns LSW of variable as WORD*/
- #define LOWRD(x) *((WORD *)&x)
- #endif
-
- #if !defined (HIWRD) /*returns 2nd-LSW of variable as WORD*/
- #define HIWRD(x) *(((WORD *)&x)+1)
- #endif
-
- #define _upper(c) ( ((c)>='a')&&((c)<='z') ? ((c)-0x20) : (c) )
- #define _lower(c) ( ((c)>='A')&&((c)<='Z') ? ((c)+0x20) : (c) )
-
- #define HEX0(x) (_hextab[(x)&0x0F])
- #define HEX1(x) (_hextab[((x)>>4)&0x0F])
- #define HEX2(x) (_hextab[((x)>>8)&0x0F])
- #define HEX3(x) (_hextab[((x)>>12)&0x0F])
- #define HEXVAL(c) ( ((c)<'A') ? ((c)-'0') : (((c)<'a') ? ((c)-'A'+10) : ((c)-'a'+10)) )
-
- #define PSEP 2
- #define PARAMSEP 1
- #define NO_PARAMSEP 0
- #define NO_PSEP 0
-
- #define MAX_PARAMS 32
- #define COLOR_POINTER (WORD far *)0xB8000000L
- #define MONO_POINTER (WORD far *)0xB0000000L
-
- #define STR_LEN 256
-
-
- /****************************************************************************/
- /* ASCII control characters... */
- /****************************************************************************/
- #ifndef __ASCII
- #define __ASCII
- #define NUL 0x00 /*null character*/
- #define SOH 0x01 /*start of header*/
- #define STX 0x02 /*start of text*/
- #define ETX 0x03 /*end of text*/
- #define EOT 0x04 /*end of transmission*/
- #define ENQ 0x05 /*enquiry*/
- #define ACK 0x06 /*acknowledge*/
- #define BEL 0x07 /*bell, beep*/
- #define BS 0x08 /*backspace*/
- #define HT 0x09 /*horizontal tab*/
- #define TAB 0x09 /*horizontal tab, common name*/
- #define LF 0x0A /*linefeed*/
- #define VT 0x0B /*vertical tab*/
- #define FF 0x0C /*formfeed*/
- #define CR 0x0D /*carriage return, enter*/
- #define SO 0x0E /*shift out*/
- #define SI 0x0F /*shift in*/
- #define DC0 0x10 /*device control 0*/
- #define DLE 0x10 /*data link escape*/
- #define DC1 0x11 /*device control 1*/
- #define XON 0x11 /*transmit on*/
- #define DC2 0x12 /*device control 2*/
- #define DC3 0x13 /*device control 3*/
- #define XOFF 0x13 /*transmit off*/
- #define DC4 0x14 /*device control 4*/
- #define NAK 0x15 /*negative acknowledge*/
- #define SYN 0x16 /*synchronous idle*/
- #define ETB 0x17 /*end transmission block*/
- #define CAN 0x18 /*cancel*/
- #define EM 0x19 /*end of medium*/
- #define SUB 0x1A /*substitute*/
- #define ESC 0x1B /*escape*/
- #define FS 0x1C /*file separator*/
- #define GS 0x1D /*group separator*/
- #define RS 0x1E /*record separator*/
- #define US 0x1F /*unit separator*/
- #define SPC 0x20 /*space, blank*/
- #define DEL 0x7F /*delete character*/
- #endif /*if ascii not already defined*/
-
-
- /****************************************************************************/
- /* The following special keys are returned by the getkey() function. */
- /* The keys are simply the second (scan) code with 256 added. */
- /****************************************************************************/
- #ifndef __FKEYS
- #define __FKEYS
- #define A_ESC 0x0101
- #define A_1 0x0178
- #define A_2 0x0179
- #define A_3 0x017A
- #define A_4 0x017B
- #define A_5 0x017C
- #define A_6 0x017D
- #define A_7 0x017E
- #define A_8 0x017F
- #define A_9 0x0180
- #define A_0 0x0181
- #define A_MINUS 0x0182 /*0x010C?*/
- #define A_EQUAL 0x0183 /*0x010D?*/
- #define A_BS 0x010E
- #define S_TAB 0x010F
- #define A_Q 0x0110
- #define A_W 0x0111
- #define A_E 0x0112
- #define A_R 0x0113
- #define A_T 0x0114
- #define A_Y 0x0115
- #define A_U 0x0116
- #define A_I 0x0117
- #define A_O 0x0118
- #define A_P 0x0119
- #define A_LTBRKT 0x011A
- #define A_RTBRKT 0x011B
- #define A_ENTER 0x011C
- #define A_A 0x011E
- #define A_S 0x011F
- #define A_D 0x0120
- #define A_F 0x0121
- #define A_G 0x0122
- #define A_H 0x0123
- #define A_J 0x0124
- #define A_K 0x0125
- #define A_L 0x0126
- #define A_SEMICOL 0x0127
- #define A_QUOTE 0x0128
- #define A_TILDE 0x0129
- #define A_BSLASH 0x012B
- #define _F11 0x01D9
- #define _F12 0x01DA
- #define S_F11 0x0187
- #define S_F12 0x0188
- #define C_F11 0x0189
- #define C_F12 0x018A
- #define A_F11 0x018B
- #define A_F12 0x018C
- #define A_Z 0x012C
- #define A_X 0x012D
- #define A_C 0x012E
- #define A_V 0x012F
- #define A_B 0x0130
- #define A_N 0x0131
- #define A_M 0x0132
- #define A_COMMA 0x0133
- #define A_PERIOD 0x0134
- #define A_SLASH 0x0135
- #define A_TAB 0x01A5
-
- #define _F1 0x013B
- #define _F2 0x013C
- #define _F3 0x013D
- #define _F4 0x013E
- #define _F5 0x013F
- #define _F6 0x0140
- #define _F7 0x0141
- #define _F8 0x0142
- #define _F9 0x0143
- #define _F10 0x0144
- #define _HOME 0x0147
- #define _UPAR 0x0148
- #define _PGUP 0x0149
- #define _LTAR 0x014B
- #define _RTAR 0x014D
- #define _END 0x014F
- #define _DNAR 0x0150
- #define _PGDN 0x0151
- #define _INS 0x0152
- #define _DEL 0x0153
- #define S_F1 0x0154
- #define S_F2 0x0155
- #define S_F3 0x0156
- #define S_F4 0x0157
- #define S_F5 0x0158
- #define S_F6 0x0159
- #define S_F7 0x015A
- #define S_F8 0x015B
- #define S_F9 0x015C
- #define S_F10 0x015D
- #define C_F1 0x015E
- #define C_F2 0x015F
- #define C_F3 0x0160
- #define C_F4 0x0161
- #define C_F5 0x0162
- #define C_F6 0x0163
- #define C_F7 0x0164
- #define C_F8 0x0165
- #define C_F9 0x0166
- #define C_F10 0x0167
- #define A_F1 0x0168
- #define A_F2 0x0169
- #define A_F3 0x016A
- #define A_F4 0x016B
- #define A_F5 0x016C
- #define A_F6 0x016D
- #define A_F7 0x016E
- #define A_F8 0x016F
- #define A_F9 0x0170
- #define A_F10 0x0171
- #define C_PRTSC 0x0172
- #define C_LTAR 0x0173
- #define C_RTAR 0x0174
- #define C_END 0x0175
- #define C_PGDN 0x0176
- #define C_HOME 0x0177
- #define C_PGUP 0x0184 /*0x0178?*/
-
- #define C_A 0x01
- #define C_B 0x02
- #define C_C 0x03
- #define C_D 0x04
- #define C_E 0x05
- #define C_F 0x06
- #define C_G 0x07
- #define C_H 0x08
- #define C_I 0x09
- #define C_J 0x0A
- #define C_K 0x0B
- #define C_L 0x0C
- #define C_M 0x0D
- #define C_N 0x0E
- #define C_O 0x0F
- #define C_P 0x10
- #define C_Q 0x11
- #define C_R 0x12
- #define C_S 0x13
- #define C_T 0x14
- #define C_U 0x15
- #define C_V 0x16
- #define C_W 0x17
- #define C_X 0x18
- #define C_Y 0x19
- #define C_Z 0x1A
- #endif /*if keys not already defined*/
-
-
- /****************************************************************************/
- /* function protoypes... */
- /****************************************************************************/
-
- int strgetch(void);
- char* strdattim(WORD form); /*returns date/time string*/
- char* strsub(char *s,int pos,int len,char *t); /*returns t*/
- char* strNcpy(char* d,char* s,int n); /*force 0 at end of strncpy()*/
- int strisalnum(char *s); /*T/F*/
- int strcmpshort(char *s,char *t); /*-1 if s<t,0 if ==,1 if >*/
- int stricmpshort(char *s,char *t); /*-1 if s<t,0 if ==,1 if >*/
- char* strcompress(char* d,char* s,int n); /*returns d*/
- char* strcomment(char *s,char comchar); /*returns s*/
- char* strcchr(char* d,char* s); //points past C-char in source
- int strcstr(char *d,char *s,int n); /*returns chars in result*/
- int str2cchr(char* d,char c); //from char to C-char sequence
- int str2cstr(char* d,char *s,int maxn); //calls str2cchr() for string
- int strparse(char *s,int psep); //returns pnum
- char* strparam(char* d,int p,char* s); //returns d
- int strparamint(char* s,int p,int *ip); //1 if parsed to int
- int strparamsep(char* s); //puts \0 after each param
- int strmatch(char *m,char *s); /*matches, with wildcards*/
- int strasc2ul(char* s,unsigned long* ul,unsigned base);
- int strul2asc(char* s,unsigned long ul,unsigned base);
-
- /*these macros allow compatibility with the old strutil...*/
- #if STRUTIL_OLD
- #define getkey strgetch
- #define dattim(x) strdattim((x))
- #define sub_str(s,p,l,t) strsub((s),(p),(l),(t))
- #define white_char(c) isspace((c))
- #define alphanum_str(s) strisalnum((s))
- #define short_eq(s,t) (strcmpshort((s),(t))==0)
- #define shorti_eq(s,t) stricmpshort((s),(t))
- #define strip_white(s) strcompress((s),(s),0)
- #define strip_comment(s,c) strcomment((s),(c))
- #define c_chr_str(d,s) strcstr((d),(s),0)
- #define parse_str(s,sep) strparse((s),(sep))
- #define param_str(s,p,d) strparam((s),(p),(d))
- #define param_int(s,p,ip) strparamint((s),(p),(ip))
- #define param_sep(s) strparamsep((s))
- #endif
-
-
- /****************************************************************************/
- /* variable definitions... */
- /****************************************************************************/
- extern char *_hextab; /*for hex translations*/
- extern int pnum; //number of parameters parsed
- extern int ppos[]; //offset of each parameter
- extern int plen[]; //length of each parameter
-
-
-
- #endif /*if not already loaded*/
-