home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / sndppr3w.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1992-01-24  |  3KB  |  131 lines

  1. /* Main.C
  2. ** 4/26/91
  3. ** mjs
  4. **
  5. ** Entry point for the Sandpaper program.
  6. */
  7.  
  8. #define MAIN            /* make all GLOBALs show up here    */
  9. #include "sp.h"
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     int c, output_fmt = FMT_NON;
  14.     quiet = debug = FALSE;
  15.  
  16.     /* scan command line and catch all the options            */
  17.     while((c = getopt(argc,argv,"PpRrNnDdVvOoQqZzHh?")) != EOF) {
  18.         switch(c) {
  19.  
  20.             case 'N' :    /* NFF(MTV) output format    */
  21.             case 'n' :
  22.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  23.                 output_fmt = FMT_NFF;
  24.                 out_func = nff_out;    /* pt to func    */
  25.                 break;
  26.  
  27.             case 'V' :    /* Vivid output format    */
  28.             case 'v' :
  29.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  30.                 output_fmt = FMT_VIV;
  31.                 out_func = viv_out;    /* pt to func    */
  32.                 break;
  33.  
  34.             case 'O' :    /* Vivid output format    */
  35.             case 'o' :
  36.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  37.                 output_fmt = FMT_VIV1;
  38.                 out_func = viv1_out;    /* pt to func    */
  39.                 break;
  40.  
  41.             case 'R' :    /* Rayshade output format    */
  42.             case 'r' :
  43.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  44.                 output_fmt = FMT_RSH;
  45.                 out_func = rsh_out;    /* pt to func    */
  46.                 break;
  47.  
  48.             case 'D' :    /* DKB output format    */
  49.             case 'd' :
  50.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  51.                 output_fmt = FMT_DKB;
  52.                 out_func = dkb_out;    /* pt to func    */
  53.                 break;
  54.  
  55.             case 'P' :    /* PoV output format    */
  56.             case 'p' :
  57.                 if(output_fmt != FMT_NON) df_erx(argv[0]);
  58.                 output_fmt = FMT_POV;
  59.                 out_func = pov_out;    /* pt to func    */
  60.                 break;
  61.  
  62.             case 'Q' :
  63.             case 'q' : quiet = TRUE; break;
  64.  
  65.             case 'Z' :
  66.             case 'z' : debug = TRUE; break;
  67.  
  68.             case '?' :
  69.             case 'H' :
  70.             case 'h' :
  71.                 instr(argv[0]);        /* bad option    */
  72.                 break;
  73.         }
  74.     }
  75.  
  76.     /* If not specified on the command line, use "raw" by default */
  77.     if(output_fmt == FMT_NON) {
  78.         out_func = raw_out;
  79.     }
  80.  
  81.     /* All set up, now go do business    */
  82.     sp();
  83.  
  84.     return(0);
  85. }
  86.  
  87. /* Duplicate format error exit    */
  88. void df_erx(char *s)
  89. {
  90.     fputs("Only 1 format spec allowed",stderr);
  91.     instr(s);
  92. }
  93.  
  94. void erx(char *s)
  95. {
  96.     fprintf(stderr,"%s\n",s);
  97.     fprintf(stderr,"%d triangles, %d unique points, %d clist entries\n",
  98.         tri_cnt, pt_cnt, cl_cnt);
  99.     exit(1);
  100. }
  101.  
  102. /* The value passed to instr should be the program's name, ie, argv[0]    */
  103. void instr(char *s)
  104. {
  105.     /* This prelimary nonsense is so that the "usage:" line will
  106.     ** show the program's name without drive, path and extension.
  107.     ** I *like* it like that; so sue me.
  108.     */
  109.     char drive[_MAX_DRIVE], dir[_MAX_DIR];
  110.     char fname[_MAX_FNAME], ext[_MAX_EXT];
  111.  
  112.     _splitpath(s,drive,dir,fname,ext);    /* isolate pgm name    */
  113.     strlwr(fname);                /* convert to lower    */
  114.  
  115. fprintf(stderr,"\nUsage: %s [-n | v | r | d ] [-q] [-z]\n",fname);
  116. fputs("Output format flags...\n",stderr);
  117. fputs("   -n : NFF (MTV)\n",stderr);
  118. fputs("   -v : Vivid 2.0\n",stderr);
  119. fputs("   -o : Vivid 1.0\n",stderr);
  120. fputs("   -r : Rayshade\n",stderr);
  121. fputs("   -d : DKB (STAR)\n",stderr);
  122. fputs("   -p : PoV Ray(lowercase)\n",stderr);
  123. fputs("If no format is specified, a 'raw' output is generated\n",stderr);
  124. fputs("-q : quiet, no triangle count displayed while working\n",stderr);
  125. fputs("-z : copious debugging info (not for the squeemish)\n",stderr);
  126.  
  127.     exit(1);
  128. }
  129.  
  130. /*** eof ****************************************************************/
  131.