ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
Revision: 1.3
Committed: Mon Oct 27 10:26:05 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -1 lines
Log Message:
Various compatibility fixes.

File Contents

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