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

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.2 by greg, Thu Sep 5 18:30:58 2013 UTC vs.
Revision 2.6 by greg, Mon Nov 18 18:07:16 2013 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   */
7  
8   #include <stdlib.h>
9 #include <unistd.h>
9   #include <string.h>
10   #include <ctype.h>
11   #include "platform.h"
# Line 35 | Line 34 | typedef struct {
34          char    *rec[1];        /* record array (extends struct) */
35   } RECINDEX;
36  
37 + int             warnings = 1;   /* report warnings? */
38 +
39   /* free loaded file */
40   static void
41   free_load(MEMLOAD *mp)
# Line 272 | Line 273 | do_transpose(const MEMLOAD *mp)
273          RECINDEX                *rp = NULL;
274          long                    nrecords;
275          int                     i, j;
276 +                                                /* propogate sizes */
277 +        if (ni_rows <= 0)
278 +                ni_rows = no_columns;
279 +        if (ni_columns <= 0)
280 +                ni_columns = no_rows;
281                                                  /* get # records (& index) */
282          if (record_width > 0) {
283                  if ((rp = index_records(mp, record_width)) == NULL)
# Line 279 | Line 285 | do_transpose(const MEMLOAD *mp)
285                  if (ni_columns <= 0)
286                          ni_columns = count_columns(rp);
287                  nrecords = rp->nrecs;
288 <        } else if ((ni_rows > 0) & (ni_columns > 0))
288 >        } else if ((ni_rows > 0) & (ni_columns > 0)) {
289                  nrecords = ni_rows*ni_columns;
290 <        else
290 >                if (nrecords > mp->len / -record_width) {
291 >                        fprintf(stderr,
292 >                            "Input too small for specified size and type\n");
293 >                        return(0);
294 >                }
295 >        } else
296                  nrecords = mp->len / -record_width;
297                                                  /* check sizes */
287        if (ni_rows <= 0)
288                ni_rows = no_columns;
289        if (ni_columns <= 0)
290                ni_columns = no_rows;
298          if ((ni_rows <= 0) & (ni_columns > 0))
299                  ni_rows = nrecords/ni_columns;
300          if ((ni_columns <= 0) & (ni_rows > 0))
# Line 378 | Line 385 | do_resize(FILE *fp)
385                          putc('\t', stdout);
386          } while (--records2go);                 /* expected EOD? */
387   done:
388 <        if (columns2go != no_columns)
388 >        if (warnings && columns2go != no_columns)
389                  fprintf(stderr, "Warning -- incomplete final row\n");
390 <        if (fget_word(word, fp) != NULL)
391 <                fprintf(stderr, "Warning -- data beyond expected EOF\n");
390 >        if (warnings && fget_word(word, fp) != NULL)
391 >                fprintf(stderr, "Warning -- characters beyond expected EOD\n");
392          return(1);
393   }
394  
# Line 464 | Line 471 | main(int argc, char *argv[])
471                                  record_width *= atoi(argv[i]+3);
472                          }
473                          break;
474 +                case 'w':                       /* warnings on/off */
475 +                        warnings = !warnings;
476 +                        break;
477                  default:
478                          goto userr;
479                  }
# Line 483 | Line 493 | main(int argc, char *argv[])
493                                                  /* check for no-op */
494          if (!transpose && (record_width < 0 ||
495                          (no_columns == ni_columns) & (no_rows == ni_rows))) {
496 <                fprintf(stderr, "%s: no-op -- copying input verbatim\n",
496 >                if (warnings)
497 >                        fprintf(stderr, "%s: no-op -- copying input verbatim\n",
498                                  argv[0]);
499                  if (!output_stream(stdin))
500                          return(1);
# Line 517 | Line 528 | main(int argc, char *argv[])
528          return(0);
529   userr:
530          fprintf(stderr,
531 < "Usage: %s [-h][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n",
531 > "Usage: %s [-h][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n",
532                          argv[0]);
533          return(1);
534   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines