home *** CD-ROM | disk | FTP | other *** search
-
-
-
- /*
- * TPCMAC.H - Macro Header for use with Turbo Pascal --> C Translator
- *
- * S.H.Smith, 22-Dec-86 (rev. 05-Aug-87)
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdarg.h>
- #include <dos.h>
- #include <conio.h>
- #include <ctype.h>
-
-
- /* define some simple keyword replacements */
-
- #define keypressed kbhit()
- #define wherex wherex()
- #define wherey wherey()
- #define memavail memavail()
- #define maxavail maxavail()
- #define maxint 0x7fff
-
- #define dispose(v) free(v)
- #define pred(v) ((v)-1)
- #define succ(v) ((v)+1)
- #define sqr(v) ((v)*(v))
- #define chr(n) (n)
- #define ord(c) (c)
- #define lo(v) (v & 0xff)
- #define hi(v) (v >> 8)
-
- #define integer int
- #define byte char
- #define real double
- #define boolean int
-
- #define false 0
- #define true 1
- #define nil NULL
-
- typedef FILE *text;
-
- #define kbd stdin
- #define input stdin
- #define con stdout
- #define output stdout
-
- #define eof(fd) feof(fd)
- #define flush(fd) fflush(fd)
- #define assign(fd,name) strcpy(_CURNAME,name)
- #define reset(fd) ioresult = (( (fd = fopen(_CURNAME,"r")) == 0))
- #define rewrite(fd) ioresult = (( (fd = fopen(_CURNAME,"w")) == 0))
- #define close(fd) ioresult = fclose(fd)
-
- #define upcase(c) toupper(c)
- #define length(s) strlen(s)
-
- #define delete(s,p,num) strcpy(s+p-1,s+p+num)
- #define val(s,res,code) code=0, res=atof(s)
- #define str(val,res) strcpy(res,ftoa((double)val));
-
- typedef char *string;
- #define STRSIZ 255 /* default string length */
-
-
-
-
- /*
- * setof(a,b,...,-1)
- * construct and return a set of the specified character values
- *
- * inset(ex,set)
- * predicate returns true if expression ex is a member of
- * the set parameter
- *
- */
- #define THRU -2
- #define ENDSET -1
-
-
-
-
- /*
- * copy len bytes from the dynamic string dstr starting at position from
- *
- */
- string copy(string str,
- int from,
- int len)
- {
- static char buf[STRSIZ];
- buf[0]=0;
- if (from>strlen(str)) /* copy past end gives null string */
- return buf;
-
- strcpy(buf,str+from-1); /* skip over first part of string */
- buf[len] = 0; /* truncate after len characters */
- return buf;
- }
-
-
- /*
- * String/character concatenation function
- *
- * This function takes a sprintf-like control string, a variable number of
- * parameters, and returns a pointer a static location where the processed
- * string is to be stored.
- *
- */
-
- string scat(string control, ...)
- {
- static char buf[STRSIZ];
- char buf2[STRSIZ];
- va_list args;
-
- va_start(args, control); /* get variable arg pointer */
- vsprintf(buf2,control,args); /* format into buf with variable args */
- va_end(args); /* finish the arglist */
-
- strcpy(buf,buf2);
- return buf; /* return a pointer to the string */
- }
-
-
- #define ctos(ch) scat("%c",ch) /* character to string conversion */
-
-
- /*
- * string build - like scat, sprintf, but will not over-write any
- * input parameters
- */
-
- int sbld(string dest,
- string control, ...)
- {
- char buf[STRSIZ];
- va_list args;
-
- va_start(args, control); /* get variable arg pointer */
- vsprintf(buf,control,args); /* format into buf with variable args */
- va_end(args); /* finish the arglist */
-
- strcpy(dest,buf); /* copy result */
- }
-
-
-
- /*
- * spos(str1,str2) - returns index of first occurence of str1 within str2;
- * 1=first char of str2
- * 0=nomatch
- */
-
- int spos(string str1,
- string str2)
- {
- string res;
- res = strstr(str2,str1);
- if (res == NULL)
- return 0;
- else
- return res - str2 + 1;
- }
-
-
- /*
- * cpos(str1,str2) - returns index of first occurence of c within str2;
- * 1=first char of str2
- * 0=nomatch
- */
-
- int cpos(char c,
- string str2)
- {
- string res;
- res = strchr(str2,c);
- if (res == NULL)
- return 0;
- else
- return res - str2 + 1;
- }
-
-
-
- /*
- * Scanf/Fscanf support
- *
- * These functions operate like scanf and fscanf except for an added control
- * code used for full-line reads.
- *
- */
-
- int fscanv(text fd,
- string control, ...)
- {
- va_list args;
- string arg1;
- int i;
-
- va_start(args, control); /* get variable arg pointer */
-
- /* process special case for full-line reads (why doesn't scanf allow
- full-line string reads? why don't gets and fgets work the same?) */
- if (*control == '#') {
- arg1 = va_arg(args,string);
- fgets(arg1,STRSIZ,fd);
- arg1[strlen(arg1)-1] = 0;
- return 1;
- }
-
- /* pass the request on to fscanf */
- i = vfscanf(fd,control,args); /* scan with variable args */
- va_end(args); /* finish the arglist */
-
- return i; /* return a pointer to the string */
- }
-
-
-
- /*
- * file access support
- */
-
- char _CURNAME[64];
- int ioresult = 0;
-
- #undef atoi /* in case of user ident clash */
- #undef getchar
-