File: getargs.c

package info (click to toggle)
tachyon 0.99~b6%2Bdsx-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 18,848 kB
  • sloc: ansic: 16,987; makefile: 737; sh: 275
file content (676 lines) | stat: -rw-r--r-- 20,170 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
/*
 * getargs.c - command line argument parsing for tachyon command line
 *
 * $Id: getargs.c,v 1.57 2011/02/04 16:11:46 johns Exp $
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include "tachyon.h"
#include "getargs.h"
#include "ctype.h"

static int strupncmp(const char *a, const char *b, int n) {
   while (n-- > 0) {
      if (toupper(*a) != toupper(*b)) {
         return toupper(*b) - toupper(*a);
      }
      if (*a == 0) return 0;
      a++; b++;
   }
   return 0;
}

static int compare(const char *a, const char *b) {
  if (strlen(a) != strlen(b)) 
    return -1;

  return strupncmp(a, b, strlen(a));
}

static void printusage(char **argv) {
  char *argv0=strdup(argv[0]);
  char *progname=basename(argv0);
  printf("Usage: %s modelfile [options] \n", progname);
  printf("\n");
  printf("Valid options and accepted formats are as follows (** denotes default behaviour).\n");
  printf("\n");
  printf("Model file formats supported:\n");
  printf("  filename.dat        the model files originated with this package\n");
  printf("  filaname.ac         AC3D model files\n");
#ifdef USELIBMGF
  printf("  filaname.mgf        MGF model files.\n");
#endif
  printf("  filename.nff        the NFF scene format used by Eric Haines' SPD\n");
  printf("\n");
  printf("\n");
  printf("Message Options:\n");
  printf("  +V                  verbose messages on \n");
  printf("  -V                  verbose messages off **\n");
  printf("\n");
  printf("Speed Tuning Options:\n");
  printf("  -raydepth xxx       maximum ray recursion depth\n");
  printf("  -numthreads xxx     (** default is auto-determined)\n");
  printf("  -nobounding\n");
  printf("  -boundthresh xxx    (** default threshold is 16)\n");
  printf("\n");
  printf("Shading Options:\n");
  printf("  -fullshade          best quality rendering (and slowest) **\n");
  printf("  -mediumshade        good quality rendering, but no shadows\n");
  printf("  -lowshade           low quality rendering, preview (and fast)\n");
  printf("  -lowestshade        worst quality rendering, preview (and fastest)\n");
  printf("\n");
  printf("Lighting Options:\n");
  printf("  -rescale_lights xxx rescale light intensity values by\n");
  printf("                      specified factor (performed before other\n");
  printf("                      lighting overrides take effect)\n");
  printf("  -auto_skylight xxx  force use of ambient occlusion lighting,\n");
  printf("                      auto-rescaling direct light sources to  \n");
  printf("                      compensate for ambient occlusion factor\n");
  printf("                      (use value 0.7 as a good starting point)\n");
  printf("  -add_skylight xxx   force use of ambient occlusion lighting,\n");
  printf("                      manually-rescaling direct light sources to\n");
  printf("                      compensate for ambient occlusion factor\n");
  printf("  -skylight_samples xxx number of sample rays to shoot\n");
  printf("\n");
  printf("Specular Highlight Shading Options:\n");
  printf("  -shade_phong        Phong specular highlights\n");
  printf("  -shade_blinn        Blinn's specular highlights **\n");
  printf("  -shade_blinn_fast   fast approximation to Blinn's highlights\n");
  printf("  -shade_nullphong    disable specular highlights\n");
  printf("\n");
  printf("Transparency Shading Options:\n");
  printf("  -trans_max_surfaces xxx  limit the number of transparent\n");
  printf("                           surfaces shown to the number specified\n");
  printf("  -trans_orig         original implementation **\n");
  printf("  -trans_raster3d     Raster3D angle-based opacity modulation\n");
  printf("  -trans_vmd          opacity post-multiply used by VMD\n");
  printf("\n");
  printf("Transparent Surface Shadowing Options:\n");
  printf("  -shadow_filter_on   transparent objects cast shadows **\n");
  printf("  -shadow_filter_off  transparent objects do not cast shadows\n");
  printf("\n");
  printf("Fog Shading Options:\n");
  printf("  -fog_radial         radial fog implementation **\n");
  printf("  -fog_vmd            planar OpenGL-like fog used by VMD\n");
  printf("\n");
  printf("Surface Normal/Winding Order Fixup Mode:\n");
  printf("  -normalfixup [off|flip|guess] (** off is default)\n");
  printf("\n");
  printf("Antialiasing Options:\n");
  printf("  -aasamples xxx      maximum supersamples taken per pixel\n");
  printf("                      (** default is 0, or scene file determined)\n");
  printf("\n");
  printf("Output Options:\n");
  printf("  -res Xres Yres      override scene-defined output image size\n");
  printf("  -o outfile.tga      set output file name\n");
  printf("  -clamp              clamp pixel values to [0 to 1) **\n");
  printf("  -normalize          normalize pixel values to [0 to 1)\n");
  printf("  -gamma val          normalize apply gamma correction\n");
  printf("  -format BMP         24-bit Windows BMP (uncompressed)\n");
#if defined(USEJPEG)
  printf("  -format JPEG        24-bit JPEG        (compressed, but lossy)\n");
#else
  printf("  -format JPEG        XXX Not compiled into this binary XXX\n");
#endif
#if defined(USEPNG)
  printf("  -format PNG         24-bit PNG         (compressed, lossless)\n");
#else
  printf("  -format PNG         XXX Not compiled into this binary XXX\n");
#endif
  printf("  -format PPM         24-bit PPM         (uncompressed)\n");
  printf("  -format PPM48       48-bit PPM         (uncompressed)\n");
  printf("  -format PSD48       48-bit PSD         (uncompressed)\n");
  printf("  -format RGB         24-bit SGI RGB     (uncompressed)\n");
  printf("  -format TARGA       24-bit Targa       (uncompressed) **\n");
  printf("\n");
  printf("Animation Related Options:\n");
  printf("  -camfile filename.cam  animate using file of camera positions\n");
  printf("  -nosave                disable writing of output frames to disk\n");
  printf("                         (only used for doing real-time rendering)\n");
  printf("\n");
  printf("Interactive Spaceball/SpaceNavigator Control:\n");
  printf("  -spaceball          enable Spaceball/SpaceNavigator camera flight\n");
  printf("  -spaceballport serialportdevicename (only for serial devices)\n");
  printf("\n");
  printf("Getting Help:\n");
  printf("  -help               display help message and exit\n");
  printf("  -version            display version string and exit\n");
  printf("  -banner             display banner and exit\n");
  printf("\n");
	free(argv0);
}

static void initoptions(argoptions * opt) {
  memset(opt, 0, sizeof(argoptions));
  opt->filenames = (char **) malloc(sizeof(char *) * 10);
  opt->numfiles = 0;
  opt->useoutfilename = -1;
  opt->outimageformat = -1;
  opt->xsize = 0;
  opt->ysize = 0;
  opt->verbosemode = -1;
  opt->ray_maxdepth = -1;
  opt->aa_maxsamples = -1;
  opt->boundmode = -1; 
  opt->boundthresh = -1; 
  opt->usecamfile = -1;
  opt->shadermode = -1;
  opt->phongfunc = -1;
  opt->transcount = -1;
  opt->transmode = -1;
  opt->shadow_filtering = -1;
  opt->fogmode = -1;
  opt->normalfixupmode = -1;
  opt->imgprocess = -1;
  opt->imggamma = 1.0;
  opt->numthreads = -1;
  opt->nosave = -1;
  opt->rescale_lights = 1.0;
  opt->auto_skylight = 0.0;
  opt->add_skylight = 0.0;
  opt->skylight_samples = 128;
  opt->cropmode = 0;     /* SPECMPI image cropping */
  opt->cropxres = 0;
  opt->cropyres = 0;
  opt->cropxstart = 0;
  opt->cropystart = 0;
}

