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 static char Ptok[128], Pct[256];
30 static int *tfirst, *tlast, *tnext, tmax;
44 tfirst = (int *)realloc((char *)tfirst,
45 (tmax += TGULP)*sizeof(int));
48 "Pfile: realloc failure!\n");
51 tlast = tfirst + tmax;
60 "unexpected character 0x%.2x = '%c' on line %ld of %s\n",
61 c, c, Plineno, Pfname);
69 "unexpected type \"%s\" on line %ld of %s\n",
70 Ptok, Plineno, Pfname);
75 badflag(tname, option)
78 fprintf(stderr, "%s type from `f2c -%s` on line %ld of %s\n",
79 tname, option, Plineno, Pfname);
88 "%sdetected on line %ld of %s\n", msg, Plineno, Pfname);
96 static int lastmsg = 0;
97 static int seen[2] = {0,0};
104 "Illegal combination of LOGICAL types -- mixing -I4 with -I2 or -i2\n\t");
109 if (tylogical == TYLONG || lastmsg >= 2)
113 badflag("LOGICAL", "I4");
117 if (tylogical == TYSHORT || lastmsg & 1)
121 badflag("LOGICAL", "i2` or `f2c -I2");
129 static int warned = 0;
130 static int seen[2] = {0,0};
135 detected("Illegal mixture of -R and -!R ");
139 if (k == forcedouble || warned)
142 badflag("REAL return", k ? "!R" : "R");
154 "%s cannot be both a procedure and a common block (line %ld of %s)\n",
155 e->fextname, Plineno, Pfname);
165 if ((c = getc(pf)) < '0' || c > '9')
169 if ((c = getc(pf)) == ' ') {
173 if (c < '0' || c > '9')
180 static void argverify(), Pbadret();
183 readref(pf, e, ftype)
195 if ((c = numread(pf, &nargs)) != ' ') {
198 /* just a typed external */
199 if (e->extstg == STGUNKNOWN) {
203 if (e->extstg == STGEXT) {
204 if (e->extype != ftype)
213 for(i = 0; i < nargs; i++) {
214 if ((c = numread(pf, &type)) != ' '
216 || type != TYFTNLEN + 100 && type % 100 > TYSUBR)
223 if (e->extstg == STGUNKNOWN) {
226 gmem(sizeof(Argtypes) + (nargs-1)*sizeof(Atype), 1);
231 for(ae = a + nargs; a < ae; a++) {
240 else if (e->extstg != STGEXT) {
243 else if (!e->arginfo) {
244 if (e->extype != ftype)
259 register char *s, *se;
260 char buf[128], cbuf[128];
265 if ((c = getc(pf)) == EOF)
282 if ((c = getc(pf)) == EOF)
288 se = buf + sizeof(buf) - 1;
290 if ((c = getc(pf)) == EOF)
294 if (s >= se || Pct[c] != P_anum)
299 if (s <= buf || *s != '_')
309 if ((c = getc(pf)) == EOF)
313 if (c < '0' && c > '9')
319 e = mkext(buf, cbuf);
321 return readref(pf, e, (int)L);
322 if (e->extstg == STGUNKNOWN) {
323 e->extstg = STGCOMMON;
326 else if (e->extstg != STGCOMMON)
328 else if (e->maxleng != L) {
330 "incompatible lengths for common block %s (line %ld of %s)\n",
331 buf, Plineno, Pfname);
344 register char *s, *se;
354 if (Pct[c] != P_space)
364 se = s + sizeof(Ptok) - 1;
368 if ((c = getc(pf)) == EOF) {
371 "unexpected end of file in %s\n",
376 while(Pct[c] == P_anum);
385 if ((c = getc(pf)) != '*') {
390 if (canend && comlen(pf))
393 while((c = getc(pf)) != '*') {
421 if (!strcmp(Ptok+1, "_f"))
425 if (!strcmp(Ptok+1, "_f")) {
426 /* TYREAL under forcedouble */
432 if (!strcmp(Ptok+1, "_f"))
436 if (!strcmp(Ptok+1, "_f"))
440 if (!strcmp(Ptok+1, "oublereal"))
444 if (!strcmp(Ptok+1, "nt"))
446 if (!strcmp(Ptok+1, "nteger"))
450 if (!strcmp(Ptok+1, "ogical")) {
456 if (!strcmp(Ptok+1, "eal")) {
462 if (!strcmp(Ptok+1, "hortint"))
464 if (!strcmp(Ptok+1, "hortlogical")) {
484 fprintf(stderr,"Error: expected %s, not \"%s\" (line %ld of %s)\n",
485 what, Ptok, Plineno, Pfname);
504 if (!strcmp(Ptok+1, "_fp"))
508 if (!strcmp(Ptok+1, "_fp"))
513 if (!strcmp(Ptok+1, "_fp"))
517 if (!strcmp(Ptok+1, "_fp"))
521 if (!strcmp(Ptok+1, "_fp"))
525 if (!strcmp(Ptok+1, "_fp"))
534 if (!strcmp(Ptok+1, "_fp"))
538 if (!strcmp(Ptok+1, "_fp"))
542 if (!strcmp(Ptok+1, "_fp"))
546 if (!strcmp(Ptok+1, "_fp"))
550 if (!strcmp(Ptok+1, "har"))
552 else if (!strcmp(Ptok+1, "omplex"))
556 if (!strcmp(Ptok+1, "oublereal"))
558 else if (!strcmp(Ptok+1, "oublecomplex"))
562 if (!strcmp(Ptok+1, "tnlen"))
566 if (!strcmp(Ptok+1, "nteger"))
570 if (!strcmp(Ptok+1, "ogical")) {
576 if (!strcmp(Ptok+1, "eal"))
580 if (!strcmp(Ptok+1, "hortint"))
582 else if (!strcmp(Ptok+1, "hortlogical")) {
588 if (tnext == tfirst && !strcmp(Ptok+1, "oid")) {
589 if ((i = Ptoken(pf,0)) != /*(*/ ')')
590 wanted(i, /*(*/ "\")\"");
596 if (rv < 100 && (i = Ptoken(pf,0)) != '*')
598 if ((i = Ptoken(pf,0)) == P_anum)
599 i = Ptoken(pf,0); /* skip variable name */
607 wanted(i, "\",\" or \")\"");
617 static char buf[128];
619 s = Ptok + strlen(Ptok) - 1;
622 "warning: %s does not end in _ (line %ld of %s)\n",
623 Ptok, Plineno, Pfname);
628 strncpy(buf, Ptok, n = s - Ptok);
639 fprintf(stderr, "%s for %s (line %ld of %s):\n\t", msg,
640 p->fextname, Plineno, Pfname);
641 p->arginfo->nargs = -1;
651 char buf1[32], buf2[32];
653 Pbadmsg("inconsistent types",p);
654 fprintf(stderr, "here %s, previously %s\n",
655 Argtype(ftype+200,buf1),
656 Argtype(p->extype+200,buf2));
667 register int *t, *te;
668 char buf1[32], buf2[32];
674 if (p->extype != ftype) {
681 if (at->nargs != i) {
683 Pbadmsg("differing numbers of arguments",p);
684 fprintf(stderr, "here %d, previously %d\n",
688 for(aty = at->atypes; t < te; t++, aty++) {
693 if (k >= 300 || k == j)
697 if (k == TYUNKNOWN + 200)
699 if (j % 100 != k - 200
701 && j != TYUNKNOWN + 300
702 && !type_fixup(at,aty,k))
705 else if (j % 100 % TYSUBR != k % TYSUBR
706 && !type_fixup(at,aty,k))
709 else if (k < 200 || j < 200)
711 else if (k == TYUNKNOWN+200)
713 else if (j != TYUNKNOWN+200)
716 Pbadmsg("differing calling sequences",p);
719 "arg %d: here %s, prevously %s\n",
720 i, Argtype(k,buf1), Argtype(j,buf2));
723 /* We've subsequently learned the right type,
724 as in the call on zoo below...
726 subroutine foo(x, zap)
745 register int *t, *te;
748 if (p->extstg == STGCOMMON) {
758 k = sizeof(Argtypes) + (i-1)*sizeof(Atype);
759 at = p->arginfo = (Argtypes *)gmem(k,1);
762 for(aty = at->atypes; t < te; aty++) {
777 for(s = fname; *s; s++);
780 || (s[-1] != 'P' && s[-1] != 'p'))
783 if (!(pf = fopen(fname, textread))) {
784 fprintf(stderr, "can't open %s\n", fname);
790 for(s = " \t\n\r\v\f"; *s; s++)
792 for(s = "*,();"; *s; s++)
794 for(i = '0'; i <= '9'; i++)
796 for(s = "abcdefghijklmnopqrstuvwxyz"; i = *s; s++)
797 Pct[i] = Pct[i+'A'-'a'] = P_anum;
803 if (!(i = Ptoken(pf,1)))
806 || !strcmp(Ptok, "extern")
807 && (i = Ptoken(pf,0)) != P_anum)
811 if ((i = Ptoken(pf,0)) != P_anum)
813 p = mkext(trimunder(), Ptok);
815 if ((i = Ptoken(pf,0)) != '(')
818 while(i = Ptype(pf)) {
834 wanted(i, "\";\" or \",\"");
845 char **f1files, **f1files0, *s;
847 register Extsym *e, *ee;
848 register Argtypes *at;
851 f1files0 = f1files = ffiles;
858 free((char *)tfirst);
859 /* following should be unnecessary, as we won't be back here */
860 tfirst = tnext = tlast = 0;
864 if (f1files == f1files0)
869 for (e = extsymtab; e < ee; e++)
870 if (e->extstg == STGEXT
871 && (at = e->arginfo)) {
872 if (at->nargs < 0 || at->changes)
878 "%d prototype%s updated while reading prototypes.\n", k,