--- ray/src/util/getinfo.c 2003/07/21 22:30:19 2.7 +++ ray/src/util/getinfo.c 2014/07/28 20:12:20 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: getinfo.c,v 2.7 2003/07/21 22:30:19 schorsch Exp $"; +static const char RCSid[] = "$Id: getinfo.c,v 2.11 2014/07/28 20:12:20 greg Exp $"; #endif /* * getinfo.c - program to read info. header from file. @@ -8,14 +8,33 @@ static const char RCSid[] = "$Id: getinfo.c,v 2.7 2003 */ #include +#include #include "platform.h" +#include "resolu.h" +#ifdef getc_unlocked /* avoid nasty file-locking overhead */ +#undef getchar +#undef putchar +#define getchar getchar_unlocked +#define putchar putchar_unlocked +#endif +#ifdef _WIN32 +#include +#define execvp _execvp +#endif -int -tabstr(s) /* put out line followed by tab */ -register char *s; +static gethfunc tabstr; +static void getdim(FILE *fp); +static void copycat(void); + + +static int +tabstr( /* put out line followed by tab */ + char *s, + void *p +) { while (*s) { putchar(*s); @@ -27,9 +46,11 @@ register char *s; } -main(argc, argv) -int argc; -char **argv; +int +main( + int argc, + char **argv +) { int dim = 0; FILE *fp; @@ -38,14 +59,23 @@ char **argv; if (argc > 1 && !strcmp(argv[1], "-d")) { argc--; argv++; dim = 1; - SET_DEFAULT_BINARY(); /* for output file */ SET_FILE_BINARY(stdin); + } else if (argc > 2 && !strcmp(argv[1], "-c")) { + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); + getheader(stdin, (gethfunc *)fputs, stdout); + printargs(argc-2, argv+2, stdout); + fputc('\n', stdout); + fflush(stdout); + execvp(argv[2], argv+2); + perror(argv[2]); + return 1; } else if (argc == 2 && !strcmp(argv[1], "-")) { SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); getheader(stdin, NULL, NULL); copycat(); - exit(0); + return 0; } for (i = 1; i < argc; i++) { fputs(argv[i], stdout); @@ -56,9 +86,9 @@ char **argv; fputs(": ", stdout); getdim(fp); } else { - tabstr(":\n"); + tabstr(":\n", NULL); getheader(fp, tabstr, NULL); - putchar('\n'); + fputc('\n', stdout); } fclose(fp); } @@ -67,19 +97,21 @@ char **argv; if (dim) { getdim(stdin); } else { - getheader(stdin, fputs, stdout); - putchar('\n'); + getheader(stdin, (gethfunc *)fputs, stdout); + fputc('\n', stdout); } } - exit(0); + return 0; } -getdim(fp) /* get dimensions from file */ -register FILE *fp; +static void +getdim( /* get dimensions from file */ + FILE *fp +) { int j; - register int c; + int c; getheader(fp, NULL, NULL); /* skip header */ @@ -94,13 +126,13 @@ register FILE *fp; getc(fp); j = 0; while ((c = getc(fp)) != EOF) - if (c == 0) + if (c == 0) { if (++j >= 4) break; - else - putchar(' '); - else + putchar(' '); + } else { putchar(c); + } putchar('\n'); break; default: /* ??? */ @@ -110,10 +142,14 @@ register FILE *fp; } -copycat() /* copy input to output */ +static void +copycat(void) /* copy input to output */ { - register int c; + char buf[8192]; + int n; - while ((c = getchar()) != EOF) - putchar(c); + fflush(stdout); + while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) + if (write(fileno(stdout), buf, n) != n) + break; }