home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
grap
/
util
/
010
/
miscres.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-16
|
27KB
|
918 lines
/*
Resident odds and ends that don't fit anywhere else.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#ifndef XFRACT
#include <stdarg.h>
#include <io.h>
#else
#include <varargs.h>
#endif
#include <math.h>
#ifdef __TURBOC__
#include <dir.h>
#endif
#include "fractint.h"
#include "fractype.h"
#include "helpdefs.h"
#include "prototyp.h"
/* routines in this module */
static void trigdetails(char *);
static void area();
int active_ovly = -1;
extern char IFSFileName[80];
extern char IFSName[40];
extern float far *ifs_defn;
extern int ifs_changed;
extern int ifs_type;
extern int neworbittype;
extern char temp[], temp1[256]; /* temporary strings */
extern int active_ovly;
extern int xdots, ydots;
extern int dotmode;
extern int show_orbit;
extern int debugflag;
extern int maxit;
extern int fractype;
extern int got_status,curpass,totpasses,currow,curcol;
extern int fileydots;
extern int xxstart,xxstop,yystart,yystop;
extern int display3d;
extern char overwrite;
extern int inside;
extern int outside;
extern double xxmax,xxmin,yymax,yymin,xx3rd,yy3rd;
/* TW's static string consolidation campaign to help brain-dead compilers */
char s_cantopen[] = {"Can't open %s"};
char s_cantwrite[] = {"Can't write %s"};
char s_cantcreate[] = {"Can't create %s"};
char s_cantunderstand[] = {"Can't understand %s"};
char s_cantfind[] = {"Can't find %s"};
/* call next when returning from resident routine and unsure whether
caller is an overlay which has been displaced */
void restore_active_ovly()
{
switch (active_ovly) {
case OVLY_MISCOVL: miscovl_overlay(); break;
case OVLY_CMDFILES: cmdfiles_overlay(); break;
case OVLY_HELP: help_overlay(); break;
case OVLY_PROMPTS1: prompts1_overlay(); break;
case OVLY_PROMPTS2: prompts2_overlay(); break;
case OVLY_LOADFILE: loadfile_overlay(); break;
case OVLY_ROTATE: rotate_overlay(); break;
case OVLY_PRINTER: printer_overlay(); break;
case OVLY_LINE3D: line3d_overlay(); break;
case OVLY_ENCODER: encoder_overlay(); break;
case OVLY_CALCFRAC: calcfrac_overlay(); break;
case OVLY_INTRO: intro_overlay(); break;
case OVLY_DECODER: decoder_overlay(); break;
}
}
#ifndef XFRACT
void findpath(char *filename, char *fullpathname) /* return full pathnames */
{
if (filename[0] == SLASHC
|| (filename[0] && filename[1] == ':')) {
strcpy(fullpathname,filename);
return;
}
fullpathname[0] = 0; /* indicate none found */
#ifdef __TURBOC__ /* look for the file */
strcpy(fullpathname,searchpath(filename));
#else
_searchenv(filename,"PATH",fullpathname);
#endif
if (fullpathname[0] != 0) /* found it! */
if (strncmp(&fullpathname[2],SLASHSLASH,2) == 0) /* stupid klooge! */
strcpy(&fullpathname[3],filename);
}
#endif
void notdiskmsg()
{
static char far sorrymsg[]={
"I'm sorry, but because of its random-screen-access algorithms, this\n\
type cannot be created using a real-disk based 'video' mode."};
stopmsg(1,sorrymsg);
}
/* convert corners to center/mag */
int cvtcentermag(double *Xctr, double *Yctr, double *Magnification)
{
double Width, Height, Radius, Ratio;
Width = xxmax - xxmin;
Height = yymax - yymin;
Ratio = Height / Width;
if(xx3rd != xxmin || yy3rd != yymin || Width < 0
|| (Width > 1e-8 && (Ratio <= 0.74 || Ratio >= 0.76))
|| Ratio < 0.66 || Ratio > 0.84)
return(0);
/* calculate center and magnification */
Radius = Height / 2.0;
*Xctr = xxmin + (Width / 2.0);
*Yctr = yymin + Radius;
*Magnification = 1.0 / Radius;
return(1);
}
void updatesavename(char *filename) /* go to the next file name */
{
char *save, *hold;
char name[80],suffix[80];
char *dotptr;
strcpy(name,filename);
suffix[0] = 0;
if ((dotptr = strrchr(name,'.')) != NULL
&& dotptr > strrchr(name,SLASHC)) {
strcpy(suffix,dotptr);
*dotptr = 0;
}
hold = name + strlen(name) - 1; /* start at the end */
while(hold >= name && (*hold == ' ' || isdigit(*hold))) /* skip backwards */
hold--;
hold++; /* recover first digit */
while (*hold == '0') /* skip leading zeros */
hold++;
save = hold;
while (*save) { /* check for all nines */
if (*save != '9')
break;
save++;
}
if (!*save) /* if the whole thing is nines then back */
save = hold - 1; /* up one place. Note that this will eat */
/* your last letter if you go to far. */
else
save = hold;
sprintf(save,"%d",atoi(hold)+1); /* increment the number */
strcpy(filename,name);
strcat(filename,suffix);
}
int check_writefile(char *name,char *ext)
{
/* after v16 release, change encoder.c to also use this routine */
char openfile[80];
char opentype[20];
int i;
nextname:
strcpy(openfile,name);
strcpy(opentype,ext);
for (i = 0; i < strlen(openfile); i++)
if (openfile[i] == '.') {
strcpy(opentype,&openfile[i]);
openfile[i] = 0;
}
strcat(openfile,opentype);
if (access(openfile,0) != 0) /* file doesn't exist */
{
strcpy(name,openfile);
return 0;
}
/* file already exists */
if (overwrite == 0) {
updatesavename(name);
goto nextname;
}
return 1;
}
/* ('check_key()' was moved to FRACTINT.C for MSC7-overlay speed purposes) */
/* ('timer()' was moved to FRACTINT.C for MSC7-overlay speed purposes) */
BYTE trigndx[] = {SIN,SQR,SINH,COSH};
#ifndef XFRACT
void (*ltrig0)(void) = lStkSin;
void (*ltrig1)(void) = lStkSqr;
void (*ltrig2)(void) = lStkSinh;
void (*ltrig3)(void) = lStkCosh;
void (*mtrig0)(void) = mStkSin;
void (*mtrig1)(void) = mStkSqr;
void (*mtrig2)(void) = mStkSinh;
void (*mtrig3)(void) = mStkCosh;
#endif
void (*dtrig0)(void) = dStkSin;
void (*dtrig1)(void) = dStkSqr;
void (*dtrig2)(void) = dStkSinh;
void (*dtrig3)(void) = dStkCosh;
struct trig_funct_lst trigfn[] =
/* changing the order of these alters meaning of *.fra file */
/* maximum 6 characters in function names or recheck all related code */
{
#ifndef XFRACT
{"sin", lStkSin, dStkSin, mStkSin },
{"cosxx", lStkCosXX, dStkCosXX, mStkCosXX },
{"sinh", lStkSinh, dStkSinh, mStkSinh },
{"cosh", lStkCosh, dStkCosh, mStkCosh },
{"exp", lStkExp, dStkExp, mStkExp },
{"log", lStkLog, dStkLog, mStkLog },
{"sqr", lStkSqr, dStkSqr, mStkSqr },
{"recip", lStkRecip, dStkRecip, mStkRecip }, /* from recip on new in v16 */
{"ident", StkIdent, StkIdent, StkIdent },
{"cos", lStkCos, dStkCos, mStkCos },
{"tan", lStkTan, dStkTan, mStkTan },
{"tanh", lStkTanh, dStkTanh, mStkTanh },
{"cotan", lStkCoTan, dStkCoTan, mStkCoTan },
{"cotanh",lStkCoTanh,dStkCoTanh,mStkCoTanh},
{"flip", lStkFlip, dStkFlip, mStkFlip },
{"conj", lStkConj, dStkConj, mStkConj },
{"zero", lStkZero, dStkZero, mStkZero },
#else
{"sin", dStkSin, dStkSin, dStkSin },
{"cosxx", dStkCosXX, dStkCosXX, dStkCosXX },
{"sinh", dStkSinh, dStkSinh, dStkSinh },
{"cosh", dStkCosh, dStkCosh, dStkCosh },
{"exp", dStkExp, dStkExp, dStkExp },
{"log", dStkLog, dStkLog, dStkLog },
{"sqr", dStkSqr, dStkSqr, dStkSqr },
{"recip", dStkRecip, dStkRecip, dStkRecip }, /* from recip on new in v16 */
{"ident", StkIdent, StkIdent, StkIdent },
{"cos", dStkCos, dStkCos, dStkCos },
{"tan", dStkTan, dStkTan, dStkTan },
{"tanh", dStkTanh, dStkTanh, dStkTanh },
{"cotan", dStkCoTan, dStkCoTan, dStkCoTan },
{"cotanh",dStkCoTanh,dStkCoTanh,dStkCoTanh},
{"flip", dStkFlip, dStkFlip, dStkFlip },
{"conj", dStkConj, dStkConj, dStkConj },
{"zero", dStkZero, dStkZero, dStkZero },
#endif
};
int numtrigfn = sizeof(trigfn)/sizeof(struct trig_funct_ls