| 49 |
|
) |
| 50 |
|
{ |
| 51 |
|
int dim = 0; |
| 52 |
+ |
char fmt[MAXFMTLEN]; |
| 53 |
|
FILE *fp; |
| 54 |
|
int i; |
| 55 |
|
|
| 62 |
|
flockfile(stdin); |
| 63 |
|
#endif |
| 64 |
|
SET_FILE_BINARY(stdin); |
| 65 |
+ |
fmt[0] = '*'; fmt[1] = '\0'; |
| 66 |
|
if (argc > 2 && !strcmp(argv[1], "-c")) { |
| 67 |
|
SET_FILE_BINARY(stdout); |
| 68 |
|
setvbuf(stdin, NULL, _IONBF, 2); |
| 69 |
< |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 69 |
> |
if (checkheader(stdin, fmt, stdout) < 0) { |
| 70 |
> |
fputs("Bad header!\n", stderr); |
| 71 |
|
return 1; |
| 72 |
+ |
} |
| 73 |
|
printargs(argc-2, argv+2, stdout); |
| 74 |
+ |
if (fmt[0] != '*') /* better be the same! */ |
| 75 |
+ |
fputformat(fmt, stdout); |
| 76 |
|
fputc('\n', stdout); |
| 77 |
|
if (dim) { /* copy resolution string? */ |
| 78 |
|
RESOLU rs; |
| 79 |
|
if (!fgetsresolu(&rs, stdin)) { |
| 80 |
< |
fputs("No resolution string\n", stderr); |
| 80 |
> |
fputs("No resolution string!\n", stderr); |
| 81 |
|
return 1; |
| 82 |
|
} |
| 83 |
|
if (dim > 0) |
| 89 |
|
return 1; |
| 90 |
|
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
| 91 |
|
SET_FILE_BINARY(stdout); |
| 92 |
< |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 92 |
> |
if (checkheader(stdin, fmt, stdout) < 0) { |
| 93 |
> |
fputs("Bad header!\n", stderr); |
| 94 |
|
return 1; |
| 95 |
+ |
} |
| 96 |
|
for (i = 2; i < argc; i++) { |
| 97 |
|
int len = strlen(argv[i]); |
| 98 |
|
if (!len) continue; |
| 100 |
|
if (argv[i][len-1] != '\n') |
| 101 |
|
fputc('\n', stdout); |
| 102 |
|
} |
| 103 |
+ |
if (fmt[0] != '*') |
| 104 |
+ |
fputformat(fmt, stdout); |
| 105 |
|
fputc('\n', stdout); |
| 106 |
|
copycat(); |
| 107 |
|
return 0; |
| 108 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
| 109 |
|
SET_FILE_BINARY(stdout); |
| 110 |
< |
if (getheader(stdin, NULL, NULL) < 0) |
| 110 |
> |
if (getheader(stdin, NULL, NULL) < 0) { |
| 111 |
> |
fputs("Bad header!\n", stderr); |
| 112 |
|
return 1; |
| 113 |
+ |
} |
| 114 |
|
if (dim < 0) { /* skip resolution string? */ |
| 115 |
|
RESOLU rs; |
| 116 |
|
if (!fgetsresolu(&rs, stdin)) { |
| 117 |
< |
fputs("No resolution string\n", stderr); |
| 117 |
> |
fputs("No resolution string!\n", stderr); |
| 118 |
|
return 1; |
| 119 |
|
} |
| 120 |
|
} |
| 128 |
|
else { |
| 129 |
|
if (dim < 0) { /* dimensions only */ |
| 130 |
|
if (getheader(fp, NULL, NULL) < 0) { |
| 131 |
< |
fputs("bad header\n", stdout); |
| 131 |
> |
fputs("bad header!\n", stdout); |
| 132 |
|
continue; |
| 133 |
|
} |
| 134 |
|
fputs(": ", stdout); |
| 135 |
|
getdim(fp); |
| 136 |
|
} else { |
| 137 |
|
tabstr(":\n", NULL); |
| 138 |
< |
if (getheader(fp, tabstr, NULL) < 0) |
| 138 |
> |
if (getheader(fp, tabstr, NULL) < 0) { |
| 139 |
> |
fputs(argv[i], stderr); |
| 140 |
> |
fputs(": bad header!\n", stderr); |
| 141 |
|
return 1; |
| 142 |
+ |
} |
| 143 |
|
fputc('\n', stdout); |
| 144 |
|
if (dim > 0) { |
| 145 |
|
fputc('\t', stdout); |
| 151 |
|
} |
| 152 |
|
if (argc == 1) { |
| 153 |
|
if (dim < 0) { |
| 154 |
< |
if (getheader(stdin, NULL, NULL) < 0) |
| 154 |
> |
if (getheader(stdin, NULL, NULL) < 0) { |
| 155 |
> |
fputs("Bad header!\n", stderr); |
| 156 |
|
return 1; |
| 157 |
+ |
} |
| 158 |
|
getdim(stdin); |
| 159 |
|
} else { |
| 160 |
< |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 160 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) { |
| 161 |
> |
fputs("Bad header!\n", stderr); |
| 162 |
|
return 1; |
| 163 |
+ |
} |
| 164 |
|
fputc('\n', stdout); |
| 165 |
|
if (dim > 0) |
| 166 |
|
getdim(stdin); |