| 20 |
|
#define putchar putchar_unlocked |
| 21 |
|
#endif |
| 22 |
|
|
| 23 |
+ |
#ifdef _WIN32 |
| 24 |
+ |
#define execvp _execvp |
| 25 |
+ |
#endif |
| 26 |
|
|
| 27 |
|
static gethfunc tabstr; |
| 28 |
< |
static void getdim(register FILE *fp); |
| 28 |
> |
static void getdim(FILE *fp); |
| 29 |
|
static void copycat(void); |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
static int |
| 33 |
|
tabstr( /* put out line followed by tab */ |
| 34 |
< |
register char *s, |
| 34 |
> |
char *s, |
| 35 |
|
void *p |
| 36 |
|
) |
| 37 |
|
{ |
| 58 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
| 59 |
|
argc--; argv++; |
| 60 |
|
dim = 1; |
| 58 |
– |
SET_DEFAULT_BINARY(); /* for output file */ |
| 61 |
|
SET_FILE_BINARY(stdin); |
| 62 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-c")) { |
| 63 |
+ |
SET_FILE_BINARY(stdin); |
| 64 |
+ |
SET_FILE_BINARY(stdout); |
| 65 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
| 66 |
+ |
printargs(argc-2, argv+2, stdout); |
| 67 |
+ |
fputc('\n', stdout); |
| 68 |
+ |
fflush(stdout); |
| 69 |
+ |
execvp(argv[2], argv+2); |
| 70 |
+ |
perror(argv[2]); |
| 71 |
+ |
return 1; |
| 72 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
| 73 |
|
SET_FILE_BINARY(stdin); |
| 74 |
|
SET_FILE_BINARY(stdout); |
| 87 |
|
} else { |
| 88 |
|
tabstr(":\n", NULL); |
| 89 |
|
getheader(fp, tabstr, NULL); |
| 90 |
< |
putchar('\n'); |
| 90 |
> |
fputc('\n', stdout); |
| 91 |
|
} |
| 92 |
|
fclose(fp); |
| 93 |
|
} |
| 96 |
|
if (dim) { |
| 97 |
|
getdim(stdin); |
| 98 |
|
} else { |
| 99 |
< |
getheader(stdin, (gethfunc*)fputs, stdout); |
| 100 |
< |
putchar('\n'); |
| 99 |
> |
getheader(stdin, (gethfunc *)fputs, stdout); |
| 100 |
> |
fputc('\n', stdout); |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
return 0; |
| 106 |
|
|
| 107 |
|
static void |
| 108 |
|
getdim( /* get dimensions from file */ |
| 109 |
< |
register FILE *fp |
| 109 |
> |
FILE *fp |
| 110 |
|
) |
| 111 |
|
{ |
| 112 |
|
int j; |
| 113 |
< |
register int c; |
| 113 |
> |
int c; |
| 114 |
|
|
| 115 |
|
getheader(fp, NULL, NULL); /* skip header */ |
| 116 |
|
|
| 125 |
|
getc(fp); |
| 126 |
|
j = 0; |
| 127 |
|
while ((c = getc(fp)) != EOF) |
| 128 |
< |
if (c == 0) |
| 128 |
> |
if (c == 0) { |
| 129 |
|
if (++j >= 4) |
| 130 |
|
break; |
| 131 |
< |
else |
| 132 |
< |
putchar(' '); |
| 121 |
< |
else |
| 131 |
> |
putchar(' '); |
| 132 |
> |
} else { |
| 133 |
|
putchar(c); |
| 134 |
+ |
} |
| 135 |
|
putchar('\n'); |
| 136 |
|
break; |
| 137 |
|
default: /* ??? */ |
| 144 |
|
static void |
| 145 |
|
copycat(void) /* copy input to output */ |
| 146 |
|
{ |
| 147 |
< |
register int c; |
| 147 |
> |
char buf[8192]; |
| 148 |
> |
ssize_t n; |
| 149 |
|
|
| 150 |
< |
while ((c = getchar()) != EOF) |
| 151 |
< |
putchar(c); |
| 150 |
> |
fflush(stdout); |
| 151 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
| 152 |
> |
if (write(fileno(stdout), buf, n) != n) |
| 153 |
> |
break; |
| 154 |
|
} |