ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
Revision: 1.6
Committed: Mon Jun 13 22:40:47 2005 UTC (18 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1
Changes since 1.5: +6 -6 lines
Log Message:
Changed rlam -t option to accept strings as well as tab characters

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: lam.c,v 1.5 2004/12/07 22:25:55 greg 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 32 /* maximum number of files */
18
19 #define MAXLINE 512 /* maximum input line */
20
21 FILE *input[MAXFILE];
22 char *tabc[MAXFILE];
23 int nfiles;
24
25 char buf[MAXLINE];
26
27 int
28 main(argc, argv)
29 int argc;
30 char *argv[];
31 {
32 register int i;
33 char *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 fputs(tabc[i], stdout);
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 }