| 1 |
# define CFUNCS_C |
| 2 |
#include "cfuncs.h" |
| 3 |
|
| 4 |
int P_argc; |
| 5 |
char **P_argv; |
| 6 |
int P_ioresult; |
| 7 |
int _EscIO2 (int errorcode, char* filename) |
| 8 |
{ fprintf(stderr,"Input file %s not found\n",filename); |
| 9 |
exit(errorcode); return errorcode; } |
| 10 |
int _EscIO (int errorcode){ return _EscIO2(errorcode,""); } |
| 11 |
int _Escape (int exitcode) |
| 12 |
{ exit(exitcode); return exitcode; } |
| 13 |
int _SETIO (int OK, int errorcode){ return P_ioresult = OK ? 0 : errorcode; } |
| 14 |
int P_eof (FILE * infile) |
| 15 |
{ int x; |
| 16 |
if (feof(infile)) return 1; |
| 17 |
x = fgetc(infile); |
| 18 |
if (x==EOF) return 1; |
| 19 |
ungetc(x,infile); return 0; |
| 20 |
} |
| 21 |
void *__MallocTemp__; |
| 22 |
int _OutMem(void) { fprintf(stderr,"Out of memory\n"); exit(-2); return -2; } |
| 23 |
void PASCAL_MAIN (int npars, char ** pars) |
| 24 |
{ P_argc = npars; P_argv = pars; } |
| 25 |
|
| 26 |
void scan1(char *s, short p, short *n) |
| 27 |
{ sscanf(s+p-1,"%hd",n); |
| 28 |
} |
| 29 |
|
| 30 |
short pos1(char c, char *s) |
| 31 |
{ char *t = strchr(s,c); |
| 32 |
if (t) return (short) (t-s+1); else return 0; |
| 33 |
} |
| 34 |
|
| 35 |
void delete1(char *s, short p) |
| 36 |
{ char *t = (s+=p); s=t-1; |
| 37 |
while (*s) *s++ = *t++; |
| 38 |
} |
| 39 |
|
| 40 |
void predelete(char *s, short l) |
| 41 |
{ char *t = s+l; |
| 42 |
while (*t) *s++ = *t++; |
| 43 |
*s = *t; |
| 44 |
} |
| 45 |
|
| 46 |
void shorten(char *s, short new_length) |
| 47 |
{ s[new_length] = '\0'; |
| 48 |
} |
| 49 |
|
| 50 |
short posNot(char c, char *s) |
| 51 |
{ char *t = s; |
| 52 |
while (*t == c) t++; |
| 53 |
if (*t) return t-s+1; |
| 54 |
else return 0; |
| 55 |
} |
| 56 |
|
| 57 |
void getNum(char *line, short *k) |
| 58 |
{ int j=sscanf(line,"%hd",k); |
| 59 |
if (j<1) *k=0; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
void getTwoNums(char *line, short *k1, short *k2) |
| 64 |
{ int param = sscanf(line,"%hd/%hd",k1,k2); |
| 65 |
if (param<2) *k2 = 0; |
| 66 |
} |
| 67 |
|
| 68 |
void toUpper(char *s) |
| 69 |
{ while (*s) { *s = toupper(*s); s++; } |
| 70 |
} |
| 71 |
|
| 72 |
boolean startsWith(char *s1, char *s2) |
| 73 |
{ while (*s2) { if (*s1++ != *s2++) return false; } |
| 74 |
return true; |
| 75 |
} |
| 76 |
|
| 77 |
void insertChar(char c, char *s, short p) |
| 78 |
{ char x; |
| 79 |
s += p-1; |
| 80 |
do { x=c; c=*s; *s++=x; } while (x); |
| 81 |
} |
| 82 |
|
| 83 |
char *substr_(char *Result, char *s, short start, short count) |
| 84 |
{ char *R = Result; |
| 85 |
s += start-1; |
| 86 |
while (count--) *R++ = *s++; |
| 87 |
*R = '\0'; |
| 88 |
return Result; |
| 89 |
} |
| 90 |
|
| 91 |
short strpos2 (char *s1, char *s2, short p) |
| 92 |
{ char *r = strstr (s1+p, s2); |
| 93 |
if (r == NULL) return 0; |
| 94 |
else return r-s1; |
| 95 |
} |
| 96 |
|
| 97 |
short nextWordBound(char *s, char trigger, short p) |
| 98 |
{ |
| 99 |
do { |
| 100 |
p++; |
| 101 |
} while (p <= strlen(s) && s[p-1] != trigger); |
| 102 |
while (p < strlen(s) && s[p] != ' ') |
| 103 |
p++; |
| 104 |
return p; |
| 105 |
} |
| 106 |
|
| 107 |
# undef CFUNCS_C |