| 1 |
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ |
| 2 |
/* From input file "files.pas" */ |
| 3 |
|
| 4 |
|
| 5 |
#include "p2c.h" |
| 6 |
|
| 7 |
|
| 8 |
#define FILES_G |
| 9 |
#include "files.h" |
| 10 |
|
| 11 |
|
| 12 |
#ifndef CONTROL_H |
| 13 |
#include "control.h" |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifndef STRINGS_H |
| 17 |
#include "strings.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
#ifndef UTILITY_H |
| 21 |
#include "utility.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
#define param_leader '-' |
| 26 |
|
| 27 |
|
| 28 |
Static Char stylefilename[256] = "mtxstyle.txt"; |
| 29 |
|
| 30 |
Static short teststyle; |
| 31 |
|
| 32 |
|
| 33 |
boolean endOfInfile(void) |
| 34 |
{ |
| 35 |
return (eofAll()); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
Static void putTeXlines(Char *s_) |
| 40 |
{ |
| 41 |
Char s[256]; |
| 42 |
short p; |
| 43 |
Char STR1[256], STR3[256]; |
| 44 |
|
| 45 |
strcpy(s, s_); |
| 46 |
p = pos1('\n', s); |
| 47 |
while (p > 0) { |
| 48 |
sprintf(STR3, "\\%s\\", substr_(STR1, s, 1, p - 1)); |
| 49 |
putLine(STR3); |
| 50 |
predelete(s, p); |
| 51 |
p = pos1('\n', s); |
| 52 |
} |
| 53 |
if (*s != '\0') { |
| 54 |
sprintf(STR3, "\\%s\\", s); |
| 55 |
putLine(STR3); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
void TeXtype2(Char *s) |
| 61 |
{ |
| 62 |
Char STR2[256]; |
| 63 |
|
| 64 |
if (!pmx_preamble_done) { |
| 65 |
putLine(s); |
| 66 |
return; |
| 67 |
} |
| 68 |
if (s[0] == '%') { |
| 69 |
putLine(s); |
| 70 |
return; |
| 71 |
} |
| 72 |
if (first_paragraph) |
| 73 |
putTeXlines(s); |
| 74 |
else { |
| 75 |
sprintf(STR2, "\\\\%s\\", s); |
| 76 |
putLine(STR2); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
void putLine(Char *line) |
| 82 |
{ |
| 83 |
if (outlen + strlen(line) >= PMXlinelength) |
| 84 |
putc('\n', outfile); |
| 85 |
fprintf(outfile, "%s\n", line); |
| 86 |
outlen = 0; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
void put(Char *line_, boolean putspace_) |
| 91 |
{ |
| 92 |
Char line[256]; |
| 93 |
short l; |
| 94 |
Char STR1[256]; |
| 95 |
|
| 96 |
strcpy(line, line_); |
| 97 |
l = strlen(line); |
| 98 |
if (l > PMXlinelength) |
| 99 |
error("Item longer than PMX line length", print); |
| 100 |
if (outlen + l >= PMXlinelength) { |
| 101 |
putLine(""); |
| 102 |
put(line, false); |
| 103 |
return; |
| 104 |
} |
| 105 |
if (putspace_ && outlen > 0 && line[0] != ' ') |
| 106 |
sprintf(line, " %s", strcpy(STR1, line)); |
| 107 |
fputs(line, outfile); |
| 108 |
outlen += l; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
boolean styleFileFound(void) |
| 113 |
{ |
| 114 |
return (teststyle != 0); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
Static void helpmessage(void) |
| 119 |
{ |
| 120 |
printf("Usage: prepmx [-bcfnhimtuvwDH0123456789] MTXFILE [TEXDIR] [STYLEFILE]\n"); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
Static void bighelpmessage(void) |
| 125 |
{ |
| 126 |
helpmessage(); |
| 127 |
printf("\nMTXFILE: name of .mtx file without its extension\n"); |
| 128 |
printf("TEXDIR: directory where the TeX file made by PMX goes, default is ./\n"); |
| 129 |
printf("STYLEFILE: name of a file containing style definitions. Default is\n"); |
| 130 |
printf(" mtxstyle.txt. This feature is now deprecated; use Include: STYLEFILE\n"); |
| 131 |
printf(" in the preamble of the .mtx file instead.\n"); |
| 132 |
printf("Options: (can also be entered separately: -b -c ...)\n"); |
| 133 |
printf(" -b: disable unbeamVocal\n"); |
| 134 |
printf(" -c: disable doChords\n"); |
| 135 |
printf(" -f: enable solfaNoteNames\n"); |
| 136 |
printf(" -h: display this message and quit\n"); |
| 137 |
printf(" -i: enable ignoreErrors\n"); |
| 138 |
printf(" -m: disable doLyrics\n"); |
| 139 |
printf(" -n: enable instrumentNames\n"); |
| 140 |
printf(" -t: disable doUptext\n"); |
| 141 |
printf(" -u: disable uptextOnRests\n"); |
| 142 |
printf(" -v: enable beVerbose\n"); |
| 143 |
printf(" -w: enable pedanticWarnings\n"); |
| 144 |
printf(" -D: enable debugMode\n"); |
| 145 |
printf(" -0123456789: select Case\n"); |
| 146 |
printf(" -H: print enabled status of all options\n"); |
| 147 |
printf("All the above, and some other, options can be enabled or disabled\n"); |
| 148 |
printf(" in the preamble. What you do there overrides what you do here.\n"); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
void processOption(Char j) |
| 153 |
{ |
| 154 |
switch (j) { |
| 155 |
|
| 156 |
case 'b': |
| 157 |
setFeature("unbeamVocal", false); |
| 158 |
break; |
| 159 |
|
| 160 |
case 'c': |
| 161 |
setFeature("doChords", false); |
| 162 |
break; |
| 163 |
|
| 164 |
case 'f': |
| 165 |
setFeature("solfaNoteNames", true); |
| 166 |
break; |
| 167 |
|
| 168 |
case 'h': |
| 169 |
bighelpmessage(); |
| 170 |
_Escape(255); |
| 171 |
break; |
| 172 |
|
| 173 |
case 'i': |
| 174 |
setFeature("ignoreErrors", true); |
| 175 |
break; |
| 176 |
|
| 177 |
case 'm': |
| 178 |
setFeature("doLyrics", false); |
| 179 |
break; |
| 180 |
|
| 181 |
case 'n': |
| 182 |
setFeature("instrumentNames", true); |
| 183 |
break; |
| 184 |
|
| 185 |
case 't': |
| 186 |
setFeature("doUptext", false); |
| 187 |
break; |
| 188 |
|
| 189 |
case 'u': |
| 190 |
setFeature("uptextOnRests", false); |
| 191 |
break; |
| 192 |
|
| 193 |
case 'v': |
| 194 |
setFeature("beVerbose", true); |
| 195 |
break; |
| 196 |
|
| 197 |
case 'w': |
| 198 |
setFeature("pedanticWarnings", true); |
| 199 |
break; |
| 200 |
|
| 201 |
case 'D': |
| 202 |
setFeature("debugMode", true); |
| 203 |
break; |
| 204 |
|
| 205 |
case 'H': |
| 206 |
printFeatures(true); |
| 207 |
break; |
| 208 |
|
| 209 |
default: |
| 210 |
if (isdigit(j)) |
| 211 |
choice = j; |
| 212 |
else { |
| 213 |
putchar(j); |
| 214 |
error(": invalid option", !print); |
| 215 |
} |
| 216 |
break; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
/* Local variables for OpenFiles: */ |
| 222 |
struct LOC_OpenFiles { |
| 223 |
short testin; |
| 224 |
Char basename[256]; |
| 225 |
} ; |
| 226 |
|
| 227 |
Local void checkExistingFile(struct LOC_OpenFiles *LINK) |
| 228 |
{ |
| 229 |
FILE *tryfile; |
| 230 |
Char tryfile_NAME[_FNSIZE]; |
| 231 |
|
| 232 |
strcpy(tryfile_NAME, LINK->basename); |
| 233 |
tryfile = fopen(tryfile_NAME, "r+b"); |
| 234 |
_SETIO(tryfile != NULL, FileNotFound); |
| 235 |
LINK->testin = P_ioresult; |
| 236 |
if (LINK->testin != 0) |
| 237 |
return; |
| 238 |
if (tryfile != NULL) |
| 239 |
fclose(tryfile); |
| 240 |
printf("There exists a file named %s. I am treating this\n", |
| 241 |
LINK->basename); |
| 242 |
error(" as a fatal error unless you specify -i", !print); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
void OpenFiles(void) |
| 247 |
{ |
| 248 |
struct LOC_OpenFiles V; |
| 249 |
short i, j, l; |
| 250 |
short fileid = 0; |
| 251 |
Char infilename[256], outfilename[256], param[256], ext[256]; |
| 252 |
short FORLIM1; |
| 253 |
Char STR3[256]; |
| 254 |
|
| 255 |
line_no = 0; |
| 256 |
paragraph_no = 0; |
| 257 |
for (i = 1; i <= P_argc - 1; i++) { |
| 258 |
strcpy(param, P_argv[i]); |
| 259 |
if (param[0] == param_leader) { |
| 260 |
FORLIM1 = strlen(param); |
| 261 |
for (j = 1; j <= FORLIM1 - 1; j++) |
| 262 |
processOption(param[j]); |
| 263 |
} else if (fileid == 0) |
| 264 |
fileid = i; |
| 265 |
else if (*texdir == '\0') |
| 266 |
strcpy(texdir, param); |
| 267 |
else |
| 268 |
strcpy(stylefilename, param); |
| 269 |
} |
| 270 |
if (fileid == 0) { |
| 271 |
helpmessage(); |
| 272 |
printf("Try \"prepmx -h\" for more information.\n"); |
| 273 |
_Escape(255); |
| 274 |
} |
| 275 |
strcpy(V.basename, P_argv[fileid]); |
| 276 |
l = strlen(V.basename); |
| 277 |
if (l > 4 && V.basename[l-4] == '.') { |
| 278 |
substr_(ext, V.basename, l - 2, 3); |
| 279 |
toUpper(ext); |
| 280 |
if (!strcmp(ext, "MTX")) { |
| 281 |
warning(".mtx extension deleted from basename", !print); |
| 282 |
shorten(V.basename, l - 4); |
| 283 |
} |
| 284 |
} |
| 285 |
if (pos1('.', V.basename) > 0) |
| 286 |
checkExistingFile(&V); |
| 287 |
sprintf(infilename, "%s.mtx", V.basename); |
| 288 |
sprintf(outfilename, "%s.pmx", V.basename); |
| 289 |
pushFile(infilename); |
| 290 |
strcpy(outfile_NAME, outfilename); |
| 291 |
if (outfile != NULL) |
| 292 |
outfile = freopen(outfile_NAME, "wb", outfile); |
| 293 |
else |
| 294 |
outfile = fopen(outfile_NAME, "wb"); |
| 295 |
_SETIO(outfile != NULL, FileNotFound); |
| 296 |
strcpy(stylefile_NAME, stylefilename); |
| 297 |
if (stylefile != NULL) |
| 298 |
stylefile = freopen(stylefile_NAME, "r", stylefile); |
| 299 |
else |
| 300 |
stylefile = fopen(stylefile_NAME, "r"); |
| 301 |
_SETIO(stylefile != NULL, FileNotFound); |
| 302 |
teststyle = P_ioresult; |
| 303 |
if (teststyle != 0 && strcmp(stylefilename, "mtxstyle.txt")) |
| 304 |
_SETIO(printf("Can't read %s\n", stylefilename) >= 0, FileWriteError); |
| 305 |
if (fileError()) { |
| 306 |
sprintf(STR3, "Input file %s not found", infilename); |
| 307 |
fatalerror(STR3); |
| 308 |
} |
| 309 |
outfile_open = true; |
| 310 |
printf("Writing to %s.pmx\n", V.basename); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
void CloseFiles(void) |
| 315 |
{ |
| 316 |
if (outfile != NULL) |
| 317 |
fclose(outfile); |
| 318 |
outfile = NULL; |
| 319 |
closeAll(); |
| 320 |
if (teststyle != 0) |
| 321 |
return; |
| 322 |
if (stylefile != NULL) |
| 323 |
fclose(stylefile); |
| 324 |
stylefile = NULL; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
void readParagraph(Char (*P)[256], short *no, paragraph_index0 *L) |
| 329 |
{ |
| 330 |
boolean another; |
| 331 |
Char filename[256], buffer[256]; |
| 332 |
Char STR1[256], STR3[256]; |
| 333 |
|
| 334 |
*L = 0; |
| 335 |
readData(buffer); |
| 336 |
line_no = currentLineNo(); |
| 337 |
if (isEmpty(buffer)) |
| 338 |
return; |
| 339 |
if (debugMode()) |
| 340 |
printf(">>>> %s\n", buffer); |
| 341 |
paragraph_no++; |
| 342 |
/* Handle directives affecting the processing of the input file */ |
| 343 |
do { |
| 344 |
another = false; |
| 345 |
if (startsWithIgnoreCase(buffer, "SUSPEND")) { |
| 346 |
ignore_input = true; |
| 347 |
another = true; |
| 348 |
if (beVerbose()) |
| 349 |
printf("-->> Suspending input file %s at line %d\n", |
| 350 |
currentFilename(STR3), line_no); |
| 351 |
} |
| 352 |
if (startsWithIgnoreCase(buffer, "RESUME")) { |
| 353 |
ignore_input = false; |
| 354 |
another = true; |
| 355 |
if (beVerbose()) |
| 356 |
printf("-->> Resuming input file %s at line %d\n", |
| 357 |
currentFilename(STR1), line_no); |
| 358 |
} |
| 359 |
if (startsWithIgnoreCase(buffer, "INCLUDE:")) { |
| 360 |
predelete(buffer, 8); |
| 361 |
NextWord(filename, buffer, ' ', ' '); |
| 362 |
pushFile(filename); |
| 363 |
another = true; |
| 364 |
} |
| 365 |
if (another) { |
| 366 |
readLine(buffer); |
| 367 |
line_no = currentLineNo(); |
| 368 |
} |
| 369 |
} while (another); |
| 370 |
/* Normal paragraph input*/ |
| 371 |
do { |
| 372 |
if (*L < lines_in_paragraph) { |
| 373 |
(*L)++; |
| 374 |
strcpy(P[*L - 1], buffer); |
| 375 |
*buffer = '\0'; |
| 376 |
no[*L - 1] = line_no; |
| 377 |
} else |
| 378 |
warning("Paragraph too long: skipping line", !print); |
| 379 |
readLine(buffer); |
| 380 |
line_no = currentLineNo(); |
| 381 |
if (debugMode()) |
| 382 |
printf("%d >> %s\n", line_no, buffer); |
| 383 |
} while (!isEmpty(buffer)); |
| 384 |
skipBlanks(); /* needed to identify final paragraph */ |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
/* End. */ |