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