| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* getinfo.c - program to read info. header from file. |
| 6 |
|
* |
| 7 |
|
* 1/3/86 |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include <stdio.h> |
| 10 |
> |
#include "rtio.h" |
| 11 |
> |
#include "platform.h" |
| 12 |
> |
#include "rtprocess.h" |
| 13 |
> |
#include "resolu.h" |
| 14 |
|
|
| 15 |
< |
#ifdef MSDOS |
| 16 |
< |
#include <fcntl.h> |
| 15 |
> |
#ifdef getc_unlocked /* avoid nasty file-locking overhead */ |
| 16 |
> |
#undef getc |
| 17 |
> |
#undef getchar |
| 18 |
> |
#undef putchar |
| 19 |
> |
#define getc getc_unlocked |
| 20 |
> |
#define getchar getchar_unlocked |
| 21 |
> |
#define putchar putchar_unlocked |
| 22 |
|
#endif |
| 23 |
|
|
| 24 |
< |
extern int fputs(); |
| 24 |
> |
static gethfunc tabstr; |
| 25 |
> |
static void getdim(FILE *fp); |
| 26 |
> |
static void copycat(void); |
| 27 |
|
|
| 28 |
|
|
| 29 |
< |
tabstr(s) /* put out line followed by tab */ |
| 30 |
< |
register char *s; |
| 29 |
> |
static int |
| 30 |
> |
tabstr( /* put out line followed by tab */ |
| 31 |
> |
char *s, |
| 32 |
> |
void *p |
| 33 |
> |
) |
| 34 |
|
{ |
| 35 |
|
while (*s) { |
| 36 |
|
putchar(*s); |
| 38 |
|
} |
| 39 |
|
if (*--s == '\n') |
| 40 |
|
putchar('\t'); |
| 41 |
+ |
return(0); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
< |
main(argc, argv) |
| 46 |
< |
int argc; |
| 47 |
< |
char *argv[]; |
| 45 |
> |
int |
| 46 |
> |
main( |
| 47 |
> |
int argc, |
| 48 |
> |
char **argv |
| 49 |
> |
) |
| 50 |
|
{ |
| 51 |
|
int dim = 0; |
| 52 |
|
FILE *fp; |
| 53 |
|
int i; |
| 54 |
|
|
| 55 |
< |
if (argc > 1 && !strcmp(argv[1], "-d")) { |
| 55 |
> |
if (argc > 1 && (argv[1][0] == '-') | (argv[1][0] == '+') && |
| 56 |
> |
argv[1][1] == 'd') { |
| 57 |
> |
dim = 1 - 2*(argv[1][0] == '-'); |
| 58 |
|
argc--; argv++; |
| 59 |
< |
dim = 1; |
| 60 |
< |
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
| 61 |
< |
#ifdef MSDOS |
| 47 |
< |
setmode(fileno(stdin), O_BINARY); |
| 48 |
< |
setmode(fileno(stdout), O_BINARY); |
| 59 |
> |
} |
| 60 |
> |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
| 61 |
> |
flockfile(stdin); |
| 62 |
|
#endif |
| 63 |
< |
getheader(stdin, NULL); |
| 63 |
> |
SET_FILE_BINARY(stdin); |
| 64 |
> |
if (argc > 2 && !strcmp(argv[1], "-c")) { |
| 65 |
> |
SET_FILE_BINARY(stdout); |
| 66 |
> |
setvbuf(stdin, NULL, _IONBF, 2); |
| 67 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 68 |
> |
return 1; |
| 69 |
> |
printargs(argc-2, argv+2, stdout); |
| 70 |
> |
fputc('\n', stdout); |
| 71 |
> |
if (dim) { /* copy resolution string? */ |
| 72 |
> |
RESOLU rs; |
| 73 |
> |
if (!fgetsresolu(&rs, stdin)) { |
| 74 |
> |
fputs("No resolution string\n", stderr); |
| 75 |
> |
return 1; |
| 76 |
> |
} |
| 77 |
> |
if (dim > 0) |
| 78 |
> |
fputsresolu(&rs, stdout); |
| 79 |
> |
} |
| 80 |
> |
fflush(stdout); |
| 81 |
> |
execvp(argv[2], argv+2); |
| 82 |
> |
perror(argv[2]); |
| 83 |
> |
return 1; |
| 84 |
> |
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
| 85 |
> |
SET_FILE_BINARY(stdout); |
| 86 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 87 |
> |
return 1; |
| 88 |
> |
for (i = 2; i < argc; i++) { |
| 89 |
> |
int len = strlen(argv[i]); |
| 90 |
> |
if (!len) continue; |
| 91 |
> |
fputs(argv[i], stdout); |
| 92 |
> |
if (argv[i][len-1] != '\n') |
| 93 |
> |
fputc('\n', stdout); |
| 94 |
> |
} |
| 95 |
> |
fputc('\n', stdout); |
| 96 |
|
copycat(); |
| 97 |
< |
exit(0); |
| 97 |
> |
return 0; |
| 98 |
> |
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
| 99 |
> |
SET_FILE_BINARY(stdout); |
| 100 |
> |
if (getheader(stdin, NULL, NULL) < 0) |
| 101 |
> |
return 1; |
| 102 |
> |
if (dim < 0) { /* skip resolution string? */ |
| 103 |
> |
RESOLU rs; |
| 104 |
> |
if (!fgetsresolu(&rs, stdin)) { |
| 105 |
> |
fputs("No resolution string\n", stderr); |
| 106 |
> |
return 1; |
| 107 |
> |
} |
| 108 |
> |
} |
| 109 |
> |
copycat(); |
| 110 |
> |
return 0; |
| 111 |
|
} |
| 112 |
|
for (i = 1; i < argc; i++) { |
| 113 |
|
fputs(argv[i], stdout); |
| 114 |
|
if ((fp = fopen(argv[i], "r")) == NULL) |
| 115 |
|
fputs(": cannot open\n", stdout); |
| 116 |
|
else { |
| 117 |
< |
if (dim) { |
| 117 |
> |
if (dim < 0) { /* dimensions only */ |
| 118 |
> |
if (getheader(fp, NULL, NULL) < 0) { |
| 119 |
> |
fputs("bad header\n", stdout); |
| 120 |
> |
continue; |
| 121 |
> |
} |
| 122 |
|
fputs(": ", stdout); |
| 123 |
|
getdim(fp); |
| 124 |
|
} else { |
| 125 |
< |
tabstr(":\n"); |
| 126 |
< |
getheader(fp, tabstr, NULL); |
| 127 |
< |
putchar('\n'); |
| 125 |
> |
tabstr(":\n", NULL); |
| 126 |
> |
if (getheader(fp, tabstr, NULL) < 0) |
| 127 |
> |
return 1; |
| 128 |
> |
fputc('\n', stdout); |
| 129 |
> |
if (dim > 0) { |
| 130 |
> |
fputc('\t', stdout); |
| 131 |
> |
getdim(fp); |
| 132 |
> |
} |
| 133 |
|
} |
| 134 |
|
fclose(fp); |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
< |
if (argc == 1) |
| 138 |
< |
if (dim) { |
| 137 |
> |
if (argc == 1) { |
| 138 |
> |
if (dim < 0) { |
| 139 |
> |
if (getheader(stdin, NULL, NULL) < 0) |
| 140 |
> |
return 1; |
| 141 |
|
getdim(stdin); |
| 142 |
|
} else { |
| 143 |
< |
getheader(stdin, fputs, stdout); |
| 144 |
< |
putchar('\n'); |
| 143 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
| 144 |
> |
return 1; |
| 145 |
> |
fputc('\n', stdout); |
| 146 |
> |
if (dim > 0) |
| 147 |
> |
getdim(stdin); |
| 148 |
|
} |
| 149 |
< |
exit(0); |
| 149 |
> |
} |
| 150 |
> |
return 0; |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
< |
getdim(fp) /* get dimensions from file */ |
| 155 |
< |
register FILE *fp; |
| 154 |
> |
static void |
| 155 |
> |
getdim( /* get dimensions from file */ |
| 156 |
> |
FILE *fp |
| 157 |
> |
) |
| 158 |
|
{ |
| 159 |
|
int j; |
| 160 |
< |
register int c; |
| 160 |
> |
int c; |
| 161 |
|
|
| 87 |
– |
getheader(fp, NULL); /* skip header */ |
| 88 |
– |
|
| 162 |
|
switch (c = getc(fp)) { |
| 163 |
|
case '+': /* picture */ |
| 164 |
|
case '-': |
| 170 |
|
getc(fp); |
| 171 |
|
j = 0; |
| 172 |
|
while ((c = getc(fp)) != EOF) |
| 173 |
< |
if (c == 0) |
| 173 |
> |
if (c == 0) { |
| 174 |
|
if (++j >= 4) |
| 175 |
|
break; |
| 176 |
< |
else |
| 177 |
< |
putchar(' '); |
| 105 |
< |
else |
| 176 |
> |
putchar(' '); |
| 177 |
> |
} else { |
| 178 |
|
putchar(c); |
| 179 |
+ |
} |
| 180 |
|
putchar('\n'); |
| 181 |
|
break; |
| 182 |
|
default: /* ??? */ |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
< |
copycat() /* copy input to output */ |
| 189 |
> |
static void |
| 190 |
> |
copycat(void) /* copy input to output */ |
| 191 |
|
{ |
| 192 |
< |
register int c; |
| 193 |
< |
|
| 194 |
< |
while ((c = getchar()) != EOF) |
| 195 |
< |
putchar(c); |
| 192 |
> |
char buf[8192]; |
| 193 |
> |
int n; |
| 194 |
> |
|
| 195 |
> |
fflush(stdout); |
| 196 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
| 197 |
> |
if (writebuf(fileno(stdout), buf, n) != n) |
| 198 |
> |
break; |
| 199 |
|
} |