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