10
MYFILE outfile = { NULL, FALSE};
13
char depend_err[50] = "";
15
void *Malloc(size_t sze) {
16
void *res = malloc(sze);
28
static char *binpath = NULL;
30
void save_binpath(char *arg0) {
31
int sl = strlen(arg0);
34
/* Accept three path seperators: / \ : */
35
while (sl > 0 && strchr("\\/:", arg0[sl-1]) == NULL) --sl;
38
if (arg0[sl-1] == ':') ap = ":.";
39
binpath = Malloc(sl + strlen(ap) );
40
if (binpath == NULL) return;
41
strncpy(binpath, arg0, sl-1);
42
strcpy(binpath+sl-1, ap);
45
char *get_logical(char *logical)
51
if (r == NULL) r = "";
53
if (*res != '\0' || strcmp(logical, "BOXDIR")!=0 || binpath == NULL)
56
/* looking for BOXDIR -> default to exe directory ! */
57
strcpy(res, binpath); /* exec path */
61
BOOL fexist(char *fname)
66
f = fopen(fname, TXT_RD);
73
int indx(char *mainstring, char *substring)
77
if (*mainstring == '\0')
79
cp = strstr(mainstring, substring);
80
if (cp == NULL) return 0;
81
return (int)(cp-mainstring)+1;
84
MYFILE *outopen(MYFILE *mf, char *fn) {
85
mf->bin = EOLmode != EOL_default;
86
mf->f = fopen(fn, (mf->bin ? BIN_WR : TXT_WR));
87
return (mf->f != NULL ? mf : NULL);
90
static char *uwb = NULL;
91
void uwriteln(MYFILE *f, char *fmt, ...) {
96
va_start(argptr, fmt);
97
vfprintf(f->f, fmt, argptr);
113
va_start(argptr, fmt);
114
cnt = vsprintf(uwb, fmt, argptr);
120
while (cp1 != NULL && *cp1 != '\0') {
121
cp2 = strchr(cp1, '\n');
130
case EOL_dos : putc('\r', f->f);
133
case EOL_mac : putc('\r', f->f); break;
135
default : putc('\n', f->f); break;
144
double str2real(void *s)
149
err = (sscanf((char *)s, "%lg", &r) == 0);
151
strcpy(depend_err, "str2real");
162
err = (sscanf((char *)s, "%d", &i) == 0);
164
strcpy(depend_err, "str2real");
173
static long rand_m = 100000000L, rand_m1 = 10000, rand_b = 31415821L;
175
static long rand_a[55];
176
static int rand_j, filecount;
180
if (c <= 90 && c >= 65)
186
char *int2str(char *Result, int intg, int dig)
190
sprintf(s, "%*d", dig, intg);
191
return strcpy(Result, s);
195
char *real2str(char *Result, double rl, int dig1, int dig2)
199
sprintf(s, "%*.*f", dig1, dig2, rl);
200
return strcpy(Result, s);
203
char *get_command_line(char *Result)
210
for (i = 1; i < P_argc; i++)
211
strcat(cl, P_argv[i]);
213
return strcpy(Result, cl);
216
static char *getTEMPname(char *Result, char *s_)
221
s[strlen(s) - 1] = '~';
222
return strcpy(Result, s);
226
void fopen_(FILE **f, char *fname_, char acc)
231
string255 tmpname, line;
233
char buf1[6144], buf2[6144];
235
char tmpfile_NAME[_FNSIZE];
237
strcpy(fname, fname_);
239
if (acc == 'w' || acc == 'W') {
241
/* p2c: dep_tp.pas, line 128: Note: REWRITE does not specify a name [181] */
247
_EscIO(FileNotFound);
248
} else if (acc == 'a' || acc == 'A') {
250
/* p2c: dep_tp.pas, line 133: Note: APPEND does not specify a name [181] */
256
_EscIO(FileNotFound);
260
/* p2c: dep_tp.pas, line 139:
261
* Note: Turbo Pascal conditional compilation directive was ignored [218] */
265
} while (!(P_eoln(*f) || c == '\n'));
269
/* p2c: dep_tp.pas, line 142:
270
* Warning: Symbol 'UXMODE' is not defined [221] */
274
setvbuf(*f, buf1, _IOFBF, 6144);
275
getTEMPname(tmpname, fname);
276
strcpy(tmpfile_NAME, tmpname);
278
tmpfile = freopen(tmpfile_NAME, "w", tmpfile);
280
tmpfile = fopen(tmpfile_NAME, "w");
281
_SETIO(tmpfile != NULL, FileNotFound);
282
/* p2c: dep_tp.pas, line 149:
283
* Note: Make sure setvbuf() call occurs when file is open [200] */
284
setvbuf(*f, buf2, _IOFBF, 6144);
286
ureadln(f, (void *)line);
289
_SETIO(fprintf(tmpfile, "%s\n", line) >= 0, FileWriteError);
297
/* p2c: dep_tp.pas, line 157: Note: Encountered an ASSIGN statement [179] */
302
strcpy(depend_err, "could not convert unix format");
304
/* p2c: dep_tp.pas, line 145:
305
* Note: Make sure setvbuf() call occurs when file is open [200] */
308
/* p2c: dep_tp.pas, line 127: Note: Encountered an ASSIGN statement [179] */
312
/* p2c: dep_tp.pas, line 132: Note: Encountered an ASSIGN statement [179] */
313
/* p2c: dep_tp.pas, line 137: Note: Encountered an ASSIGN statement [179] */
316
char *substr_(char *Result, void *original, int pos1, int count)
318
return strsub(Result, (char[256])original, pos1, count);
322
static long mult(long p, long q)
328
/* p2c: dep_tp.pas, line 182:
329
* Note: Using % for possibly-negative arguments [317] */
332
/* p2c: dep_tp.pas, line 183:
333
* Note: Using % for possibly-negative arguments [317] */
334
return (((p0 * q1 + p1 * q0) % rand_m1 * rand_m1 + p0 * q0) % rand_m);
335
/* p2c: dep_tp.pas, line 184:
336
* Note: Using % for possibly-negative arguments [317] */
337
/* p2c: dep_tp.pas, line 184:
338
* Note: Using % for possibly-negative arguments [317] */
342
void rand_init(int seed)
348
rand_a[rand_j] = (mult(rand_b, rand_a[rand_j - 1]) + 1) % rand_m;
349
/* p2c: dep_tp.pas, line 193:
350
* Note: Using % for possibly-negative arguments [317] */
351
} while (rand_j != 54);
355
int rand_int(int limit)
357
/*from 0 to limit-1*/
358
rand_j = (rand_j + 1) % 55;
359
/* p2c: dep_tp.pas, line 198:
360
* Note: Using % for possibly-negative arguments [317] */
361
rand_a[rand_j] = (rand_a[(rand_j + 23) % 55] + rand_a[(rand_j + 54) % 55]) %
363
/* p2c: dep_tp.pas, line 199:
364
* Note: Using % for possibly-negative arguments [317] */
365
/* p2c: dep_tp.pas, line 200:
366
* Note: Using % for possibly-negative arguments [317] */
367
/* p2c: dep_tp.pas, line 200:
368
* Note: Using % for possibly-negative arguments [317] */
369
return (rand_a[rand_j] / rand_m1 * limit / rand_m1);
373
double rand_real(void)
375
/* from 0(incl) to 1(excl) */
376
return (rand_int(32000) / 32000.0);
380
typedef char string1[2];
383
void ureadln(FILE **f, void *line)
390
*(string1)line = '\0';
395
else if (c != '\015') {
396
sprintf(STR1, "%s%c", (char[256])line, c);
397
strcpy((char *)(&line), STR1);
400
fscanf(*f, "%*[^\n]");
408
BOOL getunixmode(char *fname)
413
char f_NAME[_FNSIZE];
416
strcpy(f_NAME, fname);
418
f = freopen(f_NAME, "r", f);
420
f = fopen(f_NAME, "r");
422
_EscIO(FileNotFound);
425
} while (!(c == '\n' || P_eoln(f)));
438
void _dep_tp_init(void)
440
static int _was_initialized = 0;
441
if (_was_initialized++)