ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
Revision: 1.1
Committed: Sat Feb 22 02:07:20 2003 UTC (21 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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