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[Table_size];
30 static int *tfirst, *tlast, *tnext, tmax;
43 tfirst = (int *)realloc((char *)tfirst,
44 (tmax += TGULP)*sizeof(int));
47 "Pfile: realloc failure!\n");
50 tlast = tfirst + tmax;
59 "unexpected character 0x%.2x = '%c' on line %ld of %s\n",
60 c, c, Plineno, Pfname);
68 "unexpected type \"%s\" on line %ld of %s\n",
69 Ptok, Plineno, Pfname);
74 badflag(tname, option)
77 fprintf(stderr, "%s type from `f2c -%s` on line %ld of %s\n",
78 tname, option, Plineno, Pfname);
87 "%sdetected on line %ld of %s\n", msg, Plineno, Pfname);
95 static int lastmsg = 0;
96 static int seen[2] = {0,0};
103 "Illegal combination of LOGICAL types -- mixing -I4 with -I2 or -i2\n\t");
108 if (tylogical == TYLONG || lastmsg >= 2)
112 badflag("LOGICAL", "I4");
116 if (tylogical == TYSHORT || lastmsg & 1)
120 badflag("LOGICAL", "i2` or `f2c -I2");
128 static int warned = 0;
129 static int seen[2] = {0,0};
134 detected("Illegal mixture of -R and -!R ");
138 if (k == forcedouble || warned)
141 badflag("REAL return", k ? "!R" : "R");
153 "%s cannot be both a procedure and a common block (line %ld of %s)\n",
154 e->fextname, Plineno, Pfname);
164 if ((c = getc(pf)) < '0' || c > '9')
168 if ((c = getc(pf)) == ' ') {
172 if (c < '0' || c > '9')
179 static void argverify(), Pbadret();
182 readref(pf, e, ftype)
194 if ((c = numread(pf, &nargs)) != ' ') {
197 /* just a typed external */
198 if (e->extstg == STGUNKNOWN) {
202 if (e->extstg == STGEXT) {
203 if (e->extype != ftype)
212 for(i = 0; i < nargs; i++) {
213 if ((c = numread(pf, &type)) != ' '
215 || type != TYFTNLEN + 100 && type % 100 > TYSUBR)
222 if (e->extstg == STGUNKNOWN) {
225 gmem(sizeof(Argtypes) + (nargs-1)*sizeof(Atype), 1);
230 for(ae = a + nargs; a < ae; a++) {
239 else if (e->extstg != STGEXT) {
242 else if (!e->arginfo) {
243 if (e->extype != ftype)
258 register char *s, *se;
259 char buf[128], cbuf[128];
264 if ((c = getc(pf)) == EOF)
281 if ((c = getc(pf)) == EOF)
287 se = buf + sizeof(buf) - 1;
289 if ((c = getc(pf)) == EOF)
293 if (s >= se || Pct[c] != P_anum)
298 if (s <= buf || *s != '_')
308 if ((c = getc(pf)) == EOF)
312 if (c < '0' && c > '9')
318 e = mkext(buf, cbuf);
320 return readref(pf, e, (int)L);
321 if (e->extstg == STGUNKNOWN) {
322 e->extstg = STGCOMMON;
325 else if (e->extstg != STGCOMMON)
327 else if (e->maxleng != L) {
329 "incompatible lengths for common block %s (line %ld of %s)\n",
330 buf, Plineno, Pfname);
343 register char *s, *se;
353 if (Pct[c] != P_space)
363 se = s + sizeof(Ptok) - 1;
367 if ((c = getc(pf)) == EOF) {
370 "unexpected end of file in %s\n",
375 while(Pct[c] == P_anum);
384 if ((c = getc(pf)) != '*') {
389 if (canend && comlen(pf))
392 while((c = getc(pf)) != '*') {
420 if (!strcmp(Ptok+1, "_f"))
424 if (!strcmp(Ptok+1, "_f")) {
425 /* TYREAL under forcedouble */
431 if (!strcmp(Ptok+1, "_f"))
435 if (!strcmp(Ptok+1, "_f"))
439 if (!strcmp(Ptok+1, "oublereal"))
443 if (!strcmp(Ptok+1, "nt"))
445 if (!strcmp(Ptok+1, "nteger"))
449 if (!strcmp(Ptok+1, "ogical")) {
455 if (!strcmp(Ptok+1, "eal")) {
461 if (!strcmp(Ptok+1, "hortint"))
463 if (!strcmp(Ptok+1, "hortlogical")) {
483 fprintf(stderr,"Error: expected %s, not \"%s\" (line %ld of %s)\n",
484 what, Ptok, Plineno, Pfname);
503 if (!strcmp(Ptok+1, "_fp"))
507 if (!strcmp(Ptok+1, "_fp"))
512 if (!strcmp(Ptok+1, "_fp"))
516 if (!strcmp(Ptok+1, "_fp"))
520 if (!strcmp(Ptok+1, "_fp"))
524 if (!strcmp(Ptok+1, "_fp"))
533 if (!strcmp(Ptok+1, "_fp"))
537 if (!strcmp(Ptok+1, "_fp"))
541 if (!strcmp(Ptok+1, "_fp"))
545 if (!strcmp(Ptok+1, "_fp"))
549 if (!strcmp(Ptok+1, "har"))
551 else if (!strcmp(Ptok+1, "omplex"))
555 if (!strcmp(Ptok+1, "oublereal"))
557 else if (!strcmp(Ptok+1, "oublecomplex"))
561 if (!strcmp(Ptok+1, "tnlen"))
565 if (!strcmp(Ptok+1, "nteger"))
569 if (!strcmp(Ptok+1, "ogical")) {
575 if (!strcmp(Ptok+1, "eal"))
579 if (!strcmp(Ptok+1, "hortint"))
581 else if (!strcmp(Ptok+1, "hortlogical")) {
587 if (tnext == tfirst && !strcmp(Ptok+1, "oid")) {
588 if ((i = Ptoken(pf,0)) != /*(*/ ')')
589 wanted(i, /*(*/ "\")\"");
595 if (rv < 100 && (i = Ptoken(pf,0)) != '*')
597 if ((i = Ptoken(pf,0)) == P_anum)
598 i = Ptoken(pf,0); /* skip variable name */
606 wanted(i, "\",\" or \")\"");
616 static char buf[128];
618 s = Ptok + strlen(Ptok) - 1;
621 "warning: %s does not end in _ (line %ld of %s)\n",
622 Ptok, Plineno, Pfname);
627 strncpy(buf, Ptok, n = s - Ptok);
638 fprintf(stderr, "%s for %s (line %ld of %s):\n\t", msg,
639 p->fextname, Plineno, Pfname);
640 p->arginfo->nargs = -1;
650 char buf1[32], buf2[32];
652 Pbadmsg("inconsistent types",p);
653 fprintf(stderr, "here %s, previously %s\n",
654 Argtype(ftype+200,buf1),
655 Argtype(p->extype+200,buf2));
666 register int *t, *te;
667 char buf1[32], buf2[32];
673 if (p->extype != ftype) {
680 if (at->nargs != i) {
682 Pbadmsg("differing numbers of arguments",p);
683 fprintf(stderr, "here %d, previously %d\n",
687 for(aty = at->atypes; t < te; t++, aty++) {
692 if (k >= 300 || k == j)
696 if (k == TYUNKNOWN + 200)
698 if (j % 100 != k - 200
700 && j != TYUNKNOWN + 300
701 && !type_fixup(at,aty,k))
704 else if (j % 100 % TYSUBR != k % TYSUBR
705 && !type_fixup(at,aty,k))
708 else if (k < 200 || j < 200)
710 else if (k == TYUNKNOWN+200)
712 else if (j != TYUNKNOWN+200)
715 Pbadmsg("differing calling sequences",p);
718 "arg %d: here %s, prevously %s\n",
719 i, Argtype(k,buf1), Argtype(j,buf2));
722 /* We've subsequently learned the right type,
723 as in the call on zoo below...
725 subroutine foo(x, zap)
744 register int *t, *te;
747 if (p->extstg == STGCOMMON) {
757 k = sizeof(Argtypes) + (i-1)*sizeof(Atype);
758 at = p->arginfo = (Argtypes *)gmem(k,1);
761 for(aty = at->atypes; t < te; aty++) {
776 for(s = fname; *s; s++);
779 || (s[-1] != 'P' && s[-1] != 'p'))
782 if (!(pf = fopen(fname, textread))) {
783 fprintf(stderr, "can't open %s\n", fname);
789 for(s = " \t\n\r\013\f"; *s; s++) /* ACK_MOD: \v is not K&R C */
791 for(s = "*,();"; *s; s++)
793 for(i = '0'; i <= '9'; i++)
795 for(s = "abcdefghijklmnopqrstuvwxyz"; i = *s; s++)
796 Pct[i] = Pct[i+'A'-'a'] = P_anum;
802 if (!(i = Ptoken(pf,1)))
805 || !strcmp(Ptok, "extern")
806 && (i = Ptoken(pf,0)) != P_anum)
810 if ((i = Ptoken(pf,0)) != P_anum)
812 p = mkext(trimunder(), Ptok);
814 if ((i = Ptoken(pf,0)) != '(')
817 while(i = Ptype(pf)) {
833 wanted(i, "\";\" or \",\"");
844 char **f1files, **f1files0, *s;
846 register Extsym *e, *ee;
847 register Argtypes *at;
850 f1files0 = f1files = ffiles;
857 free((char *)tfirst);
858 /* following should be unnecessary, as we won't be back here */
859 tfirst = tnext = tlast = 0;
863 if (f1files == f1files0)
868 for (e = extsymtab; e < ee; e++)
869 if (e->extstg == STGEXT
870 && (at = e->arginfo)) {
871 if (at->nargs < 0 || at->changes)
877 "%d prototype%s updated while reading prototypes.\n", k,