--- ray/src/util/getinfo.c 2019/07/06 14:08:07 2.18 +++ ray/src/util/getinfo.c 2022/03/03 22:54:49 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: getinfo.c,v 2.18 2019/07/06 14:08:07 greg Exp $"; +static const char RCSid[] = "$Id: getinfo.c,v 2.22 2022/03/03 22:54:49 greg Exp $"; #endif /* * getinfo.c - program to read info. header from file. @@ -7,9 +7,7 @@ static const char RCSid[] = "$Id: getinfo.c,v 2.18 201 * 1/3/86 */ -#include -#include - +#include "rtio.h" #include "platform.h" #include "rtprocess.h" #include "resolu.h" @@ -51,31 +49,39 @@ main( ) { int dim = 0; + char fmt[MAXFMTLEN]; FILE *fp; int i; - if (argc > 1 && !strcmp(argv[1], "-d")) { + if (argc > 1 && (argv[1][0] == '-') | (argv[1][0] == '+') && + argv[1][1] == 'd') { + dim = 1 - 2*(argv[1][0] == '-'); argc--; argv++; - dim = 1; } #ifdef getc_unlocked /* avoid lock/unlock overhead */ flockfile(stdin); #endif SET_FILE_BINARY(stdin); + fmt[0] = '*'; fmt[1] = '\0'; if (argc > 2 && !strcmp(argv[1], "-c")) { SET_FILE_BINARY(stdout); setvbuf(stdin, NULL, _IONBF, 2); - if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) + if (checkheader(stdin, fmt, stdout) < 0) { + fputs("Bad header!\n", stderr); return 1; + } printargs(argc-2, argv+2, stdout); + if (fmt[0] != '*') /* better be the same! */ + fputformat(fmt, stdout); fputc('\n', stdout); if (dim) { /* copy resolution string? */ RESOLU rs; if (!fgetsresolu(&rs, stdin)) { - fputs("No resolution string\n", stderr); + fputs("No resolution string!\n", stderr); return 1; } - fputsresolu(&rs, stdout); + if (dim > 0) + fputsresolu(&rs, stdout); } fflush(stdout); execvp(argv[2], argv+2); @@ -83,8 +89,10 @@ main( return 1; } else if (argc > 2 && !strcmp(argv[1], "-a")) { SET_FILE_BINARY(stdout); - if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) + if (checkheader(stdin, fmt, stdout) < 0) { + fputs("Bad header!\n", stderr); return 1; + } for (i = 2; i < argc; i++) { int len = strlen(argv[i]); if (!len) continue; @@ -92,17 +100,21 @@ main( if (argv[i][len-1] != '\n') fputc('\n', stdout); } + if (fmt[0] != '*') + fputformat(fmt, stdout); fputc('\n', stdout); copycat(); return 0; } else if (argc == 2 && !strcmp(argv[1], "-")) { SET_FILE_BINARY(stdout); - if (getheader(stdin, NULL, NULL) < 0) + if (getheader(stdin, NULL, NULL) < 0) { + fputs("Bad header!\n", stderr); return 1; - if (dim) { /* skip resolution string? */ + } + if (dim < 0) { /* skip resolution string? */ RESOLU rs; if (!fgetsresolu(&rs, stdin)) { - fputs("No resolution string\n", stderr); + fputs("No resolution string!\n", stderr); return 1; } } @@ -114,24 +126,44 @@ main( if ((fp = fopen(argv[i], "r")) == NULL) fputs(": cannot open\n", stdout); else { - if (dim) { + if (dim < 0) { /* dimensions only */ + if (getheader(fp, NULL, NULL) < 0) { + fputs("bad header!\n", stdout); + continue; + } fputs(": ", stdout); getdim(fp); } else { tabstr(":\n", NULL); - getheader(fp, tabstr, NULL); + if (getheader(fp, tabstr, NULL) < 0) { + fputs(argv[i], stderr); + fputs(": bad header!\n", stderr); + return 1; + } fputc('\n', stdout); + if (dim > 0) { + fputc('\t', stdout); + getdim(fp); + } } fclose(fp); } } if (argc == 1) { - if (dim) { + if (dim < 0) { + if (getheader(stdin, NULL, NULL) < 0) { + fputs("Bad header!\n", stderr); + return 1; + } getdim(stdin); } else { - if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) + if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) { + fputs("Bad header!\n", stderr); return 1; + } fputc('\n', stdout); + if (dim > 0) + getdim(stdin); } } return 0; @@ -145,11 +177,7 @@ getdim( /* get dimensions from file */ { int j; int c; - /* skip header */ - if (getheader(fp, NULL, NULL) < 0) { - fputs("bad header\n", stdout); - return; - } + switch (c = getc(fp)) { case '+': /* picture */ case '-':