/* process options that affect scene generation */
int presceneoptions(argoptions * opt, SceneHandle scene) {
  if (opt->normalfixupmode != -1) {
    rt_normal_fixup_mode(scene, opt->normalfixupmode);
  }

  return 0;
}

/* process options that affect scene rendering */
int postsceneoptions(argoptions * opt, SceneHandle scene) {
  if (opt->outimageformat == -1) {
    opt->outimageformat = RT_FORMAT_TARGA;
  }
  if (opt->xsize > 0 && opt->ysize > 0) {
    rt_resolution(scene, opt->xsize, opt->ysize);
  }

  if (opt->cropmode != 0) {
    if (opt->cropmode == 1) {
      rt_crop_output(scene, opt->cropxres, opt->cropyres,
                     opt->cropxstart, opt->cropystart);
    } else {
      int xs, ys;
      rt_get_resolution(scene, &xs, &ys);
      rt_crop_output(scene, 100, 100, xs/2 - 50, ys/2 - 50);
    }
  }

  if (opt->useoutfilename == -1) {
    if (opt->usecamfile != -1) {
      strcpy(opt->outfilename, "cam.%04d");
    } else if (opt->numfiles > 1) {
      strcpy(opt->outfilename, "outfile.%04d");
    } else {
      strcpy(opt->outfilename, "outfile");
    }

    switch (opt->outimageformat) {
      case RT_FORMAT_PPM:
        strcat(opt->outfilename, ".ppm");
        break;  
  
      case RT_FORMAT_WINBMP:
        strcat(opt->outfilename, ".bmp");
        break;  

      case RT_FORMAT_SGIRGB:
        strcat(opt->outfilename, ".rgb");
        break;  

      case RT_FORMAT_JPEG:
        strcat(opt->outfilename, ".jpg");
        break;  

      case RT_FORMAT_PNG:
        strcat(opt->outfilename, ".png");
        break;  

      case RT_FORMAT_PSD48:
        strcat(opt->outfilename, ".psd");
        break;  

      case RT_FORMAT_PPM48:
        strcat(opt->outfilename, ".ppm");
        break;  

      case RT_FORMAT_TARGA:
                   default:
        strcat(opt->outfilename, ".tga");
        break;  
    }
  }

  if (opt->nosave == 1) {
    strcpy(opt->outfilename, "\0");
  }

  if (opt->rescale_lights < 1.0) {
    /* rescale all lights by supplied scaling factor */
    rt_rescale_lights(scene, opt->rescale_lights);
  }  

  if (opt->auto_skylight > 0.0) {
    /* enable ambient occlusion lighting, and rescale direct lights */
    /* to compensate. */
    apicolor col;
    float lightscale = 1.0f - opt->auto_skylight;
    if (lightscale < 0.0f)
      lightscale = 0.0f;
    rt_rescale_lights(scene, lightscale);
 
    col.r = opt->auto_skylight;    
    col.g = opt->auto_skylight;    
    col.b = opt->auto_skylight;    
    rt_ambient_occlusion(scene, opt->skylight_samples, col);
  } else if (opt->add_skylight > 0.0) {
    /* enable ambient occlusion lighting, with no automatic compensation */
    apicolor col;
    col.r = opt->add_skylight;    
    col.g = opt->add_skylight;    
    col.b = opt->add_skylight;    
    rt_ambient_occlusion(scene, opt->skylight_samples, col);
  }

  rt_outputformat(scene, opt->outimageformat);
  rt_outputfile(scene, opt->outfilename);

  if (opt->imgprocess != -1) {
    switch(opt->imgprocess) {
      case 0:
        rt_image_clamp(scene);
        break;

      case 1:
        rt_image_normalize(scene);
        break;

      case 2:
        rt_image_gamma(scene, opt->imggamma);
        break;
    }
  }

  if (opt->verbosemode == 1) {
    rt_verbose(scene, 1);
  }

  if (opt->verbosemode == 0) {
    rt_verbose(scene, 0);
  }  

  if (opt->ray_maxdepth != -1) {
    rt_camera_raydepth(scene, opt->ray_maxdepth);
  } 

  if (opt->aa_maxsamples != -1) {
    rt_aa_maxsamples(scene, opt->aa_maxsamples);
  } 

  if (opt->boundmode != -1) {
    rt_boundmode(scene, opt->boundmode);
  }

  if (opt->boundthresh != -1) {
    rt_boundthresh(scene, opt->boundthresh);
  }

  if (opt->shadermode != -1) {
    rt_shadermode(scene, opt->shadermode);
  }

  if (opt->phongfunc != -1) {
    rt_phong_shader(scene, opt->phongfunc);
  }

  if (opt->transcount != -1) {
    rt_trans_max_surfaces(scene, opt->transcount);
  }

  if (opt->transmode != -1) {
    rt_trans_mode(scene, opt->transmode);
  }

  if (opt->shadow_filtering != -1) {
    rt_shadow_filtering(scene, opt->shadow_filtering);
  }

  if (opt->fogmode != -1) {
    rt_fog_rendering_mode(scene, opt->fogmode);
  }

  if (opt->numthreads != -1) {
    rt_set_numthreads(scene, opt->numthreads);
  }

  return 0;
}    

