added depend label
[unix-history] / usr / src / usr.bin / ex / ex_cmdsub.c
index ae7b2f6..bec0d1a 100644 (file)
@@ -1,4 +1,13 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)ex_cmdsub.c 7.8 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -82,12 +91,12 @@ pargs()
 
        for (ac = 0; ac < argc0; ac++) {
                if (ac != 0)
 
        for (ac = 0; ac < argc0; ac++) {
                if (ac != 0)
-                       putchar(' ');
+                       ex_putchar(' ' | QUOTE);
                if (ac + argc == argc0 - 1)
                if (ac + argc == argc0 - 1)
-                       printf("[");
+                       ex_printf("[");
                lprintf("%s", as);
                if (ac + argc == argc0 - 1)
                lprintf("%s", as);
                if (ac + argc == argc0 - 1)
-                       printf("]");
+                       ex_printf("]");
                as = av ? *++av : strend(as) + 1;
        }
        noonl();
                as = av ? *++av : strend(as) + 1;
        }
        noonl();
@@ -97,7 +106,7 @@ pargs()
  * Delete lines; two cases are if we are really deleting,
  * more commonly we are just moving lines to the undo save area.
  */
  * Delete lines; two cases are if we are really deleting,
  * more commonly we are just moving lines to the undo save area.
  */
-delete(hush)
+ex_delete(hush)
        bool hush;
 {
        register line *a1, *a2;
        bool hush;
 {
        register line *a1, *a2;
@@ -106,6 +115,10 @@ delete(hush)
        if(FIXUNDO) {
                register int (*dsavint)();
 
        if(FIXUNDO) {
                register int (*dsavint)();
 
+#ifdef TRACE
+               if (trace)
+                       vudump("before delete");
+#endif
                change();
                dsavint = signal(SIGINT, SIG_IGN);
                undkind = UNDCHANGE;
                change();
                dsavint = signal(SIGINT, SIG_IGN);
                undkind = UNDCHANGE;
@@ -124,6 +137,10 @@ delete(hush)
                dot = a1;
                pkill[0] = pkill[1] = 0;
                signal(SIGINT, dsavint);
                dot = a1;
                pkill[0] = pkill[1] = 0;
                signal(SIGINT, dsavint);
+#ifdef TRACE
+               if (trace)
+                       vudump("after delete");
+#endif
        } else {
                register line *a3;
                register int i;
        } else {
                register line *a3;
                register int i;
@@ -213,7 +230,7 @@ join(c)
                cp--;
        }
        strcLIN(genbuf);
                cp--;
        }
        strcLIN(genbuf);
-       delete(0);
+       ex_delete(0);
        jcount = 1;
        if (FIXUNDO)
                undap1 = undap2 = addr1;
        jcount = 1;
        if (FIXUNDO)
                undap1 = undap2 = addr1;
@@ -248,7 +265,7 @@ move()
                setdot();
        }
        nonzero();
                setdot();
        }
        nonzero();
-       adt = address(0);
+       adt = address((char*)0);
        if (adt == 0)
                serror("%s where?|%s requires a trailing address", Command);
        newline();
        if (adt == 0)
                serror("%s where?|%s requires a trailing address", Command);
        newline();
@@ -460,20 +477,12 @@ tagfind(quick)
        int tfcount = 0;
        int omagic;
        char *fn, *fne;
        int tfcount = 0;
        int omagic;
        char *fn, *fne;
-#ifdef VMUNIX
-       /*
-        * We have lots of room so we bring in stdio and do
-        * a binary search on the tags file.
-        */
-# undef EOF
-# include <stdio.h>
-# undef getchar
-# undef putchar
-       FILE *iof;
-       char iofbuf[BUFSIZ];
+       struct stat sbuf;
+#ifdef FASTTAG
+       int iof;
+       char iofbuf[MAXBSIZE];
        long mid;       /* assumed byte offset */
        long top, bot;  /* length of tag file */
        long mid;       /* assumed byte offset */
        long top, bot;  /* length of tag file */
-       struct stat sbuf;
 #endif
 
        omagic = value(MAGIC);
 #endif
 
        omagic = value(MAGIC);
@@ -482,7 +491,7 @@ tagfind(quick)
 
                while (!iswhite(peekchar()) && !endcmd(peekchar()))
                        if (lp < &lasttag[sizeof lasttag - 2])
 
                while (!iswhite(peekchar()) && !endcmd(peekchar()))
                        if (lp < &lasttag[sizeof lasttag - 2])
-                               *lp++ = getchar();
+                               *lp++ = ex_getchar();
                        else
                                ignchar();
                *lp++ = 0;
                        else
                                ignchar();
                *lp++ = 0;
@@ -491,7 +500,7 @@ badtag:
                        error("Bad tag|Give one tag per line");
        } else if (lasttag[0] == 0)
                error("No previous tag");
                        error("Bad tag|Give one tag per line");
        } else if (lasttag[0] == 0)
                error("No previous tag");
-       c = getchar();
+       c = ex_getchar();
        if (!endcmd(c))
                goto badtag;
        if (c == EOF)
        if (!endcmd(c))
                goto badtag;
        if (c == EOF)
@@ -511,15 +520,14 @@ badtag:
                        fne = 0;        /* done, quit after this time */
                else
                        *fne = 0;       /* null terminate filename */
                        fne = 0;        /* done, quit after this time */
                else
                        *fne = 0;       /* null terminate filename */
-#ifdef VMUNIX
-               iof = fopen(fn, "r");
-               if (iof == NULL)
+#ifdef FASTTAG
+               iof = topen(fn, iofbuf);
+               if (iof == -1)
                        continue;
                tfcount++;
                        continue;
                tfcount++;
-               setbuf(iof, iofbuf);
-               fstat(fileno(iof), &sbuf);
+               fstat(iof, &sbuf);
                top = sbuf.st_size;
                top = sbuf.st_size;
-               if (top == 0L || iof == NULL)
+               if (top == 0L )
                        top = -1L;
                bot = 0L;
                while (top >= bot) {
                        top = -1L;
                bot = 0L;
                while (top >= bot) {
@@ -531,6 +539,13 @@ badtag:
                if (io<0)
                        continue;
                tfcount++;
                if (io<0)
                        continue;
                tfcount++;
+               if (fstat(io, &sbuf) < 0)
+                       bsize = LBSIZE;
+               else {
+                       bsize = sbuf.st_blksize;
+                       if (bsize <= 0)
+                               bsize = LBSIZE;
+               }
                while (getfile() == 0) {
 #endif
                        /* loop for each tags file entry */
                while (getfile() == 0) {
 #endif
                        /* loop for each tags file entry */
@@ -538,21 +553,29 @@ badtag:
                        register char *lp = lasttag;
                        char *oglobp;
 
                        register char *lp = lasttag;
                        char *oglobp;
 
-#ifdef VMUNIX
+#ifdef FASTTAG
                        mid = (top + bot) / 2;
                        mid = (top + bot) / 2;
-                       fseek(iof, mid, 0);
+                       tseek(iof, mid);
                        if (mid > 0)    /* to get first tag in file to work */
                        if (mid > 0)    /* to get first tag in file to work */
-                               fgets(linebuf, sizeof linebuf, iof);    /* scan to next \n */
-                       fgets(linebuf, sizeof linebuf, iof);    /* get a line */
-                       linebuf[strlen(linebuf)-1] = 0; /* was '\n' */
+                               /* scan to next \n */
+                               if(tgets(linebuf, sizeof linebuf, iof)==NULL)
+                                       goto goleft;
+                       /* get the line itself */
+                       if(tgets(linebuf, sizeof linebuf, iof)==NULL)
+                               goto goleft;
+#ifdef TDEBUG
+                       ex_printf("tag: %o %o %o %s\n", bot, mid, top, linebuf);
+#endif
 #endif
                        while (*cp && *lp == *cp)
                                cp++, lp++;
 #endif
                        while (*cp && *lp == *cp)
                                cp++, lp++;
-                       if ((*lp || !iswhite(*cp)) && (value(TAGLENGTH)==0 || lp-lasttag < value(TAGLENGTH))) {
-#ifdef VMUNIX
+                       if ((*lp || !iswhite(*cp)) && (value(TAGLENGTH)==0 ||
+                           lp-lasttag < value(TAGLENGTH))) {
+#ifdef FASTTAG
                                if (*lp > *cp)
                                        bot = mid + 1;
                                else
                                if (*lp > *cp)
                                        bot = mid + 1;
                                else
+goleft:
                                        top = mid - 1;
 #endif
                                /* Not this tag.  Try the next */
                                        top = mid - 1;
 #endif
                                /* Not this tag.  Try the next */
@@ -562,8 +585,8 @@ badtag:
                        /*
                         * We found the tag.  Decode the line in the file.
                         */
                        /*
                         * We found the tag.  Decode the line in the file.
                         */
-#ifdef VMUNIX
-                       fclose(iof);
+#ifdef FASTTAG
+                       tclose(iof);
 #else
                        close(io);
 #endif
 #else
                        close(io);
 #endif
@@ -644,8 +667,8 @@ badtags:
                /*
                 * No such tag in this file.  Close it and try the next.
                 */
                /*
                 * No such tag in this file.  Close it and try the next.
                 */
-#ifdef VMUNIX
-               fclose(iof);
+#ifdef FASTTAG
+               tclose(iof);
 #else
                close(io);
 #endif
 #else
                close(io);
 #endif
@@ -695,7 +718,7 @@ zop(hadpr)
        znoclear = 0;
        zweight = 0;
        excl = exclam();
        znoclear = 0;
        zweight = 0;
        excl = exclam();
-       switch (c = op = getchar()) {
+       switch (c = op = ex_getchar()) {
 
        case '^':
                zweight = 1;
 
        case '^':
                zweight = 1;
@@ -707,7 +730,7 @@ zop(hadpr)
                }
        case '=':
        case '.':
                }
        case '=':
        case '.':
-               c = getchar();
+               c = ex_getchar();
                break;
 
        case EOF:
                break;
 
        case EOF:
@@ -721,7 +744,7 @@ zop(hadpr)
        if (isdigit(c)) {
                lines = c - '0';
                for(;;) {
        if (isdigit(c)) {
                lines = c - '0';
                for(;;) {
-                       c = getchar();
+                       c = ex_getchar();
                        if (!isdigit(c))
                                break;
                        lines *= 10;
                        if (!isdigit(c))
                                break;
                        lines *= 10;
@@ -807,7 +830,7 @@ zop2(lines, op)
                return;
        if (op == EOF && zhadpr) {
                getline(*addr1);
                return;
        if (op == EOF && zhadpr) {
                getline(*addr1);
-               putchar('\r' | QUOTE);
+               ex_putchar('\r' | QUOTE);
                shudclob = 1;
        } else if (znoclear == 0 && CL != NOSTR && !inopen) {
                flush1();
                shudclob = 1;
        } else if (znoclear == 0 && CL != NOSTR && !inopen) {
                flush1();
@@ -831,7 +854,7 @@ splitit()
        register int l;
 
        for (l = COLUMNS > 80 ? 40 : COLUMNS / 2; l > 0; l--)
        register int l;
 
        for (l = COLUMNS > 80 ? 40 : COLUMNS / 2; l > 0; l--)
-               putchar('-');
+               ex_putchar('-');
        putnl();
 }
 
        putnl();
 }
 
@@ -847,7 +870,7 @@ plines(adr1, adr2, movedot)
                getline(*addr);
                pline(lineno(addr));
                if (inopen)
                getline(*addr);
                pline(lineno(addr));
                if (inopen)
-                       putchar('\n' | QUOTE);
+                       ex_putchar('\n' | QUOTE);
                if (movedot)
                        dot = addr;
        }
                if (movedot)
                        dot = addr;
        }
@@ -1055,7 +1078,7 @@ mapcmd(un, ab)
 {
        char lhs[100], rhs[100];        /* max sizes resp. */
        register char *p;
 {
        char lhs[100], rhs[100];        /* max sizes resp. */
        register char *p;
-       register char c;
+       register int c;         /* mjm: char --> int */
        char *dname;
        struct maps *mp;        /* the map structure we are working on */
 
        char *dname;
        struct maps *mp;        /* the map structure we are working on */
 
@@ -1073,9 +1096,9 @@ mapcmd(un, ab)
                for (i=0; mp[i].mapto; i++)
                        if (mp[i].cap) {
                                lprintf("%s", mp[i].descr);
                for (i=0; mp[i].mapto; i++)
                        if (mp[i].cap) {
                                lprintf("%s", mp[i].descr);
-                               putchar('\t');
+                               ex_putchar('\t');
                                lprintf("%s", mp[i].cap);
                                lprintf("%s", mp[i].cap);
-                               putchar('\t');
+                               ex_putchar('\t');
                                lprintf("%s", mp[i].mapto);
                                putNFL();
                        }
                                lprintf("%s", mp[i].mapto);
                                putNFL();
                        }
@@ -1084,9 +1107,9 @@ mapcmd(un, ab)
 
        ignore(skipwh());
        for (p=lhs; ; ) {
 
        ignore(skipwh());
        for (p=lhs; ; ) {
-               c = getchar();
+               c = ex_getchar();
                if (c == CTRL(v)) {
                if (c == CTRL(v)) {
-                       c = getchar();
+                       c = ex_getchar();
                } else if (!un && any(c, " \t")) {
                        /* End of lhs */
                        break;
                } else if (!un && any(c, " \t")) {
                        /* End of lhs */
                        break;
@@ -1107,9 +1130,9 @@ mapcmd(un, ab)
        if (skipend())
                error("Missing rhs");
        for (p=rhs; ; ) {
        if (skipend())
                error("Missing rhs");
        for (p=rhs; ; ) {
-               c = getchar();
+               c = ex_getchar();
                if (c == CTRL(v)) {
                if (c == CTRL(v)) {
-                       c = getchar();
+                       c = ex_getchar();
                } else if (endcmd(c) && c!='"') {
                        ungetchar(c);
                        break;
                } else if (endcmd(c) && c!='"') {
                        ungetchar(c);
                        break;
@@ -1247,7 +1270,7 @@ char c;
        char macbuf[BUFSIZ];
        line *ad, *a1, *a2;
        char *oglobp;
        char macbuf[BUFSIZ];
        line *ad, *a1, *a2;
        char *oglobp;
-       char pk;
+       short pk;
        bool oinglobal;
 
        lastmac = c;
        bool oinglobal;
 
        lastmac = c;