diff options
Diffstat (limited to 'contrib/nvi/ex')
55 files changed, 2102 insertions, 2429 deletions
diff --git a/contrib/nvi/ex/ex.c b/contrib/nvi/ex/ex.c index ecdae4b..609f961 100644 --- a/contrib/nvi/ex/ex.c +++ b/contrib/nvi/ex/ex.c @@ -7,18 +7,15 @@ * See the LICENSE file for redistribution information. */ -/* $FreeBSD$ */ - #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex.c 10.57 (Berkeley) 10/10/96"; +static const char sccsid[] = "$Id: ex.c,v 10.80 2012/10/03 16:24:40 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> #include <sys/stat.h> -#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -37,11 +34,11 @@ static const char sccsid[] = "@(#)ex.c 10.57 (Berkeley) 10/10/96"; static void ex_comlog __P((SCR *, EXCMD *)); #endif static EXCMDLIST const * - ex_comm_search __P((char *, size_t)); + ex_comm_search __P((CHAR_T *, size_t)); static int ex_discard __P((SCR *)); static int ex_line __P((SCR *, EXCMD *, MARK *, int *, int *)); static int ex_load __P((SCR *)); -static void ex_unknown __P((SCR *, char *, size_t)); +static void ex_unknown __P((SCR *, CHAR_T *, size_t)); /* * ex -- @@ -50,8 +47,7 @@ static void ex_unknown __P((SCR *, char *, size_t)); * PUBLIC: int ex __P((SCR **)); */ int -ex(spp) - SCR **spp; +ex(SCR **spp) { EX_PRIVATE *exp; GS *gp; @@ -69,9 +65,9 @@ ex(spp) return (1); /* Flush any saved messages. */ - while ((mp = gp->msgq.lh_first) != NULL) { + while ((mp = SLIST_FIRST(gp->msgq)) != NULL) { gp->scr_msg(sp, mp->mtype, mp->buf, mp->len); - LIST_REMOVE(mp, q); + SLIST_REMOVE_HEAD(gp->msgq, q); free(mp->buf); free(mp); } @@ -107,7 +103,7 @@ ex(spp) /* Clear any current interrupts, and get a command. */ CLR_INTERRUPT(sp); - if (ex_txt(sp, &sp->tiq, ':', flags)) + if (ex_txt(sp, sp->tiq, ':', flags)) return (1); if (INTERRUPTED(sp)) { (void)ex_puts(sp, "\n"); @@ -122,9 +118,9 @@ ex(spp) * If the user entered a single carriage return, send * ex_cmd() a separator -- it discards single newlines. */ - tp = sp->tiq.cqh_first; + tp = TAILQ_FIRST(sp->tiq); if (tp->len == 0) { - gp->excmd.cp = " "; /* __TK__ why not |? */ + gp->excmd.cp = L(" "); /* __TK__ why not |? */ gp->excmd.clen = 1; } else { gp->excmd.cp = tp->lb; @@ -194,8 +190,7 @@ ex(spp) * PUBLIC: int ex_cmd __P((SCR *)); */ int -ex_cmd(sp) - SCR *sp; +ex_cmd(SCR *sp) { enum nresult nret; EX_PRIVATE *exp; @@ -207,9 +202,12 @@ ex_cmd(sp) u_int32_t flags; long ltmp; int at_found, gv_found; - int ch, cnt, delim, isaddr, namelen; + int cnt, delim, isaddr, namelen; int newscreen, notempty, tmp, vi_address; - char *arg1, *p, *s, *t; + CHAR_T *arg1, *s, *p, *t; + CHAR_T ch = '\0'; + CHAR_T *n; + char *np; gp = sp->gp; exp = EXP(sp); @@ -219,7 +217,7 @@ ex_cmd(sp) * This means that *everything* must be resolved when we leave * this function for any reason. */ -loop: ecp = gp->ecq.lh_first; +loop: ecp = SLIST_FIRST(gp->ecq); /* If we're reading a command from a file, set up error information. */ if (ecp->if_name != NULL) { @@ -261,7 +259,7 @@ loop: ecp = gp->ecq.lh_first; if ((ch = *ecp->cp) == '\n') { ++gp->if_lno; ++ecp->if_lno; - } else if (isblank(ch)) + } else if (cmdskip(ch)) notempty = 1; else break; @@ -300,7 +298,7 @@ loop: ecp = gp->ecq.lh_first; /* Skip whitespace. */ for (; ecp->clen > 0; ++ecp->cp, --ecp->clen) { ch = *ecp->cp; - if (!isblank(ch)) + if (!cmdskip(ch)) break; } @@ -323,7 +321,7 @@ loop: ecp = gp->ecq.lh_first; (!notempty || F_ISSET(sp, SC_VI) || F_ISSET(ecp, E_BLIGNORE))) { if (ex_load(sp)) goto rfail; - ecp = gp->ecq.lh_first; + ecp = SLIST_FIRST(gp->ecq); if (ecp->clen == 0) goto rsuccess; goto loop; @@ -355,7 +353,7 @@ loop: ecp = gp->ecq.lh_first; */ for (; ecp->clen > 0; ++ecp->cp, --ecp->clen) { ch = *ecp->cp; - if (!isblank(ch) && ch != ':') + if (!cmdskip(ch) && ch != ':') break; } @@ -379,10 +377,10 @@ loop: ecp = gp->ecq.lh_first; * from vi mode, and displayed lines 2, 3, and 4, so we do a default * command for each separator. */ -#define SINGLE_CHAR_COMMANDS "\004!#&*<=>@~" +#define SINGLE_CHAR_COMMANDS L("\004!#&*<=>@~") newscreen = 0; if (ecp->clen != 0 && ecp->cp[0] != '|' && ecp->cp[0] != '\n') { - if (strchr(SINGLE_CHAR_COMMANDS, *ecp->cp)) { + if (STRCHR(SINGLE_CHAR_COMMANDS, *ecp->cp)) { p = ecp->cp; ++ecp->cp; --ecp->clen; @@ -390,7 +388,7 @@ loop: ecp = gp->ecq.lh_first; } else { for (p = ecp->cp; ecp->clen > 0; --ecp->clen, ++ecp->cp) - if (!isalpha(*ecp->cp)) + if (!isascii(*ecp->cp) || !isalpha(*ecp->cp)) break; if ((namelen = ecp->cp - p) == 0) { msgq(sp, M_ERR, "080|Unknown command name"); @@ -417,7 +415,7 @@ loop: ecp = gp->ecq.lh_first; switch (p[0]) { case 'd': for (s = p, - t = cmds[C_DELETE].name; *s == *t; ++s, ++t); + n = cmds[C_DELETE].name; *s == *n; ++s, ++n); if (s[0] == 'l' || s[0] == 'p' || s[0] == '+' || s[0] == '-' || s[0] == '^' || s[0] == '#') { len = (ecp->cp - p) - (s - p); @@ -512,7 +510,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) /* Secure means no shell access. */ if (F_ISSET(ecp->cmd, E_SECURE) && O_ISSET(sp, O_SECURE)) { - ex_emsg(sp, ecp->cmd->name, EXM_SECURE); + ex_wemsg(sp, ecp->cmd->name, EXM_SECURE); goto err; } @@ -576,8 +574,8 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) /* Check for ex mode legality. */ if (F_ISSET(sp, SC_EX) && (F_ISSET(ecp->cmd, E_VIONLY) || newscreen)) { - msgq(sp, M_ERR, - "082|%s: command not available in ex mode", ecp->cmd->name); + msgq_wstr(sp, M_ERR, ecp->cmd->name, + "082|%s: command not available in ex mode"); goto err; } @@ -631,7 +629,8 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) arg1_len = 0; ecp->save_cmd = ecp->cp; if (ecp->cmd == &cmds[C_EDIT] || ecp->cmd == &cmds[C_EX] || - ecp->cmd == &cmds[C_NEXT] || ecp->cmd == &cmds[C_VISUAL_VI]) { + ecp->cmd == &cmds[C_NEXT] || ecp->cmd == &cmds[C_VISUAL_VI] || + ecp->cmd == &cmds[C_VSPLIT]) { /* * Move to the next non-whitespace character. A '!' * immediately following the command is eaten as a @@ -646,7 +645,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) ecp->save_cmd = ecp->cp; } for (; ecp->clen > 0; --ecp->clen, ++ecp->cp) - if (!isblank(*ecp->cp)) + if (!cmdskip(*ecp->cp)) break; /* * QUOTING NOTE: @@ -668,7 +667,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) ++discard; --ecp->clen; ch = *++ecp->cp; - } else if (isblank(ch)) + } else if (cmdskip(ch)) break; *p++ = ch; } @@ -712,7 +711,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) */ for (tmp = 0; ecp->clen > 0; --ecp->clen, ++ecp->cp) { ch = *ecp->cp; - if (isblank(ch)) + if (cmdskip(ch)) tmp = 1; else break; @@ -730,10 +729,11 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) * into something like ":s g", so use the special s command. */ for (; ecp->clen > 0; --ecp->clen, ++ecp->cp) - if (!isblank(ecp->cp[0])) + if (!cmdskip(ecp->cp[0])) break; - if (isalnum(ecp->cp[0]) || ecp->cp[0] == '|') { + if (!isascii(ecp->cp[0]) || + isalnum(ecp->cp[0]) || ecp->cp[0] == '|') { ecp->rcmd = cmds[C_SUBSTITUTE]; ecp->rcmd.fn = ex_subagain; ecp->cmd = &ecp->rcmd; @@ -777,7 +777,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) for (p = ecp->cp; ecp->clen > 0; --ecp->clen, ++ecp->cp) { ch = ecp->cp[0]; if (IS_ESCAPE(sp, ecp, ch) && ecp->clen > 1) { - tmp = ecp->cp[1]; + CHAR_T tmp = ecp->cp[1]; if (tmp == '\n' || tmp == '|') { if (tmp == '\n') { ++gp->if_lno; @@ -818,7 +818,10 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) */ if (ecp->cmd == &cmds[C_SET]) for (p = ecp->cp, len = ecp->clen; len > 0; --len, ++p) - if (*p == '\\') + if (IS_ESCAPE(sp, ecp, *p) && len > 1) { + --len; + ++p; + } else if (*p == '\\') *p = CH_LITERAL; /* @@ -937,13 +940,13 @@ two_addr: switch (ecp->addrcnt) { } ecp->flagoff = 0; - for (p = ecp->cmd->syntax; *p != '\0'; ++p) { + for (np = ecp->cmd->syntax; *np != '\0'; ++np) { /* * The force flag is sensitive to leading whitespace, i.e. * "next !" is different from "next!". Handle it before * skipping leading <blank>s. */ - if (*p == '!') { + if (*np == '!') { if (ecp->clen > 0 && *ecp->cp == '!') { ++ecp->cp; --ecp->clen; @@ -954,12 +957,12 @@ two_addr: switch (ecp->addrcnt) { /* Skip leading <blank>s. */ for (; ecp->clen > 0; --ecp->clen, ++ecp->cp) - if (!isblank(*ecp->cp)) + if (!cmdskip(*ecp->cp)) break; if (ecp->clen == 0) break; - switch (*p) { + switch (*np) { case '1': /* +, -, #, l, p */ /* * !!! @@ -1014,7 +1017,7 @@ end_case1: break; FL_SET(ecp->iflags, E_C_CARAT); break; case '=': - if (*p == '3') { + if (*np == '3') { FL_SET(ecp->iflags, E_C_EQUAL); break; } @@ -1034,7 +1037,7 @@ end_case23: break; */ if ((ecp->cp[0] == '+' || ecp->cp[0] == '-' || ecp->cp[0] == '^' || ecp->cp[0] == '#') && - strchr(p, '1') != NULL) + strchr(np, '1') != NULL) break; /* * !!! @@ -1042,7 +1045,7 @@ end_case23: break; * command "d2" would be a delete into buffer '2', and * not a two-line deletion. */ - if (!isdigit(ecp->cp[0])) { + if (!ISDIGIT(ecp->cp[0])) { ecp->buffer = *ecp->cp; ++ecp->cp; --ecp->clen; @@ -1050,9 +1053,9 @@ end_case23: break; } break; case 'c': /* count [01+a] */ - ++p; + ++np; /* Validate any signed value. */ - if (!isdigit(*ecp->cp) && (*p != '+' || + if (!ISDIGIT(*ecp->cp) && (*np != '+' || (*ecp->cp != '+' && *ecp->cp != '-'))) break; /* If a signed value, set appropriate flags. */ @@ -1065,7 +1068,7 @@ end_case23: break; ex_badaddr(sp, NULL, A_NOTSET, nret); goto err; } - if (ltmp == 0 && *p != '0') { + if (ltmp == 0 && *np != '0') { msgq(sp, M_ERR, "083|Count may not be zero"); goto err; } @@ -1081,7 +1084,7 @@ end_case23: break; * join) do different things with counts than with * line addresses. */ - if (*p == 'a') { + if (*np == 'a') { ecp->addr1 = ecp->addr2; ecp->addr2.lno = ecp->addr1.lno + ltmp - 1; } else @@ -1108,7 +1111,7 @@ end_case23: break; /* Line specifications are always required. */ if (!isaddr) { - msgq_str(sp, M_ERR, ecp->cp, + msgq_wstr(sp, M_ERR, ecp->cp, "084|%s: bad line specification"); goto err; } @@ -1151,7 +1154,7 @@ end_case23: break; ecp, ch) && ecp->clen > 1) { --ecp->clen; *p++ = *++ecp->cp; - } else if (isblank(ch)) { + } else if (cmdskip(ch)) { ++ecp->cp; --ecp->clen; break; @@ -1165,7 +1168,7 @@ end_case23: break; for (; ecp->clen > 0; --ecp->clen, ++ecp->cp) { ch = *ecp->cp; - if (!isblank(ch)) + if (!cmdskip(ch)) break; } if (ecp->clen == 0) @@ -1188,29 +1191,35 @@ end_case23: break; case 'w': /* word */ if (argv_exp3(sp, ecp, ecp->cp, ecp->clen)) goto err; -arg_cnt_chk: if (*++p != 'N') { /* N */ +arg_cnt_chk: if (*++np != 'N') { /* N */ /* * If a number is specified, must either be * 0 or that number, if optional, and that * number, if required. */ - tmp = *p - '0'; - if ((*++p != 'o' || exp->argsoff != 0) && + tmp = *np - '0'; + if ((*++np != 'o' || exp->argsoff != 0) && exp->argsoff != tmp) goto usage; } goto addr_verify; - default: + default: { + size_t nlen; + char *nstr; + + INT2CHAR(sp, ecp->cmd->name, STRLEN(ecp->cmd->name) + 1, + nstr, nlen); msgq(sp, M_ERR, "085|Internal syntax table error (%s: %s)", - ecp->cmd->name, KEY_NAME(sp, *p)); + nstr, KEY_NAME(sp, *np)); + } } } /* Skip trailing whitespace. */ for (; ecp->clen > 0; --ecp->clen) { ch = *ecp->cp++; - if (!isblank(ch)) + if (!cmdskip(ch)) break; } @@ -1218,7 +1227,7 @@ arg_cnt_chk: if (*++p != 'N') { /* N */ * There shouldn't be anything left, and no more required fields, * i.e neither 'l' or 'r' in the syntax string. */ - if (ecp->clen != 0 || strpbrk(p, "lr")) { + if (ecp->clen != 0 || strpbrk(np, "lr")) { usage: msgq(sp, M_ERR, "086|Usage: %s", ecp->cmd->usage); goto err; } @@ -1381,8 +1390,8 @@ addr_verify: /* Make sure no function left global temporary space locked. */ if (F_ISSET(gp, G_TMP_INUSE)) { F_CLR(gp, G_TMP_INUSE); - msgq(sp, M_ERR, "087|%s: temporary buffer not released", - ecp->cmd->name); + msgq_wstr(sp, M_ERR, ecp->cmd->name, + "087|%s: temporary buffer not released"); } #endif /* @@ -1495,7 +1504,7 @@ addr_verify: ecp->save_cmd -= arg1_len; ecp->save_cmdlen += arg1_len; - memcpy(ecp->save_cmd, arg1, arg1_len); + MEMCPY(ecp->save_cmd, arg1, arg1_len); /* * Any commands executed from a +cmd are executed starting at @@ -1529,8 +1538,7 @@ addr_verify: */ if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE | SC_FSWITCH | SC_SSWITCH)) { at_found = gv_found = 0; - for (ecp = sp->gp->ecq.lh_first; - ecp != NULL; ecp = ecp->q.le_next) + SLIST_FOREACH(ecp, sp->gp->ecq, q) switch (ecp->agv_flags) { case 0: case AGV_AT_NORANGE: @@ -1582,7 +1590,7 @@ err: /* break; } } - if (ecp->save_cmdlen != 0 || gp->ecq.lh_first != &gp->excmd) { + if (ecp->save_cmdlen != 0 || SLIST_FIRST(gp->ecq) != &gp->excmd) { discard: msgq(sp, M_BERR, "092|Ex command failed: pending commands discarded"); ex_discard(sp); @@ -1611,10 +1619,7 @@ rsuccess: tmp = 0; * PUBLIC: int ex_range __P((SCR *, EXCMD *, int *)); */ int -ex_range(sp, ecp, errp) - SCR *sp; - EXCMD *ecp; - int *errp; +ex_range(SCR *sp, EXCMD *ecp, int *errp) { enum { ADDR_FOUND, ADDR_NEED, ADDR_NONE } addr; GS *gp; @@ -1813,19 +1818,15 @@ ret: if (F_ISSET(ecp, E_VISEARCH)) * it's fairly close. */ static int -ex_line(sp, ecp, mp, isaddrp, errp) - SCR *sp; - EXCMD *ecp; - MARK *mp; - int *isaddrp, *errp; +ex_line(SCR *sp, EXCMD *ecp, MARK *mp, int *isaddrp, int *errp) { enum nresult nret; EX_PRIVATE *exp; GS *gp; long total, val; int isneg; - int (*sf) __P((SCR *, MARK *, MARK *, char *, size_t, char **, u_int)); - char *endp; + int (*sf) __P((SCR *, MARK *, MARK *, CHAR_T *, size_t, CHAR_T **, u_int)); + CHAR_T *endp; gp = sp->gp; exp = EXP(sp); @@ -1834,7 +1835,7 @@ ex_line(sp, ecp, mp, isaddrp, errp) F_CLR(ecp, E_DELTA); /* No addresses permitted until a file has been read in. */ - if (sp->ep == NULL && strchr("$0123456789'\\/?.+-^", *ecp->cp)) { + if (sp->ep == NULL && STRCHR(L("$0123456789'\\/?.+-^"), *ecp->cp)) { ex_badaddr(sp, NULL, A_EMPTY, NUM_OK); *errp = 1; return (0); @@ -1895,7 +1896,7 @@ ex_line(sp, ecp, mp, isaddrp, errp) * difference. C'est la vie. */ if (ecp->clen < 2 || - ecp->cp[1] != '/' && ecp->cp[1] != '?') { + (ecp->cp[1] != '/' && ecp->cp[1] != '?')) { msgq(sp, M_ERR, "096|\\ not followed by / or ?"); *errp = 1; return (0); @@ -1945,7 +1946,7 @@ search: mp->lno = sp->lno; * the '+' could be omitted. (This feature is found in ed * as well.) */ - if (ecp->clen > 1 && isdigit(ecp->cp[1])) + if (ecp->clen > 1 && ISDIGIT(ecp->cp[1])) *ecp->cp = '+'; else { ++ecp->cp; @@ -1956,14 +1957,14 @@ search: mp->lno = sp->lno; /* Skip trailing <blank>s. */ for (; ecp->clen > 0 && - isblank(ecp->cp[0]); ++ecp->cp, --ecp->clen); + cmdskip(ecp->cp[0]); ++ecp->cp, --ecp->clen); /* * Evaluate any offset. If no address yet found, the offset * is relative to ".". */ total = 0; - if (ecp->clen != 0 && (isdigit(ecp->cp[0]) || + if (ecp->clen != 0 && (ISDIGIT(ecp->cp[0]) || ecp->cp[0] == '+' || ecp->cp[0] == '-' || ecp->cp[0] == '^')) { if (!*isaddrp) { @@ -1999,14 +2000,14 @@ search: mp->lno = sp->lno; */ F_SET(ecp, E_DELTA); for (;;) { - for (; ecp->clen > 0 && isblank(ecp->cp[0]); + for (; ecp->clen > 0 && cmdskip(ecp->cp[0]); ++ecp->cp, --ecp->clen); - if (ecp->clen == 0 || !isdigit(ecp->cp[0]) && + if (ecp->clen == 0 || (!ISDIGIT(ecp->cp[0]) && ecp->cp[0] != '+' && ecp->cp[0] != '-' && - ecp->cp[0] != '^') + ecp->cp[0] != '^')) break; - if (!isdigit(ecp->cp[0]) && - !isdigit(ecp->cp[1])) { + if (!ISDIGIT(ecp->cp[0]) && + !ISDIGIT(ecp->cp[1])) { total += ecp->cp[0] == '+' ? 1 : -1; --ecp->clen; ++ecp->cp; @@ -2064,8 +2065,7 @@ search: mp->lno = sp->lno; * Load up the next command, which may be an @ buffer or global command. */ static int -ex_load(sp) - SCR *sp; +ex_load(SCR *sp) { GS *gp; EXCMD *ecp; @@ -2078,16 +2078,18 @@ ex_load(sp) * can't be an AGV command, which makes things a bit easier. */ for (gp = sp->gp;;) { + ecp = SLIST_FIRST(gp->ecq); + + /* Discard the allocated source name as requested. */ + if (F_ISSET(ecp, E_NAMEDISCARD)) + free(ecp->if_name); + /* * If we're back to the original structure, leave it around, - * but discard any allocated source name, we've returned to - * the beginning of the command stack. + * since we've returned to the beginning of the command stack. */ - if ((ecp = gp->ecq.lh_first) == &gp->excmd) { - if (F_ISSET(ecp, E_NAMEDISCARD)) { - free(ecp->if_name); - ecp->if_name = NULL; - } + if (ecp == &gp->excmd) { + ecp->if_name = NULL; return (0); } @@ -2107,15 +2109,15 @@ ex_load(sp) */ if (FL_ISSET(ecp->agv_flags, AGV_ALL)) { /* Discard any exhausted ranges. */ - while ((rp = ecp->rq.cqh_first) != (void *)&ecp->rq) + while ((rp = TAILQ_FIRST(ecp->rq)) != NULL) if (rp->start > rp->stop) { - CIRCLEQ_REMOVE(&ecp->rq, rp, q); + TAILQ_REMOVE(ecp->rq, rp, q); free(rp); } else break; /* If there's another range, continue with it. */ - if (rp != (void *)&ecp->rq) + if (rp != NULL) break; /* If it's a global/v command, fix up the last line. */ @@ -2133,7 +2135,7 @@ ex_load(sp) } /* Discard the EXCMD. */ - LIST_REMOVE(ecp, q); + SLIST_REMOVE_HEAD(gp->ecq, q); free(ecp); } @@ -2144,7 +2146,7 @@ ex_load(sp) * so we have play games. */ ecp->cp = ecp->o_cp; - memcpy(ecp->cp, ecp->cp + ecp->o_clen, ecp->o_clen); + MEMCPY(ecp->cp, ecp->cp + ecp->o_clen, ecp->o_clen); ecp->clen = ecp->o_clen; ecp->range_lno = sp->lno = rp->start++; @@ -2158,8 +2160,7 @@ ex_load(sp) * Discard any pending ex commands. */ static int -ex_discard(sp) - SCR *sp; +ex_discard(SCR *sp) { GS *gp; EXCMD *ecp; @@ -2169,18 +2170,26 @@ ex_discard(sp) * We know the first command can't be an AGV command, so we don't * process it specially. We do, however, nail the command itself. */ - for (gp = sp->gp; (ecp = gp->ecq.lh_first) != &gp->excmd;) { + for (gp = sp->gp;;) { + ecp = SLIST_FIRST(gp->ecq); + if (F_ISSET(ecp, E_NAMEDISCARD)) + free(ecp->if_name); + /* Reset the last command without dropping it. */ + if (ecp == &gp->excmd) + break; if (FL_ISSET(ecp->agv_flags, AGV_ALL)) { - while ((rp = ecp->rq.cqh_first) != (void *)&ecp->rq) { - CIRCLEQ_REMOVE(&ecp->rq, rp, q); + while ((rp = TAILQ_FIRST(ecp->rq)) != NULL) { + TAILQ_REMOVE(ecp->rq, rp, q); free(rp); } free(ecp->o_cp); } - LIST_REMOVE(ecp, q); + SLIST_REMOVE_HEAD(gp->ecq, q); free(ecp); } - gp->ecq.lh_first->clen = 0; + + ecp->if_name = NULL; + ecp->clen = 0; return (0); } @@ -2189,19 +2198,16 @@ ex_discard(sp) * Display an unknown command name. */ static void -ex_unknown(sp, cmd, len) - SCR *sp; - char *cmd; - size_t len; +ex_unknown(SCR *sp, CHAR_T *cmd, size_t len) { size_t blen; - char *bp; + CHAR_T *bp; - GET_SPACE_GOTO(sp, bp, blen, len + 1); + GET_SPACE_GOTOW(sp, bp, blen, len + 1); bp[len] = '\0'; - memcpy(bp, cmd, len); - msgq_str(sp, M_ERR, bp, "098|The %s command is unknown"); - FREE_SPACE(sp, bp, blen); + MEMCPY(bp, cmd, len); + msgq_wstr(sp, M_ERR, bp, "098|The %s command is unknown"); + FREE_SPACEW(sp, bp, blen); alloc_err: return; @@ -2213,12 +2219,10 @@ alloc_err: * [un]abbreviate command, so it can turn off abbreviations. See * the usual ranting in the vi/v_txt_ev.c:txt_abbrev() routine. * - * PUBLIC: int ex_is_abbrev __P((char *, size_t)); + * PUBLIC: int ex_is_abbrev __P((CHAR_T *, size_t)); */ int -ex_is_abbrev(name, len) - char *name; - size_t len; +ex_is_abbrev(CHAR_T *name, size_t len) { EXCMDLIST const *cp; @@ -2232,12 +2236,10 @@ ex_is_abbrev(name, len) * unmap command, so it can turn off input mapping. See the usual * ranting in the vi/v_txt_ev.c:txt_unmap() routine. * - * PUBLIC: int ex_is_unmap __P((char *, size_t)); + * PUBLIC: int ex_is_unmap __P((CHAR_T *, size_t)); */ int -ex_is_unmap(name, len) - char *name; - size_t len; +ex_is_unmap(CHAR_T *name, size_t len) { EXCMDLIST const *cp; @@ -2257,9 +2259,7 @@ ex_is_unmap(name, len) * Search for a command name. */ static EXCMDLIST const * -ex_comm_search(name, len) - char *name; - size_t len; +ex_comm_search(CHAR_T *name, size_t len) { EXCMDLIST const *cp; @@ -2268,7 +2268,7 @@ ex_comm_search(name, len) return (NULL); if (cp->name[0] != name[0]) continue; - if (!memcmp(name, cp->name, len)) + if (!MEMCMP(name, cp->name, len)) return (cp); } return (NULL); @@ -2282,11 +2282,7 @@ ex_comm_search(name, len) * PUBLIC: __P((SCR *, EXCMDLIST const *, enum badaddr, enum nresult)); */ void -ex_badaddr(sp, cp, ba, nret) - SCR *sp; - EXCMDLIST const *cp; - enum badaddr ba; - enum nresult nret; +ex_badaddr(SCR *sp, const EXCMDLIST *cp, enum badaddr ba, enum nresult nret) { recno_t lno; @@ -2309,7 +2305,7 @@ ex_badaddr(sp, cp, ba, nret) * underlying file, that's the real problem. */ if (sp->ep == NULL) { - ex_emsg(sp, cp ? cp->name : NULL, EXM_NOFILEYET); + ex_wemsg(sp, cp ? cp->name : NULL, EXM_NOFILEYET); return; } @@ -2323,7 +2319,7 @@ ex_badaddr(sp, cp, ba, nret) if (lno != 0) { msgq(sp, M_ERR, "102|Illegal address: only %lu lines in the file", - lno); + (u_long)lno); break; } /* FALLTHROUGH */ @@ -2334,9 +2330,8 @@ ex_badaddr(sp, cp, ba, nret) abort(); /* NOTREACHED */ case A_ZERO: - msgq(sp, M_ERR, - "104|The %s command doesn't permit an address of 0", - cp->name); + msgq_wstr(sp, M_ERR, cp->name, + "104|The %s command doesn't permit an address of 0"); break; } return; @@ -2352,7 +2347,7 @@ ex_comlog(sp, ecp) SCR *sp; EXCMD *ecp; { - TRACE(sp, "ecmd: %s", ecp->cmd->name); + TRACE(sp, "ecmd: "WS, ecp->cmd->name); if (ecp->addrcnt > 0) { TRACE(sp, " a1 %d", ecp->addr1.lno); if (ecp->addrcnt > 1) @@ -2362,11 +2357,13 @@ ex_comlog(sp, ecp) TRACE(sp, " line %d", ecp->lineno); if (ecp->flags) TRACE(sp, " flags 0x%x", ecp->flags); - if (F_ISSET(&exc, E_BUFFER)) - TRACE(sp, " buffer %c", ecp->buffer); - if (ecp->argc) + if (FL_ISSET(ecp->iflags, E_C_BUFFER)) + TRACE(sp, " buffer "WC, ecp->buffer); + if (ecp->argc) { + int cnt; for (cnt = 0; cnt < ecp->argc; ++cnt) - TRACE(sp, " arg %d: {%s}", cnt, ecp->argv[cnt]->bp); + TRACE(sp, " arg %d: {"WS"}", cnt, ecp->argv[cnt]->bp); + } TRACE(sp, "\n"); } #endif diff --git a/contrib/nvi/ex/ex.h b/contrib/nvi/ex/ex.h index f40be8a..f5ba4c2 100644 --- a/contrib/nvi/ex/ex.h +++ b/contrib/nvi/ex/ex.h @@ -6,13 +6,13 @@ * * See the LICENSE file for redistribution information. * - * @(#)ex.h 10.24 (Berkeley) 8/12/96 + * $Id: ex.h,v 10.31 2012/10/03 02:33:24 zy Exp $ */ #define PROMPTCHAR ':' /* Prompt using a colon. */ typedef struct _excmdlist { /* Ex command table structure. */ - char *name; /* Command name, underlying function. */ + CHAR_T *name; /* Command name, underlying function. */ int (*fn) __P((SCR *, EXCMD *)); #define E_ADDR1 0x00000001 /* One address. */ @@ -49,6 +49,9 @@ extern EXCMDLIST const cmds[]; /* Table of ex commands. */ (F_ISSET(cmdp, E_VLITONLY) ? \ (ch) == CH_LITERAL : KEY_VAL(sp, ch) == K_VLNEXT) +#define IS_SHELLMETA(sp, ch) \ + ((ch) <= CHAR_MAX && strchr(O_STR(sp, O_SHELLMETA), ch) != NULL) + /* * File state must be checked for each command -- any ex command may be entered * at any time, and most of them won't work well if a file hasn't yet been read @@ -56,7 +59,7 @@ extern EXCMDLIST const cmds[]; /* Table of ex commands. */ */ #define NEEDFILE(sp, cmdp) { \ if ((sp)->ep == NULL) { \ - ex_emsg(sp, (cmdp)->cmd->name, EXM_NOFILEYET); \ + ex_wemsg(sp, (cmdp)->cmd->name, EXM_NOFILEYET); \ return (1); \ } \ } @@ -64,13 +67,13 @@ extern EXCMDLIST const cmds[]; /* Table of ex commands. */ /* Range structures for global and @ commands. */ typedef struct _range RANGE; struct _range { /* Global command range. */ - CIRCLEQ_ENTRY(_range) q; /* Linked list of ranges. */ + TAILQ_ENTRY(_range) q; /* Linked list of ranges. */ recno_t start, stop; /* Start/stop of the range. */ }; /* Ex command structure. */ struct _excmd { - LIST_ENTRY(_excmd) q; /* Linked list of commands. */ + SLIST_ENTRY(_excmd) q; /* Linked list of commands. */ char *if_name; /* Associated file. */ recno_t if_lno; /* Associated line number. */ @@ -80,18 +83,18 @@ struct _excmd { memset(&((cmdp)->cp), 0, ((char *)&(cmdp)->flags - \ (char *)&((cmdp)->cp)) + sizeof((cmdp)->flags)) - char *cp; /* Current command text. */ + CHAR_T *cp; /* Current command text. */ size_t clen; /* Current command length. */ - char *save_cmd; /* Remaining command. */ + CHAR_T *save_cmd; /* Remaining command. */ size_t save_cmdlen; /* Remaining command length. */ EXCMDLIST const *cmd; /* Command: entry in command table. */ EXCMDLIST rcmd; /* Command: table entry/replacement. */ - CIRCLEQ_HEAD(_rh, _range) rq; /* @/global range: linked list. */ + TAILQ_HEAD(_rh, _range) rq[1]; /* @/global range: linked list. */ recno_t range_lno; /* @/global range: set line number. */ - char *o_cp; /* Original @/global command. */ + CHAR_T *o_cp; /* Original @/global command. */ size_t o_clen; /* Original @/global command length. */ #define AGV_AT 0x01 /* @ buffer execution. */ #define AGV_AT_NORANGE 0x02 /* @ buffer execution without range. */ @@ -133,7 +136,7 @@ struct _excmd { #define E_C_PRINT 0x01000 /* p flag. */ u_int16_t iflags; /* User input information. */ -#define __INUSE2 0x000004ff /* Same name space as EXCMDLIST. */ +#define __INUSE2 0x000007ff /* Same name space as EXCMDLIST. */ #define E_BLIGNORE 0x00000800 /* Ignore blank lines. */ #define E_NAMEDISCARD 0x00001000 /* Free/discard the name. */ #define E_NOAUTO 0x00002000 /* Don't do autoprint output. */ @@ -152,18 +155,16 @@ struct _excmd { #define E_SEARCH_WMSG 0x01000000 /* Display search-wrapped message. */ #define E_USELASTCMD 0x02000000 /* Use the last command. */ #define E_VISEARCH 0x04000000 /* It's really a vi search command. */ -#ifdef GTAGS -#define E_REFERENCE 0x08000000 /* locate function references */ -#endif u_int32_t flags; /* Current flags. */ }; /* Ex private, per-screen memory. */ typedef struct _ex_private { - CIRCLEQ_HEAD(_tqh, _tagq) tq; /* Tag queue. */ - TAILQ_HEAD(_tagfh, _tagf) tagfq;/* Tag file list. */ - LIST_HEAD(_csch, _csc) cscq; /* Cscope connection list. */ - char *tag_last; /* Saved last tag string. */ + /* Tag file list. */ + TAILQ_HEAD(_tagfh, _tagf) tagfq[1]; + TAILQ_HEAD(_tqh, _tagq) tq[1]; /* Tag queue. */ + SLIST_HEAD(_csch, _csc) cscq[1];/* Cscope connection list. */ + CHAR_T *tag_last; /* Saved last tag string. */ CHAR_T *lastbcomm; /* Last bang command. */ @@ -175,6 +176,7 @@ typedef struct _ex_private { char *ibp; /* File line input buffer. */ size_t ibp_len; /* File line input buffer length. */ + CONVWIN ibcw; /* File line input conversion buffer. */ /* * Buffers for the ex output. The screen/vi support doesn't do any @@ -228,4 +230,4 @@ typedef enum { } tagmsg_t; #include "ex_def.h" -#include "ex_extern.h" +#include "extern.h" diff --git a/contrib/nvi/ex/ex_abbrev.c b/contrib/nvi/ex/ex_abbrev.c index 231098c..6624889 100644 --- a/contrib/nvi/ex/ex_abbrev.c +++ b/contrib/nvi/ex/ex_abbrev.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_abbrev.c 10.7 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_abbrev.c,v 10.10 2001/12/16 18:18:54 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -34,9 +34,7 @@ static const char sccsid[] = "@(#)ex_abbrev.c 10.7 (Berkeley) 3/6/96"; * PUBLIC: int ex_abbr __P((SCR *, EXCMD *)); */ int -ex_abbr(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_abbr(SCR *sp, EXCMD *cmdp) { CHAR_T *p; size_t len; @@ -71,7 +69,7 @@ ex_abbr(sp, cmdp) return (1); } for (p = cmdp->argv[0]->bp; *p != '\0'; ++p) - if (isblank(p[0])) { + if (ISBLANK(p[0])) { msgq(sp, M_ERR, "107|Abbreviations may not contain tabs or spaces"); return (1); @@ -100,16 +98,14 @@ ex_abbr(sp, cmdp) * PUBLIC: int ex_unabbr __P((SCR *, EXCMD *)); */ int -ex_unabbr(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_unabbr(SCR *sp, EXCMD *cmdp) { ARGS *ap; ap = cmdp->argv[0]; if (!F_ISSET(sp->gp, G_ABBREV) || seq_delete(sp, ap->bp, ap->len, SEQ_ABBREV)) { - msgq_str(sp, M_ERR, ap->bp, + msgq_wstr(sp, M_ERR, ap->bp, "109|\"%s\" is not an abbreviation"); return (1); } diff --git a/contrib/nvi/ex/ex_append.c b/contrib/nvi/ex/ex_append.c index 8d89e12..de224f8 100644 --- a/contrib/nvi/ex/ex_append.c +++ b/contrib/nvi/ex/ex_append.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_append.c 10.30 (Berkeley) 10/23/96"; +static const char sccsid[] = "$Id: ex_append.c,v 10.34 2001/06/25 15:19:14 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -36,9 +37,7 @@ static int ex_aci __P((SCR *, EXCMD *, enum which)); * PUBLIC: int ex_append __P((SCR *, EXCMD *)); */ int -ex_append(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_append(SCR *sp, EXCMD *cmdp) { return (ex_aci(sp, cmdp, APPEND)); } @@ -50,9 +49,7 @@ ex_append(sp, cmdp) * PUBLIC: int ex_change __P((SCR *, EXCMD *)); */ int -ex_change(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_change(SCR *sp, EXCMD *cmdp) { return (ex_aci(sp, cmdp, CHANGE)); } @@ -65,9 +62,7 @@ ex_change(sp, cmdp) * PUBLIC: int ex_insert __P((SCR *, EXCMD *)); */ int -ex_insert(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_insert(SCR *sp, EXCMD *cmdp) { return (ex_aci(sp, cmdp, INSERT)); } @@ -77,16 +72,13 @@ ex_insert(sp, cmdp) * Append, change, insert in ex. */ static int -ex_aci(sp, cmdp, cmd) - SCR *sp; - EXCMD *cmdp; - enum which cmd; +ex_aci(SCR *sp, EXCMD *cmdp, enum which cmd) { CHAR_T *p, *t; GS *gp; TEXT *tp; - TEXTH tiq; - recno_t cnt, lno; + TEXTH tiq[] = {{ 0 }}; + recno_t cnt = 0, lno; size_t len; u_int32_t flags; int need_newline; @@ -175,7 +167,7 @@ ex_aci(sp, cmdp, cmd) if (len != 0) { ++t; if (--len == 0 && - db_append(sp, 1, lno++, "", 0)) + db_append(sp, 1, lno++, NULL, 0)) return (1); } } @@ -213,7 +205,7 @@ ex_aci(sp, cmdp, cmd) */ if (F_ISSET(sp, SC_VI)) { if (gp->scr_screen(sp, SC_EX)) { - ex_emsg(sp, cmdp->cmd->name, EXM_NOCANON); + ex_wemsg(sp, cmdp->cmd->name, EXM_NOCANON); return (1); } @@ -254,16 +246,16 @@ ex_aci(sp, cmdp, cmd) * characters in the common TEXTH structure when they were inserted * into the file, above.) */ - memset(&tiq, 0, sizeof(TEXTH)); - CIRCLEQ_INIT(&tiq); + TAILQ_INIT(tiq); - if (ex_txt(sp, &tiq, 0, flags)) + if (ex_txt(sp, tiq, 0, flags)) return (1); - for (cnt = 0, tp = tiq.cqh_first; - tp != (TEXT *)&tiq; ++cnt, tp = tp->q.cqe_next) + TAILQ_FOREACH(tp, tiq, q) { if (db_append(sp, 1, lno++, tp->lb, tp->len)) return (1); + ++cnt; + } /* * Set sp->lno to the final line number value (correcting for a diff --git a/contrib/nvi/ex/ex_args.c b/contrib/nvi/ex/ex_args.c index bc37109..2105d2d 100644 --- a/contrib/nvi/ex/ex_args.c +++ b/contrib/nvi/ex/ex_args.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_args.c 10.16 (Berkeley) 7/13/96"; +static const char sccsid[] = "$Id: ex_args.c,v 10.19 2011/12/16 16:18:10 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -42,14 +42,16 @@ static int ex_N_next __P((SCR *, EXCMD *)); * PUBLIC: int ex_next __P((SCR *, EXCMD *)); */ int -ex_next(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_next(SCR *sp, EXCMD *cmdp) { ARGS **argv; FREF *frp; int noargs; char **ap; + CHAR_T *wp; + size_t wlen; + char *np; + size_t nlen; /* Check for file to move to. */ if (cmdp->argc == 0 && (sp->cargv == NULL || sp->cargv[1] == NULL)) { @@ -60,8 +62,9 @@ ex_next(sp, cmdp) if (F_ISSET(cmdp, E_NEWSCREEN)) { /* By default, edit the next file in the old argument list. */ if (cmdp->argc == 0) { - if (argv_exp0(sp, - cmdp, sp->cargv[1], strlen(sp->cargv[1]))) + CHAR2INT(sp, sp->cargv[1], strlen(sp->cargv[1]) + 1, + wp, wlen); + if (argv_exp0(sp, cmdp, wp, wlen - 1)) return (1); return (ex_edit(sp, cmdp)); } @@ -88,10 +91,11 @@ ex_next(sp, cmdp) CALLOC_RET(sp, sp->argv, char **, cmdp->argc + 1, sizeof(char *)); for (ap = sp->argv, - argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv) - if ((*ap = - v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL) + argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv) { + INT2CHAR(sp, argv[0]->bp, argv[0]->len, np, nlen); + if ((*ap = v_strdup(sp, np, nlen)) == NULL) return (1); + } *ap = NULL; /* Switch to the first file. */ @@ -125,12 +129,12 @@ ex_next(sp, cmdp) * New screen version of ex_next. */ static int -ex_N_next(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_N_next(SCR *sp, EXCMD *cmdp) { SCR *new; FREF *frp; + char *np; + size_t nlen; /* Get a new screen. */ if (screen_init(sp->gp, sp, &new)) @@ -141,7 +145,8 @@ ex_N_next(sp, cmdp) } /* Get a backing file. */ - if ((frp = file_add(new, cmdp->argv[0]->bp)) == NULL || + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, np, nlen); + if ((frp = file_add(new, np)) == NULL || file_init(new, frp, NULL, (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0))) { (void)vs_discard(new, NULL); @@ -169,11 +174,11 @@ ex_N_next(sp, cmdp) * PUBLIC: int ex_prev __P((SCR *, EXCMD *)); */ int -ex_prev(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_prev(SCR *sp, EXCMD *cmdp) { FREF *frp; + size_t wlen; + CHAR_T *wp; if (sp->cargv == sp->argv) { msgq(sp, M_ERR, "112|No previous files to edit"); @@ -181,7 +186,9 @@ ex_prev(sp, cmdp) } if (F_ISSET(cmdp, E_NEWSCREEN)) { - if (argv_exp0(sp, cmdp, sp->cargv[-1], strlen(sp->cargv[-1]))) + CHAR2INT(sp, sp->cargv[-1], strlen(sp->cargv[-1]) + 1, + wp, wlen); + if (argv_exp0(sp, cmdp, wp, wlen - 1)) return (1); return (ex_edit(sp, cmdp)); } @@ -216,9 +223,7 @@ ex_prev(sp, cmdp) * PUBLIC: int ex_rew __P((SCR *, EXCMD *)); */ int -ex_rew(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_rew(SCR *sp, EXCMD *cmdp) { FREF *frp; @@ -256,9 +261,7 @@ ex_rew(sp, cmdp) * PUBLIC: int ex_args __P((SCR *, EXCMD *)); */ int -ex_args(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_args(SCR *sp, EXCMD *cmdp) { GS *gp; int cnt, col, len, sep; @@ -299,14 +302,13 @@ ex_args(sp, cmdp) * PUBLIC: char **ex_buildargv __P((SCR *, EXCMD *, char *)); */ char ** -ex_buildargv(sp, cmdp, name) - SCR *sp; - EXCMD *cmdp; - char *name; +ex_buildargv(SCR *sp, EXCMD *cmdp, char *name) { ARGS **argv; int argc; char **ap, **s_argv; + char *np; + size_t nlen; argc = cmdp == NULL ? 1 : cmdp->argc; CALLOC(sp, s_argv, char **, argc + 1, sizeof(char *)); @@ -318,10 +320,11 @@ ex_buildargv(sp, cmdp, name) return (NULL); ++ap; } else - for (argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv) - if ((*ap = - v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL) + for (argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv) { + INT2CHAR(sp, argv[0]->bp, argv[0]->len, np, nlen); + if ((*ap = v_strdup(sp, np, nlen)) == NULL) return (NULL); + } *ap = NULL; return (s_argv); } diff --git a/contrib/nvi/ex/ex_argv.c b/contrib/nvi/ex/ex_argv.c index cc5a201..b3e3edf 100644 --- a/contrib/nvi/ex/ex_argv.c +++ b/contrib/nvi/ex/ex_argv.c @@ -10,17 +10,19 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_argv.c 10.26 (Berkeley) 9/20/96"; +static const char sccsid[] = "$Id: ex_argv.c,v 11.2 2012/10/09 23:00:29 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> #include <dirent.h> #include <errno.h> #include <limits.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -31,9 +33,9 @@ static const char sccsid[] = "@(#)ex_argv.c 10.26 (Berkeley) 9/20/96"; static int argv_alloc __P((SCR *, size_t)); static int argv_comp __P((const void *, const void *)); static int argv_fexp __P((SCR *, EXCMD *, - char *, size_t, char *, size_t *, char **, size_t *, int)); -static int argv_lexp __P((SCR *, EXCMD *, char *)); -static int argv_sexp __P((SCR *, char **, size_t *, size_t *)); + CHAR_T *, size_t, CHAR_T *, size_t *, CHAR_T **, size_t *, int)); +static int argv_sexp __P((SCR *, CHAR_T **, size_t *, size_t *)); +static int argv_flt_user __P((SCR *, EXCMD *, CHAR_T *, size_t)); /* * argv_init -- @@ -42,9 +44,7 @@ static int argv_sexp __P((SCR *, char **, size_t *, size_t *)); * PUBLIC: int argv_init __P((SCR *, EXCMD *)); */ int -argv_init(sp, excp) - SCR *sp; - EXCMD *excp; +argv_init(SCR *sp, EXCMD *excp) { EX_PRIVATE *exp; @@ -61,20 +61,16 @@ argv_init(sp, excp) * argv_exp0 -- * Append a string to the argument list. * - * PUBLIC: int argv_exp0 __P((SCR *, EXCMD *, char *, size_t)); + * PUBLIC: int argv_exp0 __P((SCR *, EXCMD *, CHAR_T *, size_t)); */ int -argv_exp0(sp, excp, cmd, cmdlen) - SCR *sp; - EXCMD *excp; - char *cmd; - size_t cmdlen; +argv_exp0(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen) { EX_PRIVATE *exp; exp = EXP(sp); argv_alloc(sp, cmdlen); - memcpy(exp->args[exp->argsoff]->bp, cmd, cmdlen); + MEMCPY(exp->args[exp->argsoff]->bp, cmd, cmdlen); exp->args[exp->argsoff]->bp[cmdlen] = '\0'; exp->args[exp->argsoff]->len = cmdlen; ++exp->argsoff; @@ -88,33 +84,28 @@ argv_exp0(sp, excp, cmd, cmdlen) * Do file name expansion on a string, and append it to the * argument list. * - * PUBLIC: int argv_exp1 __P((SCR *, EXCMD *, char *, size_t, int)); + * PUBLIC: int argv_exp1 __P((SCR *, EXCMD *, CHAR_T *, size_t, int)); */ int -argv_exp1(sp, excp, cmd, cmdlen, is_bang) - SCR *sp; - EXCMD *excp; - char *cmd; - size_t cmdlen; - int is_bang; +argv_exp1(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen, int is_bang) { EX_PRIVATE *exp; size_t blen, len; - char *bp, *p, *t; + CHAR_T *p, *t, *bp; - GET_SPACE_RET(sp, bp, blen, 512); + GET_SPACE_RETW(sp, bp, blen, 512); len = 0; exp = EXP(sp); if (argv_fexp(sp, excp, cmd, cmdlen, bp, &len, &bp, &blen, is_bang)) { - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); return (1); } /* If it's empty, we're done. */ if (len != 0) { for (p = bp, t = bp + len; p < t; ++p) - if (!isblank(*p)) + if (!cmdskip(*p)) break; if (p == t) goto ret; @@ -123,7 +114,7 @@ argv_exp1(sp, excp, cmd, cmdlen, is_bang) (void)argv_exp0(sp, excp, bp, len); -ret: FREE_SPACE(sp, bp, blen); +ret: FREE_SPACEW(sp, bp, blen); return (0); } @@ -132,24 +123,20 @@ ret: FREE_SPACE(sp, bp, blen); * Do file name and shell expansion on a string, and append it to * the argument list. * - * PUBLIC: int argv_exp2 __P((SCR *, EXCMD *, char *, size_t)); + * PUBLIC: int argv_exp2 __P((SCR *, EXCMD *, CHAR_T *, size_t)); */ int -argv_exp2(sp, excp, cmd, cmdlen) - SCR *sp; - EXCMD *excp; - char *cmd; - size_t cmdlen; +argv_exp2(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen) { size_t blen, len, n; int rval; - char *bp, *mp, *p; + CHAR_T *bp, *p; - GET_SPACE_RET(sp, bp, blen, 512); + GET_SPACE_RETW(sp, bp, blen, 512); -#define SHELLECHO "echo " -#define SHELLOFFSET (sizeof(SHELLECHO) - 1) - memcpy(bp, SHELLECHO, SHELLOFFSET); +#define SHELLECHO L("echo ") +#define SHELLOFFSET (SIZE(SHELLECHO) - 1) + MEMCPY(bp, SHELLECHO, SHELLOFFSET); p = bp + SHELLOFFSET; len = SHELLOFFSET; @@ -175,28 +162,15 @@ argv_exp2(sp, excp, cmd, cmdlen) * but then, if your shell was csh, the above example will behave * differently in nvi than in vi. If you want to get other characters * passed through to your shell, change the "meta" option. - * - * To avoid a function call per character, we do a first pass through - * the meta characters looking for characters that aren't expected - * to be there, and then we can ignore them in the user's argument. */ if (opts_empty(sp, O_SHELL, 1) || opts_empty(sp, O_SHELLMETA, 1)) n = 0; else { - for (p = mp = O_STR(sp, O_SHELLMETA); *p != '\0'; ++p) - if (isblank(*p) || isalnum(*p)) - break; p = bp + SHELLOFFSET; n = len - SHELLOFFSET; - if (*p != '\0') { - for (; n > 0; --n, ++p) - if (strchr(mp, *p) != NULL) - break; - } else - for (; n > 0; --n, ++p) - if (!isblank(*p) && - !isalnum(*p) && strchr(mp, *p) != NULL) - break; + for (; n > 0; --n, ++p) + if (IS_SHELLMETA(sp, *p)) + break; } /* @@ -204,13 +178,11 @@ argv_exp2(sp, excp, cmd, cmdlen) * it. Unfortunately, this is comparatively slow. Historically, it * didn't matter much, since users don't enter meta characters as part * of pathnames that frequently. The addition of filename completion - * broke that assumption because it's easy to use. As a result, lots - * folks have complained that the expansion code is too slow. So, we - * detect filename completion as a special case, and do it internally. - * Note that this code assumes that the <asterisk> character is the - * match-anything meta character. That feels safe -- if anyone writes - * a shell that doesn't follow that convention, I'd suggest giving them - * a festive hot-lead enema. + * broke that assumption because it's easy to use. To increase the + * completion performance, nvi used to have an internal routine to + * handle "filename*". However, the shell special characters does not + * limit to "shellmeta", so such a hack breaks historic practice. + * After it all, we split the completion logic out from here. */ switch (n) { case 0: @@ -218,13 +190,6 @@ argv_exp2(sp, excp, cmd, cmdlen) len -= SHELLOFFSET; rval = argv_exp3(sp, excp, p, len); break; - case 1: - if (*p == '*') { - *p = '\0'; - rval = argv_lexp(sp, excp, bp + SHELLOFFSET); - break; - } - /* FALLTHROUGH */ default: if (argv_sexp(sp, &bp, &blen, &len)) { rval = 1; @@ -235,7 +200,7 @@ argv_exp2(sp, excp, cmd, cmdlen) break; } -err: FREE_SPACE(sp, bp, blen); +err: FREE_SPACEW(sp, bp, blen); return (rval); } @@ -244,25 +209,21 @@ err: FREE_SPACE(sp, bp, blen); * Take a string and break it up into an argv, which is appended * to the argument list. * - * PUBLIC: int argv_exp3 __P((SCR *, EXCMD *, char *, size_t)); + * PUBLIC: int argv_exp3 __P((SCR *, EXCMD *, CHAR_T *, size_t)); */ int -argv_exp3(sp, excp, cmd, cmdlen) - SCR *sp; - EXCMD *excp; - char *cmd; - size_t cmdlen; +argv_exp3(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen) { EX_PRIVATE *exp; size_t len; int ch, off; - char *ap, *p; + CHAR_T *ap, *p; for (exp = EXP(sp); cmdlen > 0; ++exp->argsoff) { /* Skip any leading whitespace. */ for (; cmdlen > 0; --cmdlen, ++cmd) { ch = *cmd; - if (!isblank(ch)) + if (!cmdskip(ch)) break; } if (cmdlen == 0) @@ -282,7 +243,7 @@ argv_exp3(sp, excp, cmd, cmdlen) if (IS_ESCAPE(sp, excp, ch) && cmdlen > 1) { ++cmd; --cmdlen; - } else if (isblank(ch)) + } else if (cmdskip(ch)) break; } @@ -312,20 +273,99 @@ argv_exp3(sp, excp, cmd, cmdlen) } /* + * argv_flt_ex -- + * Filter the ex commands with a prefix, and append the results to + * the argument list. + * + * PUBLIC: int argv_flt_ex __P((SCR *, EXCMD *, CHAR_T *, size_t)); + */ +int +argv_flt_ex(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen) +{ + EX_PRIVATE *exp; + EXCMDLIST const *cp; + int off; + size_t len; + + exp = EXP(sp); + + for (off = exp->argsoff, cp = cmds; cp->name != NULL; ++cp) { + len = STRLEN(cp->name); + if (cmdlen > 0 && + (cmdlen > len || MEMCMP(cmd, cp->name, cmdlen))) + continue; + + /* Copy the matched ex command name. */ + argv_alloc(sp, len + 1); + MEMCPY(exp->args[exp->argsoff]->bp, cp->name, len + 1); + exp->args[exp->argsoff]->len = len; + ++exp->argsoff; + excp->argv = exp->args; + excp->argc = exp->argsoff; + } + + return (0); +} + +/* + * argv_flt_user -- + * Filter the ~user list on the system with a prefix, and append + * the results to the argument list. + */ +static int +argv_flt_user(SCR *sp, EXCMD *excp, CHAR_T *uname, size_t ulen) +{ + EX_PRIVATE *exp; + struct passwd *pw; + int off; + char *np; + size_t len, nlen; + + exp = EXP(sp); + off = exp->argsoff; + + /* The input must come with a leading '~'. */ + INT2CHAR(sp, uname + 1, ulen - 1, np, nlen); + if ((np = v_strdup(sp, np, nlen)) == NULL) + return (1); + + setpwent(); + while ((pw = getpwent()) != NULL) { + len = strlen(pw->pw_name); + if (nlen > 0 && + (nlen > len || memcmp(np, pw->pw_name, nlen))) + continue; + + /* Copy '~' + the matched user name. */ + CHAR2INT(sp, pw->pw_name, len + 1, uname, ulen); + argv_alloc(sp, ulen + 1); + exp->args[exp->argsoff]->bp[0] = '~'; + MEMCPY(exp->args[exp->argsoff]->bp + 1, uname, ulen); + exp->args[exp->argsoff]->len = ulen; + ++exp->argsoff; + excp->argv = exp->args; + excp->argc = exp->argsoff; + } + endpwent(); + free(np); + + qsort(exp->args + off, exp->argsoff - off, sizeof(ARGS *), argv_comp); + return (0); +} + +/* * argv_fexp -- * Do file name and bang command expansion. */ static int -argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang) - SCR *sp; - EXCMD *excp; - char *cmd, *p, **bpp; - size_t cmdlen, *lenp, *blenp; - int is_bang; +argv_fexp(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen, CHAR_T *p, size_t *lenp, CHAR_T **bpp, size_t *blenp, int is_bang) { EX_PRIVATE *exp; - char *bp, *t; + char *t; size_t blen, len, off, tlen; + CHAR_T *bp; + CHAR_T *wp; + size_t wlen; /* Replace file name characters. */ for (bp = *bpp, blen = *blenp, len = *lenp; cmdlen > 0; --cmdlen, ++cmd) @@ -339,11 +379,11 @@ argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang) "115|No previous command to replace \"!\""); return (1); } - len += tlen = strlen(exp->lastbcomm); + len += tlen = STRLEN(exp->lastbcomm); off = p - bp; - ADD_SPACE_RET(sp, bp, blen, len); + ADD_SPACE_RETW(sp, bp, blen, len); p = bp + off; - memcpy(p, exp->lastbcomm, tlen); + MEMCPY(p, exp->lastbcomm, tlen); p += tlen; F_SET(excp, E_MODIFY); break; @@ -356,10 +396,11 @@ argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang) tlen = strlen(t); len += tlen; off = p - bp; - ADD_SPACE_RET(sp, bp, blen, len); + ADD_SPACE_RETW(sp, bp, blen, len); p = bp + off; - memcpy(p, t, tlen); - p += tlen; + CHAR2INT(sp, t, tlen, wp, wlen); + MEMCPY(p, wp, wlen); + p += wlen; F_SET(excp, E_MODIFY); break; case '#': @@ -370,10 +411,11 @@ argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang) } len += tlen = strlen(t); off = p - bp; - ADD_SPACE_RET(sp, bp, blen, len); + ADD_SPACE_RETW(sp, bp, blen, len); p = bp + off; - memcpy(p, t, tlen); - p += tlen; + CHAR2INT(sp, t, tlen, wp, wlen); + MEMCPY(p, wp, wlen); + p += wlen; F_SET(excp, E_MODIFY); break; case '\\': @@ -392,7 +434,7 @@ argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang) default: ins_ch: ++len; off = p - bp; - ADD_SPACE_RET(sp, bp, blen, len); + ADD_SPACE_RETW(sp, bp, blen, len); p = bp + off; *p++ = *cmd; } @@ -400,7 +442,7 @@ ins_ch: ++len; /* Nul termination. */ ++len; off = p - bp; - ADD_SPACE_RET(sp, bp, blen, len); + ADD_SPACE_RETW(sp, bp, blen, len); p = bp + off; *p = '\0'; @@ -416,9 +458,7 @@ ins_ch: ++len; * Make more space for arguments. */ static int -argv_alloc(sp, len) - SCR *sp; - size_t len; +argv_alloc(SCR *sp, size_t len) { ARGS *ap; EX_PRIVATE *exp; @@ -483,8 +523,7 @@ mem: msgq(sp, M_SYSERR, NULL); * PUBLIC: int argv_free __P((SCR *)); */ int -argv_free(sp) - SCR *sp; +argv_free(SCR *sp) { EX_PRIVATE *exp; int off; @@ -507,89 +546,103 @@ argv_free(sp) } /* - * argv_lexp -- + * argv_flt_path -- * Find all file names matching the prefix and append them to the - * buffer. + * argument list. + * + * PUBLIC: int argv_flt_path __P((SCR *, EXCMD *, CHAR_T *, size_t)); */ -static int -argv_lexp(sp, excp, path) - SCR *sp; - EXCMD *excp; - char *path; +int +argv_flt_path(SCR *sp, EXCMD *excp, CHAR_T *path, size_t plen) { struct dirent *dp; DIR *dirp; EX_PRIVATE *exp; int off; size_t dlen, len, nlen; - char *dname, *name, *p; + CHAR_T *dname; + CHAR_T *p, *np, *n; + char *name, *tp, *epd = NULL; + CHAR_T *wp; + size_t wlen; exp = EXP(sp); /* Set up the name and length for comparison. */ - if ((p = strrchr(path, '/')) == NULL) { - dname = "."; + if ((path = v_wstrdup(sp, path, plen)) == NULL) + return (1); + if ((p = STRRCHR(path, '/')) == NULL) { + if (*path == '~') { + int rc; + + /* Filter ~user list instead. */ + rc = argv_flt_user(sp, excp, path, plen); + free(path); + return (rc); + } + dname = L("."); dlen = 0; - name = path; - } else { + np = path; + } else { if (p == path) { - dname = "/"; + dname = L("/"); dlen = 1; } else { *p = '\0'; dname = path; - dlen = strlen(path); + dlen = p - path; } - name = p + 1; + np = p + 1; } - nlen = strlen(name); - /* - * XXX - * We don't use the d_namlen field, it's not portable enough; we - * assume that d_name is nul terminated, instead. - */ - if ((dirp = opendir(dname)) == NULL) { - msgq_str(sp, M_SYSERR, dname, "%s"); + INT2CHAR(sp, dname, dlen + 1, tp, nlen); + if ((epd = expanduser(tp)) != NULL) + tp = epd; + if ((dirp = opendir(tp)) == NULL) { + free(epd); + free(path); return (1); } + free(epd); + + INT2CHAR(sp, np, STRLEN(np), tp, nlen); + if ((name = v_strdup(sp, tp, nlen)) == NULL) { + free(path); + return (1); + } + for (off = exp->argsoff; (dp = readdir(dirp)) != NULL;) { if (nlen == 0) { if (dp->d_name[0] == '.') continue; - len = strlen(dp->d_name); + len = dp->d_namlen; } else { - len = strlen(dp->d_name); + len = dp->d_namlen; if (len < nlen || memcmp(dp->d_name, name, nlen)) continue; } /* Directory + name + slash + null. */ - argv_alloc(sp, dlen + len + 2); - p = exp->args[exp->argsoff]->bp; + CHAR2INT(sp, dp->d_name, len + 1, wp, wlen); + argv_alloc(sp, dlen + wlen + 1); + n = exp->args[exp->argsoff]->bp; if (dlen != 0) { - memcpy(p, dname, dlen); - p += dlen; + MEMCPY(n, dname, dlen); + n += dlen; if (dlen > 1 || dname[0] != '/') - *p++ = '/'; + *n++ = '/'; + exp->args[exp->argsoff]->len = dlen + 1; } - memcpy(p, dp->d_name, len + 1); - exp->args[exp->argsoff]->len = dlen + len + 1; + MEMCPY(n, wp, wlen); + exp->args[exp->argsoff]->len += wlen - 1; ++exp->argsoff; excp->argv = exp->args; excp->argc = exp->argsoff; } closedir(dirp); + free(name); + free(path); - if (off == exp->argsoff) { - /* - * If we didn't find a match, complain that the expansion - * failed. We can't know for certain that's the error, but - * it's a good guess, and it matches historic practice. - */ - msgq(sp, M_ERR, "304|Shell expansion failed"); - return (1); - } qsort(exp->args + off, exp->argsoff - off, sizeof(ARGS *), argv_comp); return (0); } @@ -599,10 +652,9 @@ argv_lexp(sp, excp, path) * Alphabetic comparison. */ static int -argv_comp(a, b) - const void *a, *b; +argv_comp(const void *a, const void *b) { - return (strcmp((char *)(*(ARGS **)a)->bp, (char *)(*(ARGS **)b)->bp)); + return (STRCMP((*(ARGS **)a)->bp, (*(ARGS **)b)->bp)); } /* @@ -611,17 +663,17 @@ argv_comp(a, b) * a buffer. */ static int -argv_sexp(sp, bpp, blenp, lenp) - SCR *sp; - char **bpp; - size_t *blenp, *lenp; +argv_sexp(SCR *sp, CHAR_T **bpp, size_t *blenp, size_t *lenp) { enum { SEXP_ERR, SEXP_EXPANSION_ERR, SEXP_OK } rval; FILE *ifp; pid_t pid; size_t blen, len; int ch, std_output[2]; - char *bp, *p, *sh, *sh_path; + CHAR_T *bp, *p; + char *sh, *sh_path; + char *np; + size_t nlen; /* Secure means no shell access. */ if (O_ISSET(sp, O_SECURE)) { @@ -689,7 +741,8 @@ err: if (ifp != NULL) * XXX * Assume that all shells have -c. */ - execl(sh_path, sh, "-c", bp, NULL); + INT2CHAR(sp, bp, STRLEN(bp)+1, np, nlen); + execl(sh_path, sh, "-c", np, (char *)NULL); msgq_str(sp, M_SYSERR, sh_path, "118|Error: execl: %s"); _exit(127); default: /* Parent. */ @@ -707,9 +760,9 @@ err: if (ifp != NULL) * shell that does that is broken. */ for (p = bp, len = 0, ch = EOF; - (ch = getc(ifp)) != EOF; *p++ = ch, --blen, ++len) + (ch = GETC(ifp)) != EOF; *p++ = ch, blen-=sizeof(CHAR_T), ++len) if (blen < 5) { - ADD_SPACE_GOTO(sp, bp, *blenp, *blenp * 2); + ADD_SPACE_GOTOW(sp, bp, *blenp, *blenp * 2); p = bp + len; blen = *blenp - len; } @@ -744,7 +797,7 @@ alloc_err: rval = SEXP_ERR; rval = SEXP_EXPANSION_ERR; for (p = bp; len; ++p, --len) - if (!isblank(*p)) + if (!cmdskip(*p)) break; if (len == 0) rval = SEXP_EXPANSION_ERR; @@ -754,3 +807,108 @@ alloc_err: rval = SEXP_ERR; return (rval == SEXP_OK ? 0 : 1); } + +/* + * argv_esc -- + * Escape a string into an ex and shell argument. + * + * PUBLIC: CHAR_T *argv_esc __P((SCR *, EXCMD *, CHAR_T *, size_t)); + */ +CHAR_T * +argv_esc(SCR *sp, EXCMD *excp, CHAR_T *str, size_t len) +{ + size_t blen, off; + CHAR_T *bp, *p; + int ch; + + GET_SPACE_GOTOW(sp, bp, blen, len + 1); + + /* + * Leaving the first '~' unescaped causes the user to need a + * "./" prefix to edit a file which really starts with a '~'. + * However, the file completion happens to not work for these + * files without the prefix. + * + * All ex expansion characters, "!%#", are double escaped. + */ + for (p = bp; len > 0; ++str, --len) { + ch = *str; + off = p - bp; + if (blen / sizeof(CHAR_T) - off < 3) { + ADD_SPACE_GOTOW(sp, bp, blen, off + 3); + p = bp + off; + } + if (cmdskip(ch) || ch == '\n' || + IS_ESCAPE(sp, excp, ch)) /* Ex. */ + *p++ = CH_LITERAL; + else switch (ch) { + case '~': /* ~user. */ + if (p != bp) + *p++ = '\\'; + break; + case '+': /* Ex +cmd. */ + if (p == bp) + *p++ = '\\'; + break; + case '!': case '%': case '#': /* Ex exp. */ + *p++ = '\\'; + *p++ = '\\'; + break; + case ',': case '-': case '.': case '/': /* Safe. */ + case ':': case '=': case '@': case '_': + break; + default: /* Unsafe. */ + if (isascii(ch) && !isalnum(ch)) + *p++ = '\\'; + } + *p++ = ch; + } + *p = '\0'; + + return bp; + +alloc_err: + return NULL; +} + +/* + * argv_uesc -- + * Unescape an escaped ex and shell argument. + * + * PUBLIC: CHAR_T *argv_uesc __P((SCR *, EXCMD *, CHAR_T *, size_t)); + */ +CHAR_T * +argv_uesc(SCR *sp, EXCMD *excp, CHAR_T *str, size_t len) +{ + size_t blen; + CHAR_T *bp, *p; + + GET_SPACE_GOTOW(sp, bp, blen, len + 1); + + for (p = bp; len > 0; ++str, --len) { + if (IS_ESCAPE(sp, excp, *str)) { + if (--len < 1) + break; + ++str; + } else if (*str == '\\') { + if (--len < 1) + break; + ++str; + + /* Check for double escaping. */ + if (*str == '\\' && len > 1) + switch (str[1]) { + case '!': case '%': case '#': + ++str; + --len; + } + } + *p++ = *str; + } + *p = '\0'; + + return bp; + +alloc_err: + return NULL; +} diff --git a/contrib/nvi/ex/ex_at.c b/contrib/nvi/ex/ex_at.c index e9c6c59..0c12e6c 100644 --- a/contrib/nvi/ex/ex_at.c +++ b/contrib/nvi/ex/ex_at.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_at.c 10.12 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_at.c,v 10.16 2001/06/25 15:19:14 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -34,17 +35,15 @@ static const char sccsid[] = "@(#)ex_at.c 10.12 (Berkeley) 9/15/96"; * PUBLIC: int ex_at __P((SCR *, EXCMD *)); */ int -ex_at(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_at(SCR *sp, EXCMD *cmdp) { CB *cbp; CHAR_T name; EXCMD *ecp; RANGE *rp; TEXT *tp; - size_t len; - char *p; + size_t len = 0; + CHAR_T *p; /* * !!! @@ -84,7 +83,7 @@ ex_at(sp, cmdp) * means @ buffers are still useful in a multi-screen environment. */ CALLOC_RET(sp, ecp, EXCMD *, 1, sizeof(EXCMD)); - CIRCLEQ_INIT(&ecp->rq); + TAILQ_INIT(ecp->rq); CALLOC_RET(sp, rp, RANGE *, 1, sizeof(RANGE)); rp->start = cmdp->addr1.lno; if (F_ISSET(cmdp, E_ADDR_DEF)) { @@ -94,7 +93,7 @@ ex_at(sp, cmdp) rp->stop = cmdp->addr2.lno; FL_SET(ecp->agv_flags, AGV_AT); } - CIRCLEQ_INSERT_HEAD(&ecp->rq, rp, q); + TAILQ_INSERT_HEAD(ecp->rq, rp, q); /* * Buffers executed in ex mode or from the colon command line in vi @@ -104,23 +103,22 @@ ex_at(sp, cmdp) * Build two copies of the command. We need two copies because the * ex parser may step on the command string when it's parsing it. */ - for (len = 0, tp = cbp->textq.cqh_last; - tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) + TAILQ_FOREACH_REVERSE(tp, cbp->textq, _texth, q) len += tp->len + 1; - MALLOC_RET(sp, ecp->cp, char *, len * 2); + MALLOC_RET(sp, ecp->cp, CHAR_T *, len * 2 * sizeof(CHAR_T)); ecp->o_cp = ecp->cp; ecp->o_clen = len; ecp->cp[len] = '\0'; /* Copy the buffer into the command space. */ - for (p = ecp->cp + len, tp = cbp->textq.cqh_last; - tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) { - memcpy(p, tp->lb, tp->len); + p = ecp->cp + len; + TAILQ_FOREACH_REVERSE(tp, cbp->textq, _texth, q) { + MEMCPY(p, tp->lb, tp->len); p += tp->len; *p++ = '\n'; } - LIST_INSERT_HEAD(&sp->gp->ecq, ecp, q); + SLIST_INSERT_HEAD(sp->gp->ecq, ecp, q); return (0); } diff --git a/contrib/nvi/ex/ex_bang.c b/contrib/nvi/ex/ex_bang.c index 25f3f77..4b6f75e 100644 --- a/contrib/nvi/ex/ex_bang.c +++ b/contrib/nvi/ex/ex_bang.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_bang.c 10.33 (Berkeley) 9/23/96"; +static const char sccsid[] = "$Id: ex_bang.c,v 10.36 2001/06/25 15:19:14 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -47,9 +47,7 @@ static const char sccsid[] = "@(#)ex_bang.c 10.33 (Berkeley) 9/23/96"; * PUBLIC: int ex_bang __P((SCR *, EXCMD *)); */ int -ex_bang(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_bang(SCR *sp, EXCMD *cmdp) { enum filtertype ftype; ARGS *ap; @@ -58,6 +56,8 @@ ex_bang(sp, cmdp) recno_t lno; int rval; const char *msg; + char *np; + size_t nlen; ap = cmdp->argv[0]; if (ap->len == 0) { @@ -69,7 +69,7 @@ ex_bang(sp, cmdp) exp = EXP(sp); if (exp->lastbcomm != NULL) free(exp->lastbcomm); - if ((exp->lastbcomm = strdup(ap->bp)) == NULL) { + if ((exp->lastbcomm = v_wstrdup(sp, ap->bp, ap->len)) == NULL) { msgq(sp, M_SYSERR, NULL); return (1); } @@ -88,7 +88,7 @@ ex_bang(sp, cmdp) if (F_ISSET(sp, SC_VI)) vs_update(sp, "!", ap->bp); else { - (void)ex_printf(sp, "!%s\n", ap->bp); + (void)ex_printf(sp, "!"WS"\n", ap->bp); (void)ex_fflush(sp); } } @@ -112,8 +112,9 @@ ex_bang(sp, cmdp) NULL); /* If we're still in a vi screen, move out explicitly. */ + INT2CHAR(sp, ap->bp, ap->len+1, np, nlen); (void)ex_exec_proc(sp, - cmdp, ap->bp, msg, !F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)); + cmdp, np, msg, !F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)); } /* diff --git a/contrib/nvi/ex/ex_cd.c b/contrib/nvi/ex/ex_cd.c index 3307c7b..30a596f 100644 --- a/contrib/nvi/ex/ex_cd.c +++ b/contrib/nvi/ex/ex_cd.c @@ -10,11 +10,11 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_cd.c 10.10 (Berkeley) 8/12/96"; +static const char sccsid[] = "$Id: ex_cd.c,v 10.13 2012/04/12 06:28:27 zy Exp $"; #endif /* not lint */ -#include <sys/param.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <errno.h> @@ -34,15 +34,14 @@ static const char sccsid[] = "@(#)ex_cd.c 10.10 (Berkeley) 8/12/96"; * PUBLIC: int ex_cd __P((SCR *, EXCMD *)); */ int -ex_cd(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_cd(SCR *sp, EXCMD *cmdp) { struct passwd *pw; ARGS *ap; - CHAR_T savech; - char *dir, *p, *t; /* XXX: END OF THE STACK, DON'T TRUST GETCWD. */ - char buf[MAXPATHLEN * 2]; + int savech; + char *dir, *p, *t; + char *buf; + size_t dlen; /* * !!! @@ -71,7 +70,8 @@ ex_cd(sp, cmdp) } break; case 1: - dir = cmdp->argv[0]->bp; + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, + dir, dlen); break; default: abort(); @@ -91,33 +91,35 @@ ex_cd(sp, cmdp) */ if (cmdp->argc == 0 || (ap = cmdp->argv[0])->bp[0] == '/' || - ap->len == 1 && ap->bp[0] == '.' || - ap->len >= 2 && ap->bp[0] == '.' && ap->bp[1] == '.' && - (ap->bp[2] == '/' || ap->bp[2] == '\0')) + (ap->len == 1 && ap->bp[0] == '.') || + (ap->len >= 2 && ap->bp[0] == '.' && ap->bp[1] == '.' && + (ap->bp[2] == '/' || ap->bp[2] == '\0'))) goto err; /* Try the O_CDPATH option values. */ for (p = t = O_STR(sp, O_CDPATH);; ++p) if (*p == '\0' || *p == ':') { /* - * Empty strings specify ".". The only way to get an - * empty string is a leading colon, colons in a row, - * or a trailing colon. Or, to put it the other way, - * if the length is 1 or less, then we're dealing with - * ":XXX", "XXX::XXXX" , "XXX:", or "". Since we've - * already tried dot, we ignore tham all. + * Ignore the empty strings and ".", since we've already + * tried the current directory. */ - if (t < p - 1) { + if (t < p && (p - t != 1 || *t != '.')) { savech = *p; *p = '\0'; - (void)snprintf(buf, - sizeof(buf), "%s/%s", t, dir); + if ((buf = join(t, dir)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } *p = savech; if (!chdir(buf)) { - if (getcwd(buf, sizeof(buf)) != NULL) + free(buf); + if ((buf = getcwd(NULL, 0)) != NULL) { msgq_str(sp, M_INFO, buf, "122|New current directory: %s"); + free(buf); + } return (0); } + free(buf); } t = p + 1; if (*p == '\0') diff --git a/contrib/nvi/ex/ex_cmd.c b/contrib/nvi/ex/ex_cmd.c index 5124aeb..87e32d2 100644 --- a/contrib/nvi/ex/ex_cmd.c +++ b/contrib/nvi/ex/ex_cmd.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_cmd.c 10.20 (Berkeley) 10/10/96"; +static const char sccsid[] = "$Id: ex_cmd.c,v 10.26 2011/07/14 15:11:16 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -50,92 +51,92 @@ static const char sccsid[] = "@(#)ex_cmd.c 10.20 (Berkeley) 10/10/96"; */ EXCMDLIST const cmds[] = { /* C_SCROLL */ - {"\004", ex_pr, E_ADDR2, + {L("\004"), ex_pr, E_ADDR2, "", "^D", "scroll lines"}, /* C_BANG */ - {"!", ex_bang, E_ADDR2_NONE | E_SECURE, + {L("!"), ex_bang, E_ADDR2_NONE|E_SECURE, "S", "[line [,line]] ! command", "filter lines through commands or run commands"}, /* C_HASH */ - {"#", ex_number, E_ADDR2|E_CLRFLAG, + {L("#"), ex_number, E_ADDR2|E_CLRFLAG, "ca1", "[line [,line]] # [count] [l]", "display numbered lines"}, /* C_SUBAGAIN */ - {"&", ex_subagain, E_ADDR2, + {L("&"), ex_subagain, E_ADDR2|E_ADDR_ZERO, "s", "[line [,line]] & [cgr] [count] [#lp]", - "repeat the last substitution"}, + "repeat the last subsitution"}, /* C_STAR */ - {"*", ex_at, 0, + {L("*"), ex_at, 0, "b", "* [buffer]", "execute a buffer"}, /* C_SHIFTL */ - {"<", ex_shiftl, E_ADDR2|E_AUTOPRINT, + {L("<"), ex_shiftl, E_ADDR2|E_AUTOPRINT, "ca1", "[line [,line]] <[<...] [count] [flags]", "shift lines left"}, /* C_EQUAL */ - {"=", ex_equal, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, + {L("="), ex_equal, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, "1", "[line] = [flags]", "display line number"}, /* C_SHIFTR */ - {">", ex_shiftr, E_ADDR2|E_AUTOPRINT, + {L(">"), ex_shiftr, E_ADDR2|E_AUTOPRINT, "ca1", "[line [,line]] >[>...] [count] [flags]", "shift lines right"}, /* C_AT */ - {"@", ex_at, E_ADDR2, + {L("@"), ex_at, E_ADDR2, "b", "@ [buffer]", "execute a buffer"}, /* C_APPEND */ - {"append", ex_append, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, + {L("append"), ex_append, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, "!", "[line] a[ppend][!]", "append input to a line"}, /* C_ABBR */ - {"abbreviate", ex_abbr, 0, + {L("abbreviate"), ex_abbr, 0, "W", "ab[brev] [word replace]", "specify an input abbreviation"}, /* C_ARGS */ - {"args", ex_args, 0, + {L("args"), ex_args, 0, "", "ar[gs]", "display file argument list"}, /* C_BG */ - {"bg", ex_bg, E_VIONLY, + {L("bg"), ex_bg, E_VIONLY, "", "bg", "put a foreground screen into the background"}, /* C_CHANGE */ - {"change", ex_change, E_ADDR2|E_ADDR_ZERODEF, + {L("change"), ex_change, E_ADDR2|E_ADDR_ZERODEF, "!ca", "[line [,line]] c[hange][!] [count]", "change lines to input"}, /* C_CD */ - {"cd", ex_cd, 0, + {L("cd"), ex_cd, 0, "!f1o", "cd[!] [directory]", "change the current directory"}, /* C_CHDIR */ - {"chdir", ex_cd, 0, + {L("chdir"), ex_cd, 0, "!f1o", "chd[ir][!] [directory]", "change the current directory"}, /* C_COPY */ - {"copy", ex_copy, E_ADDR2|E_AUTOPRINT, + {L("copy"), ex_copy, E_ADDR2|E_AUTOPRINT, "l1", "[line [,line]] co[py] line [flags]", "copy lines elsewhere in the file"}, /* C_CSCOPE */ - {"cscope", ex_cscope, 0, + {L("cscope"), ex_cscope, 0, "!s", "cs[cope] command [args]", "create a set of tags using a cscope command"}, @@ -145,318 +146,298 @@ EXCMDLIST const cmds[] = { * in ex_cmd() (the ex parser). Read through the comments there, first. */ /* C_DELETE */ - {"delete", ex_delete, E_ADDR2|E_AUTOPRINT, + {L("delete"), ex_delete, E_ADDR2|E_AUTOPRINT, "bca1", "[line [,line]] d[elete][flags] [buffer] [count] [flags]", "delete lines from the file"}, /* C_DISPLAY */ - {"display", ex_display, 0, + {L("display"), ex_display, 0, "w1r", "display b[uffers] | c[onnections] | s[creens] | t[ags]", "display buffers, connections, screens or tags"}, /* C_EDIT */ - {"edit", ex_edit, E_NEWSCREEN, + {L("edit"), ex_edit, E_NEWSCREEN, "f1o", "[Ee][dit][!] [+cmd] [file]", "begin editing another file"}, /* C_EX */ - {"ex", ex_edit, E_NEWSCREEN, + {L("ex"), ex_edit, E_NEWSCREEN, "f1o", "[Ee]x[!] [+cmd] [file]", "begin editing another file"}, /* C_EXUSAGE */ - {"exusage", ex_usage, 0, + {L("exusage"), ex_usage, 0, "w1o", "[exu]sage [command]", "display ex command usage statement"}, /* C_FILE */ - {"file", ex_file, 0, + {L("file"), ex_file, 0, "f1o", "f[ile] [name]", "display (and optionally set) file name"}, /* C_FG */ - {"fg", ex_fg, E_NEWSCREEN|E_VIONLY, + {L("fg"), ex_fg, E_NEWSCREEN|E_VIONLY, "f1o", "[Ff]g [file]", "bring a backgrounded screen into the foreground"}, /* C_GLOBAL */ - {"global", ex_global, E_ADDR2_ALL, + {L("global"), ex_global, E_ADDR2_ALL, "!s", "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]", "execute a global command on lines matching an RE"}, /* C_HELP */ - {"help", ex_help, 0, + {L("help"), ex_help, 0, "", "he[lp]", "display help statement"}, /* C_INSERT */ - {"insert", ex_insert, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, + {L("insert"), ex_insert, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, "!", "[line] i[nsert][!]", "insert input before a line"}, /* C_JOIN */ - {"join", ex_join, E_ADDR2|E_AUTOPRINT, + {L("join"), ex_join, E_ADDR2|E_AUTOPRINT, "!ca1", "[line [,line]] j[oin][!] [count] [flags]", "join lines into a single line"}, /* C_K */ - {"k", ex_mark, E_ADDR1, + {L("k"), ex_mark, E_ADDR1, "w1r", "[line] k key", "mark a line position"}, /* C_LIST */ - {"list", ex_list, E_ADDR2|E_CLRFLAG, + {L("list"), ex_list, E_ADDR2|E_CLRFLAG, "ca1", "[line [,line]] l[ist] [count] [#]", "display lines in an unambiguous form"}, /* C_MOVE */ - {"move", ex_move, E_ADDR2|E_AUTOPRINT, + {L("move"), ex_move, E_ADDR2|E_AUTOPRINT, "l", "[line [,line]] m[ove] line", "move lines elsewhere in the file"}, /* C_MARK */ - {"mark", ex_mark, E_ADDR1, + {L("mark"), ex_mark, E_ADDR1, "w1r", "[line] ma[rk] key", "mark a line position"}, /* C_MAP */ - {"map", ex_map, 0, + {L("map"), ex_map, 0, "!W", "map[!] [keys replace]", "map input or commands to one or more keys"}, /* C_MKEXRC */ - {"mkexrc", ex_mkexrc, 0, + {L("mkexrc"), ex_mkexrc, 0, "!f1r", "mkexrc[!] file", "write a .exrc file"}, /* C_NEXT */ - {"next", ex_next, E_NEWSCREEN, + {L("next"), ex_next, E_NEWSCREEN, "!fN", "[Nn][ext][!] [+cmd] [file ...]", "edit (and optionally specify) the next file"}, /* C_NUMBER */ - {"number", ex_number, E_ADDR2|E_CLRFLAG, + {L("number"), ex_number, E_ADDR2|E_CLRFLAG, "ca1", "[line [,line]] nu[mber] [count] [l]", "change display to number lines"}, /* C_OPEN */ - {"open", ex_open, E_ADDR1, + {L("open"), ex_open, E_ADDR1, "s", "[line] o[pen] [/RE/] [flags]", "enter \"open\" mode (not implemented)"}, /* C_PRINT */ - {"print", ex_pr, E_ADDR2|E_CLRFLAG, + {L("print"), ex_pr, E_ADDR2|E_CLRFLAG, "ca1", "[line [,line]] p[rint] [count] [#l]", "display lines"}, -/* C_PERLCMD */ - {"perl", ex_perl, E_ADDR2_ALL|E_ADDR_ZERO| - E_ADDR_ZERODEF|E_SECURE, - "s", - "pe[rl] cmd", - "run the perl interpreter with the command"}, -/* C_PERLDOCMD */ - {"perldo", ex_perl, E_ADDR2_ALL|E_ADDR_ZERO| - E_ADDR_ZERODEF|E_SECURE, - "s", - "perld[o] cmd", - "run the perl interpreter with the command, on each line"}, /* C_PRESERVE */ - {"preserve", ex_preserve, 0, + {L("preserve"), ex_preserve, 0, "", "pre[serve]", "preserve an edit session for recovery"}, /* C_PREVIOUS */ - {"previous", ex_prev, E_NEWSCREEN, + {L("previous"), ex_prev, E_NEWSCREEN, "!", "[Pp]rev[ious][!]", "edit the previous file in the file argument list"}, /* C_PUT */ - {"put", ex_put, + {L("put"), ex_put, E_ADDR1|E_AUTOPRINT|E_ADDR_ZERO|E_ADDR_ZERODEF, "b", "[line] pu[t] [buffer]", "append a cut buffer to the line"}, /* C_QUIT */ - {"quit", ex_quit, 0, + {L("quit"), ex_quit, 0, "!", "q[uit][!]", "exit ex/vi"}, /* C_READ */ - {"read", ex_read, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, + {L("read"), ex_read, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF, "s", "[line] r[ead] [!cmd | [file]]", "append input from a command or file to the line"}, /* C_RECOVER */ - {"recover", ex_recover, 0, + {L("recover"), ex_recover, 0, "!f1r", "recover[!] file", "recover a saved file"}, /* C_RESIZE */ - {"resize", ex_resize, E_VIONLY, + {L("resize"), ex_resize, E_VIONLY, "c+", "resize [+-]rows", "grow or shrink the current screen"}, /* C_REWIND */ - {"rewind", ex_rew, 0, + {L("rewind"), ex_rew, 0, "!", "rew[ind][!]", "re-edit all the files in the file argument list"}, -#ifdef GTAGS -/* C_RTAG */ - {"rtag", ex_rtag_push, E_NEWSCREEN, - "!w1o", - "[Rr]ta[g][!] [string]", - "edit the file containing the tag"}, -#endif /* * !!! * Adding new commands starting with 's' may break the substitute command code * in ex_cmd() (the ex parser). Read through the comments there, first. */ /* C_SUBSTITUTE */ - {"s", ex_s, E_ADDR2, + {L("s"), ex_s, E_ADDR2|E_ADDR_ZERO, "s", "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]", "substitute on lines matching an RE"}, /* C_SCRIPT */ - {"script", ex_script, E_SECURE, + {L("script"), ex_script, E_SECURE, "!f1o", "sc[ript][!] [file]", "run a shell in a screen"}, /* C_SET */ - {"set", ex_set, 0, + {L("set"), ex_set, 0, "wN", "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]", "set options (use \":set all\" to see all options)"}, /* C_SHELL */ - {"shell", ex_shell, E_SECURE, + {L("shell"), ex_shell, E_SECURE, "", "sh[ell]", "suspend editing and run a shell"}, /* C_SOURCE */ - {"source", ex_source, 0, + {L("source"), ex_source, 0, "f1r", "so[urce] file", "read a file of ex commands"}, /* C_STOP */ - {"stop", ex_stop, E_SECURE, + {L("stop"), ex_stop, E_SECURE, "!", "st[op][!]", "suspend the edit session"}, /* C_SUSPEND */ - {"suspend", ex_stop, E_SECURE, + {L("suspend"), ex_stop, E_SECURE, "!", "su[spend][!]", "suspend the edit session"}, /* C_T */ - {"t", ex_copy, E_ADDR2|E_AUTOPRINT, + {L("t"), ex_copy, E_ADDR2|E_AUTOPRINT, "l1", "[line [,line]] t line [flags]", "copy lines elsewhere in the file"}, /* C_TAG */ - {"tag", ex_tag_push, E_NEWSCREEN, + {L("tag"), ex_tag_push, E_NEWSCREEN, "!w1o", "[Tt]a[g][!] [string]", "edit the file containing the tag"}, /* C_TAGNEXT */ - {"tagnext", ex_tag_next, 0, + {L("tagnext"), ex_tag_next, 0, "!", "tagn[ext][!]", "move to the next tag"}, /* C_TAGPOP */ - {"tagpop", ex_tag_pop, 0, + {L("tagpop"), ex_tag_pop, 0, "!w1o", "tagp[op][!] [number | file]", "return to the previous group of tags"}, /* C_TAGPREV */ - {"tagprev", ex_tag_prev, 0, + {L("tagprev"), ex_tag_prev, 0, "!", "tagpr[ev][!]", "move to the previous tag"}, /* C_TAGTOP */ - {"tagtop", ex_tag_top, 0, + {L("tagtop"), ex_tag_top, 0, "!", "tagt[op][!]", "discard all tags"}, -/* C_TCLCMD */ - {"tcl", ex_tcl, E_ADDR2_ALL|E_ADDR_ZERO| - E_ADDR_ZERODEF|E_SECURE, - "s", - "tc[l] cmd", - "run the tcl interpreter with the command"}, /* C_UNDO */ - {"undo", ex_undo, E_AUTOPRINT, + {L("undo"), ex_undo, E_AUTOPRINT, "", "u[ndo]", "undo the most recent change"}, /* C_UNABBREVIATE */ - {"unabbreviate",ex_unabbr, 0, + {L("unabbreviate"),ex_unabbr, 0, "w1r", "una[bbrev] word", "delete an abbreviation"}, /* C_UNMAP */ - {"unmap", ex_unmap, 0, + {L("unmap"), ex_unmap, 0, "!w1r", "unm[ap][!] word", "delete an input or command map"}, /* C_V */ - {"v", ex_v, E_ADDR2_ALL, + {L("v"), ex_v, E_ADDR2_ALL, "s", "[line [,line]] v [;/]RE[;/] [commands]", "execute a global command on lines NOT matching an RE"}, /* C_VERSION */ - {"version", ex_version, 0, + {L("version"), ex_version, 0, "", "version", "display the program version information"}, /* C_VISUAL_EX */ - {"visual", ex_visual, E_ADDR1|E_ADDR_ZERODEF, + {L("visual"), ex_visual, E_ADDR1|E_ADDR_ZERODEF, "2c11", "[line] vi[sual] [-|.|+|^] [window_size] [flags]", "enter visual (vi) mode from ex mode"}, /* C_VISUAL_VI */ - {"visual", ex_edit, E_NEWSCREEN, + {L("visual"), ex_edit, E_NEWSCREEN, "f1o", "[Vv]i[sual][!] [+cmd] [file]", "edit another file (from vi mode only)"}, /* C_VIUSAGE */ - {"viusage", ex_viusage, 0, + {L("viusage"), ex_viusage, 0, "w1o", "[viu]sage [key]", "display vi key usage statement"}, +/* C_VSPLIT */ + {L("vsplit"), ex_edit, E_VIONLY, + "f1o", + "vs[plit] [+cmd] [file]", + "split the current screen vertically"}, /* C_WRITE */ - {"write", ex_write, E_ADDR2_ALL|E_ADDR_ZERODEF, + {L("write"), ex_write, E_ADDR2_ALL|E_ADDR_ZERODEF, "!s", "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]", "write the file"}, /* C_WN */ - {"wn", ex_wn, E_ADDR2_ALL|E_ADDR_ZERODEF, + {L("wn"), ex_wn, E_ADDR2_ALL|E_ADDR_ZERODEF, "!s", "[line [,line]] wn[!] [>>] [file]", "write the file and switch to the next file"}, /* C_WQ */ - {"wq", ex_wq, E_ADDR2_ALL|E_ADDR_ZERODEF, + {L("wq"), ex_wq, E_ADDR2_ALL|E_ADDR_ZERODEF, "!s", "[line [,line]] wq[!] [>>] [file]", "write the file and exit"}, /* C_XIT */ - {"xit", ex_xit, E_ADDR2_ALL|E_ADDR_ZERODEF, + {L("xit"), ex_xit, E_ADDR2_ALL|E_ADDR_ZERODEF, "!f1o", "[line [,line]] x[it][!] [file]", "exit"}, /* C_YANK */ - {"yank", ex_yank, E_ADDR2, + {L("yank"), ex_yank, E_ADDR2, "bca", "[line [,line]] ya[nk] [buffer] [count]", "copy lines to a cut buffer"}, /* C_Z */ - {"z", ex_z, E_ADDR1, + {L("z"), ex_z, E_ADDR1, "3c01", "[line] z [-|.|+|^|=] [count] [flags]", "display different screens of the file"}, /* C_SUBTILDE */ - {"~", ex_subtilde, E_ADDR2, + {L("~"), ex_subtilde, E_ADDR2|E_ADDR_ZERO, "s", "[line [,line]] ~ [cgr] [count] [#lp]", "replace previous RE with previous replacement string,"}, diff --git a/contrib/nvi/ex/ex_cscope.c b/contrib/nvi/ex/ex_cscope.c index c2fa0a5..afc7fa9 100644 --- a/contrib/nvi/ex/ex_cscope.c +++ b/contrib/nvi/ex/ex_cscope.c @@ -10,14 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_cscope.c 10.13 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_cscope.c,v 10.25 2012/10/04 09:23:03 zy Exp $"; #endif /* not lint */ -#include <sys/param.h> -#include <sys/types.h> /* XXX: param.h may not have included types.h */ +#include <sys/types.h> #include <sys/queue.h> #include <sys/stat.h> -#include <sys/time.h> #include <sys/wait.h> #include <bitstring.h> @@ -25,6 +23,7 @@ static const char sccsid[] = "@(#)ex_cscope.c 10.13 (Berkeley) 9/15/96"; #include <errno.h> #include <fcntl.h> #include <limits.h> +#include <signal.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> @@ -62,15 +61,15 @@ find c|d|e|f|g|i|s|t buffer|pattern\n\ s: find all uses of name\n\ t: find assignments to name" -static int cscope_add __P((SCR *, EXCMD *, char *)); -static int cscope_find __P((SCR *, EXCMD*, char *)); -static int cscope_help __P((SCR *, EXCMD *, char *)); -static int cscope_kill __P((SCR *, EXCMD *, char *)); -static int cscope_reset __P((SCR *, EXCMD *, char *)); +static int cscope_add __P((SCR *, EXCMD *, CHAR_T *)); +static int cscope_find __P((SCR *, EXCMD*, CHAR_T *)); +static int cscope_help __P((SCR *, EXCMD *, CHAR_T *)); +static int cscope_kill __P((SCR *, EXCMD *, CHAR_T *)); +static int cscope_reset __P((SCR *, EXCMD *, CHAR_T *)); typedef struct _cc { char *name; - int (*function) __P((SCR *, EXCMD *, char *)); + int (*function) __P((SCR *, EXCMD *, CHAR_T *)); char *help_msg; char *usage_msg; } CC; @@ -108,14 +107,15 @@ static int terminate __P((SCR *, CSC *, int)); * PUBLIC: int ex_cscope __P((SCR *, EXCMD *)); */ int -ex_cscope(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_cscope(SCR *sp, EXCMD *cmdp) { CC const *ccp; EX_PRIVATE *exp; int i; - char *cmd, *p; + CHAR_T *cmd; + CHAR_T *p; + char *np; + size_t nlen; /* Initialize the default cscope directories. */ exp = EXP(sp); @@ -139,7 +139,8 @@ ex_cscope(sp, cmdp) for (; *p && isspace(*p); ++p); } - if ((ccp = lookup_ccmd(cmd)) == NULL) { + INT2CHAR(sp, cmd, STRLEN(cmd) + 1, np, nlen); + if ((ccp = lookup_ccmd(np)) == NULL) { usage: msgq(sp, M_ERR, "309|Use \"cscope help\" for help"); return (1); } @@ -153,12 +154,12 @@ usage: msgq(sp, M_ERR, "309|Use \"cscope help\" for help"); * Initialize the cscope package. */ static int -start_cscopes(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +start_cscopes(SCR *sp, EXCMD *cmdp) { size_t blen, len; char *bp, *cscopes, *p, *t; + CHAR_T *wp; + size_t wlen; /* * EXTENSION #1: @@ -175,12 +176,14 @@ start_cscopes(sp, cmdp) if ((cscopes = getenv("CSCOPE_DIRS")) == NULL) return (0); len = strlen(cscopes); - GET_SPACE_RET(sp, bp, blen, len); + GET_SPACE_RETC(sp, bp, blen, len); memcpy(bp, cscopes, len + 1); for (cscopes = t = bp; (p = strsep(&t, "\t :")) != NULL;) - if (*p != '\0') - (void)cscope_add(sp, cmdp, p); + if (*p != '\0') { + CHAR2INT(sp, p, strlen(p) + 1, wp, wlen); + (void)cscope_add(sp, cmdp, wp); + } FREE_SPACE(sp, bp, blen); return (0); @@ -191,17 +194,16 @@ start_cscopes(sp, cmdp) * The cscope add command. */ static int -cscope_add(sp, cmdp, dname) - SCR *sp; - EXCMD *cmdp; - char *dname; +cscope_add(SCR *sp, EXCMD *cmdp, CHAR_T *dname) { struct stat sb; EX_PRIVATE *exp; CSC *csc; size_t len; int cur_argc; - char *dbname, path[MAXPATHLEN]; + char *dbname, *path; + char *np = NULL; + size_t nlen; exp = EXP(sp); @@ -211,8 +213,9 @@ cscope_add(sp, cmdp, dname) * >1 additional args: object, too many args. */ cur_argc = cmdp->argc; - if (argv_exp2(sp, cmdp, dname, strlen(dname))) + if (argv_exp2(sp, cmdp, dname, STRLEN(dname))) { return (1); + } if (cmdp->argc == cur_argc) { (void)csc_help(sp, "add"); return (1); @@ -220,10 +223,12 @@ cscope_add(sp, cmdp, dname) if (cmdp->argc == cur_argc + 1) dname = cmdp->argv[cur_argc]->bp; else { - ex_emsg(sp, dname, EXM_FILECOUNT); + ex_emsg(sp, np, EXM_FILECOUNT); return (1); } + INT2CHAR(sp, dname, STRLEN(dname)+1, np, nlen); + /* * The user can specify a specific file (so they can have multiple * Cscope databases in a single directory) or a directory. If the @@ -231,28 +236,36 @@ cscope_add(sp, cmdp, dname) * standard database file name and try again. Store the directory * name regardless so that we can use it as a base for searches. */ - if (stat(dname, &sb)) { - msgq(sp, M_SYSERR, dname); + if (stat(np, &sb)) { + msgq(sp, M_SYSERR, "%s", np); return (1); } if (S_ISDIR(sb.st_mode)) { - (void)snprintf(path, sizeof(path), - "%s/%s", dname, CSCOPE_DBFILE); + if ((path = join(np, CSCOPE_DBFILE)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } if (stat(path, &sb)) { - msgq(sp, M_SYSERR, path); + msgq(sp, M_SYSERR, "%s", path); + free(path); return (1); } + free(path); dbname = CSCOPE_DBFILE; - } else if ((dbname = strrchr(dname, '/')) != NULL) + } else if ((dbname = strrchr(np, '/')) != NULL) *dbname++ = '\0'; + else { + dbname = np; + np = "."; + } /* Allocate a cscope connection structure and initialize its fields. */ - len = strlen(dname); + len = strlen(np); CALLOC_RET(sp, csc, CSC *, 1, sizeof(CSC) + len); csc->dname = csc->buf; csc->dlen = len; - memcpy(csc->dname, dname, len); - csc->mtime = sb.st_mtime; + memcpy(csc->dname, np, len); + csc->mtim = sb.st_mtimespec; /* Get the search paths for the cscope. */ if (get_paths(sp, csc)) @@ -267,15 +280,10 @@ cscope_add(sp, cmdp, dname) * on error, we have to call terminate, which expects the csc to * be on the chain. */ - LIST_INSERT_HEAD(&exp->cscq, csc, q); + SLIST_INSERT_HEAD(exp->cscq, csc, q); /* Read the initial prompt from the cscope to make sure it's okay. */ - if (read_prompt(sp, csc)) { - terminate(sp, csc, 0); - return (1); - } - - return (0); + return read_prompt(sp, csc); err: free(csc); return (1); @@ -287,14 +295,12 @@ err: free(csc); * cscope database. */ static int -get_paths(sp, csc) - SCR *sp; - CSC *csc; +get_paths(SCR *sp, CSC *csc) { struct stat sb; int fd, nentries; size_t len; - char *p, **pathp, buf[MAXPATHLEN * 2]; + char *p, **pathp, *buf; /* * EXTENSION #2: @@ -308,7 +314,10 @@ get_paths(sp, csc) * directory. To fix this, rewrite the each path using the cscope * directory as a prefix. */ - (void)snprintf(buf, sizeof(buf), "%s/%s", csc->dname, CSCOPE_PATHS); + if ((buf = join(csc->dname, CSCOPE_PATHS)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } if (stat(buf, &sb) == 0) { /* Read in the CSCOPE_PATHS file. */ len = sb.st_size; @@ -318,9 +327,11 @@ get_paths(sp, csc) msgq_str(sp, M_SYSERR, buf, "%s"); if (fd >= 0) (void)close(fd); + free(buf); return (1); } (void)close(fd); + free(buf); csc->pbuf[len] = '\0'; /* Count up the entries. */ @@ -336,6 +347,7 @@ get_paths(sp, csc) *pathp++ = p; return (0); } + free(buf); /* * If the CSCOPE_PATHS file doesn't exist, we look for files @@ -362,24 +374,22 @@ alloc_err: * Fork off the cscope process. */ static int -run_cscope(sp, csc, dbname) - SCR *sp; - CSC *csc; - char *dbname; +run_cscope(SCR *sp, CSC *csc, char *dbname) { int to_cs[2], from_cs[2]; - char cmd[MAXPATHLEN * 2]; + char *cmd; /* * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from * from_cs[0] and writes to to_cs[1]. */ - to_cs[0] = to_cs[1] = from_cs[0] = from_cs[0] = -1; + to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1; if (pipe(to_cs) < 0 || pipe(from_cs) < 0) { msgq(sp, M_SYSERR, "pipe"); goto err; } switch (csc->pid = vfork()) { + char *dn, *dbn; case -1: msgq(sp, M_SYSERR, "vfork"); err: if (to_cs[0] != -1) @@ -401,11 +411,23 @@ err: if (to_cs[0] != -1) (void)close(from_cs[0]); /* Run the cscope command. */ -#define CSCOPE_CMD_FMT "cd '%s' && exec cscope -dl -f %s" - (void)snprintf(cmd, sizeof(cmd), - CSCOPE_CMD_FMT, csc->dname, dbname); - (void)execl(_PATH_BSHELL, "sh", "-c", cmd, NULL); +#define CSCOPE_CMD_FMT "cd %s && exec cscope -dl -f %s" + if ((dn = quote(csc->dname)) == NULL) + goto nomem; + if ((dbn = quote(dbname)) == NULL) { + free(dn); + goto nomem; + } + (void)asprintf(&cmd, CSCOPE_CMD_FMT, dn, dbn); + free(dbn); + free(dn); + if (cmd == NULL) { +nomem: msgq(sp, M_SYSERR, NULL); + _exit (1); + } + (void)execl(_PATH_BSHELL, "sh", "-c", cmd, (char *)NULL); msgq_str(sp, M_SYSERR, cmd, "execl: %s"); + free(cmd); _exit (127); /* NOTREACHED */ default: /* parent. */ @@ -431,10 +453,7 @@ err: if (to_cs[0] != -1) * The cscope find command. */ static int -cscope_find(sp, cmdp, pattern) - SCR *sp; - EXCMD *cmdp; - char *pattern; +cscope_find(SCR *sp, EXCMD *cmdp, CHAR_T *pattern) { CSC *csc, *csc_next; EX_PRIVATE *exp; @@ -444,11 +463,13 @@ cscope_find(sp, cmdp, pattern) recno_t lno; size_t cno, search; int force, istmp, matches; + char *np = NULL; + size_t nlen; exp = EXP(sp); /* Check for connections. */ - if (exp->cscq.lh_first == NULL) { + if (SLIST_EMPTY(exp->cscq)) { msgq(sp, M_ERR, "310|No cscope connections running"); return (1); } @@ -460,20 +481,24 @@ cscope_find(sp, cmdp, pattern) */ rtp = NULL; rtqp = NULL; - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (TAILQ_EMPTY(exp->tq)) { /* Initialize the `local context' tag queue structure. */ CALLOC_GOTO(sp, rtqp, TAGQ *, 1, sizeof(TAGQ)); - CIRCLEQ_INIT(&rtqp->tagq); + TAILQ_INIT(rtqp->tagq); /* Initialize and link in its tag structure. */ CALLOC_GOTO(sp, rtp, TAG *, 1, sizeof(TAG)); - CIRCLEQ_INSERT_HEAD(&rtqp->tagq, rtp, q); - rtqp->current = rtp; + TAILQ_INSERT_HEAD(rtqp->tagq, rtp, q); + rtqp->current = rtp; } /* Create the cscope command. */ - if ((tqp = create_cs_cmd(sp, pattern, &search)) == NULL) + INT2CHAR(sp, pattern, STRLEN(pattern) + 1, np, nlen); + np = strdup(np); + if ((tqp = create_cs_cmd(sp, np, &search)) == NULL) goto err; + if (np != NULL) + free(np); /* * Stick the current context in a convenient place, we'll lose it @@ -486,35 +511,32 @@ cscope_find(sp, cmdp, pattern) /* Search all open connections for a match. */ matches = 0; - for (csc = exp->cscq.lh_first; csc != NULL; csc = csc_next) { - /* Copy csc->q.lh_next here in case csc is killed. */ - csc_next = csc->q.le_next; - + /* Copy next connect here in case csc is killed. */ + SLIST_FOREACH_SAFE(csc, exp->cscq, q, csc_next) { /* * Send the command to the cscope program. (We skip the * first two bytes of the command, because we stored the * search cscope command character and a leading space * there.) */ - (void)fprintf(csc->to_fp, "%d%s\n", search, tqp->tag + 2); + (void)fprintf(csc->to_fp, "%lu%s\n", search, tqp->tag + 2); (void)fflush(csc->to_fp); /* Read the output. */ - if (parse(sp, csc, tqp, &matches)) { - if (rtqp != NULL) - free(rtqp); - tagq_free(sp, tqp); - return (1); - } + if (parse(sp, csc, tqp, &matches)) + goto nomatch; } if (matches == 0) { msgq(sp, M_INFO, "278|No matches for query"); - return (0); +nomatch: if (rtp != NULL) + free(rtp); + if (rtqp != NULL) + free(rtqp); + tagq_free(sp, tqp); + return (1); } - tqp->current = tqp->tagq.cqh_first; - /* Try to switch to the first tag. */ force = FL_ISSET(cmdp->iflags, E_C_FORCE); if (F_ISSET(cmdp, E_NEWSCREEN)) { @@ -533,13 +555,13 @@ cscope_find(sp, cmdp, pattern) * in place, so we can pop all the way back to the current mark. * Note, it doesn't point to much of anything, it's a placeholder. */ - if (exp->tq.cqh_first == (void *)&exp->tq) { - CIRCLEQ_INSERT_HEAD(&exp->tq, rtqp, q); + if (TAILQ_EMPTY(exp->tq)) { + TAILQ_INSERT_HEAD(exp->tq, rtqp, q); } else - rtqp = exp->tq.cqh_first; + rtqp = TAILQ_FIRST(exp->tq); /* Link the current TAGQ structure into place. */ - CIRCLEQ_INSERT_HEAD(&exp->tq, tqp, q); + TAILQ_INSERT_HEAD(exp->tq, tqp, q); (void)cscope_search(sp, tqp, tqp->current); @@ -570,6 +592,8 @@ alloc_err: free(rtqp); if (rtp != NULL) free(rtp); + if (np != NULL) + free(np); return (1); } @@ -578,10 +602,7 @@ alloc_err: * Build a cscope command, creating and initializing the base TAGQ. */ static TAGQ * -create_cs_cmd(sp, pattern, searchp) - SCR *sp; - char *pattern; - size_t *searchp; +create_cs_cmd(SCR *sp, char *pattern, size_t *searchp) { CB *cbp; TAGQ *tqp; @@ -601,8 +622,8 @@ create_cs_cmd(sp, pattern, searchp) goto usage; /* Skip leading blanks, check for command character. */ - for (; isblank(pattern[0]); ++pattern); - if (pattern[0] == '\0' || !isblank(pattern[1])) + for (; cmdskip(pattern[0]); ++pattern); + if (pattern[0] == '\0' || !cmdskip(pattern[1])) goto usage; for (*searchp = 0, p = CSCOPE_QUERIES; *p != '\0' && *p != pattern[0]; ++*searchp, ++p); @@ -614,7 +635,7 @@ create_cs_cmd(sp, pattern, searchp) } /* Skip <blank> characters to the pattern. */ - for (p = pattern + 1; *p != '\0' && isblank(*p); ++p); + for (p = pattern + 1; *p != '\0' && cmdskip(*p); ++p); if (*p == '\0') { usage: (void)csc_help(sp, "find"); return (NULL); @@ -625,8 +646,8 @@ usage: (void)csc_help(sp, "find"); if (p[0] == '"' && p[1] != '\0' && p[2] == '\0') CBNAME(sp, cbp, p[1]); if (cbp != NULL) { - p = cbp->textq.cqh_first->lb; - tlen = cbp->textq.cqh_first->len; + INT2CHAR(sp, TAILQ_FIRST(cbp->textq)->lb, + TAILQ_FIRST(cbp->textq)->len, p, tlen); } else tlen = strlen(p); @@ -634,7 +655,7 @@ usage: (void)csc_help(sp, "find"); CALLOC(sp, tqp, TAGQ *, 1, sizeof(TAGQ) + tlen + 3); if (tqp == NULL) return (NULL); - CIRCLEQ_INIT(&tqp->tagq); + TAILQ_INIT(tqp->tagq); tqp->tag = tqp->buf; tqp->tag[0] = pattern[0]; tqp->tag[1] = ' '; @@ -651,17 +672,15 @@ usage: (void)csc_help(sp, "find"); * Parse the cscope output. */ static int -parse(sp, csc, tqp, matchesp) - SCR *sp; - CSC *csc; - TAGQ *tqp; - int *matchesp; +parse(SCR *sp, CSC *csc, TAGQ *tqp, int *matchesp) { TAG *tp; - recno_t slno; - size_t dlen, nlen, slen; - int ch, i, isolder, nlines; - char *dname, *name, *search, *p, *t, dummy[2], buf[2048]; + recno_t slno = 0; + size_t dlen, nlen = 0, slen = 0; + int ch, i, isolder = 0, nlines; + char *dname = NULL, *name = NULL, *search, *p, *t, dummy[2], buf[2048]; + CHAR_T *wp; + size_t wlen; for (;;) { if (!fgets(buf, sizeof(buf), csc->from_fp)) @@ -738,9 +757,12 @@ parse(sp, csc, tqp, matchesp) * length cscope information that follows it. */ CALLOC_RET(sp, tp, - TAG *, 1, sizeof(TAG) + dlen + 2 + nlen + 1 + slen + 1); - tp->fname = tp->buf; - if (dlen != 0) { + TAG *, 1, sizeof(TAG) + dlen + 2 + nlen + 1 + + (slen + 1) * sizeof(CHAR_T)); + tp->fname = (char *)tp->buf; + if (dlen == 1 && *dname == '.') + --dlen; + else if (dlen != 0) { memcpy(tp->fname, dname, dlen); tp->fname[dlen] = '/'; ++dlen; @@ -748,17 +770,23 @@ parse(sp, csc, tqp, matchesp) memcpy(tp->fname + dlen, name, nlen + 1); tp->fnlen = dlen + nlen; tp->slno = slno; - if (slen != 0) { - tp->search = tp->fname + tp->fnlen + 1; - memcpy(tp->search, search, (tp->slen = slen) + 1); - } - CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q); + tp->search = (CHAR_T*)(tp->fname + tp->fnlen + 1); + CHAR2INT(sp, search, slen + 1, wp, wlen); + MEMCPY(tp->search, wp, (tp->slen = slen) + 1); + TAILQ_INSERT_TAIL(tqp->tagq, tp, q); + + /* Try to preset the tag within the current file. */ + if (sp->frp != NULL && sp->frp->name != NULL && + tqp->current == NULL && !strcmp(tp->fname, sp->frp->name)) + tqp->current = tp; ++*matchesp; } - (void)read_prompt(sp, csc); - return (0); + if (tqp->current == NULL) + tqp->current = TAILQ_FIRST(tqp->tagq); + + return read_prompt(sp, csc); io_err: if (feof(csc->from_fp)) errno = EIO; @@ -772,15 +800,10 @@ io_err: if (feof(csc->from_fp)) * Search for the right path to this file. */ static void -csc_file(sp, csc, name, dirp, dlenp, isolderp) - SCR *sp; - CSC *csc; - char *name, **dirp; - size_t *dlenp; - int *isolderp; +csc_file(SCR *sp, CSC *csc, char *name, char **dirp, size_t *dlenp, int *isolderp) { struct stat sb; - char **pp, buf[MAXPATHLEN]; + char **pp, *buf; /* * Check for the file in all of the listed paths. If we don't @@ -790,13 +813,20 @@ csc_file(sp, csc, name, dirp, dlenp, isolderp) * lives. */ for (pp = csc->paths; *pp != NULL; ++pp) { - (void)snprintf(buf, sizeof(buf), "%s/%s", *pp, name); + if ((buf = join(*pp, name)) == NULL) { + msgq(sp, M_SYSERR, NULL); + *dlenp = 0; + return; + } if (stat(buf, &sb) == 0) { + free(buf); *dirp = *pp; *dlenp = strlen(*pp); - *isolderp = sb.st_mtime < csc->mtime; + *isolderp = timespeccmp( + &sb.st_mtimespec, &csc->mtim, <); return; } + free(buf); } *dlenp = 0; } @@ -806,12 +836,13 @@ csc_file(sp, csc, name, dirp, dlenp, isolderp) * The cscope help command. */ static int -cscope_help(sp, cmdp, subcmd) - SCR *sp; - EXCMD *cmdp; - char *subcmd; +cscope_help(SCR *sp, EXCMD *cmdp, CHAR_T *subcmd) { - return (csc_help(sp, subcmd)); + char *np; + size_t nlen; + + INT2CHAR(sp, subcmd, STRLEN(subcmd) + 1, np, nlen); + return (csc_help(sp, np)); } /* @@ -819,9 +850,7 @@ cscope_help(sp, cmdp, subcmd) * Display help/usage messages. */ static int -csc_help(sp, cmd) - SCR *sp; - char *cmd; +csc_help(SCR *sp, char *cmd) { CC const *ccp; @@ -848,12 +877,17 @@ csc_help(sp, cmd) * The cscope kill command. */ static int -cscope_kill(sp, cmdp, cn) - SCR *sp; - EXCMD *cmdp; - char *cn; +cscope_kill(SCR *sp, EXCMD *cmdp, CHAR_T *cn) { - return (terminate(sp, NULL, atoi(cn))); + char *np; + size_t nlen; + int n = 1; + + if (*cn) { + INT2CHAR(sp, cn, STRLEN(cn) + 1, np, nlen); + n = atoi(np); + } + return (terminate(sp, NULL, n)); } /* @@ -861,49 +895,54 @@ cscope_kill(sp, cmdp, cn) * Detach from a cscope process. */ static int -terminate(sp, csc, n) - SCR *sp; - CSC *csc; - int n; +terminate(SCR *sp, CSC *csc, int n) { EX_PRIVATE *exp; - int i, pstat; + int i = 0, pstat; + CSC *cp, *pre_cp = NULL; exp = EXP(sp); /* - * We either get a csc structure or a number. If not provided a - * csc structure, find the right one. + * We either get a csc structure or a number. Locate and remove + * the candidate which matches the structure or the number. */ - if (csc == NULL) { - if (n < 1) - goto badno; - for (i = 1, csc = exp->cscq.lh_first; - csc != NULL; csc = csc->q.le_next, i++) - if (i == n) - break; - if (csc == NULL) { -badno: msgq(sp, M_ERR, "312|%d: no such cscope session", n); - return (1); + if (csc == NULL && n < 1) + goto badno; + SLIST_FOREACH(cp, exp->cscq, q) { + ++i; + if (csc == NULL ? i != n : cp != csc) { + pre_cp = cp; + continue; } + if (cp == SLIST_FIRST(exp->cscq)) + SLIST_REMOVE_HEAD(exp->cscq, q); + else + SLIST_REMOVE_AFTER(pre_cp, q); + csc = cp; + break; + } + if (csc == NULL) { +badno: msgq(sp, M_ERR, "312|%d: no such cscope session", n); + return (1); } /* * XXX * Theoretically, we have the only file descriptors to the process, * so closing them should let it exit gracefully, deleting temporary - * files, etc. The original vi cscope integration sent the cscope - * connection a SIGTERM signal, so I'm not sure if closing the file - * descriptors is sufficient. + * files, etc. However, the earlier created cscope processes seems + * to refuse to quit unless we send a SIGTERM signal. */ if (csc->from_fp != NULL) (void)fclose(csc->from_fp); if (csc->to_fp != NULL) (void)fclose(csc->to_fp); + if (i > 1) + (void)kill(csc->pid, SIGTERM); (void)waitpid(csc->pid, &pstat, 0); /* Discard cscope connection information. */ - LIST_REMOVE(csc, q); if (csc->pbuf != NULL) free(csc->pbuf); if (csc->paths != NULL) @@ -917,15 +956,24 @@ badno: msgq(sp, M_ERR, "312|%d: no such cscope session", n); * The cscope reset command. */ static int -cscope_reset(sp, cmdp, notusedp) - SCR *sp; - EXCMD *cmdp; - char *notusedp; +cscope_reset(SCR *sp, EXCMD *cmdp, CHAR_T *notusedp) +{ + return cscope_end(sp); +} + +/* + * cscope_end -- + * End all cscope connections. + * + * PUBLIC: int cscope_end __P((SCR *)); + */ +int +cscope_end(SCR *sp) { EX_PRIVATE *exp; - for (exp = EXP(sp); exp->cscq.lh_first != NULL;) - if (cscope_kill(sp, cmdp, "1")) + for (exp = EXP(sp); !SLIST_EMPTY(exp->cscq);) + if (terminate(sp, NULL, 1)) return (1); return (0); } @@ -937,22 +985,20 @@ cscope_reset(sp, cmdp, notusedp) * PUBLIC: int cscope_display __P((SCR *)); */ int -cscope_display(sp) - SCR *sp; +cscope_display(SCR *sp) { EX_PRIVATE *exp; CSC *csc; - int i; + int i = 0; exp = EXP(sp); - if (exp->cscq.lh_first == NULL) { + if (SLIST_EMPTY(exp->cscq)) { ex_printf(sp, "No cscope connections.\n"); return (0); } - for (i = 1, - csc = exp->cscq.lh_first; csc != NULL; ++i, csc = csc->q.le_next) - ex_printf(sp, - "%2d %s (process %lu)\n", i, csc->dname, (u_long)csc->pid); + SLIST_FOREACH(csc, exp->cscq, q) + ex_printf(sp, "%2d %s (process %lu)\n", + ++i, csc->dname, (u_long)csc->pid); return (0); } @@ -963,10 +1009,7 @@ cscope_display(sp) * PUBLIC: int cscope_search __P((SCR *, TAGQ *, TAG *)); */ int -cscope_search(sp, tqp, tp) - SCR *sp; - TAGQ *tqp; - TAG *tp; +cscope_search(SCR *sp, TAGQ *tqp, TAG *tp) { MARK m; @@ -1015,8 +1058,7 @@ cscope_search(sp, tqp, tp) * Return a pointer to the command structure. */ static CC const * -lookup_ccmd(name) - char *name; +lookup_ccmd(char *name) { CC const *ccp; size_t len; @@ -1033,9 +1075,7 @@ lookup_ccmd(name) * Read a prompt from cscope. */ static int -read_prompt(sp, csc) - SCR *sp; - CSC *csc; +read_prompt(SCR *sp, CSC *csc) { int ch; diff --git a/contrib/nvi/ex/ex_def.h b/contrib/nvi/ex/ex_def.h new file mode 100644 index 0000000..7afb7b1 --- /dev/null +++ b/contrib/nvi/ex/ex_def.h @@ -0,0 +1,76 @@ +#define C_SCROLL 0 +#define C_BANG 1 +#define C_HASH 2 +#define C_SUBAGAIN 3 +#define C_STAR 4 +#define C_SHIFTL 5 +#define C_EQUAL 6 +#define C_SHIFTR 7 +#define C_AT 8 +#define C_APPEND 9 +#define C_ABBR 10 +#define C_ARGS 11 +#define C_BG 12 +#define C_CHANGE 13 +#define C_CD 14 +#define C_CHDIR 15 +#define C_COPY 16 +#define C_CSCOPE 17 +#define C_DELETE 18 +#define C_DISPLAY 19 +#define C_EDIT 20 +#define C_EX 21 +#define C_EXUSAGE 22 +#define C_FILE 23 +#define C_FG 24 +#define C_GLOBAL 25 +#define C_HELP 26 +#define C_INSERT 27 +#define C_JOIN 28 +#define C_K 29 +#define C_LIST 30 +#define C_MOVE 31 +#define C_MARK 32 +#define C_MAP 33 +#define C_MKEXRC 34 +#define C_NEXT 35 +#define C_NUMBER 36 +#define C_OPEN 37 +#define C_PRINT 38 +#define C_PRESERVE 39 +#define C_PREVIOUS 40 +#define C_PUT 41 +#define C_QUIT 42 +#define C_READ 43 +#define C_RECOVER 44 +#define C_RESIZE 45 +#define C_REWIND 46 +#define C_SUBSTITUTE 47 +#define C_SCRIPT 48 +#define C_SET 49 +#define C_SHELL 50 +#define C_SOURCE 51 +#define C_STOP 52 +#define C_SUSPEND 53 +#define C_T 54 +#define C_TAG 55 +#define C_TAGNEXT 56 +#define C_TAGPOP 57 +#define C_TAGPREV 58 +#define C_TAGTOP 59 +#define C_UNDO 60 +#define C_UNABBREVIATE 61 +#define C_UNMAP 62 +#define C_V 63 +#define C_VERSION 64 +#define C_VISUAL_EX 65 +#define C_VISUAL_VI 66 +#define C_VIUSAGE 67 +#define C_VSPLIT 68 +#define C_WRITE 69 +#define C_WN 70 +#define C_WQ 71 +#define C_XIT 72 +#define C_YANK 73 +#define C_Z 74 +#define C_SUBTILDE 75 diff --git a/contrib/nvi/ex/ex_delete.c b/contrib/nvi/ex/ex_delete.c index 58734bb..34bbee4 100644 --- a/contrib/nvi/ex/ex_delete.c +++ b/contrib/nvi/ex/ex_delete.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_delete.c 10.9 (Berkeley) 10/23/96"; +static const char sccsid[] = "$Id: ex_delete.c,v 10.11 2001/06/25 15:19:15 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -30,9 +31,7 @@ static const char sccsid[] = "@(#)ex_delete.c 10.9 (Berkeley) 10/23/96"; * PUBLIC: int ex_delete __P((SCR *, EXCMD *)); */ int -ex_delete(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_delete(SCR *sp, EXCMD *cmdp) { recno_t lno; diff --git a/contrib/nvi/ex/ex_display.c b/contrib/nvi/ex/ex_display.c index 7531517..6142a44 100644 --- a/contrib/nvi/ex/ex_display.c +++ b/contrib/nvi/ex/ex_display.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_display.c 10.12 (Berkeley) 4/10/96"; +static const char sccsid[] = "$Id: ex_display.c,v 10.15 2001/06/25 15:19:15 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -25,8 +26,9 @@ static const char sccsid[] = "@(#)ex_display.c 10.12 (Berkeley) 4/10/96"; #include "../common/common.h" #include "tag.h" +static int is_prefix __P((ARGS *, CHAR_T *)); static int bdisplay __P((SCR *)); -static void db __P((SCR *, CB *, CHAR_T *)); +static void db __P((SCR *, CB *, const char *)); /* * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags] @@ -36,37 +38,27 @@ static void db __P((SCR *, CB *, CHAR_T *)); * PUBLIC: int ex_display __P((SCR *, EXCMD *)); */ int -ex_display(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_display(SCR *sp, EXCMD *cmdp) { - switch (cmdp->argv[0]->bp[0]) { + ARGS *arg; + + arg = cmdp->argv[0]; + + switch (arg->bp[0]) { case 'b': -#undef ARG -#define ARG "buffers" - if (cmdp->argv[0]->len >= sizeof(ARG) || - memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) + if (!is_prefix(arg, L("buffers"))) break; return (bdisplay(sp)); case 'c': -#undef ARG -#define ARG "connections" - if (cmdp->argv[0]->len >= sizeof(ARG) || - memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) + if (!is_prefix(arg, L("connections"))) break; return (cscope_display(sp)); case 's': -#undef ARG -#define ARG "screens" - if (cmdp->argv[0]->len >= sizeof(ARG) || - memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) + if (!is_prefix(arg, L("screens"))) break; return (ex_sdisplay(sp)); case 't': -#undef ARG -#define ARG "tags" - if (cmdp->argv[0]->len >= sizeof(ARG) || - memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) + if (!is_prefix(arg, L("tags"))) break; return (ex_tag_display(sp)); } @@ -75,35 +67,45 @@ ex_display(sp, cmdp) } /* + * is_prefix -- + * + * Check that a command argument matches a prefix of a given string. + */ +static int +is_prefix(ARGS *arg, CHAR_T *str) +{ + return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len); +} + +/* * bdisplay -- * * Display buffers. */ static int -bdisplay(sp) - SCR *sp; +bdisplay(SCR *sp) { CB *cbp; - if (sp->gp->cutq.lh_first == NULL && sp->gp->dcbp == NULL) { + if (SLIST_EMPTY(sp->gp->cutq) && sp->gp->dcbp == NULL) { msgq(sp, M_INFO, "123|No cut buffers to display"); return (0); } /* Display regular cut buffers. */ - for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { + SLIST_FOREACH(cbp, sp->gp->cutq, q) { if (isdigit(cbp->name)) continue; - if (cbp->textq.cqh_first != (void *)&cbp->textq) + if (!TAILQ_EMPTY(cbp->textq)) db(sp, cbp, NULL); if (INTERRUPTED(sp)) return (0); } /* Display numbered buffers. */ - for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { + SLIST_FOREACH(cbp, sp->gp->cutq, q) { if (!isdigit(cbp->name)) continue; - if (cbp->textq.cqh_first != (void *)&cbp->textq) + if (!TAILQ_EMPTY(cbp->textq)) db(sp, cbp, NULL); if (INTERRUPTED(sp)) return (0); @@ -119,10 +121,7 @@ bdisplay(sp) * Display a buffer. */ static void -db(sp, cbp, name) - SCR *sp; - CB *cbp; - CHAR_T *name; +db(SCR *sp, CB *cbp, const char *name) { CHAR_T *p; GS *gp; @@ -133,8 +132,7 @@ db(sp, cbp, name) (void)ex_printf(sp, "********** %s%s\n", name == NULL ? KEY_NAME(sp, cbp->name) : name, F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)"); - for (tp = cbp->textq.cqh_first; - tp != (void *)&cbp->textq; tp = tp->q.cqe_next) { + TAILQ_FOREACH(tp, cbp->textq, q) { for (len = tp->len, p = tp->lb; len--; ++p) { (void)ex_puts(sp, KEY_NAME(sp, *p)); if (INTERRUPTED(sp)) diff --git a/contrib/nvi/ex/ex_edit.c b/contrib/nvi/ex/ex_edit.c index 8b18e0f..ce0f9a4 100644 --- a/contrib/nvi/ex/ex_edit.c +++ b/contrib/nvi/ex/ex_edit.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_edit.c 10.10 (Berkeley) 4/27/96"; +static const char sccsid[] = "$Id: ex_edit.c,v 10.15 2011/12/22 23:26:50 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -46,12 +46,12 @@ static int ex_N_edit __P((SCR *, EXCMD *, FREF *, int)); * PUBLIC: int ex_edit __P((SCR *, EXCMD *)); */ int -ex_edit(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_edit(SCR *sp, EXCMD *cmdp) { FREF *frp; int attach, setalt; + char *np; + size_t nlen; switch (cmdp->argc) { case 0: @@ -72,17 +72,19 @@ ex_edit(sp, cmdp) setalt = 0; break; case 1: - if ((frp = file_add(sp, cmdp->argv[0]->bp)) == NULL) + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, + np, nlen); + if ((frp = file_add(sp, np)) == NULL) return (1); attach = 0; setalt = 1; - set_alt_name(sp, cmdp->argv[0]->bp); + set_alt_name(sp, np); break; default: abort(); } - if (F_ISSET(cmdp, E_NEWSCREEN)) + if (F_ISSET(cmdp, E_NEWSCREEN) || cmdp->cmd == &cmds[C_VSPLIT]) return (ex_N_edit(sp, cmdp, frp, attach)); /* @@ -108,18 +110,15 @@ ex_edit(sp, cmdp) * New screen version of ex_edit. */ static int -ex_N_edit(sp, cmdp, frp, attach) - SCR *sp; - EXCMD *cmdp; - FREF *frp; - int attach; +ex_N_edit(SCR *sp, EXCMD *cmdp, FREF *frp, int attach) { SCR *new; /* Get a new screen. */ if (screen_init(sp->gp, sp, &new)) return (1); - if (vs_split(sp, new, 0)) { + if ((cmdp->cmd == &cmds[C_VSPLIT] && vs_vsplit(sp, new)) || + (cmdp->cmd != &cmds[C_VSPLIT] && vs_split(sp, new, 0))) { (void)screen_end(new); return (1); } @@ -135,6 +134,13 @@ ex_N_edit(sp, cmdp, frp, attach) new->lno = sp->lno; new->cno = sp->cno; + +#if defined(USE_WIDECHAR) && defined(USE_ICONV) + /* Synchronize the iconv environments. */ + o_set(new, O_FILEENCODING, OS_STRDUP, + O_STR(sp, O_FILEENCODING), 0); + conv_enc(new, O_FILEENCODING, 0); +#endif } else if (file_init(new, frp, NULL, (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0))) { (void)vs_discard(new, NULL); diff --git a/contrib/nvi/ex/ex_equal.c b/contrib/nvi/ex/ex_equal.c index 565df66..7da5a20 100644 --- a/contrib/nvi/ex/ex_equal.c +++ b/contrib/nvi/ex/ex_equal.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_equal.c 10.10 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_equal.c,v 10.12 2001/06/25 15:19:15 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -28,9 +29,7 @@ static const char sccsid[] = "@(#)ex_equal.c 10.10 (Berkeley) 3/6/96"; * PUBLIC: int ex_equal __P((SCR *, EXCMD *)); */ int -ex_equal(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_equal(SCR *sp, EXCMD *cmdp) { recno_t lno; diff --git a/contrib/nvi/ex/ex_file.c b/contrib/nvi/ex/ex_file.c index 3492f9c..12714a3 100644 --- a/contrib/nvi/ex/ex_file.c +++ b/contrib/nvi/ex/ex_file.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_file.c 10.12 (Berkeley) 7/12/96"; +static const char sccsid[] = "$Id: ex_file.c,v 10.14 2001/06/25 15:19:16 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <errno.h> @@ -32,12 +33,12 @@ static const char sccsid[] = "@(#)ex_file.c 10.12 (Berkeley) 7/12/96"; * PUBLIC: int ex_file __P((SCR *, EXCMD *)); */ int -ex_file(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_file(SCR *sp, EXCMD *cmdp) { - CHAR_T *p; + char *p; FREF *frp; + char *np; + size_t nlen; NEEDFILE(sp, cmdp); @@ -48,8 +49,9 @@ ex_file(sp, cmdp) frp = sp->frp; /* Make sure can allocate enough space. */ - if ((p = v_strdup(sp, - cmdp->argv[0]->bp, cmdp->argv[0]->len)) == NULL) + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, + np, nlen); + if ((p = v_strdup(sp, np, nlen - 1)) == NULL) return (1); /* If already have a file name, it becomes the alternate. */ diff --git a/contrib/nvi/ex/ex_filter.c b/contrib/nvi/ex/ex_filter.c index 2e86e58..9af9a7c 100644 --- a/contrib/nvi/ex/ex_filter.c +++ b/contrib/nvi/ex/ex_filter.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_filter.c 10.34 (Berkeley) 10/23/96"; +static const char sccsid[] = "$Id: ex_filter.c,v 10.44 2003/11/05 17:11:54 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -36,21 +36,18 @@ static int filter_ldisplay __P((SCR *, FILE *)); * the utility. * * PUBLIC: int ex_filter __P((SCR *, - * PUBLIC: EXCMD *, MARK *, MARK *, MARK *, char *, enum filtertype)); + * PUBLIC: EXCMD *, MARK *, MARK *, MARK *, CHAR_T *, enum filtertype)); */ int -ex_filter(sp, cmdp, fm, tm, rp, cmd, ftype) - SCR *sp; - EXCMD *cmdp; - MARK *fm, *tm, *rp; - char *cmd; - enum filtertype ftype; +ex_filter(SCR *sp, EXCMD *cmdp, MARK *fm, MARK *tm, MARK *rp, CHAR_T *cmd, enum filtertype ftype) { FILE *ifp, *ofp; pid_t parent_writer_pid, utility_pid; recno_t nread; int input[2], output[2], rval; char *name; + char *np; + size_t nlen; rval = 0; @@ -141,7 +138,8 @@ err: if (input[0] != -1) else ++name; - execl(O_STR(sp, O_SHELL), name, "-c", cmd, NULL); + INT2CHAR(sp, cmd, STRLEN(cmd)+1, np, nlen); + execl(O_STR(sp, O_SHELL), name, "-c", np, (char *)NULL); msgq_str(sp, M_SYSERR, O_STR(sp, O_SHELL), "execl: %s"); _exit (127); /* NOTREACHED */ @@ -285,7 +283,8 @@ err: if (input[0] != -1) * Ignore errors on vi file reads, to make reads prettier. It's * completely inconsistent, and historic practice. */ -uwait: return (proc_wait(sp, (long)utility_pid, cmd, +uwait: INT2CHAR(sp, cmd, STRLEN(cmd) + 1, np, nlen); + return (proc_wait(sp, (long)utility_pid, np, ftype == FILTER_READ && F_ISSET(sp, SC_VI) ? 1 : 0, 0) || rval); } @@ -298,17 +297,19 @@ uwait: return (proc_wait(sp, (long)utility_pid, cmd, * We use the ex print routines to make sure they're printable. */ static int -filter_ldisplay(sp, fp) - SCR *sp; - FILE *fp; +filter_ldisplay(SCR *sp, FILE *fp) { size_t len; + size_t wlen; + CHAR_T *wp; EX_PRIVATE *exp; - for (exp = EXP(sp); !ex_getline(sp, fp, &len) && !INTERRUPTED(sp);) - if (ex_ldisplay(sp, exp->ibp, len, 0, 0)) + for (exp = EXP(sp); !ex_getline(sp, fp, &len) && !INTERRUPTED(sp);) { + FILE2INT5(sp, exp->ibcw, exp->ibp, len, wp, wlen); + if (ex_ldisplay(sp, wp, wlen, 0, 0)) break; + } if (ferror(fp)) msgq(sp, M_SYSERR, "filter read"); (void)fclose(fp); diff --git a/contrib/nvi/ex/ex_global.c b/contrib/nvi/ex/ex_global.c index aba9dc5..5dbbb07 100644 --- a/contrib/nvi/ex/ex_global.c +++ b/contrib/nvi/ex/ex_global.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_global.c 10.22 (Berkeley) 10/10/96"; +static const char sccsid[] = "$Id: ex_global.c,v 10.32 2011/12/26 23:37:01 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -38,9 +39,7 @@ static int ex_g_setup __P((SCR *, EXCMD *, enum which)); * PUBLIC: int ex_global __P((SCR *, EXCMD *)); */ int -ex_global(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_global(SCR *sp, EXCMD *cmdp) { return (ex_g_setup(sp, cmdp, FL_ISSET(cmdp->iflags, E_C_FORCE) ? V : GLOBAL)); @@ -53,9 +52,7 @@ ex_global(sp, cmdp) * PUBLIC: int ex_v __P((SCR *, EXCMD *)); */ int -ex_v(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_v(SCR *sp, EXCMD *cmdp) { return (ex_g_setup(sp, cmdp, V)); } @@ -65,10 +62,7 @@ ex_v(sp, cmdp) * Ex global and v commands. */ static int -ex_g_setup(sp, cmdp, cmd) - SCR *sp; - EXCMD *cmdp; - enum which cmd; +ex_g_setup(SCR *sp, EXCMD *cmdp, enum which cmd) { CHAR_T *ptrn, *p, *t; EXCMD *ecp; @@ -80,14 +74,13 @@ ex_g_setup(sp, cmdp, cmd) regmatch_t match[1]; size_t len; int cnt, delim, eval; - char *dbp; + CHAR_T *dbp; NEEDFILE(sp, cmdp); if (F_ISSET(sp, SC_EX_GLOBAL)) { - msgq(sp, M_ERR, - "124|The %s command can't be used as part of a global or v command", - cmdp->cmd->name); + msgq_wstr(sp, M_ERR, cmdp->cmd->name, + "124|The %s command can't be used as part of a global or v command"); return (1); } @@ -97,8 +90,8 @@ ex_g_setup(sp, cmdp, cmd) */ if (cmdp->argc == 0) goto usage; - for (p = cmdp->argv[0]->bp; isblank(*p); ++p); - if (*p == '\0' || isalnum(*p) || + for (p = cmdp->argv[0]->bp; cmdskip(*p); ++p); + if (!isascii(*p) || *p == '\0' || isalnum(*p) || *p == '\\' || *p == '|' || *p == '\n') { usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); return (1); @@ -139,13 +132,14 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); } /* Re-compile the RE if necessary. */ - if (!F_ISSET(sp, SC_RE_SEARCH) && re_compile(sp, - sp->re, sp->re_len, NULL, NULL, &sp->re_c, RE_C_SEARCH)) + if (!F_ISSET(sp, SC_RE_SEARCH) && + re_compile(sp, sp->re, sp->re_len, + NULL, NULL, &sp->re_c, RE_C_SEARCH)) return (1); } else { /* Compile the RE. */ - if (re_compile(sp, ptrn, t - ptrn, - &sp->re, &sp->re_len, &sp->re_c, RE_C_SEARCH)) + if (re_compile(sp, ptrn, t - ptrn, &sp->re, + &sp->re_len, &sp->re_c, RE_C_SEARCH)) return (1); /* @@ -164,7 +158,7 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); /* Get an EXCMD structure. */ CALLOC_RET(sp, ecp, EXCMD *, 1, sizeof(EXCMD)); - CIRCLEQ_INIT(&ecp->rq); + TAILQ_INIT(ecp->rq); /* * Get a copy of the command string; the default command is print. @@ -174,17 +168,17 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); * parsing it. */ if ((len = cmdp->argv[0]->len - (p - cmdp->argv[0]->bp)) == 0) { - p = "pp"; + p = L("p"); len = 1; } - MALLOC_RET(sp, ecp->cp, char *, len * 2); + MALLOC_RET(sp, ecp->cp, CHAR_T *, (len * 2) * sizeof(CHAR_T)); ecp->o_cp = ecp->cp; ecp->o_clen = len; - memcpy(ecp->cp + len, p, len); + MEMCPY(ecp->cp + len, p, len); ecp->range_lno = OOBLNO; FL_SET(ecp->agv_flags, cmd == GLOBAL ? AGV_GLOBAL : AGV_V); - LIST_INSERT_HEAD(&sp->gp->ecq, ecp, q); + SLIST_INSERT_HEAD(sp->gp->ecq, ecp, q); /* * For each line... The semantics of global matching are that we first @@ -204,7 +198,7 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); end = cmdp->addr2.lno; start <= end; ++start) { if (cnt-- == 0) { if (INTERRUPTED(sp)) { - LIST_REMOVE(ecp, q); + SLIST_REMOVE_HEAD(sp->gp->ecq, q); free(ecp->cp); free(ecp); break; @@ -233,7 +227,7 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); } /* If follows the last entry, extend the last entry's range. */ - if ((rp = ecp->rq.cqh_last) != (void *)&ecp->rq && + if ((rp = TAILQ_LAST(ecp->rq, _rh)) != NULL && rp->stop == start - 1) { ++rp->stop; continue; @@ -244,7 +238,7 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); if (rp == NULL) return (1); rp->start = rp->stop = start; - CIRCLEQ_INSERT_TAIL(&ecp->rq, rp, q); + TAILQ_INSERT_TAIL(ecp->rq, rp, q); } search_busy(sp, BUSY_OFF); return (0); @@ -257,10 +251,7 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); * PUBLIC: int ex_g_insdel __P((SCR *, lnop_t, recno_t)); */ int -ex_g_insdel(sp, op, lno) - SCR *sp; - lnop_t op; - recno_t lno; +ex_g_insdel(SCR *sp, lnop_t op, recno_t lno) { EXCMD *ecp; RANGE *nrp, *rp; @@ -272,12 +263,10 @@ ex_g_insdel(sp, op, lno) if (op == LINE_RESET) return (0); - for (ecp = sp->gp->ecq.lh_first; ecp != NULL; ecp = ecp->q.le_next) { + SLIST_FOREACH(ecp, sp->gp->ecq, q) { if (!FL_ISSET(ecp->agv_flags, AGV_AT | AGV_GLOBAL | AGV_V)) continue; - for (rp = ecp->rq.cqh_first; rp != (void *)&ecp->rq; rp = nrp) { - nrp = rp->q.cqe_next; - + TAILQ_FOREACH_SAFE(rp, ecp->rq, q, nrp) { /* If range less than the line, ignore it. */ if (rp->stop < lno) continue; @@ -305,7 +294,7 @@ ex_g_insdel(sp, op, lno) */ if (op == LINE_DELETE) { if (rp->start > --rp->stop) { - CIRCLEQ_REMOVE(&ecp->rq, rp, q); + TAILQ_REMOVE(ecp->rq, rp, q); free(rp); } } else { @@ -313,8 +302,7 @@ ex_g_insdel(sp, op, lno) nrp->start = lno + 1; nrp->stop = rp->stop + 1; rp->stop = lno - 1; - CIRCLEQ_INSERT_AFTER(&ecp->rq, rp, nrp, q); - rp = nrp; + TAILQ_INSERT_AFTER(ecp->rq, rp, nrp, q); } } diff --git a/contrib/nvi/ex/ex_init.c b/contrib/nvi/ex/ex_init.c index 6a78416..5b93e5b 100644 --- a/contrib/nvi/ex/ex_init.c +++ b/contrib/nvi/ex/ex_init.c @@ -10,11 +10,10 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_init.c 10.26 (Berkeley) 8/12/96"; +static const char sccsid[] = "$Id: ex_init.c,v 10.33 2012/04/11 19:12:34 zy Exp $"; #endif /* not lint */ -#include <sys/param.h> -#include <sys/types.h> /* XXX: param.h may not have included types.h */ +#include <sys/types.h> #include <sys/queue.h> #include <sys/stat.h> @@ -42,8 +41,7 @@ static int ex_run_file __P((SCR *, char *)); * PUBLIC: int ex_screen_copy __P((SCR *, SCR *)); */ int -ex_screen_copy(orig, sp) - SCR *orig, *sp; +ex_screen_copy(SCR *orig, SCR *sp) { EX_PRIVATE *oexp, *nexp; @@ -52,16 +50,17 @@ ex_screen_copy(orig, sp) sp->ex_private = nexp; /* Initialize queues. */ - CIRCLEQ_INIT(&nexp->tq); - TAILQ_INIT(&nexp->tagfq); - LIST_INIT(&nexp->cscq); + TAILQ_INIT(nexp->tq); + TAILQ_INIT(nexp->tagfq); + SLIST_INIT(nexp->cscq); if (orig == NULL) { } else { oexp = EXP(orig); if (oexp->lastbcomm != NULL && - (nexp->lastbcomm = strdup(oexp->lastbcomm)) == NULL) { + (nexp->lastbcomm = v_wstrdup(sp, oexp->lastbcomm, + STRLEN(oexp->lastbcomm))) == NULL) { msgq(sp, M_SYSERR, NULL); return(1); } @@ -78,8 +77,7 @@ ex_screen_copy(orig, sp) * PUBLIC: int ex_screen_end __P((SCR *)); */ int -ex_screen_end(sp) - SCR *sp; +ex_screen_end(SCR *sp) { EX_PRIVATE *exp; int rval; @@ -102,9 +100,15 @@ ex_screen_end(sp) if (exp->lastbcomm != NULL) free(exp->lastbcomm); + if (exp->ibcw.bp1.c != NULL) + free(exp->ibcw.bp1.c); + if (ex_tag_free(sp)) rval = 1; + if (cscope_end(sp)) + rval = 1; + /* Free private memory. */ free(exp); sp->ex_private = NULL; @@ -119,11 +123,7 @@ ex_screen_end(sp) * PUBLIC: int ex_optchange __P((SCR *, int, char *, u_long *)); */ int -ex_optchange(sp, offset, str, valp) - SCR *sp; - int offset; - char *str; - u_long *valp; +ex_optchange(SCR *sp, int offset, char *str, u_long *valp) { switch (offset) { case O_TAGS: @@ -140,11 +140,12 @@ ex_optchange(sp, offset, str, valp) * PUBLIC: int ex_exrc __P((SCR *)); */ int -ex_exrc(sp) - SCR *sp; +ex_exrc(SCR *sp) { struct stat hsb, lsb; - char *p, path[MAXPATHLEN]; + char *p, *path; + CHAR_T *wp; + size_t wlen; /* * Source the system, environment, $HOME and local .exrc values. @@ -187,28 +188,41 @@ ex_exrc(sp) return (0); if ((p = getenv("NEXINIT")) != NULL) { - if (ex_run_str(sp, "NEXINIT", p, strlen(p), 1, 0)) + CHAR2INT(sp, p, strlen(p) + 1, wp, wlen); + if (ex_run_str(sp, "NEXINIT", wp, wlen - 1, 1, 0)) return (1); } else if ((p = getenv("EXINIT")) != NULL) { - if (ex_run_str(sp, "EXINIT", p, strlen(p), 1, 0)) + CHAR2INT(sp, p, strlen(p) + 1, wp, wlen); + if (ex_run_str(sp, "EXINIT", wp, wlen - 1, 1, 0)) return (1); } else if ((p = getenv("HOME")) != NULL && *p) { - (void)snprintf(path, sizeof(path), "%s/%s", p, _PATH_NEXRC); + int st = 0; + + if ((path = join(p, _PATH_NEXRC)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } switch (exrc_isok(sp, &hsb, path, 0, 1)) { case NOEXIST: - (void)snprintf(path, - sizeof(path), "%s/%s", p, _PATH_EXRC); + free(path); + if ((path = join(p, _PATH_EXRC)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } if (exrc_isok(sp, &hsb, path, 0, 1) == RCOK && ex_run_file(sp, path)) - return (1); + st = 1; break; case NOPERM: break; case RCOK: if (ex_run_file(sp, path)) - return (1); + st = 1; break; } + free(path); + if (st) + return st; } /* Run the commands. */ @@ -251,15 +265,15 @@ ex_exrc(sp) * Set up a file of ex commands to run. */ static int -ex_run_file(sp, name) - SCR *sp; - char *name; +ex_run_file(SCR *sp, char *name) { - ARGS *ap[2], a; EXCMD cmd; + CHAR_T *wp; + size_t wlen; - ex_cinit(&cmd, C_SOURCE, 0, OOBLNO, OOBLNO, 0, ap); - ex_cadd(&cmd, &a, name, strlen(name)); + ex_cinit(sp, &cmd, C_SOURCE, 0, OOBLNO, OOBLNO, 0); + CHAR2INT(sp, name, strlen(name)+1, wp, wlen); + argv_exp0(sp, &cmd, wp, wlen - 1); return (ex_source(sp, &cmd)); } @@ -267,14 +281,10 @@ ex_run_file(sp, name) * ex_run_str -- * Set up a string of ex commands to run. * - * PUBLIC: int ex_run_str __P((SCR *, char *, char *, size_t, int, int)); + * PUBLIC: int ex_run_str __P((SCR *, char *, CHAR_T *, size_t, int, int)); */ int -ex_run_str(sp, name, str, len, ex_flags, nocopy) - SCR *sp; - char *name, *str; - size_t len; - int ex_flags, nocopy; +ex_run_str(SCR *sp, char *name, CHAR_T *str, size_t len, int ex_flags, int nocopy) { GS *gp; EXCMD *ecp; @@ -282,7 +292,7 @@ ex_run_str(sp, name, str, len, ex_flags, nocopy) gp = sp->gp; if (EXCMD_RUNNING(gp)) { CALLOC_RET(sp, ecp, EXCMD *, 1, sizeof(EXCMD)); - LIST_INSERT_HEAD(&gp->ecq, ecp, q); + SLIST_INSERT_HEAD(gp->ecq, ecp, q); } else ecp = &gp->excmd; @@ -292,7 +302,7 @@ ex_run_str(sp, name, str, len, ex_flags, nocopy) if (nocopy) ecp->cp = str; else - if ((ecp->cp = v_strdup(sp, str, len)) == NULL) + if ((ecp->cp = v_wstrdup(sp, str, len)) == NULL) return (1); ecp->clen = len; @@ -345,16 +355,12 @@ ex_run_str(sp, name, str, len, ex_flags, nocopy) * files. */ static enum rc -exrc_isok(sp, sbp, path, rootown, rootid) - SCR *sp; - struct stat *sbp; - char *path; - int rootown, rootid; +exrc_isok(SCR *sp, struct stat *sbp, char *path, int rootown, int rootid) { enum { ROOTOWN, OWN, WRITER } etype; uid_t euid; int nf1, nf2; - char *a, *b, buf[MAXPATHLEN]; + char *a, *b, *buf; /* Check for the file's existence. */ if (stat(path, sbp)) @@ -376,23 +382,30 @@ exrc_isok(sp, sbp, path, rootown, rootid) return (RCOK); denied: a = msg_print(sp, path, &nf1); - if (strchr(path, '/') == NULL && getcwd(buf, sizeof(buf)) != NULL) { + if (strchr(path, '/') == NULL && (buf = getcwd(NULL, 0)) != NULL) { + char *p; + b = msg_print(sp, buf, &nf2); + if ((p = join(b, a)) == NULL) { + msgq(sp, M_SYSERR, NULL); + goto err; + } switch (etype) { case ROOTOWN: msgq(sp, M_ERR, - "125|%s/%s: not sourced: not owned by you or root", - b, a); + "128|%s: not sourced: not owned by you or root", p); break; case OWN: msgq(sp, M_ERR, - "126|%s/%s: not sourced: not owned by you", b, a); + "129|%s: not sourced: not owned by you", p); break; case WRITER: msgq(sp, M_ERR, - "127|%s/%s: not sourced: writeable by a user other than the owner", b, a); + "130|%s: not sourced: writeable by a user other than the owner", p); break; } + free(p); +err: free(buf); if (nf2) FREE_SPACE(sp, b, 0); } else diff --git a/contrib/nvi/ex/ex_join.c b/contrib/nvi/ex/ex_join.c index c26c424..822ed79 100644 --- a/contrib/nvi/ex/ex_join.c +++ b/contrib/nvi/ex/ex_join.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_join.c 10.10 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_join.c,v 10.17 2004/03/16 14:14:04 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -32,14 +33,13 @@ static const char sccsid[] = "@(#)ex_join.c 10.10 (Berkeley) 9/15/96"; * PUBLIC: int ex_join __P((SCR *, EXCMD *)); */ int -ex_join(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_join(SCR *sp, EXCMD *cmdp) { recno_t from, to; size_t blen, clen, len, tlen; - int echar, extra, first; - char *bp, *p, *tbp; + int echar = 0, extra, first; + CHAR_T *bp, *tbp = NULL; + CHAR_T *p; NEEDFILE(sp, cmdp); @@ -52,20 +52,13 @@ ex_join(sp, cmdp) return (1); } - GET_SPACE_RET(sp, bp, blen, 256); + GET_SPACE_RETW(sp, bp, blen, 256); /* * The count for the join command was off-by-one, * historically, to other counts for other commands. */ - if (FL_ISSET(cmdp->iflags, E_C_COUNT)) - ++cmdp->addr2.lno; - - /* - * If only a single address specified, or, the same address - * specified twice, the from/two addresses will be the same. - */ - if (cmdp->addr1.lno == cmdp->addr2.lno) + if (F_ISSET(cmdp, E_ADDR_DEF) || cmdp->addrcnt == 1) ++cmdp->addr2.lno; clen = tlen = 0; @@ -90,7 +83,7 @@ ex_join(sp, cmdp) * tbp - bp is the length of the new line. */ tlen += len + 2; - ADD_SPACE_RET(sp, bp, blen, tlen); + ADD_SPACE_RETW(sp, bp, blen, tlen); tbp = bp + clen; /* @@ -114,7 +107,7 @@ ex_join(sp, cmdp) if (isblank(echar)) for (; len && isblank(*p); --len, ++p); else if (p[0] != ')') { - if (strchr(".?!", echar)) { + if (STRCHR(L(".?!"), echar)) { *tbp++ = ' '; ++clen; extra = 1; @@ -126,7 +119,7 @@ ex_join(sp, cmdp) } if (len != 0) { - memcpy(tbp, p, len); + MEMCPY(tbp, p, len); tbp += len; clen += len; echar = p[len - 1]; @@ -167,10 +160,10 @@ ex_join(sp, cmdp) /* If the original line changed, reset it. */ if (!first && db_set(sp, from, bp, tbp - bp)) { -err: FREE_SPACE(sp, bp, blen); +err: FREE_SPACEW(sp, bp, blen); return (1); } - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); sp->rptlines[L_JOINED] += (cmdp->addr2.lno - cmdp->addr1.lno) + 1; return (0); diff --git a/contrib/nvi/ex/ex_map.c b/contrib/nvi/ex/ex_map.c index bc2cf08..60dbfe0 100644 --- a/contrib/nvi/ex/ex_map.c +++ b/contrib/nvi/ex/ex_map.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_map.c 10.9 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_map.c,v 10.11 2001/06/25 15:19:17 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -42,9 +43,7 @@ static const char sccsid[] = "@(#)ex_map.c 10.9 (Berkeley) 3/6/96"; * PUBLIC: int ex_map __P((SCR *, EXCMD *)); */ int -ex_map(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_map(SCR *sp, EXCMD *cmdp) { seq_t stype; CHAR_T *input, *p; @@ -107,13 +106,11 @@ nofunc: if (stype == SEQ_COMMAND && input[1] == '\0') * PUBLIC: int ex_unmap __P((SCR *, EXCMD *)); */ int -ex_unmap(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_unmap(SCR *sp, EXCMD *cmdp) { if (seq_delete(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len, FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) { - msgq_str(sp, M_INFO, + msgq_wstr(sp, M_INFO, cmdp->argv[0]->bp, "135|\"%s\" isn't currently mapped"); return (1); } diff --git a/contrib/nvi/ex/ex_mark.c b/contrib/nvi/ex/ex_mark.c index 08ad8c2..8c8ec34 100644 --- a/contrib/nvi/ex/ex_mark.c +++ b/contrib/nvi/ex/ex_mark.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_mark.c 10.8 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_mark.c,v 10.9 2001/06/25 15:19:17 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -31,9 +32,7 @@ static const char sccsid[] = "@(#)ex_mark.c 10.8 (Berkeley) 3/6/96"; * PUBLIC: int ex_mark __P((SCR *, EXCMD *)); */ int -ex_mark(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_mark(SCR *sp, EXCMD *cmdp) { NEEDFILE(sp, cmdp); diff --git a/contrib/nvi/ex/ex_mkexrc.c b/contrib/nvi/ex/ex_mkexrc.c index 0eb15d4..8753014 100644 --- a/contrib/nvi/ex/ex_mkexrc.c +++ b/contrib/nvi/ex/ex_mkexrc.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_mkexrc.c 10.11 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_mkexrc.c,v 10.13 2001/06/25 15:19:17 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -37,21 +37,21 @@ static const char sccsid[] = "@(#)ex_mkexrc.c 10.11 (Berkeley) 3/6/96"; * PUBLIC: int ex_mkexrc __P((SCR *, EXCMD *)); */ int -ex_mkexrc(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_mkexrc(SCR *sp, EXCMD *cmdp) { struct stat sb; FILE *fp; int fd, sverrno; char *fname; + size_t flen; switch (cmdp->argc) { case 0: fname = _PATH_EXRC; break; case 1: - fname = cmdp->argv[0]->bp; + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, + fname, flen); set_alt_name(sp, fname); break; default: diff --git a/contrib/nvi/ex/ex_move.c b/contrib/nvi/ex/ex_move.c index d6e45c3..c2499fd 100644 --- a/contrib/nvi/ex/ex_move.c +++ b/contrib/nvi/ex/ex_move.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_move.c 10.10 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_move.c,v 10.16 2012/02/11 15:52:33 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -31,11 +32,9 @@ static const char sccsid[] = "@(#)ex_move.c 10.10 (Berkeley) 9/15/96"; * PUBLIC: int ex_copy __P((SCR *, EXCMD *)); */ int -ex_copy(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_copy(SCR *sp, EXCMD *cmdp) { - CB cb; + CB cb = {{ 0 }}; MARK fm1, fm2, m, tm; recno_t cnt; int rval; @@ -51,10 +50,9 @@ ex_copy(sp, cmdp) */ fm1 = cmdp->addr1; fm2 = cmdp->addr2; - memset(&cb, 0, sizeof(cb)); - CIRCLEQ_INIT(&cb.textq); + TAILQ_INIT(cb.textq); for (cnt = fm1.lno; cnt <= fm2.lno; ++cnt) - if (cut_line(sp, cnt, 0, 0, &cb)) { + if (cut_line(sp, cnt, 0, ENTIRE_LINE, &cb)) { rval = 1; goto err; } @@ -75,7 +73,7 @@ ex_copy(sp, cmdp) sp->lno = m.lno + (cnt - 1); sp->cno = 0; } -err: text_lfree(&cb.textq); +err: text_lfree(cb.textq); return (rval); } @@ -86,16 +84,15 @@ err: text_lfree(&cb.textq); * PUBLIC: int ex_move __P((SCR *, EXCMD *)); */ int -ex_move(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_move(SCR *sp, EXCMD *cmdp) { LMARK *lmp; MARK fm1, fm2; recno_t cnt, diff, fl, tl, mfl, mtl; size_t blen, len; int mark_reset; - char *bp, *p; + CHAR_T *bp; + CHAR_T *p; NEEDFILE(sp, cmdp); @@ -126,7 +123,7 @@ ex_move(sp, cmdp) /* Log the old positions of the marks. */ mark_reset = 0; - for (lmp = sp->ep->marks.lh_first; lmp != NULL; lmp = lmp->q.le_next) + SLIST_FOREACH(lmp, sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno >= fl && lmp->lno <= tl) { mark_reset = 1; @@ -135,7 +132,7 @@ ex_move(sp, cmdp) } /* Get memory for the copy. */ - GET_SPACE_RET(sp, bp, blen, 256); + GET_SPACE_RETW(sp, bp, blen, 256); /* Move the lines. */ diff = (fm2.lno - fm1.lno) + 1; @@ -145,13 +142,12 @@ ex_move(sp, cmdp) for (cnt = diff; cnt--;) { if (db_get(sp, fl, DBG_FATAL, &p, &len)) return (1); - BINC_RET(sp, bp, blen, len); - memcpy(bp, p, len); + BINC_RETW(sp, bp, blen, len); + MEMCPY(bp, p, len); if (db_append(sp, 1, tl, bp, len)) return (1); if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + SLIST_FOREACH(lmp, sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno == fl) lmp->lno = tl + 1; @@ -164,13 +160,12 @@ ex_move(sp, cmdp) for (cnt = diff; cnt--;) { if (db_get(sp, fl, DBG_FATAL, &p, &len)) return (1); - BINC_RET(sp, bp, blen, len); - memcpy(bp, p, len); + BINC_RETW(sp, bp, blen, len); + MEMCPY(bp, p, len); if (db_append(sp, 1, tl++, bp, len)) return (1); if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + SLIST_FOREACH(lmp, sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno == fl) lmp->lno = tl; @@ -179,15 +174,14 @@ ex_move(sp, cmdp) return (1); } } - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); sp->lno = tl; /* Last line moved. */ sp->cno = 0; /* Log the new positions of the marks. */ if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + SLIST_FOREACH(lmp, sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno >= mfl && lmp->lno <= mtl) (void)log_mark(sp, lmp); diff --git a/contrib/nvi/ex/ex_open.c b/contrib/nvi/ex/ex_open.c index afffaeb..97414b9 100644 --- a/contrib/nvi/ex/ex_open.c +++ b/contrib/nvi/ex/ex_open.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_open.c 10.7 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_open.c,v 10.8 2001/06/25 15:19:17 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -30,9 +31,7 @@ static const char sccsid[] = "@(#)ex_open.c 10.7 (Berkeley) 3/6/96"; * PUBLIC: int ex_open __P((SCR *, EXCMD *)); */ int -ex_open(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_open(SCR *sp, EXCMD *cmdp) { /* If open option off, disallow open command. */ if (!O_ISSET(sp, O_OPEN)) { diff --git a/contrib/nvi/ex/ex_perl.c b/contrib/nvi/ex/ex_perl.c deleted file mode 100644 index e620352..0000000 --- a/contrib/nvi/ex/ex_perl.c +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * Copyright (c) 1992, 1993, 1994, 1995, 1996 - * Keith Bostic. All rights reserved. - * Copyright (c) 1995 - * George V. Neville-Neil. All rights reserved. - * Copyright (c) 1996 - * Sven Verdoolaege. All rights reserved. - * - * See the LICENSE file for redistribution information. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)ex_perl.c 8.10 (Berkeley) 9/15/96"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/queue.h> -#include <sys/time.h> - -#include <bitstring.h> -#include <ctype.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> -#include <termios.h> -#include <unistd.h> - -#include "../common/common.h" - -/* - * ex_perl -- :[line [,line]] perl [command] - * Run a command through the perl interpreter. - * - * ex_perldo -- :[line [,line]] perldo [command] - * Run a set of lines through the perl interpreter. - * - * PUBLIC: int ex_perl __P((SCR*, EXCMD *)); - */ -int -ex_perl(sp, cmdp) - SCR *sp; - EXCMD *cmdp; -{ -#ifdef HAVE_PERL_INTERP - CHAR_T *p; - size_t len; - - /* Skip leading white space. */ - if (cmdp->argc != 0) - for (p = cmdp->argv[0]->bp, - len = cmdp->argv[0]->len; len > 0; --len, ++p) - if (!isblank(*p)) - break; - if (cmdp->argc == 0 || len == 0) { - ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); - return (1); - } - return (cmdp->cmd == &cmds[C_PERLCMD] ? - perl_ex_perl(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno) : - perl_ex_perldo(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno)); -#else - msgq(sp, M_ERR, "306|Vi was not loaded with a Perl interpreter"); - return (1); -#endif -} diff --git a/contrib/nvi/ex/ex_preserve.c b/contrib/nvi/ex/ex_preserve.c index 5614c88..bda4bb4 100644 --- a/contrib/nvi/ex/ex_preserve.c +++ b/contrib/nvi/ex/ex_preserve.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_preserve.c 10.12 (Berkeley) 4/27/96"; +static const char sccsid[] = "$Id: ex_preserve.c,v 10.15 2001/06/25 15:19:18 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <errno.h> @@ -31,9 +32,7 @@ static const char sccsid[] = "@(#)ex_preserve.c 10.12 (Berkeley) 4/27/96"; * PUBLIC: int ex_preserve __P((SCR *, EXCMD *)); */ int -ex_preserve(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_preserve(SCR *sp, EXCMD *cmdp) { recno_t lno; @@ -67,17 +66,18 @@ ex_preserve(sp, cmdp) * PUBLIC: int ex_recover __P((SCR *, EXCMD *)); */ int -ex_recover(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_recover(SCR *sp, EXCMD *cmdp) { ARGS *ap; FREF *frp; + char *np; + size_t nlen; ap = cmdp->argv[0]; /* Set the alternate file name. */ - set_alt_name(sp, ap->bp); + INT2CHAR(sp, ap->bp, ap->len+1, np, nlen); + set_alt_name(sp, np); /* * Check for modifications. Autowrite did not historically @@ -87,7 +87,8 @@ ex_recover(sp, cmdp) return (1); /* Get a file structure for the file. */ - if ((frp = file_add(sp, ap->bp)) == NULL) + INT2CHAR(sp, ap->bp, ap->len+1, np, nlen); + if ((frp = file_add(sp, np)) == NULL) return (1); /* Set the recover bit. */ diff --git a/contrib/nvi/ex/ex_print.c b/contrib/nvi/ex/ex_print.c index 1cc2500..2c9208a 100644 --- a/contrib/nvi/ex/ex_print.c +++ b/contrib/nvi/ex/ex_print.c @@ -10,27 +10,24 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_print.c 10.18 (Berkeley) 5/12/96"; +static const char sccsid[] = "$Id: ex_print.c,v 10.25 2011/12/12 22:12:20 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> #include <limits.h> +#include <stdarg.h> #include <stdio.h> #include <string.h> -#ifdef __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - #include "../common/common.h" -static int ex_prchars __P((SCR *, const char *, size_t *, size_t, u_int, int)); +static int ex_prchars __P((SCR *, const CHAR_T *, size_t *, size_t, + u_int, int)); /* * ex_list -- :[line [,line]] l[ist] [count] [flags] @@ -40,9 +37,7 @@ static int ex_prchars __P((SCR *, const char *, size_t *, size_t, u_int, int)); * PUBLIC: int ex_list __P((SCR *, EXCMD *)); */ int -ex_list(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_list(SCR *sp, EXCMD *cmdp) { if (ex_print(sp, cmdp, &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_LIST)) @@ -60,9 +55,7 @@ ex_list(sp, cmdp) * PUBLIC: int ex_number __P((SCR *, EXCMD *)); */ int -ex_number(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_number(SCR *sp, EXCMD *cmdp) { if (ex_print(sp, cmdp, &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_HASH)) @@ -80,9 +73,7 @@ ex_number(sp, cmdp) * PUBLIC: int ex_pr __P((SCR *, EXCMD *)); */ int -ex_pr(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_pr(SCR *sp, EXCMD *cmdp) { if (ex_print(sp, cmdp, &cmdp->addr1, &cmdp->addr2, cmdp->iflags)) return (1); @@ -98,16 +89,13 @@ ex_pr(sp, cmdp) * PUBLIC: int ex_print __P((SCR *, EXCMD *, MARK *, MARK *, u_int32_t)); */ int -ex_print(sp, cmdp, fp, tp, flags) - SCR *sp; - EXCMD *cmdp; - MARK *fp, *tp; - u_int32_t flags; +ex_print(SCR *sp, EXCMD *cmdp, MARK *fp, MARK *tp, u_int32_t flags) { GS *gp; recno_t from, to; size_t col, len; - char *p, buf[10]; + CHAR_T *p; + CHAR_T buf[10]; NEEDFILE(sp, cmdp); @@ -122,11 +110,10 @@ ex_print(sp, cmdp, fp, tp, flags) */ if (LF_ISSET(E_C_HASH)) { if (from <= 999999) { - snprintf(buf, sizeof(buf), "%6lu ", - (u_long)from); + SPRINTF(buf, SIZE(buf), L("%6u "), from); p = buf; } else - p = "TOOBIG "; + p = L("TOOBIG "); if (ex_prchars(sp, p, &col, 8, 0, 0)) return (1); } @@ -154,19 +141,15 @@ ex_print(sp, cmdp, fp, tp, flags) * ex_ldisplay -- * Display a line without any preceding number. * - * PUBLIC: int ex_ldisplay __P((SCR *, const char *, size_t, size_t, u_int)); + * PUBLIC: int ex_ldisplay __P((SCR *, const CHAR_T *, size_t, size_t, u_int)); */ int -ex_ldisplay(sp, p, len, col, flags) - SCR *sp; - const char *p; - size_t len, col; - u_int flags; +ex_ldisplay(SCR *sp, const CHAR_T *p, size_t len, size_t col, u_int flags) { if (len > 0 && ex_prchars(sp, p, &col, len, LF_ISSET(E_C_LIST), 0)) return (1); if (!INTERRUPTED(sp) && LF_ISSET(E_C_LIST)) { - p = "$"; + p = L("$"); if (ex_prchars(sp, p, &col, 1, LF_ISSET(E_C_LIST), 0)) return (1); } @@ -182,21 +165,19 @@ ex_ldisplay(sp, p, len, col, flags) * PUBLIC: int ex_scprint __P((SCR *, MARK *, MARK *)); */ int -ex_scprint(sp, fp, tp) - SCR *sp; - MARK *fp, *tp; +ex_scprint(SCR *sp, MARK *fp, MARK *tp) { - const char *p; + CHAR_T *p; size_t col, len; col = 0; if (O_ISSET(sp, O_NUMBER)) { - p = " "; + p = L(" "); if (ex_prchars(sp, p, &col, 8, 0, 0)) return (1); } - if (db_get(sp, fp->lno, DBG_FATAL, (char **)&p, &len)) + if (db_get(sp, fp->lno, DBG_FATAL, &p, &len)) return (1); if (ex_prchars(sp, p, &col, fp->cno, 0, ' ')) @@ -207,7 +188,7 @@ ex_scprint(sp, fp, tp) return (1); if (INTERRUPTED(sp)) return (1); - p = "[ynq]"; /* XXX: should be msg_cat. */ + p = L("[ynq]"); /* XXX: should be msg_cat. */ if (ex_prchars(sp, p, &col, 5, 0, 0)) return (1); (void)ex_fflush(sp); @@ -219,14 +200,11 @@ ex_scprint(sp, fp, tp) * Local routine to dump characters to the screen. */ static int -ex_prchars(sp, p, colp, len, flags, repeatc) - SCR *sp; - const char *p; - size_t *colp, len; - u_int flags; - int repeatc; +ex_prchars(SCR *sp, const CHAR_T *p, size_t *colp, size_t len, + u_int flags, int repeatc) { - CHAR_T ch, *kp; + CHAR_T ch; + char *kp; GS *gp; size_t col, tlen, ts; @@ -272,14 +250,10 @@ intr: *colp = col; * PUBLIC: int ex_printf __P((SCR *, const char *, ...)); */ int -#ifdef __STDC__ -ex_printf(SCR *sp, const char *fmt, ...) -#else -ex_printf(sp, fmt, va_alist) - SCR *sp; - const char *fmt; - va_dcl -#endif +ex_printf( + SCR *sp, + const char *fmt, + ...) { EX_PRIVATE *exp; va_list ap; @@ -287,11 +261,7 @@ ex_printf(sp, fmt, va_alist) exp = EXP(sp); -#ifdef __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif exp->obp_len += n = vsnprintf(exp->obp + exp->obp_len, sizeof(exp->obp) - exp->obp_len, fmt, ap); va_end(ap); @@ -310,9 +280,7 @@ ex_printf(sp, fmt, va_alist) * PUBLIC: int ex_puts __P((SCR *, const char *)); */ int -ex_puts(sp, str) - SCR *sp; - const char *str; +ex_puts(SCR *sp, const char *str) { EX_PRIVATE *exp; int doflush, n; @@ -338,8 +306,7 @@ ex_puts(sp, str) * PUBLIC: int ex_fflush __P((SCR *sp)); */ int -ex_fflush(sp) - SCR *sp; +ex_fflush(SCR *sp) { EX_PRIVATE *exp; diff --git a/contrib/nvi/ex/ex_put.c b/contrib/nvi/ex/ex_put.c index 2facb03..7a3996b 100644 --- a/contrib/nvi/ex/ex_put.c +++ b/contrib/nvi/ex/ex_put.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_put.c 10.7 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_put.c,v 10.8 2001/06/25 15:19:18 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -31,9 +32,7 @@ static const char sccsid[] = "@(#)ex_put.c 10.7 (Berkeley) 3/6/96"; * PUBLIC: int ex_put __P((SCR *, EXCMD *)); */ int -ex_put(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_put(SCR *sp, EXCMD *cmdp) { MARK m; diff --git a/contrib/nvi/ex/ex_quit.c b/contrib/nvi/ex/ex_quit.c index 705fa1a..2cfaeb1 100644 --- a/contrib/nvi/ex/ex_quit.c +++ b/contrib/nvi/ex/ex_quit.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_quit.c 10.7 (Berkeley) 4/27/96"; +static const char sccsid[] = "$Id: ex_quit.c,v 10.8 2001/06/25 15:19:18 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -29,9 +30,7 @@ static const char sccsid[] = "@(#)ex_quit.c 10.7 (Berkeley) 4/27/96"; * PUBLIC: int ex_quit __P((SCR *, EXCMD *)); */ int -ex_quit(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_quit(SCR *sp, EXCMD *cmdp) { int force; diff --git a/contrib/nvi/ex/ex_read.c b/contrib/nvi/ex/ex_read.c index 78296ff..187f090 100644 --- a/contrib/nvi/ex/ex_read.c +++ b/contrib/nvi/ex/ex_read.c @@ -10,13 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_read.c 10.38 (Berkeley) 8/12/96"; +static const char sccsid[] = "$Id: ex_read.c,v 10.44 2001/06/25 15:19:19 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> #include <sys/stat.h> -#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -40,20 +39,20 @@ static const char sccsid[] = "@(#)ex_read.c 10.38 (Berkeley) 8/12/96"; * PUBLIC: int ex_read __P((SCR *, EXCMD *)); */ int -ex_read(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_read(SCR *sp, EXCMD *cmdp) { enum { R_ARG, R_EXPANDARG, R_FILTER } which; struct stat sb; - CHAR_T *arg, *name; + CHAR_T *arg = NULL; + char *name = NULL; + size_t nlen; EX_PRIVATE *exp; FILE *fp; FREF *frp; GS *gp; MARK rm; recno_t nlines; - size_t arglen; + size_t arglen = 0; int argc, rval; char *p; @@ -77,7 +76,7 @@ ex_read(sp, cmdp) /* Secure means no shell access. */ if (O_ISSET(sp, O_SECURE)) { - ex_emsg(sp, cmdp->cmd->name, EXM_SECURE_F); + ex_wemsg(sp, cmdp->cmd->name, EXM_SECURE_F); return (1); } } else @@ -116,7 +115,8 @@ ex_read(sp, cmdp) if (exp->lastbcomm != NULL) free(exp->lastbcomm); if ((exp->lastbcomm = - strdup(cmdp->argv[argc]->bp)) == NULL) { + v_wstrdup(sp, cmdp->argv[argc]->bp, + cmdp->argv[argc]->len)) == NULL) { msgq(sp, M_SYSERR, NULL); return (1); } @@ -132,7 +132,7 @@ ex_read(sp, cmdp) } else { if (F_ISSET(cmdp, E_MODIFY)) (void)ex_printf(sp, - "!%s\n", cmdp->argv[argc]->bp); + "!"WS"\n", cmdp->argv[argc]->bp); else (void)ex_puts(sp, "!\n"); (void)ex_fflush(sp); @@ -157,7 +157,7 @@ ex_read(sp, cmdp) */ if (F_ISSET(sp, SC_VI)) { if (gp->scr_screen(sp, SC_EX)) { - ex_emsg(sp, cmdp->cmd->name, EXM_NOCANON_F); + ex_wemsg(sp, cmdp->cmd->name, EXM_NOCANON_F); return (1); } /* @@ -207,7 +207,8 @@ ex_read(sp, cmdp) abort(); /* NOTREACHED */ case 2: - name = cmdp->argv[1]->bp; + INT2CHAR(sp, cmdp->argv[1]->bp, cmdp->argv[1]->len + 1, + name, nlen); /* * !!! * Historically, the read and write commands renamed @@ -216,8 +217,7 @@ ex_read(sp, cmdp) */ if (F_ISSET(sp->frp, FR_TMPFILE) && !F_ISSET(sp->frp, FR_EXNAMED)) { - if ((p = v_strdup(sp, cmdp->argv[1]->bp, - cmdp->argv[1]->len)) != NULL) { + if ((p = strdup(name)) != NULL) { free(sp->frp->name); sp->frp->name = p; } @@ -230,11 +230,14 @@ ex_read(sp, cmdp) /* Notify the screen. */ (void)sp->gp->scr_rename(sp, sp->frp->name, 1); - } else + name = sp->frp->name; + } else { set_alt_name(sp, name); + name = sp->alt_name; + } break; default: - ex_emsg(sp, cmdp->argv[0]->bp, EXM_FILECOUNT); + ex_wemsg(sp, cmdp->argv[0]->bp, EXM_FILECOUNT); return (1); } @@ -261,7 +264,7 @@ ex_read(sp, cmdp) } /* Try and get a lock. */ - if (file_lock(sp, NULL, NULL, fileno(fp), 0) == LOCK_UNAVAIL) + if (file_lock(sp, NULL, fileno(fp), 0) == LOCK_UNAVAIL) msgq(sp, M_ERR, "146|%s: read lock was unavailable", name); rval = ex_readfp(sp, name, fp, &cmdp->addr1, &nlines, 0); @@ -291,13 +294,7 @@ ex_read(sp, cmdp) * PUBLIC: int ex_readfp __P((SCR *, char *, FILE *, MARK *, recno_t *, int)); */ int -ex_readfp(sp, name, fp, fm, nlinesp, silent) - SCR *sp; - char *name; - FILE *fp; - MARK *fm; - recno_t *nlinesp; - int silent; +ex_readfp(SCR *sp, char *name, FILE *fp, MARK *fm, recno_t *nlinesp, int silent) { EX_PRIVATE *exp; GS *gp; @@ -306,6 +303,8 @@ ex_readfp(sp, name, fp, fm, nlinesp, silent) u_long ccnt; /* XXX: can't print off_t portably. */ int nf, rval; char *p; + size_t wlen; + CHAR_T *wp; gp = sp->gp; exp = EXP(sp); @@ -327,7 +326,8 @@ ex_readfp(sp, name, fp, fm, nlinesp, silent) p = NULL; } } - if (db_append(sp, 1, lno, exp->ibp, len)) + FILE2INT5(sp, exp->ibcw, exp->ibp, len, wp, wlen); + if (db_append(sp, 1, lno, wp, wlen)) goto err; ccnt += len; } @@ -342,7 +342,8 @@ ex_readfp(sp, name, fp, fm, nlinesp, silent) if (!silent) { p = msg_print(sp, name, &nf); msgq(sp, M_INFO, - "148|%s: %lu lines, %lu characters", p, lcnt, ccnt); + "148|%s: %lu lines, %lu characters", p, + (u_long)lcnt, ccnt); if (nf) FREE_SPACE(sp, p, 0); } diff --git a/contrib/nvi/ex/ex_screen.c b/contrib/nvi/ex/ex_screen.c index 9bc5bf0..9cb108f9 100644 --- a/contrib/nvi/ex/ex_screen.c +++ b/contrib/nvi/ex/ex_screen.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_screen.c 10.11 (Berkeley) 6/29/96"; +static const char sccsid[] = "$Id: ex_screen.c,v 10.12 2001/06/25 15:19:19 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -33,9 +33,7 @@ static const char sccsid[] = "@(#)ex_screen.c 10.11 (Berkeley) 6/29/96"; * PUBLIC: int ex_bg __P((SCR *, EXCMD *)); */ int -ex_bg(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_bg(SCR *sp, EXCMD *cmdp) { return (vs_bg(sp)); } @@ -47,9 +45,7 @@ ex_bg(sp, cmdp) * PUBLIC: int ex_fg __P((SCR *, EXCMD *)); */ int -ex_fg(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_fg(SCR *sp, EXCMD *cmdp) { SCR *nsp; int newscreen; @@ -73,9 +69,7 @@ ex_fg(sp, cmdp) * PUBLIC: int ex_resize __P((SCR *, EXCMD *)); */ int -ex_resize(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_resize(SCR *sp, EXCMD *cmdp) { adj_t adj; @@ -104,22 +98,21 @@ ex_resize(sp, cmdp) * PUBLIC: int ex_sdisplay __P((SCR *)); */ int -ex_sdisplay(sp) - SCR *sp; +ex_sdisplay(SCR *sp) { GS *gp; SCR *tsp; int cnt, col, len, sep; gp = sp->gp; - if ((tsp = gp->hq.cqh_first) == (void *)&gp->hq) { + if ((tsp = TAILQ_FIRST(gp->hq)) == NULL) { msgq(sp, M_INFO, "149|No background screens to display"); return (0); } col = len = sep = 0; - for (cnt = 1; tsp != (void *)&gp->hq && !INTERRUPTED(sp); - tsp = tsp->q.cqe_next) { + for (cnt = 1; tsp != NULL && !INTERRUPTED(sp); + tsp = TAILQ_NEXT(tsp, q)) { col += len = strlen(tsp->frp->name) + sep; if (col >= sp->cols - 1) { col = len; diff --git a/contrib/nvi/ex/ex_script.c b/contrib/nvi/ex/ex_script.c index 9ca6d60..5ba0acf 100644 --- a/contrib/nvi/ex/ex_script.c +++ b/contrib/nvi/ex/ex_script.c @@ -13,32 +13,32 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_script.c 10.30 (Berkeley) 9/24/96"; +static const char sccsid[] = "$Id: ex_script.c,v 10.44 2012/10/05 10:17:47 zy Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/queue.h> -#ifdef HAVE_SYS_SELECT_H #include <sys/select.h> -#endif #include <sys/stat.h> -#ifdef HAVE_SYS5_PTY -#include <sys/stropts.h> -#endif -#include <sys/time.h> #include <sys/wait.h> #include <bitstring.h> #include <errno.h> #include <fcntl.h> -#include <stdio.h> /* XXX: OSF/1 bug: include before <grp.h> */ #include <grp.h> #include <limits.h> +#include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h> #include <unistd.h> +#ifdef HAVE_LIBUTIL_H +#include <libutil.h> +#else +#include <util.h> +#endif #include "../common/common.h" #include "../vi/vi.h" @@ -50,7 +50,6 @@ static int sscr_getprompt __P((SCR *)); static int sscr_init __P((SCR *)); static int sscr_insert __P((SCR *)); static int sscr_matchprompt __P((SCR *, char *, size_t, size_t *)); -static int sscr_pty __P((int *, int *, char *, struct termios *, void *)); static int sscr_setprompt __P((SCR *, char *, size_t)); /* @@ -60,9 +59,7 @@ static int sscr_setprompt __P((SCR *, char *, size_t)); * PUBLIC: int ex_script __P((SCR *, EXCMD *)); */ int -ex_script(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_script(SCR *sp, EXCMD *cmdp) { /* Vi only command. */ if (!F_ISSET(sp, SC_VI)) { @@ -87,8 +84,7 @@ ex_script(sp, cmdp) * Create a pty setup for a shell. */ static int -sscr_init(sp) - SCR *sp; +sscr_init(SCR *sp) { SCRIPT *sc; char *sh, *sh_path; @@ -119,24 +115,16 @@ sscr_init(sp) sc->sh_term.c_oflag &= ~OPOST; sc->sh_term.c_cflag &= ~(ECHO|ECHOE|ECHONL|ECHOK); -#ifdef TIOCGWINSZ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &sc->sh_win) == -1) { msgq(sp, M_SYSERR, "tcgetattr"); goto err; } - if (sscr_pty(&sc->sh_master, + if (openpty(&sc->sh_master, &sc->sh_slave, sc->sh_name, &sc->sh_term, &sc->sh_win) == -1) { - msgq(sp, M_SYSERR, "pty"); + msgq(sp, M_SYSERR, "openpty"); goto err; } -#else - if (sscr_pty(&sc->sh_master, - &sc->sh_slave, sc->sh_name, &sc->sh_term, NULL) == -1) { - msgq(sp, M_SYSERR, "pty"); - goto err; - } -#endif /* * __TK__ huh? @@ -203,17 +191,20 @@ err: if (sc->sh_master != -1) * carriage return comes; set the prompt from that line. */ static int -sscr_getprompt(sp) - SCR *sp; +sscr_getprompt(SCR *sp) { + EX_PRIVATE *exp; struct timeval tv; - CHAR_T *endp, *p, *t, buf[1024]; + char *endp, *p, *t, buf[1024]; SCRIPT *sc; fd_set fdset; recno_t lline; size_t llen, len; - u_int value; int nr; + CHAR_T *wp; + size_t wlen; + + exp = EXP(sp); FD_ZERO(&fdset); endp = buf; @@ -251,10 +242,11 @@ more: len = sizeof(buf) - (endp - buf); /* If any complete lines, push them into the file. */ for (p = t = buf; p < endp; ++p) { - value = KEY_VAL(sp, *p); - if (value == K_CR || value == K_NL) { + if (*p == '\r' || *p == '\n') { + if (CHAR2INT5(sp, exp->ibcw, t, p - t, wp, wlen)) + goto conv_err; if (db_last(sp, &lline) || - db_append(sp, 0, lline, t, p - t)) + db_append(sp, 0, lline, wp, wlen)) goto prompterr; t = p + 1; } @@ -284,7 +276,11 @@ more: len = sizeof(buf) - (endp - buf); endp = buf; /* Append the line into the file. */ - if (db_last(sp, &lline) || db_append(sp, 0, lline, buf, llen)) { + if (CHAR2INT5(sp, exp->ibcw, buf, llen, wp, wlen)) + goto conv_err; + if (db_last(sp, &lline) || db_append(sp, 0, lline, wp, wlen)) { + if (0) +conv_err: msgq(sp, M_ERR, "323|Invalid input. Truncated."); prompterr: sscr_end(sp); return (1); } @@ -299,38 +295,40 @@ prompterr: sscr_end(sp); * PUBLIC: int sscr_exec __P((SCR *, recno_t)); */ int -sscr_exec(sp, lno) - SCR *sp; - recno_t lno; +sscr_exec(SCR *sp, recno_t lno) { SCRIPT *sc; recno_t last_lno; size_t blen, len, last_len, tlen; int isempty, matchprompt, nw, rval; - char *bp, *p; + char *bp = NULL, *p; + CHAR_T *wp; + size_t wlen; /* If there's a prompt on the last line, append the command. */ if (db_last(sp, &last_lno)) return (1); - if (db_get(sp, last_lno, DBG_FATAL, &p, &last_len)) + if (db_get(sp, last_lno, DBG_FATAL, &wp, &wlen)) return (1); + INT2CHAR(sp, wp, wlen, p, last_len); if (sscr_matchprompt(sp, p, last_len, &tlen) && tlen == 0) { matchprompt = 1; - GET_SPACE_RET(sp, bp, blen, last_len + 128); + GET_SPACE_RETC(sp, bp, blen, last_len + 128); memmove(bp, p, last_len); } else matchprompt = 0; /* Get something to execute. */ - if (db_eget(sp, lno, &p, &len, &isempty)) { + if (db_eget(sp, lno, &wp, &wlen, &isempty)) { if (isempty) goto empty; goto err1; } /* Empty lines aren't interesting. */ - if (len == 0) + if (wlen == 0) goto empty; + INT2CHAR(sp, wp, wlen, p, len); /* Delete any prompt. */ if (sscr_matchprompt(sp, p, len, &tlen)) { @@ -355,9 +353,10 @@ err2: if (nw == 0) } if (matchprompt) { - ADD_SPACE_RET(sp, bp, blen, last_len + len); + ADD_SPACE_RETC(sp, bp, blen, last_len + len); memmove(bp + last_len, p, len); - if (db_set(sp, last_lno, bp, last_len + len)) + CHAR2INT(sp, bp, last_len + len, wp, wlen); + if (db_set(sp, last_lno, wp, wlen)) err1: rval = 1; } if (matchprompt) @@ -372,8 +371,7 @@ err1: rval = 1; * PUBLIC: int sscr_input __P((SCR *)); */ int -sscr_input(sp) - SCR *sp; +sscr_input(SCR *sp) { GS *gp; struct timeval poll; @@ -388,7 +386,7 @@ loop: maxfd = 0; poll.tv_usec = 0; /* Set up the input mask. */ - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + TAILQ_FOREACH(sp, gp->dq, q) if (F_ISSET(sp, SC_SCRIPT)) { FD_SET(sp->script->sh_master, &rdfd); if (sp->script->sh_master > maxfd) @@ -407,9 +405,10 @@ loop: maxfd = 0; } /* Read the input. */ - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + TAILQ_FOREACH(sp, gp->dq, q) if (F_ISSET(sp, SC_SCRIPT) && - FD_ISSET(sp->script->sh_master, &rdfd) && sscr_insert(sp)) + FD_ISSET(sp->script->sh_master, &rdfd) && + sscr_insert(sp)) return (1); goto loop; } @@ -419,25 +418,29 @@ loop: maxfd = 0; * Take a line from the shell and insert it into the file. */ static int -sscr_insert(sp) - SCR *sp; +sscr_insert(SCR *sp) { + EX_PRIVATE *exp; struct timeval tv; - CHAR_T *endp, *p, *t; + char *endp, *p, *t; SCRIPT *sc; fd_set rdfd; recno_t lno; size_t blen, len, tlen; - u_int value; int nr, rval; char *bp; + CHAR_T *wp; + size_t wlen = 0; + + exp = EXP(sp); + /* Find out where the end of the file is. */ if (db_last(sp, &lno)) return (1); #define MINREAD 1024 - GET_SPACE_RET(sp, bp, blen, MINREAD); + GET_SPACE_RETC(sp, bp, blen, MINREAD); endp = bp; /* Read the characters. */ @@ -458,10 +461,11 @@ more: switch (nr = read(sc->sh_master, endp, MINREAD)) { /* Append the lines into the file. */ for (p = t = bp; p < endp; ++p) { - value = KEY_VAL(sp, *p); - if (value == K_CR || value == K_NL) { + if (*p == '\r' || *p == '\n') { len = p - t; - if (db_append(sp, 1, lno++, t, len)) + if (CHAR2INT5(sp, exp->ibcw, t, len, wp, wlen)) + goto conv_err; + if (db_append(sp, 1, lno++, wp, wlen)) goto ret; t = p + 1; } @@ -489,15 +493,20 @@ more: switch (nr = read(sc->sh_master, endp, MINREAD)) { } if (sscr_setprompt(sp, t, len)) return (1); - if (db_append(sp, 1, lno++, t, len)) + if (CHAR2INT5(sp, exp->ibcw, t, len, wp, wlen)) + goto conv_err; + if (db_append(sp, 1, lno++, wp, wlen)) goto ret; } /* The cursor moves to EOF. */ sp->lno = lno; - sp->cno = len ? len - 1 : 0; + sp->cno = wlen ? wlen - 1 : 0; rval = vs_refresh(sp, 1); + if (0) +conv_err: msgq(sp, M_ERR, "323|Invalid input. Truncated."); + ret: FREE_SPACE(sp, bp, blen); return (rval); } @@ -509,10 +518,7 @@ ret: FREE_SPACE(sp, bp, blen); * */ static int -sscr_setprompt(sp, buf, len) - SCR *sp; - char *buf; - size_t len; +sscr_setprompt(SCR *sp, char *buf, size_t len) { SCRIPT *sc; @@ -536,10 +542,7 @@ sscr_setprompt(sp, buf, len) * parts that can change, in both content and size. */ static int -sscr_matchprompt(sp, lp, line_len, lenp) - SCR *sp; - char *lp; - size_t line_len, *lenp; +sscr_matchprompt(SCR *sp, char *lp, size_t line_len, size_t *lenp) { SCRIPT *sc; size_t prompt_len; @@ -577,8 +580,7 @@ sscr_matchprompt(sp, lp, line_len, lenp) * PUBLIC: int sscr_end __P((SCR *)); */ int -sscr_end(sp) - SCR *sp; +sscr_end(SCR *sp) { SCRIPT *sc; @@ -611,188 +613,15 @@ sscr_end(sp) * Set/clear the global scripting bit. */ static void -sscr_check(sp) - SCR *sp; +sscr_check(SCR *sp) { GS *gp; gp = sp->gp; - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + TAILQ_FOREACH(sp, gp->dq, q) if (F_ISSET(sp, SC_SCRIPT)) { F_SET(gp, G_SCRWIN); return; } F_CLR(gp, G_SCRWIN); } - -#ifdef HAVE_SYS5_PTY -static int ptys_open __P((int, char *)); -static int ptym_open __P((char *)); - -static int -sscr_pty(amaster, aslave, name, termp, winp) - int *amaster, *aslave; - char *name; - struct termios *termp; - void *winp; -{ - int master, slave, ttygid; - - /* open master terminal */ - if ((master = ptym_open(name)) < 0) { - errno = ENOENT; /* out of ptys */ - return (-1); - } - - /* open slave terminal */ - if ((slave = ptys_open(master, name)) >= 0) { - *amaster = master; - *aslave = slave; - } else { - errno = ENOENT; /* out of ptys */ - return (-1); - } - - if (termp) - (void) tcsetattr(slave, TCSAFLUSH, termp); -#ifdef TIOCSWINSZ - if (winp != NULL) - (void) ioctl(slave, TIOCSWINSZ, (struct winsize *)winp); -#endif - return (0); -} - -/* - * ptym_open -- - * This function opens a master pty and returns the file descriptor - * to it. pts_name is also returned which is the name of the slave. - */ -static int -ptym_open(pts_name) - char *pts_name; -{ - int fdm; - char *ptr, *ptsname(); - - strcpy(pts_name, _PATH_SYSV_PTY); - if ((fdm = open(pts_name, O_RDWR)) < 0 ) - return (-1); - - if (grantpt(fdm) < 0) { - close(fdm); - return (-2); - } - - if (unlockpt(fdm) < 0) { - close(fdm); - return (-3); - } - - if (unlockpt(fdm) < 0) { - close(fdm); - return (-3); - } - - /* get slave's name */ - if ((ptr = ptsname(fdm)) == NULL) { - close(fdm); - return (-3); - } - strcpy(pts_name, ptr); - return (fdm); -} - -/* - * ptys_open -- - * This function opens the slave pty. - */ -static int -ptys_open(fdm, pts_name) - int fdm; - char *pts_name; -{ - int fds; - - if ((fds = open(pts_name, O_RDWR)) < 0) { - close(fdm); - return (-5); - } - - if (ioctl(fds, I_PUSH, "ptem") < 0) { - close(fds); - close(fdm); - return (-6); - } - - if (ioctl(fds, I_PUSH, "ldterm") < 0) { - close(fds); - close(fdm); - return (-7); - } - - if (ioctl(fds, I_PUSH, "ttcompat") < 0) { - close(fds); - close(fdm); - return (-8); - } - - return (fds); -} - -#else /* !HAVE_SYS5_PTY */ - -static int -sscr_pty(amaster, aslave, name, termp, winp) - int *amaster, *aslave; - char *name; - struct termios *termp; - void *winp; -{ - static char line[] = "/dev/ptyXX"; - register char *cp1, *cp2; - register int master, slave, ttygid; - struct group *gr; - - if ((gr = getgrnam("tty")) != NULL) - ttygid = gr->gr_gid; - else - ttygid = -1; - - for (cp1 = "pqrs"; *cp1; cp1++) { - line[8] = *cp1; - for (cp2 = "0123456789abcdef"; *cp2; cp2++) { - line[5] = 'p'; - line[9] = *cp2; - if ((master = open(line, O_RDWR, 0)) == -1) { - if (errno == ENOENT) - return (-1); /* out of ptys */ - } else { - line[5] = 't'; - (void) chown(line, getuid(), ttygid); - (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); -#ifdef HAVE_REVOKE - (void) revoke(line); -#endif - if ((slave = open(line, O_RDWR, 0)) != -1) { - *amaster = master; - *aslave = slave; - if (name) - strcpy(name, line); - if (termp) - (void) tcsetattr(slave, - TCSAFLUSH, termp); -#ifdef TIOCSWINSZ - if (winp) - (void) ioctl(slave, TIOCSWINSZ, - (char *)winp); -#endif - return (0); - } - (void) close(master); - } - } - } - errno = ENOENT; /* out of ptys */ - return (-1); -} -#endif /* HAVE_SYS5_PTY */ diff --git a/contrib/nvi/ex/ex_set.c b/contrib/nvi/ex/ex_set.c index 11e9297..5134bab 100644 --- a/contrib/nvi/ex/ex_set.c +++ b/contrib/nvi/ex/ex_set.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_set.c 10.7 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_set.c,v 10.8 2001/06/25 15:19:19 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -29,9 +30,7 @@ static const char sccsid[] = "@(#)ex_set.c 10.7 (Berkeley) 3/6/96"; * PUBLIC: int ex_set __P((SCR *, EXCMD *)); */ int -ex_set(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_set(SCR *sp, EXCMD *cmdp) { switch(cmdp->argc) { case 0: diff --git a/contrib/nvi/ex/ex_shell.c b/contrib/nvi/ex/ex_shell.c index 9516803..d127305 100644 --- a/contrib/nvi/ex/ex_shell.c +++ b/contrib/nvi/ex/ex_shell.c @@ -10,14 +10,15 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_shell.c 10.38 (Berkeley) 8/19/96"; +static const char sccsid[] = "$Id: ex_shell.c,v 10.44 2012/07/06 06:51:26 zy Exp $"; #endif /* not lint */ -#include <sys/param.h> #include <sys/queue.h> +#include <sys/time.h> #include <sys/wait.h> #include <bitstring.h> +#include <ctype.h> #include <errno.h> #include <limits.h> #include <signal.h> @@ -38,12 +39,10 @@ static const char *sigmsg __P((int)); * PUBLIC: int ex_shell __P((SCR *, EXCMD *)); */ int -ex_shell(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_shell(SCR *sp, EXCMD *cmdp) { int rval; - char buf[MAXPATHLEN]; + char *buf; /* We'll need a shell. */ if (opts_empty(sp, O_SHELL, 0)) @@ -53,13 +52,18 @@ ex_shell(sp, cmdp) * XXX * Assumes all shells use -i. */ - (void)snprintf(buf, sizeof(buf), "%s -i", O_STR(sp, O_SHELL)); + (void)asprintf(&buf, "%s -i", O_STR(sp, O_SHELL)); + if (buf == NULL) { + msgq(sp, M_SYSERR, NULL); + return (1); + } /* Restore the window name. */ (void)sp->gp->scr_rename(sp, NULL, 0); /* If we're still in a vi screen, move out explicitly. */ rval = ex_exec_proc(sp, cmdp, buf, NULL, !F_ISSET(sp, SC_SCR_EXWROTE)); + free(buf); /* Set the window name. */ (void)sp->gp->scr_rename(sp, sp->frp->name, 1); @@ -81,12 +85,7 @@ ex_shell(sp, cmdp) * PUBLIC: int ex_exec_proc __P((SCR *, EXCMD *, char *, const char *, int)); */ int -ex_exec_proc(sp, cmdp, cmd, msg, need_newline) - SCR *sp; - EXCMD *cmdp; - char *cmd; - const char *msg; - int need_newline; +ex_exec_proc(SCR *sp, EXCMD *cmdp, char *cmd, const char *msg, int need_newline) { GS *gp; const char *name; @@ -101,7 +100,7 @@ ex_exec_proc(sp, cmdp, cmd, msg, need_newline) /* Enter ex mode. */ if (F_ISSET(sp, SC_VI)) { if (gp->scr_screen(sp, SC_EX)) { - ex_emsg(sp, cmdp->cmd->name, EXM_NOCANON); + ex_wemsg(sp, cmdp->cmd->name, EXM_NOCANON); return (1); } (void)gp->scr_attr(sp, SA_ALTERNATE, 0); @@ -122,11 +121,13 @@ ex_exec_proc(sp, cmdp, cmd, msg, need_newline) msgq(sp, M_SYSERR, "vfork"); return (1); case 0: /* Utility. */ + if (gp->scr_child) + gp->scr_child(sp); if ((name = strrchr(O_STR(sp, O_SHELL), '/')) == NULL) name = O_STR(sp, O_SHELL); else ++name; - execl(O_STR(sp, O_SHELL), name, "-c", cmd, NULL); + execl(O_STR(sp, O_SHELL), name, "-c", cmd, (char *)NULL); msgq_str(sp, M_SYSERR, O_STR(sp, O_SHELL), "execl: %s"); _exit(127); /* NOTREACHED */ @@ -149,11 +150,7 @@ ex_exec_proc(sp, cmdp, cmd, msg, need_newline) * PUBLIC: int proc_wait __P((SCR *, long, const char *, int, int)); */ int -proc_wait(sp, pid, cmd, silent, okpipe) - SCR *sp; - long pid; - const char *cmd; - int silent, okpipe; +proc_wait(SCR *sp, long int pid, const char *cmd, int silent, int okpipe) { size_t len; int nf, pstat; @@ -176,11 +173,11 @@ proc_wait(sp, pid, cmd, silent, okpipe) * exit before reading all of its input. */ if (WIFSIGNALED(pstat) && (!okpipe || WTERMSIG(pstat) != SIGPIPE)) { - for (; isblank(*cmd); ++cmd); + for (; cmdskip(*cmd); ++cmd); p = msg_print(sp, cmd, &nf); len = strlen(p); msgq(sp, M_ERR, "%.*s%s: received signal: %s%s", - MIN(len, 20), p, len > 20 ? " ..." : "", + (int)MIN(len, 20), p, len > 20 ? " ..." : "", sigmsg(WTERMSIG(pstat)), WCOREDUMP(pstat) ? "; core dumped" : ""); if (nf) @@ -198,11 +195,11 @@ proc_wait(sp, pid, cmd, silent, okpipe) * practice. */ if (!silent) { - for (; isblank(*cmd); ++cmd); + for (; cmdskip(*cmd); ++cmd); p = msg_print(sp, cmd, &nf); len = strlen(p); msgq(sp, M_ERR, "%.*s%s: exited with status %d", - MIN(len, 20), p, len > 20 ? " ..." : "", + (int)MIN(len, 20), p, len > 20 ? " ..." : "", WEXITSTATUS(pstat)); if (nf) FREE_SPACE(sp, p, 0); @@ -213,166 +210,18 @@ proc_wait(sp, pid, cmd, silent, okpipe) } /* - * XXX - * The sys_siglist[] table in the C library has this information, but there's - * no portable way to get to it. (Believe me, I tried.) - */ -typedef struct _sigs { - int number; /* signal number */ - char *message; /* related message */ -} SIGS; - -SIGS const sigs[] = { -#ifdef SIGABRT - SIGABRT, "Abort trap", -#endif -#ifdef SIGALRM - SIGALRM, "Alarm clock", -#endif -#ifdef SIGBUS - SIGBUS, "Bus error", -#endif -#ifdef SIGCLD - SIGCLD, "Child exited or stopped", -#endif -#ifdef SIGCHLD - SIGCHLD, "Child exited", -#endif -#ifdef SIGCONT - SIGCONT, "Continued", -#endif -#ifdef SIGDANGER - SIGDANGER, "System crash imminent", -#endif -#ifdef SIGEMT - SIGEMT, "EMT trap", -#endif -#ifdef SIGFPE - SIGFPE, "Floating point exception", -#endif -#ifdef SIGGRANT - SIGGRANT, "HFT monitor mode granted", -#endif -#ifdef SIGHUP - SIGHUP, "Hangup", -#endif -#ifdef SIGILL - SIGILL, "Illegal instruction", -#endif -#ifdef SIGINFO - SIGINFO, "Information request", -#endif -#ifdef SIGINT - SIGINT, "Interrupt", -#endif -#ifdef SIGIO - SIGIO, "I/O possible", -#endif -#ifdef SIGIOT - SIGIOT, "IOT trap", -#endif -#ifdef SIGKILL - SIGKILL, "Killed", -#endif -#ifdef SIGLOST - SIGLOST, "Record lock", -#endif -#ifdef SIGMIGRATE - SIGMIGRATE, "Migrate process to another CPU", -#endif -#ifdef SIGMSG - SIGMSG, "HFT input data pending", -#endif -#ifdef SIGPIPE - SIGPIPE, "Broken pipe", -#endif -#ifdef SIGPOLL - SIGPOLL, "I/O possible", -#endif -#ifdef SIGPRE - SIGPRE, "Programming error", -#endif -#ifdef SIGPROF - SIGPROF, "Profiling timer expired", -#endif -#ifdef SIGPWR - SIGPWR, "Power failure imminent", -#endif -#ifdef SIGRETRACT - SIGRETRACT, "HFT monitor mode retracted", -#endif -#ifdef SIGQUIT - SIGQUIT, "Quit", -#endif -#ifdef SIGSAK - SIGSAK, "Secure Attention Key", -#endif -#ifdef SIGSEGV - SIGSEGV, "Segmentation fault", -#endif -#ifdef SIGSOUND - SIGSOUND, "HFT sound sequence completed", -#endif -#ifdef SIGSTOP - SIGSTOP, "Suspended (signal)", -#endif -#ifdef SIGSYS - SIGSYS, "Bad system call", -#endif -#ifdef SIGTERM - SIGTERM, "Terminated", -#endif -#ifdef SIGTRAP - SIGTRAP, "Trace/BPT trap", -#endif -#ifdef SIGTSTP - SIGTSTP, "Suspended", -#endif -#ifdef SIGTTIN - SIGTTIN, "Stopped (tty input)", -#endif -#ifdef SIGTTOU - SIGTTOU, "Stopped (tty output)", -#endif -#ifdef SIGURG - SIGURG, "Urgent I/O condition", -#endif -#ifdef SIGUSR1 - SIGUSR1, "User defined signal 1", -#endif -#ifdef SIGUSR2 - SIGUSR2, "User defined signal 2", -#endif -#ifdef SIGVTALRM - SIGVTALRM, "Virtual timer expired", -#endif -#ifdef SIGWINCH - SIGWINCH, "Window size changes", -#endif -#ifdef SIGXCPU - SIGXCPU, "Cputime limit exceeded", -#endif -#ifdef SIGXFSZ - SIGXFSZ, "Filesize limit exceeded", -#endif -}; - -/* * sigmsg -- * Return a pointer to a message describing a signal. */ static const char * -sigmsg(signo) - int signo; +sigmsg(int signo) { static char buf[40]; - const SIGS *sigp; - int n; + char *message; - for (n = 0, - sigp = &sigs[0]; n < sizeof(sigs) / sizeof(sigs[0]); ++n, ++sigp) - if (sigp->number == signo) - return (sigp->message); + /* POSIX.1-2008 leaves strsignal(3)'s return value unspecified. */ + if ((message = strsignal(signo)) != NULL) + return message; (void)snprintf(buf, sizeof(buf), "Unknown signal: %d", signo); return (buf); } diff --git a/contrib/nvi/ex/ex_shift.c b/contrib/nvi/ex/ex_shift.c index 83bd36d..cc6e1aa 100644 --- a/contrib/nvi/ex/ex_shift.c +++ b/contrib/nvi/ex/ex_shift.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_shift.c 10.11 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_shift.c,v 10.17 2001/06/25 15:19:20 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -34,9 +35,7 @@ static int shift __P((SCR *, EXCMD *, enum which)); * PUBLIC: int ex_shiftl __P((SCR *, EXCMD *)); */ int -ex_shiftl(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_shiftl(SCR *sp, EXCMD *cmdp) { return (shift(sp, cmdp, LEFT)); } @@ -47,9 +46,7 @@ ex_shiftl(sp, cmdp) * PUBLIC: int ex_shiftr __P((SCR *, EXCMD *)); */ int -ex_shiftr(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_shiftr(SCR *sp, EXCMD *cmdp) { return (shift(sp, cmdp, RIGHT)); } @@ -59,15 +56,13 @@ ex_shiftr(sp, cmdp) * Ex shift support. */ static int -shift(sp, cmdp, rl) - SCR *sp; - EXCMD *cmdp; - enum which rl; +shift(SCR *sp, EXCMD *cmdp, enum which rl) { recno_t from, to; size_t blen, len, newcol, newidx, oldcol, oldidx, sw; int curset; - char *p, *bp, *tbp; + CHAR_T *p; + CHAR_T *bp, *tbp; NEEDFILE(sp, cmdp); @@ -93,7 +88,7 @@ shift(sp, cmdp, rl) for (p = cmdp->argv[0]->bp, sw = 0; *p == '>' || *p == '<'; ++p) sw += O_VAL(sp, O_SHIFTWIDTH); - GET_SPACE_RET(sp, bp, blen, 256); + GET_SPACE_RETW(sp, bp, blen, 256); curset = 0; for (from = cmdp->addr1.lno, to = cmdp->addr2.lno; from <= to; ++from) { @@ -131,7 +126,7 @@ shift(sp, cmdp, rl) } /* Get a buffer that will hold the new line. */ - ADD_SPACE_RET(sp, bp, blen, newcol + len); + ADD_SPACE_RETW(sp, bp, blen, newcol + len); /* * Build a new indent string and count the number of @@ -146,11 +141,11 @@ shift(sp, cmdp, rl) *tbp++ = ' '; /* Add the original line. */ - memcpy(tbp, p + oldidx, len - oldidx); + MEMCPY(tbp, p + oldidx, len - oldidx); /* Set the replacement line. */ if (db_set(sp, from, bp, (tbp + (len - oldidx)) - bp)) { -err: FREE_SPACE(sp, bp, blen); +err: FREE_SPACEW(sp, bp, blen); return (1); } @@ -184,7 +179,7 @@ err: FREE_SPACE(sp, bp, blen); (void)nonblank(sp, to, &sp->cno); } - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); sp->rptlines[L_SHIFT] += cmdp->addr2.lno - cmdp->addr1.lno + 1; return (0); diff --git a/contrib/nvi/ex/ex_source.c b/contrib/nvi/ex/ex_source.c index b52c527..63375d2 100644 --- a/contrib/nvi/ex/ex_source.c +++ b/contrib/nvi/ex/ex_source.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_source.c 10.12 (Berkeley) 8/10/96"; +static const char sccsid[] = "$Id: ex_source.c,v 10.17 2011/12/19 16:17:06 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -35,15 +35,18 @@ static const char sccsid[] = "@(#)ex_source.c 10.12 (Berkeley) 8/10/96"; * PUBLIC: int ex_source __P((SCR *, EXCMD *)); */ int -ex_source(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_source(SCR *sp, EXCMD *cmdp) { struct stat sb; int fd, len; - char *bp, *name; + char *bp; + char *name, *np; + size_t nlen; + CHAR_T *wp; + size_t wlen; + int rc; - name = cmdp->argv[0]->bp; + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, name, nlen); if ((fd = open(name, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) goto err; @@ -80,6 +83,13 @@ err: msgq_str(sp, M_SYSERR, name, "%s"); return (1); } + np = strdup(name); + if (CHAR2INT(sp, bp, (size_t)sb.st_size + 1, wp, wlen)) + msgq(sp, M_ERR, "323|Invalid input. Truncated."); /* Put it on the ex queue. */ - return (ex_run_str(sp, name, bp, (size_t)sb.st_size, 1, 1)); + rc = ex_run_str(sp, np, wp, wlen - 1, 1, 0); + if (np != NULL) + free(np); + free(bp); + return (rc); } diff --git a/contrib/nvi/ex/ex_stop.c b/contrib/nvi/ex/ex_stop.c index bc55fd2..7916789 100644 --- a/contrib/nvi/ex/ex_stop.c +++ b/contrib/nvi/ex/ex_stop.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_stop.c 10.10 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_stop.c,v 10.11 2001/06/25 15:19:20 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <errno.h> @@ -33,9 +34,7 @@ static const char sccsid[] = "@(#)ex_stop.c 10.10 (Berkeley) 3/6/96"; * PUBLIC: int ex_stop __P((SCR *, EXCMD *)); */ int -ex_stop(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_stop(SCR *sp, EXCMD *cmdp) { int allowed; diff --git a/contrib/nvi/ex/ex_subst.c b/contrib/nvi/ex/ex_subst.c index 0ebb81d..9339843 100644 --- a/contrib/nvi/ex/ex_subst.c +++ b/contrib/nvi/ex/ex_subst.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_subst.c 10.37 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_subst.c,v 10.53 2011/12/21 20:40:35 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -32,12 +32,12 @@ static const char sccsid[] = "@(#)ex_subst.c 10.37 (Berkeley) 9/15/96"; #define SUB_FIRST 0x01 /* The 'r' flag isn't reasonable. */ #define SUB_MUSTSETR 0x02 /* The 'r' flag is required. */ -static int re_conv __P((SCR *, char **, size_t *, int *)); -static int re_cscope_conv __P((SCR *, char **, size_t *, int *)); +static int re_conv __P((SCR *, CHAR_T **, size_t *, int *)); +static int re_cscope_conv __P((SCR *, CHAR_T **, size_t *, int *)); static int re_sub __P((SCR *, - char *, char **, size_t *, size_t *, regmatch_t [10])); -static int re_tag_conv __P((SCR *, char **, size_t *, int *)); -static int s __P((SCR *, EXCMD *, char *, regex_t *, u_int)); + CHAR_T *, CHAR_T **, size_t *, size_t *, regmatch_t [10])); +static int re_tag_conv __P((SCR *, CHAR_T **, size_t *, int *)); +static int s __P((SCR *, EXCMD *, CHAR_T *, regex_t *, u_int)); /* * ex_s -- @@ -48,15 +48,13 @@ static int s __P((SCR *, EXCMD *, char *, regex_t *, u_int)); * PUBLIC: int ex_s __P((SCR *, EXCMD *)); */ int -ex_s(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_s(SCR *sp, EXCMD *cmdp) { regex_t *re; size_t blen, len; u_int flags; int delim; - char *bp, *ptrn, *rep, *p, *t; + CHAR_T *bp, *p, *ptrn, *rep, *t; /* * Skip leading white space. @@ -73,14 +71,14 @@ ex_s(sp, cmdp) goto subagain; for (p = cmdp->argv[0]->bp, len = cmdp->argv[0]->len; len > 0; --len, ++p) { - if (!isblank(*p)) + if (!cmdskip(*p)) break; } if (len == 0) subagain: return (ex_subagain(sp, cmdp)); delim = *p++; - if (isalnum(delim) || delim == '\\') + if (!isascii(delim) || isalnum(delim) || delim == '\\') return (s(sp, cmdp, p, &sp->subre_c, SUB_MUSTSETR)); /* @@ -140,8 +138,9 @@ subagain: return (ex_subagain(sp, cmdp)); } /* Re-compile the RE if necessary. */ - if (!F_ISSET(sp, SC_RE_SEARCH) && re_compile(sp, - sp->re, sp->re_len, NULL, NULL, &sp->re_c, RE_C_SEARCH)) + if (!F_ISSET(sp, SC_RE_SEARCH) && + re_compile(sp, sp->re, sp->re_len, + NULL, NULL, &sp->re_c, RE_C_SEARCH)) return (1); flags = 0; } else { @@ -152,11 +151,11 @@ subagain: return (ex_subagain(sp, cmdp)); * RE's. We compile the RE twice, as we don't want to bother * ref counting the pattern string and (opaque) structure. */ - if (re_compile(sp, ptrn, t - ptrn, - &sp->re, &sp->re_len, &sp->re_c, RE_C_SEARCH)) + if (re_compile(sp, ptrn, t - ptrn, &sp->re, + &sp->re_len, &sp->re_c, RE_C_SEARCH)) return (1); - if (re_compile(sp, ptrn, t - ptrn, - &sp->subre, &sp->subre_len, &sp->subre_c, RE_C_SUBST)) + if (re_compile(sp, ptrn, t - ptrn, &sp->subre, + &sp->subre_len, &sp->subre_c, RE_C_SUBST)) return (1); flags = SUB_FIRST; @@ -202,7 +201,7 @@ subagain: return (ex_subagain(sp, cmdp)); p[0] != '\0' && p[0] != delim; ++p, ++len) if (p[0] == '~') len += sp->repl_len; - GET_SPACE_RET(sp, bp, blen, len); + GET_SPACE_RETW(sp, bp, blen, len); for (t = bp, len = 0, p = rep;;) { if (p[0] == '\0' || p[0] == delim) { if (p[0] == delim) @@ -222,7 +221,7 @@ subagain: return (ex_subagain(sp, cmdp)); } } else if (p[0] == '~' && O_ISSET(sp, O_MAGIC)) { tilde: ++p; - memcpy(t, sp->repl, sp->repl_len); + MEMCPY(t, sp->repl, sp->repl_len); t += sp->repl_len; len += sp->repl_len; continue; @@ -233,14 +232,14 @@ tilde: ++p; if ((sp->repl_len = len) != 0) { if (sp->repl != NULL) free(sp->repl); - if ((sp->repl = malloc(len)) == NULL) { - msgq(sp, M_SYSERR, NULL); - FREE_SPACE(sp, bp, blen); + MALLOC(sp, sp->repl, CHAR_T *, len * sizeof(CHAR_T)); + if (sp->repl == NULL) { + FREE_SPACEW(sp, bp, blen); return (1); } - memcpy(sp->repl, bp, len); + MEMCPY(sp->repl, bp, len); } - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); } return (s(sp, cmdp, p, re, flags)); } @@ -254,16 +253,15 @@ tilde: ++p; * PUBLIC: int ex_subagain __P((SCR *, EXCMD *)); */ int -ex_subagain(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_subagain(SCR *sp, EXCMD *cmdp) { if (sp->subre == NULL) { ex_emsg(sp, NULL, EXM_NOPREVRE); return (1); } - if (!F_ISSET(sp, SC_RE_SUBST) && re_compile(sp, - sp->subre, sp->subre_len, NULL, NULL, &sp->subre_c, RE_C_SUBST)) + if (!F_ISSET(sp, SC_RE_SUBST) && + re_compile(sp, sp->subre, sp->subre_len, + NULL, NULL, &sp->subre_c, RE_C_SUBST)) return (1); return (s(sp, cmdp, cmdp->argc ? cmdp->argv[0]->bp : NULL, &sp->subre_c, 0)); @@ -278,16 +276,14 @@ ex_subagain(sp, cmdp) * PUBLIC: int ex_subtilde __P((SCR *, EXCMD *)); */ int -ex_subtilde(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_subtilde(SCR *sp, EXCMD *cmdp) { if (sp->re == NULL) { ex_emsg(sp, NULL, EXM_NOPREVRE); return (1); } - if (!F_ISSET(sp, SC_RE_SEARCH) && re_compile(sp, - sp->re, sp->re_len, NULL, NULL, &sp->re_c, RE_C_SEARCH)) + if (!F_ISSET(sp, SC_RE_SEARCH) && re_compile(sp, sp->re, + sp->re_len, NULL, NULL, &sp->re_c, RE_C_SEARCH)) return (1); return (s(sp, cmdp, cmdp->argc ? cmdp->argv[0]->bp : NULL, &sp->re_c, 0)); @@ -320,21 +316,21 @@ ex_subtilde(sp, cmdp) #define BUILD(sp, l, len) { \ if (lbclen + (len) > lblen) { \ - lblen += MAX(lbclen + (len), 256); \ - REALLOC(sp, lb, char *, lblen); \ + lblen = p2roundup(MAX(lbclen + (len), 256)); \ + REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \ if (lb == NULL) { \ lbclen = 0; \ return (1); \ } \ } \ - memcpy(lb + lbclen, l, len); \ + MEMCPY(lb + lbclen, l, len); \ lbclen += len; \ } #define NEEDSP(sp, len, pnt) { \ if (lbclen + (len) > lblen) { \ - lblen += MAX(lbclen + (len), 256); \ - REALLOC(sp, lb, char *, lblen); \ + lblen = p2roundup(MAX(lbclen + (len), 256)); \ + REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \ if (lb == NULL) { \ lbclen = 0; \ return (1); \ @@ -344,24 +340,21 @@ ex_subtilde(sp, cmdp) } static int -s(sp, cmdp, s, re, flags) - SCR *sp; - EXCMD *cmdp; - char *s; - regex_t *re; - u_int flags; +s(SCR *sp, EXCMD *cmdp, CHAR_T *s, regex_t *re, u_int flags) { EVENT ev; MARK from, to; - TEXTH tiq; + TEXTH tiq[] = {{ 0 }}; recno_t elno, lno, slno; + u_long ul; regmatch_t match[10]; size_t blen, cnt, last, lbclen, lblen, len, llen; size_t offset, saved_offset, scno; int cflag, lflag, nflag, pflag, rflag; int didsub, do_eol_match, eflags, empty_ok, eval; int linechanged, matched, quit, rval; - char *bp, *lb; + CHAR_T *bp, *lb; + enum nresult nret; NEEDFILE(sp, cmdp); @@ -414,13 +407,14 @@ s(sp, cmdp, s, re, flags) if (lno != OOBLNO) goto usage; errno = 0; - lno = strtoul(s, &s, 10); + nret = nget_uslong(&ul, s, &s, 10); + lno = ul; if (*s == '\0') /* Loop increment correction. */ --s; - if (errno == ERANGE) { - if (lno == LONG_MAX) + if (nret != NUM_OK) { + if (nret == NUM_OVER) msgq(sp, M_ERR, "153|Count overflow"); - else if (lno == LONG_MIN) + else if (nret == NUM_UNDER) msgq(sp, M_ERR, "154|Count underflow"); else msgq(sp, M_SYSERR, NULL); @@ -443,10 +437,8 @@ s(sp, cmdp, s, re, flags) sp->c_suffix = !sp->c_suffix; /* Ex text structure initialization. */ - if (F_ISSET(sp, SC_EX)) { - memset(&tiq, 0, sizeof(TEXTH)); - CIRCLEQ_INIT(&tiq); - } + if (F_ISSET(sp, SC_EX)) + TAILQ_INIT(tiq); break; case 'g': sp->g_suffix = !sp->g_suffix; @@ -474,7 +466,7 @@ s(sp, cmdp, s, re, flags) goto usage; } - if (*s != '\0' || !rflag && LF_ISSET(SUB_MUSTSETR)) { + if (*s != '\0' || (!rflag && LF_ISSET(SUB_MUSTSETR))) { usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); return (1); } @@ -496,7 +488,8 @@ noargs: if (F_ISSET(sp, SC_VI) && sp->c_suffix && (lflag || nflag || pflag)) { blen = lbclen = lblen = 0; /* For each line... */ - for (matched = quit = 0, lno = cmdp->addr1.lno, + lno = cmdp->addr1.lno == 0 ? 1 : cmdp->addr1.lno; + for (matched = quit = 0, elno = cmdp->addr2.lno; !quit && lno <= elno; ++lno) { /* Someone's unhappy, time to stop. */ @@ -513,10 +506,10 @@ noargs: if (F_ISSET(sp, SC_VI) && sp->c_suffix && (lflag || nflag || pflag)) { */ if (sp->c_suffix) { if (bp == NULL) { - GET_SPACE_RET(sp, bp, blen, llen); + GET_SPACE_RETW(sp, bp, blen, llen); } else - ADD_SPACE_RET(sp, bp, blen, llen); - memcpy(bp, s, llen); + ADD_SPACE_RETW(sp, bp, blen, llen); + MEMCPY(bp, s, llen); s = bp; } @@ -555,7 +548,7 @@ nextmatch: match[0].rm_so = 0; match[0].rm_eo = len; /* Get the next match. */ - eval = regexec(re, (char *)s + offset, 10, match, eflags); + eval = regexec(re, s + offset, 10, match, eflags); /* * There wasn't a match or if there was an error, deal with @@ -658,9 +651,9 @@ nextmatch: match[0].rm_so = 0; if (ex_print(sp, cmdp, &from, &to, 0) || ex_scprint(sp, &from, &to)) goto lquit; - if (ex_txt(sp, &tiq, 0, TXT_CR)) + if (ex_txt(sp, tiq, 0, TXT_CR)) goto err; - ev.e_c = tiq.cqh_first->lb[0]; + ev.e_c = TAILQ_FIRST(tiq)->lb[0]; } switch (ev.e_c) { @@ -749,8 +742,8 @@ skip: offset += match[0].rm_eo; goto err; if (db_get(sp, lno, DBG_FATAL, &s, &llen)) goto err; - ADD_SPACE_RET(sp, bp, blen, llen) - memcpy(bp, s, llen); + ADD_SPACE_RETW(sp, bp, blen, llen) + MEMCPY(bp, s, llen); s = bp; len = llen - offset; @@ -876,7 +869,7 @@ err: rval = 1; } if (bp != NULL) - FREE_SPACE(sp, bp, blen); + FREE_SPACEW(sp, bp, blen); if (lb != NULL) free(lb); return (rval); @@ -887,19 +880,14 @@ err: rval = 1; * Compile the RE. * * PUBLIC: int re_compile __P((SCR *, - * PUBLIC: char *, size_t, char **, size_t *, regex_t *, u_int)); + * PUBLIC: CHAR_T *, size_t, CHAR_T **, size_t *, regex_t *, u_int)); */ int -re_compile(sp, ptrn, plen, ptrnp, lenp, rep, flags) - SCR *sp; - char *ptrn, **ptrnp; - size_t plen, *lenp; - regex_t *rep; - u_int flags; +re_compile(SCR *sp, CHAR_T *ptrn, size_t plen, CHAR_T **ptrnp, size_t *lenp, regex_t *rep, u_int flags) { size_t len; int reflags, replaced, rval; - char *p; + CHAR_T *p; /* Set RE flags. */ reflags = 0; @@ -910,7 +898,7 @@ re_compile(sp, ptrn, plen, ptrnp, lenp, rep, flags) reflags |= REG_ICASE; if (O_ISSET(sp, O_ICLOWER)) { for (p = ptrn, len = plen; len > 0; ++p, --len) - if (isupper(*p)) + if (ISUPPER(*p)) break; if (len == 0) reflags |= REG_ICASE; @@ -933,6 +921,7 @@ re_compile(sp, ptrn, plen, ptrnp, lenp, rep, flags) * later recompilation. Free any previously saved value. */ if (ptrnp != NULL) { + replaced = 0; if (LF_ISSET(RE_C_CSCOPE)) { if (re_cscope_conv(sp, &ptrn, &plen, &replaced)) return (1); @@ -965,15 +954,15 @@ re_compile(sp, ptrn, plen, ptrnp, lenp, rep, flags) * Regcomp isn't 8-bit clean, so the pattern is nul-terminated * for now. There's just no other solution. */ - MALLOC(sp, *ptrnp, char *, plen + 1); + MALLOC(sp, *ptrnp, CHAR_T *, (plen + 1) * sizeof(CHAR_T)); if (*ptrnp != NULL) { - memcpy(*ptrnp, ptrn, plen); + MEMCPY(*ptrnp, ptrn, plen); (*ptrnp)[plen] = '\0'; } /* Free up conversion-routine-allocated memory. */ if (replaced) - FREE_SPACE(sp, ptrn, 0); + FREE_SPACEW(sp, ptrn, 0); if (*ptrnp == NULL) return (1); @@ -1023,15 +1012,11 @@ re_compile(sp, ptrn, plen, ptrnp, lenp, rep, flags) * weren't historically. It's a bug. */ static int -re_conv(sp, ptrnp, plenp, replacedp) - SCR *sp; - char **ptrnp; - size_t *plenp; - int *replacedp; +re_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp) { size_t blen, len, needlen; int magic; - char *bp, *p, *t; + CHAR_T *bp, *p, *t; /* * First pass through, we figure out how much space we'll need. @@ -1048,11 +1033,11 @@ re_conv(sp, ptrnp, plenp, replacedp) switch (*++p) { case '<': magic = 1; - needlen += sizeof(RE_WSTART); + needlen += RE_WSTART_LEN + 1; break; case '>': magic = 1; - needlen += sizeof(RE_WSTOP); + needlen += RE_WSTOP_LEN + 1; break; case '~': if (!O_ISSET(sp, O_MAGIC)) { @@ -1100,7 +1085,7 @@ re_conv(sp, ptrnp, plenp, replacedp) /* Get enough memory to hold the final pattern. */ *replacedp = 1; - GET_SPACE_RET(sp, bp, blen, needlen); + GET_SPACE_RETW(sp, bp, blen, needlen); for (p = *ptrnp, len = *plenp, t = bp; len > 0; ++p, --len) switch (*p) { @@ -1109,20 +1094,20 @@ re_conv(sp, ptrnp, plenp, replacedp) --len; switch (*++p) { case '<': - memcpy(t, - RE_WSTART, sizeof(RE_WSTART) - 1); - t += sizeof(RE_WSTART) - 1; + MEMCPY(t, + RE_WSTART, RE_WSTART_LEN); + t += RE_WSTART_LEN; break; case '>': - memcpy(t, - RE_WSTOP, sizeof(RE_WSTOP) - 1); - t += sizeof(RE_WSTOP) - 1; + MEMCPY(t, + RE_WSTOP, RE_WSTOP_LEN); + t += RE_WSTOP_LEN; break; case '~': if (O_ISSET(sp, O_MAGIC)) *t++ = '~'; else { - memcpy(t, + MEMCPY(t, sp->repl, sp->repl_len); t += sp->repl_len; } @@ -1143,7 +1128,7 @@ re_conv(sp, ptrnp, plenp, replacedp) break; case '~': if (O_ISSET(sp, O_MAGIC)) { - memcpy(t, sp->repl, sp->repl_len); + MEMCPY(t, sp->repl, sp->repl_len); t += sp->repl_len; } else *t++ = '~'; @@ -1171,21 +1156,17 @@ re_conv(sp, ptrnp, plenp, replacedp) * 1003.2 RE functions can handle. */ static int -re_tag_conv(sp, ptrnp, plenp, replacedp) - SCR *sp; - char **ptrnp; - size_t *plenp; - int *replacedp; +re_tag_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp) { size_t blen, len; int lastdollar; - char *bp, *p, *t; + CHAR_T *bp, *p, *t; len = *plenp; /* Max memory usage is 2 times the length of the string. */ *replacedp = 1; - GET_SPACE_RET(sp, bp, blen, len * 2); + GET_SPACE_RETW(sp, bp, blen, len * 2); p = *ptrnp; t = bp; @@ -1222,7 +1203,7 @@ re_tag_conv(sp, ptrnp, plenp, replacedp) if (p[0] == '\\' && (p[1] == '/' || p[1] == '?')) { ++p; --len; - } else if (strchr("^.[]$*", p[0])) + } else if (STRCHR(L("^.[]$*"), p[0])) *t++ = '\\'; *t++ = *p++; } @@ -1240,20 +1221,21 @@ re_tag_conv(sp, ptrnp, plenp, replacedp) * 1003.2 RE functions can handle. */ static int -re_cscope_conv(sp, ptrnp, plenp, replacedp) - SCR *sp; - char **ptrnp; - size_t *plenp; - int *replacedp; +re_cscope_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp) { size_t blen, len, nspaces; - char *bp, *p, *t; + CHAR_T *bp, *t; + CHAR_T *p; + CHAR_T *wp; + size_t wlen; /* * Each space in the source line printed by cscope represents an * arbitrary sequence of spaces, tabs, and comments. */ #define CSCOPE_RE_SPACE "([ \t]|/\\*([^*]|\\*/)*\\*/)*" +#define CSCOPE_LEN sizeof(CSCOPE_RE_SPACE) - 1 + CHAR2INT(sp, CSCOPE_RE_SPACE, CSCOPE_LEN, wp, wlen); for (nspaces = 0, p = *ptrnp, len = *plenp; len > 0; ++p, --len) if (*p == ' ') ++nspaces; @@ -1266,27 +1248,27 @@ re_cscope_conv(sp, ptrnp, plenp, replacedp) */ *replacedp = 1; len = (p - *ptrnp) * 2 + (nspaces + 2) * sizeof(CSCOPE_RE_SPACE) + 3; - GET_SPACE_RET(sp, bp, blen, len); + GET_SPACE_RETW(sp, bp, blen, len); p = *ptrnp; t = bp; *t++ = '^'; - memcpy(t, CSCOPE_RE_SPACE, sizeof(CSCOPE_RE_SPACE) - 1); - t += sizeof(CSCOPE_RE_SPACE) - 1; + MEMCPY(t, wp, wlen); + t += wlen; for (len = *plenp; len > 0; ++p, --len) if (*p == ' ') { - memcpy(t, CSCOPE_RE_SPACE, sizeof(CSCOPE_RE_SPACE) - 1); - t += sizeof(CSCOPE_RE_SPACE) - 1; + MEMCPY(t, wp, wlen); + t += wlen; } else { - if (strchr("\\^.[]$*+?()|{}", *p)) + if (STRCHR(L("\\^.[]$*+?()|{}"), *p)) *t++ = '\\'; *t++ = *p; } - memcpy(t, CSCOPE_RE_SPACE, sizeof(CSCOPE_RE_SPACE) - 1); - t += sizeof(CSCOPE_RE_SPACE) - 1; + MEMCPY(t, wp, wlen); + t += wlen; *t++ = '$'; *ptrnp = bp; @@ -1301,18 +1283,14 @@ re_cscope_conv(sp, ptrnp, plenp, replacedp) * PUBLIC: void re_error __P((SCR *, int, regex_t *)); */ void -re_error(sp, errcode, preg) - SCR *sp; - int errcode; - regex_t *preg; +re_error(SCR *sp, int errcode, regex_t *preg) { size_t s; char *oe; s = regerror(errcode, preg, "", 0); - if ((oe = malloc(s)) == NULL) - msgq(sp, M_SYSERR, NULL); - else { + MALLOC(sp, oe, char *, s); + if (oe != NULL) { (void)regerror(errcode, preg, oe, s); msgq(sp, M_ERR, "RE error: %s", oe); free(oe); @@ -1324,22 +1302,23 @@ re_error(sp, errcode, preg) * Do the substitution for a regular expression. */ static int -re_sub(sp, ip, lbp, lbclenp, lblenp, match) - SCR *sp; - char *ip; /* Input line. */ - char **lbp; - size_t *lbclenp, *lblenp; - regmatch_t match[10]; +re_sub( + SCR *sp, + CHAR_T *ip, /* Input line. */ + CHAR_T **lbp, + size_t *lbclenp, + size_t *lblenp, + regmatch_t match[10]) { enum { C_NOTSET, C_LOWER, C_ONELOWER, C_ONEUPPER, C_UPPER } conv; size_t lbclen, lblen; /* Local copies. */ size_t mlen; /* Match length. */ size_t rpl; /* Remaining replacement length. */ - char *rp; /* Replacement pointer. */ + CHAR_T *rp; /* Replacement pointer. */ int ch; int no; /* Match replacement offset. */ - char *p, *t; /* Buffer pointers. */ - char *lb; /* Local copies. */ + CHAR_T *p, *t; /* Buffer pointers. */ + CHAR_T *lb; /* Local copies. */ lb = *lbp; /* Get local copies. */ lbclen = *lbclenp; @@ -1363,8 +1342,8 @@ re_sub(sp, ip, lbp, lbclenp, lblenp, match) * all escaping characters. This (hopefully) matches historic practice. */ #define OUTCH(ch, nltrans) { \ - CHAR_T __ch = (ch); \ - u_int __value = KEY_VAL(sp, __ch); \ + ARG_CHAR_T __ch = (ch); \ + e_key_t __value = KEY_VAL(sp, __ch); \ if (nltrans && (__value == K_CR || __value == K_NL)) { \ NEEDNEWLINE(sp); \ sp->newl[sp->newl_cnt++] = lbclen; \ @@ -1374,15 +1353,15 @@ re_sub(sp, ip, lbp, lbclenp, lblenp, match) conv = C_NOTSET; \ /* FALLTHROUGH */ \ case C_LOWER: \ - if (isupper(__ch)) \ - __ch = tolower(__ch); \ + if (ISUPPER(__ch)) \ + __ch = TOLOWER(__ch); \ break; \ case C_ONEUPPER: \ conv = C_NOTSET; \ /* FALLTHROUGH */ \ case C_UPPER: \ - if (islower(__ch)) \ - __ch = toupper(__ch); \ + if (ISLOWER(__ch)) \ + __ch = TOUPPER(__ch); \ break; \ default: \ abort(); \ @@ -1444,6 +1423,9 @@ subzero: if (match[no].rm_so == -1 || ++rp; conv = C_UPPER; continue; + case '\r': + OUTCH(ch, 0); + continue; default: ++rp; break; diff --git a/contrib/nvi/ex/ex_tag.c b/contrib/nvi/ex/ex_tag.c index 8f5e7b9dc..4ef03fb 100644 --- a/contrib/nvi/ex/ex_tag.c +++ b/contrib/nvi/ex/ex_tag.c @@ -13,19 +13,13 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_tag.c 10.36 (Berkeley) 9/15/96"; +static const char sccsid[] = "$Id: ex_tag.c,v 10.54 2012/04/12 07:17:30 zy Exp $"; #endif /* not lint */ -#include <sys/param.h> -#include <sys/types.h> /* XXX: param.h may not have included types.h */ - -#ifdef HAVE_SYS_MMAN_H +#include <sys/types.h> #include <sys/mman.h> -#endif - #include <sys/queue.h> #include <sys/stat.h> -#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -45,14 +39,10 @@ static const char sccsid[] = "@(#)ex_tag.c 10.36 (Berkeley) 9/15/96"; static char *binary_search __P((char *, char *, char *)); static int compare __P((char *, char *, char *)); static void ctag_file __P((SCR *, TAGF *, char *, char **, size_t *)); -static int ctag_search __P((SCR *, char *, size_t, char *)); -#ifdef GTAGS -static int getentry __P((char *, char **, char **, char **)); -static TAGQ *gtag_slist __P((SCR *, char *, int)); -#endif +static int ctag_search __P((SCR *, CHAR_T *, size_t, char *)); static int ctag_sfile __P((SCR *, TAGF *, TAGQ *, char *)); -static TAGQ *ctag_slist __P((SCR *, char *)); -static char *linear_search __P((char *, char *, char *)); +static TAGQ *ctag_slist __P((SCR *, CHAR_T *)); +static char *linear_search __P((char *, char *, char *, long)); static int tag_copy __P((SCR *, TAG *, TAG **)); static int tag_pop __P((SCR *, TAGQ *, int)); static int tagf_copy __P((SCR *, TAGF *, TAGF **)); @@ -63,19 +53,16 @@ static int tagq_copy __P((SCR *, TAGQ *, TAGQ **)); * ex_tag_first -- * The tag code can be entered from main, e.g., "vi -t tag". * - * PUBLIC: int ex_tag_first __P((SCR *, char *)); + * PUBLIC: int ex_tag_first __P((SCR *, CHAR_T *)); */ int -ex_tag_first(sp, tagarg) - SCR *sp; - char *tagarg; +ex_tag_first(SCR *sp, CHAR_T *tagarg) { - ARGS *ap[2], a; EXCMD cmd; /* Build an argument for the ex :tag command. */ - ex_cinit(&cmd, C_TAG, 0, OOBLNO, OOBLNO, 0, ap); - ex_cadd(&cmd, &a, tagarg, strlen(tagarg)); + ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0); + argv_exp0(sp, &cmd, tagarg, STRLEN(tagarg)); /* * XXX @@ -93,25 +80,6 @@ ex_tag_first(sp, tagarg) return (0); } -#ifdef GTAGS -/* - * ex_rtag_push -- ^] - * :rtag[!] [string] - * - * Enter a new TAGQ context based on a ctag string. - * - * PUBLIC: int ex_rtag_push __P((SCR *, EXCMD *)); - */ -int -ex_rtag_push(sp, cmdp) - SCR *sp; - EXCMD *cmdp; -{ - F_SET(cmdp, E_REFERENCE); - return ex_tag_push(sp, cmdp); -} -#endif - /* * ex_tag_push -- ^] * :tag[!] [string] @@ -121,18 +89,11 @@ ex_rtag_push(sp, cmdp) * PUBLIC: int ex_tag_push __P((SCR *, EXCMD *)); */ int -ex_tag_push(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_tag_push(SCR *sp, EXCMD *cmdp) { EX_PRIVATE *exp; - FREF *frp; - TAG *rtp; - TAGQ *rtqp, *tqp; - recno_t lno; - size_t cno; + TAGQ *tqp; long tl; - int force, istmp; exp = EXP(sp); switch (cmdp->argc) { @@ -140,14 +101,15 @@ ex_tag_push(sp, cmdp) if (exp->tag_last != NULL) free(exp->tag_last); - if ((exp->tag_last = strdup(cmdp->argv[0]->bp)) == NULL) { + if ((exp->tag_last = v_wstrdup(sp, cmdp->argv[0]->bp, + cmdp->argv[0]->len)) == NULL) { msgq(sp, M_SYSERR, NULL); return (1); } /* Taglength may limit the number of characters. */ if ((tl = - O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(exp->tag_last) > tl) + O_VAL(sp, O_TAGLENGTH)) != 0 && STRLEN(exp->tag_last) > tl) exp->tag_last[tl] = '\0'; break; case 0: @@ -161,100 +123,14 @@ ex_tag_push(sp, cmdp) } /* Get the tag information. */ -#ifdef GTAGS - if (O_ISSET(sp, O_GTAGSMODE)) { - if ((tqp = gtag_slist(sp, exp->tag_last, F_ISSET(cmdp, E_REFERENCE))) == NULL) - return (1); - } else -#endif if ((tqp = ctag_slist(sp, exp->tag_last)) == NULL) return (1); - /* - * Allocate all necessary memory before swapping screens. Initialize - * flags so we know what to free. - */ - rtp = NULL; - rtqp = NULL; - if (exp->tq.cqh_first == (void *)&exp->tq) { - /* Initialize the `local context' tag queue structure. */ - CALLOC_GOTO(sp, rtqp, TAGQ *, 1, sizeof(TAGQ)); - CIRCLEQ_INIT(&rtqp->tagq); - - /* Initialize and link in its tag structure. */ - CALLOC_GOTO(sp, rtp, TAG *, 1, sizeof(TAG)); - CIRCLEQ_INSERT_HEAD(&rtqp->tagq, rtp, q); - rtqp->current = rtp; - } - - /* - * Stick the current context information in a convenient place, we're - * about to lose it. Note, if we're called on editor startup, there - * will be no FREF structure. - */ - frp = sp->frp; - lno = sp->lno; - cno = sp->cno; - istmp = frp == NULL || - F_ISSET(frp, FR_TMPFILE) && !F_ISSET(cmdp, E_NEWSCREEN); - - /* Try to switch to the tag. */ - force = FL_ISSET(cmdp->iflags, E_C_FORCE); - if (F_ISSET(cmdp, E_NEWSCREEN)) { - if (ex_tag_Nswitch(sp, tqp->tagq.cqh_first, force)) - goto err; - - /* Everything else gets done in the new screen. */ - sp = sp->nextdisp; - exp = EXP(sp); - } else - if (ex_tag_nswitch(sp, tqp->tagq.cqh_first, force)) - goto err; - - /* - * If this is the first tag, put a `current location' queue entry - * in place, so we can pop all the way back to the current mark. - * Note, it doesn't point to much of anything, it's a placeholder. - */ - if (exp->tq.cqh_first == (void *)&exp->tq) { - CIRCLEQ_INSERT_HEAD(&exp->tq, rtqp, q); - } else - rtqp = exp->tq.cqh_first; - - /* Link the new TAGQ structure into place. */ - CIRCLEQ_INSERT_HEAD(&exp->tq, tqp, q); - - (void)ctag_search(sp, - tqp->current->search, tqp->current->slen, tqp->tag); - - /* - * Move the current context from the temporary save area into the - * right structure. - * - * If we were in a temporary file, we don't have a context to which - * we can return, so just make it be the same as what we're moving - * to. It will be a little odd that ^T doesn't change anything, but - * I don't think it's a big deal. - */ - if (istmp) { - rtqp->current->frp = sp->frp; - rtqp->current->lno = sp->lno; - rtqp->current->cno = sp->cno; - } else { - rtqp->current->frp = frp; - rtqp->current->lno = lno; - rtqp->current->cno = cno; - } - return (0); + if (tagq_push(sp, tqp, F_ISSET(cmdp, E_NEWSCREEN), + FL_ISSET(cmdp->iflags, E_C_FORCE))) + return 1; -err: -alloc_err: - if (rtqp != NULL) - free(rtqp); - if (rtp != NULL) - free(rtp); - tagq_free(sp, tqp); - return (1); + return 0; } /* @@ -264,20 +140,20 @@ alloc_err: * PUBLIC: int ex_tag_next __P((SCR *, EXCMD *)); */ int -ex_tag_next(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_tag_next(SCR *sp, EXCMD *cmdp) { EX_PRIVATE *exp; TAG *tp; TAGQ *tqp; + char *np; + size_t nlen; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if ((tqp = TAILQ_FIRST(exp->tq)) == NULL) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } - if ((tp = tqp->current->q.cqe_next) == (void *)&tqp->tagq) { + if ((tp = TAILQ_NEXT(tqp->current, q)) == NULL) { msgq(sp, M_ERR, "282|Already at the last tag of this group"); return (1); } @@ -289,6 +165,11 @@ ex_tag_next(sp, cmdp) (void)cscope_search(sp, tqp, tp); else (void)ctag_search(sp, tp->search, tp->slen, tqp->tag); + if (tqp->current->msg) { + INT2CHAR(sp, tqp->current->msg, tqp->current->mlen + 1, + np, nlen); + msgq(sp, M_INFO, "%s", np); + } return (0); } @@ -299,20 +180,20 @@ ex_tag_next(sp, cmdp) * PUBLIC: int ex_tag_prev __P((SCR *, EXCMD *)); */ int -ex_tag_prev(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_tag_prev(SCR *sp, EXCMD *cmdp) { EX_PRIVATE *exp; TAG *tp; TAGQ *tqp; + char *np; + size_t nlen; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if ((tqp = TAILQ_FIRST(exp->tq)) == NULL) { tag_msg(sp, TAG_EMPTY, NULL); return (0); } - if ((tp = tqp->current->q.cqe_prev) == (void *)&tqp->tagq) { + if ((tp = TAILQ_PREV(tqp->current, _tagqh, q)) == NULL) { msgq(sp, M_ERR, "255|Already at the first tag of this group"); return (1); } @@ -324,6 +205,11 @@ ex_tag_prev(sp, cmdp) (void)cscope_search(sp, tqp, tp); else (void)ctag_search(sp, tp->search, tp->slen, tqp->tag); + if (tqp->current->msg) { + INT2CHAR(sp, tqp->current->msg, tqp->current->mlen + 1, + np, nlen); + msgq(sp, M_INFO, "%s", np); + } return (0); } @@ -334,10 +220,7 @@ ex_tag_prev(sp, cmdp) * PUBLIC: int ex_tag_nswitch __P((SCR *, TAG *, int)); */ int -ex_tag_nswitch(sp, tp, force) - SCR *sp; - TAG *tp; - int force; +ex_tag_nswitch(SCR *sp, TAG *tp, int force) { /* Get a file structure. */ if (tp->frp == NULL && (tp->frp = file_add(sp, tp->fname)) == NULL) @@ -371,10 +254,7 @@ ex_tag_nswitch(sp, tp, force) * PUBLIC: int ex_tag_Nswitch __P((SCR *, TAG *, int)); */ int -ex_tag_Nswitch(sp, tp, force) - SCR *sp; - TAG *tp; - int force; +ex_tag_Nswitch(SCR *sp, TAG *tp, int force) { SCR *new; @@ -428,19 +308,18 @@ ex_tag_Nswitch(sp, tp, force) * PUBLIC: int ex_tag_pop __P((SCR *, EXCMD *)); */ int -ex_tag_pop(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_tag_pop(SCR *sp, EXCMD *cmdp) { EX_PRIVATE *exp; TAGQ *tqp, *dtqp; size_t arglen; long off; char *arg, *p, *t; + size_t nlen; /* Check for an empty stack. */ exp = EXP(sp); - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (TAILQ_EMPTY(exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } @@ -448,10 +327,11 @@ ex_tag_pop(sp, cmdp) /* Find the last TAG structure that we're going to DISCARD! */ switch (cmdp->argc) { case 0: /* Pop one tag. */ - dtqp = exp->tq.cqh_first; + dtqp = TAILQ_FIRST(exp->tq); break; case 1: /* Name or number. */ - arg = cmdp->argv[0]->bp; + INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len+1, + arg, nlen); off = strtol(arg, &p, 10); if (*p != '\0') goto filearg; @@ -459,10 +339,9 @@ ex_tag_pop(sp, cmdp) /* Number: pop that many queue entries. */ if (off < 1) return (0); - for (tqp = exp->tq.cqh_first; - tqp != (void *)&exp->tq && --off > 1; - tqp = tqp->q.cqe_next); - if (tqp == (void *)&exp->tq) { + TAILQ_FOREACH(tqp, exp->tq, q) + if (--off <= 1) break; + if (tqp == NULL) { msgq(sp, M_ERR, "159|Less than %s entries on the tags stack; use :display t[ags]", arg); @@ -473,11 +352,10 @@ ex_tag_pop(sp, cmdp) /* File argument: pop to that queue entry. */ filearg: arglen = strlen(arg); - for (tqp = exp->tq.cqh_first; - tqp != (void *)&exp->tq; - dtqp = tqp, tqp = tqp->q.cqe_next) { + for (tqp = TAILQ_FIRST(exp->tq); tqp; + dtqp = tqp, tqp = TAILQ_NEXT(tqp, q)) { /* Don't pop to the current file. */ - if (tqp == exp->tq.cqh_first) + if (tqp == TAILQ_FIRST(exp->tq)) continue; p = tqp->current->frp->name; if ((t = strrchr(p, '/')) == NULL) @@ -487,12 +365,12 @@ filearg: arglen = strlen(arg); if (!strncmp(arg, t, arglen)) break; } - if (tqp == (void *)&exp->tq) { + if (tqp == NULL) { msgq_str(sp, M_ERR, arg, "160|No file %s on the tags stack to return to; use :display t[ags]"); return (1); } - if (tqp == exp->tq.cqh_first) + if (tqp == TAILQ_FIRST(exp->tq)) return (0); break; default: @@ -509,23 +387,21 @@ filearg: arglen = strlen(arg); * PUBLIC: int ex_tag_top __P((SCR *, EXCMD *)); */ int -ex_tag_top(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_tag_top(SCR *sp, EXCMD *cmdp) { EX_PRIVATE *exp; exp = EXP(sp); /* Check for an empty stack. */ - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (TAILQ_EMPTY(exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } /* Return to the oldest information. */ - return (tag_pop(sp, - exp->tq.cqh_last->q.cqe_prev, FL_ISSET(cmdp->iflags, E_C_FORCE))); + return (tag_pop(sp, TAILQ_PREV(TAILQ_LAST(exp->tq, _tqh), _tqh, q), + FL_ISSET(cmdp->iflags, E_C_FORCE))); } /* @@ -533,10 +409,7 @@ ex_tag_top(sp, cmdp) * Pop up to and including the specified TAGQ context. */ static int -tag_pop(sp, dtqp, force) - SCR *sp; - TAGQ *dtqp; - int force; +tag_pop(SCR *sp, TAGQ *dtqp, int force) { EX_PRIVATE *exp; TAG *tp; @@ -548,7 +421,7 @@ tag_pop(sp, dtqp, force) * Update the cursor from the saved TAG information of the TAG * structure we're moving to. */ - tp = dtqp->q.cqe_next->current; + tp = TAILQ_NEXT(dtqp, q)->current; if (tp->frp == sp->frp) { sp->lno = tp->lno; sp->cno = tp->cno; @@ -567,7 +440,7 @@ tag_pop(sp, dtqp, force) /* Pop entries off the queue up to and including dtqp. */ do { - tqp = exp->tq.cqh_first; + tqp = TAILQ_FIRST(exp->tq); if (tagq_free(sp, tqp)) return (0); } while (tqp != dtqp); @@ -576,8 +449,8 @@ tag_pop(sp, dtqp, force) * If only a single tag left, we've returned to the first tag point, * and the stack is now empty. */ - if (exp->tq.cqh_first->q.cqe_next == (void *)&exp->tq) - tagq_free(sp, exp->tq.cqh_first); + if (TAILQ_NEXT(TAILQ_FIRST(exp->tq), q) == NULL) + tagq_free(sp, TAILQ_FIRST(exp->tq)); return (0); } @@ -589,18 +462,17 @@ tag_pop(sp, dtqp, force) * PUBLIC: int ex_tag_display __P((SCR *)); */ int -ex_tag_display(sp) - SCR *sp; +ex_tag_display(SCR *sp) { EX_PRIVATE *exp; TAG *tp; TAGQ *tqp; int cnt; size_t len; - char *p, *sep; + char *p; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if (TAILQ_EMPTY(exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (0); } @@ -628,11 +500,10 @@ ex_tag_display(sp) * Display the list of tags for each queue entry. The first entry * is numbered, and the current tag entry has an asterisk appended. */ - for (cnt = 1, tqp = exp->tq.cqh_first; !INTERRUPTED(sp) && - tqp != (void *)&exp->tq; ++cnt, tqp = tqp->q.cqe_next) - for (tp = tqp->tagq.cqh_first; - tp != (void *)&tqp->tagq; tp = tp->q.cqe_next) { - if (tp == tqp->tagq.cqh_first) + for (cnt = 1, tqp = TAILQ_FIRST(exp->tq); !INTERRUPTED(sp) && + tqp != NULL; ++cnt, tqp = TAILQ_NEXT(tqp, q)) + TAILQ_FOREACH(tp, tqp->tagq, q) { + if (tp == TAILQ_FIRST(tqp->tagq)) (void)ex_printf(sp, "%2d ", cnt); else (void)ex_printf(sp, " "); @@ -647,7 +518,7 @@ ex_tag_display(sp) if (tqp->current == tp) (void)ex_printf(sp, "*"); - if (tp == tqp->tagq.cqh_first && tqp->tag != NULL && + if (tp == TAILQ_FIRST(tqp->tagq) && tqp->tag != NULL && (sp->cols - L_NAME) >= L_TAG + L_SPACE) { len = strlen(tqp->tag); if (len > sp->cols - (L_NAME + L_SPACE)) @@ -668,8 +539,7 @@ ex_tag_display(sp) * PUBLIC: int ex_tag_copy __P((SCR *, SCR *)); */ int -ex_tag_copy(orig, sp) - SCR *orig, *sp; +ex_tag_copy(SCR *orig, SCR *sp) { EX_PRIVATE *oexp, *nexp; TAGQ *aqp, *tqp; @@ -680,33 +550,31 @@ ex_tag_copy(orig, sp) nexp = EXP(sp); /* Copy tag queue and tags stack. */ - for (aqp = oexp->tq.cqh_first; - aqp != (void *)&oexp->tq; aqp = aqp->q.cqe_next) { + TAILQ_FOREACH(aqp, oexp->tq, q) { if (tagq_copy(sp, aqp, &tqp)) return (1); - for (ap = aqp->tagq.cqh_first; - ap != (void *)&aqp->tagq; ap = ap->q.cqe_next) { + TAILQ_FOREACH(ap, aqp->tagq, q) { if (tag_copy(sp, ap, &tp)) return (1); /* Set the current pointer. */ if (aqp->current == ap) tqp->current = tp; - CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q); + TAILQ_INSERT_TAIL(tqp->tagq, tp, q); } - CIRCLEQ_INSERT_TAIL(&nexp->tq, tqp, q); + TAILQ_INSERT_TAIL(nexp->tq, tqp, q); } /* Copy list of tag files. */ - for (atfp = oexp->tagfq.tqh_first; - atfp != NULL; atfp = atfp->q.tqe_next) { + TAILQ_FOREACH(atfp, oexp->tagfq, q) { if (tagf_copy(sp, atfp, &tfp)) return (1); - TAILQ_INSERT_TAIL(&nexp->tagfq, tfp, q); + TAILQ_INSERT_TAIL(nexp->tagfq, tfp, q); } /* Copy the last tag. */ if (oexp->tag_last != NULL && - (nexp->tag_last = strdup(oexp->tag_last)) == NULL) { + (nexp->tag_last = v_wstrdup(sp, oexp->tag_last, + STRLEN(oexp->tag_last))) == NULL) { msgq(sp, M_SYSERR, NULL); return (1); } @@ -718,9 +586,7 @@ ex_tag_copy(orig, sp) * Copy a TAGF structure and return it in new memory. */ static int -tagf_copy(sp, otfp, tfpp) - SCR *sp; - TAGF *otfp, **tfpp; +tagf_copy(SCR *sp, TAGF *otfp, TAGF **tfpp) { TAGF *tfp; @@ -740,9 +606,7 @@ tagf_copy(sp, otfp, tfpp) * Copy a TAGQ structure and return it in new memory. */ static int -tagq_copy(sp, otqp, tqpp) - SCR *sp; - TAGQ *otqp, **tqpp; +tagq_copy(SCR *sp, TAGQ *otqp, TAGQ **tqpp) { TAGQ *tqp; size_t len; @@ -753,7 +617,7 @@ tagq_copy(sp, otqp, tqpp) MALLOC_RET(sp, tqp, TAGQ *, len); memcpy(tqp, otqp, len); - CIRCLEQ_INIT(&tqp->tagq); + TAILQ_INIT(tqp->tagq); tqp->current = NULL; if (otqp->tag != NULL) tqp->tag = tqp->buf; @@ -767,9 +631,7 @@ tagq_copy(sp, otqp, tqpp) * Copy a TAG structure and return it in new memory. */ static int -tag_copy(sp, otp, tpp) - SCR *sp; - TAG *otp, **tpp; +tag_copy(SCR *sp, TAG *otp, TAG **tpp) { TAG *tp; size_t len; @@ -779,13 +641,17 @@ tag_copy(sp, otp, tpp) len += otp->fnlen + 1; if (otp->search != NULL) len += otp->slen + 1; + if (otp->msg != NULL) + len += otp->mlen + 1; MALLOC_RET(sp, tp, TAG *, len); memcpy(tp, otp, len); if (otp->fname != NULL) - tp->fname = tp->buf; + tp->fname = (char *)tp->buf; if (otp->search != NULL) - tp->search = tp->fname + otp->fnlen + 1; + tp->search = tp->buf + (otp->search - otp->buf); + if (otp->msg != NULL) + tp->msg = tp->buf + (otp->msg - otp->buf); *tpp = tp; return (0); @@ -796,14 +662,12 @@ tag_copy(sp, otp, tpp) * Free a TAGF structure. */ static int -tagf_free(sp, tfp) - SCR *sp; - TAGF *tfp; +tagf_free(SCR *sp, TAGF *tfp) { EX_PRIVATE *exp; exp = EXP(sp); - TAILQ_REMOVE(&exp->tagfq, tfp, q); + TAILQ_REMOVE(exp->tagfq, tfp, q); free(tfp->name); free(tfp); return (0); @@ -816,16 +680,14 @@ tagf_free(sp, tfp) * PUBLIC: int tagq_free __P((SCR *, TAGQ *)); */ int -tagq_free(sp, tqp) - SCR *sp; - TAGQ *tqp; +tagq_free(SCR *sp, TAGQ *tqp) { EX_PRIVATE *exp; TAG *tp; exp = EXP(sp); - while ((tp = tqp->tagq.cqh_first) != (void *)&tqp->tagq) { - CIRCLEQ_REMOVE(&tqp->tagq, tp, q); + while ((tp = TAILQ_FIRST(tqp->tagq)) != NULL) { + TAILQ_REMOVE(tqp->tagq, tp, q); free(tp); } /* @@ -833,23 +695,129 @@ tagq_free(sp, tqp) * If allocated and then the user failed to switch files, the TAGQ * structure was never attached to any list. */ - if (tqp->q.cqe_next != NULL) - CIRCLEQ_REMOVE(&exp->tq, tqp, q); + if (TAILQ_ENTRY_ISVALID(tqp, q)) + TAILQ_REMOVE(exp->tq, tqp, q); free(tqp); return (0); } /* + * PUBLIC: int tagq_push __P((SCR*, TAGQ*, int, int )); + */ +int +tagq_push(SCR *sp, TAGQ *tqp, int new_screen, int force) +{ + EX_PRIVATE *exp; + FREF *frp; + TAG *rtp; + TAGQ *rtqp; + recno_t lno; + size_t cno; + int istmp; + char *np; + size_t nlen; + + exp = EXP(sp); + + /* + * Allocate all necessary memory before swapping screens. Initialize + * flags so we know what to free. + */ + rtp = NULL; + rtqp = NULL; + if (TAILQ_EMPTY(exp->tq)) { + /* Initialize the `local context' tag queue structure. */ + CALLOC_GOTO(sp, rtqp, TAGQ *, 1, sizeof(TAGQ)); + TAILQ_INIT(rtqp->tagq); + + /* Initialize and link in its tag structure. */ + CALLOC_GOTO(sp, rtp, TAG *, 1, sizeof(TAG)); + TAILQ_INSERT_HEAD(rtqp->tagq, rtp, q); + rtqp->current = rtp; + } + + /* + * Stick the current context information in a convenient place, we're + * about to lose it. Note, if we're called on editor startup, there + * will be no FREF structure. + */ + frp = sp->frp; + lno = sp->lno; + cno = sp->cno; + istmp = frp == NULL || + (F_ISSET(frp, FR_TMPFILE) && !new_screen); + + /* Try to switch to the preset tag. */ + if (new_screen) { + if (ex_tag_Nswitch(sp, tqp->current, force)) + goto err; + + /* Everything else gets done in the new screen. */ + sp = sp->nextdisp; + exp = EXP(sp); + } else + if (ex_tag_nswitch(sp, tqp->current, force)) + goto err; + + /* + * If this is the first tag, put a `current location' queue entry + * in place, so we can pop all the way back to the current mark. + * Note, it doesn't point to much of anything, it's a placeholder. + */ + if (TAILQ_EMPTY(exp->tq)) { + TAILQ_INSERT_HEAD(exp->tq, rtqp, q); + } else + rtqp = TAILQ_FIRST(exp->tq); + + /* Link the new TAGQ structure into place. */ + TAILQ_INSERT_HEAD(exp->tq, tqp, q); + + (void)ctag_search(sp, + tqp->current->search, tqp->current->slen, tqp->tag); + if (tqp->current->msg) { + INT2CHAR(sp, tqp->current->msg, tqp->current->mlen + 1, + np, nlen); + msgq(sp, M_INFO, "%s", np); + } + + /* + * Move the current context from the temporary save area into the + * right structure. + * + * If we were in a temporary file, we don't have a context to which + * we can return, so just make it be the same as what we're moving + * to. It will be a little odd that ^T doesn't change anything, but + * I don't think it's a big deal. + */ + if (istmp) { + rtqp->current->frp = sp->frp; + rtqp->current->lno = sp->lno; + rtqp->current->cno = sp->cno; + } else { + rtqp->current->frp = frp; + rtqp->current->lno = lno; + rtqp->current->cno = cno; + } + return (0); + +err: +alloc_err: + if (rtqp != NULL) + free(rtqp); + if (rtp != NULL) + free(rtp); + tagq_free(sp, tqp); + return (1); +} + +/* * tag_msg * A few common messages. * * PUBLIC: void tag_msg __P((SCR *, tagmsg_t, char *)); */ void -tag_msg(sp, msg, tag) - SCR *sp; - tagmsg_t msg; - char *tag; +tag_msg(SCR *sp, tagmsg_t msg, char *tag) { switch (msg) { case TAG_BADLNO: @@ -874,9 +842,7 @@ tag_msg(sp, msg, tag) * PUBLIC: int ex_tagf_alloc __P((SCR *, char *)); */ int -ex_tagf_alloc(sp, str) - SCR *sp; - char *str; +ex_tagf_alloc(SCR *sp, char *str) { EX_PRIVATE *exp; TAGF *tfp; @@ -885,13 +851,13 @@ ex_tagf_alloc(sp, str) /* Free current queue. */ exp = EXP(sp); - while ((tfp = exp->tagfq.tqh_first) != NULL) + while ((tfp = TAILQ_FIRST(exp->tagfq)) != NULL) tagf_free(sp, tfp); /* Create new queue. */ for (p = t = str;; ++p) { - if (*p == '\0' || isblank(*p)) { - if ((len = p - t) > 1) { + if (*p == '\0' || cmdskip(*p)) { + if ((len = p - t)) { MALLOC_RET(sp, tfp, TAGF *, sizeof(TAGF)); MALLOC(sp, tfp->name, char *, len + 1); if (tfp->name == NULL) { @@ -901,7 +867,7 @@ ex_tagf_alloc(sp, str) memcpy(tfp->name, t, len); tfp->name[len] = '\0'; tfp->flags = 0; - TAILQ_INSERT_TAIL(&exp->tagfq, tfp, q); + TAILQ_INSERT_TAIL(exp->tagfq, tfp, q); } t = p + 1; } @@ -918,8 +884,7 @@ ex_tagf_alloc(sp, str) * PUBLIC: int ex_tag_free __P((SCR *)); */ int -ex_tag_free(sp) - SCR *sp; +ex_tag_free(SCR *sp) { EX_PRIVATE *exp; TAGF *tfp; @@ -927,9 +892,9 @@ ex_tag_free(sp) /* Free up tag information. */ exp = EXP(sp); - while ((tqp = exp->tq.cqh_first) != (void *)&exp->tq) + while ((tqp = TAILQ_FIRST(exp->tq)) != NULL) tagq_free(sp, tqp); - while ((tfp = exp->tagfq.tqh_first) != NULL) + while ((tfp = TAILQ_FIRST(exp->tagfq)) != NULL) tagf_free(sp, tfp); if (exp->tag_last != NULL) free(exp->tag_last); @@ -941,13 +906,12 @@ ex_tag_free(sp) * Search a file for a tag. */ static int -ctag_search(sp, search, slen, tag) - SCR *sp; - char *search, *tag; - size_t slen; +ctag_search(SCR *sp, CHAR_T *search, size_t slen, char *tag) { MARK m; char *p; + char *np; + size_t nlen; /* * !!! @@ -955,8 +919,9 @@ ctag_search(sp, search, slen, tag) * used a line number, not a search string. I got complaints, so * people are still using the format. POSIX 1003.2 permits it. */ - if (isdigit(search[0])) { - m.lno = atoi(search); + if (ISDIGIT(search[0])) { + INT2CHAR(sp, search, slen+1, np, nlen); + m.lno = atoi(np); if (!db_exist(sp, m.lno)) { tag_msg(sp, TAG_BADLNO, tag); return (1); @@ -969,9 +934,10 @@ ctag_search(sp, search, slen, tag) m.lno = 1; m.cno = 0; if (f_search(sp, &m, &m, - search, slen, NULL, SEARCH_FILE | SEARCH_TAG)) - if ((p = strrchr(search, '(')) != NULL) { - slen = p - search; + search, slen, NULL, SEARCH_FILE | SEARCH_TAG)) { + INT2CHAR(sp, search, slen, np, nlen); + if ((p = strrchr(np, '(')) != NULL) { + slen = p - np; if (f_search(sp, &m, &m, search, slen, NULL, SEARCH_FILE | SEARCH_TAG)) goto notfound; @@ -979,6 +945,7 @@ ctag_search(sp, search, slen, tag) notfound: tag_msg(sp, TAG_SEARCH, tag); return (1); } + } /* * !!! * Historically, tags set the search direction if it wasn't @@ -998,171 +965,47 @@ notfound: tag_msg(sp, TAG_SEARCH, tag); return (0); } -#ifdef GTAGS -/* - * getentry -- - * get tag information from current line. - * - * gtags temporary file format. - * <tag> <lineno> <file> <image> - * - * sample. - * +------------------------------------------------ - * |main 30 main.c main(argc, argv) - * |func 21 subr.c func(arg) - */ -static int -getentry(buf, tag, file, line) - char *buf, **tag, **file, **line; -{ - char *p = buf; - - for (*tag = p; *p && !isspace(*p); p++) /* tag name */ - ; - if (*p == 0) - goto err; - *p++ = 0; - for (; *p && isspace(*p); p++) /* (skip blanks) */ - ; - if (*p == 0) - goto err; - *line = p; /* line no */ - for (*line = p; *p && !isspace(*p); p++) - ; - if (*p == 0) - goto err; - *p++ = 0; - for (; *p && isspace(*p); p++) /* (skip blanks) */ - ; - if (*p == 0) - goto err; - *file = p; /* file name */ - for (*file = p; *p && !isspace(*p); p++) - ; - if (*p == 0) - goto err; - *p = 0; - - /* value check */ - if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0) - return 1; /* OK */ -err: - return 0; /* ERROR */ -} - -/* - * gtag_slist -- - * Search the list of tags files for a tag, and return tag queue. - */ -static TAGQ * -gtag_slist(sp, tag, ref) - SCR *sp; - char *tag; - int ref; -{ - EX_PRIVATE *exp; - TAGF *tfp; - TAGQ *tqp; - size_t len; - int echk; - TAG *tp; - char *name, *file, *line; - char command[BUFSIZ]; - char buf[BUFSIZ]; - FILE *fp; - - /* Allocate and initialize the tag queue structure. */ - len = strlen(tag); - CALLOC_GOTO(sp, tqp, TAGQ *, 1, sizeof(TAGQ) + len + 1); - CIRCLEQ_INIT(&tqp->tagq); - tqp->tag = tqp->buf; - memcpy(tqp->tag, tag, (tqp->tlen = len) + 1); - - /* - * Find the tag, only display missing file messages once, and - * then only if we didn't find the tag. - */ - snprintf(command, sizeof(command), "global -%s '%s'", ref ? "rx" : "x", tag); - if (fp = popen(command, "r")) { - while (fgets(buf, sizeof(buf), fp)) { - if (buf[strlen(buf)-1] == '\n') /* chop(buf) */ - buf[strlen(buf)-1] = 0; - else - while (fgetc(fp) != '\n') - ; - if (getentry(buf, &name, &file, &line) == 0) { - echk = 1; - F_SET(tfp, TAGF_ERR); - break; - } - CALLOC_GOTO(sp, tp, - TAG *, 1, sizeof(TAG) + strlen(file) + 1 + strlen(line) + 1); - tp->fname = tp->buf; - strcpy(tp->fname, file); - tp->fnlen = strlen(file); - tp->search = tp->fname + tp->fnlen + 1; - strcpy(tp->search, line); - CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q); - } - pclose(fp); - } - - /* Check to see if we found anything. */ - if (tqp->tagq.cqh_first == (void *)&tqp->tagq) { - msgq_str(sp, M_ERR, tag, "162|%s: tag not found"); - free(tqp); - return (NULL); - } - - tqp->current = tqp->tagq.cqh_first; - return (tqp); - -alloc_err: - return (NULL); -} -#endif /* * ctag_slist -- * Search the list of tags files for a tag, and return tag queue. */ static TAGQ * -ctag_slist(sp, tag) - SCR *sp; - char *tag; +ctag_slist(SCR *sp, CHAR_T *tag) { EX_PRIVATE *exp; TAGF *tfp; TAGQ *tqp; size_t len; - int echk; + int echk = 0; + char *np; + size_t nlen; exp = EXP(sp); /* Allocate and initialize the tag queue structure. */ - len = strlen(tag); + INT2CHAR(sp, tag, STRLEN(tag) + 1, np, nlen); + len = nlen - 1; CALLOC_GOTO(sp, tqp, TAGQ *, 1, sizeof(TAGQ) + len + 1); - CIRCLEQ_INIT(&tqp->tagq); + TAILQ_INIT(tqp->tagq); tqp->tag = tqp->buf; - memcpy(tqp->tag, tag, (tqp->tlen = len) + 1); + memcpy(tqp->tag, np, (tqp->tlen = len) + 1); /* * Find the tag, only display missing file messages once, and * then only if we didn't find the tag. */ - for (echk = 0, - tfp = exp->tagfq.tqh_first; tfp != NULL; tfp = tfp->q.tqe_next) - if (ctag_sfile(sp, tfp, tqp, tag)) { + TAILQ_FOREACH(tfp, exp->tagfq, q) + if (ctag_sfile(sp, tfp, tqp, tqp->tag)) { echk = 1; F_SET(tfp, TAGF_ERR); } else F_CLR(tfp, TAGF_ERR | TAGF_ERR_WARN); /* Check to see if we found anything. */ - if (tqp->tagq.cqh_first == (void *)&tqp->tagq) { - msgq_str(sp, M_ERR, tag, "162|%s: tag not found"); + if (TAILQ_EMPTY(tqp->tagq)) { + msgq_str(sp, M_ERR, tqp->tag, "162|%s: tag not found"); if (echk) - for (tfp = exp->tagfq.tqh_first; - tfp != NULL; tfp = tfp->q.tqe_next) + TAILQ_FOREACH(tfp, exp->tagfq, q) if (F_ISSET(tfp, TAGF_ERR) && !F_ISSET(tfp, TAGF_ERR_WARN)) { errno = tfp->errnum; @@ -1173,7 +1016,6 @@ ctag_slist(sp, tag) return (NULL); } - tqp->current = tqp->tagq.cqh_first; return (tqp); alloc_err: @@ -1185,51 +1027,36 @@ alloc_err: * Search a tags file for a tag, adding any found to the tag queue. */ static int -ctag_sfile(sp, tfp, tqp, tname) - SCR *sp; - TAGF *tfp; - TAGQ *tqp; - char *tname; +ctag_sfile(SCR *sp, TAGF *tfp, TAGQ *tqp, char *tname) { struct stat sb; TAG *tp; - size_t dlen, nlen, slen; + size_t dlen, nlen = 0, slen; int fd, i, nf1, nf2; - char *back, *cname, *dname, *front, *map, *name, *p, *search, *t; + char *back, *front, *map, *p, *search, *t; + char *cname = NULL, *dname = NULL, *name = NULL; + CHAR_T *wp; + size_t wlen; + long tl; if ((fd = open(tfp->name, O_RDONLY, 0)) < 0) { tfp->errnum = errno; return (1); } - /* - * XXX - * Some old BSD systems require MAP_FILE as an argument when mapping - * regular files. - */ -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif - /* - * XXX - * We'd like to test if the file is too big to mmap. Since we don't - * know what size or type off_t's or size_t's are, what the largest - * unsigned integral type is, or what random insanity the local C - * compiler will perpetrate, doing the comparison in a portable way - * is flatly impossible. Hope mmap fails if the file is too large. - */ if (fstat(fd, &sb) != 0 || - (map = mmap(NULL, (size_t)sb.st_size, PROT_READ | PROT_WRITE, - MAP_FILE | MAP_PRIVATE, fd, (off_t)0)) == (caddr_t)-1) { + (map = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fd, 0)) == MAP_FAILED) { tfp->errnum = errno; (void)close(fd); return (1); } + tl = O_VAL(sp, O_TAGLENGTH); front = map; back = front + sb.st_size; front = binary_search(tname, front, back); - front = linear_search(tname, front, back); + front = linear_search(tname, front, back, tl); if (front == NULL) goto done; @@ -1292,29 +1119,41 @@ corrupt: p = msg_print(sp, tname, &nf1); } /* Check for passing the last entry. */ - if (strcmp(tname, cname)) + if (tl ? strncmp(tname, cname, tl) : strcmp(tname, cname)) break; /* Resolve the file name. */ ctag_file(sp, tfp, name, &dname, &dlen); CALLOC_GOTO(sp, tp, - TAG *, 1, sizeof(TAG) + dlen + 2 + nlen + 1 + slen + 1); - tp->fname = tp->buf; - if (dlen != 0) { + TAG *, 1, sizeof(TAG) + dlen + 2 + nlen + 1 + + (slen + 1) * sizeof(CHAR_T)); + tp->fname = (char *)tp->buf; + if (dlen == 1 && *dname == '.') + --dlen; + else if (dlen != 0) { memcpy(tp->fname, dname, dlen); tp->fname[dlen] = '/'; ++dlen; } memcpy(tp->fname + dlen, name, nlen + 1); tp->fnlen = dlen + nlen; - tp->search = tp->fname + tp->fnlen + 1; - memcpy(tp->search, search, (tp->slen = slen) + 1); - CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q); + tp->search = (CHAR_T*)(tp->fname + tp->fnlen + 1); + CHAR2INT(sp, search, slen + 1, wp, wlen); + MEMCPY(tp->search, wp, (tp->slen = slen) + 1); + TAILQ_INSERT_TAIL(tqp->tagq, tp, q); + + /* Try to preset the tag within the current file. */ + if (sp->frp != NULL && sp->frp->name != NULL && + tqp->current == NULL && !strcmp(tp->fname, sp->frp->name)) + tqp->current = tp; } + if (tqp->current == NULL) + tqp->current = TAILQ_FIRST(tqp->tagq); + alloc_err: -done: if (munmap(map, (size_t)sb.st_size)) +done: if (munmap(map, sb.st_size)) msgq(sp, M_SYSERR, "munmap"); if (close(fd)) msgq(sp, M_SYSERR, "close"); @@ -1326,15 +1165,10 @@ done: if (munmap(map, (size_t)sb.st_size)) * Search for the right path to this file. */ static void -ctag_file(sp, tfp, name, dirp, dlenp) - SCR *sp; - TAGF *tfp; - char *name, **dirp; - size_t *dlenp; +ctag_file(SCR *sp, TAGF *tfp, char *name, char **dirp, size_t *dlenp) { struct stat sb; - size_t len; - char *p, buf[MAXPATHLEN]; + char *p, *buf; /* * !!! @@ -1348,12 +1182,16 @@ ctag_file(sp, tfp, name, dirp, dlenp) if (name[0] != '/' && stat(name, &sb) && (p = strrchr(tfp->name, '/')) != NULL) { *p = '\0'; - len = snprintf(buf, sizeof(buf), "%s/%s", tfp->name, name); - *p = '/'; + if ((buf = join(tfp->name, name)) == NULL) { + msgq(sp, M_SYSERR, NULL); + return; + } if (stat(buf, &sb) == 0) { *dirp = tfp->name; *dlenp = strlen(*dirp); } + free(buf); + *p = '/'; } } @@ -1399,11 +1237,11 @@ ctag_file(sp, tfp, name, dirp, dlenp) #define GREATER 1 #define LESS (-1) -#define SKIP_PAST_NEWLINE(p, back) while (p < back && *p++ != '\n'); +#define SKIP_PAST_NEWLINE(p, back) \ + while (p < back && *p++ != '\n') continue; static char * -binary_search(string, front, back) - register char *string, *front, *back; +binary_search(register char *string, register char *front, register char *back) { register char *p; @@ -1433,11 +1271,12 @@ binary_search(string, front, back) * o front is before or at the first line to be printed. */ static char * -linear_search(string, front, back) - char *string, *front, *back; +linear_search(char *string, char *front, char *back, long tl) { + char *end; while (front < back) { - switch (compare(string, front, back)) { + end = tl && back-front > tl ? front+tl : back; + switch (compare(string, front, end)) { case EQUAL: /* Found it. */ return (front); case LESS: /* No such string. */ @@ -1465,8 +1304,7 @@ linear_search(string, front, back) * However, historic programs did use spaces, and, I got complaints. */ static int -compare(s1, s2, back) - register char *s1, *s2, *back; +compare(register char *s1, register char *s2, register char *back) { for (; *s1 && s2 < back && (*s2 != '\t' && *s2 != ' '); ++s1, ++s2) if (*s1 != *s2) diff --git a/contrib/nvi/ex/ex_tcl.c b/contrib/nvi/ex/ex_tcl.c deleted file mode 100644 index 06736a7..0000000 --- a/contrib/nvi/ex/ex_tcl.c +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * Copyright (c) 1992, 1993, 1994, 1995, 1996 - * Keith Bostic. All rights reserved. - * Copyright (c) 1995 - * George V. Neville-Neil. All rights reserved. - * - * See the LICENSE file for redistribution information. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)ex_tcl.c 8.10 (Berkeley) 9/15/96"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/queue.h> - -#include <bitstring.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> -#include <termios.h> -#include <unistd.h> - -#include "../common/common.h" - -#ifdef HAVE_TCL_INTERP -#include <tcl.h> -#endif - -/* - * ex_tcl -- :[line [,line]] tcl [command] - * Run a command through the tcl interpreter. - * - * PUBLIC: int ex_tcl __P((SCR*, EXCMD *)); - */ -int -ex_tcl(sp, cmdp) - SCR *sp; - EXCMD *cmdp; -{ -#ifdef HAVE_TCL_INTERP - CHAR_T *p; - GS *gp; - size_t len; - char buf[128]; - - /* Initialize the interpreter. */ - gp = sp->gp; - if (gp->tcl_interp == NULL && tcl_init(gp)) - return (1); - - /* Skip leading white space. */ - if (cmdp->argc != 0) - for (p = cmdp->argv[0]->bp, - len = cmdp->argv[0]->len; len > 0; --len, ++p) - if (!isblank(*p)) - break; - if (cmdp->argc == 0 || len == 0) { - ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); - return (1); - } - - (void)snprintf(buf, sizeof(buf), - "set viScreenId %d\nset viStartLine %lu\nset viStopLine %lu", - sp->id, cmdp->addr1.lno, cmdp->addr2.lno); - if (Tcl_Eval(gp->tcl_interp, buf) == TCL_OK && - Tcl_Eval(gp->tcl_interp, cmdp->argv[0]->bp) == TCL_OK) - return (0); - - msgq(sp, M_ERR, "Tcl: %s", ((Tcl_Interp *)gp->tcl_interp)->result); - return (1); -#else - msgq(sp, M_ERR, "302|Vi was not loaded with a Tcl interpreter"); - return (1); -#endif /* HAVE_TCL_INTERP */ -} diff --git a/contrib/nvi/ex/ex_txt.c b/contrib/nvi/ex/ex_txt.c index 30bcf97..21d9f44 100644 --- a/contrib/nvi/ex/ex_txt.c +++ b/contrib/nvi/ex/ex_txt.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_txt.c 10.17 (Berkeley) 10/10/96"; +static const char sccsid[] = "$Id: ex_txt.c,v 10.23 2001/06/25 15:19:21 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -24,6 +25,7 @@ static const char sccsid[] = "@(#)ex_txt.c 10.17 (Berkeley) 10/10/96"; #include <string.h> #include "../common/common.h" +#include "../vi/vi.h" /* * !!! @@ -52,11 +54,7 @@ static void txt_prompt __P((SCR *, TEXT *, ARG_CHAR_T, u_int32_t)); * PUBLIC: int ex_txt __P((SCR *, TEXTH *, ARG_CHAR_T, u_int32_t)); */ int -ex_txt(sp, tiqh, prompt, flags) - SCR *sp; - TEXTH *tiqh; - ARG_CHAR_T prompt; - u_int32_t flags; +ex_txt(SCR *sp, TEXTH *tiqh, ARG_CHAR_T prompt, u_int32_t flags) { EVENT ev; GS *gp; @@ -64,6 +62,7 @@ ex_txt(sp, tiqh, prompt, flags) carat_t carat_st; size_t cnt; int rval; + int nochange; rval = 0; @@ -72,9 +71,9 @@ ex_txt(sp, tiqh, prompt, flags) * last one if it's big enough. (All TEXT bookkeeping fields default * to 0 -- text_init() handles this.) */ - if (tiqh->cqh_first != (void *)tiqh) { - tp = tiqh->cqh_first; - if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < 32) { + if (!TAILQ_EMPTY(tiqh)) { + tp = TAILQ_FIRST(tiqh); + if (TAILQ_NEXT(tp, q) != NULL || tp->lb_len < 32) { text_lfree(tiqh); goto newtp; } @@ -82,7 +81,7 @@ ex_txt(sp, tiqh, prompt, flags) } else { newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) goto err; - CIRCLEQ_INSERT_HEAD(tiqh, tp, q); + TAILQ_INSERT_HEAD(tiqh, tp, q); } /* Set the starting line number. */ @@ -112,7 +111,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) txt_prompt(sp, tp, prompt, flags); } - for (carat_st = C_NOTSET;;) { + for (carat_st = C_NOTSET, nochange = 0;;) { if (v_event_get(sp, &ev, 0, 0)) goto err; @@ -146,7 +145,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) * Check to see if the character fits into the input buffer. * (Use tp->len, ignore overwrite and non-printable chars.) */ - BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1); + BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1); switch (ev.e_value) { case K_CR: @@ -189,7 +188,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) */ if (LF_ISSET(TXT_DOTTERM) && tp->len == tp->ai + 1 && tp->lb[tp->len - 1] == '.') { -notlast: CIRCLEQ_REMOVE(tiqh, tp, q); +notlast: TAILQ_REMOVE(tiqh, tp, q); text_free(tp); goto done; } @@ -208,7 +207,8 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); * erased. */ if (LF_ISSET(TXT_AUTOINDENT)) { - if (carat_st == C_NOCHANGE) { + if (nochange) { + nochange = 0; if (v_txt_auto(sp, OOBLNO, &ait, ait.ai, ntp)) goto err; @@ -226,7 +226,7 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); * into the queue. */ tp = ntp; - CIRCLEQ_INSERT_TAIL(tiqh, tp, q); + TAILQ_INSERT_TAIL(tiqh, tp, q); break; case K_CARAT: /* Delete autoindent chars. */ if (tp->len <= tp->ai && LF_ISSET(TXT_AUTOINDENT)) @@ -291,11 +291,12 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); /* Save the ai string for later. */ ait.lb = NULL; ait.lb_len = 0; - BINC_GOTO(sp, ait.lb, ait.lb_len, tp->ai); - memcpy(ait.lb, tp->lb, tp->ai); + BINC_GOTOW(sp, ait.lb, ait.lb_len, tp->ai); + MEMCPY(ait.lb, tp->lb, tp->ai); ait.ai = ait.len = tp->ai; - carat_st = C_NOCHANGE; + carat_st = C_NOTSET; + nochange = 1; goto leftmargin; case C_ZEROSET: /* 0^D */ if (tp->len > tp->ai + 1) @@ -328,7 +329,7 @@ leftmargin: (void)gp->scr_ex_adjust(sp, EX_TERM_CE); * not already handled specially, except for <tab> and * <ff>. */ -ins_ch: if (LF_ISSET(TXT_BEAUTIFY) && iscntrl(ev.e_c) && +ins_ch: if (LF_ISSET(TXT_BEAUTIFY) && ISCNTRL(ev.e_c) && ev.e_value != K_FORMFEED && ev.e_value != K_TAB) break; @@ -352,24 +353,20 @@ alloc_err: * not ours. */ static void -txt_prompt(sp, tp, prompt, flags) - SCR *sp; - TEXT *tp; - ARG_CHAR_T prompt; - u_int32_t flags; +txt_prompt(SCR *sp, TEXT *tp, ARG_CHAR_T prompt, u_int32_t flags) { /* Display the prompt. */ if (LF_ISSET(TXT_PROMPT)) - (void)printf("%c", prompt); + (void)ex_printf(sp, "%c", prompt); /* Display the line number. */ if (LF_ISSET(TXT_NUMBER) && O_ISSET(sp, O_NUMBER)) - (void)printf("%6lu ", (u_long)tp->lno); + (void)ex_printf(sp, "%6lu ", (u_long)tp->lno); /* Print out autoindent string. */ if (LF_ISSET(TXT_AUTOINDENT)) - (void)printf("%.*s", (int)tp->ai, tp->lb); - (void)fflush(stdout); + (void)ex_printf(sp, WVS, (int)tp->ai, tp->lb); + (void)ex_fflush(sp); } /* @@ -380,9 +377,7 @@ txt_prompt(sp, tp, prompt, flags) * ranting and raving. This is a fair bit simpler as ^T isn't special. */ static int -txt_dent(sp, tp) - SCR *sp; - TEXT *tp; +txt_dent(SCR *sp, TEXT *tp) { u_long sw, ts; size_t cno, off, scno, spaces, tabs; @@ -416,7 +411,7 @@ txt_dent(sp, tp) spaces = scno - cno; /* Make sure there's enough room. */ - BINC_RET(sp, tp->lb, tp->lb_len, tabs + spaces + 1); + BINC_RETW(sp, tp->lb, tp->lb_len, tabs + spaces + 1); /* Adjust the final ai character count. */ tp->ai = tabs + spaces; diff --git a/contrib/nvi/ex/ex_undo.c b/contrib/nvi/ex/ex_undo.c index 0b0b5b2..9e4cd79 100644 --- a/contrib/nvi/ex/ex_undo.c +++ b/contrib/nvi/ex/ex_undo.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_undo.c 10.6 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_undo.c,v 10.7 2001/06/25 15:19:21 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -30,9 +31,7 @@ static const char sccsid[] = "@(#)ex_undo.c 10.6 (Berkeley) 3/6/96"; * PUBLIC: int ex_undo __P((SCR *, EXCMD *)); */ int -ex_undo(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_undo(SCR *sp, EXCMD *cmdp) { EXF *ep; MARK m; diff --git a/contrib/nvi/ex/ex_usage.c b/contrib/nvi/ex/ex_usage.c index cddf7a6..9a20ce1 100644 --- a/contrib/nvi/ex/ex_usage.c +++ b/contrib/nvi/ex/ex_usage.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_usage.c 10.13 (Berkeley) 5/3/96"; +static const char sccsid[] = "$Id: ex_usage.c,v 10.16 2011/12/21 19:26:48 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -34,9 +34,7 @@ static const char sccsid[] = "@(#)ex_usage.c 10.13 (Berkeley) 5/3/96"; * PUBLIC: int ex_help __P((SCR *, EXCMD *)); */ int -ex_help(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_help(SCR *sp, EXCMD *cmdp) { (void)ex_puts(sp, "To see the list of vi commands, enter \":viusage<CR>\"\n"); @@ -57,30 +55,28 @@ ex_help(sp, cmdp) * PUBLIC: int ex_usage __P((SCR *, EXCMD *)); */ int -ex_usage(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_usage(SCR *sp, EXCMD *cmdp) { ARGS *ap; EXCMDLIST const *cp; int newscreen; - char *name, *p, nb[MAXCMDNAMELEN + 5]; + CHAR_T *name, *p, nb[MAXCMDNAMELEN + 5]; switch (cmdp->argc) { case 1: ap = cmdp->argv[0]; - if (isupper(ap->bp[0])) { + if (ISUPPER(ap->bp[0])) { newscreen = 1; - ap->bp[0] = tolower(ap->bp[0]); + ap->bp[0] = TOLOWER(ap->bp[0]); } else newscreen = 0; for (cp = cmds; cp->name != NULL && - memcmp(ap->bp, cp->name, ap->len); ++cp); + MEMCMP(ap->bp, cp->name, ap->len); ++cp); if (cp->name == NULL || - newscreen && !F_ISSET(cp, E_NEWSCREEN)) { + (newscreen && !F_ISSET(cp, E_NEWSCREEN))) { if (newscreen) - ap->bp[0] = toupper(ap->bp[0]); - (void)ex_printf(sp, "The %.*s command is unknown\n", + ap->bp[0] = TOUPPER(ap->bp[0]); + (void)ex_printf(sp, "The "WVS" command is unknown\n", (int)ap->len, ap->bp); } else { (void)ex_printf(sp, @@ -112,10 +108,10 @@ ex_usage(sp, cmdp) * room, they're all short names. */ if (cp == &cmds[C_SCROLL]) - name = "^D"; + name = L("^D"); else if (F_ISSET(cp, E_NEWSCREEN)) { nb[0] = '['; - nb[1] = toupper(cp->name[0]); + nb[1] = TOUPPER(cp->name[0]); nb[2] = cp->name[0]; nb[3] = ']'; for (name = cp->name + 1, @@ -124,7 +120,7 @@ ex_usage(sp, cmdp) } else name = cp->name; (void)ex_printf(sp, - "%*s: %s\n", MAXCMDNAMELEN, name, cp->help); + WVS": %s\n", MAXCMDNAMELEN, name, cp->help); } break; default: @@ -140,9 +136,7 @@ ex_usage(sp, cmdp) * PUBLIC: int ex_viusage __P((SCR *, EXCMD *)); */ int -ex_viusage(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_viusage(SCR *sp, EXCMD *cmdp) { GS *gp; VIKEYS const *kp; diff --git a/contrib/nvi/ex/ex_util.c b/contrib/nvi/ex/ex_util.c index 6c4772e..2e56a06 100644 --- a/contrib/nvi/ex/ex_util.c +++ b/contrib/nvi/ex/ex_util.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_util.c 10.23 (Berkeley) 6/19/96"; +static const char sccsid[] = "$Id: ex_util.c,v 10.32 2001/06/25 15:19:21 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -31,15 +31,10 @@ static const char sccsid[] = "@(#)ex_util.c 10.23 (Berkeley) 6/19/96"; * ex_cinit -- * Create an EX command structure. * - * PUBLIC: void ex_cinit __P((EXCMD *, - * PUBLIC: int, int, recno_t, recno_t, int, ARGS **)); + * PUBLIC: void ex_cinit __P((SCR *, EXCMD *, int, int, recno_t, recno_t, int)); */ void -ex_cinit(cmdp, cmd_id, naddr, lno1, lno2, force, ap) - EXCMD *cmdp; - int cmd_id, force, naddr; - recno_t lno1, lno2; - ARGS **ap; +ex_cinit(SCR *sp, EXCMD *cmdp, int cmd_id, int naddr, recno_t lno1, recno_t lno2, int force) { memset(cmdp, 0, sizeof(EXCMD)); cmdp->cmd = &cmds[cmd_id]; @@ -49,28 +44,7 @@ ex_cinit(cmdp, cmd_id, naddr, lno1, lno2, force, ap) cmdp->addr1.cno = cmdp->addr2.cno = 1; if (force) cmdp->iflags |= E_C_FORCE; - cmdp->argc = 0; - if ((cmdp->argv = ap) != NULL) - cmdp->argv[0] = NULL; -} - -/* - * ex_cadd -- - * Add an argument to an EX command structure. - * - * PUBLIC: void ex_cadd __P((EXCMD *, ARGS *, char *, size_t)); - */ -void -ex_cadd(cmdp, ap, arg, len) - EXCMD *cmdp; - ARGS *ap; - char *arg; - size_t len; -{ - cmdp->argv[cmdp->argc] = ap; - ap->bp = arg; - ap->len = len; - cmdp->argv[++cmdp->argc] = NULL; + (void)argv_init(sp, cmdp); } /* @@ -80,10 +54,7 @@ ex_cadd(cmdp, ap, arg, len) * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *)); */ int -ex_getline(sp, fp, lenp) - SCR *sp; - FILE *fp; - size_t *lenp; +ex_getline(SCR *sp, FILE *fp, size_t *lenp) { EX_PRIVATE *exp; size_t off; @@ -93,7 +64,7 @@ ex_getline(sp, fp, lenp) exp = EXP(sp); for (errno = 0, off = 0, p = exp->ibp;;) { if (off >= exp->ibp_len) { - BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1); + BINC_RETC(sp, exp->ibp, exp->ibp_len, off + 1); p = exp->ibp + off; } if ((ch = getc(fp)) == EOF && !feof(fp)) { @@ -123,9 +94,7 @@ ex_getline(sp, fp, lenp) * PUBLIC: int ex_ncheck __P((SCR *, int)); */ int -ex_ncheck(sp, force) - SCR *sp; - int force; +ex_ncheck(SCR *sp, int force) { char **ap; @@ -140,7 +109,7 @@ ex_ncheck(sp, force) for (ap = sp->cargv + 1; *ap != NULL; ++ap); msgq(sp, M_ERR, - "167|%d more files to edit", (ap - sp->cargv) - 1); + "167|%d more files to edit", (int)(ap - sp->cargv) - 1); return (1); } @@ -154,8 +123,7 @@ ex_ncheck(sp, force) * PUBLIC: int ex_init __P((SCR *)); */ int -ex_init(sp) - SCR *sp; +ex_init(SCR *sp) { GS *gp; @@ -177,13 +145,27 @@ ex_init(sp) * ex_emsg -- * Display a few common ex and vi error messages. * + * PUBLIC: void ex_wemsg __P((SCR *, CHAR_T *, exm_t)); + */ +void +ex_wemsg(SCR* sp, CHAR_T *p, exm_t which) +{ + char *np; + size_t nlen; + + if (p) INT2CHAR(sp, p, STRLEN(p), np, nlen); + else np = NULL; + ex_emsg(sp, np, which); +} + +/* + * ex_emsg -- + * Display a few common ex and vi error messages. + * * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t)); */ void -ex_emsg(sp, p, which) - SCR *sp; - char *p; - exm_t which; +ex_emsg(SCR *sp, char *p, exm_t which) { switch (which) { case EXM_EMPTYBUF: diff --git a/contrib/nvi/ex/ex_version.c b/contrib/nvi/ex/ex_version.c index d7363c8..4f0a17d 100644 --- a/contrib/nvi/ex/ex_version.c +++ b/contrib/nvi/ex/ex_version.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_version.c 10.31 (Berkeley) 8/22/96"; +static const char sccsid[] = "$Id: ex_version.c,v 10.32 2001/06/25 15:19:22 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -30,10 +31,9 @@ static const char sccsid[] = "@(#)ex_version.c 10.31 (Berkeley) 8/22/96"; * PUBLIC: int ex_version __P((SCR *, EXCMD *)); */ int -ex_version(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_version(SCR *sp, EXCMD *cmdp) { - msgq(sp, M_INFO, VI_VERSION); + msgq(sp, M_INFO, "Version "VI_VERSION + " The CSRG, University of California, Berkeley."); return (0); } diff --git a/contrib/nvi/ex/ex_visual.c b/contrib/nvi/ex/ex_visual.c index 94479439..f913c71 100644 --- a/contrib/nvi/ex/ex_visual.c +++ b/contrib/nvi/ex/ex_visual.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_visual.c 10.13 (Berkeley) 6/28/96"; +static const char sccsid[] = "$Id: ex_visual.c,v 10.16 2001/08/29 11:04:13 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -34,14 +34,14 @@ static const char sccsid[] = "@(#)ex_visual.c 10.13 (Berkeley) 6/28/96"; * PUBLIC: int ex_visual __P((SCR *, EXCMD *)); */ int -ex_visual(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_visual(SCR *sp, EXCMD *cmdp) { SCR *tsp; size_t len; int pos; char buf[256]; + size_t wlen; + CHAR_T *wp; /* If open option off, disallow visual command. */ if (!O_ISSET(sp, O_OPEN)) { @@ -83,9 +83,9 @@ ex_visual(sp, cmdp) len = snprintf(buf, sizeof(buf), "%luz%c%lu", (u_long)sp->lno, pos, cmdp->count); else - len = snprintf(buf, sizeof(buf), "%luz%c", - (u_long)sp->lno, pos); - (void)v_event_push(sp, NULL, buf, len, CH_NOMAP | CH_QUOTED); + len = snprintf(buf, sizeof(buf), "%luz%c", (u_long)sp->lno, pos); + CHAR2INT(sp, buf, len, wp, wlen); + (void)v_event_push(sp, NULL, wp, wlen, CH_NOMAP | CH_QUOTED); /* * !!! @@ -130,6 +130,7 @@ nopush: /* */ ++sp->refcnt; ++sp->ep->refcnt; + /* XXXX where is this decremented ? */ /* * Fake up a screen pointer -- vi doesn't get to change our diff --git a/contrib/nvi/ex/ex_write.c b/contrib/nvi/ex/ex_write.c index b3122e3..1f94a63 100644 --- a/contrib/nvi/ex/ex_write.c +++ b/contrib/nvi/ex/ex_write.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_write.c 10.30 (Berkeley) 7/12/96"; +static const char sccsid[] = "$Id: ex_write.c,v 10.41 2011/12/02 01:07:06 zy Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -25,6 +25,7 @@ static const char sccsid[] = "@(#)ex_write.c 10.30 (Berkeley) 7/12/96"; #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> #include <unistd.h> #include "../common/common.h" @@ -39,9 +40,7 @@ static int exwr __P((SCR *, EXCMD *, enum which)); * PUBLIC: int ex_wn __P((SCR *, EXCMD *)); */ int -ex_wn(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_wn(SCR *sp, EXCMD *cmdp) { if (exwr(sp, cmdp, WN)) return (1); @@ -61,9 +60,7 @@ ex_wn(sp, cmdp) * PUBLIC: int ex_wq __P((SCR *, EXCMD *)); */ int -ex_wq(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_wq(SCR *sp, EXCMD *cmdp) { int force; @@ -89,9 +86,7 @@ ex_wq(sp, cmdp) * PUBLIC: int ex_write __P((SCR *, EXCMD *)); */ int -ex_write(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_write(SCR *sp, EXCMD *cmdp) { return (exwr(sp, cmdp, WRITE)); } @@ -104,9 +99,7 @@ ex_write(sp, cmdp) * PUBLIC: int ex_xit __P((SCR *, EXCMD *)); */ int -ex_xit(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_xit(SCR *sp, EXCMD *cmdp) { int force; @@ -131,14 +124,16 @@ ex_xit(sp, cmdp) * The guts of the ex write commands. */ static int -exwr(sp, cmdp, cmd) - SCR *sp; - EXCMD *cmdp; - enum which cmd; +exwr(SCR *sp, EXCMD *cmdp, enum which cmd) { MARK rm; int flags; - char *name, *p; + char *name; + CHAR_T *p = NULL; + size_t nlen; + char *n; + int rc; + EX_PRIVATE *exp; NEEDFILE(sp, cmdp); @@ -149,25 +144,31 @@ exwr(sp, cmdp, cmd) /* Skip any leading whitespace. */ if (cmdp->argc != 0) - for (p = cmdp->argv[0]->bp; *p != '\0' && isblank(*p); ++p); + for (p = cmdp->argv[0]->bp; *p != '\0' && cmdskip(*p); ++p); /* If "write !" it's a pipe to a utility. */ if (cmdp->argc != 0 && cmd == WRITE && *p == '!') { /* Secure means no shell access. */ if (O_ISSET(sp, O_SECURE)) { - ex_emsg(sp, cmdp->cmd->name, EXM_SECURE_F); + ex_wemsg(sp, cmdp->cmd->name, EXM_SECURE_F); return (1); } /* Expand the argument. */ - for (++p; *p && isblank(*p); ++p); + for (++p; *p && cmdskip(*p); ++p); if (*p == '\0') { ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); return (1); } - if (argv_exp1(sp, cmdp, p, strlen(p), 1)) + if (argv_exp1(sp, cmdp, p, STRLEN(p), 1)) return (1); + /* Set the last bang command */ + exp = EXP(sp); + free(exp->lastbcomm); + exp->lastbcomm = v_wstrdup(sp, cmdp->argv[1]->bp, + cmdp->argv[1]->len); + /* * Historically, vi waited after a write filter even if there * wasn't any output from the command. People complained when @@ -201,7 +202,7 @@ exwr(sp, cmdp, cmd) LF_SET(FS_APPEND); /* Skip ">>" and whitespace. */ - for (p += 2; *p && isblank(*p); ++p); + for (p += 2; *p && cmdskip(*p); ++p); } /* If no other arguments, just write the file back. */ @@ -210,7 +211,7 @@ exwr(sp, cmdp, cmd) &cmdp->addr1, &cmdp->addr2, NULL, flags)); /* Build an argv so we get an argument count and file expansion. */ - if (argv_exp2(sp, cmdp, p, strlen(p))) + if (argv_exp2(sp, cmdp, p, STRLEN(p))) return (1); /* @@ -228,7 +229,9 @@ exwr(sp, cmdp, cmd) abort(); /* NOTREACHED */ case 2: - name = cmdp->argv[1]->bp; + INT2CHAR(sp, cmdp->argv[1]->bp, cmdp->argv[1]->len+1, + n, nlen); + name = v_strdup(sp, n, nlen - 1); /* * !!! @@ -238,10 +241,9 @@ exwr(sp, cmdp, cmd) */ if (F_ISSET(sp->frp, FR_TMPFILE) && !F_ISSET(sp->frp, FR_EXNAMED)) { - if ((p = v_strdup(sp, - cmdp->argv[1]->bp, cmdp->argv[1]->len)) != NULL) { + if ((n = v_strdup(sp, name, nlen - 1)) != NULL) { free(sp->frp->name); - sp->frp->name = p; + sp->frp->name = n; } /* * The file has a real name, it's no longer a @@ -261,11 +263,16 @@ exwr(sp, cmdp, cmd) set_alt_name(sp, name); break; default: - ex_emsg(sp, p, EXM_FILECOUNT); + INT2CHAR(sp, p, STRLEN(p) + 1, n, nlen); + ex_emsg(sp, n, EXM_FILECOUNT); return (1); } - return (file_write(sp, &cmdp->addr1, &cmdp->addr2, name, flags)); + rc = file_write(sp, &cmdp->addr1, &cmdp->addr2, name, flags); + + free(name); + + return rc; } /* @@ -276,13 +283,7 @@ exwr(sp, cmdp, cmd) * PUBLIC: char *, FILE *, MARK *, MARK *, u_long *, u_long *, int)); */ int -ex_writefp(sp, name, fp, fm, tm, nlno, nch, silent) - SCR *sp; - char *name; - FILE *fp; - MARK *fm, *tm; - u_long *nlno, *nch; - int silent; +ex_writefp(SCR *sp, char *name, FILE *fp, MARK *fm, MARK *tm, u_long *nlno, u_long *nch, int silent) { struct stat sb; GS *gp; @@ -290,7 +291,11 @@ ex_writefp(sp, name, fp, fm, tm, nlno, nch, silent) recno_t fline, tline, lcnt; size_t len; int rval; - char *msg, *p; + char *msg; + CHAR_T *p; + char *f; + size_t flen; + int isutf16; gp = sp->gp; fline = fm->lno; @@ -319,7 +324,17 @@ ex_writefp(sp, name, fp, fm, tm, nlno, nch, silent) ccnt = 0; lcnt = 0; msg = "253|Writing..."; - if (tline != 0) + + if (O_ISSET(sp, O_FILEENCODING)) { + isutf16 = !strncasecmp(O_STR(sp, O_FILEENCODING), "utf-16", 6); + isutf16 += !strncasecmp(O_STR(sp, O_FILEENCODING), "utf-16le", 8); + } else isutf16 = 0; + + if (tline != 0) { + if (isutf16 == 1 && fwrite("\xfe\xff", 1, 2, fp) != 2) + goto err; + if (isutf16 == 2 && fwrite("\xff\xfe", 1, 2, fp) != 2) + goto err; for (; fline <= tline; ++fline, ++lcnt) { /* Caller has to provide any interrupt message. */ if ((lcnt + 1) % INTERRUPT_CHECK == 0) { @@ -333,15 +348,29 @@ ex_writefp(sp, name, fp, fm, tm, nlno, nch, silent) } if (db_get(sp, fline, DBG_FATAL, &p, &len)) goto err; - if (fwrite(p, 1, len, fp) != len) + INT2FILE(sp, p, len, f, flen); + if (fwrite(f, 1, flen, fp) != flen) goto err; ccnt += len; - if (putc('\n', fp) != '\n') + /* UTF-16 w/o BOM is big-endian */ + switch (isutf16) { + case 1: /* UTF-16BE */ + if (fwrite("\0\x0a", 1, 2, fp) != 2) + goto done; + break; + case 2: /* UTF-16LE */ + if (fwrite("\x0a\0", 1, 2, fp) != 2) + goto done; break; + default: + if (putc('\n', fp) != '\n') + goto done; + } ++ccnt; } + } - if (fflush(fp)) +done: if (fflush(fp)) goto err; /* * XXX diff --git a/contrib/nvi/ex/ex_yank.c b/contrib/nvi/ex/ex_yank.c index 778dc7d..262c78f 100644 --- a/contrib/nvi/ex/ex_yank.c +++ b/contrib/nvi/ex/ex_yank.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_yank.c 10.7 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_yank.c,v 10.8 2001/06/25 15:19:22 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -29,9 +30,7 @@ static const char sccsid[] = "@(#)ex_yank.c 10.7 (Berkeley) 3/6/96"; * PUBLIC: int ex_yank __P((SCR *, EXCMD *)); */ int -ex_yank(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_yank(SCR *sp, EXCMD *cmdp) { NEEDFILE(sp, cmdp); diff --git a/contrib/nvi/ex/ex_z.c b/contrib/nvi/ex/ex_z.c index 41b72ad..18a7859 100644 --- a/contrib/nvi/ex/ex_z.c +++ b/contrib/nvi/ex/ex_z.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_z.c 10.10 (Berkeley) 3/6/96"; +static const char sccsid[] = "$Id: ex_z.c,v 10.12 2001/06/25 15:19:22 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <limits.h> @@ -31,9 +32,7 @@ static const char sccsid[] = "@(#)ex_z.c 10.10 (Berkeley) 3/6/96"; * PUBLIC: int ex_z __P((SCR *, EXCMD *)); */ int -ex_z(sp, cmdp) - SCR *sp; - EXCMD *cmdp; +ex_z(SCR *sp, EXCMD *cmdp) { MARK abs; recno_t cnt, equals, lno; @@ -55,7 +54,7 @@ ex_z(sp, cmdp) if (FL_ISSET(cmdp->iflags, E_C_COUNT)) cnt = cmdp->count; else -#ifdef HISTORIC_PRACTICE +#ifdef HISTORICAL_PRACTICE cnt = O_VAL(sp, O_SCROLL) * 2; #else cnt = O_VAL(sp, O_WINDOW) - 1; diff --git a/contrib/nvi/ex/extern.h b/contrib/nvi/ex/extern.h new file mode 100644 index 0000000..f54548b --- /dev/null +++ b/contrib/nvi/ex/extern.h @@ -0,0 +1,130 @@ +int ex __P((SCR **)); +int ex_cmd __P((SCR *)); +int ex_range __P((SCR *, EXCMD *, int *)); +int ex_is_abbrev __P((CHAR_T *, size_t)); +int ex_is_unmap __P((CHAR_T *, size_t)); +void ex_badaddr + __P((SCR *, EXCMDLIST const *, enum badaddr, enum nresult)); +int ex_abbr __P((SCR *, EXCMD *)); +int ex_unabbr __P((SCR *, EXCMD *)); +int ex_append __P((SCR *, EXCMD *)); +int ex_change __P((SCR *, EXCMD *)); +int ex_insert __P((SCR *, EXCMD *)); +int ex_next __P((SCR *, EXCMD *)); +int ex_prev __P((SCR *, EXCMD *)); +int ex_rew __P((SCR *, EXCMD *)); +int ex_args __P((SCR *, EXCMD *)); +char **ex_buildargv __P((SCR *, EXCMD *, char *)); +int argv_init __P((SCR *, EXCMD *)); +int argv_exp0 __P((SCR *, EXCMD *, CHAR_T *, size_t)); +int argv_exp1 __P((SCR *, EXCMD *, CHAR_T *, size_t, int)); +int argv_exp2 __P((SCR *, EXCMD *, CHAR_T *, size_t)); +int argv_exp3 __P((SCR *, EXCMD *, CHAR_T *, size_t)); +int argv_flt_ex __P((SCR *, EXCMD *, CHAR_T *, size_t)); +int argv_free __P((SCR *)); +int argv_flt_path __P((SCR *, EXCMD *, CHAR_T *, size_t)); +CHAR_T *argv_esc __P((SCR *, EXCMD *, CHAR_T *, size_t)); +CHAR_T *argv_uesc __P((SCR *, EXCMD *, CHAR_T *, size_t)); +int ex_at __P((SCR *, EXCMD *)); +int ex_bang __P((SCR *, EXCMD *)); +int ex_cd __P((SCR *, EXCMD *)); +int ex_cscope __P((SCR *, EXCMD *)); +int cscope_end __P((SCR *)); +int cscope_display __P((SCR *)); +int cscope_search __P((SCR *, TAGQ *, TAG *)); +int ex_delete __P((SCR *, EXCMD *)); +int ex_display __P((SCR *, EXCMD *)); +int ex_edit __P((SCR *, EXCMD *)); +int ex_equal __P((SCR *, EXCMD *)); +int ex_file __P((SCR *, EXCMD *)); +int ex_filter __P((SCR *, + EXCMD *, MARK *, MARK *, MARK *, CHAR_T *, enum filtertype)); +int ex_global __P((SCR *, EXCMD *)); +int ex_v __P((SCR *, EXCMD *)); +int ex_g_insdel __P((SCR *, lnop_t, recno_t)); +int ex_screen_copy __P((SCR *, SCR *)); +int ex_screen_end __P((SCR *)); +int ex_optchange __P((SCR *, int, char *, u_long *)); +int ex_exrc __P((SCR *)); +int ex_run_str __P((SCR *, char *, CHAR_T *, size_t, int, int)); +int ex_join __P((SCR *, EXCMD *)); +int ex_map __P((SCR *, EXCMD *)); +int ex_unmap __P((SCR *, EXCMD *)); +int ex_mark __P((SCR *, EXCMD *)); +int ex_mkexrc __P((SCR *, EXCMD *)); +int ex_copy __P((SCR *, EXCMD *)); +int ex_move __P((SCR *, EXCMD *)); +int ex_open __P((SCR *, EXCMD *)); +int ex_preserve __P((SCR *, EXCMD *)); +int ex_recover __P((SCR *, EXCMD *)); +int ex_list __P((SCR *, EXCMD *)); +int ex_number __P((SCR *, EXCMD *)); +int ex_pr __P((SCR *, EXCMD *)); +int ex_print __P((SCR *, EXCMD *, MARK *, MARK *, u_int32_t)); +int ex_ldisplay __P((SCR *, const CHAR_T *, size_t, size_t, u_int)); +int ex_scprint __P((SCR *, MARK *, MARK *)); +int ex_printf __P((SCR *, const char *, ...)); +int ex_puts __P((SCR *, const char *)); +int ex_fflush __P((SCR *sp)); +int ex_put __P((SCR *, EXCMD *)); +int ex_quit __P((SCR *, EXCMD *)); +int ex_read __P((SCR *, EXCMD *)); +int ex_readfp __P((SCR *, char *, FILE *, MARK *, recno_t *, int)); +int ex_bg __P((SCR *, EXCMD *)); +int ex_fg __P((SCR *, EXCMD *)); +int ex_resize __P((SCR *, EXCMD *)); +int ex_sdisplay __P((SCR *)); +int ex_script __P((SCR *, EXCMD *)); +int sscr_exec __P((SCR *, recno_t)); +int sscr_input __P((SCR *)); +int sscr_end __P((SCR *)); +int ex_set __P((SCR *, EXCMD *)); +int ex_shell __P((SCR *, EXCMD *)); +int ex_exec_proc __P((SCR *, EXCMD *, char *, const char *, int)); +int proc_wait __P((SCR *, long, const char *, int, int)); +int ex_shiftl __P((SCR *, EXCMD *)); +int ex_shiftr __P((SCR *, EXCMD *)); +int ex_source __P((SCR *, EXCMD *)); +int ex_stop __P((SCR *, EXCMD *)); +int ex_s __P((SCR *, EXCMD *)); +int ex_subagain __P((SCR *, EXCMD *)); +int ex_subtilde __P((SCR *, EXCMD *)); +int re_compile __P((SCR *, + CHAR_T *, size_t, CHAR_T **, size_t *, regex_t *, u_int)); +void re_error __P((SCR *, int, regex_t *)); +int ex_tag_first __P((SCR *, CHAR_T *)); +int ex_tag_push __P((SCR *, EXCMD *)); +int ex_tag_next __P((SCR *, EXCMD *)); +int ex_tag_prev __P((SCR *, EXCMD *)); +int ex_tag_nswitch __P((SCR *, TAG *, int)); +int ex_tag_Nswitch __P((SCR *, TAG *, int)); +int ex_tag_pop __P((SCR *, EXCMD *)); +int ex_tag_top __P((SCR *, EXCMD *)); +int ex_tag_display __P((SCR *)); +int ex_tag_copy __P((SCR *, SCR *)); +int tagq_free __P((SCR *, TAGQ *)); +int tagq_push __P((SCR*, TAGQ*, int, int )); +void tag_msg __P((SCR *, tagmsg_t, char *)); +int ex_tagf_alloc __P((SCR *, char *)); +int ex_tag_free __P((SCR *)); +int ex_txt __P((SCR *, TEXTH *, ARG_CHAR_T, u_int32_t)); +int ex_undo __P((SCR *, EXCMD *)); +int ex_help __P((SCR *, EXCMD *)); +int ex_usage __P((SCR *, EXCMD *)); +int ex_viusage __P((SCR *, EXCMD *)); +void ex_cinit __P((SCR *, EXCMD *, int, int, recno_t, recno_t, int)); +int ex_getline __P((SCR *, FILE *, size_t *)); +int ex_ncheck __P((SCR *, int)); +int ex_init __P((SCR *)); +void ex_wemsg __P((SCR *, CHAR_T *, exm_t)); +void ex_emsg __P((SCR *, char *, exm_t)); +int ex_version __P((SCR *, EXCMD *)); +int ex_visual __P((SCR *, EXCMD *)); +int ex_wn __P((SCR *, EXCMD *)); +int ex_wq __P((SCR *, EXCMD *)); +int ex_write __P((SCR *, EXCMD *)); +int ex_xit __P((SCR *, EXCMD *)); +int ex_writefp __P((SCR *, + char *, FILE *, MARK *, MARK *, u_long *, u_long *, int)); +int ex_yank __P((SCR *, EXCMD *)); +int ex_z __P((SCR *, EXCMD *)); diff --git a/contrib/nvi/ex/script.h b/contrib/nvi/ex/script.h index e29f633..3952e96 100644 --- a/contrib/nvi/ex/script.h +++ b/contrib/nvi/ex/script.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * @(#)script.h 10.2 (Berkeley) 3/6/96 + * $Id: script.h,v 10.3 2012/04/21 23:51:46 zy Exp $ */ struct _script { @@ -16,8 +16,6 @@ struct _script { char *sh_prompt; /* Prompt. */ size_t sh_prompt_len; /* Prompt length. */ char sh_name[64]; /* Pty name */ -#ifdef TIOCGWINSZ struct winsize sh_win; /* Window size. */ -#endif struct termios sh_term; /* Terminal information. */ }; diff --git a/contrib/nvi/ex/tag.h b/contrib/nvi/ex/tag.h index aee3dd2..7d3b247 100644 --- a/contrib/nvi/ex/tag.h +++ b/contrib/nvi/ex/tag.h @@ -8,7 +8,7 @@ * * See the LICENSE file for redistribution information. * - * @(#)tag.h 10.5 (Berkeley) 5/15/96 + * $Id: tag.h,v 10.9 2012/07/06 16:38:36 zy Exp $ */ /* @@ -16,12 +16,12 @@ * connection, linked from the EX_PRIVATE structure. */ struct _csc { - LIST_ENTRY(_csc) q; /* Linked list of cscope connections. */ + SLIST_ENTRY(_csc) q; /* Linked list of cscope connections. */ - char *dname; /* Base directory of this cscope connection. */ - size_t dlen; /* Length of base directory. */ - pid_t pid; /* PID of the connected cscope process. */ - time_t mtime; /* Last modification time of cscope database. */ + char *dname; /* Base directory of this cscope connection. */ + size_t dlen; /* Length of base directory. */ + pid_t pid; /* PID of the connected cscope process. */ + struct timespec mtim; /* Last modification time of cscope database. */ FILE *from_fp; /* from cscope: FILE. */ int from_fd; /* from cscope: file descriptor. */ @@ -74,7 +74,7 @@ struct _tagf { /* Tag files. */ * tagtop: discard all Q */ struct _tag { /* Tag list. */ - CIRCLEQ_ENTRY(_tag) q; /* Linked list of tags. */ + TAILQ_ENTRY(_tag) q; /* Linked list of tags. */ /* Tag pop/return information. */ FREF *frp; /* Saved file. */ @@ -84,16 +84,18 @@ struct _tag { /* Tag list. */ char *fname; /* Filename. */ size_t fnlen; /* Filename length. */ recno_t slno; /* Search line number. */ - char *search; /* Search string. */ + CHAR_T *search; /* Search string. */ size_t slen; /* Search string length. */ + CHAR_T *msg; /* Message string. */ + size_t mlen; /* Message string length. */ - char buf[1]; /* Variable length buffer. */ + CHAR_T buf[1]; /* Variable length buffer. */ }; struct _tagq { /* Tag queue. */ - CIRCLEQ_ENTRY(_tagq) q; /* Linked list of tag queues. */ + TAILQ_ENTRY(_tagq) q; /* Linked list of tag queues. */ /* This queue's tag list. */ - CIRCLEQ_HEAD(_tagqh, _tag) tagq; + TAILQ_HEAD(_tagqh, _tag) tagq[1]; TAG *current; /* Current TAG within the queue. */ diff --git a/contrib/nvi/ex/version.h b/contrib/nvi/ex/version.h index 7d657b6..295dd8e 100644 --- a/contrib/nvi/ex/version.h +++ b/contrib/nvi/ex/version.h @@ -1,2 +1 @@ -#define VI_VERSION \ - "Version 1.79 (10/23/96) The CSRG, University of California, Berkeley." +#define VI_VERSION "2.1.1 (2012-10-07)" |