--- ray/src/util/getinfo.c 1990/06/28 16:39:32 1.2 +++ ray/src/util/getinfo.c 2014/09/08 18:21:39 2.12 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: getinfo.c,v 2.12 2014/09/08 18:21:39 greg Exp $"; #endif - /* * getinfo.c - program to read info. header from file. * @@ -11,10 +8,33 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include +#include "platform.h" +#include "resolu.h" -tabstr(s) /* put out line followed by tab */ -register char *s; +#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 + +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); @@ -22,12 +42,15 @@ register char *s; } if (*--s == '\n') putchar('\t'); + return(0); } -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char **argv +) { int dim = 0; FILE *fp; @@ -36,10 +59,24 @@ char *argv[]; if (argc > 1 && !strcmp(argv[1], "-d")) { argc--; argv++; dim = 1; + SET_FILE_BINARY(stdin); + } else if (argc > 2 && !strcmp(argv[1], "-c")) { + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); + setvbuf(stdin, NULL, _IONBF, 2); + 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], "-")) { - getheader(stdin, NULL); + 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); @@ -50,31 +87,34 @@ char *argv[]; fputs(": ", stdout); getdim(fp); } else { - tabstr(":\n"); - getheader(fp, tabstr); - putchar('\n'); + tabstr(":\n", NULL); + getheader(fp, tabstr, NULL); + fputc('\n', stdout); } fclose(fp); } } - if (argc == 1) + if (argc == 1) { if (dim) { getdim(stdin); } else { - copyheader(stdin, 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); /* skip header */ + getheader(fp, NULL, NULL); /* skip header */ switch (c = getc(fp)) { case '+': /* picture */ @@ -87,13 +127,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: /* ??? */ @@ -103,10 +143,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; }