home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fractint / fras1611.zip / PROMPTS.C < prev    next >
C/C++ Source or Header  |  1991-07-21  |  92KB  |  3,204 lines

  1. /*
  2.     Various routines that prompt for things.
  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 <ctype.h>
  10. #include <dos.h>
  11. #include <malloc.h>
  12. #include "fractint.h"
  13. #include "fractype.h"
  14. #include "helpdefs.h"
  15.  
  16. /* Routines in this module    */
  17.  
  18. extern    int fullscreen_prompt(char *hdg,int numprompts,
  19.            char * far *prompts,struct fullscreenvalues values[],
  20.            int options,int fkeymask,char far *extrainfo);
  21. extern    void prompts_overlay(void );
  22. extern    int get_fracttype(void );
  23. extern    int get_fract_params(int);
  24. extern    int get_3d_params(void );
  25. extern    int get_fract3d_params(void );
  26. extern    int get_toggles(void );
  27. extern    int get_toggles2(void );
  28. extern    int get_view_params(void );
  29. extern    int get_starfield_params(void );
  30. extern    void goodbye(void );
  31. extern    int getafilename(char *hdg,char *template,char *flname);
  32. extern    int get_commands(void);
  33.  
  34. static    int prompt_valuestring(char *buf,struct fullscreenvalues *val);
  35. static    int prompt_checkkey(int curkey);
  36. static    int input_field_list(int attr,char *fld,int vlen,char **list,int llen,
  37.                  int row,int col,int (*checkkey)(int));
  38. static    int select_fracttype(int t);
  39. static    int sel_fractype_help(int curkey, int choice);
  40. static    int get_corners(void);
  41. static    int edit_ifs_params(void );
  42. static    int select_type_params(int newfractype,int oldfractype);
  43. static    void set_default_parms(void);
  44. static    long get_file_entry(int,char *,char *,char *,char *);
  45. static    long gfe_choose_entry(int,char *,char *,char *);
  46. static    int check_gfe_key(int curkey,int choice);
  47. static    void load_entry_text(FILE *entfile,char far *buf,int maxlines);
  48. static    void format_parmfile_line(int,char *);
  49. static    int get_light_params(void );
  50. static    int check_mapfile(void );
  51. static    int get_funny_glasses_params(void );
  52. static    int findfirst(char *path);
  53. static    int findnext(void );
  54. static    int lccompare(void const *, void const *);
  55. static    int splitpath(char *template,char *drive,char *dir,char *fname,char *ext);
  56. static    int makepath(char *template,char *drive,char *dir,char *fname,char *ext);
  57. static    void fix_dirname(char *dirname);
  58. static    int expand_dirname(char *dirname,char *drive);
  59. static    int filename_speedstr(int, int, int, char *, int);
  60. static    int isadirectory(char *s);
  61.  
  62. extern char *strig[];
  63. extern int numtrigfn;
  64. extern int bailout;
  65. extern int dotmode;
  66.  
  67. extern int fullscreen_choice(
  68.          int options, char *hdg, char *hdg2, char *instr, int numchoices,
  69.          char **choices, int *attributes, int boxwidth, int boxdepth,
  70.          int colwidth, int current, void (*formatitem)(),
  71.          char *speedstring, int (*speedprompt)(), int (*checkkey)());
  72. extern int strncasecmp(char *s,char *t,int ct);
  73. extern int field_prompt(int options, char *hdg, char *instr, char *fld,
  74.          int len, int (*checkkey)() );
  75. extern int input_field(int options, int attr, char *fld,
  76.          int len, int row, int col, int (*checkkey)(int) );
  77. extern int read_help_topic(int label_num, int off, int len, void far *buf);
  78. extern int Formula();
  79.  
  80. static char funnyglasses_map_name[16];
  81. extern char temp[], temp1[256];   /* temporary strings          */
  82. extern int mapset;
  83. extern int previewfactor;
  84. extern int xtrans, ytrans;
  85. extern int red_crop_left, red_crop_right;
  86. extern int blue_crop_left, blue_crop_right;
  87. extern int red_bright, blue_bright;
  88. extern char showbox; /* flag to show box and vector in preview */
  89. extern int debugflag;
  90. extern int extraseg;
  91. extern int whichimage;
  92. extern int xadjust;
  93. extern int eyeseparation;
  94. extern int glassestype;
  95. extern findpath();
  96. char   MAP_name[80] = "";
  97. int    mapset = 0;
  98. extern    int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  99. extern    int    lookatmouse;
  100. extern    int full_color;
  101. extern    int haze;
  102. extern    int RANDOMIZE;
  103. extern    char light_name[];
  104. extern    int Ambient;
  105. extern    int RAY;
  106. extern    int BRIEF;
  107. extern    char ray_name[];
  108.  
  109. extern    int    init3d[20];    /* '3d=nn/nn/nn/...' values */
  110. extern    double    xxmin,xxmax;    /* initial corner values    */
  111. extern    double    yymin,yymax;    /* initial corner values    */
  112. extern    unsigned char usemag;
  113.  
  114. extern    int AntiAliasing;
  115. extern double zzmin, zzmax, ttmin, ttmax;
  116. extern int Transparent3D;
  117.  
  118. extern    double    xx3rd,yy3rd;    /* initial corner values    */
  119. extern    int    invert;     /* non-zero if inversion active */
  120. extern    double    inversion[3];    /* radius, xcenter, ycenter */
  121. extern    long    fudge;        /* 2**fudgefactor    */
  122. extern    int    bitshift;    /* fudgefactor        */
  123. extern    double    param[4];    /* up to four parameters    */
  124. extern    int    pot16bit;
  125. extern    int    disk16bit;
  126. extern    double    potparam[3];    /* three potential parameters*/
  127. extern    int    fractype;    /* if == 0, use Mandelbrot  */
  128. extern    char    usr_floatflag;    /* floating-point fractals? */
  129. extern    int    maxit;        /* try this many iterations */
  130. extern    int    inside;     /* inside color */
  131. extern    int    outside;    /* outside color */
  132. extern    int    finattract;    /* finite attractor switch */
  133. extern    char    savename[80];    /* save files using this name */
  134. extern    char    ifsfilename[80];    /* IFS code file */
  135. extern    char    ifs3dfilename[80];  /* IFS 3D code file */
  136. extern    char    preview;    /* 3D preview mode flag */
  137. extern    int    decomp[];    /* decomposition parameters */
  138. extern    int    usr_distest;    /* distance estimator option */
  139. extern    int    distestwidth;
  140. extern    int    transparent[];    /* transparency values */
  141. extern    char    usr_stdcalcmode; /* '1', '2', 'g', 'b' */
  142. extern    char overwrite;     /* overwrite= flag */
  143. extern    int    soundflag;    /* sound option */
  144. extern    int    LogFlag;    /* non-zero if logarithmic palettes */
  145. extern    int    usr_biomorph;    /* Biomorph flag */
  146. extern    long    xmin, xmax, ymin, ymax; /* screen corner values */
  147. extern    int    calc_status;    /* calc status: complete, resumable, ... */
  148. extern    int    xdots, ydots;    /* coordinates of dots on the screen  */
  149. extern    int    colors;     /* maximum colors available */
  150. extern    int    row, col;
  151. extern    int    viewwindow;
  152. extern    float    viewreduction;
  153. extern    int    viewcrop;
  154. extern    float    finalaspectratio;
  155. extern    int    viewxdots,viewydots;
  156. extern    void    aspectratio_crop(float,float);
  157. extern    int    textcbase;
  158. extern    int    textrow,textcol;
  159. extern    int    resave_flag;    /* resaving after a timed save */
  160. extern    int    started_resaves;
  161. extern    char    boxy[];
  162. extern    char    *fkeys[];
  163. extern    int    kbdkeys[];
  164. extern    int    video_type;
  165. extern    int    adapter;
  166. extern    int    rotate_lo,rotate_hi;
  167. extern    int    display3d;
  168. extern    int    rangeslen;
  169.  
  170. extern char LFileName[];    /* file to find the formulas in */
  171. extern char LName[];        /* Name of the Formula (if not null) */
  172. extern char FormFileName[];
  173. extern char FormName[];
  174. extern char IFSFileName[];
  175. extern char IFSName[];
  176. extern char CommandFile[];
  177. extern char CommandName[];
  178. extern float far *ifs_defn;
  179. extern int ifs_type;
  180. extern int ifs_changed;
  181.  
  182. /* fullscreen_choice options */
  183. #define CHOICERETURNKEY 1
  184. #define CHOICEMENU    2
  185. #define CHOICEHELP    4
  186.  
  187. /* speed key state values */
  188. #define MATCHING     0    /* string matches list - speed key mode */
  189. #define TEMPLATE    -2    /* wild cards present - buiding template */
  190. #define SEARCHPATH    -3    /* no match - building path search name */
  191.  
  192. #define   FILEATTR     0x37       /* File attributes; select all but volume labels */
  193. #define   HIDDEN     2
  194. #define   SYSTEM     4
  195. #define   SUBDIR     16
  196. #define   MAXNUMFILES     300
  197.  
  198. struct                   /* Allocate DTA and define structure */
  199. {
  200.      char path[21];            /* DOS path and filespec */
  201.      char attribute;            /* File attributes wanted */
  202.      int  ftime;            /* File creation time */
  203.      int  fdate;            /* File creation date */
  204.      long size;             /* File size in bytes */
  205.      char filename[13];         /* Filename and extension */
  206. } DTA;                   /* Disk Transfer Area */
  207.  
  208. #define GETFORMULA 0
  209. #define GETLSYS    1
  210. #define GETIFS       2
  211. #define GETPARM    3
  212.  
  213. /* --------------------------------------------------------------------- */
  214. extern char s_iter[];
  215. extern char s_real[];
  216. extern char s_mult[];
  217. extern char s_sum[];
  218. extern char s_imag[];
  219. extern char s_zmag[];
  220. extern char s_bof60[];
  221. extern char s_bof61[];
  222. extern char s_maxiter[];
  223.  
  224. extern char gifmask[];
  225. char ifsmask[13]     = {"*.ifs"};
  226. char formmask[13]    = {"*.frm"};
  227. char lsysmask[13]    = {"*.l"};
  228. char commandmask[13] = {"*.par"};
  229.  
  230. void prompts_overlay() { }    /* for restore_active_ovly */
  231.  
  232.  
  233. /* --------------------------------------------------------------------- */
  234.  
  235. static int promptfkeys;
  236.  
  237. int fullscreen_prompt(    /* full-screen prompting routine */
  238.     char *hdg,        /* heading, lines separated by \n */
  239.     int numprompts,     /* there are this many prompts (max) */
  240.     char * far *prompts,    /* array of prompting pointers */
  241.     struct fullscreenvalues values[], /* array of values */
  242.     int options,        /* for future */
  243.     int fkeymask,        /* bit n on if Fn to cause return */
  244.     char far *extrainfo    /* extra info box to display, \n separated */
  245.     )
  246. {
  247.    char far *hdgscan;
  248.    int titlelines,titlewidth,titlerow;
  249.    int maxpromptwidth,maxfldwidth,maxcomment;
  250.    int boxrow,boxlines;
  251.    int boxcol,boxwidth;
  252.    int extralines,extrawidth,extrarow;
  253.    int instrrow;
  254.    int promptrow,promptcol,valuecol;
  255.    int curchoice;
  256.    int done, i, j;
  257.    int savelookatmouse;
  258.    int curtype, curlen;
  259.    char buf[81];
  260. static char far instr1[]  = {"Use \x18 and \x19 to select values to change"};
  261. static char far instr2a[]  = {"Type in replacement value for selected field"};
  262. static char far instr2b[]  = {"Use \x1B or \x1A to change value of selected field"};
  263. static char far instr3a[] = {"Press ENTER when finished (or ESCAPE to back out)"};
  264. static char far instr3b[] = {"Press ENTER when finished, ESCAPE to back out, or F1 for help"};
  265.  
  266.    ENTER_OVLY(OVLY_PROMPTS);
  267.  
  268.    if (numprompts <= 0) {    /* ?? nothing to do! */
  269.       EXIT_OVLY;
  270.       return(0);
  271.       }
  272.  
  273.    savelookatmouse = lookatmouse;
  274.    lookatmouse = 0;
  275.    promptfkeys = fkeymask;
  276.    helptitle();                /* clear screen, display title line  */
  277.    setattr(1,0,C_PROMPT_BKGRD,24*80);  /* init rest of screen to background */
  278.  
  279.    hdgscan = hdg;               /* count title lines, find widest */
  280.    i = titlewidth = 0;
  281.    titlelines = 1;
  282.    while (*hdgscan) {
  283.       if (*(hdgscan++) == '\n') {
  284.      ++titlelines;
  285.      i = -1;
  286.      }
  287.       if (++i > titlewidth)
  288.      titlewidth = i;
  289.       }
  290.    extralines = extrawidth = i = 0;
  291.    if ((hdgscan = extrainfo))
  292.       if (*hdgscan == 0)
  293.      extrainfo = NULL;
  294.       else { /* count extra lines, find widest */
  295.      extralines = 3;
  296.      while (*hdgscan) {
  297.         if (*(hdgscan++) == '\n') {
  298.            if (extralines + numprompts + titlelines >= 20) {
  299.            *hdgscan = 0; /* full screen, cut off here */
  300.            break;
  301.            }
  302.            ++extralines;
  303.            i = -1;
  304.            }
  305.         if (++i > extrawidth)
  306.            extrawidth = i;
  307.         }
  308.      }
  309.  
  310.    /* work out vertical positioning */
  311.    i = numprompts + titlelines + extralines + 3; /* total rows required */
  312.    j = (25 - i) / 2;               /* top row of it all when centered */
  313.    j -= j / 4;                   /* higher is better if lots extra */
  314.    boxlines = numprompts;
  315.    titlerow = 1 + j;
  316.    promptrow = boxrow = titlerow + titlelines;
  317.    if (titlerow > 2) {               /* room for blank between title & box? */
  318.       --titlerow;
  319.       --boxrow;
  320.       ++boxlines;
  321.       }
  322.    instrrow = boxrow+boxlines;
  323.    if (instrrow + 3 + extralines < 25) {
  324.       ++boxlines;    /* blank at bottom of box */
  325.       ++instrrow;
  326.       if (instrrow + 3 + extralines < 25)
  327.      ++instrrow; /* blank before instructions */
  328.       }
  329.    extrarow = instrrow + 2;
  330.    if (numprompts > 1) /* 3 instructions lines */
  331.       ++extrarow;
  332.    if (extrarow + extralines < 25)
  333.       ++extrarow;
  334.  
  335.    /* work out horizontal positioning */
  336.    maxfldwidth = maxpromptwidth = maxcomment = 0;
  337.    for (i = 0; i < numprompts; i++) {
  338.       if (values[i].type == 'y') {
  339.      static char *noyes[2] = {"no","yes"};
  340.      values[i].type = 'l';
  341.      values[i].uval.ch.vlen = 3;
  342.      values[i].uval.ch.list = noyes;
  343.      values[i].uval.ch.llen = 2;
  344.      }
  345.       j = strlen(prompts[i]);
  346.       if (values[i].type == '*') {
  347.      if (j > maxcomment)     maxcomment = j;
  348.      }
  349.       else {
  350.      if (j > maxpromptwidth) maxpromptwidth = j;
  351.      j = prompt_valuestring(buf,&values[i]);
  352.      if (j > maxfldwidth)     maxfldwidth = j;
  353.      }
  354.       }
  355.    boxwidth = maxpromptwidth + maxfldwidth + 2;
  356.    if (maxcomment > boxwidth) boxwidth = maxcomment;
  357.    if ((boxwidth += 4) > 80) boxwidth = 80;
  358.    boxcol = (80 - boxwidth) / 2;       /* center the box */
  359.    promptcol = boxcol + 2;
  360.    valuecol = boxcol + boxwidth - maxfldwidth - 2;
  361.    if (boxwidth <= 76) {           /* make margin a bit wider if we can */
  362.       boxwidth += 2;
  363.       --boxcol;
  364.       }
  365.    if ((j = titlewidth) < extrawidth)
  366.       j = extrawidth;
  367.    if ((i = j + 4 - boxwidth) > 0) {   /* expand box for title/extra */
  368.       if (boxwidth + i > 80)
  369.      i = 80 - boxwidth;
  370.       boxwidth += i;
  371.       boxcol -= i / 2;
  372.       }
  373.    i = (90 - boxwidth) / 20;
  374.    boxcol    -= i;
  375.    promptcol -= i;
  376.    valuecol  -= i;
  377.  
  378.    /* display box heading */
  379.    for (i = titlerow; i < boxrow; ++i)
  380.       setattr(i,boxcol,C_PROMPT_HI,boxwidth);
  381.    textcbase = boxcol + (boxwidth - titlewidth) / 2;
  382.    putstring(titlerow,0,C_PROMPT_HI,hdg);
  383.  
  384.    /* display extra info */
  385.    if (extrainfo) {
  386.       memset(buf,'\xC4',80); buf[boxwidth-2] = 0;
  387.       textcbase = boxcol + 1;
  388.       putstring(extrarow,0,C_PROMPT_BKGRD,buf);
  389.       putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,buf);
  390.       --textcbase;
  391.       putstring(extrarow,0,C_PROMPT_BKGRD,"\xDA");
  392.       putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,"\xC0");
  393.       textcbase += boxwidth - 1;
  394.       putstring(extrarow,0,C_PROMPT_BKGRD,"\xBF");
  395.       putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,"\xD9");
  396.       textcbase = boxcol;
  397.       for (i = 1; i < extralines-1; ++i) {
  398.      putstring(extrarow+i,0,C_PROMPT_BKGRD,"\xB3");
  399.      putstring(extrarow+i,boxwidth-1,C_PROMPT_BKGRD,"\xB3");
  400.      }
  401.       textcbase += (boxwidth - extrawidth) / 2;
  402.       putstring(extrarow+1,0,C_PROMPT_TEXT,extrainfo);
  403.       }
  404.    textcbase = 0;
  405.  
  406.    /* display empty box */
  407.    for (i = 0; i < boxlines; ++i)
  408.       setattr(boxrow+i,boxcol,C_PROMPT_LO,boxwidth);
  409.  
  410.    /* display initial values */
  411.    for (i = 0; i < numprompts; i++) {
  412.       putstring(promptrow+i, promptcol, C_PROMPT_LO, prompts[i]);
  413.       prompt_valuestring(buf,&values[i]);
  414.       putstring(promptrow+i, valuecol, C_PROMPT_LO, buf);
  415.       }
  416.  
  417.    /* display footing */
  418.    if (numprompts > 1)
  419.       putstringcenter(instrrow++,0,80,C_PROMPT_BKGRD,instr1);
  420.    putstringcenter(instrrow+1,0,80,C_PROMPT_BKGRD,
  421.      (helpmode > 0) ? instr3b : instr3a);
  422.  
  423.    curchoice = done = 0;
  424.    while (values[curchoice].type == '*') ++curchoice;
  425.  
  426.    while (!done) {
  427.  
  428.       curtype = values[curchoice].type;
  429.       curlen = prompt_valuestring(buf,&values[curchoice]);
  430.       putstringcenter(instrrow,0,80,C_PROMPT_BKGRD,
  431.               (curtype == 'l') ? instr2b : instr2a);
  432.       putstring(promptrow+curchoice,promptcol,C_PROMPT_HI,prompts[curchoice]);
  433.  
  434.       if (curtype == 'l') {
  435.      i = input_field_list(
  436.         C_PROMPT_CHOOSE, buf, curlen,
  437.         values[curchoice].uval.ch.list, values[curchoice].uval.ch.llen,
  438.         promptrow+curchoice,valuecol, prompt_checkkey);
  439.      for (j = 0; j < values[curchoice].uval.ch.llen; ++j)
  440.         if (strcmp(buf,values[curchoice].uval.ch.list[j]) == 0) break;
  441.      values[curchoice].uval.ch.val = j;
  442.      }
  443.       else {
  444.      j = 0;
  445.      if (curtype == 'i') j = 3;
  446.      if (curtype == 'd') j = 5;
  447.      if (curtype == 'f') j = 1;
  448.      i = input_field(j, C_PROMPT_INPUT, buf, curlen,
  449.         promptrow+curchoice,valuecol,prompt_checkkey);
  450.      switch (values[curchoice].type) {
  451.         case 'd':
  452.            values[curchoice].uval.dval = atof(buf);
  453.            break;
  454.         case 'f':
  455.            values[curchoice].uval.dval = atof(buf);
  456.            roundfloatd(&values[curchoice].uval.dval);
  457.            break;
  458.         case 'i':
  459.            values[curchoice].uval.ival = atoi(buf);
  460.            break;
  461.         case 's':
  462.            strncpy(values[curchoice].uval.sval,buf,16);
  463.            break;
  464.         default: /* assume 0x100+n */
  465.            strcpy(values[curchoice].uval.sbuf,buf);
  466.         }
  467.      }
  468.  
  469.       putstring(promptrow+curchoice,promptcol,C_PROMPT_LO,prompts[curchoice]);
  470.       j = strlen(buf);
  471.       memset(&buf[j],' ',80-j); buf[curlen] = 0;
  472.       putstring(promptrow+curchoice, valuecol, C_PROMPT_LO,  buf);
  473.  
  474.       switch(i) {
  475.      case 0:  /* enter  */
  476.         done = 13;
  477.         break;
  478.      case -1: /* escape */
  479.      case F2:
  480.      case F3:
  481.      case F4:
  482.      case F5:
  483.      case F6:
  484.      case F7:
  485.      case F8:
  486.      case F9:
  487.      case F10:
  488.         done = i;
  489.         break;
  490.      case PAGE_UP:
  491.         curchoice = -1;
  492.      case DOWN_ARROW:
  493.      case DOWN_ARROW_2:
  494.         do {
  495.            if (++curchoice >= numprompts) curchoice = 0;
  496.            } while (values[curchoice].type == '*');
  497.         break;
  498.      case PAGE_DOWN:
  499.         curchoice = numprompts;
  500.      case UP_ARROW:
  501.      case UP_ARROW_2:
  502.         do {
  503.            if (--curchoice < 0) curchoice = numprompts - 1;
  504.            } while (values[curchoice].type == '*');
  505.         break;
  506.      }
  507.       }
  508.  
  509.    movecursor(25,80);
  510.    lookatmouse = savelookatmouse;
  511.    EXIT_OVLY;
  512.    return(done);
  513. }
  514.  
  515. static int prompt_valuestring(char *buf,struct fullscreenvalues *val)
  516. {  /* format value into buf, return field width */
  517.    int i,ret;
  518.    switch (val->type) {
  519.       case 'd':
  520.      ret = 20;
  521.      i = 15;
  522.      while (1) {
  523.         sprintf(buf,"%.*g",i,val->uval.dval);
  524.         if (strlen(buf) <= ret) break;
  525.         --i;
  526.         }
  527.      break;
  528.       case 'f':
  529.      sprintf(buf,"%.7g",val->uval.dval);
  530.      ret = 14;
  531.      break;
  532.       case 'i':
  533.      sprintf(buf,"%d",val->uval.ival);
  534.      ret = 6;
  535.      break;
  536.       case '*':
  537.      *buf = ret = 0;
  538.      break;
  539.       case 's':
  540.      strncpy(buf,val->uval.sval,16);
  541.      buf[15] = 0;
  542.      ret = 15;
  543.      break;
  544.       case 'l':
  545.      strcpy(buf,val->uval.ch.list[val->uval.ch.val]);
  546.      ret = val->uval.ch.vlen;
  547.      break;
  548.       default: /* assume 0x100+n */
  549.      strcpy(buf,val->uval.sbuf);
  550.      ret = val->type & 0xff;
  551.       }
  552.    return ret;
  553. }
  554.  
  555. static int prompt_checkkey(int curkey)
  556. {
  557.    switch(curkey) {
  558.       case PAGE_UP:
  559.       case DOWN_ARROW:
  560.       case DOWN_ARROW_2:
  561.       case PAGE_DOWN:
  562.       case UP_ARROW:
  563.       case UP_ARROW_2:
  564.      return(curkey);
  565.       case F2:
  566.       case F3:
  567.       case F4:
  568.       case F5:
  569.       case F6:
  570.       case F7:
  571.       case F8:
  572.       case F9:
  573.       case F10:
  574.      if (promptfkeys & (1<<(curkey+1-F1)) )
  575.         return(curkey);
  576.       }
  577.    return(0);
  578. }
  579.  
  580. static int input_field_list(
  581.     int attr,          /* display attribute */
  582.     char *fld,          /* display form field value */
  583.     int vlen,          /* field length */
  584.     char **list,          /* list of values */
  585.     int llen,          /* number of entries in list */
  586.     int row,          /* display row */
  587.     int col,          /* display column */
  588.     int (*checkkey)(int)  /* routine to check non data keys, or NULL */
  589.     )
  590. {
  591.    int initval,curval;
  592.    char buf[81];
  593.    int curkey;
  594.    int i, j;
  595.    int ret,savelookatmouse;
  596.    savelookatmouse = lookatmouse;
  597.    lookatmouse = 0;
  598.    for (initval = 0; initval < llen; ++initval)
  599.       if (strcmp(fld,list[initval]) == 0) break;
  600.    if (initval >= llen) initval = 0;
  601.    curval = initval;
  602.    ret = -1;
  603.    while (1) {
  604.       strcpy(buf,list[curval]);
  605.       i = strlen(buf);
  606.       while (i < vlen)
  607.      buf[i++] = ' ';
  608.       buf[vlen] = 0;
  609.       putstring(row,col,attr,buf);
  610.       curkey = keycursor(row,col); /* get a keystroke */
  611.       switch (curkey) {
  612.      case ENTER:
  613.      case ENTER_2:
  614.         ret = 0;
  615.         goto inpfldl_end;
  616.      case ESC:
  617.         goto inpfldl_end;
  618.      case RIGHT_ARROW:
  619.      case RIGHT_ARROW_2:
  620.         if (++curval >= llen)
  621.            curval = 0;
  622.         break;
  623.      case LEFT_ARROW:
  624.      case LEFT_ARROW_2:
  625.         if (--curval < 0)
  626.            curval = llen - 1;
  627.         break;
  628.      case F5:
  629.         curval = initval;
  630.         break;
  631.      default:
  632.         if (curkey < 32 || curkey >= 127) {
  633.            if (checkkey && (ret = (*checkkey)(curkey)))
  634.           goto inpfldl_end;
  635.            break;                     /* non alphanum char */
  636.            }
  637.         j = curval;
  638.         for (i = 0; i < llen; ++i) {
  639.            if (++j >= llen)
  640.           j = 0;
  641.            if ((*list[j] & 0xdf) == (curkey & 0xdf)) {
  642.           curval = j;
  643.           break;
  644.           }
  645.            }
  646.      }
  647.       }
  648. inpfldl_end:
  649.    strcpy(fld,list[curval]);
  650.    lookatmouse = savelookatmouse;
  651.    return(ret);
  652. }
  653.  
  654.  
  655. /* --------------------------------------------------------------------- */
  656.  
  657. /* MCP 7-7-91, This is static code, but not called anywhere */
  658. #ifdef DELETE_UNUSED_CODE
  659.  
  660. /* compare for sort of type table */
  661. static int compare(const void *i, const void *j)
  662. {
  663.    return(strcmp(fractalspecific[(int)*((unsigned char*)i)].name,
  664.            fractalspecific[(int)*((unsigned char*)j)].name));
  665. }
  666.  
  667. /* --------------------------------------------------------------------- */
  668.  
  669. static void clear_line(int row, int start, int stop, int color) /* clear part of a line */
  670. {
  671.    int col;
  672.    for(col=start;col<= stop;col++)
  673.       putstring(row,col,color," ");
  674. }
  675.  
  676. #endif
  677.  
  678. /* --------------------------------------------------------------------- */
  679.  
  680. int get_fracttype()        /* prompt for and select fractal type */
  681. {
  682.    int done,i,oldfractype,t;
  683.    ENTER_OVLY(OVLY_PROMPTS);
  684.    done = -1;
  685.    oldfractype = fractype;
  686.    while (1) {
  687.       if ((t = select_fracttype(fractype)) < 0)
  688.      break;
  689.       if ((i = select_type_params(t, fractype)) == 0) { /* ok, all done */
  690.      done = 0;
  691.      break;
  692.      }
  693.       if (i > 0) /* can't return to prior image anymore */
  694.      done = 1;
  695.       }
  696.    if (done < 0)
  697.       fractype = oldfractype;
  698.    curfractalspecific = &fractalspecific[fractype];
  699.    EXIT_OVLY;
  700.    return(done);
  701. }
  702.  
  703. struct FT_CHOICE {
  704.       char name[15];
  705.       int  num;
  706.       };
  707. static struct FT_CHOICE **ft_choices; /* for sel_fractype_help subrtn */
  708.  
  709. static int select_fracttype(int t) /* subrtn of get_fracttype, separated */
  710.                    /* so that storage gets freed up     */
  711. {
  712.    int oldhelpmode;
  713.    int numtypes, done;
  714.    int i, j;
  715. #define MAXFTYPES 200
  716.    char tname[40];
  717.    struct FT_CHOICE *choices[MAXFTYPES];
  718.    int attributes[MAXFTYPES];
  719.  
  720.    /* steal existing array for "choices" */
  721.    choices[0] = (struct FT_CHOICE *)boxy;
  722.    attributes[0] = 1;
  723.    for (i = 1; i < MAXFTYPES; ++i) {
  724.       choices[i] = choices[i-1] + 1;
  725.       attributes[i] = 1;
  726.       }
  727.    ft_choices = &choices[0];
  728.  
  729.    /* setup context sensitive help */
  730.    oldhelpmode = helpmode;
  731.    helpmode = HELPFRACTALS;
  732.  
  733.    if (t == IFS3D) t = IFS;
  734.    i = j = -1;
  735.    while(fractalspecific[++i].name) {
  736.       if (fractalspecific[i].name[0] == '*')
  737.      continue;
  738.       strcpy(choices[++j]->name,fractalspecific[i].name);
  739.       choices[j]->name[14] = 0; /* safety */
  740.       choices[j]->num = i;    /* remember where the real item is */
  741.       }
  742.    numtypes = j + 1;
  743.    qsort(choices,numtypes,sizeof(char *),lccompare); /* sort list */
  744.    j = 0;
  745.    for (i = 0; i < numtypes; ++i) /* find starting choice in sorted list */
  746.       if (choices[i]->num == t || choices[i]->num == fractalspecific[t].tofloat)
  747.      j = i;
  748.  
  749.    tname[0] = 0;
  750.    done = fullscreen_choice(CHOICEHELP+8,"Select a Fractal Type",NULL,
  751.                 "Press F2 for a description of the highlighted type",
  752.                 numtypes,(char **)choices,attributes,0,0,0,j,
  753.                 NULL,tname,NULL,sel_fractype_help);
  754.    if (done >= 0)
  755.       done = choices[done]->num;
  756.    helpmode = oldhelpmode;
  757.    return(done);
  758. }
  759.  
  760. static int sel_fractype_help(int curkey,int choice)
  761. {
  762.    int oldhelpmode;
  763.    if (curkey == F2) {
  764.       oldhelpmode = helpmode;
  765.       helpmode = fractalspecific[(*(ft_choices+choice))->num].helptext;
  766.       help(0);
  767.       helpmode = oldhelpmode;
  768.       }
  769.    return(0);
  770. }
  771.  
  772. static int select_type_params(    /* prompt for new fractal type parameters */
  773.     int newfractype,    /* new fractal type */
  774.     int oldfractype     /* previous fractal type */
  775.     )
  776. {
  777.    int ret,oldhelpmode;
  778.  
  779.    oldhelpmode = helpmode;
  780.    ret = 0;
  781.    fractype = newfractype;
  782.    curfractalspecific = &fractalspecific[fractype];
  783.  
  784.    if (fractype == LSYSTEM) {
  785.       helpmode = HT_LSYS;
  786.       if (get_file_entry(GETLSYS,"L-System",lsysmask,LFileName,LName) < 0) {
  787.      ret = 1;
  788.      goto sel_type_exit;
  789.      }
  790.       }
  791.    if (fractype == FORMULA || fractype == FFORMULA) {
  792.       helpmode = HT_FORMULA;
  793.       if (get_file_entry(GETFORMULA,"Formula",formmask,FormFileName,FormName) < 0) {
  794.      ret = 1;
  795.      goto sel_type_exit;
  796.      }
  797.       }
  798.    if (fractype == IFS || fractype == IFS3D) {
  799. static char far ifsmsg[] = {"\
  800. Current IFS parameters have been edited but not saved.\n\
  801. Continue to replace them with new selection, cancel to keep them."};
  802.       helpmode = HT_IFS;
  803.       if (!ifs_defn || !ifs_changed || !stopmsg(22,ifsmsg))
  804.      if (get_file_entry(GETIFS,"IFS",ifsmask,IFSFileName,IFSName) < 0) {
  805.         ret = 1;
  806.         goto sel_type_exit;
  807.         }
  808.       }
  809.  
  810.    set_default_parms();
  811.  
  812.    if (get_fract_params(0) < 0)
  813.       ret = 1;
  814.    else {
  815.       if (newfractype != oldfractype) {
  816.      invert = 0;
  817.      inversion[0] = inversion[1] = inversion[2] = 0;
  818.      }
  819.       }
  820.  
  821. sel_type_exit:
  822.    helpmode = oldhelpmode;
  823.    return(ret);
  824.  
  825. }
  826.  
  827. static void set_default_parms()
  828. {
  829.    int i;
  830.    xxmin = curfractalspecific->xmin;
  831.    xxmax = curfractalspecific->xmax;
  832.    yymin = curfractalspecific->ymin;
  833.    yymax = curfractalspecific->ymax;
  834.    xx3rd = xxmin;
  835.    yy3rd = yymin;
  836.    if (viewcrop && finalaspectratio != SCREENASPECT)
  837.       aspectratio_crop(SCREENASPECT,finalaspectratio);
  838.    for (i = 0; i < 4; i++) {
  839.       param[i] = curfractalspecific->paramvalue[i];
  840.       roundfloatd(¶m[i]);
  841.       }
  842. }
  843.  
  844.  
  845. /* --------------------------------------------------------------------- */
  846.  
  847. int get_fract_params(int caller)    /* prompt for type-specific parms */
  848. {
  849.    int i,j,k;
  850.    int curtype,numparams,numtrig;
  851.    struct fullscreenvalues paramvalues[12];
  852.    char *choices[12];
  853.    int oldbailout;
  854.    int promptnum;
  855.    char msg[120];
  856.    char *typename, *tmpptr;
  857.    char bailoutmsg[50];
  858.    int ret = 0;
  859.    int oldhelpmode;
  860.    static char *trg[] = {"First Function","Second Function",
  861.              "Third Function","Fourth Function"};
  862.    extern char dstack[4096];
  863.    char *filename,*entryname;
  864.    FILE *entryfile;
  865.    char *trignameptr[25];
  866.  
  867.    ENTER_OVLY(OVLY_PROMPTS);
  868.  
  869.    curtype = fractype;
  870.    if (curfractalspecific->name[0] == '*'
  871.      && (i = fractalspecific->tofloat) != NOFRACTAL
  872.      && fractalspecific[i].name[0] != '*')
  873.       curtype = i;
  874.    curfractalspecific = &fractalspecific[curtype];
  875.  
  876.    if (curtype == IFS || curtype == IFS3D) {
  877.       ret = ((caller) ? edit_ifs_params() : 0);
  878.       goto gfp_exit;
  879.       }
  880.  
  881.    if (*(typename = curfractalspecific->name) == '*')
  882.       ++typename;
  883.  
  884.    for (numparams = 0; numparams < 4; numparams++) {
  885.       if (curfractalspecific->param[numparams][0] == 0) break;
  886.       choices[numparams] = curfractalspecific->param[numparams];
  887.       paramvalues[numparams].type = 'd';
  888.       paramvalues[numparams].uval.dval = param[numparams];
  889.       }
  890.  
  891.    numtrig = (curfractalspecific->flags >> 6) & 7;
  892.    if(curtype==FORMULA || curtype==FFORMULA ) {
  893.       extern char maxfn;
  894.       numtrig = maxfn;
  895.       }
  896.    promptnum = numparams;
  897.  
  898.    if ((i = numtrigfn) > 25) i = 25;
  899.    while (--i >= 0)
  900.       trignameptr[i] = trigfn[i].name;
  901.    for (i = 0; i < numtrig; i++) {
  902.       paramvalues[promptnum].type = 'l';
  903.       paramvalues[promptnum].uval.ch.val  = trigndx[i];
  904.       paramvalues[promptnum].uval.ch.llen = numtrigfn;
  905.       paramvalues[promptnum].uval.ch.vlen = 6;
  906.       paramvalues[promptnum].uval.ch.list = trignameptr;
  907.       choices[promptnum] = trg[i];
  908.       ++promptnum;
  909.       }
  910.  
  911.    if (curfractalspecific->orbit_bailout)
  912.       if (potparam[0] != 0.0 && potparam[2] != 0.0) {
  913.      paramvalues[promptnum].type = '*';
  914.      choices[promptnum] = "Bailout: continuous potential (Y screen) value in use";
  915.      ++promptnum;
  916.      }
  917.       else {
  918.      choices[promptnum] = "Bailout value (0 means use default)";
  919.      paramvalues[promptnum].type = 'i';
  920.      paramvalues[promptnum].uval.ival = oldbailout = bailout;
  921.      ++promptnum;
  922.      paramvalues[promptnum].type = '*';
  923.      i = curfractalspecific->orbit_bailout;
  924.      tmpptr = typename;
  925.      if (usr_biomorph != -1) {
  926.         i = 100;
  927.         tmpptr = "biomorph";
  928.         }
  929.      sprintf(bailoutmsg,"    (%s default is %d)",tmpptr,i);
  930.      choices[promptnum] = bailoutmsg;
  931.      ++promptnum;
  932.      }
  933.  
  934.    if (caller                /* <z> command ? */
  935.       && (display3d > 0 || promptnum == 0)) {
  936.        static char far msg[]={"Current type has no type-specific parameters"};
  937.        stopmsg(20,msg);
  938.        goto gfp_exit;
  939.        }
  940.  
  941.    /* note: max of 9 prompt lines now, plus hdgs & instr of course */
  942.  
  943.    dstack[0] = 0;
  944.    if ((i = curfractalspecific->helpformula) < -1) {
  945.       if (i == -2) { /* special for formula */
  946.      filename = FormFileName;
  947.      entryname = FormName;
  948.      }
  949.       else {     /* -3, special for lsystem */
  950.      filename = LFileName;
  951.      entryname = LName;
  952.      }
  953.       if (find_file_item(filename,entryname,&entryfile) == 0) {
  954.      load_entry_text(entryfile,dstack,16);
  955.      fclose(entryfile);
  956.      }
  957.       }
  958.    else if (i >= 0) {
  959.       int c,lines;
  960.       if (i = read_help_topic(i,0,2000,dstack) > 0) i = 0;
  961.       dstack[2000-i] = 0;
  962.       i = j = lines = 0; k = 1;
  963.       while ((c = dstack[i++])) {
  964.      /* stop at ctl, blank, or line with col 1 nonblank, max 16 lines */
  965.      if (k && c == ' ' && ++k <= 5) { } /* skip 4 blanks at start of line */
  966.      else {
  967.         if (c == '\n') {
  968.            if (k) break; /* blank line */
  969.            if (++lines >= 16) break;
  970.            k = 1;
  971.            }
  972.         else if (c < 16) /* a special help format control char */
  973.            break;
  974.         else {
  975.            if (k == 1) /* line starts in column 1 */
  976.           break;
  977.            k = 0;
  978.            }
  979.         dstack[j++] = c;
  980.         }
  981.      }
  982.       while (--j >= 0 && dstack[j] == '\n') { }
  983.       dstack[j+1] = 0;
  984.       }
  985.  
  986.    sprintf(msg,
  987.        "Parameters for fractal type %s\n(Press F6 for corner parameters)",
  988.        typename);
  989.    while (1) {
  990.       oldhelpmode = helpmode;
  991.       helpmode = curfractalspecific->helptext;
  992.       i = fullscreen_prompt(msg,promptnum,choices,paramvalues,0,0x40,dstack);
  993.       helpmode = oldhelpmode;
  994.       if (i < 0) {
  995.      if (ret == 0)
  996.         ret = -1;
  997.      goto gfp_exit;
  998.      }
  999.       if (i != F6) break;
  1000.       if (get_corners() > 0)
  1001.      ret = 1;
  1002.       }
  1003.  
  1004.    for ( i = 0; i < numparams; i++) {
  1005.       if (param[i] != paramvalues[i].uval.dval) {
  1006.      param[i] = paramvalues[i].uval.dval;
  1007.      ret = 1;
  1008.      }
  1009.       }
  1010.  
  1011.    for ( i = 0; i < numtrig; i++) {
  1012.       j = numparams + i;
  1013.       if (paramvalues[j].uval.ch.val != trigndx[i]) {
  1014.      set_trig_array(i,trigfn[paramvalues[j].uval.ch.val].name);
  1015.      ret = 1;
  1016.      }
  1017.       }
  1018.  
  1019.    if ((potparam[0] == 0.0 || potparam[2] == 0.0)
  1020.      && curfractalspecific->orbit_bailout) {
  1021.       bailout = paramvalues[numparams+numtrig].uval.ival;
  1022.       if (bailout != 0 && (bailout < 4 || bailout > 32000))
  1023.      bailout = oldbailout;
  1024.       if (bailout != oldbailout)
  1025.      ret = 1;
  1026.       }
  1027.  
  1028. gfp_exit:
  1029.    curfractalspecific = &fractalspecific[fractype];
  1030.    EXIT_OVLY;
  1031.    return(ret);
  1032. }
  1033.  
  1034. /* --------------------------------------------------------------------- */
  1035.  
  1036.    static FILE *gfe_file;
  1037.  
  1038. static long get_file_entry(int type,char *title,char *fmask,
  1039.               char *filename,char *entryname)
  1040. {
  1041.    /* Formula, LSystem, etc type structure, select from file */
  1042.    /* containing definitions in the form    name { ... }     */
  1043.    int newfile,firsttry;
  1044.    long entry_pointer;
  1045.    extern char dstack[4096];
  1046.    newfile = 0;
  1047.    while (1) {
  1048.       firsttry = 0;
  1049.       /* pb: binary mode used here - it is more work, but much faster, */
  1050.       /*     especially when ftell or fgetpos is used               */
  1051.       while (newfile || (gfe_file = fopen(filename, "rb")) == NULL) {
  1052.      char buf[60];
  1053.      newfile = 0;
  1054.      if (firsttry) {
  1055.         sprintf(temp1,"I Can't find %s", filename);
  1056.         stopmsg(0,temp1);
  1057.         }
  1058.      sprintf(buf,"Select %s File",title);
  1059.      if (getafilename(buf,fmask,filename) < 0)
  1060.         return -1;
  1061.      firsttry = 1; /* if around open loop again it is an error */
  1062.      }
  1063.       setvbuf(gfe_file,dstack,_IOFBF,4096); /* improves speed when file is big */
  1064.       newfile = 0;
  1065.       if ((entry_pointer = gfe_choose_entry(type,title,filename,entryname)) == -2) {
  1066.      newfile = 1; /* go to file list, */
  1067.      continue;    /* back to getafilename */
  1068.      }
  1069.       if (entry_pointer == -1)
  1070.      return -1;
  1071.       switch (type) {
  1072.      case GETFORMULA:
  1073.         if (RunForm(entryname) == 0) return 0;
  1074.         break;
  1075.      case GETLSYS:
  1076.         if (LLoad() == 0) return 0;
  1077.         break;
  1078.      case GETIFS:
  1079.         if (ifsload() == 0) {
  1080.            fractype = (ifs_type == 0) ? IFS : IFS3D;
  1081.            curfractalspecific = &fractalspecific[fractype];
  1082.            set_default_parms(); /* to correct them if 3d */
  1083.            return 0;
  1084.            }
  1085.         break;
  1086.      case GETPARM:
  1087.         return entry_pointer;
  1088.      }
  1089.       }
  1090. }
  1091.  
  1092.    struct entryinfo {
  1093.       char name[ITEMNAMELEN+1];
  1094.       long point; /* points to the ( or the { following the name */
  1095.       };
  1096.    static struct entryinfo **gfe_choices; /* for format_getparm_line */
  1097.    static char *gfe_title;
  1098.  
  1099. static long gfe_choose_entry(int type,char *title,char *filename,char *entryname)
  1100. /* subrtn of get_file_entry, separated so that storage gets freed up */
  1101. {
  1102. #define MAXENTRIES 200
  1103.    int numentries, i;
  1104.    char buf[101];
  1105.    struct entryinfo *choices[MAXENTRIES];
  1106.    int attributes[MAXENTRIES];
  1107.    void (*formatitem)();
  1108.    int boxwidth,boxdepth,colwidth;
  1109.    long file_offset,name_offset;
  1110.    extern struct entryinfo boxx[MAXENTRIES];
  1111.  
  1112.    gfe_choices = &choices[0];
  1113.    gfe_title = title;
  1114.    for (i = 0; i < MAXENTRIES; i++) {
  1115.       attributes[i] = 1;
  1116.       choices[i] = &boxx[i];
  1117.       }
  1118.    numentries = 0;
  1119.    file_offset = -1;
  1120.  
  1121.    helptitle(); /* to display a clue when file big and next is slow */
  1122.  
  1123.    while (1) { /* scan the file for entry names */
  1124.       int c,len;
  1125.       do {
  1126.      ++file_offset;
  1127.      c = getc(gfe_file);
  1128.      } while (c == ' ' /* skip white space */
  1129.            || c == '\t' || c == '\n' || c == '\r');
  1130.       if (c == ';') {
  1131.      do {
  1132.         ++file_offset;
  1133.         c = getc(gfe_file);
  1134.         } while (c != '\n' && c != EOF && c != '\x1a');
  1135.      if (c == EOF || c == '\x1a') break;
  1136.      continue;
  1137.      }
  1138.       name_offset = file_offset;
  1139.       len = 0; /* next equiv roughly to fscanf(..,"%40[^ \n\r\t({\x1a]",buf) */
  1140.       while (c != ' ' && c != '\t' && c != '('
  1141.     && c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  1142.      if (len < 40) buf[len++] = c;
  1143.      c = getc(gfe_file);
  1144.      ++file_offset;
  1145.      }
  1146.       buf[len] = 0;
  1147.       while (c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  1148.      c = getc(gfe_file);
  1149.      ++file_offset;
  1150.      }
  1151.       if (c == '{') {
  1152.      while (c != '}' && c != EOF && c != '\x1a') {
  1153.         c = getc(gfe_file);
  1154.         ++file_offset;
  1155.         }
  1156.      if (c != '}') break;
  1157.      buf[ITEMNAMELEN] = 0;
  1158.      if (buf[0] != 0 && stricmp(buf,"comment") != 0) {
  1159.         strcpy(boxx[numentries].name,buf);
  1160.         boxx[numentries].point = name_offset;
  1161.         if (++numentries >= MAXENTRIES) {
  1162.            sprintf(buf,"Too many entries in file, first %d used",MAXENTRIES);
  1163.            stopmsg(0,buf);
  1164.            break;
  1165.            }
  1166.         }
  1167.      }
  1168.       else
  1169.      if (c == EOF || c == '\x1a') break;
  1170.       }
  1171.  
  1172.    if (numentries == 0) {
  1173.       static char far msg[]={"File doesn't contain any valid entries"};
  1174.       stopmsg(0,msg);
  1175.       fclose(gfe_file);
  1176.       return -2; /* back to file list */
  1177.       }
  1178.  
  1179.    qsort((char **)choices,numentries,sizeof(char *),lccompare);
  1180.  
  1181.    strcpy(buf,entryname); /* preset to last choice made */
  1182.    sprintf(temp1,"%s Selection\nFile: %s",title,filename);
  1183.    formatitem = NULL;
  1184.    boxwidth = colwidth = boxdepth = 0;
  1185.    if (type == GETPARM) {
  1186.       formatitem = format_parmfile_line;
  1187.       boxwidth = 1;
  1188.       boxdepth = 16;
  1189.       colwidth = 76;
  1190.       }
  1191.    i = fullscreen_choice(8,temp1,NULL,
  1192.       "Press F6 to select different file, F2 for details of highlighted choice",
  1193.                numentries,(char **)choices,attributes,
  1194.                boxwidth,boxdepth,colwidth,0,
  1195.                formatitem,buf,NULL,check_gfe_key);
  1196.    fclose(gfe_file);
  1197.    if (i < 0) {
  1198.       if (i == 0-F6)
  1199.      return -2; /* go back to file list */
  1200.       return -1;    /* cancel */
  1201.       }
  1202.    strcpy(entryname, choices[i]->name);
  1203.    return(choices[i]->point);
  1204. }
  1205.  
  1206. static int check_gfe_key(int curkey,int choice)
  1207. {
  1208.    char infhdg[60];
  1209.    char far *infbuf;
  1210.  
  1211.    if (curkey == F6)
  1212.       return 0-F6;
  1213.    if (curkey == F2) {
  1214.       infbuf = MK_FP(extraseg,0);
  1215.       fseek(gfe_file,gfe_choices[choice]->point,SEEK_SET);
  1216.       load_entry_text(gfe_file,infbuf,16);
  1217.       strcpy(infhdg,gfe_title);
  1218.       strcat(infhdg," file entry:\n\n");
  1219.  /* ... instead, call help with buffer?  heading added */
  1220.       stackscreen();
  1221.       helptitle();
  1222.       setattr(1,0,C_GENERAL_MED,24*80);
  1223.       putstring(2,1,C_GENERAL_HI,infhdg);
  1224.       textcbase = 2; /* left margin is 2 */
  1225.       putstring(-1,0,C_GENERAL_MED,infbuf);
  1226.       putstring(-1,0,C_GENERAL_LO,"\n\n\nPress any key to return to selection list");
  1227.       textcbase = 0;
  1228.       movecursor(25,80);
  1229.       getakeynohelp();
  1230.       unstackscreen();
  1231.       }
  1232.    return 0;
  1233. }
  1234.  
  1235. static void load_entry_text(FILE *entfile,char far *buf,int maxlines)
  1236. {
  1237.    int linect,linelen,c;
  1238.    linect = linelen = 0;
  1239.    while ((c = fgetc(entfile)) != EOF && c != '\x1a') {
  1240.       if (c != '\r') {
  1241.      if (c == '\t') {
  1242.         while ((linelen % 8) != 7 && linelen < 75) { /* 76 wide max */
  1243.            *(buf++) = ' ';
  1244.            ++linelen;
  1245.            }
  1246.         c = ' ';
  1247.         }
  1248.      if (c == '\n') {
  1249.         if (++linect > maxlines) break;
  1250.         linelen = -1;
  1251.         }
  1252.      if (++linelen > 75) {
  1253.         if (linelen == 76) *(buf++) = '\x11';
  1254.         }
  1255.      else
  1256.         *(buf++) = c;
  1257.      if (c == '}') break;
  1258.      }
  1259.       }
  1260.    *buf = 0;
  1261. }
  1262.  
  1263. static void format_parmfile_line(int choice,char *buf)
  1264. {
  1265.    int c,i;
  1266.    char line[80];
  1267.    fseek(gfe_file,gfe_choices[choice]->point,SEEK_SET);
  1268.    while (getc(gfe_file) != '{') { }
  1269.    while ((c = getc(gfe_file)) == ' ' || c == '\t' || c == ';') { }
  1270.    i = 0;
  1271.    while (i < 56 && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  1272.       line[i++] = (c == '\t') ? ' ' : c;
  1273.       c = getc(gfe_file);
  1274.       }
  1275.    line[i] = 0;
  1276.    sprintf(buf,"%-20s%-56s",gfe_choices[choice]->name,line);
  1277. }
  1278.  
  1279. /* --------------------------------------------------------------------- */
  1280.  
  1281. int get_fract3d_params() /* prompt for 3D fractal parameters */
  1282. {
  1283.    int i,k,ret,oldhelpmode;
  1284. static char *ifs3d_prompts[] = {
  1285.    "X-axis rotation in degrees",
  1286.    "Y-axis rotation in degrees",
  1287.    "Z-axis rotation in degrees",
  1288.    "Perspective distance [1 - 999, 0 for no persp]",
  1289.    "X shift with perspective (positive = right)",
  1290.    "Y shift with perspective (positive = up   )",
  1291.    "Stereo (R/B 3D)? (0=no,1=alternate,2=superimpose,3=photo)",
  1292.    ""
  1293.    };
  1294.    struct fullscreenvalues uvalues[20];
  1295.  
  1296.    ENTER_OVLY(OVLY_PROMPTS);
  1297.    stackscreen();
  1298.  
  1299.    k = 0;
  1300.    uvalues[k].type = 'i';
  1301.    uvalues[k++].uval.ival = XROT;
  1302.    uvalues[k].type = 'i';
  1303.    uvalues[k++].uval.ival = YROT;
  1304.    uvalues[k].type = 'i';
  1305.    uvalues[k++].uval.ival = ZROT;
  1306.    uvalues[k].type = 'i';
  1307.    uvalues[k++].uval.ival = ZVIEWER;
  1308.    uvalues[k].type = 'i';
  1309.    uvalues[k++].uval.ival = XSHIFT;
  1310.    uvalues[k].type = 'i';
  1311.    uvalues[k++].uval.ival = YSHIFT;
  1312.    uvalues[k].type = 'i';
  1313.    uvalues[k++].uval.ival = glassestype;
  1314.  
  1315.    oldhelpmode = helpmode;
  1316.    helpmode = HELP3DFRACT;
  1317.    i = fullscreen_prompt("3D Parameters",k,ifs3d_prompts,uvalues,0,0,NULL);
  1318.    helpmode = oldhelpmode;
  1319.    if (i < 0) {
  1320.       ret = -1;
  1321.       goto get_f3d_exit;
  1322.       }
  1323.  
  1324.    ret = k = 0;
  1325.    XROT    =  uvalues[k++].uval.ival;
  1326.    YROT    =  uvalues[k++].uval.ival;
  1327.    ZROT    =  uvalues[k++].uval.ival;
  1328.    ZVIEWER =  uvalues[k++].uval.ival;
  1329.    XSHIFT  =  uvalues[k++].uval.ival;
  1330.    YSHIFT  =  uvalues[k++].uval.ival;
  1331.    glassestype = uvalues[k++].uval.ival;
  1332.    if (glassestype < 0 || glassestype > 3) glassestype = 0;
  1333.    if (glassestype)
  1334.       if (get_funny_glasses_params() || check_mapfile())
  1335.      ret = -1;
  1336.  
  1337. get_f3d_exit:
  1338.    unstackscreen();
  1339.    EXIT_OVLY;
  1340.    return(ret);
  1341. }
  1342.  
  1343. /* --------------------------------------------------------------------- */
  1344.  
  1345. int get_3d_params()    /* prompt for 3D parameters */
  1346. {
  1347.    char *choices[10];
  1348.    int attributes[21];
  1349.    int sphere;
  1350.    char *s;
  1351.    char *prompts3d[21];
  1352.    struct fullscreenvalues uvalues[21];
  1353.    int i, k;
  1354.    int oldhelpmode;
  1355.  
  1356.    ENTER_OVLY(OVLY_PROMPTS);
  1357.  
  1358. restart_1:
  1359.  
  1360.    k=-1;
  1361.  
  1362.    prompts3d[++k]= "Preview Mode?";
  1363.    uvalues[k].type = 'y';
  1364.    uvalues[k].uval.ch.val = preview;
  1365.  
  1366.    prompts3d[++k]= "    Show Box?";
  1367.    uvalues[k].type = 'y';
  1368.    uvalues[k].uval.ch.val = showbox;
  1369.  
  1370.    prompts3d[++k]= "Coarseness, preview/grid/ray (in y dir)";
  1371.    uvalues[k].type = 'i';
  1372.    uvalues[k].uval.ival = previewfactor;
  1373.  
  1374.    prompts3d[++k]= "Spherical Projection?";
  1375.    uvalues[k].type = 'y';
  1376.    uvalues[k].uval.ch.val = sphere = SPHERE;
  1377.  
  1378.    prompts3d[++k]= "Stereo (R/B 3D)? (0=no,1=alternate,2=superimpose,3=photo)";
  1379.    uvalues[k].type = 'i';
  1380.    uvalues[k].uval.ival = glassestype;
  1381.  
  1382.    prompts3d[++k]= "Ray trace out? (0=No, 1=DKB/STAR, 2=VIVID, 3=RAW,";
  1383.    uvalues[k].type = 'i';
  1384.    uvalues[k].uval.ival = RAY;
  1385.    prompts3d[++k]= "                4=MTV, 5=RAYSHADE, 6=ACROSPIN)";
  1386.    uvalues[k].type = '*';
  1387.  
  1388.    prompts3d[++k]= "    Brief output?";
  1389.    uvalues[k].type = 'y';
  1390.    uvalues[k].uval.ch.val = BRIEF;
  1391.  
  1392.    check_writefile(ray_name,".ray");
  1393.    prompts3d[++k]= "    Output File Name";
  1394.    uvalues[k].type = 's';
  1395.    strcpy(uvalues[k].uval.sval,ray_name);
  1396.  
  1397.    oldhelpmode = helpmode;
  1398.    helpmode = HELP3DMODE;
  1399.  
  1400.    k = fullscreen_prompt("3D Mode Selection",k+1,prompts3d,uvalues,0,0,NULL);
  1401.    helpmode = oldhelpmode;
  1402.    if (k < 0) {
  1403.       EXIT_OVLY;
  1404.       return(-1);
  1405.       }
  1406.  
  1407.    k=0;
  1408.  
  1409.    preview = uvalues[k++].uval.ch.val;
  1410.  
  1411.    showbox = uvalues[k++].uval.ch.val;
  1412.  
  1413.    previewfactor  = uvalues[k++].uval.ival;
  1414.  
  1415.    sphere = uvalues[k++].uval.ch.val;
  1416.  
  1417.    glassestype = uvalues[k++].uval.ival;
  1418.  
  1419.    RAY = uvalues[k++].uval.ival;
  1420.    k++;
  1421.  
  1422.    BRIEF = uvalues[k++].uval.ch.val;
  1423.  
  1424.    strcpy(ray_name,uvalues[k++].uval.sval);
  1425.  
  1426.    /* check ranges */
  1427.    if(previewfactor < 2)
  1428.       previewfactor = 2;
  1429.    if(previewfactor > 2000)
  1430.       previewfactor = 2000;
  1431.  
  1432.    if(sphere && !SPHERE)
  1433.    {
  1434.       SPHERE = TRUE;
  1435.       set_3d_defaults();
  1436.    }
  1437.    else if(!sphere && SPHERE)
  1438.    {
  1439.       SPHERE = FALSE;
  1440.       set_3d_defaults();
  1441.    }
  1442.  
  1443.    if(glassestype < 0)
  1444.       glassestype = 0;
  1445.    if(glassestype > 3)
  1446.       glassestype = 3;
  1447.    if(glassestype)
  1448.       whichimage = 1;
  1449.  
  1450.    if (RAY < 0)
  1451.       RAY = 0;
  1452.    if (RAY > 6)
  1453.       RAY = 6;
  1454.  
  1455.    if (!RAY)
  1456.    {
  1457.       k=0;
  1458.       choices[k++] = "make a surface grid";
  1459.       choices[k++] = "just draw the points";
  1460.       choices[k++] = "connect the dots (wire frame)";
  1461.       choices[k++] = "surface fill (colors interpolated)";
  1462.       choices[k++] = "surface fill (colors not interpolated)";
  1463.       choices[k++] = "solid fill (bars up from \"ground\")";
  1464.       if(SPHERE)
  1465.      choices[k++] = "light source";
  1466.       else
  1467.       {
  1468.      choices[k++] = "light source before transformation";
  1469.      choices[k++] = "light source after transformation";
  1470.       }
  1471.  
  1472.       for (i = 0; i < k; ++i)
  1473.      attributes[i] = 1;
  1474.       helpmode = HELP3DFILL;
  1475.       i = fullscreen_choice(CHOICEHELP,"Select 3D Fill Type",NULL,NULL,
  1476.                   k,choices,attributes,
  1477.                   0,0,0,FILLTYPE+1,NULL,NULL,NULL,NULL);
  1478.       helpmode = oldhelpmode;
  1479.       if (i < 0)
  1480.      goto restart_1;
  1481.       FILLTYPE = i-1;
  1482.  
  1483.       if(glassestype)
  1484.       {
  1485.      if(get_funny_glasses_params())
  1486.         goto restart_1;
  1487.       }
  1488.  
  1489.       if (check_mapfile())
  1490.      goto restart_1;
  1491.    }
  1492.  
  1493. restart_3:
  1494.  
  1495.    if(SPHERE)
  1496.    {
  1497.       prompts3d[0] = "Longitude start (degrees)";
  1498.       prompts3d[1] = "Longitude stop  (degrees)";
  1499.       prompts3d[2] = "Latitude start  (degrees)";
  1500.       prompts3d[3] = "Latitude stop   (degrees)";
  1501.       prompts3d[4] = "Radius scaling factor in pct";
  1502.    }
  1503.    else
  1504.    {
  1505.       i = 0;
  1506.       if (!RAY)
  1507.       {
  1508.      prompts3d[i++] = "X-axis rotation in degrees";
  1509.      prompts3d[i++] = "Y-axis rotation in degrees";
  1510.      prompts3d[i++] = "Z-axis rotation in degrees";
  1511.       }
  1512.       prompts3d[i++] = "X-axis scaling factor in pct";
  1513.       prompts3d[i++] = "Y-axis scaling factor in pct";
  1514.    }
  1515.    k = 0;
  1516.    if (!RAY)
  1517.    {
  1518.       uvalues[k].uval.ival   = XROT     ;
  1519.       uvalues[k++].type = 'i';
  1520.       uvalues[k].uval.ival   = YROT     ;
  1521.       uvalues[k++].type = 'i';
  1522.       uvalues[k].uval.ival   = ZROT     ;
  1523.       uvalues[k++].type = 'i';
  1524.    }
  1525.    uvalues[k].uval.ival   = XSCALE    ;
  1526.    uvalues[k++].type = 'i';
  1527.    uvalues[k].uval.ival   = YSCALE    ;
  1528.    uvalues[k++].type = 'i';
  1529.    prompts3d[k] = "Surface Roughness scaling factor in pct";
  1530.    uvalues[k].type = 'i';
  1531.    uvalues[k++].uval.ival = ROUGH     ;
  1532.  
  1533.    prompts3d[k]= "'Water Level' (minimum color value)";
  1534.    uvalues[k].type = 'i';
  1535.    uvalues[k++].uval.ival = WATERLINE ;
  1536.  
  1537.    if(!RAY)
  1538.    {
  1539.       prompts3d[k]= "Perspective distance [1 - 999, 0 for no persp]";
  1540.       uvalues[k].type = 'i';
  1541.       uvalues[k++].uval.ival = ZVIEWER     ;
  1542.  
  1543.    prompts3d[k]= "X shift with perspective (positive = right)";
  1544.    uvalues[k].type = 'i';
  1545.    uvalues[k++].uval.ival = XSHIFT    ;
  1546.  
  1547.    prompts3d[k]= "Y shift with perspective (positive = up   )";
  1548.    uvalues[k].type = 'i';
  1549.    uvalues[k++].uval.ival = YSHIFT    ;
  1550.  
  1551.    prompts3d[k]= "Image non-perspective X adjust (positive = right)";
  1552.    uvalues[k].type = 'i';
  1553.    uvalues[k++].uval.ival = xtrans    ;
  1554.  
  1555.    prompts3d[k]= "Image non-perspective Y adjust (positive = up)";
  1556.    uvalues[k].type = 'i';
  1557.    uvalues[k++].uval.ival = ytrans    ;
  1558.  
  1559.    prompts3d[k]= "First transparent color";
  1560.    uvalues[k].type = 'i';
  1561.    uvalues[k++].uval.ival = transparent[0];
  1562.  
  1563.    prompts3d[k]= "Last transparent color";
  1564.    uvalues[k].type = 'i';
  1565.    uvalues[k++].uval.ival = transparent[1];
  1566.    }
  1567.  
  1568.    prompts3d[k]= "Randomize Colors      (0 - 7, '0' disables)";
  1569.    uvalues[k].type = 'i';
  1570.    uvalues[k++].uval.ival = RANDOMIZE;
  1571.  
  1572.    if (ILLUMINE && !RAY)
  1573.    {
  1574.     prompts3d[k]= "Color/Mono Images With Light Source   (1 = Color)";
  1575.     uvalues[k].type = 'i';
  1576.     uvalues[k++].uval.ival = full_color;
  1577.    }
  1578.  
  1579.    if (SPHERE)
  1580.       s = "              Sphere 3D Parameters\n\
  1581. Sphere is on its side; North pole to right\n\
  1582. Long. 180 is top, 0 is bottom; Lat. -90 is left, 90 is right";
  1583.    else
  1584.       s = "              Planar 3D Parameters\n\
  1585. Pre-rotation X axis is screen top; Y axis is left side\n\
  1586. Pre-rotation Z axis is coming at you out of the screen!";
  1587.  
  1588.    helpmode = HELP3DPARMS;
  1589.    k = fullscreen_prompt(s,k,prompts3d,uvalues,0,0,NULL);
  1590.    helpmode = oldhelpmode;
  1591.    if (k < 0)
  1592.       goto restart_1;
  1593.  
  1594.    k = 0;
  1595.    if (!RAY)
  1596.    {
  1597.       XROT    = uvalues[k++].uval.ival;
  1598.       YROT    = uvalues[k++].uval.ival;
  1599.       ZROT    = uvalues[k++].uval.ival;
  1600.    }
  1601.    XSCALE     = uvalues[k++].uval.ival;
  1602.    YSCALE     = uvalues[k++].uval.ival;
  1603.    ROUGH      = uvalues[k++].uval.ival;
  1604.    WATERLINE  = uvalues[k++].uval.ival;
  1605.    if (!RAY)
  1606.    {
  1607.       ZVIEWER = uvalues[k++].uval.ival;
  1608.    XSHIFT     = uvalues[k++].uval.ival;
  1609.    YSHIFT     = uvalues[k++].uval.ival;
  1610.    xtrans     = uvalues[k++].uval.ival;
  1611.    ytrans     = uvalues[k++].uval.ival;
  1612.    transparent[0] = uvalues[k++].uval.ival;
  1613.    transparent[1] = uvalues[k++].uval.ival;
  1614.    }
  1615.    RANDOMIZE  = uvalues[k++].uval.ival;
  1616.    if (RANDOMIZE >= 7) RANDOMIZE = 7;
  1617.    if (RANDOMIZE <= 0) RANDOMIZE = 0;
  1618.  
  1619.    if (ILLUMINE && !RAY)
  1620.    {
  1621.     full_color = uvalues[k++].uval.ival;
  1622.     if(get_light_params())
  1623.         goto restart_3;
  1624.    }
  1625.  
  1626. EXIT_OVLY;
  1627. return(0);
  1628. }
  1629.  
  1630. /* --------------------------------------------------------------------- */
  1631. static int get_light_params()
  1632. {
  1633.    char *prompts3d[10];
  1634.    struct fullscreenvalues uvalues[10];
  1635.  
  1636.    int k;
  1637.    int oldhelpmode;
  1638.  
  1639.    /* defaults go here */
  1640.  
  1641.    k = -1;
  1642.    prompts3d[++k]= "X value light vector";
  1643.    uvalues[k].type = 'i';
  1644.    uvalues[k].uval.ival = XLIGHT    ;
  1645.  
  1646.    prompts3d[++k]= "Y value light vector";
  1647.    uvalues[k].type = 'i';
  1648.    uvalues[k].uval.ival = YLIGHT    ;
  1649.  
  1650.    prompts3d[++k]= "Z value light vector";
  1651.    uvalues[k].type = 'i';
  1652.    uvalues[k].uval.ival = ZLIGHT    ;
  1653.  
  1654.    prompts3d[++k]= "Light Source Smoothing Factor";
  1655.    uvalues[k].type = 'i';
  1656.    uvalues[k].uval.ival = LIGHTAVG  ;
  1657.  
  1658.    prompts3d[++k]= "Ambient Light      (0 - 100, '0' = 'Black' shadows";
  1659.    uvalues[k].type = 'i';
  1660.    uvalues[k].uval.ival = Ambient;
  1661.  
  1662.    if (full_color)
  1663.    {
  1664.     prompts3d[++k]    = "Haze Factor        (0 - 100, '0' disables)";
  1665.     uvalues[k].type = 'i';
  1666.     uvalues[k].uval.ival= haze;
  1667.  
  1668.     check_writefile(light_name,".tga");
  1669.     prompts3d[++k]= "Full Color Light File Name";
  1670.     uvalues[k].type = 's';
  1671.     strcpy(uvalues[k].uval.sval,light_name);
  1672.    }
  1673.  
  1674.    prompts3d[++k]= "";
  1675.  
  1676.    oldhelpmode = helpmode;
  1677.    helpmode = HELP3DLIGHT;
  1678.    k = fullscreen_prompt("Light Source Parameters",k,prompts3d,uvalues,0,0,NULL);
  1679.    helpmode = oldhelpmode;
  1680.    if (k < 0)
  1681.       return(-1);
  1682.  
  1683.    k = 0;
  1684.       XLIGHT   = uvalues[k++].uval.ival;
  1685.       YLIGHT   = uvalues[k++].uval.ival;
  1686.       ZLIGHT   = uvalues[k++].uval.ival;
  1687.       LIGHTAVG = uvalues[k++].uval.ival;
  1688.       Ambient  = uvalues[k++].uval.ival;
  1689.       if (Ambient >= 100) Ambient = 100;
  1690.       if (Ambient <= 0) Ambient = 0;
  1691.    if (full_color)
  1692.    {
  1693.     haze  =  uvalues[k++].uval.ival;
  1694.     if (haze >= 100) haze = 100;
  1695.     if (haze <= 0) haze = 0;
  1696.     strcpy(light_name,uvalues[k].uval.sval);
  1697.    }
  1698.    return(0);
  1699. }
  1700.  
  1701. /* --------------------------------------------------------------------- */
  1702.  
  1703.  
  1704. static int check_mapfile()
  1705. {
  1706.    extern unsigned char dacbox[256][3];
  1707.    extern unsigned char olddacbox[256][3];
  1708.    int askflag = 0;
  1709.    int i,oldhelpmode;
  1710.    strcpy(temp1,"*");
  1711.    if (mapset)
  1712.       strcpy(temp1,MAP_name);
  1713.    if (glassestype == 0 || glassestype == 3)
  1714.       askflag = 1;
  1715.    else
  1716.       strcpy(temp1,funnyglasses_map_name);
  1717.    while ((FILLTYPE >= 5) || overlay3d || (mapset == 1) || glassestype) {
  1718.       if (askflag) {
  1719.      oldhelpmode = helpmode;
  1720.      helpmode = -1;
  1721.      i = field_prompt(0,"\
  1722. Enter name of .MAP file to use,\n\
  1723. or '*' to use palette from the image about to be loaded.",
  1724.          NULL,temp1,60,NULL);
  1725.      helpmode = oldhelpmode;
  1726.      if (i < 0)
  1727.         return(-1);
  1728.      if (temp1[0] == '*') {
  1729.         mapset = 0;
  1730.         break;
  1731.         }
  1732.      }
  1733.       memcpy(olddacbox,dacbox,256*3); /* save the DAC */
  1734.       i = ValidateLuts(temp1);
  1735.       memcpy(dacbox,olddacbox,256*3); /* restore the DAC */
  1736.       if (i != 0) { /* Oops, somethings wrong */
  1737.      askflag = 1;
  1738.      continue;
  1739.      }
  1740.       mapset = 1;
  1741.       strcpy (MAP_name,temp1);
  1742.       break;
  1743.       }
  1744.    return(0);
  1745. }
  1746.  
  1747. static int get_funny_glasses_params()
  1748. {
  1749.    char *prompts3d[10];
  1750.  
  1751.    struct fullscreenvalues uvalues[10];
  1752.  
  1753.    int k;
  1754.    int oldhelpmode;
  1755.  
  1756.    /* defaults */
  1757.    if(ZVIEWER == 0)
  1758.       ZVIEWER = 150;
  1759.    if(eyeseparation == 0)
  1760.    {
  1761.       if(fractype==IFS3D || fractype==LLORENZ3D || fractype==FPLORENZ3D)
  1762.       {
  1763.      eyeseparation =  2;
  1764.      xadjust       = -2;
  1765.       }
  1766.       else
  1767.       {
  1768.      eyeseparation =  3;
  1769.      xadjust       =  0;
  1770.       }
  1771.    }
  1772.  
  1773.    if(glassestype == 1)
  1774.       strcpy(funnyglasses_map_name,"glasses1.map");
  1775.    else if(glassestype == 2)
  1776.    {
  1777.       if(FILLTYPE == -1)
  1778.      strcpy(funnyglasses_map_name,"grid.map");
  1779.       else
  1780.      strcpy(funnyglasses_map_name,"glasses2.map");
  1781.    }
  1782.  
  1783.    k = -1;
  1784.    prompts3d[++k]  = "Interocular distance (as % of screen)";
  1785.    uvalues[k].type = 'i';
  1786.    uvalues[k].uval.ival= eyeseparation;
  1787.  
  1788.    prompts3d[++k]= "Convergence adjust (positive = spread greater)";
  1789.    uvalues[k].type = 'i';
  1790.    uvalues[k].uval.ival = xadjust;
  1791.  
  1792.    prompts3d[++k]= "Left  red image crop (% of screen)";
  1793.    uvalues[k].type = 'i';
  1794.    uvalues[k].uval.ival = red_crop_left;
  1795.  
  1796.    prompts3d[++k]= "Right red image crop (% of screen)";
  1797.    uvalues[k].type = 'i';
  1798.    uvalues[k].uval.ival = red_crop_right;
  1799.  
  1800.    prompts3d[++k]= "Left  blue image crop (% of screen)";
  1801.    uvalues[k].type = 'i';
  1802.    uvalues[k].uval.ival = blue_crop_left;
  1803.  
  1804.    prompts3d[++k]= "Right blue image crop (% of screen)";
  1805.    uvalues[k].type = 'i';
  1806.    uvalues[k].uval.ival = blue_crop_right;
  1807.  
  1808.    prompts3d[++k]= "Red brightness factor (%)";
  1809.    uvalues[k].type = 'i';
  1810.    uvalues[k].uval.ival = red_bright;
  1811.  
  1812.    prompts3d[++k]= "Blue brightness factor (%)";
  1813.    uvalues[k].type = 'i';
  1814.    uvalues[k].uval.ival = blue_bright;
  1815.  
  1816.    if(glassestype == 1 || glassestype == 2)
  1817.    {
  1818.       prompts3d[++k]= "Map File name";
  1819.       uvalues[k].type = 's';
  1820.       strcpy(uvalues[k].uval.sval,funnyglasses_map_name);
  1821.    }
  1822.  
  1823.    oldhelpmode = helpmode;
  1824.    helpmode = HELP3DGLASSES;
  1825.    k = fullscreen_prompt("Funny Glasses Parameters",k+1,prompts3d,uvalues,0,0,NULL);
  1826.    helpmode = oldhelpmode;
  1827.    if (k < 0)
  1828.       return(-1);
  1829.  
  1830.    k = 0;
  1831.    eyeseparation   =  uvalues[k++].uval.ival;
  1832.    xadjust       =  uvalues[k++].uval.ival;
  1833.    red_crop_left   =  uvalues[k++].uval.ival;
  1834.    red_crop_right  =  uvalues[k++].uval.ival;
  1835.    blue_crop_left  =  uvalues[k++].uval.ival;
  1836.    blue_crop_right =  uvalues[k++].uval.ival;
  1837.    red_bright       =  uvalues[k++].uval.ival;
  1838.    blue_bright       =  uvalues[k++].uval.ival;
  1839.  
  1840.    if(glassestype == 1 || glassestype == 2)
  1841.       strcpy(funnyglasses_map_name,uvalues[k].uval.sval);
  1842.    return(0);
  1843. }
  1844.  
  1845. /* --------------------------------------------------------------------- */
  1846.  
  1847. static int edit_ifs_params()    /* prompt for IFS params */
  1848. {
  1849.    int totcols;
  1850.    int i, j, k, numlines, ret;
  1851.    FILE *tempfile;
  1852.    char msg[81];
  1853.    char filename[81];
  1854.    float ftemp;
  1855.    int oldhelpmode;
  1856.  
  1857.    if (!ifs_defn && !ifsload())
  1858.       return(-1);
  1859.  
  1860.    totcols = (ifs_type == 0) ? IFSPARM : IFS3DPARM;
  1861.    ret = 0;
  1862.    oldhelpmode = helpmode;
  1863.    helpmode = HT_IFS;
  1864.  
  1865.    for ( ;; ) {
  1866. static char far ifshdg2[]={"2D IFS Parameters"};
  1867. static char far ifshdg3[]={"3D IFS Parameters"};
  1868. static char far ifsparmmsg1[]={"#    a     b     c     d     e     f"};
  1869. static char far ifsparmmsg2[]={"     g     h     i     j     k     l"};
  1870. static char far ifsprompt[]={"\
  1871. Enter the number of the line you want to edit,\n\
  1872. S to save your edits in a file, or ENTER to end ==>"};
  1873.       int leftcol,promptrow,promptcol;
  1874.  
  1875.       for (numlines = 0; numlines < NUMIFS; numlines++) /* find the first zero entry */
  1876.      if (ifs_defn[(numlines * totcols) + totcols - 1] <= 0.0001) break;
  1877.  
  1878.       helptitle();
  1879.       setattr(1,0,C_PROMPT_BKGRD,24*80); /* init rest of screen to background */
  1880.       putstringcenter(2,0,80,C_GENERAL_HI,(ifs_type == 0) ? ifshdg2 : ifshdg3);
  1881.       leftcol = (ifs_type == 0) ? 15 : 0;
  1882.       putstring(4,leftcol+1,C_GENERAL_HI,ifsparmmsg1);
  1883.       if (ifs_type != 0)
  1884.      putstring(-1,-1,C_GENERAL_HI,ifsparmmsg2);
  1885.       putstring(-1,-1,C_GENERAL_HI,"   prob \n\n");
  1886.  
  1887.       if ((k = numlines) > 12) k = 12;
  1888.       for (i = 0; i < k; i++) {
  1889.      sprintf(msg,"%2d", i+1);
  1890.      putstring(5+i,leftcol,C_GENERAL_HI,msg);
  1891.      for (j = 0; j < totcols; j++) {
  1892.         sprintf(msg,"%6.2f",ifs_defn[(i*totcols)+j]);
  1893.         putstring(-1,-1,C_GENERAL_MED,msg);
  1894.         }
  1895.      }
  1896.  
  1897.       textcbase = 14;
  1898.       putstring(5+i+1,0,C_GENERAL_HI,ifsprompt);
  1899.       promptrow = textrow;
  1900.       promptcol = textcol + textcbase + 1;
  1901.       temp1[0] = textcbase = 0;
  1902.       if (input_field(0,C_GENERAL_INPUT,temp1,2,promptrow,promptcol,NULL) < 0
  1903.     || temp1[0] == 0)
  1904.      break; /* ESCAPE or ENTER */
  1905.  
  1906.       putstring(promptrow,promptcol,C_GENERAL_HI,temp1);
  1907.       if (temp1[0] == 's' || temp1[0] == 'S') {
  1908.      stackscreen();
  1909.      i = field_prompt(0,"Enter the name of the .IFS file to save:",
  1910.              NULL,filename,60,NULL);
  1911.      unstackscreen();
  1912.      if (i != -1) {
  1913.         if (strchr(filename,'.') == NULL)
  1914.            strcat(filename,".ifs");
  1915.         if ((tempfile=fopen(filename,"w")) != NULL) {
  1916.            for (i = 0; i < numlines; i++) {
  1917.           for (j = 0; j < totcols; j++)
  1918.              fprintf(tempfile, "%6.2f", (float)ifs_defn[(i*totcols)+j]);
  1919.           fprintf(tempfile, "\n");
  1920.           }
  1921.            fclose(tempfile);
  1922.            ifs_changed = 0;
  1923.            }
  1924.         else {
  1925.            static char far msg[]={"Could not create file"};
  1926.            stopmsg(0,msg);
  1927.            }
  1928.         }
  1929.      continue;
  1930.      }
  1931.       i = atoi(temp1) - 1;
  1932.       if (i >= 0 && i <= numlines) {
  1933.      for (j = 0; j < totcols; j++) {
  1934.         if (j < totcols-1)
  1935.            sprintf(msg,"Parameter %c",'a'+j);
  1936.         else
  1937.            sprintf(msg,"Probability");
  1938.         putstring(promptrow+2,25,C_GENERAL_HI,msg);
  1939.         sprintf(temp1,"%6.2f",(float)ifs_defn[k=(i*totcols)+j]);
  1940.         if (input_field(1,C_GENERAL_INPUT,temp1,6,
  1941.                 textrow,textcol+1,NULL) < 0)
  1942.            break;
  1943.         if (ifs_defn[k] != (ftemp = atof(temp1))) {
  1944.            ifs_defn[k] = ftemp;
  1945.            ret = ifs_changed = 1;
  1946.            }
  1947.         }
  1948.      memset(msg,' ',80); msg[81] = 0;
  1949.      putstring(promptrow+2,0,C_PROMPT_BKGRD,msg);
  1950.      }
  1951.       }
  1952.  
  1953.    helpmode = oldhelpmode;
  1954.    return(ret);
  1955. }
  1956.  
  1957. /* --------------------------------------------------------------------- */
  1958. /*
  1959.     get_toggles() is called from FRACTINT.C whenever the 'x' key
  1960.     is pressed.  This routine prompts for several options,
  1961.     sets the appropriate variables, and returns the following code
  1962.     to the calling routine:
  1963.  
  1964.     -1  routine was ESCAPEd - no need to re-generate the image.
  1965.      0  nothing changed, or minor variable such as "overwrite=".
  1966.         No need to re-generate the image.
  1967.      1  major variable changed (such as "inside=").  Re-generate
  1968.         the image.
  1969.  
  1970.     Finally, remember to insert variables in the list *and* check
  1971.     for them in the same order!!!
  1972. */
  1973.  
  1974. int get_toggles()
  1975. {
  1976.    char *choices[20];
  1977.    int oldhelpmode;
  1978.    char prevsavename[81];
  1979.    struct fullscreenvalues uvalues[25];
  1980.    int i, j, k;
  1981.    char old_usr_stdcalcmode;
  1982.    int old_maxit,old_inside,old_outside,old_soundflag;
  1983.    int old_logflag,old_biomorph,old_decomp;
  1984.  
  1985.    static char *calcmodes[4] ={"1","2","g","b"};
  1986.    static char *soundmodes[5]={"yes","no","x","y","z"};
  1987.  
  1988.    ENTER_OVLY(OVLY_PROMPTS);
  1989.  
  1990.    k = -1;
  1991.  
  1992.    k++;
  1993.    choices[k] =  "Passes (1, 2, g[uessing], or b[oundary trace])";
  1994.    uvalues[k].type = 'l';
  1995.    uvalues[k].uval.ch.vlen = 3;
  1996.    uvalues[k].uval.ch.llen = 4;
  1997.    uvalues[k].uval.ch.list = calcmodes;
  1998.    uvalues[k].uval.ch.val = (usr_stdcalcmode == '1') ? 0
  1999.               : (usr_stdcalcmode == '2') ? 1
  2000.               : (usr_stdcalcmode == 'g') ? 2 : 3;
  2001.    old_usr_stdcalcmode = usr_stdcalcmode;
  2002.  
  2003.    k++;
  2004.    choices[k] =  "Floating Point Algorithm";
  2005.    uvalues[k].type = 'y';
  2006.    uvalues[k].uval.ch.val = usr_floatflag;
  2007.  
  2008.    k++;
  2009.    choices[k] = "Maximum Iterations (2 to 32767)";
  2010.    uvalues[k].type = 'i';
  2011.    uvalues[k].uval.ival = old_maxit = maxit;
  2012.  
  2013.    k++;
  2014.    choices[k] = "Inside Color (<nnn>, maxiter, zmag, bof60, bof61)";
  2015.    uvalues[k].type = 's';
  2016.    if(inside == -59)
  2017.       strcpy(uvalues[k].uval.sval,s_zmag);
  2018.    else if(inside == -60)
  2019.       strcpy(uvalues[k].uval.sval,s_bof60);
  2020.    else if(inside == -61)
  2021.       strcpy(uvalues[k].uval.sval,s_bof61);
  2022.    else if(inside == -1)
  2023.       strcpy(uvalues[k].uval.sval,s_maxiter);
  2024.    else
  2025.       sprintf(uvalues[k].uval.sval,"%d",inside);
  2026.    old_inside = inside;
  2027.  
  2028.    k++;
  2029.    choices[k] = "Outside Color (<nnn>,iter,real,imag,mult,summ)";
  2030.    uvalues[k].type = 's';
  2031.    if(outside == -1)
  2032.       strcpy(uvalues[k].uval.sval,s_iter);
  2033.    else if(outside == -2)
  2034.       strcpy(uvalues[k].uval.sval,s_real);
  2035.    else if(outside == -3)
  2036.       strcpy(uvalues[k].uval.sval,s_imag);
  2037.    else if(outside == -4)
  2038.       strcpy(uvalues[k].uval.sval,s_mult);
  2039.    else if(outside == -5)
  2040.       strcpy(uvalues[k].uval.sval,s_sum);
  2041.    else
  2042.       sprintf(uvalues[k].uval.sval,"%d",outside);
  2043.    old_outside = outside;
  2044.  
  2045.    k++;
  2046.    choices[k] = "Savename (.GIF implied)";
  2047.    uvalues[k].type = 's';
  2048.    strcpy(prevsavename,savename);
  2049.    strcpy(uvalues[k].uval.sval,savename);
  2050.  
  2051.    k++;
  2052.    choices[k] = "File Overwrite ('overwrite=')";
  2053.    uvalues[k].type = 'y';
  2054.    uvalues[k].uval.ch.val = overwrite;
  2055.  
  2056.    k++;
  2057.    choices[k] = "Sound (no, yes, x, y, z)";
  2058.    uvalues[k].type = 'l';
  2059.    uvalues[k].uval.ch.vlen = 3;
  2060.    uvalues[k].uval.ch.llen = 5;
  2061.    uvalues[k].uval.ch.list = soundmodes;
  2062.    uvalues[k].uval.ch.val = 1 + (old_soundflag = soundflag);
  2063.  
  2064.    k++;
  2065.    if (rangeslen == 0) {
  2066.       choices[k] = "Log Palette (0=no,1=yes,-1=old,+n=cmprsd,-n=sqrt)";
  2067.       uvalues[k].type = 'i';
  2068.       }
  2069.    else {
  2070.       choices[k] = "Log Palette (n/a, ranges= parameter is in effect)";
  2071.       uvalues[k].type = '*';
  2072.       }
  2073.    uvalues[k].uval.ival = old_logflag = LogFlag;
  2074.  
  2075.    k++;
  2076.    choices[k] = "Biomorph Color (-1 means OFF)";
  2077.    uvalues[k].type = 'i';
  2078.    uvalues[k].uval.ival = old_biomorph = usr_biomorph;
  2079.  
  2080.    k++;
  2081.    choices[k] = "Decomp Option (2,4,8,..,256, 0=OFF)";
  2082.    uvalues[k].type = 'i';
  2083.    uvalues[k].uval.ival = old_decomp = decomp[0];
  2084.  
  2085.    k++;
  2086.    choices[k] = "Antialiasing (0 to 8)";
  2087.    uvalues[k].type = 'i';
  2088.    uvalues[k].uval.ival = AntiAliasing;
  2089.  
  2090.    oldhelpmode = helpmode;
  2091.    helpmode = HELPXOPTS;
  2092.    i = fullscreen_prompt("        Basic Options\n"
  2093.              "(not all combinations make sense)",
  2094.      k+1,choices,uvalues,0,0,NULL);
  2095.    helpmode = oldhelpmode;
  2096.    if (i < 0) {
  2097.       EXIT_OVLY;
  2098.       return(-1);
  2099.       }
  2100.  
  2101.    /* now check out the results (*hopefully* in the same order <grin>) */
  2102.    k = -1;
  2103.    j = 0;   /* return code */
  2104.  
  2105.    usr_stdcalcmode = calcmodes[uvalues[++k].uval.ch.val][0];
  2106.    if (old_usr_stdcalcmode != usr_stdcalcmode) j = 1;
  2107.  
  2108.    if (uvalues[++k].uval.ch.val != usr_floatflag) {
  2109.       usr_floatflag = uvalues[k].uval.ch.val;
  2110.       j = 1;
  2111.       }
  2112.  
  2113.    ++k;
  2114.    maxit = uvalues[k].uval.ival;
  2115.    if (maxit < 2) maxit = 2;
  2116.    if (maxit > 32767) maxit = 32767;
  2117.    if (maxit != old_maxit) j = 1;
  2118.  
  2119.    if(strncmp(strlwr(uvalues[++k].uval.sval),s_zmag,4)==0)
  2120.       inside = -59;
  2121.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_bof60,5)==0)
  2122.       inside = -60;
  2123.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_bof61,5)==0)
  2124.       inside = -61;
  2125.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_maxiter,5)==0)
  2126.       inside = -1;
  2127.    else
  2128.       inside = atoi(uvalues[k].uval.sval);
  2129.    if (inside != old_inside) j = 1;
  2130.  
  2131.    if(strncmp(strlwr(uvalues[++k].uval.sval),s_real,4)==0)
  2132.       outside = -2;
  2133.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_imag,4)==0)
  2134.       outside = -3;
  2135.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_mult,4)==0)
  2136.       outside = -4;
  2137.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_sum,4)==0)
  2138.       outside = -5;
  2139.    else if(strncmp(strlwr(uvalues[k].uval.sval),s_iter,4)==0)
  2140.       outside = -1;
  2141.    else
  2142.       outside = atoi(uvalues[k].uval.sval);
  2143.    if (outside != old_outside) j = 1;
  2144.  
  2145.    strcpy(savename,uvalues[++k].uval.sval);
  2146.    if (strcmp(savename,prevsavename))
  2147.       resave_flag = started_resaves = 0; /* forget pending increment */
  2148.  
  2149.    overwrite = uvalues[++k].uval.ch.val;
  2150.  
  2151.    soundflag = uvalues[++k].uval.ch.val - 1;
  2152.    if (soundflag != old_soundflag && (soundflag > 1 || old_soundflag > 1))
  2153.       j = 1;
  2154.  
  2155.    LogFlag = uvalues[++k].uval.ival;
  2156.    if (LogFlag != old_logflag) j = 1;
  2157.  
  2158.    usr_biomorph = uvalues[++k].uval.ival;
  2159.    if (usr_biomorph != old_biomorph) j = 1;
  2160.  
  2161.    decomp[0] = uvalues[++k].uval.ival;
  2162.    if (decomp[0] != old_decomp) j = 1;
  2163.  
  2164.    ++k;
  2165.    if(AntiAliasing != uvalues[k].uval.ival) j = 1;
  2166.    AntiAliasing = uvalues[k].uval.ival;
  2167.    if(AntiAliasing < 0) AntiAliasing = 0;
  2168.    if(AntiAliasing > 8) AntiAliasing = 8;
  2169.  
  2170.    EXIT_OVLY;
  2171.    return(j);
  2172. }
  2173.  
  2174. /*
  2175.     get_toggles2() is similar to get_toggles, invoked by 'y' key
  2176. */
  2177.  
  2178. int get_toggles2()
  2179. {
  2180.    char *choices[20];
  2181.    int oldhelpmode;
  2182.  
  2183.    struct fullscreenvalues uvalues[25];
  2184.    int i, j, k;
  2185.  
  2186.    int old_rotate_lo,old_rotate_hi;
  2187.    int old_usr_distest,old_distestwidth;
  2188.    double old_potparam[3],old_inversion[3];
  2189.  
  2190.    ENTER_OVLY(OVLY_PROMPTS);
  2191.  
  2192.    /* fill up the choices (and previous values) arrays */
  2193.    k = -1;
  2194.  
  2195.    k++;
  2196.    choices[k] = "Look for finite attractor";
  2197.    uvalues[k].type = 'y';
  2198.    uvalues[k].uval.ch.val = finattract;
  2199.  
  2200.    k++;
  2201.    choices[k] = "Potential Max Color (0 means off)";
  2202.    uvalues[k].type = 'i';
  2203.    uvalues[k].uval.ival = old_potparam[0] = potparam[0];
  2204.  
  2205.    k++;
  2206.    choices[k] = "          Slope";
  2207.    uvalues[k].type = 'i';
  2208.    uvalues[k].uval.ival = old_potparam[1] = potparam[1];
  2209.  
  2210.    k++;
  2211.    choices[k] = "          Bailout";
  2212.    uvalues[k].type = 'i';
  2213.    uvalues[k].uval.ival = old_potparam[2] = potparam[2];
  2214.  
  2215.    k++;
  2216.    choices[k] = "          16 bit values";
  2217.    uvalues[k].type = 'y';
  2218.    uvalues[k].uval.ch.val = pot16bit;
  2219.  
  2220.    k++;
  2221.    choices[k] = "Distance Estimator (0=off, <0=edge, >0=on):";
  2222.    uvalues[k].type = 'i';
  2223.    uvalues[k].uval.ival = old_usr_distest = usr_distest;
  2224.    k++;
  2225.    choices[k] = "          width factor:";
  2226.    uvalues[k].type = 'i';
  2227.    uvalues[k].uval.ival = old_distestwidth = distestwidth;
  2228.  
  2229.    choices[k+1] = "Inversion radius or \"auto\" (0 means off)";
  2230.    choices[k+2] = "          center X coordinate or \"auto\"";
  2231.    choices[k+3] = "          center Y coordinate or \"auto\"";
  2232.    for (i = 0; i < 3; i++) {
  2233.       uvalues[++k].type = 's';
  2234.       if ((old_inversion[i] = inversion[i]) == AUTOINVERT)
  2235.      sprintf(uvalues[k].uval.sval,"auto");
  2236.       else
  2237.      sprintf(uvalues[k].uval.sval,"%g",inversion[i]);
  2238.       }
  2239.    k++;
  2240.    choices[k] = "  (use fixed radius & center when zooming)",
  2241.    uvalues[k].type = '*';
  2242.  
  2243.    k++;
  2244.    choices[k] = "Color cycling from color (0 ... 254)";
  2245.    uvalues[k].type = 'i';
  2246.    uvalues[k].uval.ival = old_rotate_lo = rotate_lo;
  2247.    k++;
  2248.    choices[k] = "              to   color (1 ... 255)";
  2249.    uvalues[k].type = 'i';
  2250.    uvalues[k].uval.ival = old_rotate_hi = rotate_hi;
  2251.  
  2252.    oldhelpmode = helpmode;
  2253.    helpmode = HELPYOPTS;
  2254.    i = fullscreen_prompt("       Extended Doodads\n"
  2255.              "(not all combinations make sense)",
  2256.      k+1,choices,uvalues,0,0,NULL);
  2257.    helpmode = oldhelpmode;
  2258.    if (i < 0) {
  2259.       EXIT_OVLY;
  2260.       return(-1);
  2261.       }
  2262.  
  2263.    /* now check out the results (*hopefully* in the same order <grin>) */
  2264.    k = -1;
  2265.    j = 0;   /* return code */
  2266.  
  2267.    if (uvalues[++k].uval.ch.val != finattract) {
  2268.       finattract = uvalues[k].uval.ch.val;
  2269.       j = 1;
  2270.       }
  2271.  
  2272.    potparam[0] = uvalues[++k].uval.ival;
  2273.    if (potparam[0] != old_potparam[0]) j = 1;
  2274.  
  2275.    potparam[1] = uvalues[++k].uval.ival;
  2276.    if (potparam[0] != 0.0 && potparam[1] != old_potparam[1]) j = 1;
  2277.  
  2278.    potparam[2] = uvalues[++k].uval.ival;
  2279.    if (potparam[0] != 0.0 && potparam[2] != old_potparam[2]) j = 1;
  2280.  
  2281.    if (uvalues[++k].uval.ch.val != pot16bit) {
  2282.       pot16bit = uvalues[k].uval.ch.val;
  2283.       if (pot16bit) { /* turned it on */
  2284.      if (potparam[0] != 0.0) j = 1;
  2285.      }
  2286.       else /* turned it off */
  2287.      if (dotmode != 11) /* ditch the disk video */
  2288.         enddisk();
  2289.      else /* keep disk video, but ditch the fraction part at end */
  2290.         disk16bit = 0;
  2291.       }
  2292.  
  2293.    ++k;
  2294.    usr_distest = (uvalues[k].uval.ival > 32000) ? 32000 : uvalues[k].uval.ival;
  2295.    if (usr_distest != old_usr_distest) j = 1;
  2296.    ++k;
  2297.    distestwidth = uvalues[k].uval.ival;
  2298.    if (usr_distest && distestwidth != old_distestwidth) j = 1;
  2299.  
  2300.    for (i = 0; i < 3; i++) {
  2301.       if (uvalues[++k].uval.sval[0] == 'a' || uvalues[k].uval.sval[0] == 'A')
  2302.      inversion[i] = AUTOINVERT;
  2303.       else
  2304.      inversion[i] = atof(uvalues[k].uval.sval);
  2305.       if (old_inversion[i] != inversion[i]
  2306.     && (i == 0 || inversion[0] != 0.0))
  2307.      j = 1;
  2308.       }
  2309.    invert = (inversion[0] == 0.0) ? 0 : 3;
  2310.    ++k;
  2311.  
  2312.    rotate_lo = uvalues[++k].uval.ival;
  2313.    rotate_hi = uvalues[++k].uval.ival;
  2314.    if (rotate_lo < 0 || rotate_hi > 255 || rotate_lo > rotate_hi) {
  2315.       rotate_lo = old_rotate_lo;
  2316.       rotate_hi = old_rotate_hi;
  2317.       }
  2318.  
  2319.    EXIT_OVLY;
  2320.    return(j);
  2321. }
  2322.  
  2323. /* --------------------------------------------------------------------- */
  2324. /*
  2325.     get_view_params() is called from FRACTINT.C whenever the 'v' key
  2326.     is pressed.  Return codes are:
  2327.     -1  routine was ESCAPEd - no need to re-generate the image.
  2328.      0  minor variable changed.  No need to re-generate the image.
  2329.      1  View changed.  Re-generate the image.
  2330. */
  2331.  
  2332. int get_view_params()
  2333. {
  2334.    char *choices[20];
  2335.    int oldhelpmode;
  2336.    struct fullscreenvalues uvalues[25];
  2337.    int i, k;
  2338.    float old_viewreduction,old_aspectratio;
  2339.    int old_viewwindow,old_viewcrop,old_viewxdots,old_viewydots;
  2340.  
  2341.    ENTER_OVLY(OVLY_PROMPTS);
  2342.    stackscreen();
  2343.  
  2344.    old_viewwindow    = viewwindow;
  2345.    old_viewcrop      = viewcrop;
  2346.    old_viewreduction = viewreduction;
  2347.    old_aspectratio   = finalaspectratio;
  2348.    old_viewxdots     = viewxdots;
  2349.    old_viewydots     = viewydots;
  2350.  
  2351. get_view_restart:
  2352.    /* fill up the choices (and previous values) arrays */
  2353.    k = -1;
  2354.  
  2355.    k++;
  2356.    choices[k] = "Preview display? (no for full screen)";
  2357.    uvalues[k].type = 'y';
  2358.    uvalues[k].uval.ch.val = viewwindow;
  2359.  
  2360.    k++;
  2361.    choices[k] = "Auto window size reduction factor";
  2362.    uvalues[k].type = 'f';
  2363.    uvalues[k].uval.dval = viewreduction;
  2364.  
  2365.    k++;
  2366.    choices[k] = "Final media overall aspect ratio, y/x";
  2367.    uvalues[k].type = 'f';
  2368.    uvalues[k].uval.dval = finalaspectratio;
  2369.  
  2370.    k++;
  2371.    choices[k] = "Crop starting coordinates to new aspect ratio?";
  2372.    uvalues[k].type = 'y';
  2373.    uvalues[k].uval.ch.val = viewcrop;
  2374.  
  2375.    k++;
  2376.    choices[k] = "explicit size x pixels (0 for auto size)";
  2377.    uvalues[k].type = 'i';
  2378.    uvalues[k].uval.ival = viewxdots;
  2379.    k++;
  2380.    choices[k] = "              y pixels (0 to base on aspect ratio)";
  2381.    uvalues[k].type = 'i';
  2382.    uvalues[k].uval.ival = viewydots;
  2383.  
  2384.    k++;
  2385.    choices[k] = "";
  2386.    uvalues[k].type = '*';
  2387.    k++;
  2388.    choices[k] = "Press F4 to reset view parameters to defaults.";
  2389.    uvalues[k].type = '*';
  2390.  
  2391.    oldhelpmode = helpmode;     /* this prevents HELP from activating */
  2392.    helpmode = HELPVIEW;
  2393.    i = fullscreen_prompt("View Window Options",k+1,choices,uvalues,0,16,NULL);
  2394.    helpmode = oldhelpmode;     /* re-enable HELP */
  2395.    if (i < 0) {
  2396.       viewwindow    = old_viewwindow;
  2397.       viewcrop        = old_viewcrop;
  2398.       viewreduction = old_viewreduction;
  2399.       finalaspectratio = old_aspectratio;
  2400.       viewxdots     = old_viewxdots;
  2401.       viewydots     = old_viewydots;
  2402.       unstackscreen();
  2403.       EXIT_OVLY;
  2404.       return(-1);
  2405.       }
  2406.  
  2407.    if (i == F4) {
  2408.       viewwindow = viewxdots = viewydots = 0;
  2409.       viewreduction = 4.2;
  2410.       viewcrop = 1;
  2411.       finalaspectratio = SCREENASPECT;
  2412.       goto get_view_restart;
  2413.       }
  2414.  
  2415.    /* now check out the results (*hopefully* in the same order <grin>) */
  2416.    k = -1;
  2417.  
  2418.    viewwindow = uvalues[++k].uval.ch.val;
  2419.  
  2420.    viewreduction = uvalues[++k].uval.dval;
  2421.  
  2422.    if ((finalaspectratio = uvalues[++k].uval.dval) == 0)
  2423.       finalaspectratio = SCREENASPECT;
  2424.  
  2425.    viewcrop = uvalues[++k].uval.ch.val;
  2426.  
  2427.    viewxdots = uvalues[++k].uval.ival;
  2428.    viewydots = uvalues[++k].uval.ival;
  2429.  
  2430.    if (finalaspectratio != old_aspectratio && viewcrop)
  2431.       aspectratio_crop(old_aspectratio,finalaspectratio);
  2432.  
  2433.    i = 0;
  2434.    if (viewwindow != old_viewwindow
  2435.       || (viewwindow
  2436.      && (  viewreduction != old_viewreduction
  2437.         || finalaspectratio != old_aspectratio
  2438.         || viewxdots != old_viewxdots
  2439.         || (viewydots != old_viewydots && viewxdots) ) ) )
  2440.       i = 1;
  2441.  
  2442.    unstackscreen();
  2443.    EXIT_OVLY;
  2444.    return(i);
  2445. }
  2446.  
  2447.  
  2448. /* --------------------------------------------------------------------- */
  2449.  
  2450. int Distribution = 30, Offset = 0, Slope = 25;
  2451. long con;
  2452.  
  2453. static char *starfield_prompts[4] = {
  2454.     "Star Density in Pixels per Star",
  2455.     "Percent Clumpiness",
  2456.     "Ratio of Dim stars to Bright",
  2457.     ""
  2458.     };
  2459. static double starfield_values[4] = {
  2460.     30.0,100.0,25.0,0.0
  2461.     };
  2462.  
  2463. int get_starfield_params(void) {
  2464.    static char StarMap[] = "altern.map";
  2465.    int i, c;
  2466.    struct fullscreenvalues uvalues[3];
  2467.    int oldhelpmode;
  2468.  
  2469.    ENTER_OVLY(OVLY_PROMPTS);
  2470.  
  2471.    if(colors < 255) {
  2472.       static char far msg[]={"starfield requires 256 color mode"};
  2473.       stopmsg(0,msg);
  2474.       EXIT_OVLY;
  2475.       return(-1);
  2476.    }
  2477.    for (i = 0; i < 3; i++) {
  2478.       uvalues[i].uval.dval = starfield_values[i];
  2479.       uvalues[i].type = 'f';
  2480.    }
  2481.    stackscreen();
  2482.    oldhelpmode = helpmode;
  2483.    helpmode = HELPSTARFLD;
  2484.    i = fullscreen_prompt("Starfield Parameters",
  2485.              3,starfield_prompts,uvalues,0,0,NULL);
  2486.    helpmode = oldhelpmode;
  2487.    if (i < 0) {
  2488.       unstackscreen();
  2489.       EXIT_OVLY;
  2490.       return(-1);
  2491.       }
  2492.    unstackscreen();
  2493.  
  2494.    for (i = 0; i < 3; i++)
  2495.       starfield_values[i] = uvalues[i].uval.dval;
  2496.  
  2497.    if (starfield_values[0] <   1.0) starfield_values[0] =   1.0;
  2498.    if (starfield_values[0] > 100.0) starfield_values[0] = 100.0;
  2499.    if (starfield_values[1] <   1.0) starfield_values[1] =   1.0;
  2500.    if (starfield_values[1] > 100.0) starfield_values[1] = 100.0;
  2501.    if (starfield_values[2] <   1.0) starfield_values[2] =   1.0;
  2502.    if (starfield_values[2] > 100.0) starfield_values[2] = 100.0;
  2503.  
  2504.    Distribution = (int)(starfield_values[0]);
  2505.    con    = (long)(((starfield_values[1]) / 100.0) * (1L << 16));
  2506.    Slope = (int)(starfield_values[2]);
  2507.  
  2508.    if (ValidateLuts(StarMap) != 0) {
  2509.       EXIT_OVLY;
  2510.       return(-1);
  2511.       }
  2512.    spindac(0,1);         /* load it, but don't spin */
  2513.  
  2514.    for(row = 0; row < ydots; row++) {
  2515.       for(col = 0; col < xdots; col++) {
  2516.      if(check_key()) {
  2517.         buzzer(1);
  2518.         EXIT_OVLY;
  2519.         return(1);
  2520.         }
  2521.      c = getcolor(col, row);
  2522.      putcolor(col, row, GausianNumber(c, colors));
  2523.       }
  2524.    }
  2525.    buzzer(0);
  2526.    EXIT_OVLY;
  2527.    return(0);
  2528. }
  2529.  
  2530. /* --------------------------------------------------------------------- */
  2531.  
  2532. int get_commands()        /* execute commands from file */
  2533. {
  2534.    int ret;
  2535.    FILE *parmfile;
  2536.    long point;
  2537.    int oldhelpmode;
  2538.    ENTER_OVLY(OVLY_PROMPTS);
  2539.    ret = 0;
  2540.    oldhelpmode = helpmode;
  2541.    helpmode = HELPPARMFILE;
  2542.    if ((point = get_file_entry(GETPARM,"Parameter Set",
  2543.                    commandmask,CommandFile,CommandName)) >= 0
  2544.      && (parmfile = fopen(CommandFile,"rb"))) {
  2545.       fseek(parmfile,point,SEEK_SET);
  2546.       ret = load_commands(parmfile);
  2547.       }
  2548.    helpmode = oldhelpmode;
  2549.    EXIT_OVLY;
  2550.    return(ret);
  2551. }
  2552.  
  2553. /* --------------------------------------------------------------------- */
  2554.  
  2555. void goodbye()            /* we done.  Bail out */
  2556. {
  2557.    extern unsigned char exitmode;
  2558.    extern int mode7text;
  2559.    extern int made_dsktemp;
  2560.    union REGS r;
  2561.    static char far goodbyemessage[]={"   Thank You for using FRACTINT"};
  2562.    setvideotext();
  2563.    r.h.al = (mode7text == 0) ? exitmode : 7;
  2564.    r.h.ah = 0;
  2565.    int86(0x10, &r, &r);
  2566.    printf("\n\n\n%Fs\n",goodbyemessage); /* printf takes far pointer */
  2567.    movecursor(6,0);
  2568.    discardgraphics(); /* if any emm/xmm tied up there, release it */
  2569.    stopslideshow();
  2570.    if (made_dsktemp)
  2571.       remove("FRACTINT.DSK");
  2572.    end_help();
  2573.    exit(0);
  2574. }
  2575.  
  2576.  
  2577. /* --------------------------------------------------------------------- */
  2578.  
  2579. static int  findfirst(char *path)    /* Find 1st file (or subdir) meeting path/filespec */
  2580. {
  2581.      union REGS regs;
  2582.      regs.h.ah = 0x1A;           /* Set DTA to filedata */
  2583.      regs.x.dx = (unsigned)&DTA;
  2584.      intdos(®s, ®s);
  2585.      regs.h.ah = 0x4E;           /* Find 1st file meeting path */
  2586.      regs.x.dx = (unsigned)path;
  2587.      regs.x.cx = FILEATTR;
  2588.      intdos(®s, ®s);
  2589.      return(regs.x.ax);        /* Return error code */
  2590. }
  2591.  
  2592. static int  findnext()        /* Find next file (or subdir) meeting above path/filespec */
  2593. {
  2594.      union REGS regs;
  2595.      regs.h.ah = 0x4F;           /* Find next file meeting path */
  2596.      regs.x.dx = (unsigned)&DTA;
  2597.      intdos(®s, ®s);
  2598.      return(regs.x.ax);
  2599. }
  2600.  
  2601. static int lccompare(void const *arg1, void const *arg2) /* for qsort */
  2602. {
  2603.    return(strncasecmp(*((char **)arg1),*((char **)arg2),40));
  2604. }
  2605.  
  2606.  
  2607. static char *masks[] = {"*.pot","*.gif"};
  2608. #define FILE_MAX_PATH  80
  2609. #define FILE_MAX_DIR   80
  2610. #define FILE_MAX_DRIVE    3
  2611. #define FILE_MAX_FNAME    9
  2612. #define FILE_MAX_EXT    5
  2613. static int speedstate;
  2614.  
  2615. int getafilename(char *hdg,char *template,char *flname)
  2616. {
  2617.    int masklen;
  2618.    char filename[13];
  2619.    char speedstr[81];
  2620.    char tmpmask[FILE_MAX_PATH];   /* used to locate next file in list */
  2621.    static int numtemplates = 1;
  2622.    int i,j;
  2623.    int out;
  2624.    int retried;
  2625.    struct CHOICE
  2626.    {
  2627.       char name[13];
  2628.       char type;
  2629.    }
  2630.    *choices[MAXNUMFILES];
  2631.    int attributes[MAXNUMFILES];
  2632.    int filecount;   /* how many files */
  2633.    int dircount;    /* how many directories */
  2634.    int notroot;     /* not the root directory */
  2635.  
  2636.    char drive[FILE_MAX_DRIVE];
  2637.    char dir[FILE_MAX_DIR];
  2638.    char fname[FILE_MAX_FNAME];
  2639.    char ext[FILE_MAX_EXT];
  2640.  
  2641.    ENTER_OVLY(OVLY_PROMPTS);
  2642.  
  2643.    /* steal existing array for "choices" */
  2644.    choices[0] = (struct CHOICE *)boxy;
  2645.    attributes[0] = 1;
  2646.    for(i=1;i<MAXNUMFILES;i++)
  2647.    {
  2648.       choices[i] = choices[i-1] + 1;
  2649.       attributes[i] = 1;
  2650.    }
  2651.  
  2652. restart:  /* return here if template or directory changes */
  2653.  
  2654.    tmpmask[0] = 0;
  2655.    if(flname[0] == 0)
  2656.       strcpy(flname,".\\");
  2657.    splitpath(flname ,drive,dir,fname,ext);
  2658.    makepath(filename,""   ,"" ,fname,ext);
  2659.    retried = 0;
  2660. retry_dir:
  2661.    if (dir[0] == 0)
  2662.       strcpy(dir,".");
  2663.    expand_dirname(dir,drive);
  2664.    makepath(tmpmask,drive,dir,"","");
  2665.    fix_dirname(tmpmask);
  2666.    if (retried == 0 && strcmp(dir,"\\") && strcmp(dir,".\\"))
  2667.    {
  2668.       tmpmask[(j = strlen(tmpmask) - 1)] = 0; /* strip trailing \ */
  2669.       if (strchr(tmpmask,'*') || strchr(tmpmask,'?')
  2670.     || findfirst(tmpmask) != 0
  2671.     || (DTA.attribute & SUBDIR) == 0)
  2672.       {
  2673.      strcpy(dir,".\\");
  2674.      ++retried;
  2675.      goto retry_dir;
  2676.       }
  2677.       tmpmask[j] = '\\';
  2678.    }
  2679.    if(template[0])
  2680.    {
  2681.       numtemplates = 1;
  2682.       splitpath(template,NULL,NULL,fname,ext);
  2683.    }
  2684.    else
  2685.       numtemplates = sizeof(masks)/sizeof(masks[0]);
  2686.    filecount = -1;
  2687.    dircount  = 0;
  2688.    notroot   = 0;
  2689.    j = 0;
  2690.    masklen = strlen(tmpmask);
  2691.    strcat(tmpmask,"*.*");
  2692.    out = findfirst(tmpmask);
  2693.    while(out == 0 && filecount < MAXNUMFILES)
  2694.    {
  2695.       if((DTA.attribute & SUBDIR) && strcmp(DTA.filename,"."))
  2696.       {
  2697.      strlwr(DTA.filename);
  2698.      if(strcmp(DTA.filename,".."))
  2699.         strcat(DTA.filename,"\\");
  2700.      strncpy(choices[++filecount]->name,DTA.filename,13);
  2701.      choices[filecount]->type = 1;
  2702.      dircount++;
  2703.      if(strcmp(DTA.filename,"..")==0)
  2704.         notroot = 1;
  2705.       }
  2706.       out = findnext();
  2707.    }
  2708.    tmpmask[masklen] = 0;
  2709.    if(template[0])
  2710.       makepath(tmpmask,drive,dir,fname,ext);
  2711.    do
  2712.    {
  2713.       if(numtemplates > 1)
  2714.      strcpy(&(tmpmask[masklen]),masks[j]);
  2715.       out = findfirst(tmpmask);
  2716.       while(out == 0 && filecount < MAXNUMFILES)
  2717.       {
  2718.      if(!(DTA.attribute & SUBDIR))
  2719.      {
  2720.         strlwr(DTA.filename);
  2721.         strncpy(choices[++filecount]->name,DTA.filename,13);
  2722.         choices[filecount]->type = 0;
  2723.      }
  2724.      out = findnext();
  2725.       }
  2726.    }
  2727.    while (++j < numtemplates);
  2728.    if (++filecount == 0)
  2729.    {
  2730.       strcpy(choices[filecount]->name,"*nofiles*");
  2731.       choices[filecount]->type = 0;
  2732.       ++filecount;
  2733.    }
  2734.    qsort(choices,filecount,sizeof(char *),lccompare); /* sort type list */
  2735.    if(notroot == 0) /* must be in root directory */
  2736.    {
  2737.       splitpath(tmpmask,drive,dir,fname,ext);
  2738.       strcpy(dir,"\\");
  2739.       makepath(tmpmask,drive,dir,fname,ext);
  2740.    }
  2741.    if(numtemplates > 1)
  2742.       strcat(tmpmask," *.pot");
  2743.    strcpy(temp1,hdg);
  2744.    strcat(temp1,"\nTemplate: ");
  2745.    strcat(temp1,tmpmask);
  2746.    strcpy(speedstr,filename);
  2747.    if (speedstr[0] == 0)
  2748.    {
  2749.       for (i=0; i<filecount; i++) /* find first file */
  2750.      if (choices[i]->type == 0)
  2751.         break;
  2752.       if (i >= filecount)
  2753.      i = 0;
  2754.    }
  2755.    i = fullscreen_choice(0,temp1,NULL,NULL,
  2756.              filecount,(char **)choices,attributes,5,99,12,
  2757.              i,NULL,speedstr,filename_speedstr,NULL);
  2758.    if (i < 0)
  2759.    {
  2760.       EXIT_OVLY;
  2761.       return(-1);
  2762.    }
  2763.    if(speedstr[0] == 0 || speedstate == MATCHING)
  2764.    {
  2765.       if(choices[i]->type)
  2766.       {
  2767.      if(strcmp(choices[i]->name,"..") == 0) /* go up a directory */
  2768.      {
  2769.         if(strcmp(dir,".\\") == 0)
  2770.            strcpy(dir,"..\\");
  2771.         else
  2772.         {
  2773.            char *s;
  2774.            if(s = strrchr(dir,'\\')) /* trailing slash */
  2775.            {
  2776.           *s = 0;
  2777.           if(s = strrchr(dir,'\\'))
  2778.              *(s+1) = 0;
  2779.            }
  2780.         }
  2781.      }
  2782.      else  /* go down a directory */
  2783.         strcat(dir,choices[i]->name);
  2784.      fix_dirname(dir);
  2785.      makepath(flname,drive,dir,"","");
  2786.      goto restart;
  2787.       }
  2788.       splitpath(choices[i]->name,NULL,NULL,fname,ext);
  2789.       makepath(flname,drive,dir,fname,ext);
  2790.    }
  2791.    else
  2792.    {
  2793.       if (speedstate == SEARCHPATH
  2794.     && strchr(speedstr,'*') == 0 && strchr(speedstr,'?') == 0
  2795.     && findfirst(speedstr) == 0
  2796.     && (DTA.attribute & SUBDIR)) /* it is a directory */
  2797.      speedstate = TEMPLATE;
  2798.       if(speedstate == TEMPLATE)
  2799.       {
  2800.      /* extract from tempstr the pathname and template information,
  2801.         being careful not to overwrite drive and directory if not
  2802.         newly specified */
  2803.      char drive1[FILE_MAX_DRIVE];
  2804.      char dir1[FILE_MAX_DIR];
  2805.      char fname1[FILE_MAX_FNAME];
  2806.      char ext1[FILE_MAX_EXT];
  2807.      splitpath(speedstr,drive1,dir1,fname1,ext1);
  2808.      if(drive1[0])
  2809.         strcpy(drive,drive1);
  2810.      if(dir1[0])
  2811.         strcpy(dir,dir1);
  2812.      makepath(flname,drive,dir,fname1,ext1);
  2813.      if(strchr(fname1,'*') || strchr(fname1,'?') ||
  2814.          strchr(ext1  ,'*') || strchr(ext1  ,'?'))
  2815.         makepath(template,"","",fname1,ext1);
  2816.      else if(isadirectory(flname))
  2817.         fix_dirname(flname);
  2818.      goto restart;
  2819.       }
  2820.       else /* speedstate == SEARCHPATH */
  2821.       {
  2822.      char fullpath[80];
  2823.       /* if (strchr(speedstr,'.') == NULL)
  2824.         strcat(speedstr,".gif"); */
  2825.      findpath(speedstr,fullpath);
  2826.      if(fullpath[0])
  2827.         strcpy(flname,fullpath);
  2828.      else
  2829.      {  /* failed, make diagnostic useful: */
  2830.         strcpy(flname,speedstr);
  2831.         if (strchr(speedstr,'\\') == NULL)
  2832.         {
  2833.            splitpath(speedstr,NULL,NULL,fname,ext);
  2834.            makepath(flname,drive,dir,fname,ext);
  2835.         }
  2836.      }
  2837.       }
  2838.    }
  2839.    EXIT_OVLY;
  2840.    return(0);
  2841. }
  2842.  
  2843. static int filename_speedstr(int row, int col, int vid,
  2844.                  char *speedstring, int speed_match)
  2845. {
  2846.    extern char speed_prompt[];
  2847.    char *prompt;
  2848.    if ( strchr(speedstring,':')
  2849.      || strchr(speedstring,'*') || strchr(speedstring,'*')
  2850.      || strchr(speedstring,'?')) {
  2851.       speedstate = TEMPLATE;  /* template */
  2852.       prompt = "File Template";
  2853.       }
  2854.    else if (speed_match) {
  2855.       speedstate = SEARCHPATH; /* does not match list */
  2856.       prompt = "Search Path for";
  2857.       }
  2858.    else {
  2859.       speedstate = MATCHING;
  2860.       prompt = speed_prompt;
  2861.       }
  2862.    putstring(row,col,vid,prompt);
  2863.    return(strlen(prompt));
  2864. }
  2865.  
  2866. static int isadirectory(char *s)
  2867. {
  2868.    if(strchr(s,'*') || strchr(s,'?'))
  2869.       return(0); /* for my purposes, not a directory */
  2870.    if(findfirst(s) != 0) /* couldn't find it */
  2871.    {
  2872.       /* any better ideas?? */
  2873.       if(strchr(s,'\\')) /* we'll guess it is a directory */
  2874.      return(1);
  2875.       else
  2876.      return(0);  /* no slashes - we'll guess it's a file */
  2877.    }
  2878.    else if(DTA.attribute & SUBDIR)
  2879.       return(1);   /* we're SURE it's a directory */
  2880.    else
  2881.       return(0);
  2882. }
  2883.  
  2884. static splitpath(char *template,char *drive,char *dir,char *fname,char *ext)
  2885. {
  2886.    int length;
  2887.    int len;
  2888.    int offset;
  2889.    char *tmp;
  2890.  
  2891.    if(drive)
  2892.       drive[0] = 0;
  2893.    if(dir)
  2894.       dir[0]   = 0;
  2895.    if(fname)
  2896.       fname[0] = 0;
  2897.    if(ext)
  2898.       ext[0]   = 0;
  2899.  
  2900.    if((length = strlen(template)) == 0)
  2901.       return(0);
  2902.    offset = 0;
  2903.  
  2904.    /* get drive */
  2905.    if(length >= 2)
  2906.       if(template[1] == ':')
  2907.       {
  2908.      if(drive)
  2909.      {
  2910.         drive[0] = template[offset++];
  2911.         drive[1] = template[offset++];
  2912.         drive[2] = 0;
  2913.      }
  2914.      else
  2915.      {
  2916.         offset++;
  2917.         offset++;
  2918.      }
  2919.       }
  2920.  
  2921.    /* get dir */
  2922.    if(offset < length)
  2923.    {
  2924.       tmp = strrchr(template,'\\');
  2925.       if(tmp)
  2926.       {
  2927.      tmp++;  /* first character after slash */
  2928.      len = tmp - &template[offset];
  2929.      if(len >=0 && len < 80 && dir)
  2930.         strncpy(dir,&template[offset],len);
  2931.      if(len < 80 && dir)
  2932.         dir[len] = 0;
  2933.      offset += len;
  2934.       }
  2935.    }
  2936.    else
  2937.       return(0);
  2938.  
  2939.    /* get fname */
  2940.    if(offset < length)
  2941.    {
  2942.       tmp = strrchr(template,'.');
  2943.       if(tmp < strrchr(template,'\\') || tmp < strrchr(template,':'))
  2944.      tmp = 0; /* in this case the '.' must be a directory */
  2945.       if(tmp)
  2946.       {
  2947.      tmp++; /* first character past "." */
  2948.      len = tmp - &template[offset];
  2949.      if((len > 0) && (offset+len < length) && fname)
  2950.      {
  2951.         strncpy(fname,&template[offset],len);
  2952.         fname[len] = 0;
  2953.      }
  2954.      offset += len;
  2955.      if((offset < length) && ext)
  2956.         strcpy(ext,&template[offset]);
  2957.       }
  2958.       else if((offset < length) && fname)
  2959.      strcpy(fname,&template[offset]);
  2960.    }
  2961.    return(0);
  2962. }
  2963.  
  2964. static makepath(char *template,char *drive,char *dir,char *fname,char *ext)
  2965. {
  2966.    strcpy(template,drive);
  2967.    strcat(template,dir);
  2968.    strcat(template,fname);
  2969.    strcat(template,ext);
  2970.    return(0);
  2971. }
  2972.  
  2973.  
  2974. /* fix up directory names */
  2975. static void fix_dirname(char *dirname)
  2976. {
  2977.    int length;
  2978.    /* scrub white space from end for safety */
  2979.    length = strlen(dirname); /* index of last character */
  2980.    while (--length >= 0 && isspace(dirname[length])) { }
  2981.    dirname[++length] = 0;
  2982.    /* make sure dirname ends with a slash */
  2983.    if(length == 0 || dirname[length-1] != '\\')
  2984.       strcat(dirname,"\\");
  2985. }
  2986.  
  2987. static int expand_dirname(char *dirname,char *drive)
  2988. {
  2989.    fix_dirname(dirname);
  2990.    if (dirname[0] != '\\') {
  2991.       char buf[81],curdir[81];
  2992.       union REGS regs;
  2993.       struct SREGS sregs;
  2994.       curdir[0] = 0;
  2995.       regs.h.ah = 0x47; /* get current directory */
  2996.       regs.h.dl = 0;
  2997.       if (drive[0] && drive[0] != ' ')
  2998.      regs.h.dl = tolower(drive[0])-'a'+1;
  2999.       regs.x.si = (unsigned int) &curdir[0];
  3000.       segread(&sregs);
  3001.       intdosx(®s, ®s, &sregs);
  3002.       strcat(curdir,"\\");
  3003.       while (strncmp(dirname,".\\",2) == 0) {
  3004.      strcpy(buf,&dirname[2]);
  3005.      strcpy(dirname,buf);
  3006.      }
  3007.       while (strncmp(dirname,"..\\",3) == 0) {
  3008.      char *s;
  3009.      curdir[strlen(curdir)-1] = 0; /* strip trailing slash */
  3010.      if (s = strrchr(curdir,'\\'))
  3011.         *s = 0;
  3012.      strcat(curdir,"\\");
  3013.      strcpy(buf,&dirname[3]);
  3014.      strcpy(dirname,buf);
  3015.      }
  3016.       strcpy(buf,dirname);
  3017.       dirname[0] = 0;
  3018.       if (curdir[0] != '\\')
  3019.      strcpy(dirname,"\\");
  3020.       strcat(dirname,curdir);
  3021.       strcat(dirname,buf);
  3022.       }
  3023.    return(0);
  3024. }
  3025.  
  3026. static int get_corners()
  3027. {
  3028.    struct fullscreenvalues values[15];
  3029.    char *prompts[15];
  3030.    static char xprompt[]={"          X"};
  3031.    static char yprompt[]={"          Y"};
  3032.    static char zprompt[]={"          Z"};
  3033.    int i,nump,prompt_ret;
  3034.    int cmag,transp3d;
  3035.    double Xctr,Yctr,Mag;
  3036.    unsigned char ousemag;
  3037.    double oxxmin,oxxmax,oyymin,oyymax,oxx3rd,oyy3rd;
  3038.    double ozzmin,ozzmax,ottmin,ottmax;
  3039.    /* note that hdg[15] is used for non-transparent heading: */
  3040.    static char hdg[]={"Transparent 3d Image Coordinates"};
  3041.    int oldhelpmode;
  3042.  
  3043.    transp3d = (Transparent3D && fractalspecific[fractype].orbitcalc == Formula);
  3044.    oldhelpmode = helpmode;
  3045.    ousemag = usemag;
  3046.    oxxmin = xxmin; oxxmax = xxmax;
  3047.    oyymin = yymin; oyymax = yymax;
  3048.    oxx3rd = xx3rd; oyy3rd = yy3rd;
  3049.    ozzmin = zzmin; ozzmax = zzmax;
  3050.    ottmin = ttmin; ottmax = ttmax;
  3051.  
  3052. gc_loop:
  3053.    for (i = 0; i < 15; ++i)
  3054.       values[i].type = 'd'; /* most values on this screen are type d */
  3055.    cmag = (!transp3d && usemag && cvtcentermag(&Xctr, &Yctr, &Mag));
  3056.  
  3057.    if (cmag) {
  3058.       values[0].uval.dval = Xctr;
  3059.       prompts[0] = "Center X";
  3060.       values[1].uval.dval = Yctr;
  3061.       prompts[1] = "Center Y";
  3062.       values[2].uval.dval = Mag;
  3063.       prompts[2] = "Magnification";
  3064.       values[3].type = '*';
  3065.       prompts[3] = "";
  3066.       values[4].type = '*';
  3067.       prompts[4] = "Press F7 to switch to \"corners\" mode";
  3068.       nump = 5;
  3069.       }
  3070.  
  3071.    else {
  3072.       nump = 0;
  3073.       values[nump].type = '*';
  3074.       prompts[nump++] = "Top-Left Corner";
  3075.       values[nump].uval.dval = xxmin;
  3076.       prompts[nump++] = xprompt;
  3077.       values[nump].uval.dval = yymax;
  3078.       prompts[nump++] = yprompt;
  3079.       if (transp3d) {
  3080.      values[nump].uval.dval = zzmin;
  3081.      prompts[nump++] = zprompt;
  3082.      }
  3083.       values[nump].type = '*';
  3084.       prompts[nump++] = "Bottom-Right Corner";
  3085.       values[nump].uval.dval = xxmax;
  3086.       prompts[nump++] = xprompt;
  3087.       values[nump].uval.dval = yymin;
  3088.       prompts[nump++] = yprompt;
  3089.       if (transp3d) {
  3090.      values[nump].uval.dval = zzmax;
  3091.      prompts[nump++] = zprompt;
  3092.      }
  3093.       if (transp3d) {
  3094.      values[nump].type = '*';
  3095.      prompts[nump++] = "Time Step";
  3096.      values[nump].uval.dval = ttmin;
  3097.      prompts[nump++] = "          From";
  3098.      values[nump].uval.dval = ttmax;
  3099.      prompts[nump++] = "          To";
  3100.      }
  3101.       else {
  3102.      if (xxmin == xx3rd && yymin == yy3rd)
  3103.         xx3rd = yy3rd = 0;
  3104.      values[nump].type = '*';
  3105.      prompts[nump++] = "Bottom-left (zeros for top-left X, bottom-right Y)";
  3106.      values[nump].uval.dval = xx3rd;
  3107.      prompts[nump++] = xprompt;
  3108.      values[nump].uval.dval = yy3rd;
  3109.      prompts[nump++] = yprompt;
  3110.      values[nump].type = '*';
  3111.      prompts[nump++] = "Press F7 to switch to \"center-mag\" mode";
  3112.      }
  3113.       }
  3114.  
  3115.    values[nump].type = '*';
  3116.    prompts[nump++] = "Press F4 to reset to type default values";
  3117.  
  3118.    oldhelpmode = helpmode;
  3119.    helpmode = HELPCOORDS;
  3120.    prompt_ret = fullscreen_prompt((transp3d) ? hdg : &hdg[15],
  3121.              nump, prompts, values, 0,
  3122.              (transp3d) ? 0x10 : 0x90, /* function keys */
  3123.              NULL);
  3124.    helpmode = oldhelpmode;
  3125.  
  3126.    if (prompt_ret < 0) {
  3127.       usemag = ousemag;
  3128.       xxmin = oxxmin; xxmax = oxxmax;
  3129.       yymin = oyymin; yymax = oyymax;
  3130.       xx3rd = oxx3rd; yy3rd = oyy3rd;
  3131.       zzmin = ozzmin; zzmax = ozzmax;
  3132.       ttmin = ottmin; ttmax = ottmax;
  3133.       return -1;
  3134.       }
  3135.  
  3136.    if (prompt_ret == F4) { /* reset to type defaults */
  3137.       xx3rd = xxmin = curfractalspecific->xmin;
  3138.       xxmax        = curfractalspecific->xmax;
  3139.       yy3rd = yymin = curfractalspecific->ymin;
  3140.       yymax        = curfractalspecific->ymax;
  3141.       if (viewcrop && finalaspectratio != SCREENASPECT)
  3142.      aspectratio_crop(SCREENASPECT,finalaspectratio);
  3143.       goto gc_loop;
  3144.       }
  3145.  
  3146.    if (cmag) {
  3147.       if ( values[0].uval.dval != Xctr
  3148.     || values[1].uval.dval != Yctr
  3149.     || values[2].uval.dval != Mag) {
  3150.      double radius,width;
  3151.      radius = 1.0 / values[2].uval.dval;
  3152.      width = radius * (1.0 / SCREENASPECT);
  3153.      yymax           = values[1].uval.dval + radius;
  3154.      yy3rd = yymin = values[1].uval.dval - radius;
  3155.      xxmax           = values[0].uval.dval + width;
  3156.      xx3rd = xxmin = values[0].uval.dval - width;
  3157.      }
  3158.       }
  3159.  
  3160.    else {
  3161.       nump = 1;
  3162.       xxmin = values[nump++].uval.dval;
  3163.       yymax = values[nump++].uval.dval;
  3164.       if (transp3d)
  3165.      zzmin = values[nump++].uval.dval;
  3166.       nump++;
  3167.       xxmax = values[nump++].uval.dval;
  3168.       yymin = values[nump++].uval.dval;
  3169.       if (transp3d)
  3170.      zzmax = values[nump++].uval.dval;
  3171.       nump++;
  3172.       if (transp3d) {
  3173.      ttmin = values[nump++].uval.dval;
  3174.      ttmax = values[nump++].uval.dval;
  3175.      }
  3176.       else {
  3177.      xx3rd = values[nump++].uval.dval;
  3178.      yy3rd = values[nump++].uval.dval;
  3179.      if (xx3rd == 0 && yy3rd == 0) {
  3180.         xx3rd = xxmin;
  3181.         yy3rd = yymin;
  3182.         }
  3183.      }
  3184.       }
  3185.  
  3186.    if (prompt_ret == F7) { /* toggle corners/center-mag mode */
  3187.       if (usemag == 0)
  3188.      if (cvtcentermag(&Xctr, &Yctr, &Mag) == 0)
  3189.         stopmsg(0,"Corners rotated or stretched, can't use center-mag");
  3190.      else
  3191.         usemag = 1;
  3192.       else
  3193.      usemag = 0;
  3194.       goto gc_loop;
  3195.       }
  3196.  
  3197.    return((xxmin == oxxmin && xxmax == oxxmax
  3198.     && yymin == oyymin && yymax == oyymax
  3199.     && xx3rd == oxx3rd && yy3rd == oyy3rd
  3200.     && zzmin == ozzmin && zzmax == ozzmax
  3201.     && ttmin == ottmin && ttmax == ottmax) ? 0 : 1);
  3202. }
  3203.  
  3204.