1 /****************************************************************
2 Copyright 1990 by AT&T Bell Laboratories and Bellcore.
4 Permission to use, copy, modify, and distribute this software
5 and its documentation for any purpose and without fee is hereby
6 granted, provided that the above copyright notice appear in all
7 copies and that both that the copyright notice and this
8 permission notice and warranty disclaimer appear in supporting
9 documentation, and that the names of AT&T Bell Laboratories or
10 Bellcore or any of their entities not be used in advertising or
11 publicity pertaining to distribution of the software without
12 specific, written prior permission.
14 AT&T and Bellcore disclaim all warranties with regard to this
15 software, including all implied warranties of merchantability
16 and fitness. In no event shall AT&T or Bellcore be liable for
17 any special, indirect or consequential damages or any damages
18 whatsoever resulting from loss of use, data or profits, whether
19 in an action of contract, negligence or other tortious action,
20 arising out of or in connection with the use or performance of
22 ****************************************************************/
26 char binread[] = "rb", textread[] = "r";
27 char binwrite[] = "wb", textwrite[] = "w";
28 char *c_functions = "c_functions";
29 char *coutput = "c_output";
30 char *initfname = "raw_data";
31 char *initbname = "raw_data.b";
32 char *blkdfname = "block_data";
33 char *p1_file = "p1_file";
34 char *p1_bakfile = "p1_file.BAK";
35 char *sortfname = "init_file";
37 char link_msg[] = "-lF77 -lI77 -lm -lc";
47 char *tmpdir = TMPDIR;
58 if (cdelete && coutput)
69 k = strlen(tmpdir) + 16;
70 c_functions = (char *)ckalloc(7*k);
71 initfname = c_functions + k;
72 initbname = initfname + k;
73 blkdfname = initbname + k;
74 p1_file = blkdfname + k;
75 p1_bakfile = p1_file + k;
76 sortfname = p1_bakfile + k;
80 if (!*tmpdir || *tmpdir == '.' && !tmpdir[1])
83 /* substitute \ for / to avoid confusion with a
84 * switch indicator in the system("sort ...")
85 * call in formatdata.c
87 for(s = tmpdir, t = buf; *s; s++, t++)
95 sprintf(c_functions, "%sf2c_func", t);
96 sprintf(initfname, "%sf2c_rd", t);
97 sprintf(blkdfname, "%sf2c_blkd", t);
98 sprintf(p1_file, "%sf2c_p1f", t);
99 sprintf(p1_bakfile, "%sf2c_p1fb", t);
100 sprintf(sortfname, "%sf2c_sort", t);
103 sprintf(c_functions, "%s/f2c%d_func", tmpdir, pid);
104 sprintf(initfname, "%s/f2c%d_rd", tmpdir, pid);
105 sprintf(blkdfname, "%s/f2c%d_blkd", tmpdir, pid);
106 sprintf(p1_file, "%s/f2c%d_p1f", tmpdir, pid);
107 sprintf(p1_bakfile, "%s/f2c%d_p1fb", tmpdir, pid);
108 sprintf(sortfname, "%s/f2c%d_sort", tmpdir, pid);
110 sprintf(initbname, "%s.b", initfname);
113 fprintf(diagfile, "%s %s %s %s %s %s\n", c_functions,
114 initfname, blkdfname, p1_file, p1_bakfile, sortfname);
127 if (--s < s0 + 3 || s[-2] != '.'
128 || ((c = *--s) != 'f' && c != 'F')) {
130 Fatal("file name must end in .f or .F");
141 signal(SIGINT, SIG_IGN);
143 signal(SIGQUIT, SIG_IGN);
146 signal(SIGHUP, SIG_IGN);
148 signal(SIGTERM, SIG_IGN);
154 sig1catch(sig) int sig;
156 if (signal(sig, SIG_IGN) != SIG_IGN)
163 Fatal("floating exception during constant evaluation; cannot recover");
164 /* vax returns a reserved operand that generates
165 an illegal operand fault on next instruction,
166 which if ignored causes an infinite loop.
168 signal(SIGFPE, flovflo);
182 signal(SIGFPE, flovflo); /* catch overflows */
189 Fatal("Only one Fortran input file allowed under MS-DOS");
198 while((w = wait(&status)) != pid)
200 Fatal("bad wait code");
201 retcode |= status >> 8;
206 /* Initialization of tables that change with the character set... */
208 char escapes[Table_size];
211 char *str_fmt[Table_size];
212 static char *str0fmt[127] = { /*}*/
214 char *str_fmt[Table_size] = {
216 "\\000", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
217 "\\b", "\\t", "\\n", "\\013", "\\f", "\\r", "\\016", "\\017",
218 "\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
219 "\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
220 " ", "!", "\\\"", "#", "$", "%%", "&", "'",
221 "(", ")", "*", "+", ",", "-", ".", "/",
222 "0", "1", "2", "3", "4", "5", "6", "7",
223 "8", "9", ":", ";", "<", "=", ">", "?",
224 "@", "A", "B", "C", "D", "E", "F", "G",
225 "H", "I", "J", "K", "L", "M", "N", "O",
226 "P", "Q", "R", "S", "T", "U", "V", "W",
227 "X", "Y", "Z", "[", "\\\\", "]", "^", "_",
228 "`", "a", "b", "c", "d", "e", "f", "g",
229 "h", "i", "j", "k", "l", "m", "n", "o",
230 "p", "q", "r", "s", "t", "u", "v", "w",
231 "x", "y", "z", "{", "|", "}", "~"
235 char *chr_fmt[Table_size];
236 static char *chr0fmt[127] = { /*}*/
238 char *chr_fmt[Table_size] = {
240 "\\0", "\\1", "\\2", "\\3", "\\4", "\\5", "\\6", "\\7",
241 "\\b", "\\t", "\\n", "\\13", "\\f", "\\r", "\\16", "\\17",
242 "\\20", "\\21", "\\22", "\\23", "\\24", "\\25", "\\26", "\\27",
243 "\\30", "\\31", "\\32", "\\33", "\\34", "\\35", "\\36", "\\37",
244 " ", "!", "\"", "#", "$", "%%", "&", "\\'",
245 "(", ")", "*", "+", ",", "-", ".", "/",
246 "0", "1", "2", "3", "4", "5", "6", "7",
247 "8", "9", ":", ";", "<", "=", ">", "?",
248 "@", "A", "B", "C", "D", "E", "F", "G",
249 "H", "I", "J", "K", "L", "M", "N", "O",
250 "P", "Q", "R", "S", "T", "U", "V", "W",
251 "X", "Y", "Z", "[", "\\\\", "]", "^", "_",
252 "`", "a", "b", "c", "d", "e", "f", "g",
253 "h", "i", "j", "k", "l", "m", "n", "o",
254 "p", "q", "r", "s", "t", "u", "v", "w",
255 "x", "y", "z", "{", "|", "}", "~"
261 static char *str1fmt[6] =
262 { "\\b", "\\t", "\\n", "\\f", "\\r", "\\%03o" };
273 for(; i < Table_size; i++)
274 str_fmt[i] = "\\%03o";
276 for(i = 32; i < 127; i++) {
278 str_fmt[*(unsigned char *)s] = s;
280 str_fmt['"'] = "\\\"";
283 str_fmt[7] = chr_fmt[7] = "\\a";
289 for(i = 0; i < 32; i++)
290 chr_fmt[i] = chr0fmt[i];
294 for(; i < Table_size; i++)
297 for(i = 32; i < 127; i++) {
299 j = *(unsigned char *)s;
301 j = *(unsigned char *)(s+1);
306 /* escapes (used in lex.c) */
308 for(i = 0; i < Table_size; i++)
310 for(s = "btnfr0", i = 0; i < 6; i++)
311 escapes[*(unsigned char *)s++] = "\b\t\n\f\r"[i];
312 /* finish str_fmt and chr_fmt */
316 if ('\v' == 'v') { /* ancient C compiler */
324 for(s = "\b\t\n\f\r\v", i = 0; j = *(unsigned char *)s++;)
325 str_fmt[j] = chr_fmt[j] = str1fmt[i++];
326 /* '\v' = 11 for both EBCDIC and ASCII... */
327 chr_fmt[11] = Ansi ? "\\v" : "\\13";
332 /* Unless SYSTEM_SORT is defined, the following gives a simple
333 * in-core version of dsort(). On Fortran source with huge DATA
334 * statements, the in-core version may exhaust the available memory,
335 * in which case you might either recompile this source file with
336 * SYSTEM_SORT defined (if that's reasonable on your system), or
337 * replace the dsort below with a more elaborate version that
338 * does a merging sort with the help of auxiliary files.
347 sprintf(buf, "sort <%s >%s", from, to);
348 return system(buf) >> 8;
354 compare(const void *a, const void *b)
359 { return strcmp(*(char **)a, *(char **)b); }
364 extern char *Alloc();
371 typedef struct Memb memb;
373 register char *x, *x0, *xe;
379 f = opf(from, textread);
380 mb = (memb *)Alloc(sizeof(memb));
383 xe = x + sizeof(mb->buf);
387 if (x >= xe && (c != EOF || x != x0)) {
392 mb1 = (memb *)Alloc(sizeof(memb));
395 memcpy(mb->buf, x0, n = x-x0);
398 xe = x0 + sizeof(mb->buf);
412 f = opf(to, textwrite);
413 if (x > x0) { /* shouldn't happen */
419 if (!nn) /* shouldn't happen */
421 z = z0 = (char **)Alloc(nn*sizeof(char *));
422 for(mb1 = mb; mb1; mb1 = mb1->next) {
432 qsort((char *)z0, nn, sizeof(char *), compare);
433 for(n = nn, z = z0; n > 0; n--)
434 fprintf(f, "%s\n", *z++);