static int getparm(int argc, char **argv, int num, argoptions * opt, int node) {
  if (!strcmp(argv[num], "-o")) {
    opt->useoutfilename = 1;
    sscanf(argv[num + 1], "%s", (char *) &opt->outfilename);
    return 2;
  }
  if (!strcmp(argv[num], "-numthreads")) {
    sscanf(argv[num + 1], "%d", &opt->numthreads);
    return 2;
  }
  if (!strcmp(argv[num], "-camfile")) {
    opt->usecamfile = 1;
    sscanf(argv[num + 1], "%s", &opt->camfilename[0]);
    return 2;
  }
  if (!strcmp(argv[num], "-nosave")) {
    /* disable writing of images to disk files */
    opt->nosave = 1;
    return 1;
  }
  if (!strcmp(argv[num], "-normalfixup")) {
    char tmp[1024];
    sscanf(argv[num + 1], "%s", tmp);
    if (!strcmp(tmp, "off")) {
      opt->normalfixupmode = RT_NORMAL_FIXUP_OFF;
    } else if (!strcmp(tmp, "flip")) {
      opt->normalfixupmode = RT_NORMAL_FIXUP_FLIP;
    } else if (!strcmp(tmp, "guess")) {
      opt->normalfixupmode = RT_NORMAL_FIXUP_GUESS;
    }
    return 2;
  }
  if (!strcmp(argv[num], "-raydepth")) {
    sscanf(argv[num + 1], "%d", &opt->ray_maxdepth);
    return 2;
  }
  if (!strcmp(argv[num], "-aasamples")) {
    sscanf(argv[num + 1], "%d", &opt->aa_maxsamples);
    return 2;
  }
  if (!strcmp(argv[num], "-V")) {
    /* turn verbose messages off */
    opt->verbosemode = 0;
    return 1;
  }
  if (!strcmp(argv[num], "+V")) {
    /* turn verbose messages on */
    opt->verbosemode = 1;
    return 1;
  }
  if (!strcmp(argv[num], "-nobounding")) {
    /* disable automatic spatial subdivision optimizations */
    opt->boundmode = RT_BOUNDING_DISABLED;
    return 1;
  }
  if (!strcmp(argv[num], "-boundthresh")) {
    /* set automatic bounding threshold control value */
    sscanf(argv[num + 1], "%d", &opt->boundthresh);
    return 2;
  }
  if (!strcmp(argv[num], "-fullshade")) {
    opt->shadermode = RT_SHADER_FULL;
    return 1;
  }
  if (!strcmp(argv[num], "-mediumshade")) {
    opt->shadermode = RT_SHADER_MEDIUM;
    return 1;
  }
  if (!strcmp(argv[num], "-lowshade")) {
    opt->shadermode = RT_SHADER_LOW;
    return 1;
  }
  if (!strcmp(argv[num], "-lowestshade")) {
    opt->shadermode = RT_SHADER_LOWEST;
    return 1;
  }
  if (!strcmp(argv[num], "-rescale_lights")) {
    sscanf(argv[num + 1], "%f", &opt->rescale_lights);
    return 2;
  }
  if (!strcmp(argv[num], "-auto_skylight")) {
    sscanf(argv[num + 1], "%f", &opt->auto_skylight);
    return 2;
  }
  if (!strcmp(argv[num], "-add_skylight")) {
    sscanf(argv[num + 1], "%f", &opt->add_skylight);
    return 2;
  }
  if (!strcmp(argv[num], "-skylight_samples")) {
    sscanf(argv[num + 1], "%d", &opt->skylight_samples);
    return 2;
  }
  if (!strcmp(argv[num], "-shade_phong")) {
    opt->phongfunc  = RT_SHADER_PHONG;
    return 1;
  }
  if (!strcmp(argv[num], "-shade_blinn")) {
    opt->phongfunc  = RT_SHADER_BLINN;
    return 1;
  }
  if (!strcmp(argv[num], "-shade_blinn_fast")) {
    opt->phongfunc  = RT_SHADER_BLINN_FAST;
    return 1;
  }
  if (!strcmp(argv[num], "-shade_nullphong")) {
    opt->phongfunc  = RT_SHADER_NULL_PHONG;
    return 1;
  }
  if (!strcmp(argv[num], "-trans_max_surfaces")) {
    sscanf(argv[num + 1], "%d", &opt->transcount);
    return 2;
  }
  if (!strcmp(argv[num], "-trans_orig")) {
    opt->transmode  = RT_TRANS_ORIG; /* reset all flags to default */
    return 1;
  }
  if (!strcmp(argv[num], "-trans_raster3d")) {
    if (opt->transmode == -1)
      opt->transmode  = RT_TRANS_RASTER3D; /* combine with other flags */
    else
      opt->transmode  |= RT_TRANS_RASTER3D; /* combine with other flags */
    return 1;
  }
  if (!strcmp(argv[num], "-trans_vmd")) {
    if (opt->transmode == -1)
      opt->transmode  = RT_TRANS_VMD; /* combine with other flags */
    else
      opt->transmode  |= RT_TRANS_VMD; /* combine with other flags */
    return 1;
  }
  if (!strcmp(argv[num], "-shadow_filter_on")) {
    opt->shadow_filtering = 1;
    return 1;
  }
  if (!strcmp(argv[num], "-shadow_filter_off")) {
    opt->shadow_filtering = 0;
    return 1;
  }
  if (!strcmp(argv[num], "-fog_normal")) {
    opt->fogmode  = RT_FOG_NORMAL;
    return 1;
  }
  if (!strcmp(argv[num], "-fog_vmd")) {
    opt->fogmode  = RT_FOG_VMD;
    return 1;
  }
  if (!strcmp(argv[num], "-res")) {
    sscanf(argv[num + 1], "%d", &opt->xsize);
    sscanf(argv[num + 2], "%d", &opt->ysize);
    return 3;
  }
  if (!strcmp(argv[num], "-cropoutputauto")) {
    opt->cropmode = 2; /* SPECMPI automatic mode */
    return 1;
  }
  if (!strcmp(argv[num], "-cropoutput")) {
    opt->cropmode = 1;
    sscanf(argv[num + 1], "%d", &opt->cropxres);
    sscanf(argv[num + 2], "%d", &opt->cropyres);
    sscanf(argv[num + 3], "%d", &opt->cropxstart);
    sscanf(argv[num + 4], "%d", &opt->cropystart);
    return 5;
  }
  if (!strcmp(argv[num], "-clamp")) {
    opt->imgprocess = 0; /* clamp pixel values */
    return 1;
  }
  if (!strcmp(argv[num], "-normalize")) {
    opt->imgprocess = 1; /* normalize pixel values */
    return 1;
  }
  if (!strcmp(argv[num], "-gamma")) {
    opt->imgprocess = 2; /* normalize pixel values */
    sscanf(argv[num + 1], "%f", &opt->imggamma);
    return 2;
  } 
  if (!strcmp(argv[num], "-format")) {
    char str[80];
    sscanf(argv[num + 1], "%s", &str[0]);

    if (!compare(str, "TARGA")) {
      opt->outimageformat = RT_FORMAT_TARGA;
    } else if (!compare(str, "BMP")) {
      opt->outimageformat = RT_FORMAT_WINBMP;
    } else if (!compare(str, "PPM48")) {
      opt->outimageformat = RT_FORMAT_PPM48;
    } else if (!compare(str, "PPM")) {
      opt->outimageformat = RT_FORMAT_PPM;
    } else if (!compare(str, "PSD48")) {
      opt->outimageformat = RT_FORMAT_PSD48;
    } else if (!compare(str, "RGB")) {
      opt->outimageformat = RT_FORMAT_SGIRGB;
#if defined(USEJPEG)
    } else if (!compare(str, "JPEG")) {
      opt->outimageformat = RT_FORMAT_JPEG;
#endif
#if defined(USEPNG)
    } else if (!compare(str, "PNG")) {
      opt->outimageformat = RT_FORMAT_PNG;
#endif
    } else {
      if (node == 0) 
        printf("Unknown/Unsupported Image Format: %s, defaulting to Targa...\n", str);
    }
    return 2;
  }

  if (!strcmp(argv[num], "-spaceball")) {
    opt->spaceballon=1;
    return 1;
  }
  if (!strcmp(argv[num], "-spaceballport")) {
    sscanf(argv[num + 1], "%s", &opt->spaceballport[0]);
    return 2;
  }

  /* getting help */
	if (!strcmp(argv[num], "-help")) {
    return -2;
  }
	if (!strcmp(argv[num], "-version")) {
    return -3;
  }
	if (!strcmp(argv[num], "-banner")) {
    return -4;
  }

  /* unknown parameter setting */
  if (node == 0) 
    printf("Unrecognized parameter/option flag: %s\n", argv[num]);

  return -1;
}

