diff options
Diffstat (limited to 'ex')
-rw-r--r-- | ex/ex.c | 9 | ||||
-rw-r--r-- | ex/ex.h | 8 | ||||
-rw-r--r-- | ex/ex_argv.c | 8 | ||||
-rw-r--r-- | ex/ex_bang.c | 3 | ||||
-rw-r--r-- | ex/ex_cscope.c | 10 | ||||
-rw-r--r-- | ex/ex_filter.c | 3 | ||||
-rw-r--r-- | ex/ex_global.c | 3 | ||||
-rw-r--r-- | ex/ex_script.c | 2 | ||||
-rw-r--r-- | ex/ex_shell.c | 3 | ||||
-rw-r--r-- | ex/ex_subst.c | 27 |
10 files changed, 47 insertions, 29 deletions
@@ -811,13 +811,14 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI)) * this isn't a particularly complex trap, and if backslashes were * legal in set commands, this would have to be much more complicated. */ - if (ecp->cmd == &cmds[C_SET]) + if (ecp->cmd == &cmds[C_SET]) { for (p = ecp->cp, len = ecp->clen; len > 0; --len, ++p) if (IS_ESCAPE(sp, ecp, *p) && len > 1) { --len; ++p; } else if (*p == '\\') *p = CH_LITERAL; + } /* * Set the default addresses. It's an error to specify an address for @@ -1254,7 +1255,7 @@ addr_verify: ex_badaddr(sp, ecp->cmd, A_ZERO, NUM_OK); goto err; } - } else if (!db_exist(sp, ecp->addr2.lno)) + } else if (!db_exist(sp, ecp->addr2.lno)) { if (FL_ISSET(ecp->iflags, E_C_COUNT)) { if (db_last(sp, &lno)) goto err; @@ -1263,6 +1264,7 @@ addr_verify: ex_badaddr(sp, NULL, A_EOF, NUM_OK); goto err; } + } /* FALLTHROUGH */ case 1: if (ecp->addr1.lno == 0) { @@ -2117,7 +2119,7 @@ ex_load(SCR *sp) /* If it's a global/v command, fix up the last line. */ if (FL_ISSET(ecp->agv_flags, - AGV_GLOBAL | AGV_V) && ecp->range_lno != OOBLNO) + AGV_GLOBAL | AGV_V) && ecp->range_lno != OOBLNO) { if (db_exist(sp, ecp->range_lno)) sp->lno = ecp->range_lno; else { @@ -2126,6 +2128,7 @@ ex_load(SCR *sp) if (sp->lno == 0) sp->lno = 1; } + } free(ecp->o_cp); } @@ -55,12 +55,12 @@ extern EXCMDLIST const cmds[]; /* Table of ex commands. */ * at any time, and most of them won't work well if a file hasn't yet been read * in. Historic vi generally took the easy way out and dropped core. */ -#define NEEDFILE(sp, cmdp) { \ +#define NEEDFILE(sp, cmdp) do { \ if ((sp)->ep == NULL) { \ ex_wemsg(sp, (cmdp)->cmd->name, EXM_NOFILEYET); \ return (1); \ } \ -} +} while (0) /* Range structures for global and @ commands. */ typedef struct _range RANGE; @@ -102,12 +102,12 @@ struct _excmd { u_int8_t agv_flags; /* Clear the structure before each ex command. */ -#define CLEAR_EX_CMD(cmdp) { \ +#define CLEAR_EX_CMD(cmdp) do { \ u_int32_t L__f = F_ISSET(cmdp, E_PRESERVE); \ memset(&((cmdp)->buffer), 0, ((char *)&(cmdp)->flags - \ (char *)&((cmdp)->buffer)) + sizeof((cmdp)->flags)); \ F_SET(cmdp, L__f); \ -} +} while (0) CHAR_T buffer; /* Command: named buffer. */ recno_t lineno; /* Command: line number. */ diff --git a/ex/ex_argv.c b/ex/ex_argv.c index d6f9a8bb8aa5..8b1fd7858fb1 100644 --- a/ex/ex_argv.c +++ b/ex/ex_argv.c @@ -611,9 +611,17 @@ argv_flt_path(SCR *sp, EXCMD *excp, CHAR_T *path, size_t plen) if (nlen == 0) { if (dp->d_name[0] == '.') continue; +#ifdef HAVE_DIRENT_D_NAMLEN len = dp->d_namlen; +#else + len = strlen(dp->d_name); +#endif } else { +#ifdef HAVE_DIRENT_D_NAMLEN len = dp->d_namlen; +#else + len = strlen(dp->d_name); +#endif if (len < nlen || memcmp(dp->d_name, name, nlen)) continue; } diff --git a/ex/ex_bang.c b/ex/ex_bang.c index ff2b39bbff9a..c5744708664a 100644 --- a/ex/ex_bang.c +++ b/ex/ex_bang.c @@ -96,7 +96,7 @@ ex_bang(SCR *sp, EXCMD *cmdp) */ if (cmdp->addrcnt == 0) { msg = NULL; - if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED)) + if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED)) { if (O_ISSET(sp, O_AUTOWRITE)) { if (file_aw(sp, FS_ALL)) return (0); @@ -105,6 +105,7 @@ ex_bang(SCR *sp, EXCMD *cmdp) msg = msg_cat(sp, "303|File modified since last write.", NULL); + } /* If we're still in a vi screen, move out explicitly. */ INT2CHAR(sp, ap->bp, ap->len+1, np, nlen); diff --git a/ex/ex_cscope.c b/ex/ex_cscope.c index 629861d55680..74d7f8af95be 100644 --- a/ex/ex_cscope.c +++ b/ex/ex_cscope.c @@ -261,7 +261,7 @@ cscope_add(SCR *sp, EXCMD *cmdp, CHAR_T *dname) csc->dname = csc->buf; csc->dlen = len; memcpy(csc->dname, np, len); - csc->mtim = sb.st_mtimespec; + csc->mtim = sb.st_mtim; /* Get the search paths for the cscope. */ if (get_paths(sp, csc)) @@ -411,7 +411,8 @@ err: if (to_cs[0] != -1) free(dn); goto nomem; } - (void)asprintf(&cmd, CSCOPE_CMD_FMT, dn, dbn); + if (asprintf(&cmd, CSCOPE_CMD_FMT, dn, dbn) == -1) + cmd = NULL; free(dbn); free(dn); if (cmd == NULL) { @@ -812,7 +813,7 @@ csc_file(SCR *sp, CSC *csc, char *name, char **dirp, size_t *dlenp, int *isolder *dirp = *pp; *dlenp = strlen(*pp); *isolderp = timespeccmp( - &sb.st_mtimespec, &csc->mtim, <); + &sb.st_mtim, &csc->mtim, <); return; } free(buf); @@ -843,7 +844,7 @@ csc_help(SCR *sp, char *cmd) { CC const *ccp; - if (cmd != NULL && *cmd != '\0') + if (cmd != NULL && *cmd != '\0') { if ((ccp = lookup_ccmd(cmd)) == NULL) { ex_printf(sp, "%s doesn't match any cscope command\n", cmd); @@ -854,6 +855,7 @@ csc_help(SCR *sp, char *cmd) ex_printf(sp, " Usage: %s\n", ccp->usage_msg); return (0); } + } ex_printf(sp, "cscope commands:\n"); for (ccp = cscope_cmds; ccp->name != NULL; ++ccp) diff --git a/ex/ex_filter.c b/ex/ex_filter.c index cd04643b5f08..fee34a6dc639 100644 --- a/ex/ex_filter.c +++ b/ex/ex_filter.c @@ -174,11 +174,12 @@ err: if (input[0] != -1) if (ex_readfp(sp, "filter", ofp, fm, &nread, 1)) rval = 1; sp->rptlines[L_ADDED] += nread; - if (ftype == FILTER_READ) + if (ftype == FILTER_READ) { if (fm->lno == 0) rp->lno = nread; else rp->lno += nread; + } goto uwait; } diff --git a/ex/ex_global.c b/ex/ex_global.c index 54c6411d8799..cf3c8c9ce7cb 100644 --- a/ex/ex_global.c +++ b/ex/ex_global.c @@ -112,11 +112,12 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); *t = '\0'; break; } - if (p[0] == '\\') + if (p[0] == '\\') { if (p[1] == delim) ++p; else if (p[1] == '\\') *t++ = *p++; + } *t++ = *p++; } diff --git a/ex/ex_script.c b/ex/ex_script.c index 5ba8c028f81a..def590d86741 100644 --- a/ex/ex_script.c +++ b/ex/ex_script.c @@ -32,6 +32,8 @@ #include <unistd.h> #ifdef HAVE_LIBUTIL_H #include <libutil.h> +#elif defined HAVE_PTY_H +#include <pty.h> #else #include <util.h> #endif diff --git a/ex/ex_shell.c b/ex/ex_shell.c index 7b483fd4e14c..7d73253dfbc5 100644 --- a/ex/ex_shell.c +++ b/ex/ex_shell.c @@ -48,8 +48,7 @@ ex_shell(SCR *sp, EXCMD *cmdp) * XXX * Assumes all shells use -i. */ - (void)asprintf(&buf, "%s -i", O_STR(sp, O_SHELL)); - if (buf == NULL) { + if (asprintf(&buf, "%s -i", O_STR(sp, O_SHELL)) == -1) { msgq(sp, M_SYSERR, NULL); return (1); } diff --git a/ex/ex_subst.c b/ex/ex_subst.c index d32d583f6a3b..bf03e4417e91 100644 --- a/ex/ex_subst.c +++ b/ex/ex_subst.c @@ -115,11 +115,12 @@ subagain: return (ex_subagain(sp, cmdp)); *t = '\0'; break; } - if (p[0] == '\\') + if (p[0] == '\\') { if (p[1] == delim) ++p; else if (p[1] == '\\') *t++ = *p++; + } *t++ = *p++; } @@ -296,7 +297,7 @@ ex_subtilde(SCR *sp, EXCMD *cmdp) * when the replacement is done. Don't change it unless you're *damned* * confident. */ -#define NEEDNEWLINE(sp) { \ +#define NEEDNEWLINE(sp) do { \ if (sp->newl_len == sp->newl_cnt) { \ sp->newl_len += 25; \ REALLOC(sp, sp->newl, size_t *, \ @@ -306,9 +307,9 @@ ex_subtilde(SCR *sp, EXCMD *cmdp) return (1); \ } \ } \ -} +} while (0) -#define BUILD(sp, l, len) { \ +#define BUILD(sp, l, len) do { \ if (lbclen + (len) > lblen) { \ lblen = p2roundup(MAX(lbclen + (len), 256)); \ REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \ @@ -319,9 +320,9 @@ ex_subtilde(SCR *sp, EXCMD *cmdp) } \ MEMCPY(lb + lbclen, l, len); \ lbclen += len; \ -} +} while (0) -#define NEEDSP(sp, len, pnt) { \ +#define NEEDSP(sp, len, pnt) do { \ if (lbclen + (len) > lblen) { \ lblen = p2roundup(MAX(lbclen + (len), 256)); \ REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \ @@ -331,7 +332,7 @@ ex_subtilde(SCR *sp, EXCMD *cmdp) } \ pnt = lb + lbclen; \ } \ -} +} while (0) static int s(SCR *sp, EXCMD *cmdp, CHAR_T *s, regex_t *re, u_int flags) @@ -584,7 +585,7 @@ nextmatch: match[0].rm_so = 0; empty_ok = 1; if (len == 0) goto endmatch; - BUILD(sp, s + offset, 1) + BUILD(sp, s + offset, 1); ++offset; --len; goto nextmatch; @@ -710,7 +711,7 @@ skip: offset += match[0].rm_eo; /* Copy the rest of the line. */ if (len) - BUILD(sp, s + offset, len) + BUILD(sp, s + offset, len); /* Set the new offset. */ offset = saved_offset; @@ -736,7 +737,7 @@ skip: offset += match[0].rm_eo; goto err; if (db_get(sp, lno, DBG_FATAL, &s, &llen)) goto err; - ADD_SPACE_RETW(sp, bp, blen, llen) + ADD_SPACE_RETW(sp, bp, blen, llen); MEMCPY(bp, s, llen); s = bp; len = llen - offset; @@ -779,7 +780,7 @@ endmatch: if (!linechanged) /* Copy any remaining bytes into the build buffer. */ if (len) - BUILD(sp, s + offset, len) + BUILD(sp, s + offset, len); /* Store inserted lines, adjusting the build buffer. */ last = 0; @@ -1333,7 +1334,7 @@ re_sub( * Otherwise, since this is the lowest level of replacement, discard * all escaping characters. This (hopefully) matches historic practice. */ -#define OUTCH(ch, nltrans) { \ +#define OUTCH(ch, nltrans) do { \ ARG_CHAR_T __ch = (ch); \ e_key_t __value = KEY_VAL(sp, __ch); \ if (nltrans && (__value == K_CR || __value == K_NL)) { \ @@ -1362,7 +1363,7 @@ re_sub( NEEDSP(sp, 1, p); \ *p++ = __ch; \ ++lbclen; \ -} +} while (0) conv = C_NOTSET; for (rp = sp->repl, rpl = sp->repl_len, p = lb + lbclen; rpl--;) { switch (ch = *rp++) { |