diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2016-01-06 22:29:39 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2016-01-06 22:29:39 +0000 |
commit | 74f1e2fed47cfb3fe673015d1159ec40d72866a3 (patch) | |
tree | a7880dea29269973134f6a08be2d98b783cd2928 /usr.bin/vi | |
parent | 6ecd686c369d3893ce5d4df22d01170b10cc1047 (diff) |
Remove the msg_cat() function and adjust its former callers.
From Martijn van Duren
Diffstat (limited to 'usr.bin/vi')
-rw-r--r-- | usr.bin/vi/common/exf.c | 11 | ||||
-rw-r--r-- | usr.bin/vi/common/msg.c | 101 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_append.c | 6 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_bang.c | 6 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_print.c | 4 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_subst.c | 5 | ||||
-rw-r--r-- | usr.bin/vi/include/com_extern.h | 3 | ||||
-rw-r--r-- | usr.bin/vi/vi/vs_msg.c | 6 | ||||
-rw-r--r-- | usr.bin/vi/vi/vs_refresh.c | 6 |
9 files changed, 57 insertions, 91 deletions
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c index 8071ffb301b..7938cf17d7f 100644 --- a/usr.bin/vi/common/exf.c +++ b/usr.bin/vi/common/exf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exf.c,v 1.40 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: exf.c,v 1.41 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -914,16 +914,15 @@ file_write(SCR *sp, MARK *fm, MARK *tm, char *name, int flags) p = msg_print(sp, name, &nf); switch (mtype) { case NEWFILE: - msgstr = msg_cat(sp, - "%s: new file: %lu lines, %lu characters", NULL); - len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch); + len = snprintf(buf, sizeof(buf), + "%s: new file: %lu lines, %lu characters", p, nlno, nch); if (len >= sizeof(buf)) len = sizeof(buf) - 1; break; case OLDFILE: - msgstr = msg_cat(sp, LF_ISSET(FS_APPEND) ? + msgstr = LF_ISSET(FS_APPEND) ? "%s: appended: %lu lines, %lu characters" : - "%s: %lu lines, %lu characters", NULL); + "%s: %lu lines, %lu characters", NULL; len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch); if (len >= sizeof(buf)) len = sizeof(buf) - 1; diff --git a/usr.bin/vi/common/msg.c b/usr.bin/vi/common/msg.c index 4339a913d32..4d164ad1236 100644 --- a/usr.bin/vi/common/msg.c +++ b/usr.bin/vi/common/msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msg.c,v 1.25 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: msg.c,v 1.26 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -115,7 +115,8 @@ retry: FREE_SPACE(sp, bp, blen); mp = bp; mlen = 0; if (mt == M_SYSERR) { - p = msg_cat(sp, "Error: ", &len); + p = "Error: "; + len = strlen(p); if (REM < len) goto retry; memcpy(mp, p, len); @@ -146,7 +147,6 @@ retry: FREE_SPACE(sp, bp, blen); len = 0; goto nofmt; } - fmt = msg_cat(sp, fmt, NULL); /* Format the arguments into the string. */ va_start(ap, fmt); @@ -303,15 +303,15 @@ mod_rpt(SCR *sp) len = snprintf(p, MAXNUM, "%u ", sp->rptlines[cnt]); p += len; tlen += len; - t = msg_cat(sp, - lines[sp->rptlines[cnt] == 1 ? 0 : 1], &len); + t = lines[sp->rptlines[cnt] == 1 ? 0 : 1]; + len = strlen(t); memcpy(p, t, len); p += len; tlen += len; *p++ = ' '; ++tlen; - t = msg_cat(sp, *ap, &len); - memcpy(p, t, len); + len = strlen(*ap); + memcpy(p, *ap, len); p += len; tlen += len; sp->rptlines[cnt] = 0; @@ -367,8 +367,7 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) if (F_ISSET(sp, SC_STATUS_CNT) && sp->argv != NULL) { for (cnt = 0, ap = sp->argv; *ap != NULL; ++ap, ++cnt); if (cnt > 1) { - (void)snprintf(p, ep - p, - msg_cat(sp, "%d files to edit", NULL), cnt); + (void)snprintf(p, ep - p, "%d files to edit", cnt); p += strlen(p); *p++ = ':'; *p++ = ' '; @@ -386,14 +385,14 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) needsep = 0; if (F_ISSET(sp->frp, FR_NEWFILE)) { F_CLR(sp->frp, FR_NEWFILE); - t = msg_cat(sp, "new file", &len); - memcpy(p, t, len); + len = strlen("new file"); + memcpy(p, "new file", len); p += len; needsep = 1; } else { if (F_ISSET(sp->frp, FR_NAMECHANGE)) { - t = msg_cat(sp, "name changed", &len); - memcpy(p, t, len); + len = strlen("name changed"); + memcpy(p, "name changed", len); p += len; needsep = 1; } @@ -401,10 +400,8 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) *p++ = ','; *p++ = ' '; } - if (F_ISSET(sp->ep, F_MODIFIED)) - t = msg_cat(sp, "modified", &len); - else - t = msg_cat(sp, "unmodified", &len); + t = (F_ISSET(sp->ep, F_MODIFIED)) ? "modified" : "unmodified"; + len = strlen(t); memcpy(p, t, len); p += len; needsep = 1; @@ -414,8 +411,8 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) *p++ = ','; *p++ = ' '; } - t = msg_cat(sp, "UNLOCKED", &len); - memcpy(p, t, len); + len = strlen("UNLOCKED"); + memcpy(p, "UNLOCKED", len); p += len; needsep = 1; } @@ -424,8 +421,8 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) *p++ = ','; *p++ = ' '; } - t = msg_cat(sp, "readonly", &len); - memcpy(p, t, len); + len = strlen("readonly"); + memcpy(p, "readonly", len); p += len; needsep = 1; } @@ -437,18 +434,16 @@ msgq_status(SCR *sp, recno_t lno, u_int flags) if (db_last(sp, &last)) return; if (last == 0) { - t = msg_cat(sp, "empty file", &len); - memcpy(p, t, len); + len = strlen("emptry file"); + memcpy(p, "empty file", len); p += len; } else { - t = msg_cat(sp, "line %lu of %lu [%ld%%]", &len); - (void)snprintf(p, ep - p, t, lno, last, - (lno * 100) / last); + (void)snprintf(p, ep - p, "line %lu of %lu [%ld%%]", + lno, last, (lno * 100) / last); p += strlen(p); } } else { - t = msg_cat(sp, "line %lu", &len); - (void)snprintf(p, ep - p, t, lno); + (void)snprintf(p, ep - p, "line %lu", lno); p += strlen(p); } #ifdef DEBUG @@ -505,51 +500,31 @@ alloc_err: const char * msg_cmsg(SCR *sp, cmsg_t which, size_t *lenp) { + const char *s; switch (which) { case CMSG_CONF: - return (msg_cat(sp, "confirm? [ynq]", lenp)); + s = "confirm? [ynq]"; + break; case CMSG_CONT: - return (msg_cat(sp, "Press any key to continue: ", lenp)); + s = "Press any key to continue: "; + break; case CMSG_CONT_EX: - return (msg_cat(sp, - "Press any key to continue [: to enter more ex commands]: ", - lenp)); + s = "Press any key to continue [: to enter more ex commands]: "; + break; case CMSG_CONT_R: - return (msg_cat(sp, "Press Enter to continue: ", lenp)); + s = "Press Enter to continue: "; + break; case CMSG_CONT_S: - return (msg_cat(sp, " cont?", lenp)); + s = " cont?"; + break; case CMSG_CONT_Q: - return (msg_cat(sp, - "Press any key to continue [q to quit]: ", lenp)); + s = "Press any key to continue [q to quit]: "; + break; default: abort(); } - /* NOTREACHED */ -} - -/* - * msg_cat -- - * Return a single message from the catalog, plus its length. - * - * PUBLIC: const char *msg_cat(SCR *, const char *, size_t *); - */ -const char * -msg_cat(SCR *sp, const char *str, size_t *lenp) -{ - GS *gp; - DBT data, key; - recno_t msgno; - - /* - * If it's not a catalog message, i.e. has doesn't have a leading - * number and '|' symbol, we're done. - */ - if (isdigit(str[0]) && - isdigit(str[1]) && isdigit(str[2]) && str[3] == '|') - str = &str[4]; - if (lenp != NULL) - *lenp = strlen(str); - return (str); + *lenp = strlen(s); + return s; } /* diff --git a/usr.bin/vi/ex/ex_append.c b/usr.bin/vi/ex/ex_append.c index 8f4465541cc..20431d460c8 100644 --- a/usr.bin/vi/ex/ex_append.c +++ b/usr.bin/vi/ex/ex_append.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_append.c,v 1.11 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: ex_append.c,v 1.12 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -218,9 +218,7 @@ ex_aci(SCR *sp, EXCMD *cmdp, enum which cmd) * when they enter append mode, and can't seem to get out of * it. Give them an informational message. */ - (void)ex_puts(sp, - msg_cat(sp, "Entering ex input mode.", NULL)); - (void)ex_puts(sp, "\n"); + (void)ex_puts(sp, "Entering ex input mode.\n"); (void)ex_fflush(sp); } diff --git a/usr.bin/vi/ex/ex_bang.c b/usr.bin/vi/ex/ex_bang.c index be0a64cc6a4..4486c9785bc 100644 --- a/usr.bin/vi/ex/ex_bang.c +++ b/usr.bin/vi/ex/ex_bang.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_bang.c,v 1.9 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: ex_bang.c,v 1.10 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -103,9 +103,7 @@ ex_bang(SCR *sp, EXCMD *cmdp) return (0); } else if (O_ISSET(sp, O_WARN) && !F_ISSET(sp, SC_EX_SILENT)) - msg = msg_cat(sp, - "File modified since last write.", - NULL); + msg = "File modified since last write."; } /* If we're still in a vi screen, move out explicitly. */ diff --git a/usr.bin/vi/ex/ex_print.c b/usr.bin/vi/ex/ex_print.c index c9841073e5b..346ccab8076 100644 --- a/usr.bin/vi/ex/ex_print.c +++ b/usr.bin/vi/ex/ex_print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_print.c,v 1.10 2014/11/12 04:28:41 bentley Exp $ */ +/* $OpenBSD: ex_print.c,v 1.11 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -181,7 +181,7 @@ ex_scprint(SCR *sp, MARK *fp, MARK *tp) return (1); if (INTERRUPTED(sp)) return (1); - p = "[ynq]"; /* XXX: should be msg_cat. */ + p = "[ynq]"; if (ex_prchars(sp, p, &col, 5, 0, 0)) return (1); (void)ex_fflush(sp); diff --git a/usr.bin/vi/ex/ex_subst.c b/usr.bin/vi/ex/ex_subst.c index 624e28adfd1..0467a0c8e8a 100644 --- a/usr.bin/vi/ex/ex_subst.c +++ b/usr.bin/vi/ex/ex_subst.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_subst.c,v 1.25 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: ex_subst.c,v 1.26 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -626,8 +626,7 @@ nextmatch: match[0].rm_so = 0; if (vs_refresh(sp, 1)) goto err; - vs_update(sp, msg_cat(sp, - "Confirm change? [n]", NULL), NULL); + vs_update(sp, "Confirm change? [n]", NULL); if (v_event_get(sp, &ev, 0, 0)) goto err; diff --git a/usr.bin/vi/include/com_extern.h b/usr.bin/vi/include/com_extern.h index 045b141e93e..b34893ba3a5 100644 --- a/usr.bin/vi/include/com_extern.h +++ b/usr.bin/vi/include/com_extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: com_extern.h,v 1.8 2016/01/06 22:27:40 millert Exp $ */ +/* $OpenBSD: com_extern.h,v 1.9 2016/01/06 22:29:38 millert Exp $ */ int cut(SCR *, CHAR_T *, MARK *, MARK *, int); int cut_line(SCR *, recno_t, size_t, size_t, CB *); @@ -55,7 +55,6 @@ void msgq_str(SCR *, mtype_t, char *, char *); void mod_rpt(SCR *); void msgq_status(SCR *, recno_t, u_int); const char *msg_cmsg(SCR *, cmsg_t, size_t *); -const char *msg_cat(SCR *, const char *, size_t *); char *msg_print(SCR *, const char *, int *); int opts_init(SCR *, int *); int opts_set(SCR *, ARGS *[], char *); diff --git a/usr.bin/vi/vi/vs_msg.c b/usr.bin/vi/vi/vs_msg.c index c528df14dba..40f1142bf74 100644 --- a/usr.bin/vi/vi/vs_msg.c +++ b/usr.bin/vi/vi/vs_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_msg.c,v 1.15 2015/12/07 20:39:19 mmcc Exp $ */ +/* $OpenBSD: vs_msg.c,v 1.16 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -62,7 +62,6 @@ vs_busy(SCR *sp, const char *msg, busy_t btype) static const char flagc[] = "|/-\\"; struct timespec ts, ts_diff; size_t len, notused; - const char *p; /* Ex doesn't display busy messages. */ if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)) @@ -91,9 +90,8 @@ vs_busy(SCR *sp, const char *msg, busy_t btype) (void)gp->scr_cursor(sp, &vip->busy_oldy, &vip->busy_oldx); /* Display the busy message. */ - p = msg_cat(sp, msg, &len); (void)gp->scr_move(sp, LASTLINE(sp), 0); - (void)gp->scr_addstr(sp, p, len); + (void)gp->scr_addstr(sp, msg, strlen(msg)); (void)gp->scr_cursor(sp, ¬used, &vip->busy_fx); (void)gp->scr_clrtoeol(sp); (void)gp->scr_move(sp, LASTLINE(sp), vip->busy_fx); diff --git a/usr.bin/vi/vi/vs_refresh.c b/usr.bin/vi/vi/vs_refresh.c index 781614015ff..5f316a16fd3 100644 --- a/usr.bin/vi/vi/vs_refresh.c +++ b/usr.bin/vi/vi/vs_refresh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_refresh.c,v 1.20 2016/01/06 22:28:52 millert Exp $ */ +/* $OpenBSD: vs_refresh.c,v 1.21 2016/01/06 22:29:38 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -880,8 +880,8 @@ vs_modeline(SCR *sp) if (O_ISSET(sp, O_SHOWMODE)) { if (F_ISSET(sp->ep, F_MODIFIED)) --endpoint; - t = msg_cat(sp, modes[sp->showmode], &len); - endpoint -= len; + t = modes[sp->showmode]; + endpoint -= (len = strlen(t)); } if (endpoint > curlen + 2) { |