ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
Revision: 1.4
Committed: Fri Nov 14 17:31:24 2003 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 1.3: +2 -1 lines
Log Message:
Reduced compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.4 static const char RCSid[] = "$Id: lam.c,v 1.3 2003/10/27 10:26:05 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * lam.c - simple program to laminate files.
6     *
7     * 7/14/88 Greg Ward
8     */
9    
10 schorsch 1.2 #include <stdlib.h>
11     #include <string.h>
12 greg 1.1 #include <stdio.h>
13 schorsch 1.2
14     #include "platform.h"
15 schorsch 1.3 #include "rtprocess.h"
16 greg 1.1
17     #define MAXFILE 16 /* maximum number of files */
18    
19     #define MAXLINE 512 /* maximum input line */
20    
21     FILE *input[MAXFILE];
22     int tabc[MAXFILE];
23     int nfiles;
24    
25     char buf[MAXLINE];
26    
27 schorsch 1.4 int
28 greg 1.1 main(argc, argv)
29     int argc;
30     char *argv[];
31     {
32     register int i;
33     int curtab;
34     int running;
35    
36     curtab = '\t';
37     nfiles = 0;
38     for (i = 1; i < argc; i++) {
39     if (argv[i][0] == '-') {
40     switch (argv[i][1]) {
41     case 't':
42     curtab = argv[i][2];
43     break;
44     case '\0':
45     tabc[nfiles] = curtab;
46     input[nfiles++] = stdin;
47     break;
48     default:
49     fputs(argv[0], stderr);
50     fputs(": bad option\n", stderr);
51     exit(1);
52     }
53     } else if (argv[i][0] == '!') {
54     tabc[nfiles] = curtab;
55     if ((input[nfiles++] = popen(argv[i]+1, "r")) == NULL) {
56     fputs(argv[i], stderr);
57     fputs(": cannot start command\n", stderr);
58     exit(1);
59     }
60     } else {
61     tabc[nfiles] = curtab;
62     if ((input[nfiles++] = fopen(argv[i], "r")) == NULL) {
63     fputs(argv[i], stderr);
64     fputs(": cannot open file\n", stderr);
65     exit(1);
66     }
67     }
68     if (nfiles >= MAXFILE) {
69     fputs(argv[0], stderr);
70     fputs(": too many input streams\n", stderr);
71     exit(1);
72     }
73     }
74    
75     do {
76     running = 0;
77     for (i = 0; i < nfiles; i++) {
78     if (fgets(buf, MAXLINE, input[i]) != NULL) {
79     if (i)
80     putchar(tabc[i]);
81     buf[strlen(buf)-1] = '\0';
82     fputs(buf, stdout);
83     running++;
84     }
85     }
86     if (running)
87     putchar('\n');
88     } while (running);
89    
90     exit(0);
91     }