home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winsrc.zip / CMDFILES.C < prev    next >
Text File  |  1990-12-18  |  46KB  |  1,504 lines

  1.  
  2. /*
  3.     Command-line / Command-File Parser Routines
  4.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  5. */
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <float.h>
  11. #include <ctype.h>
  12. #include "fractint.h"
  13. #ifdef __TURBOC__
  14. #include <dir.h>
  15. #endif
  16.  
  17. /* routines in this module    */
  18.  
  19. void cmdfiles_overlay(void);
  20. int  cmdfiles(int argc, char *argv[]);
  21. void set_3d_defaults(void);
  22. int  readconfig(void);
  23.  
  24. static void cmdfile(FILE *);
  25. static int  cmdarg(char *);
  26. static void argerror(char *);
  27. static void makeconfig(void);
  28.  
  29. /* variables defined by the command line/files processor */
  30. char    temp1[256];        /* temporary strings        */
  31. char    ifsfilename[80];    /* IFS code file */
  32. char    readname[80];        /* name of fractal input file */
  33. char    PrintName[80];        /* Name for print-to-file */
  34. int    potflag=0;        /* continuous potential enabled? */
  35. int    pot16bit;        /* store 16 bit continuous potential values */
  36. char    savename[80];        /* save files using this name */
  37. char    ifs3dfilename[80];    /* IFS 3D code file */
  38. int    gif87a_flag;        /* 1 if GIF87a format, 0 otherwise */
  39. int    askvideo;        /* flag for video prompting */
  40. char    floatflag;
  41. int    biomorph;        /* flag for biomorph */
  42. int    forcesymmetry;        /* force symmetry */
  43. int    showfile;        /* zero if file display pending */
  44. int    rflag, rseed;        /* Random number seeding flag and value */
  45. int    decomp[2];        /* Decomposition coloring */
  46. int    distest;
  47. char overwrite = 0;    /* 0 if file overwrite not allowed */
  48. int    soundflag;        /* 0 if sound is off, 1 if on */
  49. int    basehertz;        /* sound=x/y/x hertz value */
  50. int    debugflag;        /* internal use only - you didn't see this */
  51. int    timerflag;        /* you didn't see this, either */
  52. int    cyclelimit;        /* color-rotator upper limit */
  53. int    inside;         /* inside color: 1=blue     */
  54. int    outside;        /* outside color    */
  55. int    finattract;        /* finite attractor logic */
  56. int    display3d;        /* 3D display flag: 0 = OFF */
  57. int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  58. int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  59. int    initbatch;        /* 1 if batch run (no kbd)  */
  60. unsigned initsavetime;        /* autosave minutes        */
  61. double    initorbit[2];        /* initial orbitvalue */
  62. char    useinitorbit;        /* flag for initorbit */
  63. int    initmode;        /* initial video mode        */
  64. int    initcyclelimit;     /* initial cycle limit        */
  65. unsigned char usemag;        /* use center-mag corners   */
  66. int    bailout;        /* user input bailout value */
  67. double    inversion[3];        /* radius, xcenter, ycenter */
  68. extern    int invert;
  69. extern int fractype;        /* fractal type         */
  70. extern double param[4];     /* initial parameters        */
  71. extern double xxmin,xxmax;    /* initial corner values    */
  72. extern double yymin,yymax;    /* initial corner values    */
  73. extern double xx3rd,yy3rd;    /* initial corner values    */
  74. extern char usr_stdcalcmode;    /* '1', '2', 'g', 'b'       */
  75. extern int maxit;        /* max iterations        */
  76. extern int usr_periodicitycheck; /* periodicity checking  1=on,0=off */
  77. extern char usr_floatflag;    /* flag for float calcs */
  78. extern int usr_distest;     /* nonzero if distance estimator option */
  79. extern char color_lakes;    /* finite attractor flag */
  80. extern int haze;
  81. extern int RANDOMIZE;
  82. extern int Ambient;
  83. extern int full_color;
  84. extern char light_name[];
  85. extern char back_color[];
  86.  
  87. extern double potparam[];    /* potential parameters  */
  88. extern int Printer_Resolution, LPTNumber,
  89.        Printer_Type, Printer_Titleblock,
  90.        Printer_ColorXlat, Printer_SetScreen,
  91.        Printer_SFrequency, Printer_SAngle,
  92.        Printer_SStyle, EPSFileType,
  93.        Print_To_File;            /* for printer functions */
  94.  
  95. int    transparent[2];     /* transparency min/max values */
  96. int    LogFlag;        /* Logarithmic palette flag: 0 = no */
  97.  
  98. unsigned char exitmode = 3;    /* video mode on exit */
  99.  
  100. char FormFileName[80];        /* file to find (type=)formulas in */
  101. char FormName[40];        /* Name of the Formula (if not null) */
  102.  
  103. extern int video_type;
  104. extern int mode7text;
  105. extern int textsafe;
  106.  
  107. extern int   viewwindow;
  108. extern float viewreduction;
  109. extern int   viewcrop;
  110. extern float finalaspectratio;
  111. extern int   viewxdots,viewydots;
  112.  
  113. extern    char *fkeys[];        /* Function Key names for display table */
  114.  
  115. static    int toolsfile;        /* 1 if inside a TOOLS file, 0 otherwise */
  116.  
  117. extern char MAP_name[];
  118. extern int mapset;
  119. extern char loadPalette;
  120.  
  121. extern int eyeseparation; /* Occular Separation */
  122. extern int glassestype;
  123. extern int xadjust; /* Convergence */
  124. extern int yadjust;
  125. extern int xtrans, ytrans; /* X,Y shift with no perspective */
  126. extern int red_crop_left, red_crop_right;
  127. extern int blue_crop_left, blue_crop_right;
  128. extern int red_bright, blue_bright;
  129. extern char showbox; /* flag to show box and vector in preview */
  130. extern char preview;        /* 3D preview mode flag */
  131. extern int previewfactor; /* Coarsness */
  132.  
  133. static int first_init=1;    /* first time into cmdfiles? */
  134. static int init_rseed;
  135. static int initcorners;     /* corners set flag */
  136.  
  137.  
  138. void cmdfiles_overlay() { }    /* for restore_active_ovly */
  139.  
  140. char LFileName[80]; /* file to find (type=)L-System's in */
  141. char LName[40];    /* Name of L-System */
  142.  
  143. unsigned char textcolor[]={
  144.       BLUE*16+L_WHITE,      /* C_TITLE           title background */
  145.       BLUE*16+L_GREEN,      /* C_TITLE_DEV       development vsn foreground */
  146.       GREEN*16+YELLOW,      /* C_HELP_HDG        help page title line */
  147.       WHITE*16+BLACK,      /* C_HELP_BODY       help page body */
  148.       GREEN*16+GRAY,      /* C_HELP_INSTR      help page instr at bottom */
  149.       WHITE*16+GRAY,      /* C_PROMPT_BKGRD    prompt/choice background */
  150.       BLUE*16+WHITE,      /* C_PROMPT_LO       prompt/choice text */
  151.       BLUE*16+L_WHITE,      /* C_PROMPT_MED      prompt/choice hdg2/... */
  152.       BLUE*16+YELLOW,      /* C_PROMPT_HI       prompt/choice hdg/cur/... */
  153.       GREEN*16+L_WHITE,   /* C_PROMPT_INPUT    fullscreen_prompt input */
  154.       MAGENTA*16+L_WHITE, /* C_CHOICE_CURRENT  fullscreen_choice input */
  155.       BLACK*16+WHITE,      /* C_CHOICE_SP_INSTR speed key bar & instr */
  156.       BLACK*16+L_MAGENTA, /* C_CHOICE_SP_KEYIN speed key value */
  157.       WHITE*16+BLUE,      /* C_GENERAL_HI      tab, thinking, IFS */
  158.       WHITE*16+BLACK,      /* C_GENERAL_MED */
  159.       WHITE*16+GRAY,      /* C_GENERAL_LO */
  160.       BLACK*16+L_WHITE,   /* C_GENERAL_INPUT */
  161.       WHITE*16+BLACK,      /* C_DVID_BKGRD      disk video */
  162.       BLACK*16+YELLOW,      /* C_DVID_HI */
  163.       BLACK*16+L_WHITE,   /* C_DVID_LO */
  164.       RED*16+L_WHITE,      /* C_STOP_ERR        stop message, error */
  165.       GREEN*16+BLACK,      /* C_STOP_INFO       stop message, info */
  166.       BLUE*16+WHITE,      /* C_TITLE_LOW       bottom lines of title screen */
  167.       GREEN*16+BLACK,      /* C_AUTHDIV1        title screen dividers */
  168.       GREEN*16+GRAY,      /* C_AUTHDIV2        title screen dividers */
  169.       BLACK*16+L_WHITE,   /* C_PRIMARY           primary authors */
  170.       BLACK*16+WHITE      /* C_CONTRIB           contributing authors */
  171.       };
  172.  
  173. extern int active_system;
  174.  
  175. /*
  176.     cmdfiles(argc,argv) process the command-line arguments
  177.         it also processes the 'sstools.ini' file and any
  178.         indirect files ('fractint @myfile')
  179. */
  180.  
  181. int cmdfiles(argc,argv)
  182. int argc;
  183. char *argv[];
  184. {
  185. double    atof(), ftemp;            /* floating point stuff    */
  186. int    i, j, k, l;            /* temporary loop counters */
  187.  
  188. char    curarg[141];            /* temporary strings        */
  189.  
  190. char tempstring[101];            /* temporary strings        */
  191. FILE *initfile;             /* for .INI, '@' files      */
  192.  
  193. ENTER_OVLY(OVLY_CMDFILES);
  194.  
  195. gif87a_flag = 0;            /* turn on GIF89a processing */
  196.  
  197. usr_periodicitycheck = 1;        /* turn on periodicity      */
  198. rflag = 0;                /* not a fixed srand() seed */
  199. if (first_init)
  200.     init_rseed = (int)time(NULL);
  201. rseed = init_rseed;
  202. usr_floatflag = 0;            /* turn off the float flag */
  203. biomorph = -1;                /* turn off biomorph flag */
  204. askvideo = 1;                /* turn on video-prompt flag */
  205. overwrite = 0;                /* don't overwrite */
  206. soundflag = -1;             /* sound is on          */
  207. basehertz = 440;            /* basic hertz rate */
  208. initbatch = 0;                /* not in batch mode      */
  209. initsavetime = 0;            /* no auto-save       */
  210. initmode = -1;                /* no initial video mode  */
  211. inside = 1;                /* inside color = blue      */
  212. outside = -1;                /* outside color = -1 (not used) */
  213. finattract = 0;             /* disable finite attractor logic */
  214. maxit = 150;                /* initial maxiter      */
  215. /* initincr = 50;      */        /* initial iter increment */
  216. usr_stdcalcmode = 'g';                  /* initial solid-guessing */
  217. fractype = 0;                /* initial type Set flag  */
  218. initcorners = 0;            /* initial flag: no corners */
  219. usemag = 0;                /* use corners, not center-mag */
  220. bailout = 0;                /* no user-entered bailout */
  221. for (i = 0; i < 4; i++) param[i] = FLT_MAX; /* initial parameter values */
  222. for (i = 0; i < 3; i++) potparam[i]  = 0.0; /* initial potential values */
  223. for (i = 0; i < 3; i++) inversion[i] = 0.0;  /* initial invert values */
  224. invert = 0;
  225. decomp[0] = decomp[1] = 0;
  226. usr_distest = 0;
  227. initorbit[0] = initorbit[1] = 0.0;    /* initial orbit values */
  228. useinitorbit = 0;
  229. forcesymmetry = 999;            /* symmetry not forced */
  230.  
  231. viewwindow = 0;             /* full screen */
  232. viewreduction = 4.2;
  233. viewcrop = 1;
  234. finalaspectratio = SCREENASPECT;
  235. viewxdots = viewydots = 0;
  236.  
  237. xx3rd = xxmin = -2.5; xxmax = 1.5;    /* initial corner values  */
  238. yy3rd = yymin = -1.5; yymax = 1.5;    /* initial corner values  */
  239. pot16bit = potflag = 0;
  240. initcyclelimit=55;            /* spin-DAC default speed limit */
  241. transparent[0] = transparent[1] = 0;        /* no min/max transparency */
  242. LogFlag = 0;                    /* no logarithmic palette */
  243. ifsfilename[0] = 0;                /* initially current directory */
  244. ifs3dfilename[0] = 0;                /* initially current directory */
  245. mapset = 0;                    /* no map= name active */
  246. loadPalette = 0;
  247.  
  248. debugflag = 0;                    /* debugging flag(s) are off */
  249. timerflag = 0;                    /* timer flags are off        */
  250.  
  251. display3d = 0;                    /* 3D display is off        */
  252. overlay3d = 0;                    /* 3D overlay is off        */
  253.  
  254. /* 3D defaults */
  255. SPHERE = FALSE;
  256. preview = 0;
  257. showbox = 0;
  258. previewfactor = 20;
  259. xadjust = 0;
  260. yadjust = 0;
  261. eyeseparation = 0;
  262. glassestype = 0;
  263. xtrans = 0;
  264. ytrans = 0;
  265. red_crop_left    = 4;
  266. red_crop_right    = 0;
  267. blue_crop_left    = 0;
  268. blue_crop_right = 4;
  269. red_bright     = 80;
  270. blue_bright   = 100;
  271. set_3d_defaults();
  272.  
  273. set_trig_array(0,"sin");                        /* trigfn defaults */
  274. set_trig_array(1,"sqr");
  275. set_trig_array(2,"sinh");
  276. set_trig_array(3,"cosh");
  277.  
  278. strcpy(readname,".\\");                         /* initially current directory */
  279. showfile = 1;
  280.  
  281. Printer_Type = 2;                /* assume an IBM/EPSON      */
  282. Printer_Resolution = 60;            /* assume low resolution  */
  283. Printer_Titleblock = 0;             /* assume no title block  */
  284. Printer_ColorXlat = 0;                /* assume positive image  */
  285. Printer_SetScreen = 0;                /* assume default screen  */
  286. Printer_SFrequency = 0;             /* New screen frequency   */
  287. Printer_SAngle = 0;                /* New screen angle      */
  288. Printer_SStyle = 0;                /* New screen style      */
  289. Print_To_File = 0;                /* No print-to-file      */
  290. EPSFileType = 0;                /* Assume no save to .EPS */
  291.  
  292. LPTNumber = 1;                    /* assume LPT1 */
  293.  
  294. strcpy(FormFileName,"fractint.frm");            /* default formula file */
  295. strcpy(FormName,"");                            /* default formula name */
  296.  
  297. strcpy(LFileName,"fractint.l");
  298. strcpy(LName,"");
  299.  
  300. if (first_init) {
  301.     strcpy(savename,"fract001");            /* initial save filename  */
  302.     strcpy(light_name,"light001.tga");      /* initial light filename */
  303.     strcpy(PrintName,"fract001.prn");       /* initial print-to-file  */
  304.     }
  305.  
  306.  
  307. toolsfile = 1;                    /* enable TOOLS processing */
  308.  
  309. findpath("sstools.ini", tempstring);            /* look for SSTOOLS.INI */
  310. if (tempstring[0] != 0)             /* found it! */
  311.     if ((initfile = fopen(tempstring,"r")) != NULL)
  312.         cmdfile(initfile);        /* process it */
  313.  
  314. toolsfile = 0;                    /* disable TOOLS processing */
  315.  
  316. for (i = 1; i < argc; i++) {            /* cycle through args    */
  317.     strcpy(curarg,argv[i]);
  318.     strlwr(curarg);             /* using lower case    */
  319.     for (j = 1; j < strlen(curarg) && curarg[j] != '='; j++) ;
  320.  
  321.     if (j < strlen(curarg)) {        /* xxx=yyy argument? */
  322.         cmdarg(curarg);         /* process it */
  323.         continue;
  324.         }
  325.  
  326.     if (curarg[0] == ';')                   /* start of comments? */
  327.         break;                /* we done! */
  328.  
  329.     if (curarg[0] == '@') {                 /* command indirection? */
  330.         if ((initfile = fopen(&curarg[1],"r")) != NULL) {
  331.             cmdfile(initfile);    /* process it */
  332.             continue;
  333.             }
  334.         else argerror(curarg);        /* oops.  error. */
  335.         }
  336.  
  337.     strcpy(readname,curarg);        /* else, assume a filename */
  338.     showfile = 0;
  339.  
  340.     }
  341.  
  342. for (i = 0; i < 4; i++) {
  343.     if (param[i] != FLT_MAX)
  344.         fractalspecific[fractype].paramvalue[i] = param[i];
  345.     else
  346.         param[i] = fractalspecific[fractype].paramvalue[i];
  347.     }
  348.  
  349. if (first_init == 0) {
  350.     initmode = -1; /* don't set video when <ins> key used */
  351.     showfile = 1;  /* nor startup image file          */
  352.     }
  353.  
  354. first_init = 0;
  355. EXIT_OVLY;
  356. return(0);                    /* we done */
  357. }
  358.  
  359. /*
  360.     cmdfile(handle) processes a single command-file.
  361.         if (toolsfile), it looks for '[...]' codes as well
  362. */
  363.  
  364. static void cmdfile(handle)        /* process a command file of some sort */
  365. FILE *handle;
  366. {
  367. char line[513];
  368. int toolssection;
  369. int i, j;
  370.  
  371. toolssection = 1;            /* assume an implied [fractint] */
  372.  
  373. while (fgets(line,512,handle) != NULL) {    /* read thru a line at a time */
  374.     i = strlen(line);
  375.     if (i > 0 && line[i-1] == '\n') line[i-1] = 0;  /* strip trailing \n */
  376.     else line[i+1] = 0;                /* add second null   */
  377.  
  378.     strlwr(line);                /* convert to lower case */
  379.     if (toolsfile && line[0] == '[') {      /* TOOLS-style header */
  380.         toolssection = 0;
  381.         if (strncmp(line,"[fractint]",10) == 0)
  382.             toolssection = 1;
  383.         continue;            /* ignore this line in any case */
  384.         }
  385.  
  386.     if (! toolssection) continue;        /* not our section */
  387.  
  388.     i = -1;                 /* get a running start */
  389.     while (line[++i] != 0) {        /* scan through the line */
  390.         if (line[i] <= ' ') continue;   /* white space */
  391.         if (line[i] == ';') break;      /* comments */
  392.         j = i;                /* argument starts here */
  393.         while (line[++i] > ' ');        /* find the argument end */
  394.         line[i] = 0;            /* force an end-of-string */
  395.         if (j == 0 && strcmp(&line[j],"fractint") == 0)
  396.             continue;        /* skip leading "fractint " */
  397.         cmdarg(&line[j]);        /* process the argument */
  398.         }
  399.     }
  400.  
  401. fclose(handle);
  402. }
  403.  
  404. /*
  405.     cmdarg(string) processes a single command-line/command-file argument
  406.         isolate 'variable=value' (or 'variable:=value') into
  407.         its components and process it.
  408.         All components have already been converted to lower case.
  409. */
  410.  
  411. static int cmdarg(char *curarg)     /* process a single argument */
  412. {
  413.     char    variable[21];            /* variable name goes here */
  414.     char    value[141];            /* variable value goes here*/
  415.     int    numval;             /* numeric value of arg    */
  416.     char    charval;            /* character value of arg  */
  417.  
  418.     double    atof(), ftemp;            /* floating point stuff    */
  419.     int    i, j, k, l;            /* temporary loop counters */
  420.     char    *slash;             /* temporary string ptr    */
  421.  
  422.     strlwr(curarg);             /* using lower case      */
  423.     for (j = 1; j < strlen(curarg) && curarg[j] != '='; j++) ;
  424.     if (j > 20 || j >= strlen(curarg))
  425.         argerror(curarg);        /* oops.  '=' not found   */
  426.  
  427.     strncpy(variable,curarg,j);        /* get the variable name  */
  428.     variable[j] = 0;            /* truncate it          */
  429.     if (j > 1 && variable[j-1] == ':')      /* strip any trailing ':' */
  430.         variable[j-1] = 0;
  431.     strcpy(value,&curarg[j+1]);        /* get the value string   */
  432.     numval = atoi(value);            /* get any numeric value  */
  433.     charval = value[0];            /* get any letter  value  */
  434.  
  435.     if (strcmp(variable,"filename") == 0) {         /* filename=?   */
  436.         strcpy(readname,value);         /* set up filename */
  437.         showfile = 0;
  438.         return(0);
  439.         }
  440.     if( strcmp(variable, "map") == 0 ) {    /* map option */
  441.         if (SetColorPaletteName(value) != 0)
  442.             argerror(curarg);
  443.         mapset = 1;
  444.         strcpy(MAP_name,value);
  445.         return(0);
  446.         }
  447.     if (strcmp(variable,"batch") == 0 ) {           /* batch=?      */
  448.         if (charval == 'c') {                   /* config run   */
  449.             makeconfig();
  450.             goodbye();
  451.             }
  452.         if (charval == 'y'){                    /* batch = yes  */
  453.             initbatch = 1;
  454.             return(0);
  455.             }
  456.         if (charval == 'n'){
  457.             initbatch = 0;
  458.             return(0);
  459.             }
  460.         }
  461.     /* keep this for backward compatibility */
  462.     if (strcmp(variable,"warn") == 0 ) {            /* warn=?       */
  463.         if (charval == 'y')
  464.             overwrite = 0;
  465.         else if (charval == 'n')
  466.             overwrite = 1;
  467.     else
  468.             argerror(curarg);
  469.         return(0);
  470.         }
  471.     if (strcmp(variable,"overwrite") == 0 ) {            /* overwrite=?       */
  472.         if (charval == 'n')
  473.             overwrite = 0;
  474.         else if (charval == 'y')
  475.             overwrite = 1;
  476.     else
  477.             argerror(curarg);
  478.         return(0);
  479.         }
  480.     if (strcmp(variable,"gif87a") == 0 ) {          /* gif87a=?     */
  481.         if (charval == 'y')
  482.             gif87a_flag = 1;
  483.         return(0);
  484.         }
  485.     if (strcmp(variable,"savetime") == 0) {         /* savetime=?   */
  486.         initsavetime = numval;
  487.         return(0);
  488.         }
  489.     if (strcmp(variable,"type") == 0 ) {            /* type=?       */
  490.         if (value[strlen(value)-1] == '*')
  491.             value[strlen(value)-1] = 0;
  492.         for (k = 0; fractalspecific[k].name != NULL; k++)
  493.             if (strcmp(value,fractalspecific[k].name) == 0)
  494.                 break;
  495.         if (fractalspecific[k].name == NULL) argerror(curarg);
  496.         fractype = k;
  497.         if (initcorners == 0) {
  498.             xx3rd = xxmin = fractalspecific[fractype].xmin;
  499.             xxmax          = fractalspecific[fractype].xmax;
  500.             yy3rd = yymin = fractalspecific[fractype].ymin;
  501.             yymax          = fractalspecific[fractype].ymax;
  502.             }
  503.         return(0);
  504.         }
  505.     if (strcmp(variable,"inside") == 0 ) {          /* inside=?     */
  506.         if(strcmp(value,"bof60")==0)
  507.             inside = -60;
  508.         else if(strcmp(value,"bof61")==0)
  509.             inside = -61;
  510.         else if(strcmp(value,"maxiter")==0)
  511.             inside = -1;
  512.         else if(isalpha(*value))
  513.             argerror(curarg);
  514.         else
  515.             inside = numval;
  516.         return(0);
  517.         }
  518.     if (strcmp(variable,"finattract") == 0 ) {      /* finattract=? */
  519.         if (charval == 'y')
  520.             finattract = 1;
  521.         return(0);
  522.         }
  523.  
  524.     if (strcmp(variable,"function") == 0) {           /* function=?,?   */
  525.         k = 0;
  526.         slash = strchr(curarg,'=');
  527.         while ( k < 4) {
  528.             slash++;
  529.             if(set_trig_array(k++,slash)) {
  530.                argerror(curarg);
  531.                return(0);
  532.                }
  533.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  534.             }
  535.         return(0);
  536.         }
  537.     if (strcmp(variable,"outside") == 0 ) {         /* outside=?    */
  538.         if(numval < -1 || numval > 255)
  539.             argerror(curarg);
  540.         else
  541.             outside = numval;
  542.         return(0);
  543.         }
  544.     if (strcmp(variable,"maxiter") == 0) {          /* maxiter=?    */
  545.         if (numval < 2 || numval > 32767) argerror(curarg);
  546.         maxit = numval;
  547.         return(0);
  548.         }
  549.     if (strcmp(variable,"iterincr") == 0) {         /* iterincr=?   */
  550.         /*    if (numval <= 0 || numval > 32000) argerror(curarg);
  551.         initincr = numval;
  552.          */
  553.         return(0);
  554.         }
  555.     if (strcmp(variable,"passes") == 0) {           /* passes=?     */
  556.         if ( charval != '1' && charval != '2'
  557.           && charval != 'g' && charval != 'b')
  558.            argerror(curarg);
  559.         usr_stdcalcmode = charval;
  560.         return(0);
  561.         }
  562.     if (strcmp(variable,"cyclelimit") == 0 ) {      /* cyclelimit=? */
  563.         if (numval > 1 && numval <= 256)
  564.             initcyclelimit = numval;
  565.         return(0);
  566.         }
  567.     if (strcmp(variable,"savename") == 0) {         /* savename=?   */
  568.         if (first_init)
  569.             strcpy(savename,value);
  570.         return(0);
  571.         }
  572.     if (strcmp(variable,"video") == 0) {            /* video=?      */
  573.         if (active_system != 0)
  574.             return(0);
  575.         for (k = 0; k < maxvideomode; k++) {
  576.             strcpy(variable,fkeys[k]);
  577.             strlwr(variable);
  578.             if (strcmp(variable, value) == 0)
  579.                 break;
  580.             }
  581.         if (k == maxvideomode) argerror(curarg);
  582.         initmode = k;
  583.         return(0);
  584.         }
  585.     if (strcmp(variable,"adapter") == 0 ) {         /* adapter==?     */
  586.         slash = strchr(curarg,'=');
  587.         video_type = 5;             /* assume video=vga */
  588.         if (strcmp(&slash[1],"egamono") == 0) {
  589.             video_type = 3;
  590.             mode7text = 1;
  591.             }
  592.         else if (charval == 'h') {              /* video = hgc */
  593.             video_type = 1;
  594.             mode7text = 1;
  595.             }
  596.         else if (charval == 'e')                /* video = ega */
  597.             video_type = 3;
  598.         else if (charval == 'c')                /* video = cga */
  599.             video_type = 2;
  600.         else if (charval == 'm')                /* video = mcga */
  601.             video_type = 4;
  602.         return(0);
  603.         }
  604.  
  605.     if (strcmp(variable,"textsafe") == 0 ) {        /* textsafe==?     */
  606.         if (first_init) {
  607.             if (charval == 'n') /* no */
  608.             textsafe = 2;
  609.             else if (charval == 'y') /* yes */
  610.             textsafe = 1;
  611.             else if (charval == 'b') /* bios */
  612.             textsafe = 3;
  613.             else if (charval == 's') /* save */
  614.             textsafe = 4;
  615.             else
  616.             argerror(curarg);
  617.             }
  618.         return(0);
  619.         }
  620.     if (strcmp(variable,"exitmode") == 0) {         /* exitmode=?   */
  621.         sscanf(value,"%x",&numval);
  622.         exitmode = numval;
  623.         return(0);
  624.         }
  625.     if (strcmp(variable,"textcolors") == 0) {
  626.         slash = strchr(curarg,'=');
  627.         if (strcmp(&slash[1],"mono") == 0) {
  628.            for (k = 0; k < sizeof(textcolor); ++k)
  629.               textcolor[k] = BLACK*16+WHITE;
  630.         /* C_PROMPT_INPUT = C_CHOICE_CURRENT = C_GENERAL_INPUT
  631.                = C_AUTHDIV1 = C_AUTHDIV2 = WHITE*16+BLACK; */
  632.            textcolor[9] = textcolor[10] = textcolor[16]
  633.                = textcolor[23] = textcolor[24] = WHITE*16+BLACK;
  634.         /* C_TITLE = C_HELP_HDG = C_PROMPT_HI = C_CHOICE_SP_KEYIN
  635.                = C_GENERAL_HI = C_DVID_HI = C_STOP_ERR
  636.                = C_STOP_INFO = BLACK*16+L_WHITE; */
  637.            textcolor[0] = textcolor[2] = textcolor[8] = textcolor[12]
  638.                = textcolor[13] = textcolor[18] = textcolor[20]
  639.                = textcolor[21] = BLACK*16+L_WHITE;
  640.            }
  641.         else {
  642.            k = 0;
  643.            while ( k < sizeof(textcolor)) {
  644.               if (slash[1] && slash[1] != '/') {
  645.              sscanf(&slash[1],"%x",&numval);
  646.              i = (numval / 16) & 7;
  647.              j = numval & 15;
  648.              if (i == j || (i == 0 && j == 8)) /* force contrast */
  649.                 j = 15;
  650.              textcolor[k] = i * 16 + j;
  651.              }
  652.               ++k;
  653.               if ((slash = strchr(&slash[1],'/')) == NULL) k = 99;
  654.               }
  655.            }
  656.         return(0);
  657.         }
  658.     if (strcmp(variable,"potential") == 0) {        /* potential=?  */
  659.         k = 0;
  660.         slash = strchr(curarg,'=');
  661.         while ( k < 3) {
  662.             potparam[k++] = atoi(++slash);
  663.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  664.             }
  665.         pot16bit = 0;
  666.         if (k < 99) {
  667.             if (strcmp(++slash,"16bit"))
  668.                 argerror(curarg);
  669.             pot16bit = 1;
  670.             }
  671.         return(0);
  672.         }
  673.     if (strcmp(variable,"params") == 0) {           /* params=?,?   */
  674.         k = 0;
  675.         slash = strchr(curarg,'=');
  676.         while ( k < 4) {
  677.             param[k++] = atof(++slash);
  678.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  679.             }
  680.         return(0);
  681.         }
  682.     if (strcmp(variable,"initorbit") == 0) {           /* initorbit=?,?   */
  683.         k = 0;
  684.         slash = strchr(curarg,'=');
  685.         if(strcmp(slash+1,"pixel")==0)
  686.         {
  687.            useinitorbit = 2;
  688.            return(0);
  689.         }
  690.         while ( k < 2) {
  691.             initorbit[k++] = atof(++slash);
  692.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  693.             }
  694.         useinitorbit = 1;
  695.         return(0);
  696.         }
  697.     if (strcmp(variable,"corners") == 0) {          /* corners=?,?,?,? */
  698.         initcorners = 1;
  699.         slash = strchr(curarg,'=');
  700.         xx3rd=xxmin=atof(++slash);
  701.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  702.         xxmax=atof(++slash);
  703.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  704.         yy3rd=yymin=atof(++slash);
  705.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  706.         yymax=atof(++slash);
  707.         if ((slash = strchr(slash,'/')) != NULL) {
  708.             xx3rd=atof(++slash);
  709.             if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  710.             yy3rd=atof(++slash);
  711.             }
  712.         return(0);
  713.         }
  714.     if (strcmp(variable,"center-mag") == 0) {          /* center-mag=?,?,? */
  715.         double Xctr, Yctr,Magnification,Ratio,Height, Width,Radius;
  716.         usemag = 1;
  717.         slash = strchr(curarg,'=');
  718.         Xctr=atof(++slash);
  719.         if ((slash = strchr(slash,'/')) == NULL)
  720.            return(0);
  721.         initcorners = 1;
  722.         Yctr=atof(++slash);
  723.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  724.         if((Magnification=atof(++slash))<=0.0)
  725.             argerror(curarg);
  726.         else
  727.             Radius = 1.0 / Magnification;
  728.  
  729.         if ((slash = strchr(slash,'/')) != NULL) argerror(curarg);
  730.         Ratio = .75;    /* inverse aspect ratio of screen  */
  731.  
  732.         /* calculate bounds */
  733.         Height = 2.0 * Radius;
  734.         Width = Height / Ratio;
  735.         yymax = Yctr + Radius;
  736.         yy3rd = yymin = Yctr - Radius;
  737.         xxmax = Xctr + Width / 2.0;
  738.         xx3rd = xxmin = Xctr - Width / 2.0;
  739.         return(0);
  740.         }
  741.     if (strcmp(variable,"3d") == 0) {               /* 3d=?/?/..    */
  742.         display3d = 1;                /* turn on 3D */
  743.         k = 0;
  744.         slash = strchr(curarg,'=');
  745.         while ( k < 20) {
  746.             l = atoi(++slash);
  747.             if (slash[0] > 32 && slash[0] != '/') init3d[k] = l;
  748.             /* reset sphere defaults, done here cause [0]==sphere */
  749.             if (k == 0)
  750.                 set_3d_defaults();
  751.             if ((slash = strchr(slash,'/')) == NULL) break;
  752.             k++;
  753.             }
  754.         return(0);
  755.         }
  756.     if (strcmp(variable,"sphere") == 0 ) {          /* sphere=?     */
  757.         if (charval == 'y')
  758.             SPHERE      = TRUE;
  759.         else if (charval == 'n')
  760.             SPHERE      = FALSE;
  761.         else
  762.             argerror(curarg);        /* oops.  error. */
  763.         return(0);
  764.         }
  765.     if (strcmp(variable,"rotation") == 0) {         /* rotation=?/?/?       */
  766.         k = 0;
  767.         slash = strchr(curarg,'=');
  768.         while ( k < 3) {
  769.             l = atoi(++slash);
  770.             if (slash[0] > 32 && slash[0] != '/') *(&XROT+k) = l;
  771.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  772.             k++;
  773.             }
  774.         return(0);
  775.         }
  776.     if (strcmp(variable,"scalexyz") == 0) {         /* scalexyz=?/?/?       */
  777.         k = 0;
  778.         slash = strchr(curarg,'=');
  779.         while ( k < 3) {
  780.             l = atoi(++slash);
  781.             if (slash[0] > 32 && slash[0] != '/') *(&XSCALE+k) = l;
  782.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  783.             k++;
  784.             }
  785.         return(0);
  786.         }
  787.     /* "rough" is really scale z, but we add it here for convenience */
  788.     if (strcmp(variable,"roughness") == 0) {        /* roughness=?  */
  789.         ROUGH = numval;
  790.         return(0);
  791.         }
  792.     if (strcmp(variable,"waterline") == 0) {        /* waterline=?  */
  793.         if (numval<0) argerror(curarg);
  794.         WATERLINE = numval;
  795.         return(0);
  796.         }
  797.     if (strcmp(variable,"filltype") == 0) {         /* filltype=?   */
  798.         if (numval < -1 || numval > 6) argerror(curarg);
  799.         FILLTYPE = numval;
  800.         return(0);
  801.         }
  802.     if (strcmp(variable,"perspective") == 0) {      /* perspective=?        */
  803.         k = 0;
  804.         slash = strchr(curarg,'=');
  805.         while ( k < 1) {
  806.             l = atoi(++slash);
  807.             if (slash[0] > 32 && slash[0] != '/') *(&ZVIEWER+k) = l;
  808.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  809.             k++;
  810.             }
  811.         return(0);
  812.         }
  813.     if (strcmp(variable,"xyshift") == 0) {          /* xyshift=?/?  */
  814.         k = 0;
  815.         slash = strchr(curarg,'=');
  816.         while ( k < 2) {
  817.             l = atoi(++slash);
  818.             if (slash[0] > 32 && slash[0] != '/') *(&XSHIFT+k) = l;
  819.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  820.             k++;
  821.             }
  822.         return(0);
  823.         }
  824.     if (strcmp(variable,"lightsource") == 0) {      /* lightsource=?/?/?    */
  825.         k = 0;
  826.         slash = strchr(curarg,'=');
  827.         while ( k < 3) {
  828.             l = atoi(++slash);
  829.             if (slash[0] > 32 && slash[0] != '/') *(&XLIGHT+k) = l;
  830.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  831.             k++;
  832.             }
  833.         return(0);
  834.         }
  835.     if (strcmp(variable,"smoothing") == 0) {        /* smoothing=?  */
  836.         if (numval<0) argerror(curarg);
  837.         LIGHTAVG = numval;
  838.         return(0);
  839.         }
  840.     if (strcmp(variable,"latitude") == 0) {         /* latitude=?/? */
  841.         k = 0;
  842.         slash = strchr(curarg,'=');
  843.         while ( k < 2) {
  844.             l = atoi(++slash);
  845.             if (slash[0] > 32 && slash[0] != '/') *(&THETA1+k) = l;
  846.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  847.             k++;
  848.             }
  849.         return(0);
  850.         }
  851.     if (strcmp(variable,"longitude") == 0) {        /* longitude=?/?        */
  852.         k = 0;
  853.         slash = strchr(curarg,'=');
  854.         while ( k < 2) {
  855.             l = atoi(++slash);
  856.             if (slash[0] > 32 && slash[0] != '/') *(&PHI1+k) = l;
  857.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  858.             k++;
  859.             }
  860.         return(0);
  861.         }
  862.     if (strcmp(variable,"radius") == 0) {           /* radius=?     */
  863.         if (numval<0) argerror(curarg);
  864.         RADIUS = numval;
  865.         return(0);
  866.         }
  867.     if (strcmp(variable,"invert") == 0) {           /* invert=?,?,? */
  868.         k = 0;
  869.         slash = strchr(curarg,'=');
  870.         while ( k < 3) {
  871.             inversion[k++] = atof(++slash);
  872.             if(inversion[0] != 0.0)
  873.                 invert = k; /* record highest inversion parameter set */
  874.             if ((slash = strchr(slash,'/')) == NULL) k = 99;
  875.             }
  876.         return(0);
  877.         }
  878.     if (strcmp(variable,"askvideo") == 0 ) {        /* askvideo=?   */
  879.         if (charval == 'y')
  880.             askvideo = 1;
  881.         else if (charval == 'n')
  882.             askvideo = 0;
  883.         else
  884.             argerror(curarg);
  885.         return(0);
  886.         }
  887.     if (strcmp(variable,"ramvideo") == 0 ) {        /* ramvideo=?   */
  888.         return(0); /* just ignore and return, for old time's sake */
  889.         }
  890.     if (strcmp(variable,"float") == 0 ) {           /* float=?      */
  891.         if (charval == 'y')
  892.             usr_floatflag = 1;
  893.         else if (charval == 'n')
  894.             usr_floatflag = 0;
  895.         else
  896.             argerror(curarg);
  897.         return(0);
  898.         }
  899.     if (strcmp(variable,"biomorph") == 0 ) {        /* biomorph=?   */
  900.         biomorph = numval;
  901.         return(0);
  902.         }
  903.     if (strcmp(variable,"bailout") == 0 ) {         /* bailout=?    */
  904.         if (numval < 4 || numval > 32000) argerror(curarg);
  905.         bailout = numval;
  906.         return(0);
  907.         }
  908.     if (strcmp(variable,"symmetry") == 0 ) {        /* symmetry=?   */
  909.         if     (strcmp(value,"xaxis" )==0) forcesymmetry = XAXIS;
  910.         else if(strcmp(value,"yaxis" )==0) forcesymmetry = YAXIS;
  911.         else if(strcmp(value,"xyaxis")==0) forcesymmetry = XYAXIS;
  912.         else if(strcmp(value,"origin")==0) forcesymmetry = ORIGIN;
  913.         else if(strcmp(value,"pi"    )==0) forcesymmetry = PI_SYM;
  914.         else if(strcmp(value,"none"  )==0) forcesymmetry = NOSYM;
  915.         else argerror(curarg);
  916.         return(0);
  917.         }
  918.  
  919.     if (strcmp(variable,"printer") == 0 ) { /* printer=?    */
  920.         if (charval=='h' && value[1]=='p')
  921.             Printer_Type=1;          /* HP LaserJet        */
  922.         if (charval=='i' && value[1]=='b')
  923.             Printer_Type=2;          /* IBM Graphics        */
  924.         if (charval=='e' && value[1]=='p')
  925.             Printer_Type=2;          /* Epson (model?)        */
  926.         if (charval=='c' && value[1]=='o')
  927.             Printer_Type=3;          /* Star (Epson-Comp?) color */
  928.         if (charval=='p' && value[1]=='a')
  929.             Printer_Type=4;          /* HP Paintjet (color)    */
  930.         if (charval=='p' && (value[1]=='o' || value[1]=='s'))
  931.             {                  /* PostScript  SWT */
  932.             Printer_Type=5;
  933.             slash=strchr(curarg,'=');
  934.             if ((slash=strchr(slash,'/'))==NULL)
  935.                slash = &curarg[strlen(curarg)];
  936.             slash--;
  937.             if (*slash=='h' || *slash=='l')
  938.                Printer_Type=6;
  939.             }
  940.  
  941.         if (Printer_Type == 1)        /* assume low resolution */
  942.             Printer_Resolution = 75;
  943.         else
  944.             Printer_Resolution = 60;
  945.  
  946.         if (EPSFileType > 0)           /* EPS save - force type 5 */
  947.             Printer_Type = 5;
  948.  
  949.         if ((Printer_Type == 5) || (Printer_Type == 6))
  950.             Printer_Resolution = 150; /* PostScript def. res. */
  951.  
  952.         slash=strchr(curarg,'=');
  953.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  954.         if ((k=atoi(++slash)) > 0) Printer_Resolution=k;
  955.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  956.         if ((k=atoi(++slash))> 0) LPTNumber = k;
  957.         if (k < 0) Print_To_File = 1;
  958.         return(0);
  959.         }
  960.  
  961.     if (strcmp(variable,"printfile") == 0) {   /* print-to-file? SWT */
  962.         Print_To_File = 1;
  963.         strcpy(PrintName,value);
  964.         return(0);
  965.         }
  966.  
  967.     if (strcmp(variable,"epsf") == 0) {   /* EPS type? SWT */
  968.         Print_To_File = 1;
  969.         EPSFileType = numval;
  970.         Printer_Type = 5;
  971.         if (strcmp(PrintName,"fract001.prn")==0)
  972.             strcpy(PrintName,"fract001.eps");
  973.         return(0);
  974.         }
  975.  
  976.     if (strcmp(variable,"title") == 0) {   /* Printer title block? SWT */
  977.         if (charval=='y') Printer_Titleblock=1;
  978.         return(0);
  979.         }
  980.  
  981.     if (strcmp(variable,"translate") == 0) {   /* Translate color? SWT */
  982.         if (charval=='y')
  983.           {
  984.           Printer_ColorXlat=1;
  985.           return(0);
  986.           }
  987.         if ((numval>1) || (numval<-1))
  988.           {
  989.           Printer_ColorXlat=numval;
  990.           return(0);
  991.           }
  992.         Printer_ColorXlat=0;
  993.         return(0);
  994.         }
  995.  
  996.     if (strcmp(variable,"halftone") == 0) {   /* New halftoning? SWT */
  997.         Printer_SetScreen=1;
  998.         slash = strchr(curarg,'=');
  999.         if ((k=atoi(++slash))>0) Printer_SFrequency=k;
  1000.         else Printer_SFrequency=80;
  1001.         if ((slash=strchr(slash,'/')) == NULL)
  1002.           {
  1003.           Printer_SAngle=45;
  1004.           Printer_SStyle=0;
  1005.           return(0);
  1006.           }
  1007.         Printer_SAngle=atoi(++slash);
  1008.         if ((slash=strchr(slash,'/')) == NULL)
  1009.           {
  1010.           Printer_SStyle=0;
  1011.           return(0);
  1012.           }
  1013.         Printer_SStyle=atoi(++slash);
  1014.         return(0);
  1015.         }
  1016.  
  1017.     if (strcmp(variable,"comport") == 0 ) /* Set the COM parameters */
  1018.     {
  1019.         slash=strchr(curarg,'=');
  1020.         if ((slash=strchr(slash,'/')) == NULL) return(-1);
  1021.         switch (atoi(++slash))
  1022.           {
  1023.           case 110:
  1024.             l = 0;
  1025.             break;
  1026.           case 150:
  1027.             l = 32;
  1028.             break;
  1029.           case 300:
  1030.             l = 64;
  1031.             break;
  1032.           case 600:
  1033.             l = 96;
  1034.             break;
  1035.           case 1200:
  1036.             l = 128;
  1037.             break;
  1038.           case 2400:
  1039.             l = 160;
  1040.             break;
  1041.           case 4800:
  1042.             l = 192;
  1043.             break;
  1044.           case 9600:
  1045.           default:
  1046.             l = 224;
  1047.             break;
  1048.           }
  1049.         if ((slash=strchr(slash,'/')) == NULL) return(-1);
  1050.         for (k=0; k < strlen(slash); k++)
  1051.           {
  1052.           switch (slash[k])
  1053.             {
  1054.             case '7':
  1055.             l |= 2;
  1056.             break;
  1057.             case '8':
  1058.             l |= 3;
  1059.             break;
  1060.             /* No parity = do nothing */
  1061.             case 'o':
  1062.             case 'O':
  1063.             l |= 8;
  1064.             break;
  1065.             case 'e':
  1066.             case 'E':
  1067.             l |= 24;
  1068.             break;
  1069.             /* 1 stop bit = do nothing */
  1070.             case '2':
  1071.             l |= 4;
  1072.             break;
  1073.             }
  1074.           }
  1075. #ifdef __TURBOC__
  1076.         bioscom(0,l,numval-1);
  1077. #else
  1078.         _bios_serialcom(0,numval-1,l);
  1079. #endif
  1080.         return(0);
  1081.     }
  1082.  
  1083.  
  1084.     if (strcmp(variable,"transparent") == 0) { /* transparent? */
  1085.         slash = strchr(curarg,'=');
  1086.         if ((k=atoi(++slash)) > 0) transparent[0] = k;
  1087.         transparent[1] = transparent[0];
  1088.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1089.         if ((k=atoi(++slash)) > 0) transparent[1] = k;
  1090.         return(0);
  1091.         }
  1092.     if (strcmp(variable,"sound") == 0 ) {           /* sound=?      */
  1093.         soundflag = 0;                /* sound is off */
  1094.         if (strncmp(value,"ye",2) == 0)
  1095.             soundflag = -1;         /* sound is on    */
  1096.         if (charval == 'x')
  1097.             soundflag = 1;
  1098.         if (charval == 'y')
  1099.             soundflag = 2;
  1100.         if (charval == 'z')
  1101.             soundflag = 3;
  1102.         return(0);
  1103.         }
  1104.  
  1105.     if (strcmp(variable,"hertz") == 0) {   /* Hertz=? */
  1106.         if (numval < 200 || numval > 10000) argerror(curarg);
  1107.         basehertz = numval;
  1108.         return(0);
  1109.         }
  1110.  
  1111.     if (strcmp(variable,"periodicity") == 0 ) {     /* periodicity=?    */
  1112.         usr_periodicitycheck=1;
  1113.         if (charval == 'n')
  1114.             usr_periodicitycheck=0;
  1115.         else if (charval == 'y')
  1116.             usr_periodicitycheck=1;
  1117.         else if (charval == 's')   /* 's' for 'show' */
  1118.             usr_periodicitycheck=-1;
  1119.         else if(isalpha(*value))
  1120.             argerror(curarg);
  1121.         else if(numval != 0)
  1122.             usr_periodicitycheck=numval;
  1123.         return(0);
  1124.         }
  1125.  
  1126.     if (strcmp(variable,"logmap") == 0 ) {          /* logmap=?     */
  1127.         if (charval == 'y')
  1128.             LogFlag = 1;            /* palette is logarithmic */
  1129.         else if (charval == 'n')
  1130.             LogFlag = 0;
  1131.         else if (charval == 'o')
  1132.             LogFlag = -1;            /* old log palette */
  1133.         else
  1134.             LogFlag = numval;
  1135.         return(0);
  1136.         }
  1137.     if (strcmp(variable,"debugflag") == 0 ||
  1138.          strcmp(variable,"debug") == 0) {       /* internal use only */
  1139.         debugflag = numval;
  1140.         timerflag = debugflag & 1;        /* separate timer flag */
  1141.         debugflag -= timerflag;
  1142.         return(0);
  1143.         }
  1144.     if (strcmp(variable,"ifs") == 0) {              /* ifs=?        */
  1145.         strcpy(ifsfilename,value);
  1146.         if (strchr(value,'.') == NULL)
  1147.             strcat(ifsfilename,".ifs");
  1148.         ifsgetfile();
  1149.         return(0);
  1150.         }
  1151.     if (strcmp(variable,"ifs3d") == 0) {            /* ifs3d=?      */
  1152.         strcpy(ifs3dfilename,value);
  1153.         if (strchr(value,'.') == NULL)
  1154.             strcat(ifs3dfilename,".ifs");
  1155.         ifs3dgetfile();
  1156.         return(0);
  1157.         }
  1158.     if (strcmp(variable,"ifscodes") == 0) {    /* ifscodes=?,?,?,? */
  1159.         int ifsindex;
  1160.         slash = strchr(curarg,'=');
  1161.         ifsindex=atoi(++slash) - 1;
  1162.         if(ifsindex < 0 || ifsindex > NUMIFS) argerror(curarg);
  1163.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1164.         initifs[ifsindex][0]=atof(++slash);
  1165.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1166.         initifs[ifsindex][1]=atof(++slash);
  1167.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1168.         initifs[ifsindex][2]=atof(++slash);
  1169.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1170.         initifs[ifsindex][3]=atof(++slash);
  1171.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1172.         initifs[ifsindex][4]=atof(++slash);
  1173.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1174.         initifs[ifsindex][5]=atof(++slash);
  1175.         if ((slash = strchr(slash,'/')) == NULL) argerror(curarg);
  1176.         initifs[ifsindex][6]=atof(++slash);
  1177.         return(0);
  1178.         }
  1179.     if (strcmp(variable, "rseed") == 0) {
  1180.         rseed = numval;
  1181.         rflag = 1;
  1182.         return(0);
  1183.         }
  1184.     if (strcmp(variable, "decomp") == 0) {
  1185.         k = 0;
  1186.         slash = strchr(curarg,'=');
  1187.         while (k < 2) {
  1188.             decomp[k++] = atoi(++slash);
  1189.             if ((slash = strchr(slash,'/')) == NULL) break;
  1190.             if (k == 2) /* backward compatibility */
  1191.                 bailout = decomp[1];
  1192.             }
  1193.         return(0);
  1194.         }
  1195.     if (strcmp(variable, "distest") == 0) {
  1196.         usr_distest = numval;
  1197.         return(0);
  1198.         }
  1199.     if (strcmp(variable,"formulafile") == 0) {      /* formulafile=?        */
  1200.         strcpy(FormFileName,value);
  1201.         return(0);
  1202.         }
  1203.     if (strcmp(variable,"formulaname") == 0) {      /* formulaname=?        */
  1204.         strcpy(FormName,value);
  1205.         return(0);
  1206.         }
  1207.     if (strcmp(variable,"lfile") == 0) {
  1208.         strcpy(LFileName,value);
  1209.         return(0);
  1210.     }
  1211.     if (strcmp(variable,"lname") == 0) {
  1212.         strcpy(LName,value);
  1213.         return(0);
  1214.      }
  1215.  
  1216.     if (strcmp(variable,"preview") == 0) { /* preview? */
  1217.         if (charval == 'y')
  1218.             preview = 1;
  1219.         return(0);
  1220.         }
  1221.     if (strcmp(variable,"showbox") == 0) { /* showbox? */
  1222.         if (charval == 'y')
  1223.         showbox = 1;
  1224.         return(0);
  1225.         }
  1226.     if (strcmp(variable,"coarse") == 0) {  /* coarse=? */
  1227.         if (numval<1) argerror(curarg);
  1228.         previewfactor = numval;
  1229.         return(0);
  1230.         }
  1231.     if (strcmp(variable,"stereo") == 0) {  /* stereo=? */
  1232.         if ((numval<0) || (numval>3)) argerror(curarg);
  1233.         glassestype = numval;
  1234.         return(0);
  1235.         }
  1236.     if (strcmp(variable,"interocular") == 0) {  /* interocular=? */
  1237.         eyeseparation = numval;
  1238.         return(0);
  1239.         }
  1240.     if (strcmp(variable,"converge") == 0) {  /* converg=? */
  1241.         xadjust = numval;
  1242.         return(0);
  1243.         }
  1244.     if (strcmp(variable,"crop") == 0) {  /* crop=? */
  1245.         slash = strchr(curarg,'=');
  1246.         if ((k=atoi(++slash)) >= 0 && atoi(slash) <= 100) red_crop_left = k;
  1247.         else argerror(curarg);
  1248.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1249.         if ((k=atoi(++slash)) >= 0 && atoi(slash) <= 100) red_crop_right = k;
  1250.         else argerror(curarg);
  1251.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1252.         if ((k=atoi(++slash)) >= 0 && atoi(slash) <= 100) blue_crop_left = k;
  1253.         else argerror(curarg);
  1254.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1255.         if ((k=atoi(++slash)) >= 0 && atoi(slash) <= 100) blue_crop_right = k;
  1256.         else argerror(curarg);
  1257.         return(0);
  1258.         }
  1259.     if (strcmp(variable,"bright") == 0) {  /* bright=? */
  1260.         slash = strchr(curarg,'=');
  1261.         if ((k=atoi(++slash)) >= 0) red_bright = k;
  1262.         else argerror(curarg);
  1263.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1264.         if ((k=atoi(++slash)) >= 0) blue_bright = k;
  1265.         else argerror(curarg);
  1266.         return(0);
  1267.         }
  1268.     if (strcmp(variable,"xyadjust") == 0) { /* trans=? */
  1269.         slash = strchr(curarg,'=');
  1270.         xtrans=atoi(++slash);
  1271.         if ((slash=strchr(slash,'/')) == NULL) return(0);
  1272.         ytrans=atoi(++slash);
  1273.         return(0);
  1274.         }
  1275.     if (strcmp(variable,"randomize") == 0) {  /* RANDOMIZE=? */
  1276.         if (numval<0 || numval>7) argerror(curarg);
  1277.         RANDOMIZE = numval;
  1278.         return(0);
  1279.         }
  1280.     if (strcmp(variable,"ambient") == 0) {  /* ambient=? */
  1281.         if (numval<0||numval>100) argerror(curarg);
  1282.         Ambient = numval;
  1283.         return(0);
  1284.         }
  1285.     if (strcmp(variable,"haze") == 0) {  /* haze=? */
  1286.         if (numval<0||numval>100) argerror(curarg);
  1287.         haze = numval;
  1288.         return(0);
  1289.         }
  1290.     if (strcmp(variable,"fullcolor") == 0) {  /* fullcolor=? */
  1291.         if (charval != 'y' && charval != 'n') argerror(curarg);
  1292.         if (charval == 'y') full_color = 1;
  1293.         return(0);
  1294.         }
  1295.     if (strcmp(variable,"lightname") == 0) {         /* lightname=?   */
  1296.         if (first_init)
  1297.             strcpy(light_name,value);
  1298.         return(0);
  1299.         }
  1300.  
  1301.     argerror(curarg);
  1302.     return(-1);
  1303. }
  1304.  
  1305. static void argerror(char *badarg)    /* oops. couldn't decode this */
  1306. {
  1307.    static char far argerrormessage[]={"\
  1308. (see the Startup Help screens or documentation for a complete\n\
  1309.  argument list with descriptions)"};
  1310.    char msg[200];
  1311.    setvideomode(3,0,0,0);
  1312.    sprintf(msg,"Oops.  I couldn't understand the argument:\n  '%s'",badarg);
  1313.    if (active_system == 0) {   /* DOS version */
  1314.        buzzer(2);
  1315.        putstring(0,0,15,msg);
  1316.        putstring(3,0,7,argerrormessage);
  1317.        movecursor(8,0);
  1318.        exit(1);
  1319.        }
  1320.    else
  1321.        stopmsg(0,msg);          /* Windows version */
  1322. }
  1323.  
  1324. void set_3d_defaults()
  1325. {
  1326.    ENTER_OVLY(OVLY_CMDFILES);
  1327.    if(SPHERE) {
  1328.       PHI1    =  180;
  1329.       PHI2    =  0;
  1330.       THETA1    =  -90;
  1331.       THETA2    =  90;
  1332.       RADIUS    =  100;
  1333.       ROUGH    =  30;
  1334.       WATERLINE = 0;
  1335.       FILLTYPE    = 2;
  1336.       ZVIEWER    = 0;
  1337.       XSHIFT    = 0;
  1338.       YSHIFT    = 0;
  1339.       xtrans    = 0;
  1340.       ytrans    = 0;
  1341.       XLIGHT    = 1;
  1342.       YLIGHT    = 1;
  1343.       ZLIGHT    = 1;
  1344.       LIGHTAVG    = 0;
  1345.       Ambient    = 20;
  1346.       RANDOMIZE = 0;
  1347.       haze    = 0;
  1348.       full_color= 0;
  1349.       back_color[0] = 51; back_color[1] = 153; back_color[2] = 200;
  1350.       }
  1351.    else {
  1352.       XROT    = 60;
  1353.       YROT    = 30;
  1354.       ZROT    = 0;
  1355.       XSCALE    = 90;
  1356.       YSCALE    = 90;
  1357.       ROUGH    = 30;
  1358.       WATERLINE = 0;
  1359.       FILLTYPE    = 0;
  1360.       if (active_system != 0)
  1361.      FILLTYPE = 2;
  1362.       ZVIEWER    = 0;
  1363.       XSHIFT    = 0;
  1364.       YSHIFT    = 0;
  1365.       xtrans    = 0;
  1366.       ytrans    = 0;
  1367.       XLIGHT    = 1;
  1368.       YLIGHT    = -1;
  1369.       ZLIGHT    = 1;
  1370.       LIGHTAVG    = 0;
  1371.       Ambient    = 20;
  1372.       RANDOMIZE = 0;
  1373.       haze    = 0;
  1374.       full_color= 0;
  1375.       back_color[0] = 51; back_color[1] = 153; back_color[2] = 200;
  1376.       }
  1377.     EXIT_OVLY;
  1378. }
  1379.  
  1380. int readconfig()    /* search for, read, decode fractint.cfg file */
  1381. {
  1382.    char tempstring[101];
  1383.    FILE *cfgfile;
  1384.    int count, i, j, ax, bx, cx, dx, dotmode, xdots, ydots, colors, commas[10];
  1385.    int textsafe2;
  1386.    ENTER_OVLY(OVLY_CMDFILES);
  1387.    findpath("fractint.cfg",tempstring); /* look for FRACTINT.CFG */
  1388.    if (tempstring[0] == 0                 /* can't find the file */
  1389.      || (cfgfile = fopen(tempstring,"r")) == NULL) { /* can't open it */
  1390.       EXIT_OVLY;
  1391.       return(-1);
  1392.       }
  1393.  
  1394.    count = 0;                /* build a new videomode file */
  1395.    while (feof(cfgfile) == 0 && count < MAXVIDEOMODES) {   /* scan through strings */
  1396.       if (!fgets(tempstring, 100, cfgfile)) break;
  1397.       tempstring[strlen(tempstring)-1] = 0;
  1398.       if (tempstring[0] <= 32) continue;    /* comment line     */
  1399.       j = 9;
  1400.       for (i = 0; i <= j; i++) commas[i] = 0;
  1401.       for (i = strlen(tempstring); i >= 0 && j >= 0; i--)  /* check for commas */
  1402.      if (tempstring[i] == ',') {
  1403.         tempstring[i] = 0;
  1404.         commas[--j] = i+1;
  1405.         }
  1406.       sscanf(&tempstring[commas[0]],"%x",&ax);
  1407.       sscanf(&tempstring[commas[1]],"%x",&bx);
  1408.       sscanf(&tempstring[commas[2]],"%x",&cx);
  1409.       sscanf(&tempstring[commas[3]],"%x",&dx);
  1410.       dotmode      = atoi(&tempstring[commas[4]]);
  1411.       xdots      = atoi(&tempstring[commas[5]]);
  1412.       ydots      = atoi(&tempstring[commas[6]]);
  1413.       colors      = atoi(&tempstring[commas[7]]);
  1414.       textsafe2   = dotmode / 100;
  1415.       dotmode     %= 100;
  1416.       if (  i >= 0 || j != 0 ||
  1417.         dotmode < 0 || dotmode > 30 ||
  1418.         textsafe2 < 0 || textsafe2 > 4 ||
  1419.         xdots < 160 || xdots > 2048 ||
  1420.         ydots < 160 || ydots > 2048 ||
  1421.         (colors != 2 && colors != 4 && colors != 16 && colors != 256)
  1422.        ) {
  1423.      buzzer(2);
  1424.      printf("\n\n There is a bad entry in fractint.cfg\n\n");
  1425.      printf(" ==> %s \n", tempstring);
  1426.      exit(-1);
  1427.      }
  1428.       tempstring[commas[8]+26] = 0;
  1429.       if (commas[0] >= 25) tempstring[25] = 0;
  1430.       strcpy(videoentry.name,     tempstring);
  1431.       strcpy(videoentry.comment, &tempstring[commas[8]]);
  1432.       if (tempstring[commas[8]] == ' ')
  1433.      strcpy(videoentry.comment, &tempstring[commas[8]+1]);
  1434.       videoentry.videomodeax =     ax;
  1435.       videoentry.videomodebx =     bx;
  1436.       videoentry.videomodecx =     cx;
  1437.       videoentry.videomodedx =     dx;
  1438.       videoentry.dotmode     =     textsafe2 * 100 + dotmode;
  1439.       videoentry.xdots         =     xdots;
  1440.       videoentry.ydots         =     ydots;
  1441.       videoentry.colors      =     colors;
  1442.       tovideotable(count);
  1443.       count++;
  1444.       }
  1445.  
  1446.    if (count > 0) strcpy(videoentry.name, "END");
  1447.    videoentry.colors = 0;
  1448.    tovideotable(count);
  1449.    fclose(cfgfile);
  1450.    EXIT_OVLY;
  1451.    if (count <= 0) return(-1);
  1452.    return(0);            /* successful return    */
  1453. }
  1454.  
  1455. static void makeconfig()    /* routine to build a FRACTINT.CFG file */
  1456. {
  1457.    char tempstring[101];
  1458.    FILE *cfgfile;
  1459.    int count;
  1460.  
  1461.    if (active_system != 0)  /* non-DOS version */
  1462.        return;
  1463.  
  1464. #ifdef __TURBOC__
  1465.    strcpy(tempstring,searchpath("fractint.cfg"));
  1466. #else
  1467.    _searchenv("fractint.cfg","PATH",tempstring);
  1468. #endif
  1469.  
  1470.    if (tempstring[0] != 0) {
  1471.       buzzer(2);
  1472.       printf("\n There is a FRACTINT.CFG file already located in the PATH.\n\n");
  1473.       printf(" I won't make another one until after you manually remove\n");
  1474.       printf(" the old one.  Safety first!\n\n");
  1475.       exit(-1);
  1476.       }
  1477.  
  1478.    if ((cfgfile = fopen("fractint.cfg","w")) == NULL)
  1479.       exit(-1);                   /* ?? can't open file   */
  1480.    fprintf(cfgfile,"   Full FRACTINT.CFG File, built by a 'fractint batch=config' command\n\n");
  1481.    fprintf(cfgfile," name of adapter/mode    | AX | BX | CX | DX |mode|  x |  y |clrs| comments\n");
  1482.    fprintf(cfgfile," =============================================================================\n\n");
  1483.    for (count = 0; count < maxvideomode; count++) {    /* write the entries */
  1484.       fromvideotable(count);
  1485. #ifdef __TURBOC__
  1486.       fprintf(cfgfile,"%-25.25s,%4x,%4x,%4x,%4x,%4d,%4d,%4d,%4d, %-25.25s\n",
  1487. #else
  1488.       fprintf(cfgfile,"%-25s,%4x,%4x,%4x,%4x,%4d,%4d,%4d,%4d, %-25s\n",
  1489. #endif
  1490.           videoentry.name,
  1491.           videoentry.videomodeax,
  1492.           videoentry.videomodebx,
  1493.           videoentry.videomodecx,
  1494.           videoentry.videomodedx,
  1495.           videoentry.dotmode,
  1496.           videoentry.xdots,
  1497.           videoentry.ydots,
  1498.           videoentry.colors,
  1499.           videoentry.comment);
  1500.       }
  1501.    fclose(cfgfile);
  1502. }
  1503.  
  1504.