1 # define CFUNCS_C
2 #include "cfuncs.h"
3 
4 int P_argc;
5 char **P_argv;
6 int P_ioresult;
_EscIO2(int errorcode,char * filename)7 int _EscIO2 (int errorcode, char* filename)
8 { fprintf(stderr,"Input file %s not found\n",filename);
9   exit(errorcode); return errorcode; }
_EscIO(int errorcode)10 int _EscIO (int errorcode){ return _EscIO2(errorcode,""); }
_Escape(int exitcode)11 int _Escape (int exitcode)
12 { exit(exitcode); return exitcode; }
_SETIO(int OK,int errorcode)13 int _SETIO (int OK, int errorcode){ return P_ioresult = OK ? 0 : errorcode; }
P_eof(FILE * infile)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__;
_OutMem(void)22 int _OutMem(void) { fprintf(stderr,"Out of memory\n"); exit(-2); return -2; }
PASCAL_MAIN(int npars,char ** pars)23 void PASCAL_MAIN (int npars, char ** pars)
24 { P_argc = npars; P_argv = pars; }
25 
scan1(char * s,short p,short * n)26 void scan1(char *s, short p, short *n)
27 { sscanf(s+p-1,"%hd",n);
28 }
29 
pos1(char c,char * s)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 
delete1(char * s,short p)35 void delete1(char *s, short p)
36 { char *t = (s+=p); s=t-1;
37   while (*s) *s++ = *t++;
38 }
39 
predelete(char * s,short l)40 void predelete(char *s, short l)
41 { char *t = s+l;
42   while (*t) *s++ = *t++;
43   *s = *t;
44 }
45 
shorten(char * s,short new_length)46 void shorten(char *s, short new_length)
47 { s[new_length] = '\0';
48 }
49 
posNot(char c,char * s)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 
getNum(char * line,short * k)57 void getNum(char *line, short *k)
58 { int j=sscanf(line,"%hd",k);
59   if (j<1) *k=0;
60 }
61 
62 
getTwoNums(char * line,short * k1,short * k2)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 
toUpper(char * s)68 void toUpper(char *s)
69 { while (*s) { *s = toupper(*s); s++; }
70 }
71 
startsWith(char * s1,char * s2)72 boolean startsWith(char *s1, char *s2)
73 { while (*s2) { if (*s1++ != *s2++) return false; }
74   return true;
75 }
76 
insertChar(char c,char * s,short p)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 
substr_(char * Result,char * s,short start,short count)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 # undef CFUNCS_C
92