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