home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / graf / fract4.zip / CMDFILES.C < prev    next >
C/C++ Source or Header  |  1989-12-01  |  29KB  |  878 lines

  1.  
  2. /*
  3.     Command-line / Command-File Parser Routines
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "fractint.h"
  11.  
  12. /* variables defined by the command line/files processor */
  13. char    temp1[256];        /* temporary strings        */
  14. char    ifsfilename[80];          /* IFS code file */
  15. char    readname[80];         /* name of fractal input file */
  16. char    potfile[80];        /* save potential using this name  */
  17. char    savename[80];        /* save files using this name */
  18. char    ifs3dfilename[80];          /* IFS 3D code file */
  19. int    askvideo;        /* flag for video prompting */
  20. char    floatflag = 0;         /* flag for float calcs */
  21. int    biomorph  = -1;         /* flag for biomorph */
  22. int     forcesymmetry = 999;   /* force symmetry */
  23. int     showfile;            /* has file been displayed yet? */
  24. int rflag, rseed;    /* Random number seeding flag and value */
  25. int decomp[2];        /* Decomposition coloring */
  26. int    warn;            /* 0 if savename warnings off, 1 if on */
  27. int    sound;            /* 0 if sound is off, 1 if on */
  28. int    debugflag;        /* internal use only - you didn't see this */
  29. int    timerflag;        /* you didn't see this, either */
  30. int    cyclelimit;        /* color-rotator upper limit */
  31. int    inside;            /* inside color: 1=blue     */
  32. int    display3d;        /* 3D display flag: 0 = OFF */
  33. int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  34. int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  35. int    initbatch;        /* 1 if batch run (no kbd)  */
  36. int    initmode;        /* initial video mode       */
  37. int    inititer;        /* initial value of maxiter */
  38. int    initincr;        /* initial maxiter incrmnt  */
  39. int    initpass;        /* initial pass mode        */
  40. int    initsolidguessing;    /* initial solid-guessing md*/
  41. int    initfractype;        /* initial type set flag    */
  42. int    initcyclelimit;        /* initial cycle limit      */
  43. int    initcorners;        /* initial flag: corners set*/
  44. int bailout = 0;            /* user input bailout value */
  45. double   inversion[3];      /* radius, xcenter, ycenter */
  46. double    initxmin,initxmax;    /* initial corner values    */
  47. double    initymin,initymax;    /* initial corner values    */
  48. double    initparam[4];        /* initial parameters       */
  49. extern double  potparam[];  /* potential parameters  */
  50. extern int Printer_Resolution, LPTNumber, Printer_Type;   /* for printer functions */
  51. int    transparent[2];        /* transparency min/max values */
  52. int    LogFlag;            /* Logarithmic palette flag: 0 = no */
  53.  
  54. extern unsigned char olddacbox[256][3];    /* Video-DAC saved values */
  55. extern unsigned char dacbox[256][3];       /* Video-DAC values */
  56.  
  57. extern    char *fkeys[];        /* Function Key names for display table */
  58.  
  59. static    int toolsfile;        /* 1 if inside a TOOLS file, 0 otherwise */
  60.  
  61. /*
  62.     cmdfiles(argc,argv) process the command-line arguments
  63.         it also processes the 'sstools.ini' file and any
  64.         indirect files ('fractint @myfile')
  65. */
  66.  
  67. int cmdfiles(argc,argv)
  68. int argc;
  69. char *argv[];
  70. {
  71. double    atof(), ftemp;                /* floating point stuff    */
  72. int    i, j, k, l;                /* temporary loop counters */
  73.  
  74. char    param[81];                /* temporary strings        */
  75.  
  76. char tempstring[101];                /* temporary strings        */
  77. FILE *initfile;                    /* for .INI, '@' files      */
  78.  
  79. rflag = 0;                    /* Use time() for srand() */
  80. floatflag = 0;                    /* turn off the float flag */
  81. biomorph = -1;                    /* turn off biomorph flag */
  82. askvideo = 1;                    /* turn on video-prompt flag */
  83.  
  84. warn = 0;                    /* no warnings on savename */
  85. sound = 1;                    /* sound is on            */
  86. initbatch = 0;                    /* not in batch mode      */
  87. initmode = -1;                    /* no initial video mode  */
  88. inside = 1;                    /* inside color = blue    */
  89. inititer = 150;                    /* initial maxiter        */
  90. initincr = 50;                    /* initial iter increment */
  91. initpass = 2;                    /* initial dual-pass mode */
  92. initsolidguessing = 1;                /* initial solid-guessing */
  93. initfractype = 0;                /* initial type Set flag  */
  94. initcorners = 0;                /* initial flag: no corners */
  95. for (i = 0; i < 4; i++) initparam[i] = 0;    /* initial parameter values */
  96. for (i = 0; i < 3; i++) potparam[i]  = 0.0; /* initial potential values */
  97. for (i = 0; i < 3; i++) inversion[i] = 0.0;  /* initial invert values */
  98.  
  99. initxmin = -2.5; initxmax = 1.5;        /* initial corner values  */
  100. initymin = -1.5; initymax = 1.5;        /* initial corner values  */
  101. strcpy(savename,"fract001");            /* initial save filename  */
  102. potfile[0] = NULL;                              /* initial potfile value */
  103. initcyclelimit=55;                /* spin-DAC default speed limit */
  104. transparent[0] = transparent[1] = 0;        /* no min/max transparency */
  105. LogFlag = 0;                    /* no logarithmic palette */
  106. ifsfilename[0] = NULL;          /* initial ifs file name */
  107. ifs3dfilename[0] = NULL;        /* initial ifs3d file value */
  108.  
  109. debugflag = 0;                    /* debugging flag(s) are off */
  110. timerflag = 0;                    /* timer flags are off      */
  111.  
  112. display3d = 0;                    /* 3D display is off        */
  113. overlay3d = 0;                    /* 3D overlay is off        */
  114.  
  115. /* 3D defaults */
  116. SPHERE    = FALSE;    
  117. XROT      = 60;
  118. YROT      = 30;
  119. ZROT      = 0;
  120. XSCALE    = 90;
  121. YSCALE    = 90;
  122. ROUGH     = 30;   
  123. WATERLINE = 0;
  124. FILLTYPE  = 0;
  125. ZVIEWER   = 0;
  126. XSHIFT    = 0;
  127. YSHIFT    = 0;
  128. XLIGHT    = 0;
  129. YLIGHT    = 0;
  130. ZLIGHT    = 1;
  131. LIGHTAVG  = 1;
  132.  
  133. *readname= NULL;                                  /* initial input filename */
  134.  
  135. Printer_Type = 2;                /* assume an IBM/EPSON */
  136. if (Printer_Type == 1)                /* assume low resolution */
  137.     Printer_Resolution = 75;
  138. else
  139.     Printer_Resolution = 60;
  140. LPTNumber = 1 ;                    /* assume LPT1 */
  141.  
  142. toolsfile = 1;                    /* enable TOOLS processing */
  143.  
  144. findpath("sstools.ini", tempstring);        /* look for SSTOOLS.INI */
  145. if (tempstring[0] != 0)             /* found it! */
  146.     if ((initfile = fopen(tempstring,"r")) != NULL) 
  147.         cmdfile(initfile);        /* process it */
  148.  
  149. toolsfile = 0;                    /* disable TOOLS processing */
  150.  
  151. for (i = 1; i < argc; i++) {            /* cycle through args    */
  152.     strcpy(param,argv[i]);
  153.     strlwr(param);                /* using lower case    */
  154.     for (j = 1; j < strlen(param) && param[j] != '='; j++) ;
  155.  
  156.     if (j < strlen(param)) {        /* xxx=yyy argument? */
  157.         cmdarg(param);            /* process it */
  158.         continue;
  159.         }
  160.         
  161.     if (param[0] == ';')            /* start of comments? */
  162.         break;                /* we done! */
  163.         
  164.     if (param[0] == '@') {            /* command indirection? */
  165.         if ((initfile = fopen(¶m[1],"r")) != NULL) {
  166.             cmdfile(initfile);    /* process it */
  167.             continue;
  168.             }
  169.         else argerror(param);        /* oops.  error. */
  170.         }
  171.     
  172.         strcpy(readname,param);            /* else, assume a filename */
  173.         showfile = 1;
  174.  
  175.     }
  176.  
  177. return(0);                    /* we done */
  178. }
  179.  
  180. /*
  181.     cmdfile(handle) processes a single command-file.
  182.         if (toolsfile), it looks for '[...]' codes as well
  183. */
  184.  
  185. cmdfile(handle)                /* process a command file of some sort */
  186. FILE *handle;
  187. {
  188. char line[513];
  189. int toolssection;
  190. int i, j;
  191.  
  192. toolssection = 1;            /* assume an implied [fractint] */
  193.  
  194. while (fgets(line,512,handle) != NULL) {    /* read thru a line at a time */
  195.     i = strlen(line);
  196.     if (i > 0 && line[i-1] == '\n') line[i-1] = 0;    /* strip trailing \n */
  197.  
  198.     strlwr(line);                /* convert to lower case */
  199.     if (toolsfile && line[0] == '[') {    /* TOOLS-style header */
  200.         toolssection = 0;
  201.         if (strncmp(line,"[fractint]",10) == 0)
  202.             toolssection = 1;
  203.         continue;            /* ignore this line in any case */
  204.         }
  205.  
  206.     if (! toolssection) continue;        /* not our section */
  207.  
  208.     i = -1;                    /* get a running start */
  209.     while (line[++i] != 0) {        /* scan through the line */
  210.         if (line[i] <= ' ') continue;    /* white space */
  211.         if (line[i] == ';') break;    /* comments */
  212.         j = i;                /* argument starts here */
  213.         while (line[++i] > ' ');    /* find the argument end */
  214.         line[i] = 0;            /* force an end-of-string */
  215.         if (j == 0 && strcmp(&line[j],"fractint") == 0)
  216.             continue;        /* skip leading "fractint " */
  217.         cmdarg(&line[j]);        /* process the argument */
  218.         }
  219.     }
  220.  
  221. fclose(handle);
  222. }
  223.  
  224. /*
  225.     cmdarg(string) processes a single command-line/command-file argument
  226.         isolate 'variable=value' (or 'variable:=value') into
  227.         its components and process it.
  228.         All components have already been converted to lower case.
  229. */
  230.  
  231. cmdarg(char *param)                /* process a single argument */
  232. {
  233.     char    variable[21];            /* variable name goes here */
  234.     char    value[81];            /* variable value goes here*/
  235.     int    numval;                /* numeric value of arg    */
  236.     char    charval;            /* character value of arg  */
  237.  
  238.     double    atof(), ftemp;            /* floating point stuff    */
  239.     int    i, j, k, l;            /* temporary loop counters */
  240.     char    *slash;                /* temporary string ptr    */
  241.  
  242.     strlwr(param);                /* using lower case       */
  243.     for (j = 1; j < strlen(param) && param[j] != '='; j++) ;
  244.     if (j > 20 || j >= strlen(param))
  245.         argerror(param);        /* oops.  '=' not found   */
  246.  
  247.     strncpy(variable,param,j);        /* get the variable name  */
  248.     variable[j] = 0;            /* truncate it            */
  249.     if (j > 1 && variable[j-1] == ':')    /* strip any trailing ':' */
  250.         variable[j-1] = 0;
  251.     strcpy(value,¶m[j+1]);        /* get the value string   */
  252.     numval = atoi(value);            /* get any numeric value  */
  253.     charval = value[0];            /* get any letter  value  */
  254.  
  255.     if (strcmp(variable,"filename") == 0) {        /* filename=?    */
  256.             strcpy(readname,value);            /* set up filename */
  257.         showfile = 1;
  258.         }
  259.     else if( strcmp(variable, "map") == 0 ) {    /* map option */
  260.         SetColorPaletteName( value );
  261.         }
  262.     else if (strcmp(variable,"batch") == 0 ) {    /* batch=?    */
  263.         if (charval == 'c') {            /* config run   */
  264.             makeconfig();
  265.             goodbye();
  266.             }
  267.         if (charval == 'y')            /* batch = yes  */
  268.             initbatch = 1;
  269.         }
  270.     else if (strcmp(variable,"warn") == 0 ) {    /* warn=?    */
  271.         if (charval == 'y')
  272.             warn = 1;
  273.         }
  274.     else if (strcmp(variable,"type") == 0 ) {    /* type=?    */
  275.         if (value[strlen(value)-1] == '*')
  276.             value[strlen(value)-1] = 0;
  277.         for (k = 0; fractalspecific[k].name != NULL; k++)
  278.             if (strcmp(value,fractalspecific[k].name) == 0)
  279.                 break;
  280.         if (fractalspecific[k].name == NULL) argerror(param);
  281.         initfractype = k;
  282.         if (initcorners == 0) {
  283.             initxmin = fractalspecific[initfractype].xmin;
  284.             initxmax = fractalspecific[initfractype].xmax;
  285.             initymin = fractalspecific[initfractype].ymin;
  286.             initymax = fractalspecific[initfractype].ymax;
  287.             }
  288.         }
  289.     else if (strcmp(variable,"inside") == 0 ) {    /* inside=?    */
  290.         inside = numval;
  291.         }
  292.     else if (strcmp(variable,"maxiter") == 0) {    /* maxiter=?    */
  293.         if (numval < 10 || numval > 32000) argerror(param);
  294.         inititer = numval;
  295.         }
  296.     else if (strcmp(variable,"iterincr") == 0) {    /* iterincr=?    */
  297.         if (numval <= 0 || numval > inititer) argerror(param);
  298.         initincr = numval;
  299.         }
  300.     else if (strcmp(variable,"passes") == 0) {    /* passes=?    */
  301.         initsolidguessing = 0;
  302.         if ( charval == 'g') {            /* solid-guessing */
  303.             numval = 2;
  304.             initsolidguessing = 1;
  305.             }
  306.         if (numval < 1 || numval > 2) argerror(param);
  307.         initpass = numval;
  308.         }
  309.     else if (strcmp(variable,"cyclelimit") == 0 ) {    /* cyclelimit=?    */
  310.         if (numval > 1 && numval <= 256)
  311.             initcyclelimit = numval;
  312.         }
  313.     else if (strcmp(variable,"savename") == 0) {    /* savename=?    */
  314.         strcpy(savename,value);
  315.         }
  316.     else if (strcmp(variable,"video") == 0) {    /* video=?    */
  317.         for (k = 0; k < maxvideomode; k++) {
  318.             strcpy(variable,fkeys[k]);
  319.             strlwr(variable);
  320.             if (strcmp(variable, value) == 0)
  321.                 break;
  322.             }
  323.             if (k == maxvideomode) argerror(param);
  324.         initmode = k;
  325.         }
  326.     else if (strcmp(variable,"potential") == 0) {    /* potential=?    */
  327.         k = 0;
  328.         slash = strchr(param,'=');
  329.         while ( k < 4) {
  330.             if(k < 3)  
  331.                 potparam[k++] = atoi(++slash);
  332.                else {
  333.                 k++;
  334.                 strcpy(potfile,++slash);
  335.                 }   
  336.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  337.             }
  338.         }
  339.     else if (strcmp(variable,"params") == 0) {    /* params=?,?    */
  340.         k = 0;
  341.         slash = strchr(param,'=');
  342.         while ( k < 4) {
  343.             initparam[k++] = atof(++slash);
  344.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  345.             }
  346.         }
  347.     else if (strcmp(variable,"corners") == 0) {    /* corners=?,?,?,? */
  348.             initcorners = 1;
  349.         slash = strchr(param,'=');
  350.         initxmin=atof(++slash);
  351.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  352.         initxmax=atof(++slash);
  353.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  354.         initymin=atof(++slash);
  355.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  356.         initymax=atof(++slash);
  357.         }
  358.     else if (strcmp(variable,"3d") == 0) {        /* 3d=?/?/..    */
  359.         display3d = 1;                /* turn on 3D */
  360.         k = 0;
  361.         slash = strchr(param,'=');
  362.         while ( k < 20) {
  363.             l = atoi(++slash);
  364.             if (slash[0] > 32 && slash[0] != '/') init3d[k] = l;
  365.             if (k == 0 && SPHERE) {
  366.                 /* reset sphere defaults */
  367.                 SPHERE    = TRUE;    
  368.                 PHI1      =  180;    
  369.                 PHI2      =  0;   
  370.                 THETA1    =  -90;   
  371.                 THETA2    =  90;   
  372.                 RADIUS    =  100;   
  373.                 ROUGH     =  30;   
  374.                 WATERLINE = 0;
  375.                 FILLTYPE  = 2;
  376.                 ZVIEWER   = 0;
  377.                 XSHIFT    = 0;
  378.                 YSHIFT    = 0;
  379.                 XLIGHT    = 0;
  380.                 YLIGHT    = 0;
  381.                   ZLIGHT    = 1;
  382.                 LIGHTAVG  = 1;
  383.                 }   
  384.             if (k == 0 && !SPHERE) {
  385.                 SPHERE    = FALSE;    
  386.                 XROT      = 60;
  387.                 YROT      = 30;
  388.                 ZROT      = 0;
  389.                 XSCALE    = 90;
  390.                 YSCALE    = 90;
  391.                 ROUGH     = 30;   
  392.                 WATERLINE = 0;
  393.                 FILLTYPE  = 0;
  394.                 ZVIEWER   = 0;
  395.                 XSHIFT    = 0;
  396.                 YSHIFT    = 0;
  397.                 XLIGHT    = 0;
  398.                 YLIGHT    = 0;
  399.                 ZLIGHT    = 1;
  400.                 LIGHTAVG  = 1;
  401.                 }
  402.             if ((slash = strchr(slash,'/')) == NULL) break;
  403.             k++;
  404.             }
  405.         }
  406.     else if (strcmp(variable,"sphere") == 0 ) {    /* sphere=?    */
  407.         if (charval == 'y') 
  408.             SPHERE    = TRUE;    
  409.         else if (charval == 'n')
  410.             SPHERE    = FALSE;
  411.         else 
  412.             argerror(param);        /* oops.  error. */
  413.         }
  414.     else if (strcmp(variable,"rotation") == 0) {    /* rotation=?/?/?    */
  415.         k = 0;
  416.         slash = strchr(param,'=');
  417.         while ( k < 3) {
  418.             l = atoi(++slash);
  419.             if (slash[0] > 32 && slash[0] != '/') *(&XROT+k) = l;
  420.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  421.             k++;
  422.             }
  423.         }
  424.     else if (strcmp(variable,"scalexyz") == 0) {    /* scalexyz=?/?/?    */
  425.         k = 0;
  426.         slash = strchr(param,'=');
  427.         while ( k < 3) {
  428.             l = atoi(++slash);
  429.             if (slash[0] > 32 && slash[0] != '/') *(&XSCALE+k) = l;
  430.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  431.             k++;
  432.             }
  433.         }
  434.     /* "rough" is really scale z, but we add it here for convenience */
  435.     else if (strcmp(variable,"roughness") == 0) {    /* roughness=?    */
  436.         ROUGH = numval;
  437.         }
  438.     else if (strcmp(variable,"waterline") == 0) {    /* waterline=?    */
  439.         if (numval<0) argerror(param);
  440.         WATERLINE = numval;
  441.         }
  442.     else if (strcmp(variable,"filltype") == 0) {    /* filltype=?    */
  443.         if (numval < 0 || numval > 6) argerror(param);
  444.         FILLTYPE = numval;
  445.         }
  446.     else if (strcmp(variable,"perspective") == 0) {    /* perspective=?    */
  447.         k = 0;
  448.         slash = strchr(param,'=');
  449.         while ( k < 1) {
  450.             l = atoi(++slash);
  451.             if (slash[0] > 32 && slash[0] != '/') *(&ZVIEWER+k) = l;
  452.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  453.             k++;
  454.             }
  455.         }
  456.     else if (strcmp(variable,"xyshift") == 0) {    /* xyshift=?/?    */
  457.         k = 0;
  458.         slash = strchr(param,'=');
  459.         while ( k < 2) {
  460.             l = atoi(++slash);
  461.             if (slash[0] > 32 && slash[0] != '/') *(&XSHIFT+k) = l;
  462.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  463.             k++;
  464.             }
  465.         }
  466.     else if (strcmp(variable,"lightsource") == 0) {    /* lightsource=?/?/?    */
  467.         k = 0;
  468.         slash = strchr(param,'=');
  469.         while ( k < 3) {
  470.             l = atoi(++slash);
  471.             if (slash[0] > 32 && slash[0] != '/') *(&XLIGHT+k) = l;
  472.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  473.             k++;
  474.             }
  475.         }
  476.     else if (strcmp(variable,"smoothing") == 0) {    /* smoothing=?    */
  477.         if (numval<0) argerror(param);
  478.         LIGHTAVG = numval;
  479.         }
  480.     else if (strcmp(variable,"latitude") == 0) {    /* latitude=?/?    */
  481.         k = 0;
  482.         slash = strchr(param,'=');
  483.         while ( k < 2) {
  484.             l = atoi(++slash);
  485.             if (slash[0] > 32 && slash[0] != '/') *(&THETA1+k) = l;
  486.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  487.             k++;
  488.             }
  489.         }
  490.     else if (strcmp(variable,"longitude") == 0) {    /* longitude=?/?    */
  491.         k = 0;
  492.         slash = strchr(param,'=');
  493.         while ( k < 2) {
  494.             l = atoi(++slash);
  495.             if (slash[0] > 32 && slash[0] != '/') *(&PHI1+k) = l;
  496.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  497.             k++;
  498.             }
  499.         }
  500.     else if (strcmp(variable,"radius") == 0) {    /* radius=?    */
  501.         if (numval<0) argerror(param);
  502.         RADIUS = numval;
  503.         }
  504.     else if (strcmp(variable,"invert") == 0) {    /* invert=?,?,?    */
  505.         k = 0;
  506.         slash = strchr(param,'=');
  507.         while ( k < 3) {
  508.             extern int invert;
  509.             inversion[k++] = atof(++slash);
  510.             if(inversion[0] != 0.0)
  511.                 invert = k;      /* record highest inversion parameter set */
  512.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  513.             }
  514.         }
  515.     else if (strcmp(variable,"askvideo") == 0 ) {     /* askvideo=?    */
  516.         if (charval == 'y')
  517.             askvideo = 1;
  518.         else if (charval == 'n')
  519.                 askvideo = 0;
  520.             else
  521.                 argerror(param);
  522.             }    
  523.     else if (strcmp(variable,"float") == 0 ) {     /* float=?    */
  524.         if (charval == 'y')
  525.             floatflag = 1;
  526.         else if (charval == 'n')
  527.                     floatflag = 0;
  528.             else
  529.                 argerror(param);
  530.             }    
  531.     else if (strcmp(variable,"biomorph") == 0 ) {     /* biomorph=?    */
  532.         biomorph = numval;
  533.               }   
  534.     else if (strcmp(variable,"bailout") == 0 ) {     /* bailout=?    */
  535.         if (numval < 4 || numval > 32000) argerror(param);
  536.         bailout = numval;
  537.         }
  538.     else if (strcmp(variable,"symmetry") == 0 ) {     /* symmetry=?    */
  539.         if     (strcmp(value,"xaxis" )==0) forcesymmetry = XAXIS;
  540.         else if(strcmp(value,"yaxis" )==0) forcesymmetry = YAXIS;
  541.         else if(strcmp(value,"xyaxis")==0) forcesymmetry = XYAXIS;
  542.         else if(strcmp(value,"origin")==0) forcesymmetry = ORIGIN;
  543.         else if(strcmp(value,"pi"    )==0) forcesymmetry = PI_SYM;
  544.         else if(strcmp(value,"none"  )==0) forcesymmetry = NOSYM;
  545.         else argerror(param);
  546.         }
  547.  
  548.     else if (strcmp(variable,"printer") == 0 ) {    /* printer=?    */
  549.         if (charval=='h') Printer_Type=1; /* HP LaserJet           */
  550.         if (charval=='i') Printer_Type=2; /* IBM Graphics          */
  551.         if (charval=='e') Printer_Type=2; /* Epson (model?)        */
  552.         if (Printer_Type == 1)        /* assume low resolution */
  553.             Printer_Resolution = 75;
  554.         else
  555.             Printer_Resolution = 60;
  556.         slash=strchr(param,'=');
  557.         if ((slash=strchr(slash,'/')) == NULL) return;
  558.         if ((k=atoi(++slash)) > 0) Printer_Resolution=k;
  559.         if ((slash=strchr(slash,'/')) == NULL) return;
  560.         if ((k=atoi(++slash))> 0) LPTNumber = k;
  561.         }
  562.     else if (strcmp(variable,"transparent") == 0) { /* transparent? */
  563.         slash = strchr(param,'=');
  564.         if ((k=atoi(++slash)) > 0) transparent[0] = k;
  565.         transparent[1] = transparent[0];
  566.         if ((slash=strchr(slash,'/')) == NULL) return;
  567.         if ((k=atoi(++slash)) > 0) transparent[1] = k;
  568.         }
  569.     else if (strcmp(variable,"sound") == 0 ) {    /* sound=?    */
  570.         sound = 0;                /* sound is off */
  571.         if (charval == 'y')
  572.             sound = 1;            /* sound is on  */
  573.         }
  574.     else if (strcmp(variable,"logmap") == 0 ) {    /* logmap=?    */
  575.         LogFlag = 0;                /* palette is continuous */
  576.         if (charval == 'y')
  577.             LogFlag = 1;            /* palette is logarithmic */
  578.         }
  579.     else if (strcmp(variable,"debugflag") == 0 ||
  580.          strcmp(variable,"debug") == 0) {    /* internal use only */
  581.         debugflag = numval;
  582.         timerflag = debugflag & 1;        /* separate timer flag */
  583.         debugflag -= timerflag;
  584.         }
  585.     else if (strcmp(variable,"ifs") == 0) {        /* ifs=?    */
  586.         strcpy(ifsfilename,value);
  587.         if (strchr(value,'.') == NULL)
  588.             strcat(ifsfilename,".ifs");
  589.         ifsgetfile();
  590.         }
  591.     else if (strcmp(variable,"ifs3d") == 0) {    /* ifs3d=?    */
  592.         strcpy(ifs3dfilename,value);
  593.         if (strchr(value,'.') == NULL)
  594.             strcat(ifs3dfilename,".ifs");
  595.         ifs3dgetfile();
  596.         }
  597.     else if (strcmp(variable,"ifscodes") == 0) {    /* ifscodes=?,?,?,? */
  598.         int ifsindex;
  599.         slash = strchr(param,'=');
  600.         ifsindex=atoi(++slash) - 1;
  601.         if(ifsindex < 0 || ifsindex > NUMIFS) argerror(param);
  602.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  603.         initifs[ifsindex][0]=atof(++slash);
  604.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  605.         initifs[ifsindex][1]=atof(++slash);
  606.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  607.         initifs[ifsindex][2]=atof(++slash);
  608.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  609.         initifs[ifsindex][3]=atof(++slash);
  610.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  611.         initifs[ifsindex][4]=atof(++slash);
  612.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  613.         initifs[ifsindex][5]=atof(++slash);
  614.         if ((slash = strchr(slash,'/')) == NULL) argerror(param);
  615.         initifs[ifsindex][6]=atof(++slash);
  616.         }
  617.     else if (strcmp(variable, "rseed") == 0) {
  618.         rseed = numval;
  619.         rflag = 1;
  620.         }
  621.     else if (strcmp(variable, "decomp") == 0) {
  622.         k = 0;
  623.         slash = strchr(param,'=');
  624.         while (k < 2) {
  625.             decomp[k++] = atoi(++slash);
  626.             if ((slash = strchr(slash,'/')) == NULL) break;
  627.             }
  628.         }
  629.     else argerror(param);
  630. }
  631.  
  632. #ifdef __TURBOC__
  633. #include <dir.h>
  634. #endif
  635.  
  636. findpath(char *filename, char *fullpathname)    /* return full pathnames */
  637. {
  638.  
  639. fullpathname[0] = 0;                /* indicate none found */
  640.  
  641. #ifdef __TURBOC__                /* look for the file */
  642. strcpy(fullpathname,searchpath(filename));
  643. #else
  644. _searchenv(filename,"PATH",fullpathname);
  645. #endif
  646. if (fullpathname[0] != 0)             /* found it! */
  647.     if (strncmp(&fullpathname[2],"\\\\",2) == 0)    /* stupid klooge! */
  648.         strcpy(&fullpathname[3],filename);
  649. }
  650.  
  651. /* keep this in synch with fractals.c !!! */
  652. #define IFS          26
  653. #define IFS3D        27
  654. extern int fractype;
  655.  
  656. ifsgetparams()            /* prompt for IFS params */
  657. {
  658. char *filename;
  659. float far *initarray;
  660. static char ifstype = '2';
  661. int totrows, totcols;
  662. int i, j, numlines;
  663. FILE *tempfile;
  664.  
  665. setfortext();            /* switch to text mode */
  666.  
  667. memcpy(olddacbox,dacbox,256*3);        /* save the DAC */
  668. setvideomode(3,0,0,0);                 /* clear the screen entirely */
  669. memcpy(dacbox,olddacbox,256*3);        /* restore the DAC */
  670.  
  671.  
  672. ifsgetfile();            /* read in any "IFS=" file */
  673.  
  674. ifs3dgetfile();            /* read in any "IFS3D=" file */
  675.  
  676. filename = ifsfilename;
  677. initarray = &initifs[0][0];
  678. totrows = NUMIFS;
  679. totcols = IFSPARM;
  680.  
  681. /* assume if an IFS type is already selected, user wants to edit that type */
  682. if(fractype == IFS)
  683.    ifstype = '2';
  684. else if (fractype == IFS3D)
  685.    ifstype = '3';
  686. else
  687. {
  688.    printf("Edit 2D IFS, 3D IFS, or generic 3D Transform parameters?\n\n");
  689.    printf("     (2, 3, or t - if not %c) --> ",ifstype);
  690.    while((i=getch())!='2' && i!='3' && i!='t' && i!='T' && i!=13);
  691.    if (i == 't' || i == 'T') {
  692.        printf("\n\n");
  693.        getifs3dstuff();
  694.        return;
  695.        }
  696.    if (i == '2' || i == '3') ifstype = i;
  697. }
  698. if (ifstype == '3') {
  699.    filename = ifs3dfilename;
  700.    initarray = &initifs3d[0][0];
  701.    totrows = NUMIFS;
  702.    totcols = IFS3DPARM;
  703.    }
  704.  
  705. for ( ;; ) {
  706.  
  707.     for (numlines = 0; numlines < totrows; numlines++)    /* find the first zero entry */
  708.         if (initarray[(numlines * totcols) + totcols - 1] <= 0.0001) break;
  709.  
  710.     memcpy(olddacbox,dacbox,256*3);        /* save the DAC */
  711.     setvideomode(3,0,0,0);                 /* clear the screen entirely */
  712.     memcpy(dacbox,olddacbox,256*3);        /* restore the DAC */
  713.  
  714.     printf(" Your current IFS Parameters are: \n\n");
  715.     printf("#   a     b     c     d     e     f");
  716.     if (ifstype == '3')
  717.          printf("     g     h     i     j     k     l");
  718.     printf("    prob \n\n");
  719.  
  720.     for (i = 0; i < numlines; i++) {
  721.         printf("%1d", i+1);
  722.         for (j = 0; j < totcols; j++)
  723.             printf("%6.2f", (float )initarray[(i*totcols)+j]);
  724.         printf("\n");
  725.         }
  726.  
  727.     printf("\n\n Enter the number of the line you want to edit\n");
  728.     printf("  (or RESTORE to start from another (.IFS) file, or SAVE to\n");
  729.     if(ifstype == '3')
  730.     {
  731.        printf("   save your edits in an (.IFS) file, or TRANSFORM to alter\n");
  732.        printf("   3D transformation values, or <ENTER> to end) ==> ");
  733.     }
  734.     else
  735.        printf("   save your edits in an (.IFS) file, or <ENTER> to end) ==> ");
  736.     gets(temp1);
  737.     if (ifstype == '3' && (temp1[0] == 't' || temp1[0] == 'T')) {
  738.        getifs3dstuff();
  739.        continue;
  740.        }
  741.     if (temp1[0] == 's' || temp1[0] == 'S') {
  742.        printf("\n\n enter the name of your new .IFS file ==> ");
  743.        gets(filename);
  744.        if (strchr(filename,'.') == NULL)
  745.           strcat(filename,".ifs");
  746.        if ((tempfile=fopen(filename,"w")) != NULL) {
  747.           for (i = 0; i < numlines; i++) {
  748.              for (j = 0; j < totcols; j++)
  749.                 fprintf(tempfile, "%6.2f", (float)initarray[(i*totcols)+j]);
  750.              fprintf(tempfile, "\n");
  751.              }
  752.           fclose(tempfile);
  753.           }
  754.        return(0);
  755.        }
  756.     if (temp1[0] == 'r' || temp1[0] == 'R') {
  757.        printf("\n\n enter the name of your new .IFS file ==> ");
  758.        gets(filename);
  759.        if (strchr(filename,'.') == NULL)
  760.           strcat(filename,".ifs");
  761.        if (ifstype == '3')
  762.           ifs3dgetfile();
  763.        else
  764.           ifsgetfile();
  765.        continue;
  766.        }
  767.     i = atoi(temp1) - 1;
  768.     if (temp1[0] == 0 || i < 0 || i > numlines) return(0);
  769.  
  770.     for (j = 0; j < totcols; j++) {
  771.         printf(" Parameter %2d (if not %6.2f) ", j, (float)initarray[(i*totcols)+j]);
  772.         gets(temp1);
  773.         if (temp1[0] != 0)
  774.             initarray[(i*totcols)+j] = atof(temp1);
  775.         }
  776.     }
  777. }
  778. getifs3dstuff()
  779. {
  780.    int k;
  781.    printf("X-axis rotation in degrees (if not %3d) ",XROT);
  782.    gets(temp1);
  783.    k = atoi(temp1);
  784.    if (temp1[0] >19) XROT = k;
  785.    printf("Y-axis rotation in degrees (if not %3d) ",YROT);
  786.    gets(temp1);
  787.    k = atoi(temp1);
  788.    if (temp1[0] >19) YROT = k;
  789.    printf("Z-axis rotation in degrees (if not %3d)  ",ZROT);
  790.    gets(temp1);
  791.    k = atoi(temp1);
  792.    if (temp1[0] >19) ZROT = k;
  793.    /*
  794.    printf("X-axis scaling factor in pct  (if not %3d)  ",XSCALE);
  795.    gets(temp1);
  796.    k = atoi(temp1);
  797.    if (temp1[0] >19) XSCALE = k;
  798.    printf("Y-axis scaling factor in pct  (if not %3d)  ",YSCALE);
  799.    gets(temp1);
  800.    k = atoi(temp1);
  801.    if (temp1[0] >19) YSCALE = k;
  802.    printf("Z-axis scaling factor in pct  (if not %3d)  ",ROUGH);
  803.    gets(temp1);
  804.    k = atoi(temp1);
  805.    if (temp1[0] >19) ROUGH = k;
  806.    */
  807.    printf("Perspective 'height' [1 - 999, 0 for no perspective] (if not %3d) ",ZVIEWER);
  808.    gets(temp1);
  809.    k = atoi(temp1);
  810.    if (temp1[0] >19) ZVIEWER = k;
  811.    printf("X shift (positive = right)(if not %3d) ",XSHIFT);
  812.    gets(temp1);
  813.    k = atoi(temp1);
  814.    if (temp1[0] >19) XSHIFT = k;
  815.    printf("Y shift (positive = up    )(if not %3d) ",YSHIFT);
  816.    gets(temp1);
  817.    k = atoi(temp1);
  818.    if (temp1[0] >19) YSHIFT = k;
  819. }
  820.  
  821. ifsgetfile()
  822. {
  823.    FILE     *ifsfile;        /* IFS code file pointer */
  824.    float localifs[IFSPARM];
  825.    int i, j;
  826.  
  827.    /* read in IFS codes from file */
  828.    if (ifsfilename[0] != 0) {
  829.       findpath(ifsfilename, temp1);
  830.       if ( (ifsfile = fopen( temp1,"r" )) != NULL ) {
  831.          i = -1;
  832.          while (fgets(temp1, 155, ifsfile) != NULL) {
  833.             if (++i >= NUMIFS) break;
  834.             sscanf(temp1," %f %f %f %f %f %f %f",
  835.                &localifs[0], &localifs[1], &localifs[2], &localifs[3], 
  836.                &localifs[4], &localifs[5], &localifs[6]  );
  837.             for (j = 0; j < IFSPARM; j++) {
  838.                initifs[i][j]   = localifs[j];
  839.                initifs[i+1][j] = 0.0;
  840.                }
  841.             }
  842.          fclose(ifsfile);                
  843.          }
  844.       ifsfilename[0] = 0;
  845.       }
  846. }
  847.  
  848. ifs3dgetfile()
  849. {
  850.    FILE     *ifsfile;        /* IFS code file pointer */
  851.    float localifs[IFS3DPARM];
  852.    int i, j;
  853.  
  854.    /* read in IFS codes from file */
  855.    if (ifs3dfilename[0] != 0) {
  856.       findpath(ifs3dfilename, temp1);
  857.       if ( (ifsfile = fopen( temp1,"r" )) != NULL ) {
  858.          i = -1;
  859.          while (fgets(temp1, 155, ifsfile) != NULL) {
  860.             if (++i >= NUMIFS) break;
  861.             sscanf(temp1," %f %f %f %f %f %f %f %f %f %f %f %f %f",
  862.                &localifs[ 0], &localifs[ 1], &localifs[ 2],
  863.                &localifs[ 3], &localifs[ 4], &localifs[ 5],
  864.                &localifs[ 6], &localifs[ 7], &localifs[ 8],
  865.                &localifs[ 9], &localifs[10], &localifs[11],
  866.                &localifs[12]
  867.                );
  868.             for (j = 0; j < IFS3DPARM; j++) {
  869.                initifs3d[i][j]   = localifs[j];
  870.                initifs3d[i+1][j] = 0.0;
  871.                }
  872.             }
  873.          fclose(ifsfile);                
  874.          }
  875.       ifs3dfilename[0] = 0;
  876.       }
  877. }
  878.