home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / simplerd.lha / simplerad / FinalFTP / Light / args.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  7.9 KB  |  278 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /* args.c : handle command line args                                  */
  4. /*                                                                    */
  5. /* Copyright (C) 1992, Bernard Kwok                                   */
  6. /* All rights reserved.                                               */
  7. /* Revision 1.0                                                       */
  8. /* May, 1992                                                          */
  9. /**********************************************************************/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "geo.h"
  14. #include "struct.h"
  15. #include "rad.h"
  16. #include "io.h"
  17. #include "ff.h"
  18. #include "misc.h"
  19. #include "vcr.h"
  20.  
  21. #define shift argc--; argv++;
  22. extern FF_OptionType FF_Options;
  23. extern OptionType Option;
  24. extern char *ProgName;
  25. int test_vtxshade = 0;
  26. int test_optik = 0;
  27. int intermed[4] = { -1, -1, -1, -1 }; /* Intermediate results to store */
  28. int num_inter = 0;
  29.  
  30. /**********************************************************************/
  31. static char StrUsage[] =              /* program usage                */
  32.   "[-dhsONV] -p file -v eye (-f 0/1 0/1/2)\n\t (-R 0/1 samples) [-I n i1..in]";
  33.  
  34. /**********************************************************************/
  35. /* Syntax                                                             */
  36. /**********************************************************************/
  37. void Usage()
  38. {
  39.   fprintf(stderr,"usage: %s %s\n", ProgName, StrUsage);
  40. }
  41.  
  42. /**********************************************************************/
  43. /* Help                                                               */
  44. /**********************************************************************/
  45. void LongUsage()
  46. {
  47.   fprintf(stderr,"\nWhere:\n");
  48.   fprintf(stderr,"\td : Set debug mode\n");
  49.   fprintf(stderr,"\tf : 0/1 = hemicube/ray cast ffs\n");
  50.   fprintf(stderr,"\t    0/1/2 = circle/ellipse/analyt ffs\n");
  51.   fprintf(stderr,"\tp : Set patch input file\n");
  52.   fprintf(stderr,"\ts : Statistics: 0/1 = stdout or to file\n");
  53.   fprintf(stderr,"\tI : Storage of intermediate results\n");
  54.   fprintf(stderr,"\t    n = number of places (max=4), i_n = iteration #\n");
  55.   fprintf(stderr,"\tO : 0/1 = output to Optik output or not\n");
  56.   fprintf(stderr,"\tR : 0/1 s = (don't) ray cast with s samples\n");
  57.   fprintf(stderr,"\tN : Set to NTSC window mode\n");
  58.   fprintf(stderr,"\tV : Record to VCR in NTSC mode\n");
  59.   fprintf(stderr,"\th : This message\n");
  60. }
  61.  
  62. /**********************************************************************/
  63. /* Parse command line arguments                                       */
  64. /**********************************************************************/
  65. void ParseArgs(argc, argv)
  66.      int argc;
  67.      char **argv;
  68. {
  69.   char *env_var = "                    ";
  70.   int enough_args = 0;
  71.   int i;
  72.  
  73.   ProgName = argv[0];
  74.   if (argc < 2) {
  75.     Usage();
  76.     exit(1);
  77.   }
  78.  
  79.   shift;
  80.   while (argc && **argv == '-') {
  81.     switch(*++*argv) {
  82.  
  83.     case 'I':                    /* Output intermediate results up to 4 */
  84.       shift;
  85.       if (argc < 2) {
  86.     fprintf(stderr,"Not enough I parameters\n");    
  87.     exit(1);
  88.       }
  89.       num_inter = atoi(*argv);
  90.       if (num_inter > 4) {
  91.     fprintf(stderr,"Current maximum intermediate results is four\n");
  92.     exit(1);
  93.       }
  94.       if (argc < num_inter || num_inter <= 0) {
  95.     fprintf(stderr,"Incorrect I parameters\n");    
  96.     exit(1);
  97.       }
  98.       for (i=0;i<num_inter;i++) {
  99.     shift;
  100.     if (!argc) {
  101.       fprintf(stderr,"Not enough I parameters\n");    
  102.       exit(1);
  103.     }      
  104.     intermed[i] = atoi(*argv);
  105.       }
  106.       /* for (i=0;i<num_inter;i++) {
  107.      printf("intermed = %d\n",intermed[i]);
  108.      } */
  109.       break;
  110.  
  111.     case 'N':                    /* Set NTSC window size and placement */
  112.       if ((env_var = getenv("HOSTTYPE")) != 0)
  113.     if (strcmp("iris4d",env_var) == 0) {
  114.       Option.VCRmode = NTSC;
  115.       Option.UseVCR = TRUE;
  116.       fprintf(stderr,"Displaying NTSC mode\n");
  117.     } else {
  118.       Option.UseVCR = FALSE;
  119.       fprintf(stderr,"Sorry can't video run on a %s\n", env_var);
  120.       exit(1);
  121.     }
  122.       break;
  123.  
  124.     case 'O':                    /* Optik output or not ? */
  125.       shift;
  126.       if (argc < 1) {
  127.     fprintf(stderr,"Not enough O parameters\n");    
  128.     exit(1);
  129.       }
  130.       test_optik = atoi(*argv);
  131.       break;
  132.  
  133.     case 'R': 
  134.       shift;
  135.       if (argc < 2) {
  136.     fprintf(stderr,"Not enough ray parameters\n");    
  137.     exit(1);
  138.       }
  139.       /* Really ray cast */
  140.       if (atoi(*argv) == 1) 
  141.     Option.visibility = FORM_FACTOR; 
  142.       shift;
  143.  
  144.       /* This many samples */
  145.       if ((atoi(*argv) == 1) || (atoi(*argv) == 4) || (atoi(*argv) == 16)) {
  146.     FF_Options.num_samples = atoi(*argv);
  147.     /* printf("samples = %d\n", FF_Options.num_samples); */
  148.       }
  149.       enough_args++;
  150.       break;
  151.  
  152.     case 'T':                    /* Test of vertex shading (not used) */
  153.       test_vtxshade = 1;
  154.       break;
  155.  
  156.     case 'V':                    /* Run in NTSC mode */
  157.       if ((env_var = getenv("HOSTTYPE")) != 0)
  158.     if (strcmp("iris4d",env_var) == 0) {
  159.       Option.VCRmode = REC;
  160.       Option.UseVCR = TRUE;
  161.       Option.debug = FALSE;
  162.       Option.statistics = FALSE;
  163.       fprintf(stderr,"Recording in NTSC mode\n");
  164.     } else {
  165.       Option.UseVCR = FALSE;
  166.       fprintf(stderr,"Sorry can't run video on a %s\n", env_var);
  167.       exit(1);
  168.     }  
  169.       break;
  170.  
  171.     case 'd':                     /* Run in debug mode */
  172.       fprintf(stderr,"In debug mode\n");
  173.       Option.debug = TRUE;
  174.       break;
  175.       
  176.     case 'f': /* ray cast or hemicube ffs */
  177.       shift;
  178.       if (argc < 2) {
  179.     fprintf(stderr,"Not enough ff parameters\n");    
  180.     exit(1);
  181.       }
  182.  
  183.       /* Hemicube =0, or ray cast = 1 */
  184.       if ((atoi(*argv) == 0) || (atoi(*argv) == 1)) {
  185.     Option.ff_raytrace = atoi(*argv); shift;
  186.     /* printf("hc/rt = %d\n", Option.ff_raytrace); */
  187.       } else {
  188.     fprintf(stderr,"Incorrect ff parameters\n");    
  189.     exit(1);
  190.       }
  191.  
  192.       /* 0 = circle, 1=ellipse, 2=analytic */
  193.       if (atoi(*argv) == 0) 
  194.     FF_Options.sample_shape = DISC_FF;
  195.       else if (atoi(*argv) == 1) 
  196.     FF_Options.sample_shape = ELLIPSE_FF;
  197.       else if (atoi(*argv) == 2) {
  198.     FF_Options.sample_shape = DISC_FF;
  199.     FF_Options.fftype = ANALYTIC_FF;
  200.       }
  201.  
  202.       if ((atoi(*argv) < 0) || (atoi(*argv) > 2)) {
  203.     fprintf(stderr,"Incorrect ff parameters\n");    
  204.     exit(1);
  205.       } else {
  206.     /* printf("shape = %d\n", FF_Options.sample_shape);
  207.        printf("type = %d\n", FF_Options.fftype); */
  208.       }
  209.       enough_args++;
  210.       break;
  211.  
  212.     case 'h':                    /* Help */
  213.       Usage();
  214.       LongUsage();
  215.       exit(0);
  216.       break;
  217.  
  218.     case 'p':                    /* Patch file name */
  219.       shift;
  220.       if (!argc) {
  221.     fprintf(stderr,"No patch filename given\n"); 
  222.     exit(1);
  223.       }
  224.       env_var = *argv;
  225.       Option.meshfilename = env_var;
  226.       /* printf("Mesh = %s\n", Option.meshfilename); */
  227.       enough_args++;
  228.       break;
  229.  
  230.     case 's':                     /* Statistics  */
  231.       shift;
  232.       if (argc < 1) {
  233.     fprintf(stderr,"Not enough stat parameter\n");    
  234.     exit(1);
  235.       }    
  236.       Option.statistics = TRUE;
  237.  
  238.       /* Stdout = 0, or File = 1 */
  239.       if (atoi(*argv) == 0)      Option.device = PRINT;
  240.       else if (atoi(*argv) == 1)  Option.device = FILES;
  241.       else {
  242.     fprintf(stderr,"Incorrect stat output parameter\n");    
  243.     exit(1);
  244.       }
  245.       fprintf(stderr,"Statistics sent to %s.\n",
  246.           (Option.device == PRINT ? "terminal" : "file"));
  247.       break;
  248.  
  249.       /* case 'P': */                    /* Directory containing patch files */
  250.       /* Option.data_dir = ".";
  251.      fprintf(stderr,"Set patch directory to current. Not done yet.\n"); 
  252.       break; */
  253.  
  254.     case 'v':                    /* Patch file name */
  255.       shift;
  256.       if (!argc) {
  257.     fprintf(stderr,"No view filename given\n");
  258.     exit(1);
  259.       }
  260.       env_var = *argv;
  261.       Option.viewfilename = env_var;
  262.       enough_args++;
  263.       break;
  264.       
  265.     default:
  266.       Usage();
  267.       exit(-1);
  268.     }
  269.     shift;
  270.   }
  271.  
  272.   /* Check for enough args */
  273.   if (enough_args < 4) {
  274.     Usage();
  275.     exit(1);
  276.   }
  277. }
  278.