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.5 by greg, Fri Sep 6 21:43:29 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines