8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
+ |
#include <fcntl.h> |
12 |
|
#include <stdio.h> |
13 |
|
#include <string.h> |
14 |
|
#include <math.h> |
16 |
|
|
17 |
|
#include "platform.h" |
18 |
|
#include "calcomp.h" |
19 |
+ |
#include "rterror.h" |
20 |
|
|
19 |
– |
#ifdef CPM |
20 |
– |
#define getc agetc /* text files only, right? */ |
21 |
– |
#endif |
22 |
– |
|
21 |
|
#define isnum(c) (isdigit(c) || (c)=='-' || (c)=='.' \ |
22 |
|
|| (c)=='+' || (c)=='e' || (c)=='E') |
23 |
|
|
55 |
|
#define savqstr(s) strcpy(emalloc(strlen(s)+1),s) |
56 |
|
#define freqstr(s) efree(s) |
57 |
|
|
58 |
+ |
static int getinputrec(FILE *fp); |
59 |
|
static void scaninp(void), advinp(void), resetinp(void); |
60 |
|
static void putrec(void), putout(void), nbsynch(void); |
61 |
|
static int getrec(void); |
68 |
|
static void chanset(int n, double v); |
69 |
|
static void bchanset(int n, double v); |
70 |
|
static struct strvar* getsvar(char *svname); |
71 |
+ |
static double l_in(char *); |
72 |
|
|
73 |
|
struct field *inpfmt = NULL; /* input record format */ |
74 |
|
struct field *outfmt = NULL; /* output record structure */ |
112 |
|
biggerlib(); |
113 |
|
#endif |
114 |
|
varset("PI", ':', 3.14159265358979323846); |
115 |
+ |
funset("in", 1, '=', &l_in); |
116 |
|
|
117 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
118 |
|
switch (argv[i][1]) { |
151 |
|
nbicols = atoi(argv[i]+3); |
152 |
|
else |
153 |
|
nbicols = 1; |
154 |
+ |
if (nbicols*sizeof(double) > INBSIZ) { |
155 |
+ |
eputs(argv[0]); |
156 |
+ |
eputs(": too many input columns\n"); |
157 |
+ |
quit(1); |
158 |
+ |
} |
159 |
|
break; |
160 |
|
case 'f': |
161 |
|
if (isdigit(argv[i][3])) |
162 |
|
nbicols = -atoi(argv[i]+3); |
163 |
|
else |
164 |
|
nbicols = -1; |
165 |
+ |
if (-nbicols*sizeof(float) > INBSIZ) { |
166 |
+ |
eputs(argv[0]); |
167 |
+ |
eputs(": too many input columns\n"); |
168 |
+ |
quit(1); |
169 |
+ |
} |
170 |
|
break; |
171 |
|
default: |
172 |
|
goto userr; |
219 |
|
execute(argv[i]); |
220 |
|
|
221 |
|
quit(0); |
222 |
+ |
return 0; /* pro forma return */ |
223 |
|
} |
224 |
|
|
225 |
|
|
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
< |
int |
238 |
> |
static int |
239 |
|
getinputrec( /* get next input record */ |
240 |
|
FILE *fp |
241 |
|
) |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
+ |
static double |
307 |
+ |
l_in(char *funame) /* function call for $channel */ |
308 |
+ |
{ |
309 |
+ |
int n; |
310 |
+ |
register char *cp; |
311 |
+ |
/* get argument as integer */ |
312 |
+ |
n = (int)(argument(1) + .5); |
313 |
+ |
if (n != 0) /* return channel value */ |
314 |
+ |
return(chanvalue(n)); |
315 |
+ |
/* determine number of channels */ |
316 |
+ |
if (noinput || inpfmt != NULL) |
317 |
+ |
return(0); |
318 |
+ |
if (nbicols > 0) |
319 |
+ |
return(nbicols); |
320 |
+ |
if (nbicols < 0) |
321 |
+ |
return(-nbicols); |
322 |
+ |
cp = inpbuf; /* need to count */ |
323 |
+ |
for (n = 0; *cp; ) |
324 |
+ |
if (blnkeq && isspace(sepchar)) { |
325 |
+ |
while (isspace(*cp)) |
326 |
+ |
cp++; |
327 |
+ |
n += *cp != '\0'; |
328 |
+ |
while (*cp && !isspace(*cp)) |
329 |
+ |
cp++; |
330 |
+ |
} else { |
331 |
+ |
n += *cp != '\n'; |
332 |
+ |
while (*cp && *cp++ != sepchar) |
333 |
+ |
; |
334 |
+ |
} |
335 |
+ |
return(n); |
336 |
+ |
} |
337 |
+ |
|
338 |
|
double |
339 |
|
chanvalue( /* return value for column n */ |
340 |
|
int n |
660 |
|
register struct field *f |
661 |
|
) |
662 |
|
{ |
663 |
< |
static char buf[MAXWORD+1]; /* no recursion! */ |
663 |
> |
static char buf[RMAXWORD+1]; /* no recursion! */ |
664 |
|
int delim, inword; |
665 |
|
double d; |
666 |
|
char *np; |
693 |
|
delim = f->next->f.sl[0]; |
694 |
|
cp = buf; |
695 |
|
do { |
696 |
< |
if (ipb.chr == EOF) |
696 |
> |
if (ipb.chr == EOF || ipb.chr == '\n') |
697 |
|
inword = 0; |
698 |
|
else if (blnkeq && delim != EOF) |
699 |
|
inword = isblnk(delim) ? |
705 |
|
*cp++ = ipb.chr; |
706 |
|
scaninp(); |
707 |
|
} |
708 |
< |
} while (inword && cp < &buf[MAXWORD]); |
708 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
709 |
|
*cp = '\0'; |
710 |
|
if (f->f.sv->val == NULL) |
711 |
|
f->f.sv->val = savqstr(buf); /* first setting */ |
734 |
|
*cp++ = ipb.chr; |
735 |
|
scaninp(); |
736 |
|
} |
737 |
< |
} while (inword && cp < &buf[MAXWORD]); |
737 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
738 |
|
*cp = '\0'; |
739 |
|
d = np==NULL ? 0. : atof(np); |
740 |
|
if (!vardefined(f->f.nv)) |