📄 driver.c
字号:
}
AnsiColor(DEFAULT);
}
/* Print out a list of the 12 signs and houses of the zodiac, and their */
/* standard and traditional names, as done when the -H0 switch is invoked. */
void PrintSigns()
{
int i;
fprintf(S, "%s signs and houses:\n", appname);
fprintf(S, "Sign English name House Traditional name\n\n");
for (i = 1; i <= SIGNS; i++) {
AnsiColor(signansi(i));
fprintf(S, "%-12sthe %-14s%2d%s House of %s\n",
signname[i], signenglish[i], i, post[i], housetradition[i]);
}
AnsiColor(DEFAULT);
}
/*
******************************************************************************
** File IO Routines.
******************************************************************************
*/
/* Print an error message signifying that a particular option in the */
/* defaults file is invalid. This is a subprocedure of InputDefaults below. */
void BadDef(option)
char *option;
{
char string[STRING];
sprintf(string, "Bad default %s in %s.", option, DEFAULT_INFOFILE);
PrintError(string);
}
/* Read in a set of default program values used in the program, such as */
/* present location, time zone, the system of houses to use, the number */
/* of aspects and what orbs to use, and so on. These values are always */
/* read in at the beginning of program execution. */
/* The NEXTDEFAULT macro means to skip all comments in the file until we */
/* reach the beginning of the next set of data, delimited with a '=' sign. */
#define NEXTDEFAULT while(getc(data) != '=');
bool InputDefaults()
{
FILE *data;
char name[STRING];
int i, j;
filename = DEFAULT_INFOFILE; /* First lets open the info file. */
data = fopen(filename, "r"); /* Look for file in current directory. */
if (data == NULL) {
sprintf(name, "%s%s", DEFAULT_DIR, filename); /* Look for file in */
data = fopen(name, "r"); /* default directory. */
if (data == NULL) /* If file not found anywhere, then forget */
return FALSE; /* it and use the compile time defaults. */
}
NEXTDEFAULT; fscanf(data, "%s", name);
if (StringCmp(name, VERSION) != 0) {
sprintf(name, "%s: Bad information in default parameter file '%s'.",
appname, filename);
PrintWarning(name);
PrintWarning(
"Delete this file or obtain one compatible with current version.");
Terminate(_ERROR);
return FALSE;
}
NEXTDEFAULT; fscanf(data, "%lf", &defzone); /* Time zone */
if (!IsValidZon(defzone))
BadDef("Time Zone");
NEXTDEFAULT; fscanf(data, "%lf", &deflong); /* Longitude */
if (!IsValidLon(deflong))
BadDef("Longitude");
NEXTDEFAULT; fscanf(data, "%lf", &deflat); /* Latitude */
if (!IsValidLat(deflat))
BadDef("Latitude");
NEXTDEFAULT; fscanf(data, "%d", &aspects); /* # of aspects */
if (!IsValidAspect(aspects))
BadDef("Aspect Number");
NEXTDEFAULT; fscanf(data, "%d", &housesystem); /* House type */
if (!IsValidSystem(housesystem))
BadDef("House System");
NEXTDEFAULT; fscanf(data, "%d", &ansi); /* Ansi text? */
NEXTDEFAULT; fscanf(data, "%d", &divisions); /* For -d and -T */
if (!IsValidDivision(divisions))
BadDef("Searching Divisions");
NEXTDEFAULT; fscanf(data, "%d", &placalc); /* Use ephemeris */
NEXTDEFAULT; fscanf(data, "%d", &seconds); /* Zodiac seconds */
seconds = seconds != 0;
NEXTDEFAULT; fscanf(data, "%d", &wheelrows); /* For -w charts */
if (!IsValidWheel(wheelrows))
BadDef("Wheel Rows");
NEXTDEFAULT; fscanf(data, "%d", &screenwidth); /* For -I charts */
if (!IsValidScreen(screenwidth))
BadDef("Screen Width");
NEXTDEFAULT; fscanf(data, "%d", &eurodate); /* D/M/Y vs. M/D/Y? */
NEXTDEFAULT; fscanf(data, "%d", &eurotime); /* 24hr vs. 12hr clock? */
NEXTDEFAULT; fscanf(data, "%d", &smartcusp); /* Logical -C displays? */
NEXTDEFAULT; fscanf(data, "%d", &column80); /* Clip text at col 80? */
NEXTDEFAULT;
for (i = 1; i <= BASE; i++) { /* Object restrictions */
fscanf(data, "%d", &j);
ignore[i] = j > 0;
}
NEXTDEFAULT;
for (i = 1; i <= BASE; i++) { /* Transit object restrictions */
fscanf(data, "%d", &j);
ignore2[i] = j > 0;
}
NEXTDEFAULT;
fscanf(data, "%d", &j); ignore[0] = j > 0; /* Restrict sign changes */
NEXTDEFAULT;
fscanf(data, "%d", &j); ignore2[0] = j > 0; /* Restrict dir. changes */
NEXTDEFAULT;
for (i = 1; i <= ASPECTS; i++) /* Orbs for aspects */
fscanf(data, "%lf", &aspectorb[i]);
NEXTDEFAULT;
for (i = 1; i <= BASE; i++) /* Orbs for planets */
fscanf(data, "%lf", &planetorb[i]);
NEXTDEFAULT;
for (i = 1; i <= BASE; i++) /* Extra planet orbs */
fscanf(data, "%lf", &planetadd[i]);
NEXTDEFAULT; fscanf(data, "%lf", &objectinf[BASE+1]); /* Rules sign */
NEXTDEFAULT; fscanf(data, "%lf", &objectinf[BASE+2]); /* Exalts in */
NEXTDEFAULT; fscanf(data, "%lf", &houseinf[SIGNS+1]); /* Rules house */
NEXTDEFAULT; fscanf(data, "%lf", &houseinf[SIGNS+2]); /* Exalts in */
NEXTDEFAULT;
for (i = 1; i <= BASE; i++)
fscanf(data, "%lf", &objectinf[i]); /* Influence of each object */
for (i = 1; i <= SIGNS; i++)
fscanf(data, "%lf", &houseinf[i]); /* Influence of each house */
for (i = 1; i <= ASPECTS; i++)
fscanf(data, "%lf", &aspectinf[i]); /* Influence of each aspect */
NEXTDEFAULT;
for (i = 1; i <= BASE; i++)
fscanf(data, "%lf", &transitinf[i]); /* Each object when transiting */
/* Graphics defaults begin here. These are only read in with certain */
/* compile options. They need to be read in last for file compatibility. */
#ifdef GRAPH
NEXTDEFAULT; fscanf(data, "%d", &chartx); /* Horizontal graph size */
if (!IsValidGraphx(chartx))
BadDef("Horizontal Bitmap Size");
NEXTDEFAULT; fscanf(data, "%d", &charty); /* Vertical graph size */
if (!IsValidGraphx(chartx))
BadDef("Vertical Bitmap Size");
NEXTDEFAULT; fscanf(data, "%d", &gridobjects); /* Aspect grid cells */
if (!IsValidGrid(gridobjects))
BadDef("Aspect Grid Cells");
NEXTDEFAULT;
do {
bitmapmode = getc(data);
} while (bitmapmode <= ' ');
if (!IsValidBmpmode(bitmapmode)) /* Bitmap file mode */
BadDef("Bitmap File Mode");
NEXTDEFAULT; fscanf(data, "%d", &xfont); /* Font simulation flag */
#ifdef MSG
NEXTDEFAULT; fscanf(data, "%d", &hiresmode); /* Normal graphics mode */
if (!IsValidResmode(hiresmode))
BadDef("High Resolution Size");
NEXTDEFAULT; fscanf(data, "%d", &loresmode); /* Animation graphics mode */
if (!IsValidResmode(loresmode))
BadDef("Low Resolution Size");
#endif
#endif /* GRAPH */
fclose(data);
return TRUE;
}
/* Take the current chart information, and write it out to the file */
/* as indicated by the -o switch. This is only executed at the end of */
/* program execution if the -o switch is in effect. */
bool OutputData()
{
char string[STRING];
FILE *data;
int i, j;
real k;
data = fopen(filenameout, "w"); /* Create and open the file for output. */
if (data == NULL) {
sprintf(string, "File %s can not be created.", filenameout);
PrintError(string);
return FALSE;
}
if (!(operation & DASHo0)) {
/* Write the chart information to the file. */
if (Mon < 1) {
fclose(data);
PrintError("Can't output chart with no time/space to file.");
return FALSE;
}
fprintf(data, "%d\n%d\n%d\n%.2f\n%.2f\n%.2f\n%.2f\n",
Mon, Day, Yea, Tim, Zon, Lon, Lat);
} else {
/* However, if the -o0 switch is in effect, then write the actual */
/* positions of the planets and houses to the file instead. */
for (i = 1; i <= BASE; i++) {
j = (int) planet[i];
fprintf(data, "%c%c%c: %2d %2d %10.7f\n", OBJNAM(i),
j%30, j/30+1, FRACT(planet[i])*60.0); /* Position */
k = planetalt[i];
fprintf(data, "[%c]: %3d %12.8f\n", /* Altitude */
ret[i] >= 0.0 ? 'D' : 'R', (int)(Sgn(k)*
floor(dabs(k))), (k-(real)(int)k)*60.0); /* Retrograde? */
if (i == OBJECTS) {
if (operation & DASHu) /* Skip minor cusps to write uranians */
i = C_HI;
else
i = total;
}
}
for (i = 1; i <= SIGNS/2; i++) { /* Write first six cusp positions */
j = (int) house[i];
fprintf(data, "H_%c: %2d %2d %10.7f\n",
'a'+i-1, j%30, j/30+1, FRACT(house[i])*60.0);
}
}
/* Now write any extra strings that were on the command line after the -o */
/* specification but before the next switch, to the file as comments. */
for (i = 1; i < extracount; i++) {
extralines++;
fprintf(data, "%s\n", extralines[1]);
}
fclose(data);
return TRUE;
}
/*
******************************************************************************
** Program Dispatch Procedures.
******************************************************************************
*/
/* Initialize an Ansi color array with the color to print each object in. */
void InitColors()
{
int i;
objectansi[0] = elemansi[_EAR];
for (i = 1; i <= 10; i++)
objectansi[i] = signansi(ruler1[i]);
for (i = 11; i <= 15; i++)
objectansi[i] = MAGENTA;
for (i = 16; i <= 20; i++)
objectansi[i] = DKCYAN;
objectansi[_MC] = elemansi[_EAR]; objectansi[_ASC] = elemansi[_FIR];
objectansi[21] = elemansi[_AIR]; objectansi[22] = elemansi[_WAT];
objectansi[23] = elemansi[_EAR]; objectansi[24] = elemansi[_AIR];
for (i = U_LO; i <= U_HI; i++)
objectansi[i] = PURPLE;
for (i = S_LO; i <= S_HI; i++)
objectansi[i] = starbright[i-BASE] < 1.0 ? ORANGE : MAROON;
}
/* This is the dispatch procedure for all the generic table information */
/* routines, such as those displaying the -H switch list, the list of signs, */
/* objects, default interpretations, and so on not requiring a date or time. */
int PrintTables()
{
if (andisplay < 2)
return FALSE;
if (andisplay & DASHHc) {
DisplayCredits();
if (andisplay - (andisplay & DASHHc*2-1))
printl2();
}
if (andisplay & DASHH) {
DisplaySwitches();
if (andisplay - (andisplay & DASHH*2-1))
printl2();
}
if (andisplay & DASHH0) {
PrintSigns();
if (andisplay - (andisplay & DASHH0*2-1))
printl2();
}
if (andisplay & DASHO) {
PrintObjects((andisplay & DASHO0) > 0);
if (andisplay - (andisplay & DASHO*2-1))
printl2();
}
if (andisplay & DASHA) {
PrintAspects();
if (andisplay - (andisplay & DASHA*2-1))
printl2();
}
#ifdef INTERPRET
if (andisplay & DASHI0) {
InterpretGeneral();
InterpretAspectGeneral();
}
#endif
/* If we also already have enough information to generate a chart, */
/* then go on and do so, else exit. (So things like "-O -i file" will */
/* work, but things like just "-H" will print and exit right away.) */
if (autom)
printl2();
return !autom;
}
/* This is the dispatch procedure for the entire program. After all the */
/* command switches have been processed, this routine is called to */
/* actually call the various routines to generate and display the charts. */
void Action()
{
char string[STRING];
int i;
AnsiColor(DEFAULT);
InitColors();
/* First let's adjust the restriction status of the minor cusps, uranians, */
/* and fixed stars based on whether -C, -u, and -U switches are in effect. */
if (!(operation & DASHC))
for (i = C_LO; i <= C_HI; i++)
ignore[i] = ignore2[i] = TRUE;
if (!(operation & DASHu))
for (i = U_LO; i <= U_HI; i++)
ignore[i] = ignore2[i] = TRUE;
if (!universe)
for (i = S_LO; i <= S_HI; i++)
ignore[i] = ignore2[i] = TRUE;
/* If the -os switch is in effect, open a file and set a global to */
/* internally 'redirect' all screen output to. */
if (filenamescreen) {
S = fopen(filenamescreen, "w");
if (S == NULL) {
sprintf(string, "File %s can not be created.", filenamescreen);
PrintError(string);
S = stdout;
}
} else
S = stdout;
if (PrintTables()) /* Print out any generic tables specified. */
return; /* If nothing else to do, we can exit right away. */
/* If -+ or -- switches in effect, then add the specified delta value to */
/* the date and use that as a new date before proceeding to make chart. */
if (Delta != 0) {
JD = (real)MdyToJulian(MM, DD+Delta, YY);
JulianToMdy(JD, &MM, &DD, &YY);
}
/* Here we either do a normal chart or some kind of relationship chart. */
if (!relation) {
if (!autom && !InputData("tty")) /* If chart info not in mem yet, then */
return; /* prompt the user for the time, etc. */
SetMain(MM, DD, YY, TT, ZZ, OO, AA);
CastChart(TRUE);
} else
CastRelation(TRUE);
SetSave(Mon, Day, Yea, Tim, Zon, Lon, Lat);
#ifdef GRAPH
if (operation & DASHX) /* If any of the X window switches in effect, */
XAction(); /* then go make a graphics chart... */
else
#endif
PrintChart(prog); /* Otherwise print chart on text screen. */
if (operation & DASHo) /* If -o switch in effect, then write */
OutputData(); /* the chart information to a file. */
if (S != stdout) /* If we were internally directing chart display to a */
fclose(S); /* file as with the -os switch, close it here. */
}
/* Reset a few variables to their default values they have upon startup of */
/* the program. We don't reset all variables, just the most volatile ones. */
/* This is called when in the -Q loop to reset things like which charts to */
/* display, but leave setups such as object restrictions and orbs alone. */
void InitVariables()
{
filenamescreen = NULL;
relation = 0;
todisplay = exdisplay = andisplay = operation = 0x0;
interpret = progress = autom = FALSE;
}
/* This routine is called by the main program to actually prompt the user */
/* for command switches and parameters, entered in the same format as they */
/* would be on a Unix command line. This is only executed for certain non- */
/* Unix systems which don't allow passing of a command line to the program, */
/* or when -Q is in effect. The result of this routine is passed back to the */
/* main program which then processes it just like in a Unix system. */
#define MAXSWITCHES 30
int InputSwitches(line, argv)
char *line, *argv[MAXSWITCHES];
{
FILE *data;
int argc = 1, i = 0, j = 1;
char *c = line;
data = S; S = stdout;
AnsiColor(WHITE);
fprintf(S, "** %s version %s ", appname, VERSION);
fprintf(S, "(See '%cHc' switch for copyrights and credits.) **\n", DASH);
AnsiColor(DEFAULT);
fprintf(S, "Enter all parameter options below. ");
fprintf(S, "(Enter '%cH' for help. Enter '.' to exit.)\n", DASH);
S = data;
InputString("Input command line", line);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -