Upgrade embedded pcc.
authorDavid Given <dg@cowlark.com>
Mon, 18 Apr 2016 17:04:52 +0000 (19:04 +0200)
committerDavid Given <dg@cowlark.com>
Mon, 18 Apr 2016 17:04:52 +0000 (19:04 +0200)
--HG--
branch : default-branch

14 files changed:
lang/pcc/UPSTREAM_VERSION
lang/pcc/pcc/DATESTAMP
lang/pcc/pcc/cc/ccom/cgram.y
lang/pcc/pcc/cc/ccom/gcc_compat.c
lang/pcc/pcc/cc/ccom/init.c
lang/pcc/pcc/cc/ccom/optim.c
lang/pcc/pcc/cc/ccom/trees.c
lang/pcc/pcc/cc/cpp/cpp.c
lang/pcc/pcc/cc/cpp/cpp.h
lang/pcc/pcc/cc/cpp/token.c
lang/pcc/pcc/config.h.in
lang/pcc/pcc/configure
lang/pcc/pcc/configure.ac
lang/pcc/pcc/mip/reader.c

index df6ac44..ba2e935 100644 (file)
@@ -1,2 +1,2 @@
-ftp://pcc.ludd.ltu.se/pub/pcc/pcc-20160315.tgz
+ftp://pcc.ludd.ltu.se/pub/pcc/pcc-20160418.tgz
 
index 4ed5216..c75c25e 100644 (file)
@@ -1 +1 @@
-20160315
+20160413
index 86ae5b6..7e10ce1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: cgram.y,v 1.414 2016/03/05 15:31:24 ragge Exp $    */
+/*     $Id: cgram.y,v 1.415 2016/04/02 09:02:56 ragge Exp $    */
 
 /*
  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
@@ -953,9 +953,11 @@ statement:    e ';' { ecomp(eve($1)); symclear(blevel); }
                        p->n_type = DECREF(p->n_type);
                        q = eve($2);
 #ifdef TARGET_TIMODE  
+                       {
                        P1ND *r;
                        if ((r = gcc_eval_ticast(RETURN, p, q)) != NULL)
                                q = r;
+                       }
 #endif
 #ifndef NO_COMPLEX
                        if (ANYCX(q) || ANYCX(p))
index 374dad4..8b181b2 100644 (file)
@@ -1,4 +1,4 @@
-/*      $Id: gcc_compat.c,v 1.119 2015/11/13 17:11:40 ragge Exp $     */
+/*      $Id: gcc_compat.c,v 1.120 2016/04/02 09:02:56 ragge Exp $     */
 /*
  * Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
  * All rights reserved.
@@ -785,7 +785,7 @@ ticast(NODE *p, int u)
        switch (p->n_op) {
        case ICON:
                val = 0;
-               if (u == 0 && p->n_lval < 0)
+               if (u == 0 && glval(p) < 0)
                        val = -1;
                q = eve(biop(DOT, bdty(NAME, n), bdty(NAME, loti)));
                q = buildtree(ASSIGN, q, p);
@@ -803,7 +803,7 @@ ticast(NODE *p, int u)
                if (u2) {
                        p = eve(biop(ASSIGN, p, bcon(0)));
                } else {
-                       q = buildtree(ASSIGN, eve(ccopy(p)), q);
+                       q = buildtree(ASSIGN, eve(p1tcopy(p)), q);
                        p = buildtree(RSEQ, eve(p), bcon(SZLONG-1));
                }
                q = buildtree(COMOP, q, p);
@@ -822,11 +822,12 @@ gcc_eval_ticast(int op, NODE *p1, NODE *p2)
        struct attr *a1, *a2;
        int t;
 
+       a2 = NULL; /* XXX flow analysis */
        if ((a1 = isti(p1)) == NULL && (a2 = isti(p2)) == NULL)
                return NIL;
 
        if (op == RETURN)
