home *** CD-ROM | disk | FTP | other *** search
/ Mega A/V / mega_av.zip / mega_av / GRAPHUTL / FRPOR172.ZIP / CMDFILES.C < prev    next >
C/C++ Source or Header  |  1992-03-14  |  62KB  |  1,988 lines

  1. /*
  2.     Command-line / Command-File Parser Routines
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <float.h>
  10. #include <ctype.h>
  11. #include "fractint.h"
  12. #ifdef __TURBOC__
  13. #include <dir.h>
  14. #endif
  15.  
  16. #ifdef XFRACT
  17. #define DEFAULT_PRINTER 5    /* Assume a Postscript printer */
  18. #define PRT_RESOLUTION  100    /* Assume medium resolution    */
  19. #define INIT_GIF87 1        /* Turn off GIF 89a processing */
  20. #else
  21. #define DEFAULT_PRINTER 2    /* Assume an IBM/Epson printer */
  22. #define PRT_RESOLUTION  60    /* Assume low resolution       */
  23. #define INIT_GIF87      0    /* Turn on GIF 89a processing  */
  24. #endif
  25.  
  26. /* routines in this module    */
  27.  
  28. void cmdfiles_overlay(void);
  29. int  cmdfiles(int argc, char *argv[]);
  30. int  load_commands(FILE *);
  31. void set_3d_defaults(void);
  32.  
  33. static int  cmdfile(FILE *,int);
  34. static int  next_command(char *,int,FILE *,char *,int *,int);
  35. static int  next_line(FILE *,char *,int);
  36. static int  cmdarg(char *,int);
  37. static void argerror(char *);
  38. static void initvars_run(void);
  39. static void initvars_restart(void);
  40. static void initvars_fractal(void);
  41. static void initvars_3d(void);
  42. static void reset_ifs_defn(void);
  43. static void parse_textcolors(char *value);
  44. static int  parse_colors(char *value);
  45. static int  parse_printer(char *value);
  46.  
  47. extern int  makedoc_msg_func(int,int);
  48.  
  49. /* variables defined by the command line/files processor */
  50. int        showdot;    /* color to show crawling graphics cursor */
  51. char    temp1[256];        /* temporary strings        */
  52. char    readname[80];        /* name of fractal input file */
  53. char    gifmask[13] = {""};
  54. char    PrintName[80]={"fract001.prn"}; /* Name for print-to-file */
  55. char    savename[80]={"fract001"};      /* save files using this name */
  56. char    autoname[80]={"auto.key"};      /* record auto keystrokes here */
  57. int    potflag=0;        /* continuous potential enabled? */
  58. int    pot16bit;        /* store 16 bit continuous potential values */
  59. int    gif87a_flag;        /* 1 if GIF87a format, 0 otherwise */
  60. int    askvideo;        /* flag for video prompting */
  61. char    floatflag;
  62. int    biomorph;        /* flag for biomorph */
  63. int    usr_biomorph;
  64. int    forcesymmetry;        /* force symmetry */
  65. int    showfile;        /* zero if file display pending */
  66. int    rflag, rseed;        /* Random number seeding flag and value */
  67. int    decomp[2];        /* Decomposition coloring */
  68. int    distest;
  69. int    distestwidth;
  70. char overwrite = 0;    /* 0 if file overwrite not allowed */
  71. int    soundflag;        /* 0 if sound is off, 1 if on */
  72. int    basehertz;        /* sound=x/y/x hertz value */
  73. int    debugflag;        /* internal use only - you didn't see this */
  74. int    timerflag;        /* you didn't see this, either */
  75. int    cyclelimit;        /* color-rotator upper limit */
  76. int    inside;         /* inside color: 1=blue     */
  77. int    fillcolor;         /* fillcolor: -1=normal     */
  78. int    outside;        /* outside color    */
  79. int    finattract;        /* finite attractor logic */
  80. int    display3d;        /* 3D display flag: 0 = OFF */
  81. int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  82. int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  83. int    initbatch;        /* 1 if batch run (no kbd)  */
  84. unsigned initsavetime;        /* autosave minutes        */
  85. double    initorbit[2];        /* initial orbitvalue */
  86. char    useinitorbit;        /* flag for initorbit */
  87. int    initmode;        /* initial video mode        */
  88. int    initcyclelimit;     /* initial cycle limit        */
  89. BYTE usemag;        /* use center-mag corners   */
  90. int    bailout;        /* user input bailout value */
  91. double    inversion[3];        /* radius, xcenter, ycenter */
  92. int    rotate_lo,rotate_hi;    /* cycling color range        */
  93. int far *ranges;        /* iter->color ranges mapping */
  94. int    rangeslen = 0;        /* size of ranges array     */
  95. char far *mapdacbox = NULL;    /* map= (default colors)    */
  96. int    colorstate;        /* 0, dacbox matches default (bios or map=) */
  97.                 /* 1, dacbox matches no known defined map   */
  98.                 /* 2, dacbox matches the colorfile map        */
  99. int    colorpreloaded;     /* if dacbox preloaded for next mode select */
  100. extern int Targa_Overlay;
  101. int Targa_Out = 0;
  102. char    colorfile[80];        /* from last <l> <s> or colors=@filename    */
  103.  
  104. /* TARGA+ variables */
  105. int    TPlusFlag;        /* Use the TARGA+ if found  */
  106. int    MaxColorRes;        /* Default Color Resolution if available */
  107. int    PixelZoom;        /* TPlus Zoom Level */
  108. int    NonInterlaced;        /* Non-Interlaced video flag */
  109.  
  110. /* 3D Transparency Variables, MCP 5-30-91 */
  111. double xcoord, ycoord, zcoord, tcoord;
  112. double zzmin, zzmax;        /* initial depth corner values */
  113. double ttmin, ttmax;        /* initial time coordinates */
  114. int Transparent3D, SolidCore, MultiDrawing;
  115. int tpdepth, tptime;
  116. unsigned CoreRed, CoreGreen, CoreBlue, NumFrames;
  117.  
  118. /* AntiAliasing variables, MCP 6-6-91 */
  119. int AntiAliasing, Shadowing;
  120.  
  121. int    orbitsave = 0;        /* for IFS and LORENZ to output acrospin file */
  122. int orbit_delay;                /* clock ticks delating orbit release */
  123. extern    int invert;
  124. extern int fractype;        /* fractal type         */
  125. extern double param[4];     /* initial parameters        */
  126. extern double xxmin,xxmax;    /* initial corner values    */
  127. extern double yymin,yymax;    /* initial corner values    */
  128. extern double xx3rd,yy3rd;    /* initial corner values    */
  129. extern char usr_stdcalcmode;    /* '1', '2', 'g', 'b'       */
  130. extern int maxit;        /* max iterations        */
  131. extern int usr_periodicitycheck; /* periodicity checking  1=on,0=off */
  132. extern char usr_floatflag;    /* flag for float calcs */
  133. extern int usr_distest;     /* nonzero if distance estimator option */
  134. extern char color_lakes;    /* finite attractor flag */
  135. extern int haze;
  136. extern int RANDOMIZE;
  137. extern int Ambient;
  138. extern char light_name[];
  139. extern int BRIEF;
  140. extern int RAY;
  141.  
  142. extern BYTE back_color[];
  143. extern BYTE dacbox[256][3];
  144. extern struct videoinfo far videotable[];
  145. extern int fpu;
  146. extern int iit;
  147.  
  148. extern double potparam[];    /* potential parameters  */
  149. extern int Printer_Resolution, LPTNumber,
  150.        Printer_Type, Printer_Titleblock,
  151.        Printer_ColorXlat, Printer_SetScreen,
  152.        Printer_SFrequency, Printer_SAngle, Printer_SStyle,
  153.        Printer_RFrequency, Printer_RAngle, Printer_RStyle,
  154.        Printer_GFrequency, Printer_GAngle, Printer_GStyle,
  155.        Printer_BFrequency, Printer_BAngle, Printer_BStyle,
  156.        EPSFileType, ColorPS,
  157.        Print_To_File,Printer_CRLF;        /* for printer functions */
  158.  
  159. int    transparent[2];     /* transparency min/max values */
  160. int    LogFlag;        /* Logarithmic palette flag: 0 = no */
  161.  
  162. BYTE exitmode = 3;    /* video mode on exit */
  163.  
  164. extern int video_type;
  165. extern int svga_type;           /* for forcing a specific SVGA adapter */
  166. extern int mode7text;
  167. extern int textsafe;
  168. extern int vesa_detect;
  169.  
  170. int        bios_palette;        /* set to 1 to force BIOS palette updates */
  171. int        escape_exit;         /* set to 1 to avoid the "are you sure?" screen */
  172.  
  173. extern int   viewwindow;
  174. extern float viewreduction;
  175. extern int   viewcrop;
  176. extern float finalaspectratio;
  177. extern int   viewxdots,viewydots;
  178.  
  179. extern char MAP_name[];
  180. extern int mapset;
  181.  
  182. extern int eyeseparation; /* Occular Separation */
  183. extern int glassestype;
  184. extern int xadjust; /* Convergence */
  185. extern int yadjust;
  186. extern int xtrans, ytrans; /* X,Y shift with no perspective */
  187. extern int red_crop_left, red_crop_right;
  188. extern int blue_crop_left, blue_crop_right;
  189. extern int red_bright, blue_bright;
  190. extern char showbox; /* flag to show box and vector in preview */
  191. extern char preview;        /* 3D preview mode flag */
  192. extern int previewfactor; /* Coarsness */
  193.  
  194. int first_init=1;        /* first time into cmdfiles? */
  195. static int init_rseed;
  196. static char initcorners,initparams;
  197. struct fractalspecificstuff far *curfractalspecific;
  198.  
  199. char FormFileName[80];        /* file to find (type=)formulas in */
  200. char FormName[ITEMNAMELEN+1];    /* Name of the Formula (if not null) */
  201. char LFileName[80];        /* file to find (type=)L-System's in */
  202. char LName[ITEMNAMELEN+1];    /* Name of L-System */
  203. char CommandFile[80];        /* file to find command sets in */
  204. char CommandName[ITEMNAMELEN+1];/* Name of Command set */
  205. char CommandComment1[57];    /* comments for command set */
  206. char CommandComment2[57];
  207. char IFSFileName[80];        /* file to find (type=)IFS in */
  208. char IFSName[ITEMNAMELEN+1];    /* Name of the IFS def'n (if not null) */
  209. float far *ifs_defn = NULL;    /* ifs parameters */
  210. int  ifs_changed;        /* nonzero if parameters have been edited */
  211. int  ifs_type;            /* 0=2d, 1=3d */
  212. int  slides = 0;        /* 1 autokey=play, 2 autokey=record */
  213.  
  214. BYTE txtcolor[]={
  215.       BLUE*16+L_WHITE,      /* C_TITLE           title background */
  216.       BLUE*16+L_GREEN,      /* C_TITLE_DEV       development vsn foreground */
  217.       GREEN*16+YELLOW,      /* C_HELP_HDG        help page title line */
  218.       WHITE*16+BLACK,      /* C_HELP_BODY       help page body */
  219.       GREEN*16+GRAY,      /* C_HELP_INSTR      help page instr at bottom */
  220.       WHITE*16+BLUE,      /* C_HELP_LINK       help page links */
  221.       CYAN*16+BLUE,      /* C_HELP_CURLINK    help page current link */
  222.       WHITE*16+GRAY,      /* C_PROMPT_BKGRD    prompt/choice background */
  223.       WHITE*16+BLACK,      /* C_PROMPT_TEXT     prompt/choice extra info */
  224.       BLUE*16+WHITE,      /* C_PROMPT_LO       prompt/choice text */
  225.       BLUE*16+L_WHITE,      /* C_PROMPT_MED      prompt/choice hdg2/... */
  226.       BLUE*16+YELLOW,      /* C_PROMPT_HI       prompt/choice hdg/cur/... */
  227.       GREEN*16+L_WHITE,   /* C_PROMPT_INPUT    fullscreen_prompt input */
  228.       CYAN*16+L_WHITE,      /* C_PROMPT_CHOOSE   fullscreen_prompt choice */
  229.       MAGENTA*16+L_WHITE, /* C_CHOICE_CURRENT  fullscreen_choice input */
  230.       BLACK*16+WHITE,      /* C_CHOICE_SP_INSTR speed key bar & instr */
  231.       BLACK*16+L_MAGENTA, /* C_CHOICE_SP_KEYIN speed key value */
  232.       WHITE*16+BLUE,      /* C_GENERAL_HI      tab, thinking, IFS */
  233.       WHITE*16+BLACK,      /* C_GENERAL_MED */
  234.       WHITE*16+GRAY,      /* C_GENERAL_LO */
  235.       BLACK*16+L_WHITE,   /* C_GENERAL_INPUT */
  236.       WHITE*16+BLACK,      /* C_DVID_BKGRD      disk video */
  237.       BLACK*16+YELLOW,      /* C_DVID_HI */
  238.       BLACK*16+L_WHITE,   /* C_DVID_LO */
  239.       RED*16+L_WHITE,      /* C_STOP_ERR        stop message, error */
  240.       GREEN*16+BLACK,      /* C_STOP_INFO       stop message, info */
  241.       BLUE*16+WHITE,      /* C_TITLE_LOW       bottom lines of title screen */
  242.       GREEN*16+BLACK,      /* C_AUTHDIV1        title screen dividers */
  243.       GREEN*16+GRAY,      /* C_AUTHDIV2        title screen dividers */
  244.       BLACK*16+L_WHITE,   /* C_PRIMARY           primary authors */
  245.       BLACK*16+WHITE      /* C_CONTRIB           contributing authors */
  246.       };
  247.  
  248. extern int active_system;
  249. /* start of string literals cleanup */
  250. char s_iter[]    = "iter";
  251. char s_real[]    = "real";
  252. char s_mult[]     = "mult";
  253. char s_sum[]     = "summ";
  254. char s_imag[]    = "imag";
  255. char s_zmag[]    = "zmag";
  256. char s_bof60[]   = "bof60";
  257. char s_bof61[]   = "bof61";
  258. char s_maxiter[] =  "maxiter";
  259. char s_epscross[] =  "epsilon cross";
  260. char s_startrail[] =  "star trail";
  261. char s_normal[] =  "normal";
  262.  
  263.  
  264. void cmdfiles_overlay() { }    /* for restore_active_ovly */
  265.  
  266. /*
  267.     cmdfiles(argc,argv) process the command-line arguments
  268.         it also processes the 'sstools.ini' file and any
  269.         indirect files ('fractint @myfile')
  270. */
  271.  
  272. int cmdfiles(int argc,char *argv[])
  273. {
  274.    int       i;
  275.    char    curarg[141];
  276.    char    tempstring[101];
  277.    char    *sptr;
  278.    FILE    *initfile;
  279.  
  280.    ENTER_OVLY(OVLY_CMDFILES);
  281.  
  282.    if (first_init) initvars_run();    /* once per run initialization */
  283.    initvars_restart();            /* <ins> key initialization */
  284.    initvars_fractal();            /* image initialization */
  285.  
  286.    findpath("sstools.ini", tempstring); /* look for SSTOOLS.INI */
  287.    if (tempstring[0] != 0)        /* found it! */
  288.       if ((initfile = fopen(tempstring,"r")) != NULL)
  289.      cmdfile(initfile,1);        /* process it */
  290.  
  291.    for (i = 1; i < argc; i++) {     /* cycle through args */
  292. #ifdef XFRACT
  293.       /* Let the xfract code take a look at the argument */
  294.       if (unixarg(argc,argv,&i)) continue;
  295. #endif
  296.       strcpy(curarg,argv[i]);
  297.       if (curarg[0] == ';')             /* start of comments? */
  298.      break;
  299.       if (curarg[0] != '@') {           /* simple command? */
  300.      if (strchr(curarg,'=') == NULL) { /* not xxx=yyy, so check for gif */
  301.         strcpy(tempstring,curarg);
  302.         if (strchr(curarg,'.') == NULL)
  303.            strcat(tempstring,".gif");
  304.         if ((initfile = fopen(tempstring,"rb"))) {
  305.            fread(tempstring,6,1,initfile);
  306.            if ( tempstring[0] == 'G'
  307.          && tempstring[1] == 'I'
  308.          && tempstring[2] == 'F'
  309.          && tempstring[3] >= '8' && tempstring[3] <= '9'
  310.          && tempstring[4] >= '0' && tempstring[4] <= '9') {
  311.           strcpy(readname,curarg);
  312.           curarg[0] = showfile = 0;
  313.           }
  314.            fclose(initfile);
  315.            }
  316.         }
  317.      if (curarg[0])
  318.         cmdarg(curarg,0);        /* process simple command */
  319.      }
  320.       else if ((sptr = strchr(curarg,'/'))) { /* @filename/setname? */
  321.      *sptr = 0;
  322.      strcpy(CommandFile,&curarg[1]);
  323.      strcpy(CommandName,sptr+1);
  324.      find_file_item(CommandFile,CommandName,&initfile);
  325.      cmdfile(initfile,3);
  326.      }
  327.       else {                /* @filename */
  328.      if ((initfile = fopen(&curarg[1],"r")) == NULL)
  329.         argerror(curarg);
  330.      cmdfile(initfile,0);
  331.      }
  332.       }
  333.  
  334.    if (first_init == 0) {
  335.       initmode = -1; /* don't set video when <ins> key used */
  336.       showfile = 1;  /* nor startup image file            */
  337.       }
  338.  
  339.    first_init = 0;
  340.    EXIT_OVLY;
  341.    return(0);
  342. }
  343.  
  344.  
  345. int load_commands(FILE *infile)
  346. {
  347.    /* when called, file is open in binary mode, positioned at the */
  348.    /* '(' or '{' following the desired parameter set's name       */
  349.    int ret;
  350.    ENTER_OVLY(OVLY_CMDFILES);
  351.    initcorners = initparams = 0; /* reset flags for type= */
  352.    ret = cmdfile(infile,2);
  353.    EXIT_OVLY;
  354.    return ret;
  355. }
  356.  
  357.  
  358. static void initvars_run()        /* once per run init */
  359. {
  360.    init_rseed = (int)time(NULL);
  361. }
  362.  
  363. static void initvars_restart()        /* <ins> key init */
  364. {
  365.    gif87a_flag = INIT_GIF87;            /* turn on GIF89a processing */
  366.    askvideo = 1;            /* turn on video-prompt flag */
  367.    overwrite = 0;            /* don't overwrite           */
  368.    soundflag = -1;            /* sound is on             */
  369.    basehertz = 440;            /* basic hertz rate         */
  370.    initbatch = 0;            /* not in batch mode         */
  371.    initsavetime = 0;            /* no auto-save          */
  372.    initmode = -1;            /* no initial video mode     */
  373.    viewwindow = 0;            /* no view window         */
  374.    viewreduction = 4.2;
  375.    viewcrop = 1;
  376.    finalaspectratio = SCREENASPECT;
  377.    viewxdots = viewydots = 0;
  378.    orbit_delay = 0;                     /* full speed orbits */
  379.    debugflag = 0;            /* debugging flag(s) are off */
  380.    timerflag = 0;            /* timer flags are off         */
  381.    strcpy(FormFileName,"fractint.frm"); /* default formula file      */
  382.    FormName[0] = 0;
  383.    strcpy(LFileName,"fractint.l");
  384.    LName[0] = 0;
  385.    strcpy(CommandFile,"fractint.par");
  386.    CommandName[0] = CommandComment1[0] = CommandComment2[0] = 0;
  387.    strcpy(IFSFileName,"fractint.ifs");
  388.    IFSName[0] = 0;
  389.    reset_ifs_defn();
  390.    rflag = 0;                /* not a fixed srand() seed */
  391.    rseed = init_rseed;
  392.    strcpy(readname,DOTSLASH);           /* initially current directory */
  393.    showfile = 1;
  394.    /* next should perhaps be fractal re-init, not just <ins> ? */
  395.    initcyclelimit=55;            /* spin-DAC default speed limit */
  396.    mapset = 0;                /* no map= name active */
  397.    if (mapdacbox) {
  398.       farmemfree(mapdacbox);
  399.       mapdacbox = NULL;
  400.       }
  401.    TPlusFlag = 1;
  402.    MaxColorRes = 8;
  403.    PixelZoom = 0;
  404.    NonInterlaced = 0;
  405.  
  406.    Transparent3D = 0;
  407.    SolidCore = 1;
  408.    CoreRed   = 128;
  409.    CoreGreen = 128;
  410.    CoreBlue  = 128;
  411.    zzmin = -1.5;
  412.    zzmax = 1.5;
  413.    ttmin = 0.0;
  414.    ttmax = 0.0;
  415.    NumFrames = 1;
  416.    tpdepth = tptime = 0;
  417.  
  418.    AntiAliasing = 0;
  419.    Shadowing = 0;
  420.  
  421.    Printer_Type = DEFAULT_PRINTER;      /* assume an IBM/EPSON    */
  422.    Printer_Resolution = PRT_RESOLUTION; /* assume low resolution  */
  423.    Printer_Titleblock = 0;        /* assume no title block  */
  424.    Printer_ColorXlat = 0;        /* assume positive image  */
  425.    Printer_SetScreen = 0;               /* assume default screen  */
  426.    Printer_SFrequency = 45;             /* New screen frequency K */
  427.    Printer_SAngle = 45;                 /* New screen angle     K */
  428.    Printer_SStyle = 1;                  /* New screen style     K */
  429.    Printer_RFrequency = 45;             /* New screen frequency R */
  430.    Printer_RAngle = 75;                 /* New screen angle     R */
  431.    Printer_RStyle = 1;                  /* New screen style     R */
  432.    Printer_GFrequency = 45;             /* New screen frequency G */
  433.    Printer_GAngle = 15;                 /* New screen angle     G */
  434.    Printer_GStyle = 1;                  /* New screen style     G */
  435.    Printer_BFrequency = 45;             /* New screen frequency B */
  436.    Printer_BAngle = 0;                  /* New screen angle     B */
  437.    Printer_BStyle = 1;                  /* New screen style     B */
  438. #ifndef XFRACT
  439.    Print_To_File = 0;                   /* No print-to-file       */
  440.    Printer_CRLF = 0;                    /* Assume CR+LF           */
  441. #else
  442.    Print_To_File = 1;                   /* Print-to-file          */
  443.    Printer_CRLF = 2;                    /* Assume LF              */
  444. #endif
  445.    EPSFileType = 0;            /* Assume no save to .EPS */
  446.    LPTNumber = 1;            /* assume LPT1 */
  447.    ColorPS = 0;                         /* Assume NO Color PostScr*/
  448.  
  449. }
  450.  
  451. static void initvars_fractal()        /* init vars affecting calculation */
  452. {
  453.    int i;
  454.    bios_palette = 0;                    /* don't force use of a BIOS palette */
  455.    escape_exit = 0;                     /* don't disable the "are you sure?" screen */
  456.    usr_periodicitycheck = 1;        /* turn on periodicity      */
  457.    inside = 1;                /* inside color = blue      */
  458.    fillcolor = -1;            /* no special fill color */
  459.    usr_biomorph = -1;            /* turn off biomorph flag */
  460.    outside = -1;            /* outside color = -1 (not used) */
  461.    maxit = 150;             /* initial maxiter      */
  462.    usr_stdcalcmode = 'g';               /* initial solid-guessing */
  463.    usr_floatflag = 0;            /* turn off the float flag */
  464.    finattract = 0;            /* disable finite attractor logic */
  465.    fractype = 0;            /* initial type Set flag  */
  466.    curfractalspecific = &fractalspecific[0];
  467.    initcorners = initparams = 0;
  468.    bailout = 0;             /* no user-entered bailout */
  469.    useinitorbit = 0;
  470.    for (i = 0; i < 4; i++) param[i] = 0.0;     /* initial parameter values */
  471.    for (i = 0; i < 3; i++) potparam[i]    = 0.0; /* initial potential values */
  472.    for (i = 0; i < 3; i++) inversion[i] = 0.0;    /* initial invert values */
  473.    initorbit[0] = initorbit[1] = 0.0;    /* initial orbit values */
  474.    invert = 0;
  475.    decomp[0] = decomp[1] = 0;
  476.    usr_distest = 0;
  477.    distestwidth = 71;
  478.    forcesymmetry = 999;         /* symmetry not forced */
  479.    xx3rd = xxmin = -2.5; xxmax = 1.5;    /* initial corner values  */
  480.    yy3rd = yymin = -1.5; yymax = 1.5;    /* initial corner values  */
  481.    pot16bit = potflag = 0;
  482.    LogFlag = 0;             /* no logarithmic palette */
  483.    set_trig_array(0,"sin");             /* trigfn defaults */
  484.    set_trig_array(1,"sqr");
  485.    set_trig_array(2,"sinh");
  486.    set_trig_array(3,"cosh");
  487.    if (rangeslen) {
  488.       farmemfree((char far *)ranges);
  489.       rangeslen = 0;
  490.       }
  491.    usemag = 0;                /* use corners, not center-mag */
  492.  
  493.    colorstate = colorpreloaded = 0;
  494.    rotate_lo = 1; rotate_hi = 255;    /* color cycling default range */
  495.  
  496.    display3d = 0;            /* 3D display is off        */
  497.    overlay3d = 0;            /* 3D overlay is off        */
  498.  
  499.    initvars_3d();
  500. }
  501.  
  502. static void initvars_3d()        /* init vars affecting 3d */
  503. {
  504.    RAY     = 0;
  505.    BRIEF   = 0;
  506.    SPHERE = FALSE;
  507.    preview = 0;
  508.    showbox = 0;
  509.    xadjust = 0;
  510.    yadjust = 0;
  511.    eyeseparation = 0;
  512.    glassestype = 0;
  513.    previewfactor = 20;
  514.    red_crop_left   = 4;
  515.    red_crop_right  = 0;
  516.    blue_crop_left  = 0;
  517.    blue_crop_right = 4;
  518.    red_bright      = 80;
  519.    blue_bright     = 100;
  520.    transparent[0] = transparent[1] = 0; /* no min/max transparency */
  521.    set_3d_defaults();
  522. }
  523.  
  524. static void reset_ifs_defn()
  525. {
  526.    if (ifs_defn) {
  527.       farmemfree((char far *)ifs_defn);
  528.       ifs_defn = NULL;
  529.       }
  530. }
  531.  
  532.  
  533. static int cmdfile(FILE *handle,int mode)
  534.    /* mode = 0 command line @filename          */
  535.    /*         1 sstools.ini              */
  536.    /*         2 <@> command after startup      */
  537.    /*         3 command line @filename/setname */
  538. {
  539.    /* note that cmdfile could be open as text OR as binary */
  540.    /* binary is used in @ command processing for reasonable speed note/point */
  541.    int i;
  542.    int lineoffset = 0;
  543.    int changeflag = 0; /* &1 fractal stuff chgd, &2 3d stuff chgd */
  544.    char linebuf[513],cmdbuf[1001];
  545.    if (mode == 2 || mode == 3) {
  546.       while ((i = getc(handle)) != '{' && i != EOF) { }
  547.       CommandComment1[0] = CommandComment2[0] = 0;
  548.       }
  549.    linebuf[0] = 0;
  550.    while (next_command(cmdbuf,1000,handle,linebuf,&lineoffset,mode) > 0) {
  551.       if ((mode == 2 || mode == 3) && strcmp(cmdbuf,"}") == 0) break;
  552.       if ((i = cmdarg(cmdbuf,mode)) < 0) break;
  553.       changeflag |= i;
  554.       }
  555.    fclose(handle);
  556.    return changeflag;
  557. }
  558.  
  559. static int next_command(char *cmdbuf,int maxlen,
  560.               FILE *handle,char *linebuf,int *lineoffset,int mode)
  561. {
  562.    int cmdlen = 0;
  563.    char *lineptr;
  564.    lineptr = linebuf + *lineoffset;
  565.    while(1) {
  566.       while (*lineptr <= ' ' || *lineptr == ';') {
  567.      if (cmdlen) {            /* space or ; marks end of command */
  568.         cmdbuf[cmdlen] = 0;
  569.         *lineoffset = lineptr - linebuf;
  570.         return cmdlen;
  571.         }
  572.      while (*lineptr && *lineptr <= ' ')
  573.         ++lineptr;            /* skip spaces and tabs */
  574.      if (*lineptr == ';' || *lineptr == 0) {
  575.         if (*lineptr == ';'
  576.           && (mode == 2 || mode == 3)
  577.           && (CommandComment1[0] == 0 || CommandComment2[0] == 0)) {
  578.            /* save comment */
  579.            while (*(++lineptr)
  580.          && (*lineptr == ' ' || *lineptr == '\t')) { }
  581.            if (*lineptr) {
  582.           if (strlen(lineptr) > 56)
  583.              *(lineptr+56) = 0;
  584.           if (CommandComment1[0] == 0)
  585.              strcpy(CommandComment1,lineptr);
  586.           else
  587.              strcpy(CommandComment2,lineptr);
  588.           }
  589.            }
  590.         if (next_line(handle,linebuf,mode) != 0)
  591.            return(-1); /* eof */
  592.         lineptr = linebuf; /* start new line */
  593.         }
  594.      }
  595.       if (*lineptr == '\\'              /* continuation onto next line? */
  596.     && *(lineptr+1) == 0) {
  597.      if (next_line(handle,linebuf,mode) != 0) {
  598.         argerror(cmdbuf);        /* missing continuation */
  599.         return(-1);
  600.         }
  601.      lineptr = linebuf;
  602.      while (*lineptr && *lineptr <= ' ')
  603.         ++lineptr;            /* skip white space @ start next line */
  604.      continue;            /* loop to check end of line again */
  605.      }
  606.       cmdbuf[cmdlen] = *(lineptr++);    /* copy character to command buffer */
  607.       if (++cmdlen >= maxlen) {     /* command too long? */
  608.      argerror(cmdbuf);
  609.      return(-1);
  610.      }
  611.       }
  612. }
  613.  
  614. static int next_line(FILE *handle,char *linebuf,int mode)
  615. {
  616.    int toolssection;
  617.    char tmpbuf[10];
  618.    toolssection = 0;
  619.    while (file_gets(linebuf,512,handle) >= 0) {
  620.       if (mode == 1 && linebuf[0] == '[') {     /* check for [fractint] */
  621.      strncpy(tmpbuf,&linebuf[1],9);
  622.      tmpbuf[9] = 0;
  623.      strlwr(tmpbuf);
  624.      toolssection = strncmp(tmpbuf,"fractint]",9);
  625.      continue;                /* skip tools section heading */
  626.      }
  627.       if (toolssection == 0) return(0);
  628.       }
  629.    return(-1);
  630. }
  631.  
  632.  
  633. /*
  634.   cmdarg(string,mode) processes a single command-line/command-file argument
  635.     return:
  636.       -1 error, >= 0 ok
  637.       if ok, return value:
  638.     | 1 means fractal parm has been set
  639.     | 2 means 3d parm has been set
  640.     | 4 means 3d=yes specified
  641.     | 8 means reset specified
  642. */
  643.  
  644. static int cmdarg(char *curarg,int mode) /* process a single argument */
  645. {
  646.    char    variable[21];        /* variable name goes here   */
  647.    char    *value;            /* pointer to variable value */
  648.    int       valuelen;            /* length of value         */
  649.    int       numval;            /* numeric value of arg      */
  650. #define NONNUMERIC -32767
  651.    char    charval;            /* first character of arg    */
  652.    int       yesnoval;            /* 0 if 'n', 1 if 'y', -1 if not */
  653.    double  ftemp;
  654.    int       i, j, k, l;
  655.    char    *argptr,*argptr2;
  656.    int       totparms;            /* # of / delimited parms    */
  657.    int       intparms;            /* # of / delimited ints     */
  658.    int       floatparms;            /* # of / delimited floats   */
  659.    int       intval[64];            /* pre-parsed integer parms  */
  660.    double  floatval[16];        /* pre-parsed floating parms */
  661.    char    tmpc;
  662.    int       lastarg;
  663.  
  664.    argptr = curarg;
  665.    while (*argptr) {            /* convert to lower case */
  666.       if (*argptr >= 'A' && *argptr <= 'Z')
  667.      *argptr += 'a' - 'A';
  668.       if (*argptr == '=' && strncmp(curarg,"colors=",7) == 0)
  669.      break;             /* don't convert colors=value */
  670.       ++argptr;
  671.       }
  672.  
  673.    if ((value = strchr(&curarg[1],'='))) {
  674.       if ((j = (value++) - curarg) > 1 && curarg[j-1] == ':')
  675.      --j;                /* treat := same as =      */
  676.       }
  677.    else
  678.       value = curarg + (j = strlen(curarg));
  679.    if (j > 20) goto badarg;        /* keyword too long */
  680.    strncpy(variable,curarg,j);        /* get the variable name  */
  681.    variable[j] = 0;            /* truncate variable name */
  682.    valuelen = strlen(value);        /* note value's length    */
  683.    charval = value[0];            /* first letter of value  */
  684.    yesnoval = -1;            /* note yes|no value      */
  685.    if (charval == 'n') yesnoval = 0;
  686.    if (charval == 'y') yesnoval = 1;
  687.  
  688.    argptr = value;
  689.    numval = totparms = intparms = floatparms = 0;
  690.    while (*argptr) {            /* count and pre-parse parms */
  691.       lastarg = 0;
  692.       if ((argptr2 = strchr(argptr,'/')) == NULL) {     /* find next '/' */
  693.      argptr2 = argptr + strlen(argptr);
  694.      *argptr2 = '/';
  695.      lastarg = 1;
  696.      }
  697.       if (totparms == 0) numval = NONNUMERIC;
  698.       i = -1;
  699.       if (sscanf(argptr,"%d%c",&j,&tmpc) > 0            /* got an integer */
  700.     && tmpc == '/') {
  701.      ++floatparms; ++intparms;
  702.      if (totparms < 16) floatval[totparms] = j;
  703.      if (totparms < 64) intval[totparms] = j;
  704.      if (totparms == 0) numval = j;
  705.      }
  706. #ifndef XFRACT
  707.       else if (sscanf(argptr,"%lg%c",&ftemp,&tmpc) > 0  /* got a float */
  708. #else
  709.       else if (sscanf(argptr,"%lf%c",&ftemp,&tmpc) > 0  /* got a float */
  710. #endif
  711.          && tmpc == '/') {
  712.      ++floatparms;
  713.      if (totparms < 16) floatval[totparms] = ftemp;
  714.      }
  715.       ++totparms;
  716.       argptr = argptr2;                 /* on to the next */
  717.       if (lastarg)
  718.      *argptr = 0;
  719.       else
  720.      ++argptr;
  721.       }
  722.  
  723.    if (mode != 2) {    /* these commands are allowed only at startup */
  724.  
  725.       if (strcmp(variable,"batch") == 0 ) {     /* batch=?      */
  726.      if (yesnoval < 0) goto badarg;
  727.      initbatch = yesnoval;
  728.      return 3;
  729.      }
  730.  
  731.       if (strcmp(variable,"adapter") == 0 ) {   /* adapter==?     */
  732.  
  733.          if (strncmp(value,"aheada",6) == 0) svga_type = 1;
  734.          if (strncmp(value,"ati"   ,3) == 0) svga_type = 2;
  735.          if (strncmp(value,"chi"   ,3) == 0) svga_type = 3;
  736.          if (strncmp(value,"eve"   ,3) == 0) svga_type = 4;
  737.          if (strncmp(value,"gen"   ,3) == 0) svga_type = 5;
  738.          if (strncmp(value,"ncr"   ,3) == 0) svga_type = 6;
  739.          if (strncmp(value,"oak"   ,3) == 0) svga_type = 7;
  740.          if (strncmp(value,"par"   ,3) == 0) svga_type = 8;
  741.          if (strncmp(value,"tri"   ,3) == 0) svga_type = 9;
  742.          if (strncmp(value,"tseng3",6) == 0) svga_type = 10;
  743.          if (strncmp(value,"tseng4",6) == 0) svga_type = 11;
  744.          if (strncmp(value,"vid"   ,3) == 0) svga_type = 12;
  745.          if (strncmp(value,"aheadb",6) == 0) svga_type = 13;
  746.          if (strncmp(value,"null"  ,4) == 0) svga_type = 14; /* for testing only */
  747.          if (svga_type != 0) return 3;
  748.  
  749.      video_type = 5;            /* assume video=vga */
  750.      if (strcmp(value,"egamono") == 0) {
  751.         video_type = 3;
  752.         mode7text = 1;
  753.         }
  754.      else if (strcmp(value,"hgc")) {             /* video = hgc */
  755.         video_type = 1;
  756.         mode7text = 1;
  757.         }
  758.      else if (strcmp(value,"ega"))               /* video = ega */
  759.         video_type = 3;
  760.      else if (strcmp(value,"cga"))               /* video = cga */
  761.         video_type = 2;
  762.      else if (strcmp(value,"mcga"))              /* video = mcga */
  763.         video_type = 4;
  764.      else if (strcmp(value,"vga"))               /* video = vga */
  765.         video_type = 5;
  766.      else
  767.         goto badarg;
  768.      return 3;
  769.      }
  770.  
  771.       if (strcmp(variable,"textsafe") == 0 ) {  /* textsafe==? */
  772.      if (first_init) {
  773.         if (charval == 'n') /* no */
  774.            textsafe = 2;
  775.         else if (charval == 'y') /* yes */
  776.            textsafe = 1;
  777.         else if (charval == 'b') /* bios */
  778.            textsafe = 3;
  779.         else if (charval == 's') /* save */
  780.            textsafe = 4;
  781.         else
  782.            goto badarg;
  783.         }
  784.      return 3;
  785.      }
  786.  
  787.       if (strcmp(variable, "vesadetect") == 0) {
  788.      if (yesnoval < 0) goto badarg;
  789.      vesa_detect = yesnoval;
  790.      return 3;
  791.      }
  792.  
  793.       if (strcmp(variable, "biospalette") == 0) {
  794.          if (yesnoval < 0) goto badarg;
  795.          bios_palette = yesnoval;
  796.          return 3;
  797.          }
  798.  
  799.       if (strcmp(variable, "exitnoask") == 0) {
  800.          if (yesnoval < 0) goto badarg;
  801.          escape_exit = yesnoval;
  802.          return 3;
  803.          }
  804.  
  805.       if (strcmp(variable,"fpu") == 0) {
  806.      if (strcmp(value,"iit") == 0) {
  807.         fpu = 387;
  808.         iit = 1;
  809.         return 0;
  810.         }
  811.      if (strcmp(value,"noiit") == 0) {
  812.         iit = -2;
  813.         return 0;
  814.         }
  815.      if (strcmp(value,"387") == 0) {
  816.         fpu = 387;
  817.         iit = -2;
  818.         return 0;
  819.         }
  820.      goto badarg;
  821.      }
  822.  
  823.       if (strcmp(variable,"makedoc") == 0) {
  824.      print_document(*value ? value : "fractint.doc", makedoc_msg_func, 0);
  825.      goodbye();
  826.      }
  827.  
  828.       } /* end of commands allowed only at startup */
  829.  
  830.    if (strcmp(variable,"reset") == 0) {
  831.       initvars_fractal();
  832.       return 9;
  833.       }
  834.  
  835.    if (strcmp(variable,"filename") == 0) {      /* filename=?     */
  836.       if (charval == '.') {
  837.      if (valuelen > 4) goto badarg;
  838.      gifmask[0] = '*';
  839.      gifmask[1] = 0;
  840.      strcat(gifmask,value);
  841.      return 0;
  842.      }
  843.       if (valuelen > 79) goto badarg;
  844.       if (mode == 2 && display3d == 0) /* can't do this in @ command */
  845.      goto badarg;
  846.       strcpy(readname,value);
  847.       showfile = 0;
  848.       return 3;
  849.       }
  850.  
  851.    if (strcmp(variable,"video") == 0) {         /* video=? */
  852.       if (active_system == 0) {
  853.      if ((k = check_vidmode_keyname(value)) == 0) goto badarg;
  854.      initmode = -1;
  855.      for (i = 0; i < MAXVIDEOTABLE; ++i) {
  856.         if (videotable[i].keynum == k) {
  857.            initmode = i;
  858.            break;
  859.            }
  860.         }
  861.      if (initmode == -1) goto badarg;
  862.      }
  863.       return 3;
  864.       }
  865.  
  866.    if (strcmp(variable,"map") == 0 ) {         /* map=, set default colors */
  867.       if (valuelen > 79 || SetColorPaletteName(value) != 0) goto badarg;
  868.       mapset = 1;
  869.       strcpy(MAP_name,value);
  870.       return 0;
  871.       }
  872.  
  873.    if (strcmp(variable,"colors") == 0) {       /* colors=, set current colors */
  874.       if (parse_colors(value) < 0) goto badarg;
  875.       return 0;
  876.       }
  877.  
  878.    if (strcmp(variable, "tplus") == 0) {       /* Use the TARGA+ if found? */
  879.       if (yesnoval < 0) goto badarg;
  880.       TPlusFlag = yesnoval;
  881.       return 0;
  882.       }
  883.  
  884.    if (strcmp(variable, "noninterlaced") == 0) {
  885.       if (yesnoval < 0) goto badarg;
  886.       NonInterlaced = yesnoval;
  887.       return 0;
  888.       }
  889.  
  890.    if (strcmp(variable, "maxcolorres") == 0) { /* Change default color resolution */
  891.       if (numval == 1 || numval == 4 || numval == 8 ||
  892.             numval == 16 || numval == 24) {
  893.      MaxColorRes = numval;
  894.      return 0;
  895.      }
  896.       goto badarg;
  897.       }
  898.  
  899.    if (strcmp(variable, "pixelzoom") == 0) {
  900.       if (numval < 5)
  901.      PixelZoom = numval;
  902.       return 0;
  903.       }
  904.  
  905.    /* keep this for backward compatibility */
  906.    if (strcmp(variable,"warn") == 0 ) {         /* warn=? */
  907.       if (yesnoval < 0) goto badarg;
  908.       overwrite = yesnoval ^ 1;
  909.       return 0;
  910.       }
  911.    if (strcmp(variable,"overwrite") == 0 ) {    /* overwrite=? */
  912.       if (yesnoval < 0) goto badarg;
  913.       overwrite = yesnoval;
  914.       return 0;
  915.       }
  916.  
  917.    if (strcmp(variable,"gif87a") == 0 ) {       /* gif87a=? */
  918.       if (yesnoval < 0) goto badarg;
  919.       gif87a_flag = yesnoval;
  920.       return 0;
  921.       }
  922.  
  923.    if (strcmp(variable,"savetime") == 0) {      /* savetime=? */
  924.       initsavetime = numval;
  925.       return 0;
  926.       }
  927.  
  928.    if (strcmp(variable,"autokey") == 0) {       /* autokey=? */
  929.       if (strcmp(value,"record")==0)
  930.      slides=2;
  931.       else if (strcmp(value,"play")==0)
  932.      slides=1;
  933.       else
  934.      goto badarg;
  935.       return 0;
  936.       }
  937.  
  938.    if(strcmp(variable, "solidcore") == 0) {
  939.       SolidCore = yesnoval;
  940.       return(0);
  941.       }
  942.  
  943.    if(strcmp(variable, "antialias") == 0) {
  944.       if(numval < 0 || numval > 8)
  945.      goto badarg;
  946.       AntiAliasing = numval;
  947.       return(0);
  948.       }
  949.  
  950.    if(strcmp(variable, "transparent3d") == 0) {
  951.       Transparent3D = yesnoval;
  952.       return(0);
  953.       }
  954.  
  955.    if(strcmp(variable, "corecolor") == 0) {
  956.       if(floatparms != totparms || totparms != 3)
  957.      goto badarg;
  958.       CoreRed    = (int)floatval[0];
  959.       CoreGreen = (int)floatval[1];
  960.       CoreBlue    = (int)floatval[2];
  961.       return(0);
  962.       }
  963.  
  964.    if(strcmp(variable, "mdcorners") == 0) {
  965.       if(floatparms != totparms || totparms < 2 || totparms > 4)
  966.      goto badarg;
  967.       zzmin = floatval[0];
  968.       zzmax = floatval[1];
  969.       if(totparms >= 3)
  970.      ttmin = floatval[2];
  971.       if(totparms == 4)
  972.      ttmax = floatval[3];
  973.       return(0);
  974.       }
  975.  
  976.    if(strcmp(variable, "numframes") == 0) {
  977.       NumFrames = numval;
  978.       return(0);
  979.       }
  980.  
  981.    if (strcmp(variable,"autokeyname") == 0) {   /* autokeyname=? */
  982.       strcpy(autoname,value);
  983.       return 0;
  984.       }
  985.  
  986.    if (strcmp(variable,"type") == 0 ) {         /* type=? */
  987.       if (value[valuelen-1] == '*')
  988.      value[--valuelen] = 0;
  989.       /* kludge because type ifs3d has an asterisk in front */
  990.       if(strcmp(value,"ifs3d")==0)
  991.          value[3]=0;
  992.       for (k = 0; fractalspecific[k].name != NULL; k++)
  993.      if (strcmp(value,fractalspecific[k].name) == 0)
  994.         break;
  995.       if (fractalspecific[k].name == NULL) goto badarg;
  996.       curfractalspecific = &fractalspecific[fractype = k];
  997.       if (initcorners == 0) {
  998.      xx3rd = xxmin = curfractalspecific->xmin;
  999.      xxmax           = curfractalspecific->xmax;
  1000.      yy3rd = yymin = curfractalspecific->ymin;
  1001.      yymax           = curfractalspecific->ymax;
  1002.      }
  1003.       if (initparams == 0)
  1004.      for (k = 0; k < 4; ++k) {
  1005.         param[k] = curfractalspecific->paramvalue[k];
  1006.         roundfloatd(¶m[k]);
  1007.         }
  1008.       return 1;
  1009.       }
  1010.  
  1011.    if (strcmp(variable,"inside") == 0 ) {       /* inside=? */
  1012.       if(strcmp(value,s_zmag)==0)
  1013.      inside = -59;
  1014.       else if(strcmp(value,s_bof60)==0)
  1015.      inside = -60;
  1016.       else if(strcmp(value,s_bof61)==0)
  1017.      inside = -61;
  1018.       else if(strncmp(value,s_epscross,3)==0)
  1019.      inside = -100;
  1020.       else if(strncmp(value,s_startrail,4)==0)
  1021.      inside = -101;
  1022.       else if(strcmp(value,s_maxiter)==0)
  1023.      inside = -1;
  1024.       else if(numval == NONNUMERIC)
  1025.      goto badarg;
  1026.       else
  1027.      inside = numval;
  1028.       return 1;
  1029.       }
  1030.    if (strcmp(variable,"fillcolor") == 0 ) {       /* fillcolor */
  1031.       if(strcmp(value,s_normal)==0)
  1032.      fillcolor = -1;
  1033.       else if(numval == NONNUMERIC)
  1034.      goto badarg;
  1035.       else
  1036.      fillcolor = numval;
  1037.       return 1;
  1038.       }
  1039.  
  1040.    if (strcmp(variable,"finattract") == 0 ) {   /* finattract=? */
  1041.       if (yesnoval < 0) goto badarg;
  1042.       finattract = yesnoval;
  1043.       return 1;
  1044.       }
  1045.  
  1046.    if (strcmp(variable,"function") == 0) {      /* function=?,? */
  1047.       k = 0;
  1048.       while (*value && k < 4) {
  1049.      if(set_trig_array(k++,value)) goto badarg;
  1050.      if ((value = strchr(value,'/')) == NULL) break;
  1051.      ++value;
  1052.      }
  1053.       return 1;
  1054.       }
  1055.  
  1056.    if (strcmp(variable,"outside") == 0 ) {      /* outside=? */
  1057.       if(strcmp(value,s_iter)==0)
  1058.      outside = -1;
  1059.       if(strcmp(value,s_real)==0)
  1060.      outside = -2;
  1061.       else if(strcmp(value,s_imag)==0)
  1062.      outside = -3;
  1063.       else if(strcmp(value,s_mult)==0)
  1064.      outside = -4;
  1065.       else if(strcmp(value,s_sum)==0)
  1066.      outside = -5;
  1067.  
  1068.       else if(numval == NONNUMERIC)
  1069.      goto badarg;
  1070.       else if(numval < -5 || numval > 255) goto badarg;
  1071.       else outside = numval;
  1072.       return 1;
  1073.       }
  1074.  
  1075.    if (strcmp(variable,s_maxiter) == 0) {       /* maxiter=? */
  1076.       if (numval < 2) goto badarg;
  1077.       maxit = numval;
  1078.       return 1;
  1079.       }
  1080.  
  1081.    if (strcmp(variable,"iterincr") == 0)        /* iterincr=? */
  1082.       return 0;
  1083.  
  1084.    if (strcmp(variable,"passes") == 0) {        /* passes=? */
  1085.       if ( charval != '1' && charval != '2'
  1086.     && charval != 'g' && charval != 'b'
  1087.     && charval != 't')
  1088.      goto badarg;
  1089.       usr_stdcalcmode = charval;
  1090.       return 1;
  1091.       }
  1092.  
  1093.    if (strcmp(variable,"cyclelimit") == 0 ) {   /* cyclelimit=? */
  1094.       if (numval <= 1 || numval > 256) goto badarg;
  1095.       initcyclelimit = numval;
  1096.       return 0;
  1097.       }
  1098.  
  1099.    if (strcmp(variable,"cyclerange") == 0) {
  1100.       if (totparms < 2) intval[1] = 255;
  1101.       if (totparms < 1) intval[0] = 1;
  1102.       if (totparms != intparms
  1103.     || intval[0] < 0 || intval[1] > 255 || intval[0] > intval[1])
  1104.      goto badarg;
  1105.       rotate_lo = intval[0];
  1106.       rotate_hi = intval[1];
  1107.       return 0;
  1108.       }
  1109.  
  1110.    if (strcmp(variable,"ranges") == 0) {
  1111.       int i,j,entries,prev;
  1112.       int tmpranges[128];
  1113.       if (totparms != intparms) goto badarg;
  1114.       entries = prev = i = 0;
  1115.       while (i < totparms) {
  1116.      if ((j = intval[i++]) < 0) { /* striping */
  1117.         if ((j = 0-j) < 1 || j >= 16384 || i >= totparms) goto badarg;
  1118.         tmpranges[entries++] = -1; /* {-1,width,limit} for striping */
  1119.         tmpranges[entries++] = j;
  1120.         j = intval[i++];
  1121.         }
  1122.      if (j < prev) goto badarg;
  1123.      tmpranges[entries++] = prev = j;
  1124.      }
  1125.       if (prev == 0) goto badarg;
  1126.       if ((ranges = (int far *)farmemalloc(2L*entries)) == NULL) {
  1127.      static char far msg[] = {"Insufficient memory for ranges="};
  1128.      stopmsg(0,msg);
  1129.      return(-1);
  1130.      }
  1131.       rangeslen = entries;
  1132.       for (i = 0; i < rangeslen; ++i)
  1133.      ranges[i] = tmpranges[i];
  1134.       return 1;
  1135.       }
  1136.  
  1137.    if (strcmp(variable,"savename") == 0) {      /* savename=? */
  1138.       if (valuelen > 79) goto badarg;
  1139.       if (first_init || mode == 2)
  1140.      strcpy(savename,value);
  1141.       return 0;
  1142.       }
  1143.  
  1144.    if (strcmp(variable,"exitmode") == 0) {      /* exitmode=? */
  1145.       sscanf(value,"%x",&numval);
  1146.       exitmode = numval;
  1147.       return 0;
  1148.       }
  1149.  
  1150.    if (strcmp(variable,"textcolors") == 0) {
  1151.       parse_textcolors(value);
  1152.       return 0;
  1153.       }
  1154.  
  1155.    if (strcmp(variable,"potential") == 0) {     /* potential=? */
  1156.       k = 0;
  1157.       while (k < 3 && *value) {
  1158.      potparam[k++] = atoi(value);
  1159.      if ((value = strchr(value,'/')) == NULL) k = 99;
  1160.      ++value;
  1161.      }
  1162.       pot16bit = 0;
  1163.       if (k < 99) {
  1164.      if (strcmp(value,"16bit")) goto badarg;
  1165.      pot16bit = 1;
  1166.      }
  1167.       return 1;
  1168.       }
  1169.  
  1170.    if (strcmp(variable,"params") == 0) {        /* params=?,? */
  1171.       if (totparms != floatparms || totparms > 4)
  1172.      goto badarg;
  1173.       for (k = 0; k < 4; ++k)
  1174.      param[k] = (k < totparms) ? floatval[k] : 0.0;
  1175.       initparams = 1;
  1176.       return 1;
  1177.       }
  1178.  
  1179.    if (strcmp(variable,"initorbit") == 0) {     /* initorbit=?,? */
  1180.       if(strcmp(value,"pixel")==0)
  1181.      useinitorbit = 2;
  1182.       else {
  1183.      if (totparms != 2 || floatparms != 2) goto badarg;
  1184.      initorbit[0] = floatval[0];
  1185.      initorbit[1] = floatval[1];
  1186.      useinitorbit = 1;
  1187.      }
  1188.       return 1;
  1189.       }
  1190.  
  1191.    if (strcmp(variable,"corners") == 0) {       /* corners=?,?,?,? */
  1192.       if (floatparms != totparms || (totparms != 4 && totparms != 6))
  1193.      goto badarg;
  1194.       usemag = 0;
  1195.       initcorners = 1;
  1196.       xx3rd = xxmin = floatval[0];
  1197.       xxmax =          floatval[1];
  1198.       yy3rd = yymin = floatval[2];
  1199.       yymax =          floatval[3];
  1200.       if (totparms == 6) {
  1201.      xx3rd =      floatval[4];
  1202.      yy3rd =      floatval[5];
  1203.      }
  1204.       return 1;
  1205.       }
  1206.  
  1207.    if (strcmp(variable,"center-mag") == 0) {    /* center-mag=?,?,? */
  1208.       double Xctr, Yctr,Magnification,Ratio,Height, Width,Radius;
  1209.       if (totparms != floatparms
  1210.     || (totparms != 0 && totparms != 3)
  1211.     || (totparms == 3 && floatval[2] <= 0.0))
  1212.      goto badarg;
  1213.       usemag = 1;
  1214.       if (totparms == 0) return 0;
  1215.       initcorners = 1;
  1216.       Xctr = floatval[0];
  1217.       Yctr = floatval[1];
  1218.       Magnification = floatval[2];
  1219.       Radius = 1.0 / Magnification;
  1220.       Ratio = .75;    /* inverse aspect ratio of screen  */
  1221.       /* calculate bounds */
  1222.       Height = 2.0 * Radius;
  1223.       Width = Height / Ratio;
  1224.       yymax = Yctr + Radius;
  1225.       yy3rd = yymin = Yctr - Radius;
  1226.       xxmax = Xctr + Width / 2.0;
  1227.       xx3rd = xxmin = Xctr - Width / 2.0;
  1228.       return 1;
  1229.       }
  1230.  
  1231.    if (strcmp(variable,"invert") == 0) {        /* invert=?,?,? */
  1232.       if (totparms != floatparms || (totparms != 1 && totparms != 3))
  1233.      goto badarg;
  1234.       invert = ((inversion[0] = floatval[0]) != 0.0) ? totparms : 0;
  1235.       if (totparms == 3) {
  1236.      inversion[1] = floatval[1];
  1237.      inversion[2] = floatval[2];
  1238.      }
  1239.       return 1;
  1240.       }
  1241.  
  1242.    if (strcmp(variable,"askvideo") == 0 ) {     /* askvideo=?   */
  1243.       if (yesnoval < 0) goto badarg;
  1244.       askvideo = yesnoval;
  1245.       return 0;
  1246.       }
  1247.  
  1248.    if (strcmp(variable,"ramvideo") == 0 )       /* ramvideo=?   */
  1249.       return 0; /* just ignore and return, for old time's sake */
  1250.  
  1251.    if (strcmp(variable,"float") == 0 ) {        /* float=? */
  1252.       if (yesnoval < 0) goto badarg;
  1253.       usr_floatflag = yesnoval;
  1254.       return 3;
  1255.       }
  1256.  
  1257.    if (strcmp(variable,"biomorph") == 0 ) {     /* biomorph=? */
  1258.       usr_biomorph = numval;
  1259.       return 1;
  1260.       }
  1261.  
  1262.    if (strcmp(variable,"orbitsave") == 0 ) {     /* orbitsave=? */
  1263.       if (yesnoval < 0) goto badarg;
  1264.       orbitsave = yesnoval;
  1265.       return 1;
  1266.       }
  1267.  
  1268.    if (strcmp(variable,"bailout") == 0 ) {      /* bailout=? */
  1269.       if (numval < 4 || numval > 32000) goto badarg;
  1270.       bailout = numval;
  1271.       return 1;
  1272.       }
  1273.  
  1274.    if (strcmp(variable,"symmetry") == 0 ) {     /* symmetry=? */
  1275.       if     (strcmp(value,"xaxis" )==0) forcesymmetry = XAXIS;
  1276.       else if(strcmp(value,"yaxis" )==0) forcesymmetry = YAXIS;
  1277.       else if(strcmp(value,"xyaxis")==0) forcesymmetry = XYAXIS;
  1278.       else if(strcmp(value,"origin")==0) forcesymmetry = ORIGIN;
  1279.       else if(strcmp(value,"pi"    )==0) forcesymmetry = PI_SYM;
  1280.       else if(strcmp(value,"none"  )==0) forcesymmetry = NOSYM;
  1281.       else goto badarg;
  1282.       return 1;
  1283.       }
  1284.  
  1285.    if (strcmp(variable,"printer") == 0 ) {      /* printer=? */
  1286.       if (parse_printer(value) < 0) goto badarg;
  1287.       return 0;
  1288.       }
  1289.  
  1290.    if (strcmp(variable,"printfile") == 0) {     /* print-to-file? SWT */
  1291.       if (valuelen > 79) goto badarg;
  1292.       Print_To_File = 1;
  1293.       strcpy(PrintName,value);
  1294.       return 0;
  1295.       }
  1296.  
  1297.    if(strcmp(variable, "colorps") == 0) {
  1298.       ColorPS = yesnoval;
  1299.       return(0);
  1300.       }
  1301.  
  1302.    if (strcmp(variable,"epsf") == 0) {          /* EPS type? SWT */
  1303.       Print_To_File = 1;
  1304.       EPSFileType = numval;
  1305.       Printer_Type = 5;
  1306.       if (strcmp(PrintName,"fract001.prn")==0)
  1307.      strcpy(PrintName,"fract001.eps");
  1308.       return 0;
  1309.       }
  1310.  
  1311.    if (strcmp(variable,"title") == 0) {         /* Printer title block? SWT */
  1312.       if (yesnoval < 0) goto badarg;
  1313.       Printer_Titleblock = yesnoval;
  1314.       return 0;
  1315.       }
  1316.  
  1317.    if (strcmp(variable,"translate") == 0) {     /* Translate color? SWT */
  1318.       Printer_ColorXlat=0;
  1319.       if (charval == 'y')
  1320.      Printer_ColorXlat=1;
  1321.       else if (numval > 1 || numval < -1)
  1322.      Printer_ColorXlat=numval;
  1323.       return 0;
  1324.       }
  1325.  
  1326.    if (strcmp(variable,"plotstyle") == 0) {     /* plot style? SWT */
  1327.       Printer_SStyle = numval;
  1328.       return 0;
  1329.       }
  1330.  
  1331.    if (strcmp(variable,"halftone") == 0) {      /* New halftoning? SWT */
  1332.       if (totparms != intparms) goto badarg;
  1333.       Printer_SetScreen=1;
  1334.       if ((totparms >  0) && ( intval[ 0] >= 0))
  1335.                       Printer_SFrequency = intval[ 0];
  1336.       if ((totparms >  1) && ( intval[ 1] >= 0))
  1337.                       Printer_SAngle     = intval[ 1];
  1338.       if ((totparms >  2) && ( intval[ 2] >= 0))
  1339.                       Printer_SStyle     = intval[ 2];
  1340.       if ((totparms >  3) && ( intval[ 3] >= 0))
  1341.                       Printer_RFrequency = intval[ 3];
  1342.       if ((totparms >  4) && ( intval[ 4] >= 0))
  1343.                       Printer_RAngle     = intval[ 4];
  1344.       if ((totparms >  5) && ( intval[ 5] >= 0))
  1345.                       Printer_RStyle     = intval[ 5];
  1346.       if ((totparms >  6) && ( intval[ 6] >= 0))
  1347.                       Printer_GFrequency = intval[ 6];
  1348.       if ((totparms >  7) && ( intval[ 7] >= 0))
  1349.                       Printer_GAngle     = intval[ 7];
  1350.       if ((totparms >  8) && ( intval[ 8] >= 0))
  1351.                       Printer_GStyle     = intval[ 8];
  1352.       if ((totparms >  9) && ( intval[ 9] >= 0))
  1353.                       Printer_BFrequency = intval[ 9];
  1354.       if ((totparms > 10) && ( intval[10] >= 0))
  1355.                       Printer_BAngle     = intval[10];
  1356.       if ((totparms > 11) && ( intval[11] >= 0))
  1357.                       Printer_BStyle     = intval[11];
  1358.       return 0;
  1359.       }
  1360.  
  1361.    if (strcmp(variable,"linefeed") == 0) {      /* Use LF for printer */
  1362.       if      (strcmp(value,"cr")   == 0) Printer_CRLF = 1;
  1363.       else if (strcmp(value,"lf")   == 0) Printer_CRLF = 2;
  1364.       else if (strcmp(value,"crlf") == 0) Printer_CRLF = 0;
  1365.       else goto badarg;
  1366.       return 0;
  1367.       }
  1368.  
  1369.    if (strcmp(variable,"comport") == 0 ) {      /* Set the COM parameters */
  1370.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1371.       switch (atoi(++value)) {
  1372.      case 110:  l = 0;   break;
  1373.      case 150:  l = 32;  break;
  1374.      case 300:  l = 64;  break;
  1375.      case 600:  l = 96;  break;
  1376.      case 1200: l = 128; break;
  1377.      case 2400: l = 160; break;
  1378.      case 4800: l = 192; break;
  1379.      case 9600:
  1380.      default:   l = 224; break;
  1381.      }
  1382.       if ((value=strchr(value,'/')) == NULL) goto badarg;
  1383.       for (k=0; k < strlen(value); k++) {
  1384.      switch (value[k]) {
  1385.         case '7':  l |= 2;  break;
  1386.         case '8':  l |= 3;  break;
  1387.         case 'o':  l |= 8;  break;
  1388.         case 'e':  l |= 24; break;
  1389.         case '2':  l |= 4;  break;
  1390.         }
  1391.      }
  1392. #ifndef XFRACT
  1393. #ifndef WINFRACT
  1394.       _bios_serialcom(0,numval-1,l);
  1395. #endif
  1396. #endif
  1397.       return 0;
  1398.       }
  1399.  
  1400.    if (strcmp(variable,"sound") == 0 ) {        /* sound=? */
  1401.       soundflag = 0;
  1402.       if (strncmp(value,"ye",2) == 0)
  1403.      soundflag = -1;
  1404.       if (charval == 'x')
  1405.      soundflag = 1;
  1406.       if (charval == 'y')
  1407.      soundflag = 2;
  1408.       if (charval == 'z')
  1409.      soundflag = 3;
  1410.       return 0;
  1411.       }
  1412.  
  1413.    if (strcmp(variable,"hertz") == 0) {         /* Hertz=? */
  1414.       if (numval < 200 || numval > 10000) goto badarg;
  1415.       basehertz = numval;
  1416.       return 0;
  1417.       }
  1418.  
  1419.    if (strcmp(variable,"periodicity") == 0 ) {  /* periodicity=? */
  1420.       usr_periodicitycheck=1;
  1421.       if (charval == 'n')
  1422.      usr_periodicitycheck=0;
  1423.       else if (charval == 'y')
  1424.      usr_periodicitycheck=1;
  1425.       else if (charval == 's')   /* 's' for 'show' */
  1426.      usr_periodicitycheck=-1;
  1427.       else if(numval == NONNUMERIC)
  1428.      goto badarg;
  1429.       else if(numval != 0)
  1430.      usr_periodicitycheck=numval;
  1431.       return 1;
  1432.       }
  1433.  
  1434.    if (strcmp(variable,"logmap") == 0 ) {       /* logmap=? */
  1435.       if (charval == 'y')
  1436.      LogFlag = 1;                /* palette is logarithmic */
  1437.       else if (charval == 'n')
  1438.      LogFlag = 0;
  1439.       else if (charval == 'o')
  1440.      LogFlag = -1;                /* old log palette */
  1441.       else
  1442.      LogFlag = numval;
  1443.       return 1;
  1444.       }
  1445.  
  1446.    if (strcmp(variable,"debugflag") == 0
  1447.      || strcmp(variable,"debug") == 0) {        /* internal use only */
  1448.       debugflag = numval;
  1449.       timerflag = debugflag & 1;        /* separate timer flag */
  1450.       debugflag -= timerflag;
  1451.       return 0;
  1452.       }
  1453.  
  1454.    if (strcmp(variable, "rseed") == 0) {
  1455.       rseed = numval;
  1456.       rflag = 1;
  1457.       return 1;
  1458.       }
  1459.  
  1460.    if (strcmp(variable, "orbitdelay") == 0) {
  1461.       orbit_delay = numval;
  1462.       return 0;
  1463.       }
  1464.  
  1465.    if (strcmp(variable, "showdot") == 0) {
  1466.       showdot=numval;
  1467.       if(showdot<0)
  1468.          showdot=0;
  1469.       return 0;
  1470.       }
  1471.  
  1472.    if (strcmp(variable, "decomp") == 0) {
  1473.       if (totparms != intparms || totparms < 1) goto badarg;
  1474.       decomp[0] = intval[0];
  1475.       decomp[1] = 0;
  1476.       if (totparms > 1) /* backward compatibility */
  1477.      bailout = decomp[1] = intval[1];
  1478.       return 1;
  1479.       }
  1480.  
  1481.    if (strcmp(variable, "distest") == 0) {
  1482.       if (totparms != intparms || totparms < 1) goto badarg;
  1483.       usr_distest = intval[0];
  1484.       distestwidth = 71;
  1485.       if (totparms > 1)
  1486.      distestwidth = intval[1];
  1487.       return 1;
  1488.       }
  1489.  
  1490.    if (strcmp(variable,"formulafile") == 0) {   /* formulafile=? */
  1491.       if (valuelen > 79) goto badarg;
  1492.       strcpy(FormFileName,value);
  1493.       return 1;
  1494.       }
  1495.  
  1496.    if (strcmp(variable,"formulaname") == 0) {   /* formulaname=? */
  1497.       if (valuelen > ITEMNAMELEN) goto badarg;
  1498.       strcpy(FormName,value);
  1499.       return 1;
  1500.       }
  1501.  
  1502.    if (strcmp(variable,"lfile") == 0) {
  1503.       if (valuelen > 79) goto badarg;
  1504.       strcpy(LFileName,value);
  1505.       return 1;
  1506.       }
  1507.  
  1508.    if (strcmp(variable,"lname") == 0) {
  1509.       if (valuelen > ITEMNAMELEN) goto badarg;
  1510.       strcpy(LName,value);
  1511.       return 1;
  1512.       }
  1513.  
  1514.    if (strcmp(variable,"ifsfile") == 0) {
  1515.       if (valuelen > 79) goto badarg;
  1516.       strcpy(IFSFileName,value);
  1517.       reset_ifs_defn();
  1518.       return 1;
  1519.       }
  1520.  
  1521.    if (strcmp(variable,"ifs") == 0
  1522.      || strcmp(variable,"ifs3d") == 0) {        /* ifs3d for old time's sake */
  1523.       if (valuelen > ITEMNAMELEN) goto badarg;
  1524.       strcpy(IFSName,value);
  1525.       reset_ifs_defn();
  1526.       return 1;
  1527.       }
  1528.  
  1529.    if (strcmp(variable,"parmfile") == 0) {
  1530.       if (valuelen > 79) goto badarg;
  1531.       strcpy(CommandFile,value);
  1532.       return 0;
  1533.       }
  1534.  
  1535.    if (strcmp(variable,"stereo") == 0) {        /* stereo=? */
  1536.       if ((numval<0) || (numval>3)) goto badarg;
  1537.       glassestype = numval;
  1538.       return 3;
  1539.       }
  1540.  
  1541.    if (strcmp(variable,"rotation") == 0) {      /* rotation=?/?/? */
  1542.       if (totparms != 3 || intparms != 3) goto badarg;
  1543.       XROT = intval[0];
  1544.       YROT = intval[1];
  1545.       ZROT = intval[2];
  1546.       return 3;
  1547.       }
  1548.  
  1549.    if (strcmp(variable,"perspective") == 0) {   /* perspective=? */
  1550.       if (numval == NONNUMERIC) goto badarg;
  1551.       ZVIEWER = numval;
  1552.       return 3;
  1553.       }
  1554.  
  1555.    if (strcmp(variable,"xyshift") == 0) {       /* xyshift=?/?  */
  1556.       if (totparms != 2 || intparms != 2) goto badarg;
  1557.       XSHIFT = intval[0];
  1558.       YSHIFT = intval[1];
  1559.       return 3;
  1560.       }
  1561.  
  1562.    if (strcmp(variable,"interocular") == 0) {   /* interocular=? */
  1563.       eyeseparation = numval;
  1564.       return 3;
  1565.       }
  1566.  
  1567.    if (strcmp(variable,"converge") == 0) {      /* converg=? */
  1568.       xadjust = numval;
  1569.       return 3;
  1570.       }
  1571.  
  1572.    if (strcmp(variable,"crop") == 0) {          /* crop=? */
  1573.       if (totparms != 4 || intparms != 4
  1574.     || intval[0] < 0 || intval[0] > 100
  1575.     || intval[1] < 0 || intval[1] > 100
  1576.     || intval[2] < 0 || intval[2] > 100
  1577.     || intval[3] < 0 || intval[3] > 100)
  1578.       goto badarg;
  1579.       red_crop_left   = intval[0];
  1580.       red_crop_right  = intval[1];
  1581.       blue_crop_left  = intval[2];
  1582.       blue_crop_right = intval[3];
  1583.       return 3;
  1584.       }
  1585.  
  1586.    if (strcmp(variable,"bright") == 0) {        /* bright=? */
  1587.       if (totparms != 2 || intparms != 2) goto badarg;
  1588.       red_bright  = intval[0];
  1589.       blue_bright = intval[1];
  1590.       return 3;
  1591.       }
  1592.  
  1593.    if (strcmp(variable,"xyadjust") == 0) {      /* trans=? */
  1594.       if (totparms != 2 || intparms != 2) goto badarg;
  1595.       xtrans = intval[0];
  1596.       ytrans = intval[1];
  1597.       return 3;
  1598.       }
  1599.  
  1600.    if (strcmp(variable,"3d") == 0) {            /* 3d=?/?/..    */
  1601.       if (yesnoval < 0) goto badarg;
  1602.       display3d = yesnoval;
  1603.       initvars_3d();
  1604.       return (display3d) ? 6 : 2;
  1605.       }
  1606.  
  1607.    if (strcmp(variable,"sphere") == 0 ) {       /* sphere=? */
  1608.       if (yesnoval < 0) goto badarg;
  1609.       SPHERE = yesnoval;
  1610.       return 2;
  1611.       }
  1612.  
  1613.    if (strcmp(variable,"scalexyz") == 0) {      /* scalexyz=?/?/? */
  1614.       if (totparms < 2 || intparms != totparms) goto badarg;
  1615.       XSCALE = intval[0];
  1616.       YSCALE = intval[1];
  1617.       if (totparms > 2) ROUGH = intval[2];
  1618.       return 2;
  1619.       }
  1620.  
  1621.    /* "rough" is really scale z, but we add it here for convenience */
  1622.    if (strcmp(variable,"roughness") == 0) {     /* roughness=?  */
  1623.       ROUGH = numval;
  1624.       return 2;
  1625.       }
  1626.  
  1627.    if (strcmp(variable,"waterline") == 0) {     /* waterline=?  */
  1628.       if (numval<0) goto badarg;
  1629.       WATERLINE = numval;
  1630.       return 2;
  1631.       }
  1632.  
  1633.    if (strcmp(variable,"filltype") == 0) {      /* filltype=?   */
  1634.       if (numval < -1 || numval > 6) goto badarg;
  1635.       FILLTYPE = numval;
  1636.       return 2;
  1637.       }
  1638.  
  1639.    if (strcmp(variable,"lightsource") == 0) {   /* lightsource=?/?/? */
  1640.       if (totparms != 3 || intparms != 3) goto badarg;
  1641.       XLIGHT = intval[0];
  1642.       YLIGHT = intval[1];
  1643.       ZLIGHT = intval[2];
  1644.       return 2;
  1645.       }
  1646.  
  1647.    if (strcmp(variable,"smoothing") == 0) {     /* smoothing=?  */
  1648.       if (numval<0) goto badarg;
  1649.       LIGHTAVG = numval;
  1650.       return 2;
  1651.       }
  1652.  
  1653.    if (strcmp(variable,"latitude") == 0) {      /* latitude=?/? */
  1654.       if (totparms != 2 || intparms != 2) goto badarg;
  1655.       THETA1 = intval[0];
  1656.       THETA2 = intval[1];
  1657.       return 2;
  1658.       }
  1659.  
  1660.    if (strcmp(variable,"longitude") == 0) {     /* longitude=?/? */
  1661.       if (totparms != 2 || intparms != 2) goto badarg;
  1662.       PHI1 = intval[0];
  1663.       PHI2 = intval[1];
  1664.       return 2;
  1665.       }
  1666.  
  1667.    if (strcmp(variable,"radius") == 0) {        /* radius=? */
  1668.       if (numval < 0) goto badarg;
  1669.       RADIUS = numval;
  1670.       return 2;
  1671.       }
  1672.  
  1673.    if (strcmp(variable,"transparent") == 0) {   /* transparent? */
  1674.       if (totparms != intparms || totparms < 1) goto badarg;
  1675.       transparent[1] = transparent[0] = intval[0];
  1676.       if (totparms > 1) transparent[1] = intval[1];
  1677.       return 2;
  1678.       }
  1679.  
  1680.    if (strcmp(variable,"preview") == 0) {       /* preview? */
  1681.       if (yesnoval < 0) goto badarg;
  1682.       preview = yesnoval;
  1683.       return 2;
  1684.       }
  1685.  
  1686.    if (strcmp(variable,"showbox") == 0) {       /* showbox? */
  1687.       if (yesnoval < 0) goto badarg;
  1688.       showbox = yesnoval;
  1689.       return 2;
  1690.       }
  1691.  
  1692.    if (strcmp(variable,"coarse") == 0) {        /* coarse=? */
  1693.       if (numval < 3 || numval > 2000) goto badarg;
  1694.       previewfactor = numval;
  1695.       return 2;
  1696.       }
  1697.  
  1698.    if (strcmp(variable,"randomize") == 0) {     /* RANDOMIZE=? */
  1699.       if (numval<0 || numval>7) goto badarg;
  1700.       RANDOMIZE = numval;
  1701.       return 2;
  1702.       }
  1703.  
  1704.    if (strcmp(variable,"ambient") == 0) {       /* ambient=? */
  1705.       if (numval<0||numval>100) goto badarg;
  1706.       Ambient = numval;
  1707.       return 2;
  1708.       }
  1709.  
  1710.    if (strcmp(variable,"haze") == 0) {          /* haze=? */
  1711.       if (numval<0||numval>100) goto badarg;
  1712.       haze = numval;
  1713.       return 2;
  1714.       }
  1715.  
  1716.    if (strcmp(variable,"fullcolor") == 0) {     /* fullcolor=? */
  1717.       if (yesnoval < 0) goto badarg;
  1718.       Targa_Out = yesnoval;
  1719.       return 2;
  1720.       }
  1721.    if (strcmp(variable,"targa_out") == 0) {     /* Targa Out? */
  1722.       if (yesnoval < 0) goto badarg;
  1723.       Targa_Out = yesnoval;
  1724.       return 2;
  1725.       }
  1726.  
  1727.    if (strcmp(variable,"targa_overlay") == 0) {         /* Targa Overlay? */
  1728.       if (yesnoval < 0) goto badarg;
  1729.       Targa_Overlay = yesnoval;
  1730.       return 2;
  1731.       }
  1732.  
  1733.    if (strcmp(variable,"background") == 0) {     /* background=?/? */
  1734.       if (totparms != 3 || intparms != 3) goto badarg;
  1735.                 for (i=0;i<3;i++)
  1736.                         if (intval[i] & 0xff)
  1737.                                 goto badarg;
  1738.       back_color[0] = intval[0];
  1739.       back_color[1] = intval[1];
  1740.       back_color[2] = intval[2];
  1741.       return 2;
  1742.       }
  1743.  
  1744.    if (strcmp(variable,"lightname") == 0) {     /* lightname=?   */
  1745.       if (valuelen > 79) goto badarg;
  1746.       if (first_init || mode == 2)
  1747.      strcpy(light_name,value);
  1748.       return 0;
  1749.       }
  1750.  
  1751.    if (strcmp(variable,"ray") == 0) {           /* RAY=? */
  1752.       if (numval < 0 || numval > 6) goto badarg;
  1753.       RAY = numval;
  1754.       return 2;
  1755.       }
  1756.  
  1757.    if (strcmp(variable,"brief") == 0) {         /* BRIEF? */
  1758.       if (yesnoval < 0) goto badarg;
  1759.       BRIEF = yesnoval;
  1760.       return 2;
  1761.       }
  1762.  
  1763.  
  1764. badarg:
  1765.    argerror(curarg);
  1766.    return(-1);
  1767.  
  1768. }
  1769.  
  1770. /* Some routines broken out of above so compiler doesn't run out of heap: */
  1771.  
  1772. static void parse_textcolors(char *value)
  1773. {
  1774.    int i,j,k,hexval;
  1775.    if (strcmp(value,"mono") == 0) {
  1776.       for (k = 0; k < sizeof(txtcolor); ++k)
  1777.      txtcolor[k] = BLACK*16+WHITE;
  1778.    /* C_HELP_CURLINK = C_PROMPT_INPUT = C_CHOICE_CURRENT = C_GENERAL_INPUT
  1779.              = C_AUTHDIV1 = C_AUTHDIV2 = WHITE*16+BLACK; */
  1780.       txtcolor[6] = txtcolor[12] = txtcolor[13] = txtcolor[14] = txtcolor[20]
  1781.           = txtcolor[27] = txtcolor[28] = WHITE*16+BLACK;
  1782.       /* C_TITLE = C_HELP_HDG = C_HELP_LINK = C_PROMPT_HI = C_CHOICE_SP_KEYIN
  1783.          = C_GENERAL_HI = C_DVID_HI = C_STOP_ERR
  1784.          = C_STOP_INFO = BLACK*16+L_WHITE; */
  1785.       txtcolor[0] = txtcolor[2] = txtcolor[5] = txtcolor[11] = txtcolor[16]
  1786.           = txtcolor[17] = txtcolor[22] = txtcolor[24]
  1787.           = txtcolor[25] = BLACK*16+L_WHITE;
  1788.       }
  1789.    else {
  1790.       k = 0;
  1791.       while ( k < sizeof(txtcolor)) {
  1792.      if (*value == 0) break;
  1793.      if (*value != '/') {
  1794.         sscanf(value,"%x",&hexval);
  1795.         i = (hexval / 16) & 7;
  1796.         j = hexval & 15;
  1797.         if (i == j || (i == 0 && j == 8)) /* force contrast */
  1798.            j = 15;
  1799.         txtcolor[k] = i * 16 + j;
  1800.         if ((value = strchr(value,'/')) == NULL) break;
  1801.         }
  1802.      ++value;
  1803.      ++k;
  1804.      }
  1805.       }
  1806. }
  1807.  
  1808. static int parse_colors(char *value)
  1809. {
  1810.    int i,j,k;
  1811.    if (*value == '@') {
  1812.       if (strlen(value) > 80 || ValidateLuts(&value[1]) != 0) goto badcolor;
  1813.       if (display3d) {
  1814.         mapset = 1;
  1815.         strcpy(MAP_name,&value[1]);
  1816.         }
  1817.       else {
  1818.         strcpy(colorfile,&value[1]);
  1819.         colorstate = 2;
  1820.         }
  1821.       }
  1822.    else {
  1823.       int smooth;
  1824.       i = smooth = 0;
  1825.       while (*value) {
  1826.      if (i >= 256) goto badcolor;
  1827.      if (*value == '<') {
  1828.         if (i == 0 || smooth
  1829.           || (smooth = atoi(value+1)) < 2
  1830.           || (value = strchr(value,'>')) == NULL)
  1831.            goto badcolor;
  1832.         i += smooth;
  1833.         ++value;
  1834.         }
  1835.      else {
  1836.         for (j = 0; j < 3; ++j) {
  1837.            if ((k = *(value++)) < '0')  goto badcolor;
  1838.            else if (k <= '9')       k -= '0';
  1839.            else if (k < 'A')            goto badcolor;
  1840.            else if (k <= 'Z')       k -= ('A'-10);
  1841.            else if (k < '_' || k > 'z') goto badcolor;
  1842.            else            k -= ('_'-36);
  1843.            dacbox[i][j] = k;
  1844.            if (smooth) {
  1845.           int start,spread,cnum;
  1846.           start = i - (spread = smooth + 1);
  1847.           cnum = 0;
  1848.           if ((k - (int)dacbox[start][j]) == 0) {
  1849.              while (++cnum < spread)
  1850.             dacbox[start+cnum][j] = k;
  1851.              }
  1852.           else {
  1853.              while (++cnum < spread)
  1854.             dacbox[start+cnum][j] =
  1855.                ( cnum         *dacbox[i][j]
  1856.                + (i-(start+cnum))*dacbox[start][j]
  1857.                + spread/2 )
  1858.                / spread;
  1859.              }
  1860.           }
  1861.            }
  1862.         smooth = 0;
  1863.         ++i;
  1864.         }
  1865.      }
  1866.       if (smooth) goto badcolor;
  1867.       while (i < 256)  { /* zap unset entries */
  1868.      dacbox[i][0] = dacbox[i][1] = dacbox[i][2] = 40;
  1869.      ++i;
  1870.      }
  1871.       colorstate = 1;
  1872.       }
  1873.    colorpreloaded = 1;
  1874.    return(0);
  1875. badcolor:
  1876.    return(-1);
  1877. }
  1878.  
  1879. static int parse_printer(char *value)
  1880. {
  1881.    int k;
  1882.    if (value[0]=='h' && value[1]=='p')
  1883.       Printer_Type=1;                 /* HP LaserJet           */
  1884.    if (value[0]=='i' && value[1]=='b')
  1885.       Printer_Type=2;                 /* IBM Graphics           */
  1886.    if (value[0]=='e' && value[1]=='p')
  1887.       Printer_Type=2;                 /* Epson (model?)           */
  1888.    if (value[0]=='c' && value[1]=='o')
  1889.       Printer_Type=3;                 /* Star (Epson-Comp?) color */
  1890.    if (value[0]=='p') {
  1891.       if (value[1]=='a')
  1892.      Printer_Type=4;             /* HP Paintjet (color)    */
  1893.       if ((value[1]=='o' || value[1]=='s')) {
  1894.      Printer_Type=5;             /* PostScript  SWT */
  1895.      if (value[2]=='h' || value[2]=='l')
  1896.         Printer_Type=6;
  1897.      }
  1898.       if (value[1]=='l')
  1899.      Printer_Type=7;             /* HP Plotter (semi-color) */
  1900.       }
  1901.    if (Printer_Type == 1)             /* assume low resolution */
  1902.       Printer_Resolution = 75;
  1903.    else
  1904.       Printer_Resolution = 60;
  1905.    if (EPSFileType > 0)              /* EPS save - force type 5 */
  1906.       Printer_Type = 5;
  1907.    if ((Printer_Type == 5) || (Printer_Type == 6))
  1908.       Printer_Resolution = 150;          /* PostScript def. res. */
  1909.    if ((value=strchr(value,'/'))) {
  1910.       if ((k=atoi(++value)) >= 0) Printer_Resolution=k;
  1911.       if ((value=strchr(value,'/'))) {
  1912.      if ((k=atoi(++value))> 0) LPTNumber = k;
  1913.      if (k < 0) {
  1914.         Print_To_File = 1;
  1915.         LPTNumber = 1;
  1916.         }
  1917.      }
  1918.       }
  1919.    return(0);
  1920. }
  1921.  
  1922.  
  1923.  
  1924. static void argerror(char *badarg)    /* oops. couldn't decode this */
  1925. {
  1926.    static char far argerrmsg1[]={"\
  1927. Oops. I couldn't understand the argument:\n  "};
  1928.    static char far argerrmsg2[]={"\n\n\
  1929. (see the Startup Help screens or documentation for a complete\n\
  1930.  argument list with descriptions)"};
  1931.    char msg[300];
  1932.    if (strlen(badarg) > 70) badarg[70] = 0;
  1933.    if (active_system == 0 /* DOS */
  1934.      && first_init)      /* & this is 1st call to cmdfiles */
  1935. #ifndef XFRACT
  1936.       sprintf(msg,"%Fs%s%Fs",argerrmsg1,badarg,argerrmsg2);
  1937.    else
  1938.       sprintf(msg,"%Fs%s",argerrmsg1,badarg);
  1939. #else
  1940.       sprintf(msg,"%s%s%s",argerrmsg1,badarg,argerrmsg2);
  1941.    else
  1942.       sprintf(msg,"%s%s",argerrmsg1,badarg);
  1943. #endif
  1944.    stopmsg(0,msg);
  1945. }
  1946.  
  1947. void set_3d_defaults()
  1948. {
  1949.    ENTER_OVLY(OVLY_CMDFILES);
  1950.    ROUGH     = 30;
  1951.    WATERLINE = 0;
  1952.    ZVIEWER   = 0;
  1953.    XSHIFT    = 0;
  1954.    YSHIFT    = 0;
  1955.    xtrans    = 0;
  1956.    ytrans    = 0;
  1957.    LIGHTAVG  = 0;
  1958.    Ambient   = 20;
  1959.    RANDOMIZE = 0;
  1960.    haze      = 0;
  1961.    back_color[0] = 51; back_color[1] = 153; back_color[2] = 200;
  1962.    if(SPHERE) {
  1963.       PHI1    =  180;
  1964.       PHI2    =  0;
  1965.       THETA1    =  -90;
  1966.       THETA2    =  90;
  1967.       RADIUS    =  100;
  1968.       FILLTYPE    = 2;
  1969.       XLIGHT    = 1;
  1970.       YLIGHT    = 1;
  1971.       ZLIGHT    = 1;
  1972.       }
  1973.    else {
  1974.       XROT    = 60;
  1975.       YROT    = 30;
  1976.       ZROT    = 0;
  1977.       XSCALE    = 90;
  1978.       YSCALE    = 90;
  1979.       FILLTYPE    = 0;
  1980.       if (active_system != 0)
  1981.      FILLTYPE = 2;
  1982.       XLIGHT    = 1;
  1983.       YLIGHT    = -1;
  1984.       ZLIGHT    = 1;
  1985.       }
  1986.     EXIT_OVLY;
  1987. }
  1988.