ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
Revision: 1.2
Committed: Sun Jun 8 12:03:09 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +5 -1 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

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