-               p1 = ccopy(p1);
+               p1 = p1tcopy(p1);
        if (a1 == NULL) {
                if (a2 == NULL)
                        cerror("gcc_eval_ticast error");
@@ -906,16 +907,16 @@ gcc_andorer(int op, NODE *p1, NODE *p2)
        t1 = tempnode(0, p1->n_type, p1->n_df, p1->n_ap);
        t2 = tempnode(0, p2->n_type, p2->n_df, p2->n_ap);
 
-       p1 = buildtree(ASSIGN, ccopy(t1), p1);
-       p2 = buildtree(ASSIGN, ccopy(t2), p2);
+       p1 = buildtree(ASSIGN, p1tcopy(t1), p1);
+       p2 = buildtree(ASSIGN, p1tcopy(t2), p2);
        p = buildtree(COMOP, p1, p2);
 
        p3 = buildtree(ADDROF, eve(bdty(NAME, n)), NIL);
-       p1 = buildtree(ASSIGN, structref(ccopy(p3), STREF, hiti),
-           buildtree(op, structref(ccopy(t1), STREF, hiti),
-           structref(ccopy(t2), STREF, hiti)));
+       p1 = buildtree(ASSIGN, structref(p1tcopy(p3), STREF, hiti),
+           buildtree(op, structref(p1tcopy(t1), STREF, hiti),
+           structref(p1tcopy(t2), STREF, hiti)));
        p = buildtree(COMOP, p, p1);
-       p1 = buildtree(ASSIGN, structref(ccopy(p3), STREF, loti),
+       p1 = buildtree(ASSIGN, structref(p1tcopy(p3), STREF, loti),
            buildtree(op, structref(t1, STREF, loti),
            structref(t2, STREF, loti)));
        p = buildtree(COMOP, p, p1);
@@ -1019,8 +1020,8 @@ gcc_eval_timode(int op, NODE *p1, NODE *p2)
                sp = op == LS || op == LSEQ ? ashldi3sp :
                    isu ? lshrdi3sp : ashrdi3sp;
                p2 = cast(p2, INT, 0);
-               /* XXX p1 ccopy may have side effects */
-               p = doacall(sp, nametree(sp), buildtree(CM, ccopy(p1), p2));
+               /* XXX p1 p1tcopy may have side effects */
+               p = doacall(sp, nametree(sp), buildtree(CM, p1tcopy(p1), p2));
                if (op == LSEQ || op == RSEQ) {
                        p = buildtree(ASSIGN, p1, p);
                } else
@@ -1045,8 +1046,8 @@ gcc_eval_timode(int op, NODE *p1, NODE *p2)
                    op == MUL ? mulvti3sp :
                    op == DIV ? (isu ? udivti3sp : divti3sp) :
                    op == MOD ? (isu ? umodti3sp : modti3sp) : 0;
-               /* XXX p1 ccopy may have side effects */
-               p = doacall(sp, nametree(sp), buildtree(CM, ccopy(p1), p2));
+               /* XXX p1 p1tcopy may have side effects */
+               p = doacall(sp, nametree(sp), buildtree(CM, p1tcopy(p1), p2));
                if (isaop)
                        p = buildtree(ASSIGN, p1, p);
                else
index a18a557..481607a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: init.c,v 1.99 2015/11/17 19:19:40 ragge Exp $      */
+/*     $Id: init.c,v 1.100 2016/04/02 09:02:57 ragge Exp $     */
 
 /*
  * Copyright (c) 2004, 2007 Anders Magnusson (ragge@ludd.ltu.se).
@@ -1238,7 +1238,7 @@ simpleinit(struct symtab *sp, NODE *p)
                        sz = (int)tsize(sp->stype, sp->sdf, sp->sap);
                        p->n_type = ctype(LONGLONG);
                        inval(0, sz/2, p);
-                       p->n_lval = 0; /* XXX fix signed types */
+                       slval(p, 0); /* XXX fix signed types */
                        inval(0, sz/2, p);
                        tfree(p);
                        tfree(q);
index b91e6cd..ff1a6fc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: optim.c,v 1.61 2016/02/09 17:57:35 ragge Exp $     */
+/*     $Id: optim.c,v 1.63 2016/04/02 20:16:23 ragge Exp $     */
 /*
  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
  *
 # define SWAP(p,q) {sp=p; p=q; q=sp;}
 # define RCON(p) (p->n_right->n_op==ICON)
 # define RO(p) p->n_right->n_op
-# define RV(p) getlval(p->n_right)
+# define RV(p) glval(p->n_right)
 # define LCON(p) (p->n_left->n_op==ICON)
 # define LO(p) p->n_left->n_op
-# define LV(p) getlval(p->n_left)
+# define LV(p) glval(p->n_left)
 
 /* remove left node */
 static NODE *
@@ -253,6 +253,7 @@ again:      o = p->n_op;
                        p->n_right->n_left = p->n_right->n_right;
                }
                p->n_right->n_op = UMUL; /* for tfree() */
+               p1walkf(p, putjops, 0);
                tfree(p);
                p = q;
                break;
@@ -367,7 +368,7 @@ again:      o = p->n_op;
                break;
 
        case DIV:
-               if( nncon( p->n_right ) && getlval(p->n_right) == 1 )
+               if( nncon( p->n_right ) && glval(p->n_right) == 1 )
                        goto zapright;
                if (LCON(p) && RCON(p) && conval(p->n_left, DIV, p->n_right))
                        goto zapright;
index e7edeba..ccfd1db 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: trees.c,v 1.373 2016/03/05 15:49:36 ragge Exp $    */
+/*     $Id: trees.c,v 1.374 2016/04/02 09:47:12 ragge Exp $    */
 /*
  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
  * All rights reserved.
@@ -2702,7 +2702,7 @@ p2print(NODE *p)
 
        printf("%d %d ", p->n_type, p->n_qual);
        if (ty == LTYPE)
-               printf(CONFMT " ", p->n_lval);
+               printf(CONFMT " ", glval(p));
        if (ty != BITYPE) {
                if (p->n_op != NAME && p->n_op != ICON)
                        printf("%d ", p->n_rval);
index 05e4d37..482a614 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: cpp.c,v 1.258 2016/03/14 20:27:56 ragge Exp $      */
+/*     $Id: cpp.c,v 1.274 2016/04/12 18:49:35 ragge Exp $      */
 
 /*
  * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se).
 
 /*
  * Buffers used:
- *     - expansion buffers (via getobuf etc...)
+ *     - expansion buffers (BNORMAL)
  *     - string buffers (used to store macros)
- *     - tree buffers (used by macro search algorithm)
- *     - scratch buffer (identifier readin)
  */
 
-
-
-
-#define        SBSIZE  1000000
-
-static usch    sbf[SBSIZE];
 static int     counter;
 /* C command */
 
 int tflag;     /* traditional cpp syntax */
 #ifdef PCC_DEBUG
 int dflag;     /* debug printouts */
-//static void imp(const char *);
 static void prline(const usch *s);
 static void prrep(const usch *s);
 #define        DPRINT(x) if (dflag) printf x
@@ -94,10 +85,13 @@ static void prrep(const usch *s);
 
 int Aflag, Cflag, Eflag, Mflag, dMflag, Pflag, MPflag, MMDflag;
 char *Mfile, *MPfile;
-struct initar *initar;
 char *Mxfile;
 int warnings, Mxlen;
-FILE *of;
+static usch utbuf[CPPBUF];
+struct iobuf pb = { utbuf, 0, CPPBUF, 0, 1, BUTBUF };
+#if LIBVMF
+struct vspace ibspc;
+#endif
 
 /* include dirs */
 struct incs {
@@ -116,7 +110,6 @@ int trulvl;
 int    flslvl;
 int    elflvl;
 int    elslvl;
-usch *stringbuf = sbf;
 
 /*
  * Macro replacement list syntax:
@@ -155,8 +148,8 @@ struct blocker {
 struct blocker *blkidx[RECMAX];
 int blkidp;
 
-static struct iobuf *readargs2(usch **, struct symtab *sp, const usch **args);
-static int readargs1(struct symtab *sp, const usch **args);
+static struct iobuf *readargs2(struct iobuf *, struct symtab *sp, const usch **args);
+static struct iobuf *readargs1(struct symtab *sp, const usch **args);
 static struct iobuf *exparg(int, struct iobuf *, struct iobuf *, struct blocker *);
 static struct iobuf *subarg(struct symtab *sp, const usch **args, int, struct blocker *);
 static void usage(void);
@@ -166,16 +159,14 @@ static void vsheap(struct iobuf *, const char *, va_list);
 static int skipws(struct iobuf *ib);
 static int getyp(usch *s);
 
-usch locs[] =
-       { FILLOC, LINLOC, PRAGLOC, DEFLOC,
-           'd','e','f','i','n','e','d',0, CTRLOC };
-
 int
 main(int argc, char **argv)
 {
-       struct initar *it;
+       struct includ bic;
+       struct iobuf *fb = getobuf(BNORMAL);
        register int ch;
        const usch *fn1, *fn2;
+       char *a;
 
 #ifdef TIMING
        struct timeval t1, t2;
@@ -183,6 +174,13 @@ main(int argc, char **argv)
        (void)gettimeofday(&t1, NULL);
 #endif
 
+#if LIBVMF
+       if (vminit(2))
+               error("vminit");
+       if (vmopen(&ibspc, NULL) < 0)
+               error("vmopen ibspc");
+#endif
+
        while ((ch = getopt(argc, argv, "ACD:d:EI:i:MPS:tU:Vvx:")) != -1) {
                switch (ch) {
                case 'A': /* assembler input */
@@ -198,15 +196,17 @@ main(int argc, char **argv)
                        break;
 
                case 'D': /* define something */
+                       if ((a = strchr(optarg, '=')) != NULL)
+                               *a = ' ';
+                       bsheap(fb, "#define %s%s", optarg, a ? "\n" : " 1\n");
+                       break;
+
                case 'i': /* include */
+                       bsheap(fb, "#include \"%s\"\n", optarg);
+                       break;
+
                case 'U': /* undef */
-                       /* XXX should not need malloc() here */
-                       if ((it = xmalloc(sizeof(struct initar))) == NULL)
-                               error("couldn't apply -%c %s", ch, optarg);
-                       it->type = ch;
-                       it->str = optarg;
-                       it->next = initar;
-                       initar = it;
+                       bsheap(fb, "#undef %s\n", optarg);
                        break;
 
                case 'd':
@@ -294,11 +294,14 @@ main(int argc, char **argv)
        pragloc = lookup((const usch *)"_Pragma", ENTER);
        defloc = lookup((const usch *)"defined", ENTER);
        ctrloc = lookup((const usch *)"__COUNTER__", ENTER);
-       filloc->value = locs;
-       linloc->value = locs+1;
-       pragloc->value = locs+2;
-       defloc->value = locs+3; /* also have macro name here */
-       ctrloc->value = locs+12;
+       filloc->value = linloc->value = pragloc->value =
+           ctrloc->value = (const usch *)"";
+       defloc->value = defloc->namep;
+       filloc->type = FILLOC;
+       linloc->type = LINLOC;
+       pragloc->type = PRAGLOC;
+       defloc->type = DEFLOC;
+       ctrloc->type = CTRLOC;
 
        if (Mflag && !dMflag) {
                char *c;
@@ -321,10 +324,10 @@ main(int argc, char **argv)
        }
 
        if (argc == 2) {
-               if ((of = freopen(argv[1], "w", stdout)) == NULL)
+               close(1);
+               if (open(argv[1], O_WRONLY|O_CREAT, 0600) < 0)
                        error("Can't creat %s", argv[1]);
-       } else
-               of = stdout;
+       }
 
        if (argc && strcmp(argv[0], "-")) {
                fn1 = fn2 = (usch *)argv[0];
@@ -332,10 +335,29 @@ main(int argc, char **argv)
                fn1 = NULL;
                fn2 = (const usch *)"";
        }
+
+       /* initialization defines */
+       if (dMflag)
+               write(1, fb->buf, fb->cptr);
+       fb->buf[fb->cptr] = 0;
+       memset(&bic, 0, sizeof(bic));
+       bic.fname = bic.orgfn = (const usch *)"<command line>";
+       bic.lineno = 1;
+       bic.infil = -1;
+       bic.ib = fb;
+       fb->bsz = fb->cptr;
+       fb->cptr = 0;
+       ifiles = &bic;
+       fastscan();
+       bufree(fb);
+       ifiles = NULL;
+       /* end initial defines */
+
        if (pushfile(fn1, fn2, 0, NULL))
                error("cannot open %s", argv[0]);
 
-       fclose(of);
+       if (Mflag == 0)
+               write(1, pb.buf, pb.cptr);
 #ifdef TIMING
        (void)gettimeofday(&t2, NULL);
        t2.tv_sec -= t1.tv_sec;
@@ -360,28 +382,68 @@ void
 putob(struct iobuf *ob, int ch)
 {
        if (ob->cptr == ob->bsz) {
-               int sz = ob->bsz - ob->buf;
-               ob->buf = xrealloc(ob->buf, sz + BUFSIZ);
-               ob->cptr = ob->buf + sz;
-               ob->bsz = ob->buf + sz + BUFSIZ;
+               int sz = ob->bsz;
+               switch (ob->type) {
+               case BNORMAL:
+                       ob->buf = xrealloc(ob->buf, sz + CPPBUF+1);
+                       /* ob->cptr = ob->buf + sz; */
+                       ob->bsz = sz + CPPBUF;
+                       break;
+               case BMAC:
+               case BINBUF:
+                       error("putob");
+               case BUTBUF:
+                       if (Mflag == 0)
+                               (void)write(1, ob->buf, sz);
+                       ob->cptr = 0;
+                       break;
+               }
        }
 //     DDPRINT(("putob: iob %p pos %p ch %c (%d)\n", ob, ob->cptr, ch, ch));
-       *ob->cptr++ = ch;
+       ob->buf[ob->cptr++] = ch;
 }
 
-static int nbufused;
+static struct iobuf *
+giob(int typ, const usch *bp, int bsz)
+{
+       struct iobuf *iob = xmalloc(sizeof(struct iobuf));
+
+       if (bp == NULL)
+               bp = xmalloc(bsz);
+       iob->buf = (usch *)bp;
+       iob->cptr = 0;
+       iob->bsz = bsz;
+       iob->ro = 0;
+       iob->type = typ;
+       return iob;
+}
+
+
+int nbufused;
 /*
  * Write a character to an out buffer.
  */
 struct iobuf *
-getobuf(void)
+getobuf(int type)
 {
-       struct iobuf *iob = xmalloc(sizeof(struct iobuf));
+       struct iobuf *iob = 0;
 
-       nbufused++;
-       iob->buf = iob->cptr = xmalloc(BUFSIZ);
-       iob->bsz = iob->buf + BUFSIZ;
-       iob->ro = 0;
+       switch (type) {
+       case BNORMAL:
+               nbufused++;
+               iob = giob(BNORMAL, NULL, CPPBUF);
+               iob->bsz = CPPBUF-1; /* space for \0 */
+               break;
+       case BINBUF:
+#if LIBVMF
+               iob = giob(BINBUF, (usch *)ifiles->vseg->s_cinfo, CPPBUF);
+#else
+               iob = giob(BINBUF, NULL, CPPBUF);
+#endif
+               break;
+       default:
+               error("getobuf");
+       }
        return iob;
 }
 
@@ -391,25 +453,40 @@ getobuf(void)
 static struct iobuf *
 mkrobuf(const usch *s)
 {
-       struct iobuf *iob = xmalloc(sizeof(struct iobuf));
+       struct iobuf *iob;
 
        nbufused++;
-       DPRINT(("mkrobuf %s\n", s));
-       iob->buf = iob->cptr = (usch *)s;
-       iob->bsz = iob->buf + strlen((char *)iob->buf);
+       iob = giob(BNORMAL, s, strlen((char *)s));
        iob->ro = 1;
+       DPRINT(("mkrobuf %s\n", s));
+       return iob;
+}
+
+/*
+ * Copy a buffer to another buffer.
+ */
+struct iobuf *
+buftobuf(struct iobuf *in, struct iobuf *iob)
+{
+       int cp;
+
+       DPRINT(("strtobuf iob %p buf %p str %p\n", iob, iob->buf, in));
+       if (iob == NULL)
+               iob = getobuf(BNORMAL);
+       for (cp = 0; cp < in->cptr; cp++)
+               putob(iob, in->buf[cp]);
        return iob;
 }
 
 /*
  * Copy a string to a buffer.
  */
-static struct iobuf *
-strtobuf(usch *str, struct iobuf *iob)
+struct iobuf *
+strtobuf(const usch *str, struct iobuf *iob)
 {
-       DPRINT(("strtobuf iob %p buf %p str %s\n", iob, iob->buf, str));
        if (iob == NULL)
-               iob = getobuf();
+               iob = getobuf(BNORMAL);
+       DPRINT(("strtobuf iob %p buf %p str %s\n", iob, iob->buf, str));
        do {
                putob(iob, *str);
        } while (*str++);
@@ -431,7 +508,6 @@ macsav(int ch)
                        error("macro too large");
                tb = xmalloc(CPPBUF);
                memcpy(tb, macbase+cmbase, CPPBUF-cmbase);
-               xrealloc(macbase, cmbase);
                macpos -= cmbase;
                cmbase = 0;
                macbase = tb;
@@ -454,7 +530,8 @@ macstr(const usch *s)
 void
 bufree(struct iobuf *iob)
 {
-       nbufused--;
+       if (iob->type == BNORMAL)
+               nbufused--;
        if (iob->ro == 0)
                free(iob->buf);
        free(iob);
@@ -509,7 +586,7 @@ line(void)
                if ((nl = lookup(dp, FIND)) == 0 || (ob = kfind(nl)) == 0)
                        goto bad;
        } else {
-               ob = getobuf();
+               ob = getobuf(BNORMAL);
                do {
                        putob(ob, c);
                } while (ISDIGIT(c = cinput()));
@@ -542,13 +619,10 @@ line(void)
                if (c != '\"')
                        goto bad;
 
-               setcmbase();
-               ifiles->fname = macbase+1;
-               faststr(c, macsav);
-               macbase[--macpos] = 0;
-               if (strcmp((char *)ifiles->fname, (char *)macbase+cmbase+1))
-                       ifiles->fname = xstrdup(macbase+cmbase+1);
-               clrcmbase();
+               ob = faststr(c, NULL);
+               if (strcmp((char *)ifiles->fname, (char *)ob->buf))
+                       ifiles->fname = xstrdup(ob->buf);
+               bufree(ob);
 
                c = skipws(0);
        }
@@ -567,6 +641,9 @@ bad:        error("bad #line");
 #ifdef MACHOABI
 
 /*
+ * Example:
+ * Library/Frameworks/VideoToolbox.framework/Headers/VTSession.h
+ *
  * Search for framework header file.
  * Return 1 on success.
  */
@@ -574,50 +651,38 @@ bad:      error("bad #line");
 static int
 fsrch_macos_framework(const usch *fn, const usch *dir)
 {
-       usch *saved_stringbuf = stringbuf;
+       struct iobuf *ob;
        usch *s = (usch *)strchr((const char*)fn, '/');
-       usch *nm;
-       usch *p;
+       usch *p, *q, *nm;
        int len  = s - fn;
 
        if (s == NULL)
                return 0;
 
-//     fprintf(stderr, "searching for %s in %s\n", (const char *)fn, (const char *)dir);
-
-       nm = savstr(dir);
-       savch(0);
-       p = savstr(fn);
-       stringbuf = p + len;
-       savch(0);
-//     fprintf(stderr, "comparing \"%s\" against \"%.*s\"\n", nm, len, fn);
-       p = (usch *)strstr((const char *)nm, (const char *)p);
-//     fprintf(stderr, "p = %s\n", (const char *)p);
-       if (p != NULL) {
-               stringbuf = p;
-               savch(0);
+       nm = xstrdup(dir);
+       p = xstrdup(fn);
+       *(p + len) = 0;
+
+       q = (usch *)strstr((const char *)nm, (const char *)p);
+       if (q != NULL) {
+               *q = 0;
                return fsrch_macos_framework(fn, nm);
        }
+       free(p);
 
        p = nm + strlen((char *)nm) - 1;
        while (*p == '/')
                p--;
        while (*p != '/')
                p--;
-       stringbuf = ++p;
-       savstr((const usch *)"Frameworks/");
-       stringbuf = savstr(fn) + len;
-       savstr((const usch*)".framework/Headers");
-       savstr(s);
-       savch(0);
-
-//     fprintf(stderr, "nm: %s\n", nm);
-
+       ++p;
+       
+       ob = bsheap(NULL, "%s/Frameworks/%s.framework/Headers%s", nm, fn, s);
+       free(nm);
+       nm = xstrdup(ob->buf);
+       bufree(ob);
        if (pushfile(nm, fn, SYSINC, NULL) == 0)
                return 1;
-//     fprintf(stderr, "not found %s, continuing...\n", nm);
-
-       stringbuf = saved_stringbuf;
 
        return 0;
 }
@@ -652,21 +717,23 @@ fsrch(const usch *fn, int idx, struct incs *w)
         * to resolve framework headers.
         */
        {
-               usch *dir = stringbuf;
-               savstr(ifiles->orgfn);
-               stringbuf = (usch *)strrchr((char *)dir, '/');
-               if (stringbuf != NULL) {
-                       stringbuf++;
-                       savch(0);
+               /*
+                * Dig out org filename path and try to find.
+                */
+               usch *p, *dir = xstrdup(ifiles->orgfn);
+               if ((p = (usch *)strrchr((char *)dir, '/')) != NULL) {
+                       p[1] = 0;
                        if (fsrch_macos_framework(fn, dir) == 1)
                                return 1;
                }
-               stringbuf = dir;
+               free(dir);
 
-               if (fsrch_macos_framework(fn, (const usch *)"/Library/Frameworks/") == 1)
+               if (fsrch_macos_framework(fn,
+                   (const usch *)"/Library/Frameworks/") == 1)
                        return 1;
 
-               if (fsrch_macos_framework(fn, (const usch *)"/System/Library/Frameworks/") == 1)
+               if (fsrch_macos_framework(fn,
+                   (const usch *)"/System/Library/Frameworks/") == 1)
                        return 1;
        }
 #endif
@@ -696,7 +763,7 @@ incfn(void)
                if ((ob = kfind(nl)) == 0)
                        return NULL;
        } else {
-               ob = getobuf();
+               ob = getobuf(BNORMAL);
                putob(ob, c);
                while ((c = cinput()) && c != '\n')
                        putob(ob, c);
@@ -706,14 +773,14 @@ incfn(void)
        }
 
        /* now we have an (expanded?) filename in obuf */
-       while (ob->buf < ob->cptr && ISWS(ob->cptr[-1]))
+       while (0 < ob->cptr && ISWS(ob->buf[ob->cptr-1]))
                ob->cptr--;
 
        if (ob->buf[0] != '\"' && ob->buf[0] != '<')
                return NULL;
-       if (ob->cptr[-1] != '\"' && ob->cptr[-1] != '>')
+       if (ob->buf[ob->cptr-1] != '\"' && ob->buf[ob->cptr-1] != '>')
                return NULL;
-       ob->cptr[-1] = 0;
+       ob->buf[ob->cptr-1] = 0;
        return ob;
 }
 
@@ -743,14 +810,12 @@ include(void)
                /* nope, failed, try to create a path for it */
                if ((nm = (usch *)strrchr((char *)ifiles->orgfn, '/'))) {
                        ob = strtobuf((usch *)ifiles->orgfn, NULL);
-                       ob->cptr = ob->buf + (nm - ifiles->orgfn) + 1;
+                       ob->cptr = (nm - ifiles->orgfn) + 1;
                        strtobuf(fn, ob);
-                       putob(ob, 0);
                        nm = xstrdup(ob->buf);
                        bufree(ob);
-               } else {
+               } else
                        nm = xstrdup(fn);
-               }
                if (pushfile(nm, nm, 0, NULL) == 0) {
                        free(fn-1);
                        goto okret;
@@ -832,12 +897,12 @@ skipwscmnt(struct iobuf *ib)
 }
 
 static int
-findarg(usch *s, usch **args, int narg)
+findarg(usch *s, struct iobuf *ab, int *arg, int narg)
 {
        int i;
 
        for (i = 0; i < narg; i++)
-               if (strcmp((char *)s, (char *)args[i]) == 0)
+               if (strcmp((char *)s, (char *)ab->buf + arg[i]) == 0)
                        return i;
        return -1;
 }
@@ -850,10 +915,12 @@ findarg(usch *s, usch **args, int narg)
 void
 define(void)
 {
+       struct iobuf *ib, *ab;
        struct symtab *np;
-       usch *args[MAXARGS+1], cc[2], *vararg, *dp;
+       usch cc[2], *vararg, *dp;
+       int arg[MAXARGS+1];
        int c, i, redef, oCflag, t;
-       int narg = -1;
+       int type, narg;
        int wascon;
 
        if (flslvl)
@@ -863,7 +930,6 @@ define(void)
        if (!ISID0(c = skipws(0)))
                goto bad;
 
-       setcmbase();
        dp = readid(c);
        np = lookup(dp, ENTER);
        if (np->value) {
@@ -873,10 +939,12 @@ define(void)
                redef = 0;
        }
 
+       type = OBJCT;
+       narg = 0;
+       ab = getobuf(BNORMAL);
        vararg = NULL;
-       macsav(0); /* set type slot */
        if ((c = cinput()) == '(') {
-               narg = 0;
+               type = 0;
                /* function-like macros, deal with identifiers */
                c = skipws(0);
                for (;;) {
@@ -892,20 +960,21 @@ define(void)
                                if (!ISID0(c))
                                        goto bad;
 
-                               dp = readid(c);
+                               dp = bufid(c, ab);
                                /* make sure there is no arg of same name */
-                               if (findarg(dp, args, narg) >= 0)
+                               if (findarg(dp, ab, arg, narg) >= 0)
                                        error("Duplicate parameter \"%s\"", dp);
                                if (narg == MAXARGS)
                                        error("Too many macro args");
-                               args[narg++] = xstrdup(dp);
+                               putob(ab, 0);
+                               arg[narg++] = dp - ab->buf;
                                switch ((c = skipws(0))) {
                                case ',': break;
                                case ')': continue;
                                case '.':
                                        if (isell() == 0 || skipws(0) != ')')
                                                goto bad;
-                                       vararg = args[--narg];
+                                       vararg = ab->buf + arg[--narg];
                                        c = ')';
                                        continue;
                                default:
@@ -927,13 +996,11 @@ define(void)
 
        Cflag = oCflag; /* Enable comments again */
 
-       if (vararg)
-               macsav(0); /* for macro type */
-
+       setcmbase();
        if (ISWS(c))
                c = skipwscmnt(0);
 
-#define        DELEWS() while (macpos > cmbase+1+(vararg!=NULL) && \
+#define        DELEWS() while ((macpos > cmbase) && \
        ISWS(macbase[macpos-1])) macpos--
 
        /* parse replacement-list, substituting arguments */
@@ -957,14 +1024,14 @@ define(void)
                                (void)cinput(); /* eat # */
                                DELEWS();
                                macsav(CONC);
-                               if (ISID0(c = skipws(0)) && narg >= 0)
+                               if (ISID0(c = skipws(0)) && type == 0)
                                        wascon = 1;
                                if (c == '\n')
                                        goto bad; /* 6.10.3.3 p1 */
                                continue;
                        }
 
-                       if (narg < 0) {
+                       if (type == OBJCT) {
                                /* no meaning in object-type macro */
                                macsav('#');
                                break;
@@ -983,15 +1050,23 @@ define(void)
                                break;
                                
                        }
-                       if ((i = findarg(dp, args, narg)) < 0)
+                       if ((i = findarg(dp, ab, arg, narg)) < 0)
                                goto bad;
                        macsav(WARN);
                        macsav(i);
                        macsav(SNUFF);
                        break;
 
+               case CMNT:
+                       Ccmnt(macsav);
+                       break;
+
                case NUMBER: 
-                       c = fastnum(c, macsav);
+                       ib = getobuf(BNORMAL);
+                       c = fastnum(c, ib);
+                       for (dp = ib->buf; dp < ib->buf + ib->cptr; dp++)
+                               macsav(*dp);
+                       bufree(ib);
                        continue;
 
                case STRING:
@@ -1004,13 +1079,17 @@ define(void)
                        }
                        if (tflag)
                                macsav(c);
-                       else
-                               faststr(c, macsav);
+                       else {
+                               ib = faststr(c, NULL);
+                               for (dp = ib->buf; *dp ; dp++)
+                                       macsav(*dp);
+                               bufree(ib);
+                       }
                        break;
 
                case IDENT:
                        dp = readid(c);
-                       if (narg < 0) {
+                       if (type == OBJCT) {
                                macstr(dp);
                                break; /* keep on heap */
                        }
@@ -1021,7 +1100,7 @@ define(void)
                        }
 
                        /* check if its an argument */
-                       if ((i = findarg(dp, args, narg)) < 0) {
+                       if ((i = findarg(dp, ab, arg, narg)) < 0) {
                                macstr(dp);
                                break;
                        }
@@ -1043,18 +1122,16 @@ define(void)
        /* remove trailing whitespace */
        DELEWS();
 
-       if (macbase[cmbase+1+(vararg != 0)] == CONC)
-               goto bad; /* 6.10.3.3 p1 */
-
-       if (vararg) {
-               macbase[cmbase] = VARG;
-               macbase[cmbase+1] = narg;
-       } else
-               macbase[cmbase] = (narg < 0 ? OBJCT : narg);
        macsav(0);
+       if (vararg)
+               type = VARG;
+
+       if (macbase[cmbase] == CONC)
+               goto bad; /* 6.10.3.3 p1 */
 
        if (redef && ifiles->idx != SYSINC) {
-               if (cmprepl(np->value, macbase+cmbase)) { /* not equal */
+               if (cmprepl(np->value, macbase+cmbase) || 
+                   np->type != type || np->narg != narg) { /* not equal */
                        np->value = macbase+cmbase;
                        warning("%s redefined (previously defined at \"%s\" line %d)",
                            np->namep, np->file, np->line);
@@ -1062,25 +1139,26 @@ define(void)
                        macpos = cmbase;  /* forget this space */
        } else
                np->value = macbase+cmbase;
+       np->type = type;
+       np->narg = narg;
 
 #ifdef PCC_DEBUG
        if (dflag) {
                const usch *w = np->value;
 
                printf("!define %s: ", np->namep);
-               if (*w == OBJCT)
+               if (type == OBJCT)
                        printf("[object]");
-               else if (*w == VARG)
-                       printf("[VARG%d]", *++w);
+               else if (type == VARG)
+                       printf("[VARG%d]", narg);
                else
-                       printf("[%d]", *w);
+                       printf("[%d]", narg);
                putchar('\'');
-               prrep(++w);
+               prrep(w);
                printf("\'\n");
        }
 #endif
-       for (i = 0; i < narg; i++)
-               free(args[i]);
+       bufree(ab);
        return;
 
 bad:   error("bad #define");
@@ -1119,22 +1197,10 @@ error(const char *fmt, ...)
        exit(1);
 }
 
-/*
- * store a character into the "define" buffer.
- */
-void
-savch(int c)
-{
-       if (stringbuf >= &sbf[SBSIZE])
-               error("out of macro space!");
-
-       *stringbuf++ = (usch)c;
-}
-
 static int
 pragwin(struct iobuf *ib)
 {
-       return ib ? *ib->cptr++ : cinput();
+       return ib ? ib->buf[ib->cptr++] : cinput();
 }
 
 static int
@@ -1155,7 +1221,7 @@ static void
 pragoper(struct iobuf *ib)
 {
        int t;
-       struct iobuf *ob = getobuf();
+       struct iobuf *ob = getobuf(BNORMAL);
 
        if (skipws(ib) != '(' || ((t = skipws(ib)) != '\"' && t != 'L'))
                goto err;
@@ -1286,7 +1352,7 @@ storeblk(int l, struct iobuf *ob)
 static struct iobuf *
 unfname(void)
 {
-       struct iobuf *ob = getobuf();
+       struct iobuf *ob = getobuf(BNORMAL);
        const usch *bp = ifiles->fname;
 
        putob(ob, '\"');
@@ -1303,9 +1369,11 @@ unfname(void)
  * Version of fastnum that reads from a string and saves in ob.
  * We know that it is a number before calling this routine.
  */
-static usch *
-fstrnum(usch *s, struct iobuf *ob)  
+static void
+fstrnum(struct iobuf *ib, struct iobuf *ob)  
 {      
+       usch *s = ib->buf+ib->cptr;
+
        if (*s == '.') {
                /* not digit, dot.  Next will be digit */
                putob(ob, *s++);
@@ -1319,16 +1387,17 @@ fstrnum(usch *s, struct iobuf *ob)
                } else if ((*s != '.') && ((spechr[*s] & C_ID) == 0))
                        break;
        }
-        return s;
+       ib->cptr = s - ib->buf;
 }
 
 /*
  * get a string or character constant.
  * similar to faststr.
  */
-static usch *
-fstrstr(usch *s, struct iobuf *ob)
+static void
+fstrstr(struct iobuf *ib, struct iobuf *ob)
 {
+       usch *s = ib->buf+ib->cptr;
        int ch;
 
        if (*s == 'L' || *s == 'U' || *s == 'u')
@@ -1343,15 +1412,17 @@ fstrstr(usch *s, struct iobuf *ob)
                putob(ob, *s++);
        }
        putob(ob, *s++);
-       return s;
+       ib->cptr = s - ib->buf;
 }
 
 /*
  * Save standard comments if found.
  */
-static usch *
-fcmnt(usch *s, struct iobuf *ob)
+static void
+fcmnt(struct iobuf *ib, struct iobuf *ob)
 {
+       usch *s = ib->buf+ib->cptr;
+
        putob(ob, *s++); /* / */
        putob(ob, *s++); /* * */
        for (;;s++) {
@@ -1359,7 +1430,7 @@ fcmnt(usch *s, struct iobuf *ob)
                if (s[-1] == '*' && *s == '/')
                        break;
        }
-       return s+1;
+       ib->cptr = s - ib->buf + 1;
 }
 
 static int
@@ -1390,30 +1461,30 @@ loopover(struct iobuf *ib, struct iobuf *ob)
        struct iobuf *xb, *xob;
        struct symtab *sp;
        usch *cp;
-       int l, c, t;
+       int l, c, t, cn;
 
-       ib->cptr = ib->buf; /* start from beginning */
+       ib->cptr = 0; /* start from beginning */
 #ifdef PCC_DEBUG
        if (dflag) {
                printf("loopover: '");
-               prline(ib->cptr);
+               prline(ib->buf+ib->cptr);
                printf("'\n");
        }
 #endif
 
-       xb = getobuf();
-       while ((c = *ib->cptr)) {
-               switch (t = getyp(ib->cptr)) {
+       xb = getobuf(BNORMAL);
+       while ((c = ib->buf[ib->cptr])) {
+               switch (t = getyp(ib->buf+ib->cptr)) {
                case CMNT:
-                       ib->cptr = fcmnt(ib->cptr, ob);
+                       fcmnt(ib, ob);
                        continue;
                case NUMBER:
-                       ib->cptr = fstrnum(ib->cptr, ob);
+                       fstrnum(ib, ob);
                        continue;
                case STRING:
-                       xb->cptr = xb->buf;
-                       ib->cptr = fstrstr(ib->cptr,xb);
-                       *xb->cptr = 0;
+                       xb->cptr = 0;
+                       fstrstr(ib, xb);
+                       xb->buf[xb->cptr] = 0;
                        for (cp = xb->buf; *cp; cp++) {
                                if (*cp <= BLKID) {
                                        if (*cp == BLKID)
@@ -1424,7 +1495,7 @@ loopover(struct iobuf *ib, struct iobuf *ob)
                        }
                        continue;
                case BLKID:
-                       l = ib->cptr[1];
+                       l = ib->buf[ib->cptr+1];
                        ib->cptr+=2;
                        /* FALLTHROUGH */
                case IDENT:
@@ -1439,26 +1510,27 @@ loopover(struct iobuf *ib, struct iobuf *ob)
                         * BUT: if this macro is blocked then this
                         * should not be done.
                         */
-                       for (cp = ib->cptr; ISID(*ib->cptr); ib->cptr++)
+                       for (cn = ib->cptr;
+                           ISID(ib->buf[ib->cptr]); ib->cptr++)
                                ;
-                       if ((sp = lookup(cp, FIND)) == NULL) {
-sstr:                          for (; cp < ib->cptr; cp++)
-                                       putob(ob, *cp);
+                       if ((sp = lookup(cn+ib->buf, FIND)) == NULL) {
+sstr:                          for (; cn < ib->cptr; cn++)
+                                       putob(ob, ib->buf[cn]);
                                continue;
                        }
                        if (expok(sp, l) == 0) {
                                /* blocked */
                                goto sstr;
                        } else {
-                               if (*sp->value != OBJCT) {
-                                       cp = ib->cptr;
-                                       while (ISWS(*ib->cptr))
+                               if (sp->type != OBJCT) {
+                                       cn = ib->cptr;
+                                       while (ISWS(ib->buf[ib->cptr]))
                                                ib->cptr++;
-                                       if (*ib->cptr == 0) {
+                                       if (ib->buf[ib->cptr] == 0) {
                                                bufree(xb);
                                                return sp;
                                        }
-                                       ib->cptr = cp;
+                                       ib->cptr = cn;
                                }
 newmac:                                if ((xob = submac(sp, 1, ib, NULL)) == NULL) {
                                        strtobuf((usch *)sp->namep, ob);
@@ -1486,7 +1558,7 @@ newmac:                           if ((xob = submac(sp, 1, ib, NULL)) == NULL) {
  * Handle defined macro keywords found on input stream.
  * When finished print out the full expanded line.
  * Input here is from the lex buffer.
- * Return 1 if success, 0 otherwise.  fastscan restores stringbuf.
+ * Return 1 if success, 0 otherwise.
  * Scanned data is stored on heap.  Last scan prints out the buffer.
  */
 struct iobuf *
@@ -1494,15 +1566,15 @@ kfind(struct symtab *sp)
 {
        extern int inexpr;
        struct blocker *bl;
-       struct iobuf *ib, *ob, *outb;
-       const usch *argary[MAXARGS+1], *sbp;
+       struct iobuf *ib, *ob, *outb, *ab;
+       const usch *argary[MAXARGS+1];
        int c, n = 0;
 
        blkidp = 1;
        outb = NULL;
-       sbp = stringbuf;
        DPRINT(("%d:enter kfind(%s)\n",0,sp->namep));
-       switch (*sp->value) {
+       DPRINT(("%d:enter kfind2(%s)\n",0,sp->value));
+       switch ((unsigned int)sp->type) {
        case FILLOC:
                ob = unfname();
                return ob;
@@ -1512,13 +1584,13 @@ kfind(struct symtab *sp)
 
        case PRAGLOC:
                pragoper(NULL);
-               return getobuf();
+               return getobuf(BNORMAL);
 
        case DEFLOC:
        case OBJCT:
                bl = blkget(sp, NULL);
-               ib = mkrobuf(sp->value+1);
-               ob = getobuf();
+               ib = mkrobuf(sp->value);
+               ob = getobuf(BNORMAL);
                ob = exparg(1, ib, ob, bl);
                bufree(ib);
                break;
@@ -1543,27 +1615,27 @@ kfind(struct symtab *sp)
                }
 
                /* fetch arguments */
-again:         if (readargs1(sp, argary))
+again:         if ((ab = readargs1(sp, argary)) == 0)
                        error("readargs");
 
                bl = blkget(sp, NULL);
                ib = subarg(sp, argary, 1, bl);
-               ob = getobuf();
+               bufree(ab);
+               ob = getobuf(BNORMAL);
                ob = exparg(1, ib, ob, bl);
                bufree(ib);
                break;
        }
 
        /*
-        * Loop over stringbuf, output the data and remove remaining  
+        * Loop over ob, output the data and remove remaining  
         * directives.  Start with extracting the last keyword (if any).
         */
        putob(ob, 0); /* XXX needed? */
 
        if (outb == NULL)
-               outb = getobuf();
+               outb = getobuf(BNORMAL);
 
-       stringbuf = (usch *)sbp; /* XXX should check cleanup */
        if ((sp = loopover(ob, outb))) {
                /* Search for '(' */
                while (ISWSNL(c = cinput()))
@@ -1580,7 +1652,6 @@ again:            if (readargs1(sp, argary))
 
        for (ifiles->lineno += n; n; n--)
                putob(outb, '\n');
-       stringbuf = (usch *)sbp;
        if (nbufused != 1)
                error("lost buffer");
        return outb;
@@ -1598,10 +1669,10 @@ submac(struct symtab *sp, int lvl, struct iobuf *ib, struct blocker *obl)
        struct blocker *bl;
        struct iobuf *ob, *ab;
        const usch *argary[MAXARGS+1];
-       usch *cp, *pr;
+       int cn;
 
        DPRINT(("%d:submac: trying '%s'\n", lvl, sp->namep));
-       switch (*sp->value) {
+       switch ((unsigned int)sp->type) {
        case FILLOC:
                ob = unfname();
                break;
@@ -1610,12 +1681,12 @@ submac(struct symtab *sp, int lvl, struct iobuf *ib, struct blocker *obl)
                break;
        case PRAGLOC:
                pragoper(ib);
-               ob = getobuf();
+               ob = getobuf(BNORMAL);
                break;
        case OBJCT:
                bl = blkget(sp, obl);
-               ib = mkrobuf(sp->value+1);
-               ob = getobuf();
+               ib = mkrobuf(sp->value);
+               ob = getobuf(BNORMAL);
                DPRINT(("%d:submac: calling exparg\n", lvl));
                ob = exparg(lvl+1, ib, ob, bl);
                bufree(ib);
@@ -1625,26 +1696,24 @@ submac(struct symtab *sp, int lvl, struct iobuf *ib, struct blocker *obl)
                ob = bsheap(NULL, "%d", counter++);
                break;
        default:
-               cp = ib->cptr;
-               while (ISWSNL(*ib->cptr))
+               cn = ib->cptr;
+               while (ISWSNL(ib->buf[ib->cptr]))
                        ib->cptr++;
-               if (*ib->cptr != '(') {
-                       ib->cptr = cp;
+               if (ib->buf[ib->cptr] != '(') {
+                       ib->cptr = cn;
                        return 0;
                }
-               cp = ib->cptr++;
-               pr = stringbuf;
-               if ((ab = readargs2(&ib->cptr, sp, argary)) == 0) {
+               cn = ib->cptr++;
+               if ((ab = readargs2(ib, sp, argary)) == 0) {
                        /* Bailed out in the middle of arg list */
-                       ib->cptr = cp; /* XXX */
+                       ib->cptr = cn; /* XXX */
                        return 0;
                }
                bl = blkget(sp, obl);
                ib = subarg(sp, argary, lvl+1, bl);
                bufree(ab);
-               stringbuf = pr;
 
-               ob = getobuf();
+               ob = getobuf(BNORMAL);
                DPRINT(("%d:submac(: calling exparg\n", lvl));
                ob = exparg(lvl+1, ib, ob, bl);
                bufree(ib);
@@ -1696,7 +1765,7 @@ chkdir(void)
 }
 
 static int
-ra1_wsnl(int sp)
+ra1_wsnl(void)
 {
        int c;
 
@@ -1705,7 +1774,6 @@ ra1_wsnl(int sp)
                        putch('\n');
                        chkdir();
                        ifiles->lineno++;
-                       if (sp) savch(' ');
                }
        }
        return c;
@@ -1715,19 +1783,18 @@ ra1_wsnl(int sp)
  * Read arguments and put in argument array.
  * If EOF is encountered return 1, otherwise 0.
  */
-int
+struct iobuf *
 readargs1(struct symtab *sp, const usch **args)
 {
-       struct iobuf *ob;
+       struct iobuf *ab;
        const usch *vp = sp->value;
-       int c, i, plev, narg, ellips = 0;
+       int c, i, j, plev, narg, ellips = 0;
+       int argary[MAXARGS+1];
 
        DPRINT(("readargs1\n"));
-       narg = *vp++;
-       if (narg == VARG) {
-               narg = *vp++;
-               ellips = 1;
-       }
+       narg = sp->narg;
+       ellips = sp->type == VARG;
+
 #ifdef PCC_DEBUG
        if (dflag > 1) {
                printf("narg %d varg %d: ", narg, ellips);
@@ -1739,12 +1806,13 @@ readargs1(struct symtab *sp, const usch **args)
        /*
         * read arguments and store them on heap.
         */
+       ab = getobuf(BNORMAL);
        c = '(';
        for (i = 0; i < narg && c != ')'; i++) {
-               args[i] = stringbuf;
+               argary[i] = ab->cptr;
                plev = 0;
 
-               c = ra1_wsnl(0);
+               c = ra1_wsnl();
                for (;;) {
                        if (plev == 0 && (c == ')' || c == ','))
                                break;
@@ -1752,106 +1820,105 @@ readargs1(struct symtab *sp, const usch **args)
                        if (c == ')') plev--;
                        if (c == 0)
                                error("eof in macro");
-                       else if (c == '/') Ccmnt(savch);
-                       else if (c == '\"' || c == '\'') faststr(c, savch);
-                       else if (ISID0(c)) {
-                               usch *bp = stringbuf;
-                               do {
-                                       savch(c);
-                               } while ((spechr[c = cinput()] & C_ID));
-                               if ((sp = lookup(bp, FIND)) != NULL) {
-                                       if (sp == linloc) {
-                                               stringbuf = bp;
-                                               ob = bsheap(NULL, "%d", ifiles->lineno);
-                                               savstr(ob->buf);
-                                               bufree(ob);
-                                       } else if (sp == ctrloc) {
-                                               stringbuf = bp;
-                                               ob = bsheap(NULL, "%d", counter++);
-                                               savstr(ob->buf);
-                                               bufree(ob);
-                                       }
+                       else if (c == '/') {
+                               int mp = macpos;
+                               Ccmnt(macsav);
+                               macsav(0);
+                               strtobuf(macbase+mp, ab);
+                               macpos = mp;
+                       } else if (c == '\"' || c == '\'') {
+                               faststr(c, ab);
+                       } else if (ISID0(c)) {
+                               int mp = ab->cptr;
+                               bufid(c, ab);
+                               if ((sp = lookup(ab->buf+mp, FIND)) != NULL &&
+                                   (sp == linloc || sp == ctrloc)) {
+                                       ab->cptr = mp;
+                                       bsheap(ab,"%d", (sp == linloc ?
+                                       ifiles->lineno : counter++));
                                }
-                               cunput(c);
                        } else
-                               savch(c);
+                               putob(ab, c);
                        if ((c = cinput()) == '\n') {
                                chkdir();
                                ifiles->lineno++, putch(c), c = ' ';
                        }
                }
 
-               while (args[i] < stringbuf && ISWSNL(stringbuf[-1]))
-                       stringbuf--;
-               savch('\0');
+               while (argary[i] < ab->cptr && ISWSNL(ab->buf[ab->cptr-1]))
+                       ab->cptr--;
+               putob(ab, '\0');
 #ifdef PCC_DEBUG
                if (dflag) {
                        printf("readargs: save arg %d '", i);
-                       prline(args[i]);
+                       prline(ab->buf+argary[i]);
                        printf("'\n");
                }
 #endif
        }
 
        /* Handle varargs readin */
-       if (ellips)
-               args[i] = (const usch *)"";
+       argary[i] = ab->cptr;
+       putob(ab, 0);
+       ab->cptr--;
        if (ellips && c != ')') {
-               args[i] = stringbuf;
                plev = 0;
-               c = ra1_wsnl(0);
+               c = ra1_wsnl();
                for (;;) {
                        if (plev == 0 && c == ')')
                                break;
                        if (c == '(') plev++;
                        if (c == ')') plev--;
-                       if (c == '\"' || c == '\'') faststr(c, savch);
-                       else
-                               savch(c);
+                       if (c == '\"' || c == '\'') {
+                               faststr(c, ab);
+                       } else
+                               putob(ab, c);
                        if ((c = cinput()) == '\n')
                                ifiles->lineno++, c = ' ';
                }
-               while (args[i] < stringbuf && ISWSNL(stringbuf[-1]))
-                       stringbuf--;
-               savch('\0');
+               while (argary[i] < ab->cptr && ISWSNL(ab->buf[ab->cptr-1]))
+                       ab->cptr--;
+               putob(ab, '\0');
 #ifdef PCC_DEBUG
                if (dflag) {
                        printf("readargs: vararg arg %d '", i);
-                       prline(args[i]);
+                       prline(ab->buf+argary[i]);
                        printf("'\n");
                }
 #endif
-
        }
+       if (ellips)
+               i++;
        if (narg == 0 && ellips == 0)
-               c = ra1_wsnl(0);
+               c = ra1_wsnl();
 
        if (c != ')' || (i != narg && ellips == 0) || (i < narg && ellips == 1))
                error("wrong arg count");
-       return 0;
+       for (j = 0; j < i; j++)
+               args[j] = ab->buf + argary[j];
+       return ab;
 }
 
-static usch *raptr;
+static struct iobuf *rabuf;
 static int
 raread(void)
 {
        int rv;
 
-       if (raptr) {
-               if ((rv = *raptr))
-                       raptr++;
+       if (rabuf) {
+               if ((rv = rabuf->buf[rabuf->cptr]))
+                       rabuf->cptr++;
        } else
                rv = cinput();
        return rv;
 }
 
-
 /*
  * Read arguments and put in argument array.
  * If EOF is encountered return 1, otherwise 0.
  */
 struct iobuf *
-readargs2(usch **inp, struct symtab *sp, const usch **args)
+readargs2(struct iobuf *in, struct symtab *sp, const usch **args)
 {
        struct iobuf *ab;
        const usch *vp = sp->value;
@@ -1860,17 +1927,15 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
 
        DPRINT(("readargs2 %s '", sp->namep));
 #ifdef PCC_DEBUG
-       if (dflag && inp) {
-               prline(*inp);
+       if (dflag) {
+               prline(in->buf+in->cptr);
                printf("'\n");
        }
 #endif
-       raptr = inp ? *inp : 0;
-       narg = *vp++;
-       if (narg == VARG) {
-               narg = *vp++;
-               ellips = 1;
-       }
+       rabuf = in;
+       narg = sp->narg;
+       ellips = sp->type == VARG;
+
 #ifdef PCC_DEBUG
        if (dflag > 1) {
                prrep(vp);
@@ -1881,10 +1946,10 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
        /*
         * read arguments and store them on heap.
         */
-       ab = getobuf();
+       ab = getobuf(BNORMAL);
        c = '(';
        for (i = 0; i < narg && c != ')'; i++) {
-               argary[i] = ab->cptr - ab->buf;
+               argary[i] = ab->cptr;
                plev = 0;
 
                while ((c = raread()) == ' ' || c == '\t')
@@ -1895,9 +1960,8 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
                        if (c == '(') plev++;
                        if (c == ')') plev--;
                        if (c == 0) {
-                               if (raptr) {
-                                       *inp = raptr;
-                                       raptr = 0;
+                               if (rabuf) {
+                                       rabuf = 0;
                                } else
                                        error("eof in macro");
                        } else if (c == BLKID) {
@@ -1908,33 +1972,30 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
                                putob(ab, '/');
                                continue;
                        } else if (c == '\"' || c == '\'') {
-                               if (raptr) {
-                                       raptr = fstrstr(raptr-1, ab);
+                               if (rabuf) {
+                                       rabuf->cptr--;
+                                       fstrstr(rabuf, ab);
                                } else {
-                                       int mp = macpos;
-                                       faststr(c, macsav);
-                                       strtobuf(macbase+mp, ab);
-                                       macpos = mp;
+                                       faststr(c, ab);
                                }
                        } else if (ISID0(c)) {
-                               int mp = macpos;
+                               int mp = ab->cptr;
                                do {
-                                       macsav(c);
+                                       putob(ab, c);
                                } while (ISID(c = raread()));
-                               macsav(0);
-                               macpos = mp;
-                               if ((sp = lookup(macbase+mp, FIND)) &&
+                               ab->buf[ab->cptr] = 0;
+                               if ((sp = lookup(ab->buf+mp, FIND)) &&
                                    (sp == linloc)) {
+                                       ab->cptr = mp;
                                        bsheap(ab, "%d", ifiles->lineno);
-                               } else
-                                       strtobuf(macbase+mp, ab);
+                               }
                                continue;
                        } else
                                putob(ab, c);
                        c = raread();
                }
 
-               while (argary[i] < ab->cptr-ab->buf && ISWSNL(ab->cptr[-1]))
+               while (argary[i] < ab->cptr && ISWSNL(ab->buf[ab->cptr-1]))
                        ab->cptr--;
                putob(ab, '\0');
 #ifdef PCC_DEBUG
@@ -1950,7 +2011,7 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
        if (ellips)
                args[i] = (const usch *)"";
        if (ellips && c != ')') {
-               argary[i] = ab->cptr - ab->buf;
+               argary[i] = ab->cptr;
                plev = 0;
                while ((c = raread()) == ' ' || c == '\t')
                        ;
@@ -1960,19 +2021,17 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
                        if (c == '(') plev++;
                        if (c == ')') plev--;
                        if (c == '\"' || c == '\'') {
-                               if (raptr) {
-                                       raptr = fstrstr(raptr-1, ab);
+                               if (rabuf) {
+                                       rabuf->cptr--;
+                                       fstrstr(rabuf, ab);
                                } else {
-                                       int mp = macpos;
-                                       faststr(c, macsav);
-                                       strtobuf(macbase+mp, ab);
-                                       macpos = mp;
+                                       faststr(c, ab);
                                }
                        } else
                                putob(ab, c);
                        c = raread();
                }
-               while (argary[i] < ab->cptr-ab->buf && ISWSNL(ab->cptr[-1]))
+               while (argary[i] < ab->cptr && ISWSNL(ab->buf[ab->cptr-1]))
                        ab->cptr--;
                putob(ab, '\0');
                i++;
@@ -1984,8 +2043,6 @@ readargs2(usch **inp, struct symtab *sp, const usch **args)
 
        if (c != ')' || (i != narg && ellips == 0) || (i < narg && ellips == 1))
                error("wrong arg count");
-       if (raptr)
-               *inp = raptr;
        for (j = 0; j < i; j++)
                args[j] = ab->buf + argary[j];
        return ab;
@@ -2006,11 +2063,9 @@ subarg(struct symtab *nl, const usch **args, int lvl, struct blocker *bl)
        const usch *sp, *bp, *ap, *vp, *tp;
 
        DPRINT(("%d:subarg '%s'\n", lvl, nl->namep));
-       ob = getobuf();
+       ob = getobuf(BNORMAL);
        vp = nl->value;
-       narg = *vp++;
-       if (narg == VARG)
-               narg = *vp++;
+       narg = nl->narg;
 
        sp = vp;
        instr = snuff = 0;
@@ -2067,7 +2122,7 @@ subarg(struct symtab *nl, const usch **args, int lvl, struct blocker *bl)
                                 */
                                w = bl ? bl->next : NULL;
                                cb = mkrobuf(bp);
-                               nb = getobuf();
+                               nb = getobuf(BNORMAL);
                                DPRINT(("%d:subarg: calling exparg\n", lvl));
                                nb = exparg(lvl+1, cb, nb, w);
                                DPRINT(("%d:subarg: return exparg\n", lvl));
@@ -2107,7 +2162,7 @@ subarg(struct symtab *nl, const usch **args, int lvl, struct blocker *bl)
                sp++;
        }
        putob(ob, 0);
-       ob->cptr = ob->buf;
+       ob->cptr = 0;
        DPRINT(("%d:subarg retline %s\n", lvl, ob->buf));
        return ob;
 }
@@ -2122,108 +2177,92 @@ struct iobuf *
 exparg(int lvl, struct iobuf *ib, struct iobuf *ob, struct blocker *bl)
 {
        extern int inexpr;
-       struct iobuf *nob;
+       struct iobuf *nob, *tb;
        struct symtab *nl;
        int c, m;
-       usch *cp, *bp, *sbp;
+       usch *cp;
 
-       DPRINT(("%d:exparg: entry ib %s\n", lvl, ib->cptr));
+       DPRINT(("%d:exparg: entry ib %s\n", lvl, ib->buf+ib->cptr));
 #ifdef PCC_DEBUG
        if (dflag > 1) {
                printf("exparg entry: full ");
-               prline(ib->cptr);
+               prline(ib->buf+ib->cptr);
                printf("\n");
        }
 #endif
 
-       while ((c = getyp(ib->cptr)) != 0) {
+       while ((c = getyp(ib->buf+ib->cptr)) != 0) {
                ib->cptr++;
 
                switch (c) {
 
                case CMNT:
-                       ib->cptr = fcmnt(ib->cptr-1, ob);
+                       ib->cptr--;
+                       fcmnt(ib, ob);
                        break;
                case NUMBER:
-                       ib->cptr = fstrnum(ib->cptr-1, ob);
+                       ib->cptr--;
+                       fstrnum(ib, ob);
                        break;
                case STRING:
-                       ib->cptr = fstrstr(ib->cptr-1, ob);
+                       ib->cptr--;
+                       fstrstr(ib, ob);
                        break;
                case BLKID:
-                       m = *ib->cptr++;
+                       m = ib->buf[ib->cptr++];
                        ib->cptr++;
                        /* FALLTHROUGH */
                case IDENT:
                        if (c != BLKID)
                                m = 0;
-                       for (cp = ib->cptr-1; ISID(*cp); cp++)
-                               ;
-#ifdef PCC_DEBUG
-if (dflag) { printf("!! ident "); prline(ib->cptr-1); printf("\n"); }
-#endif
-                       sbp = stringbuf;
-                       if (*cp == BLKID) {
-                               /* concatenation */
-                               bp = stringbuf;
-                               for (cp = ib->cptr-1; 
-                                   ISID(*cp) || *cp == BLKID; cp++) {
-                                       if (*cp == BLKID) {
-                                               /* XXX add to block list */
-                                               cp++;
-                                       } else
-                                               savch(*cp);
-                               }
-                               ib->cptr = cp;
-                               cp = stringbuf;
-                               savch(0);
-                       } else {
-                               bp = ib->cptr-1;
-                               ib->cptr = cp;
+                       tb = getobuf(BNORMAL);
+                       cp = ib->buf+ib->cptr-1;
+                       for (; ISID(*cp) || *cp == BLKID; cp++) {
+                               if (*cp == BLKID) {
+                                       /* XXX add to block list */
+                                       cp++;
+                               } else
+                                       putob(tb, *cp);
                        }
-#ifdef PCC_DEBUG
-if (dflag) { printf("!! ident2 "); prline(bp); printf("\n"); }
-#endif
-                       if ((nl = lookup(bp, FIND)) == NULL) {
-sstr:                          for (; bp < cp; bp++)
-                                       putob(ob, *bp);
-                               stringbuf = sbp;
-                               break;
-                       } else if (inexpr && *nl->value == DEFLOC) {
+                       tb->buf[tb->cptr] = 0;
+                       ib->cptr = cp - ib->buf;
+
+                       /* Any match? */
+                       if ((nl = lookup(tb->buf, FIND)) == NULL) {
+                               buftobuf(tb, ob);
+                       } else if (inexpr && nl->type == DEFLOC) {
+                               /* Used in #if stmts */
                                int gotlp = 0;
-                               while (ISWS(*ib->cptr)) ib->cptr++;
-                               if (*ib->cptr == '(')
-                                       gotlp++, ib->cptr++;
-                               while (ISWS(*ib->cptr)) ib->cptr++;
-                               if (!ISID0(*ib->cptr))
+
+                               cp = ib->buf+ib->cptr;
+                               while (ISWS(*cp)) cp++;
+                               if (*cp == '(')
+                                       gotlp++, cp++;
+                               while (ISWS(*cp)) cp++;
+                               if (!ISID0(*cp))
                                        error("bad defined");
-                               putob(ob, lookup(ib->cptr, FIND) ? '1' : '0');
-                               while (ISID(*ib->cptr)) ib->cptr++;
-                               while (ISWS(*ib->cptr)) ib->cptr++;
-                               if (gotlp && *ib->cptr != ')')
+                               putob(ob, lookup(cp, FIND) ? '1' : '0');
+                               while (ISID(*cp)) cp++;
+                               while (ISWS(*cp)) cp++;
+                               if (gotlp && *cp != ')')
                                        error("bad defined");
-                               ib->cptr++;
-                               break;
-                       }
-                       stringbuf = sbp;
-                       if (expokb(nl, bl) && expok(nl, m)) {
-                               if ((nob = submac(nl, lvl+1, ib, bl))) {
-                                       if (nob->buf[0] == '-' ||
-                                           nob->buf[0] == '+')
-                                               putob(ob, ' ');
-                                       strtobuf(nob->buf, ob);
-                                       if (ob->cptr[-1] == '-' ||
-                                           ob->cptr[-1] == '+')
-                                               putob(ob, ' ');
-                                       bufree(nob);
-                               } else {
-                                       goto sblk;
-                               }
+                               cp++;
+                               ib->cptr = cp - ib->buf;
+                       } else if (expokb(nl, bl) && expok(nl, m) &&
+                           (nob = submac(nl, lvl+1, ib, bl))) {
+                               if (nob->buf[0] == '-' || nob->buf[0] == '+')
+                                       putob(ob, ' ');
+                               strtobuf(nob->buf, ob);
+                               if (ob->cptr > 0 &&
+                                   (ob->buf[ob->cptr-1] == '-' ||
+                                    ob->buf[ob->cptr-1] == '+'))
+                                       putob(ob, ' ');
+                               bufree(nob);
                        } else {
-                               /* blocked */
-sblk:                          storeblk(blkix(mergeadd(bl, m)), ob);
-                               goto sstr;
+                               storeblk(blkix(mergeadd(bl, m)), ob);
+                               buftobuf(tb, ob);
                        }
+                       bufree(tb);
                        break;
 
                default:
@@ -2288,34 +2327,16 @@ prline(const usch *s)
 }
 #endif
 
-usch *
-savstr(const usch *str)
-{
-       usch *rv = stringbuf;
-
-       do {
-               if (stringbuf >= &sbf[SBSIZE])
-                       error("out of macro space!");
-       } while ((*stringbuf++ = *str++));
-       stringbuf--;
-       return rv;
-}
-
 void
 putch(int ch)
 {
-       if (Mflag)
-               return;
-       fputc(ch, stdout);
+       putob(&pb, ch);
 }
 
 void
 putstr(const usch *s)
 {
-       for (; *s; s++) {
-               if (Mflag == 0)
-                       fputc(*s, stdout);
-       }
+       strtobuf(s, &pb);
 }
 
 /*
@@ -2376,7 +2397,7 @@ bsheap(struct iobuf *ob, const char *fmt, ...)
        va_list ap;
 
        if (ob == NULL)
-               ob = getobuf();
+               ob = getobuf(BNORMAL);
 
        va_start(ap, fmt);
        vsheap(ob, fmt, ap);
@@ -2431,8 +2452,8 @@ gtree(void)
        static struct tree *tp;
 
        if (ntrees == 0) {
-               tp = xmalloc(BUFSIZ);
-               ntrees = BUFSIZ/sizeof(*tp);
+               tp = xmalloc(CPPBUF);
+               ntrees = CPPBUF/sizeof(*tp);
        }
        return &tp[--ntrees];
 }
@@ -2448,8 +2469,8 @@ getsymtab(const usch *str)
        struct symtab *sp;
 
        if (nsyms == 0) {
-               spp = xmalloc(BUFSIZ);
-               nsyms = BUFSIZ/sizeof(*sp);
+               spp = xmalloc(CPPBUF);
+               nsyms = CPPBUF/sizeof(*sp);
        }
        sp = &spp[--nsyms];
 
index 9e21af1..8985d79 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: cpp.h,v 1.93 2016/03/12 15:46:06 ragge Exp $       */
+/*     $Id: cpp.h,v 1.102 2016/04/12 18:49:35 ragge Exp $      */
 
 /*
  * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se).
  */
 
 #include <stdio.h>     /* for debug/printf */
+#if LIBVMF
+#include <vmf.h>
+#endif
 
 typedef unsigned char usch;
-extern usch *stringbuf;
 
 extern int     trulvl;
 extern int     flslvl;
@@ -38,28 +40,23 @@ extern      int     dflag;
 extern int     tflag, Aflag, Cflag, Pflag;
 extern int     Mflag, dMflag, MPflag, MMDflag;
 extern char    *Mfile, *MPfile;
-extern int     defining;
-extern FILE    *of;
+extern int     defining, inclevel;
 
 /* args for lookup() */
 #define FIND    0
 #define ENTER   1
 
 /* buffer used internally */
-#ifndef CPPBUF
-#if defined(mach_pdp11)
-#define CPPBUF  BUFSIZ
-#define        BUF_STACK
+#if SIZEOF_INT_P == 2 || LIBVMF
+#define CPPBUF  1024
 #else
 #define CPPBUF 16384
 #endif
-#endif
 
 #define        MAXARGS 128     /* Max # of args to a macro. Should be enough */
 #define        MAXIDSZ 63      /* Max length of C99 identifier; 5.2.4.1 */
 
 #define        PBMAX   10      /* min pushbackbuffer size */
-#define        BBUFSZ  (PBMAX+CPPBUF+1)
 
 #define        CTRLOC  0xf8    /* __COUNTER__ */
 #define        DEFLOC  0xf9    /* defined */
@@ -96,6 +93,31 @@ extern usch spechr[];
 #define ISID0(x)       (spechr[x] & C_ID0)
 #define        ISDIGIT(x)      (spechr[x] & C_DIGIT)
 
+/* buffer definition */
+#define        BNORMAL 0       /* standard buffer */
+#define        BMAC    1       /* store macro definitions */
+#define        BINBUF  2       /* read data from input files */
+#define        BUTBUF  3       /* write data to stdout */
+struct iobuf {
+       usch *buf;
+       int cptr;       /* current pointer */
+       int bsz;        /* bufsize */
+       int ro:1, inuse:1, type:4;
+};
+struct iobuf *getobuf(int);
+void putob(struct iobuf *ob, int ch);
+void bufree(struct iobuf *iob);
+extern struct iobuf pb;
+
+#define        curptr  ib->cptr
+#define        maxread ib->bsz
+#define        buffer  ib->buf+PBMAX
+#define        bbuf    ib->buf
+
+#if LIBVMF
+extern struct vspace ibspc;
+#endif
+
 /*
  * definition for include file info
  */
@@ -106,17 +128,12 @@ struct includ {
        int lineno;
        int escln;              /* escaped newlines, to be added */
        int infil;
-       usch *curptr;
-       usch *maxread;
-       usch *ostr;
-       usch *buffer;
+       struct iobuf *ib;
        int idx;
        void *incs;
        const usch *fn;
-#ifdef BUF_STACK
-       usch bbuf[BBUFSZ];
-#else
-       usch *bbuf;
+#if LIBVMF
+       struct vseg *vseg;
 #endif
 };
 #define INCINC 0
@@ -130,25 +147,10 @@ struct symtab {
        const usch *value;
        const usch *file;
        int line;
+       unsigned char type;     /* macro type */
+       unsigned char narg;     /* # of args (if feasible) */
 };
 
-struct initar {
-       struct initar *next;
-       int type;
-       char *str;
-};
-
-/* buffer definition */
-struct iobuf {
-       usch *buf;
-       usch *cptr;
-       usch *bsz;
-       int ro:1, inuse:1;
-};
-struct iobuf *getobuf(void);
-void putob(struct iobuf *ob, int ch);
-void bufree(struct iobuf *iob);
-
 /*
  * Struct used in parse tree evaluation.
  * op is one of:
@@ -188,20 +190,21 @@ void prtline(int nl);
 int yylex(void);
 void cunput(int);
 int yyparse(void);
-usch *savstr(const usch *str);
-void savch(int c);
 void putch(int);
 void putstr(const usch *s);
 usch *sheap(const char *fmt, ...);
 struct iobuf *bsheap(struct iobuf *, const char *fmt, ...);
+struct iobuf *strtobuf(const usch *str, struct iobuf *iob);
+struct iobuf *buftobuf(struct iobuf *in, struct iobuf *iob);
 void warning(const char *fmt, ...);
 void error(const char *fmt, ...);
 int cinput(void);
 int inc2(void);
 int Ccmnt(void (*d)(int));
-usch *heapid(int ch);
+usch *bufid(int ch, struct iobuf *);
 usch *readid(int ch);
-void faststr(int bc, void (*d)(int));
-int fastnum(int ch, void (*d)(int));
+struct iobuf *faststr(int bc, struct iobuf *);
+int fastnum(int ch, struct iobuf *);
 void *xrealloc(void *p, int sz);
 void *xmalloc(int sz);
+void fastscan(void);
index 2b13b17..6b9b733 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: token.c,v 1.162 2016/03/12 15:46:06 ragge Exp $    */
+/*     $Id: token.c,v 1.172 2016/04/12 18:49:35 ragge Exp $    */
 
 /*
  * Copyright (c) 2004,2009 Anders Magnusson. All rights reserved.
@@ -92,7 +92,7 @@ static void unch(int c);
 #define        PUTCH(ch) if (!flslvl) putch(ch)
 /* protection against recursion in #include */
 #define MAX_INCLEVEL   100
-static int inclevel;
+int inclevel;
 
 struct includ *ifiles;
 
@@ -157,13 +157,12 @@ inpbuf(void)
 
        if (ifiles->infil == -1)
                return 0;
-       len = read(ifiles->infil, ifiles->buffer, CPPBUF);
+       len = read(ifiles->infil, ifiles->buffer, CPPBUF-PBMAX);
        if (len == -1)
                error("read error on file %s", ifiles->orgfn);
        if (len > 0) {
-               ifiles->buffer[len] = 0;
-               ifiles->curptr = ifiles->buffer;
-               ifiles->maxread = ifiles->buffer + len;
+               ifiles->ib->cptr = PBMAX;
+               ifiles->ib->bsz = PBMAX + len;
        }
        return len;
 }
@@ -180,15 +179,15 @@ refill(int minsz)
        if (ifiles->curptr+minsz < ifiles->maxread)
                return 0; /* already enough in input buffer */
 
-       sz = ifiles->maxread - ifiles->curptr;
-       dp = ifiles->buffer - sz;
+       sz = ifiles->ib->bsz - ifiles->ib->cptr;
+       dp = ifiles->ib->buf+PBMAX - sz;
        for (i = 0; i < sz; i++)
-               dp[i] = ifiles->curptr[i];
+               dp[i] = ifiles->ib->buf[ifiles->ib->cptr+i];
        i = inpbuf();
-       ifiles->curptr = dp;
+       ifiles->ib->cptr = dp - ifiles->ib->buf;
        if (i == 0) {
-               ifiles->maxread = ifiles->buffer;
-               ifiles->buffer[0] = 0;
+               ifiles->ib->bsz = PBMAX;
+               ifiles->ib->buf[PBMAX] = 0;
        }
        return 0;
 }
@@ -202,8 +201,8 @@ inpch(void)
 {
 
        do {
-               if (ifiles->curptr < ifiles->maxread)
-                       return *ifiles->curptr++;
+               if (ifiles->ib->cptr < ifiles->ib->bsz)
+                       return ifiles->ib->buf[ifiles->ib->cptr++];
        } while (inpbuf() > 0);
 
        return -1;
@@ -218,10 +217,10 @@ unch(int c)
        if (c == -1)
                return;
 
-       ifiles->curptr--;
-       if (ifiles->curptr < ifiles->bbuf)
+       ifiles->ib->cptr--;
+       if (ifiles->ib->cptr < 0)
                error("pushback buffer full");
-       *ifiles->curptr = (usch)c;
+       ifiles->ib->buf[ifiles->ib->cptr] = (usch)c;
 }
 
 /*
@@ -479,6 +478,27 @@ fastspcg(void)
        return ch;
 }
 
+/*
+ * readin chars and store in buf. Warn about too long names.
+ */
+usch *
+bufid(int ch, struct iobuf *ob)
+{
+       int n = ob->cptr;
+
+       do {
+               if (ob->cptr - n == MAXIDSZ)
+                       warning("identifier exceeds C99 5.2.4.1");
+               if (ob->cptr < ob->bsz)
+                       ob->buf[ob->cptr++] = ch;
+               else
+                       putob(ob, ch);
+       } while (spechr[ch = inch()] & C_ID);
+       ob->buf[ob->cptr] = 0; /* legal */
+       unch(ch);
+       return ob->buf+n;
+}
+
 usch idbuf[MAXIDSZ+1];
 /*
  * readin chars and store in buf. Warn about too long names.
@@ -503,40 +523,45 @@ readid(int ch)
 /*
  * get a string or character constant and save it as given by d.
  */
-void
-faststr(int bc, void (*d)(int))
+struct iobuf *
+faststr(int bc, struct iobuf *ob)
 {
        int ch;
 
+       if (ob == NULL)
+               ob = getobuf(BNORMAL);
+
        incmnt = 1;
-       d(bc);
+       putob(ob, bc);
        while ((ch = inc2()) != bc) {
                if (ch == '\n') {
                        warning("unterminated literal");
                        incmnt = 0;
                        unch(ch);
-                       return;
+                       return ob;
                }
                if (ch < 0)
-                       return;
+                       return ob;
                if (ch == '\\') {
                        incmnt = 0;
                        if (chkucn())
                                continue;
                        incmnt = 1;
-                       d(ch);
+                       putob(ob, ch);
                        ch = inc2();
                }
-               d(ch);
+               putob(ob, ch);
        }
-       d(ch);
+       putob(ob, ch);
+       ob->buf[ob->cptr] = 0;
        incmnt = 0;
+       return ob;
 }
 
 /*
- * get a preprocessing number and save it as given by d.
- * Initial char ch is always stored.
+ * get a preprocessing number and save it as given by ob.
  * returns first non-pp-number char.
+ * We know that this is a valid number already.
  *
  *     pp-number:      digit
  *                     . digit
@@ -549,19 +574,17 @@ faststr(int bc, void (*d)(int))
  *                     pp-number .
  */
 int
-fastnum(int ch, void (*d)(int))
+fastnum(int ch, struct iobuf *ob)
 {
        int c2;
 
        if ((spechr[ch] & C_DIGIT) == 0) {
                /* not digit, dot */
-               d(ch);
+               putob(ob, ch);
                ch = inch();
-               if ((spechr[ch] & C_DIGIT) == 0)
-                       return ch;
        }
        for (;;) {
-               d(ch);
+               putob(ob, ch);
                if ((ch = inch()) < 0)
                        return -1;
                if ((spechr[ch] & C_EP)) {
@@ -570,7 +593,7 @@ fastnum(int ch, void (*d)(int))
                                        unch(c2);
                                break;
                        }
-                       d(ch);
+                       putob(ob, ch);
                        ch = c2;
                } else if (ch == '.' || (spechr[ch] & C_ID)) {
                        continue;
@@ -590,13 +613,19 @@ fastnum(int ch, void (*d)(int))
  *     Only data from pp files are scanned here, never any rescans.
  *     This loop is always at trulvl.
  */
-static void
+void
 fastscan(void)
 {
-       struct iobuf *ob;
+       struct iobuf *ob, rbs, *rb = &rbs;
+       extern struct iobuf pb;
        struct symtab *nl;
        int ch, c2, i, nch;
-       usch *cp, *dp;
+       usch *dp;
+
+#define        IDSIZE  128
+       rb->buf = xmalloc(IDSIZE+1);
+       rb->cptr = 0;
+       rb->bsz = IDSIZE;
 
        goto run;
 
@@ -604,22 +633,25 @@ fastscan(void)
                /* tight loop to find special chars */
                /* should use getchar/putchar here */
                for (;;) {
-                       if (ifiles->curptr < ifiles->maxread) {
-                               ch = *ifiles->curptr++;
+                       if (ifiles->ib->cptr < ifiles->ib->bsz) {
+                               ch = ifiles->ib->buf[ifiles->ib->cptr++];
                        } else {
                                if (inpbuf() > 0)
                                        continue;
+                               free(rb->buf);
                                return;
                        }
-xloop:                 if (ch < 0)
+xloop:                 if (ch < 0) {
+                               free(rb->buf);
                                return; /* EOF */
+                       }
                        if ((spechr[ch] & C_SPEC) != 0)
                                break;
                        putch(ch);
                }
 
                REFILL(2);
-               nch = *ifiles->curptr;
+               nch = ifiles->ib->buf[ifiles->curptr];
                switch (ch) {
                case WARN:
                case CONC:
@@ -674,17 +706,21 @@ run:                      while ((ch = inch()) == '\t' || ch == ' ')
                        }
                        /* FALLTHROUGH */
                case '\"': /* strings */
-                       faststr(ch, putch);
+                       faststr(ch, &pb);
                        break;
 
                case '.':  /* for pp-number */
+                       if ((spechr[nch] & C_DIGIT) == 0) {
+                               putch('.');
+                               break;
+                       }
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
-                       ch = fastnum(ch, putch);
+                       ch = fastnum(ch, &pb);
                        goto xloop;
 
                case 'u':
-                       if (nch == '8' && ifiles->curptr[1] == '\"') {
+                       if (nch == '8' && ifiles->ib->buf[ifiles->curptr+1] == '\"') {
                                putch(ch);
                                break;
                        }
@@ -704,20 +740,22 @@ run:                      while ((ch = inch()) == '\t' || ch == ' ')
                ident:
                        if (flslvl)
                                error("fastscan flslvl");
-                       dp = readid(ch);
-                       if ((nl = lookup(dp, FIND))) {
-                               if ((ob = kfind(nl))) {
+                       rb->cptr = 0;
+                       dp = bufid(ch, rb);
+                       if ((nl = lookup(dp, FIND)) != NULL) {
+                               if ((ob = kfind(nl)) != NULL) {
                                        if (*ob->buf == '-' || *ob->buf == '+')
                                                putch(' ');
-                                       for (cp = ob->buf; cp < ob->cptr; cp++)
-                                               putch(*cp);
-                                       if (ob->cptr[-1] == '-' ||
-                                           ob->cptr[-1] == '+')
+                                       buftobuf(ob, &pb);
+                                       if (ob->cptr > 0 &&
+                                           (ob->buf[ob->cptr-1] == '-' ||
+                                           ob->buf[ob->cptr-1] == '+'))
                                                putch(' ');
                                        bufree(ob);
                                }
-                       } else
+                       } else {
                                putstr(dp);
+                       }
                        break;
 
                case '\\':
@@ -748,24 +786,32 @@ int inexpr;
 static int
 exprline(void)
 {
-       struct iobuf *ob;
+       extern int nbufused;
+       struct iobuf *ob, *rb;
        struct symtab *nl;
        int oCflag = Cflag;
-       usch *bp = stringbuf, *dp;
+       usch *dp;
        int c, d, ifdef;
 
+       rb = getobuf(BNORMAL);
+       nbufused--;
        Cflag = ifdef = 0;
 
-       while ((c = inch()) != '\n') {
-               if (c == '\'' || c == '\"') {
-                       faststr(c, savch);
-                       continue;
+       for (;;) {
+               c = inch();
+xloop:         if (c == '\n')
+                       break;
+               if (c == '.') {
+                       putob(rb, '.');
+                       if ((spechr[c = inch()] & C_DIGIT) == 0)
+                               goto xloop;
                }
-               if (ISDIGIT(c) || c == '.') {
-                       c = fastnum(c, savch);
-                       if (c == '\n')
-                               break;
-                       unch(c);
+               if (ISDIGIT(c)) {
+                       c = fastnum(c, rb);
+                       goto xloop;
+               }
+               if (c == '\'' || c == '\"') {
+                       faststr(c, rb);
                        continue;
                }
                if (c == 'L' || c == 'u' || c == 'U') {
@@ -776,30 +822,31 @@ exprline(void)
                if (ISID0(c)) {
                        dp = readid(c);
                        nl = lookup(dp, FIND);
-                       if (nl && *nl->value == DEFLOC) {
+                       if (nl && nl->type == DEFLOC) {
                                ifdef = 1;
                        } else if (ifdef) {
-                               savch(nl ? '1' : '0');
+                               putob(rb, nl ? '1' : '0');
                                ifdef = 0;
                        } else if (nl != NULL) {
                                inexpr = 1;
                                if ((ob = kfind(nl))) {
-                                       putob(ob, 0);
-                                       savstr(ob->buf);
+                                       ob->buf[ob->cptr] = 0;
+                                       strtobuf(ob->buf, rb);
                                        bufree(ob);
                                } else
-                                       savch('0');
+                                       putob(rb, '0');
                                inexpr = 0;
                        } else
-                               savch('0');
+                               putob(rb, '0');
                } else
-                       savch(c);
+                       putob(rb, c);
        }
-       savch(0);
+       rb->buf[rb->cptr] = 0;
        unch('\n');
-       yyinp = bp;
+       yyinp = rb->buf;
        c = yyparse();
-       stringbuf = bp;
+       bufree(rb);
+       nbufused++;
        Cflag = oCflag;
        return c;
 }
@@ -868,48 +915,6 @@ yylex(void)
        return ch;
 }
 
-/*
- * Let the command-line args be faked defines at beginning of file.
- */
-static void
-prinit(struct initar *it, struct includ *ic)
-{
-       const char *pre, *post;
-       char *a;
-
-       if (it->next)
-               prinit(it->next, ic);
-       pre = post = NULL; /* XXX gcc */
-       switch (it->type) {
-       case 'D':
-               pre = "#define ";
-               if ((a = strchr(it->str, '=')) != NULL) {
-                       *a = ' ';
-                       post = "\n";
-               } else
-                       post = " 1\n";
-               break;
-       case 'U':
-               pre = "#undef ";
-               post = "\n";
-               break;
-       case 'i':
-               pre = "#include \"";
-               post = "\"\n";
-               break;
-       default:
-               error("prinit");
-       }
-       strlcat((char *)ic->buffer, pre, CPPBUF+1);
-       strlcat((char *)ic->buffer, it->str, CPPBUF+1);
-       if (strlcat((char *)ic->buffer, post, CPPBUF+1) >= CPPBUF+1)
-               error("line exceeds buffer size");
-
-       ic->lineno--;
-       while (*ic->maxread)
-               ic->maxread++;
-}
-
 /*
  * A new file included.
  * If ifiles == NULL, this is the first file and already opened (stdin).
@@ -918,7 +923,6 @@ prinit(struct initar *it, struct includ *ic)
 int
 pushfile(const usch *file, const usch *fn, int idx, void *incs)
 {
-       extern struct initar *initar;
        struct includ ibuf;
        struct includ *ic;
        int otrulvl;
@@ -936,12 +940,16 @@ pushfile(const usch *file, const usch *fn, int idx, void *incs)
                ic->infil = 0;
                ic->orgfn = ic->fname = (const usch *)"<stdin>";
        }
-#ifndef BUF_STACK
-       ic->bbuf = malloc(BBUFSZ);
+#if LIBVMF
+       if (ifiles) {
+               vmmodify(ifiles->vseg);
+               vmunlock(ifiles->vseg);
+       }
+       ic->vseg = vmmapseg(&ibspc, inclevel);
+       vmlock(ic->vseg);
 #endif
-       ic->buffer = ic->bbuf+PBMAX;
-       ic->curptr = ic->buffer;
        ifiles = ic;
+       ic->ib = getobuf(BINBUF);
        ic->lineno = 1;
        ic->escln = 0;
        ic->maxread = ic->curptr;
@@ -949,19 +957,6 @@ pushfile(const usch *file, const usch *fn, int idx, void *incs)
        ic->incs = incs;
        ic->fn = fn;
        prtline(1);
-       if (initar) {
-               int oin = ic->infil;
-               ic->infil = -1;
-               *ic->maxread = 0;
-               prinit(initar, ic);
-               initar = NULL;
-               if (dMflag)
-                       printf("%s", (char *)ic->buffer);
-               fastscan();
-               prtline(1);
-               ic->infil = oin;
-       }
-
        otrulvl = trulvl;
 
        fastscan();
@@ -969,12 +964,26 @@ pushfile(const usch *file, const usch *fn, int idx, void *incs)
        if (otrulvl != trulvl || flslvl)
                error("unterminated conditional");
 
-#ifndef BUF_STACK
-       free(ic->bbuf);
-#endif
        ifiles = ic->next;
-       close(ic->infil);
        inclevel--;
+#if LIBVMF
+       vmmodify(ic->vseg);
+       vmunlock(ic->vseg);
+       ic->ib->ro = 1; /* XXX no free */
+       if (ifiles) {
+               int diff;
+
+               ifiles->vseg = vmmapseg(&ibspc, inclevel);
+               vmlock(ifiles->vseg);
+               /* XXX recalc ptr diffs */
+               diff = (usch *)ifiles->vseg->s_cinfo - ifiles->bbuf;
+               ifiles->bbuf += diff;
+               ifiles->maxread += diff;
+               ifiles->curptr += diff;
+       }
+#endif
+       close(ic->infil);
+       bufree(ic->ib);
        return 0;
 }
 
@@ -991,18 +1000,18 @@ prtline(int nl)
                        return; /* no output */
                if (ifiles->lineno == 1 &&
                    (MMDflag == 0 || ifiles->idx != SYSINC)) {
-                       printf("%s: %s\n", Mfile, ifiles->fname);
+                       ob = bsheap(0, "%s: %s\n", Mfile, ifiles->fname);
                        if (MPflag &&
                            strcmp((const char *)ifiles->fname, (char *)MPfile))
-                               printf("%s:\n", ifiles->fname);
+                               bsheap(ob, "%s:\n", ifiles->fname);
+                       write(1, ob->buf, ob->cptr);
+                       bufree(ob);
                }
        } else if (!Pflag) {
-               ob = bsheap(0, "\n# %d \"%s\"", ifiles->lineno, ifiles->fname);
+               bsheap(&pb, "\n# %d \"%s\"", ifiles->lineno, ifiles->fname);
                if (ifiles->idx == SYSINC)
-                       bsheap(ob, " 3");
-               if (nl) bsheap(ob, "\n");
-               putstr(ob->buf);
-               bufree(ob);
+                       strtobuf((usch *)" 3", &pb);
+               if (nl) strtobuf((usch *)"\n", &pb);
        }
 }
 
@@ -1224,43 +1233,38 @@ elifstmt(void)
                error("#elif in non-conditional section");
 }
 
-/* save line into stringbuf */
-static usch *
+/* save line into iobuf */
+static struct iobuf *
 savln(void)
 {
+       struct iobuf *ob = getobuf(BNORMAL);
        int c;
-       usch *cp = stringbuf;
 
        while ((c = inch()) != -1) {
                if (c == '\n') {
                        unch(c);
                        break;
                }
-               savch(c);
+               putob(ob, c);
        }
-       savch(0);
-
-       return cp;
+       ob->buf[ob->cptr] = 0;
+       return ob;
 }
 
 static void
 cpperror(void)
 {
-       usch *cp;
-
-       cp = savln();
-       error("#error %s", cp);
-       stringbuf = cp;
+       struct iobuf *ob = savln();
+       error("#error %s", ob->buf);
+       bufree(ob);
 }
 
 static void
 cppwarning(void)
 {
-       usch *cp;
-
-       cp = savln();
-       warning("#warning %s", cp);
-       stringbuf = cp;
+       struct iobuf *ob = savln();
+       error("#warning %s", ob->buf);
+       bufree(ob);
 }
 
 static void
@@ -1295,7 +1299,8 @@ identstmt(void)
                if (ob)
                        bufree(ob);
        } else if (ch == '\"') {
-               faststr(ch, savch);
+               bufree(faststr(ch, NULL));
+               
        } else
                goto bad;
        chknl(1);
index 14a1fef..290f7b6 100644 (file)
 /* Type to use for wide characters */
 #undef WCHAR_TYPE
 
+/* determine whether 16, 32 or 64 bit host */
+#undef SIZEOF_INT_P
+
+/* Compile for use of libvmf */
+#undef LIBVMF
+
 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
    significant byte first (like Motorola and SPARC, unlike Intel). */
 #if defined AC_APPLE_UNIVERSAL_BUILD
index d40b18a..3442a2d 100755 (executable)
@@ -712,6 +712,7 @@ with_incdir
 with_libdir
 with_assembler
 with_linker
+with_libvmf
 enable_tls
 enable_Werror
 enable_gcc_compat
@@ -1366,6 +1367,7 @@ Optional Packages:
   --with-libdir=<path>    Specify the default library path.
   --with-assembler=<path> Specify alternate assember.
   --with-linker=<path>    Specify alternate linker.
+  --with-libvmf=<path>    Use libvmf.
   --use-yasm              Use yasm assembler
 
 Some influential environment variables:
@@ -1613,6 +1615,189 @@ $as_echo "$ac_res" >&6; }
 
 } # ac_fn_c_check_header_compile
 
+# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
+# --------------------------------------------
+# Tries to find the compile-time value of EXPR in a program that includes
+# INCLUDES, setting VAR accordingly. Returns whether the value could be
+# computed
+ac_fn_c_compute_int ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if test "$cross_compiling" = yes; then
+    # Depending upon the size, compute the lo and hi bounds.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= 0)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid; break
+else
+  as_fn_arith $ac_mid + 1 && ac_lo=$as_val
+                       if test $ac_lo -le $ac_mid; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) < 0)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=$ac_mid; break
+else
+  as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val
+                       if test $ac_mid -le $ac_hi; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  ac_lo= ac_hi=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid
+else
+  as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in #((
+?*) eval "$3=\$ac_lo"; ac_retval=0 ;;
+'') ac_retval=1 ;;
+esac
+  else
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+static long int longval () { return $2; }
+static unsigned long int ulongval () { return $2; }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    return 1;
+  if (($2) < 0)
+    {
+      long int i = longval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%ld", i);
+    }
+  else
+    {
+      unsigned long int i = ulongval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%lu", i);
+    }
+  /* Do not output a trailing newline, as this causes \r\n confusion
+     on some platforms.  */
+  return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  echo >>conftest.val; read $3 <conftest.val; ac_retval=0
+else
+  ac_retval=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+rm -f conftest.val
+
+  fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_compute_int
+
 # ac_fn_c_try_link LINENO
 # -----------------------
 # Try to link conftest.$ac_ext, and return whether this succeeded.
@@ -2769,6 +2954,14 @@ if test "${with_linker+set}" = set; then :
   withval=$with_linker; linker=$withval
 fi
 
+
+# Check whether --with-libvmf was given.
+if test "${with_libvmf+set}" = set; then :
+  withval=$with_libvmf; libvmf=$withval
+else
+  libvmf=no
+fi
+
 # Check whether --enable-tls was given.
 if test "${enable_tls+set}" = set; then :
   enableval=$enable_tls; tls=$enableval
@@ -4314,6 +4507,40 @@ $as_echo "#define HAVE_C99_FORMAT 1" >>confdefs.h
 
 fi
 
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of int *" >&5
+$as_echo_n "checking size of int *... " >&6; }
+if ${ac_cv_sizeof_int_p+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (int *))" "ac_cv_sizeof_int_p"        "$ac_includes_default"; then :
+
+else
+  if test "$ac_cv_type_int_p" = yes; then
+     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "cannot compute sizeof (int *)
+See \`config.log' for more details" "$LINENO" 5; }
+   else
+     ac_cv_sizeof_int_p=0
+   fi
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_int_p" >&5
+$as_echo "$ac_cv_sizeof_int_p" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_INT_P $ac_cv_sizeof_int_p
+_ACEOF
+
+
+
 # Byteorder of host
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
 $as_echo_n "checking whether byte ordering is bigendian... " >&6; }
@@ -4872,6 +5099,15 @@ rm -f conftest.l $LEX_OUTPUT_ROOT.c
 fi
 
 # Checks for libraries.
+if test $libvmf != no ; then
+       LIBS=-lvmf
+
+$as_echo "#define LIBVMF 1" >>confdefs.h
+
+if test $libvmf != yes ; then
+       LDFLAGS=-L$libvmf
+fi
+fi
 
 # Checks for header files.
 # AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h])
@@ -5005,6 +5241,8 @@ else
 # ifdef _MSC_VER
 #  include <malloc.h>
 #  define alloca _alloca
+# elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
+#   include <stdlib.h>
 # else
 #  ifdef HAVE_ALLOCA_H
 #   include <alloca.h>
@@ -5160,6 +5398,8 @@ fi
 
 
 
+
+
 
 pcc_major=`echo $PACKAGE_VERSION | awk -F. '{print $1}'`
 pcc_minor=`echo $PACKAGE_VERSION | awk -F. '{print $2}'`
@@ -6496,6 +6736,7 @@ echo "Using linker ..................... ${linker-<default>}"
 echo "Using Multi-Arch path ............ ${multiarch}"
 echo "Using include path ............... ${altincdir-<default>}"
 echo "Using library path ............... ${altlibdir-<default>}"
+echo "Use libvmf ....................... $libvmf"
 echo "Has TLS support .................. $tls"
 echo "Has native floating point ........ $nativefp"
 echo "Has GCC compatibility ............ $gcccompat"
index 6affe90..c10ccd2 100644 (file)
@@ -384,6 +384,11 @@ AC_ARG_WITH(linker,
                [Specify alternate linker.]),
        linker=$withval,
        [])
+AC_ARG_WITH(libvmf,
+       AS_HELP_STRING([--with-libvmf=<path>],
+               [Use libvmf.]),
+       libvmf=$withval,
+       libvmf=no)
 AC_ARG_ENABLE(tls,
        AS_HELP_STRING([--enable-tls],
                [Enable Thread-local storage (TLS).]),
@@ -610,6 +615,8 @@ if test $ac_cv_have_c99_format = yes; then
     [Define to 1 if printf supports C99 size specifiers])
 fi
 
+AC_CHECK_SIZEOF([int *])
+
 # Byteorder of host
 AC_C_BIGENDIAN([AC_DEFINE(HOST_BIG_ENDIAN, 1, [Define if host is BIG endian])],
        [AC_DEFINE(HOST_LITTLE_ENDIAN, 1, [Define if host is LITTLE endian])],
@@ -622,6 +629,13 @@ AC_PROG_YACC
 AC_PROG_LEX
 
 # Checks for libraries.
+if test $libvmf != no ; then
+       LIBS=-lvmf
+       AC_DEFINE(LIBVMF, 1, [Use libvmf.])
+if test $libvmf != yes ; then
+       LDFLAGS=-L$libvmf
+fi
+fi
 
 # Checks for header files.
 # AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h])
@@ -651,6 +665,8 @@ AC_SUBST(ADD_CPPFLAGS)
 AC_SUBST(CCNAMES)
 AC_SUBST(CF0)
 AC_SUBST(CF1)
+AC_SUBST(LIBS)
+AC_SUBST(LDFLAGS)
 
 pcc_major=`echo $PACKAGE_VERSION | awk -F. '{print $1}'`
 pcc_minor=`echo $PACKAGE_VERSION | awk -F. '{print $2}'`
@@ -692,6 +708,7 @@ echo "Using linker ..................... ${linker-<default>}"
 echo "Using Multi-Arch path ............ ${multiarch}"
 echo "Using include path ............... ${altincdir-<default>}"
 echo "Using library path ............... ${altlibdir-<default>}"
+echo "Use libvmf ....................... $libvmf"
 echo "Has TLS support .................. $tls"
 echo "Has native floating point ........ $nativefp"
 echo "Has GCC compatibility ............ $gcccompat"
index b710f74..1e6a67b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: reader.c,v 1.299 2015/11/17 19:19:40 ragge Exp $   */
+/*     $Id: reader.c,v 1.300 2016/04/02 09:47:12 ragge Exp $   */
 /*
  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
  * All rights reserved.
@@ -414,7 +414,8 @@ rdnode(char *s)
        s++; s++;
        p->n_regw = NULL;
        p->n_ap = NULL;
-       p->n_su = p->n_lval = p->n_rval = 0;
+       p->n_su = p->n_rval = 0;
+       setlval(p, 0);
        p->n_op = rdint(&s);
        p->n_type = rdint(&s);
        p->n_qual = rdint(&s);
@@ -431,7 +432,7 @@ rdnode(char *s)
        if (ty == UTYPE) {
                p->n_rval = rdint(&s);
        } else if (ty == LTYPE) {
-               p->n_lval = strtoll(s, &s, 10);
+               setlval(p, strtoll(s, &s, 10));
                if (p->n_op == NAME || p->n_op == ICON) {
                        SKIPWS(s);
                        if (*s && *s != '+')