| 1 |
– |
/* Copyright (c) 1986 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 |
|
* |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include <stdio.h> |
| 11 |
+ |
#include <string.h> |
| 12 |
|
|
| 13 |
+ |
#include "platform.h" |
| 14 |
+ |
#include "resolu.h" |
| 15 |
|
|
| 16 |
< |
tabstr(s) /* put out line followed by tab */ |
| 17 |
< |
register char *s; |
| 16 |
> |
#ifdef getc_unlocked /* avoid nasty file-locking overhead */ |
| 17 |
> |
#undef getchar |
| 18 |
> |
#undef putchar |
| 19 |
> |
#define getchar getchar_unlocked |
| 20 |
> |
#define putchar putchar_unlocked |
| 21 |
> |
#endif |
| 22 |
> |
|
| 23 |
> |
#if defined(_WIN32) || defined(_WIN64) |
| 24 |
> |
#include <process.h> |
| 25 |
> |
#define execvp _execvp |
| 26 |
> |
#endif |
| 27 |
> |
|
| 28 |
> |
static gethfunc tabstr; |
| 29 |
> |
static void getdim(FILE *fp); |
| 30 |
> |
static void copycat(void); |
| 31 |
> |
|
| 32 |
> |
|
| 33 |
> |
static int |
| 34 |
> |
tabstr( /* put out line followed by tab */ |
| 35 |
> |
char *s, |
| 36 |
> |
void *p |
| 37 |
> |
) |
| 38 |
|
{ |
| 39 |
|
while (*s) { |
| 40 |
|
putchar(*s); |
| 42 |
|
} |
| 43 |
|
if (*--s == '\n') |
| 44 |
|
putchar('\t'); |
| 45 |
+ |
return(0); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
|
| 49 |
< |
main(argc, argv) |
| 50 |
< |
int argc; |
| 51 |
< |
char *argv[]; |
| 49 |
> |
int |
| 50 |
> |
main( |
| 51 |
> |
int argc, |
| 52 |
> |
char **argv |
| 53 |
> |
) |
| 54 |
|
{ |
| 55 |
|
int dim = 0; |
| 56 |
|
FILE *fp; |
| 59 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
| 60 |
|
argc--; argv++; |
| 61 |
|
dim = 1; |
| 62 |
+ |
SET_FILE_BINARY(stdin); |
| 63 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-c")) { |
| 64 |
+ |
SET_FILE_BINARY(stdin); |
| 65 |
+ |
SET_FILE_BINARY(stdout); |
| 66 |
+ |
setvbuf(stdin, NULL, _IONBF, 2); |
| 67 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
| 68 |
+ |
printargs(argc-2, argv+2, stdout); |
| 69 |
+ |
fputc('\n', stdout); |
| 70 |
+ |
fflush(stdout); |
| 71 |
+ |
execvp(argv[2], argv+2); |
| 72 |
+ |
perror(argv[2]); |
| 73 |
+ |
return 1; |
| 74 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
| 75 |
+ |
SET_FILE_BINARY(stdin); |
| 76 |
+ |
SET_FILE_BINARY(stdout); |
| 77 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
| 78 |
+ |
for (i = 2; i < argc; i++) { |
| 79 |
+ |
int len = strlen(argv[i]); |
| 80 |
+ |
if (!len) continue; |
| 81 |
+ |
fputs(argv[i], stdout); |
| 82 |
+ |
if (argv[i][len-1] != '\n') |
| 83 |
+ |
fputc('\n', stdout); |
| 84 |
+ |
} |
| 85 |
+ |
fputc('\n', stdout); |
| 86 |
+ |
copycat(); |
| 87 |
+ |
return 0; |
| 88 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
| 89 |
< |
getheader(stdin, NULL); |
| 89 |
> |
SET_FILE_BINARY(stdin); |
| 90 |
> |
SET_FILE_BINARY(stdout); |
| 91 |
> |
getheader(stdin, NULL, NULL); |
| 92 |
|
copycat(); |
| 93 |
< |
exit(0); |
| 93 |
> |
return 0; |
| 94 |
|
} |
| 95 |
|
for (i = 1; i < argc; i++) { |
| 96 |
|
fputs(argv[i], stdout); |
| 101 |
|
fputs(": ", stdout); |
| 102 |
|
getdim(fp); |
| 103 |
|
} else { |
| 104 |
< |
tabstr(":\n"); |
| 105 |
< |
getheader(fp, tabstr); |
| 106 |
< |
putchar('\n'); |
| 104 |
> |
tabstr(":\n", NULL); |
| 105 |
> |
getheader(fp, tabstr, NULL); |
| 106 |
> |
fputc('\n', stdout); |
| 107 |
|
} |
| 108 |
|
fclose(fp); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
< |
if (argc == 1) |
| 111 |
> |
if (argc == 1) { |
| 112 |
|
if (dim) { |
| 113 |
|
getdim(stdin); |
| 114 |
|
} else { |
| 115 |
< |
copyheader(stdin, stdout); |
| 116 |
< |
putchar('\n'); |
| 115 |
> |
getheader(stdin, (gethfunc *)fputs, stdout); |
| 116 |
> |
fputc('\n', stdout); |
| 117 |
|
} |
| 118 |
< |
exit(0); |
| 118 |
> |
} |
| 119 |
> |
return 0; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
< |
getdim(fp) /* get dimensions from file */ |
| 124 |
< |
register FILE *fp; |
| 123 |
> |
static void |
| 124 |
> |
getdim( /* get dimensions from file */ |
| 125 |
> |
FILE *fp |
| 126 |
> |
) |
| 127 |
|
{ |
| 128 |
|
int j; |
| 129 |
< |
register int c; |
| 129 |
> |
int c; |
| 130 |
|
|
| 131 |
< |
getheader(fp, NULL); /* skip header */ |
| 131 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
| 132 |
|
|
| 133 |
|
switch (c = getc(fp)) { |
| 134 |
|
case '+': /* picture */ |
| 141 |
|
getc(fp); |
| 142 |
|
j = 0; |
| 143 |
|
while ((c = getc(fp)) != EOF) |
| 144 |
< |
if (c == 0) |
| 144 |
> |
if (c == 0) { |
| 145 |
|
if (++j >= 4) |
| 146 |
|
break; |
| 147 |
< |
else |
| 148 |
< |
putchar(' '); |
| 95 |
< |
else |
| 147 |
> |
putchar(' '); |
| 148 |
> |
} else { |
| 149 |
|
putchar(c); |
| 150 |
+ |
} |
| 151 |
|
putchar('\n'); |
| 152 |
|
break; |
| 153 |
|
default: /* ??? */ |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
|
| 160 |
< |
copycat() /* copy input to output */ |
| 160 |
> |
static void |
| 161 |
> |
copycat(void) /* copy input to output */ |
| 162 |
|
{ |
| 163 |
< |
register int c; |
| 163 |
> |
char buf[8192]; |
| 164 |
> |
int n; |
| 165 |
|
|
| 166 |
< |
while ((c = getchar()) != EOF) |
| 167 |
< |
putchar(c); |
| 166 |
> |
fflush(stdout); |
| 167 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
| 168 |
> |
if (write(fileno(stdout), buf, n) != n) |
| 169 |
> |
break; |
| 170 |
|
} |