274 |
|
int ni_rows = 0; /* number of input rows */ |
275 |
|
int no_columns = 0; /* number of output columns */ |
276 |
|
int no_rows = 0; /* number of output rows */ |
277 |
+ |
int transpose = 0; /* transpose rows & cols? */ |
278 |
+ |
int i_header = 1; /* input header? */ |
279 |
+ |
int o_header = 1; /* output header? */ |
280 |
|
|
281 |
|
/* check settings and assign defaults */ |
282 |
|
static int |
296 |
|
return(0); |
297 |
|
} |
298 |
|
} |
299 |
+ |
if (transpose && (no_rows <= 0) & (no_columns <= 0)) { |
300 |
+ |
if (ni_rows > 0) no_columns = ni_rows; |
301 |
+ |
if (ni_columns > 0) no_rows = ni_columns; |
302 |
+ |
} else if ((no_rows <= 0) & (no_columns > 0) && |
303 |
+ |
!((ni_rows*ni_columns) % no_columns)) |
304 |
+ |
no_rows = ni_rows*ni_columns/no_columns; |
305 |
|
if (n_comp <= 0) |
306 |
|
n_comp = 3; |
307 |
|
return(1); |
381 |
|
int columns2go = no_columns; |
382 |
|
char word[256]; |
383 |
|
/* sanity checks */ |
384 |
< |
if (comp_size) |
385 |
< |
return(output_stream(fp)); /* binary data -- just copy */ |
384 |
> |
if (comp_size || (no_columns == ni_columns) & (no_rows == ni_rows)) |
385 |
> |
return(output_stream(fp)); /* no-op -- just copy */ |
386 |
|
if (no_columns <= 0) { |
387 |
|
fprintf(stderr, "Missing -oc specification\n"); |
388 |
|
return(0); |
475 |
|
n_comp = n; |
476 |
|
return(0); |
477 |
|
} |
478 |
< |
fputs(s, stdout); /* copy header info. */ |
478 |
> |
if (o_header) |
479 |
> |
fputs(s, stdout); /* copy header info. */ |
480 |
|
return(0); |
481 |
|
} |
482 |
|
|
484 |
|
int |
485 |
|
main(int argc, char *argv[]) |
486 |
|
{ |
477 |
– |
int i_header = 1; /* input header? */ |
478 |
– |
int o_header = 1; /* output header? */ |
479 |
– |
int transpose = 0; /* transpose rows & cols? */ |
487 |
|
int a; |
488 |
|
|
489 |
|
for (a = 1; a < argc && argv[a][0] == '-'; a++) |
572 |
|
SET_FILE_BINARY(stdout); |
573 |
|
} |
574 |
|
/* check for no-op */ |
575 |
< |
if (!transpose & (i_header == o_header) && (comp_size || |
576 |
< |
(no_columns == ni_columns) & (no_rows == ni_rows))) { |
575 |
> |
if (!transpose & (i_header == o_header) && |
576 |
> |
(no_columns == ni_columns) & (no_rows == ni_rows)) { |
577 |
|
if (warnings) |
578 |
|
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
579 |
|
argv[0]); |
594 |
|
return(1); |
595 |
|
if (o_header) { /* write header */ |
596 |
|
printargs(a, argv, stdout); |
590 |
– |
if (transpose && (no_rows <= 0) & (no_columns <= 0)) { |
591 |
– |
if (ni_rows > 0) no_columns = ni_rows; |
592 |
– |
if (ni_columns > 0) no_rows = ni_columns; |
593 |
– |
} |
597 |
|
if (no_rows > 0) |
598 |
|
printf("NROWS=%d\n", no_rows); |
599 |
|
if (no_columns > 0) |
603 |
|
fputc('\n', stdout); /* finish new header */ |
604 |
|
} |
605 |
|
if (transpose) { /* transposing rows & columns? */ |
606 |
< |
MEMLOAD myMem; /* need to load into memory */ |
606 |
> |
MEMLOAD myMem; /* need to map into memory */ |
607 |
|
if (a == argc-1) { |
608 |
|
if (load_file(&myMem, stdin) <= 0) { |
609 |
|
fprintf(stderr, "%s: error loading file into memory\n", |
617 |
|
} |
618 |
|
if (!do_transpose(&myMem)) |
619 |
|
return(1); |
620 |
< |
/* free_load(&myMem); */ |
621 |
< |
} else if (!do_resize(stdin)) /* just reshaping input */ |
620 |
> |
/* free_load(&myMem); about to exit, so don't bother */ |
621 |
> |
} else if (!do_resize(stdin)) /* reshaping input */ |
622 |
|
return(1); |
623 |
|
return(0); |
624 |
|
userr: |