1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include "Main.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "Defines.h"
#include "Shade.h"
#include "Error.h"
#include "HpFile.h"
#include "Reorder.h"
/* own stuff */
#include "AuxFile.h"
static void GetAuxLine PROTO((FILE *)); /* forward */
static void GetAuxTok PROTO((FILE *)); /* forward */
void
GetAuxFile(FILE *auxfp)
{
ch = ' ';
endfile = 0;
linenum = 1;
GetAuxTok(auxfp);
while (endfile == 0) {
GetAuxLine(auxfp);
}
fclose(auxfp);
}
/*
* Read the next line from the aux file, check the syntax, and
* perform the appropriate action.
*/
static void
GetAuxLine(FILE *auxfp)
{
switch (thetok) {
case X_RANGE_TOK:
GetAuxTok(auxfp);
if (thetok != FLOAT_TOK) {
Error("%s, line %d, floating point number must follow X_RANGE",
auxfile, linenum);
}
auxxrange = thefloatish;
GetAuxTok(auxfp);
break;
case Y_RANGE_TOK:
GetAuxTok(auxfp);
if (thetok != FLOAT_TOK) {
Error("%s, line %d, floating point number must follow Y_RANGE",
auxfile, linenum);
}
auxyrange = thefloatish;
GetAuxTok(auxfp);
break;
case ORDER_TOK:
GetAuxTok(auxfp);
if (thetok != IDENTIFIER_TOK) {
Error("%s, line %d: identifier must follow ORDER",
auxfile, linenum);
}
GetAuxTok(auxfp);
if (thetok != INTEGER_TOK) {
Error("%s, line %d: identifier and integer must follow ORDER",
auxfile, linenum);
}
OrderFor(theident, theinteger);
GetAuxTok(auxfp);
break;
case SHADE_TOK:
GetAuxTok(auxfp);
if (thetok != IDENTIFIER_TOK) {
Error("%s, line %d: identifier must follow SHADE",
auxfile, linenum);
}
GetAuxTok(auxfp);
if (thetok != FLOAT_TOK) {
Error("%s, line %d: identifier and floating point number must follow SHADE",
auxfile, linenum);
}
ShadeFor(theident, thefloatish);
GetAuxTok(auxfp);
break;
case EOF_TOK:
endfile = 1;
break;
default:
Error("%s, line %d: %s unexpected", auxfile, linenum,
TokenToString(thetok));
break;
}
}
/*
* Read the next token from the input and assign its value
* to the global variable "thetok". In the case of numbers,
* the corresponding value is also assigned to "thefloatish";
* in the case of identifiers it is assigned to "theident".
*/
static void GetAuxTok(FILE *auxfp)
{
while (isspace(ch)) { /* skip whitespace */
if (ch == '\n') linenum++;
ch = getc(auxfp);
}
if (ch == EOF) {
thetok = EOF_TOK;
return;
}
if (isdigit(ch)) {
thetok = GetNumber(auxfp);
return;
} else if (IsIdChar(ch)) { /* ch can't be a digit here */
GetIdent(auxfp);
if (!isupper((int)theident[0])) {
thetok = IDENTIFIER_TOK;
} else if (strcmp(theident, "X_RANGE") == 0) {
thetok = X_RANGE_TOK;
} else if (strcmp(theident, "Y_RANGE") == 0) {
thetok = Y_RANGE_TOK;
} else if (strcmp(theident, "ORDER") == 0) {
thetok = ORDER_TOK;
} else if (strcmp(theident, "SHADE") == 0) {
thetok = SHADE_TOK;
} else {
thetok = IDENTIFIER_TOK;
}
return;
} else {
Error("%s, line %d: strange character (%c)", auxfile, linenum, ch);
}
}
void
PutAuxFile(FILE *auxfp)
{
int i;
fprintf(auxfp, "X_RANGE %.2f\n", xrange);
fprintf(auxfp, "Y_RANGE %.2f\n", yrange);
for (i = 0; i < nidents; i++) {
fprintf(auxfp, "ORDER %s %d\n", identtable[i]->name, i+1);
}
for (i = 0; i < nidents; i++) {
fprintf(auxfp, "SHADE %s %.2f\n", identtable[i]->name,
ShadeOf(identtable[i]->name));
}
fclose(auxfp);
}
|