ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/lam.c
(Generate patch)

Comparing ray/src/cal/lam.c (file contents):
Revision 1.11 by greg, Fri Jun 18 21:22:49 2010 UTC vs.
Revision 1.16 by greg, Thu Mar 24 19:00:54 2016 UTC

# Line 17 | Line 17 | static const char      RCSid[] = "$Id$";
17  
18   #define MAXFILE         512             /* maximum number of files */
19  
20 < #define MAXLINE         4096            /* maximum input line */
20 > #define MAXLINE         65536           /* maximum input line */
21  
22 + long    incnt = 0;                      /* limit number of records? */
23 +
24   FILE    *input[MAXFILE];
25   int     bytsiz[MAXFILE];
26   char    *tabc[MAXFILE];
# Line 32 | Line 34 | int    argc;
34   char    *argv[];
35   {
36          int     unbuff = 0;
37 +        int     binout = 0;
38          int     i;
39          char    *curtab;
40          int     curbytes;
# Line 51 | Line 54 | char   *argv[];
54                                  break;
55                          case 'i':
56                                  switch (argv[i][2]) {
57 +                                case 'n':
58 +                                        incnt = atol(argv[++i]);
59 +                                        break;
60                                  case 'f':
61                                          curbytes = sizeof(float);
62                                          break;
# Line 67 | Line 73 | char   *argv[];
73                                          curbytes = 1;
74                                          break;
75                                  case 'a':
76 <                                        curbytes = argv[i][3] ? 1 : 0;
76 >                                        curbytes = argv[i][3] ? -1 : 0;
77                                          break;
78                                  default:
79                                          goto badopt;
80                                  }
81                                  if (isdigit(argv[i][3]))
82                                          curbytes *= atoi(argv[i]+3);
83 <                                if (curbytes < 0 || curbytes > MAXLINE) {
83 >                                if (abs(curbytes) > MAXLINE) {
84                                          fputs(argv[0], stderr);
85 <                                        fputs(": illegal input size\n", stderr);
85 >                                        fputs(": input size too big\n", stderr);
86                                          exit(1);
87                                  }
88 <                                if (curbytes)
88 >                                if (curbytes) {
89                                          curtab = "";
90 +                                        ++binout;
91 +                                }
92                                  break;
93                          case '\0':
94                                  tabc[nfiles] = curtab;
95 <                                bytsiz[nfiles] = curbytes;
96 <                                input[nfiles++] = stdin;
95 >                                input[nfiles] = stdin;
96 >                                if (curbytes > 0)
97 >                                        SET_FILE_BINARY(input[nfiles]);
98 >                                else
99 >                                        curbytes = -curbytes;
100 >                                bytsiz[nfiles++] = curbytes;
101                                  break;
102                          badopt:;
103                          default:
# Line 95 | Line 107 | char   *argv[];
107                          }
108                  } else if (argv[i][0] == '!') {
109                          tabc[nfiles] = curtab;
98                        bytsiz[nfiles] = curbytes;
110                          if ((input[nfiles] = popen(argv[i]+1, "r")) == NULL) {
111                                  fputs(argv[i], stderr);
112                                  fputs(": cannot start command\n", stderr);
113                                  exit(1);
114                          }
115 <                        if (bytsiz[nfiles])
115 >                        if (curbytes > 0)
116                                  SET_FILE_BINARY(input[nfiles]);
117 <                        ++nfiles;
117 >                        else
118 >                                curbytes = -curbytes;
119 >                        bytsiz[nfiles++] = curbytes;
120                  } else {
121                          tabc[nfiles] = curtab;
109                        bytsiz[nfiles] = curbytes;
122                          if ((input[nfiles] = fopen(argv[i], "r")) == NULL) {
123                                  fputs(argv[i], stderr);
124                                  fputs(": cannot open file\n", stderr);
125                                  exit(1);
126                          }
127 <                        if (bytsiz[nfiles])
127 >                        if (curbytes > 0)
128                                  SET_FILE_BINARY(input[nfiles]);
129 <                        ++nfiles;
129 >                        else
130 >                                curbytes = -curbytes;
131 >                        bytsiz[nfiles++] = curbytes;
132                  }
133                  if (nfiles >= MAXFILE) {
134                          fputs(argv[0], stderr);
# Line 122 | Line 136 | char   *argv[];
136                          exit(1);
137                  }
138          }
139 <        puteol = 0;                             /* check for ASCII output */
139 >        if (binout)                             /* binary output? */
140 >                SET_FILE_BINARY(stdout);
141 > #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
142          for (i = nfiles; i--; )
143 +                flockfile(input[i]);
144 +        flockfile(stdout);
145 + #endif
146 +        puteol = 0;                             /* any ASCII output at all? */
147 +        for (i = nfiles; i--; )
148                  if (!bytsiz[i] || isprint(tabc[i][0]) || tabc[i][0] == '\t') {
149                          puteol++;
150                          break;
151                  }
152 <        for ( ; ; ) {                           /* main loop */
152 >        do {                                    /* main loop */
153                  for (i = 0; i < nfiles; i++) {
154                          if (bytsiz[i]) {                /* binary file */
155                                  if (fread(buf, bytsiz[i], 1, input[i]) < 1)
# Line 151 | Line 172 | char   *argv[];
172                          putchar('\n');
173                  if (unbuff)
174                          fflush(stdout);
175 <        }
175 >        } while (--incnt);
176          return(0);
177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines