home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / grap / util / 010 / miscres.c < prev    next >
C/C++ Source or Header  |  1993-04-16  |  27KB  |  918 lines

  1. /*
  2.     Resident odds and ends that don't fit anywhere else.
  3. */
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <time.h>
  10. #ifndef XFRACT
  11. #include <stdarg.h>
  12. #include <io.h>
  13. #else
  14. #include <varargs.h>
  15. #endif
  16. #include <math.h>
  17. #ifdef __TURBOC__
  18. #include <dir.h>
  19. #endif
  20. #include "fractint.h"
  21. #include "fractype.h"
  22. #include "helpdefs.h"
  23. #include "prototyp.h"
  24.  
  25. /* routines in this module    */
  26.  
  27. static    void trigdetails(char *);
  28. static void area();
  29.  
  30. int active_ovly = -1;
  31.  
  32. extern char IFSFileName[80];
  33. extern char IFSName[40];
  34. extern float far *ifs_defn;
  35. extern int  ifs_changed;
  36. extern int  ifs_type;
  37. extern int neworbittype;
  38. extern char temp[], temp1[256];   /* temporary strings          */
  39.  
  40. extern int  active_ovly;
  41. extern int  xdots, ydots;
  42. extern int  dotmode;
  43. extern int  show_orbit;
  44. extern int  debugflag;
  45. extern int  maxit;
  46. extern int  fractype;
  47. extern int  got_status,curpass,totpasses,currow,curcol;
  48. extern int  fileydots;
  49. extern int  xxstart,xxstop,yystart,yystop;
  50. extern int  display3d;
  51. extern char overwrite;
  52. extern int  inside;
  53. extern int  outside;
  54. extern double xxmax,xxmin,yymax,yymin,xx3rd,yy3rd;
  55.  
  56.  
  57. /* TW's static string consolidation campaign to help brain-dead compilers */
  58. char s_cantopen[]       = {"Can't open %s"};
  59. char s_cantwrite[]      = {"Can't write %s"};
  60. char s_cantcreate[]     = {"Can't create %s"};
  61. char s_cantunderstand[] = {"Can't understand %s"};
  62. char s_cantfind[]       = {"Can't find %s"};
  63.  
  64. /* call next when returning from resident routine and unsure whether
  65.    caller is an overlay which has been displaced */
  66. void restore_active_ovly()
  67. {
  68.    switch (active_ovly) {
  69.       case OVLY_MISCOVL:  miscovl_overlay();  break;
  70.       case OVLY_CMDFILES: cmdfiles_overlay(); break;
  71.       case OVLY_HELP:      help_overlay();     break;
  72.       case OVLY_PROMPTS1: prompts1_overlay(); break;
  73.       case OVLY_PROMPTS2: prompts2_overlay(); break;
  74.       case OVLY_LOADFILE: loadfile_overlay(); break;
  75.       case OVLY_ROTATE:   rotate_overlay();   break;
  76.       case OVLY_PRINTER:  printer_overlay();  break;
  77.       case OVLY_LINE3D:   line3d_overlay();   break;
  78.       case OVLY_ENCODER:  encoder_overlay();  break;
  79.       case OVLY_CALCFRAC: calcfrac_overlay(); break;
  80.       case OVLY_INTRO:      intro_overlay();    break;
  81.       case OVLY_DECODER:  decoder_overlay();  break;
  82.       }
  83. }
  84.  
  85.  
  86. #ifndef XFRACT
  87. void findpath(char *filename, char *fullpathname) /* return full pathnames */
  88. {
  89.    if (filename[0] == SLASHC
  90.      || (filename[0] && filename[1] == ':')) {
  91.       strcpy(fullpathname,filename);
  92.       return;
  93.       }
  94.    fullpathname[0] = 0;             /* indicate none found */
  95. #ifdef __TURBOC__                /* look for the file */
  96.    strcpy(fullpathname,searchpath(filename));
  97. #else
  98.    _searchenv(filename,"PATH",fullpathname);
  99. #endif
  100.    if (fullpathname[0] != 0)            /* found it! */
  101.       if (strncmp(&fullpathname[2],SLASHSLASH,2) == 0) /* stupid klooge! */
  102.      strcpy(&fullpathname[3],filename);
  103. }
  104. #endif
  105.  
  106.  
  107. void notdiskmsg()
  108. {
  109. static char far sorrymsg[]={
  110. "I'm sorry, but because of its random-screen-access algorithms, this\n\
  111. type cannot be created using a real-disk based 'video' mode."};
  112.    stopmsg(1,sorrymsg);
  113. }
  114.  
  115.  
  116. /* convert corners to center/mag */
  117. int cvtcentermag(double *Xctr, double *Yctr, double *Magnification)
  118. {
  119.    double Width, Height, Radius, Ratio;
  120.    Width  = xxmax - xxmin;
  121.    Height = yymax - yymin;
  122.    Ratio = Height / Width;
  123.    if(xx3rd != xxmin || yy3rd != yymin || Width < 0
  124.      || (Width > 1e-8 && (Ratio <= 0.74 || Ratio >= 0.76))
  125.      || Ratio < 0.66 || Ratio > 0.84)
  126.       return(0);
  127.    /* calculate center and magnification */
  128.    Radius = Height / 2.0;
  129.    *Xctr = xxmin + (Width / 2.0);
  130.    *Yctr = yymin + Radius;
  131.    *Magnification = 1.0 / Radius;
  132.    return(1);
  133. }
  134.  
  135.  
  136. void updatesavename(char *filename) /* go to the next file name */
  137. {
  138.    char *save, *hold;
  139.    char name[80],suffix[80];
  140.    char *dotptr;
  141.  
  142.    strcpy(name,filename);
  143.    suffix[0] = 0;
  144.    if ((dotptr = strrchr(name,'.')) != NULL
  145.      && dotptr > strrchr(name,SLASHC)) {
  146.       strcpy(suffix,dotptr);
  147.       *dotptr = 0;
  148.       }
  149.  
  150.    hold = name + strlen(name) - 1; /* start at the end */
  151.    while(hold >= name && (*hold == ' ' || isdigit(*hold))) /* skip backwards */
  152.       hold--;
  153.    hold++;            /* recover first digit */
  154.    while (*hold == '0')         /* skip leading zeros */
  155.       hold++;
  156.    save = hold;
  157.    while (*save) {        /* check for all nines */
  158.       if (*save != '9')
  159.      break;
  160.       save++;
  161.       }
  162.    if (!*save)            /* if the whole thing is nines then back */
  163.       save = hold - 1;        /* up one place. Note that this will eat */
  164.                 /* your last letter if you go to far.     */
  165.    else
  166.       save = hold;
  167.    sprintf(save,"%d",atoi(hold)+1); /* increment the number */
  168.    strcpy(filename,name);
  169.    strcat(filename,suffix);
  170. }
  171.  
  172. int check_writefile(char *name,char *ext)
  173. {
  174.  /* after v16 release, change encoder.c to also use this routine */
  175.    char openfile[80];
  176.    char opentype[20];
  177.    int i;
  178. nextname:
  179.    strcpy(openfile,name);
  180.    strcpy(opentype,ext);
  181.    for (i = 0; i < strlen(openfile); i++)
  182.       if (openfile[i] == '.') {
  183.      strcpy(opentype,&openfile[i]);
  184.      openfile[i] = 0;
  185.      }
  186.    strcat(openfile,opentype);
  187.    if (access(openfile,0) != 0) /* file doesn't exist */
  188.    {
  189.       strcpy(name,openfile);
  190.       return 0;
  191.     }
  192.    /* file already exists */
  193.    if (overwrite == 0) {
  194.       updatesavename(name);
  195.       goto nextname;
  196.       }
  197.    return 1;
  198. }
  199.  
  200. /* ('check_key()' was moved to FRACTINT.C for MSC7-overlay speed purposes) */
  201. /* ('timer()'     was moved to FRACTINT.C for MSC7-overlay speed purposes) */
  202.  
  203. BYTE trigndx[] = {SIN,SQR,SINH,COSH};
  204. #ifndef XFRACT
  205. void (*ltrig0)(void) = lStkSin;
  206. void (*ltrig1)(void) = lStkSqr;
  207. void (*ltrig2)(void) = lStkSinh;
  208. void (*ltrig3)(void) = lStkCosh;
  209. void (*mtrig0)(void) = mStkSin;
  210. void (*mtrig1)(void) = mStkSqr;
  211. void (*mtrig2)(void) = mStkSinh;
  212. void (*mtrig3)(void) = mStkCosh;
  213. #endif
  214. void (*dtrig0)(void) = dStkSin;
  215. void (*dtrig1)(void) = dStkSqr;
  216. void (*dtrig2)(void) = dStkSinh;
  217. void (*dtrig3)(void) = dStkCosh;
  218.  
  219. struct trig_funct_lst trigfn[] =
  220. /* changing the order of these alters meaning of *.fra file */
  221. /* maximum 6 characters in function names or recheck all related code */
  222. {
  223. #ifndef XFRACT
  224.    {"sin",   lStkSin,   dStkSin,   mStkSin   },
  225.    {"cosxx", lStkCosXX, dStkCosXX, mStkCosXX },
  226.    {"sinh",  lStkSinh,  dStkSinh,  mStkSinh  },
  227.    {"cosh",  lStkCosh,  dStkCosh,  mStkCosh  },
  228.    {"exp",   lStkExp,   dStkExp,   mStkExp   },
  229.    {"log",   lStkLog,   dStkLog,   mStkLog   },
  230.    {"sqr",   lStkSqr,   dStkSqr,   mStkSqr   },
  231.    {"recip", lStkRecip, dStkRecip, mStkRecip }, /* from recip on new in v16 */
  232.    {"ident", StkIdent,  StkIdent,  StkIdent  },
  233.    {"cos",   lStkCos,   dStkCos,   mStkCos   },
  234.    {"tan",   lStkTan,   dStkTan,   mStkTan   },
  235.    {"tanh",  lStkTanh,  dStkTanh,  mStkTanh  },
  236.    {"cotan", lStkCoTan, dStkCoTan, mStkCoTan },
  237.    {"cotanh",lStkCoTanh,dStkCoTanh,mStkCoTanh},
  238.    {"flip",  lStkFlip,  dStkFlip,  mStkFlip  },
  239.    {"conj",  lStkConj,  dStkConj,  mStkConj  },
  240.    {"zero",  lStkZero,  dStkZero,  mStkZero  },
  241. #else
  242.    {"sin",   dStkSin,   dStkSin,   dStkSin   },
  243.    {"cosxx", dStkCosXX, dStkCosXX, dStkCosXX },
  244.    {"sinh",  dStkSinh,  dStkSinh,  dStkSinh  },
  245.    {"cosh",  dStkCosh,  dStkCosh,  dStkCosh  },
  246.    {"exp",   dStkExp,   dStkExp,   dStkExp   },
  247.    {"log",   dStkLog,   dStkLog,   dStkLog   },
  248.    {"sqr",   dStkSqr,   dStkSqr,   dStkSqr   },
  249.    {"recip", dStkRecip, dStkRecip, dStkRecip }, /* from recip on new in v16 */
  250.    {"ident", StkIdent,  StkIdent,  StkIdent  },
  251.    {"cos",   dStkCos,   dStkCos,   dStkCos   },
  252.    {"tan",   dStkTan,   dStkTan,   dStkTan   },
  253.    {"tanh",  dStkTanh,  dStkTanh,  dStkTanh  },
  254.    {"cotan", dStkCoTan, dStkCoTan, dStkCoTan },
  255.    {"cotanh",dStkCoTanh,dStkCoTanh,dStkCoTanh},
  256.    {"flip",  dStkFlip,  dStkFlip,  dStkFlip  },
  257.    {"conj",  dStkConj,  dStkConj,  dStkConj  },
  258.    {"zero",  dStkZero,  dStkZero,  dStkZero  },
  259. #endif
  260. };
  261. int numtrigfn = sizeof(trigfn)/sizeof(struct trig_funct_ls