73 |
|
struct field *outfmt = NULL; /* output record structure */ |
74 |
|
struct strvar *svhead = NULL; /* string variables */ |
75 |
|
|
76 |
+ |
long incnt = 0; /* limit number of input records? */ |
77 |
+ |
long outcnt = 0; /* limit number of output records? */ |
78 |
+ |
|
79 |
|
int blnkeq = 1; /* blanks compare equal? */ |
80 |
|
int igneol = 0; /* ignore end of line? */ |
81 |
|
int passive = 0; /* passive mode (transmit unmatched input) */ |
160 |
|
nbicols = 0; |
161 |
|
readfmt(argv[++i], 0); |
162 |
|
break; |
163 |
+ |
case 'n': |
164 |
+ |
incnt = atol(argv[++i]); |
165 |
+ |
break; |
166 |
|
case 'a': |
167 |
|
itype = 'a'; |
168 |
|
nbicols = 0; |
203 |
|
otype = 'a'; |
204 |
|
readfmt(argv[++i], 1); |
205 |
|
break; |
206 |
+ |
case 'n': |
207 |
+ |
outcnt = atol(argv[++i]); |
208 |
+ |
break; |
209 |
|
case 'a': |
210 |
|
otype = 'a'; |
211 |
|
break; |
281 |
|
if (inpfmt != NULL) |
282 |
|
return(getrec()); |
283 |
|
if (tolower(itype) == 'd') { |
284 |
< |
if (fread(inpbuf, sizeof(double), nbicols, fp) != nbicols) |
284 |
> |
if (getbinary(inpbuf, sizeof(double), nbicols, fp) != nbicols) |
285 |
|
return(0); |
286 |
|
if (itype == 'D') |
287 |
|
swap64(inpbuf, nbicols); |
288 |
|
return(1); |
289 |
|
} |
290 |
|
if (tolower(itype) == 'f') { |
291 |
< |
if (fread(inpbuf, sizeof(float), nbicols, fp) != nbicols) |
291 |
> |
if (getbinary(inpbuf, sizeof(float), nbicols, fp) != nbicols) |
292 |
|
return(0); |
293 |
|
if (itype == 'F') |
294 |
|
swap32(inpbuf, nbicols); |
303 |
|
char *file |
304 |
|
) |
305 |
|
{ |
306 |
< |
int conditional = vardefined("cond"); |
306 |
> |
const int conditional = vardefined("cond"); |
307 |
> |
const int set_recno = (varlookup("recno") != NULL); |
308 |
> |
const int set_outno = (varlookup("outno") != NULL); |
309 |
|
long nrecs = 0; |
310 |
|
long nout = 0; |
311 |
|
FILE *fp; |
326 |
|
initinp(fp); |
327 |
|
|
328 |
|
while (getinputrec(fp)) { |
329 |
< |
varset("recno", '=', (double)++nrecs); |
330 |
< |
varset("outno", '=', (double)(nout+1)); |
329 |
> |
++nrecs; |
330 |
> |
if (set_recno) |
331 |
> |
varset("recno", '=', (double)nrecs); |
332 |
> |
if (set_outno) |
333 |
> |
varset("outno", '=', (double)(nout+1)); |
334 |
|
colflg = 0; |
335 |
|
eclock++; |
336 |
|
if (!conditional || varvalue("cond") > 0.0) { |
337 |
|
putout(); |
338 |
|
++nout; |
339 |
|
} |
340 |
+ |
if (incnt && nrecs >= incnt) |
341 |
+ |
break; |
342 |
+ |
if (outcnt && nout >= outcnt) |
343 |
+ |
break; |
344 |
|
} |
345 |
|
fclose(fp); |
346 |
|
} |
471 |
|
float fval = v; |
472 |
|
|
473 |
|
while (++colpos < n) |
474 |
< |
fwrite(zerobuf, |
474 |
> |
putbinary(zerobuf, |
475 |
|
tolower(otype)=='d' ? sizeof(double) : sizeof(float), |
476 |
|
1, stdout); |
477 |
|
switch (otype) { |
479 |
|
swap64((char *)&v, 1); |
480 |
|
/* fall through */ |
481 |
|
case 'd': |
482 |
< |
fwrite(&v, sizeof(double), 1, stdout); |
482 |
> |
putbinary(&v, sizeof(double), 1, stdout); |
483 |
|
break; |
484 |
|
case 'F': |
485 |
|
swap32((char *)&fval, 1); |
486 |
|
/* fall through */ |
487 |
|
case 'f': |
488 |
< |
fwrite(&fval, sizeof(float), 1, stdout); |
488 |
> |
putbinary(&fval, sizeof(float), 1, stdout); |
489 |
|
break; |
490 |
|
} |
491 |
|
} |