int getargs(int argc, char **argv, argoptions * opt, int node) {
  int i, rc;

  if (opt == NULL)
    return -1;

  if (argc < 2) {
    if (node == 0)
      printusage(argv);

    return -1;
  }

  initoptions(opt);  

  i = 1;
  while (i < argc) {
    if (argv[i][0] == '-' || argv[i][0] == '+') {
      rc = getparm(argc, argv, i, opt, node);
      if (0 < rc) {
        i += rc;
      } else {
        if (node == 0) {
          if (rc == -2)
            printusage(argv);
          else if (rc == -3)
            printf(TACHYON_VERSION_STRING"\n");
          else if (rc == -4)
            printf(
              "Tachyon Parallel/Multiprocessor Ray Tracer      Version "TACHYON_VERSION_STRING"\n"
              "Copyright 1994-2013,    John E. Stone <john.stone@gmail.com>\n"
              "------------------------------------------------------------\n"
              );
          else
            printusage(argv);
          }

        return -1;
      }
    }
    else {
      opt->filenames = (char **) realloc(opt->filenames, sizeof(char *) * (opt->numfiles + 10));
      opt->filenames[opt->numfiles] = 
        (char *) malloc(sizeof(char) * strlen(argv[i]) + 1);
      strcpy(opt->filenames[opt->numfiles], argv[i]);        

#if 0
{ int i; 
  for (i=0; i<opt->numfiles; i++) {
    printf("parsefile[%d]: %s\n", i, opt->filenames[i]);
  }
}
#endif

      opt->numfiles++;
      i++;
    }
  }

  if (opt->numfiles == 0) {
    if (node == 0) {
      printf("Missing model file name!\n");
      printusage(argv);
    } 
    return -1;
  }

  return 0;
}

void freeoptions(argoptions * opt) {
  if (opt->filenames != NULL) {
    int i;

    for (i=0; i<opt->numfiles; i++) {
      if (opt->filenames[i] != NULL)
        free(opt->filenames[i]);
    }

    free(opt->filenames);
  }
}