summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlum <lum@openbsd.org>2021-02-28 15:30:35 +0000
committerlum <lum@openbsd.org>2021-02-28 15:30:35 +0000
commitc77684c87fbf60ac435867dbccc60c3b333ca615 (patch)
treea801050a4e53ad085f9486468e494e1c674437bc
parentIntroduce #defines for exponential backoff, explain where they come (diff)
downloadwireguard-openbsd-c77684c87fbf60ac435867dbccc60c3b333ca615.tar.xz
wireguard-openbsd-c77684c87fbf60ac435867dbccc60c3b333ca615.zip
Add dobeep functions that take messages to buffer.c and cscope.c
No functional change intended.
-rw-r--r--usr.bin/mg/buffer.c45
-rw-r--r--usr.bin/mg/cscope.c117
2 files changed, 55 insertions, 107 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index 57ef738cfd1..ac2a2721eae 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -398,11 +398,8 @@ listbuf_goto_buffer_helper(int f, int n, int only)
char *line = NULL;
int i, ret = FALSE;
- if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') {
- dobeep();
- ewprintf("buffer name truncated");
- return (FALSE);
- }
+ if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$')
+ return(dobeep_msg("buffer name truncated"));
if ((line = malloc(listbuf_ncol/2)) == NULL)
return (FALSE);
@@ -489,8 +486,7 @@ anycb(int f)
ret = snprintf(pbuf, sizeof(pbuf), "Save file %s",
bp->b_fname);
if (ret < 0 || ret >= sizeof(pbuf)) {
- dobeep();
- ewprintf("Error: filename too long!");
+ (void)dobeep_msg("Error: filename too long!");
return (UERROR);
}
if ((f == TRUE || (save = eyorn(pbuf)) == TRUE) &&
@@ -779,11 +775,9 @@ bufferinsert(int f, int n)
else if ((bp = bfind(bufn, FALSE)) == NULL)
return (FALSE);
- if (bp == curbp) {
- dobeep();
- ewprintf("Cannot insert buffer into self");
- return (FALSE);
- }
+ if (bp == curbp)
+ return(dobeep_msg("Cannot insert buffer into self"));
+
/* insert the buffer */
nline = 0;
clp = bfirstlp(bp);
@@ -921,11 +915,9 @@ revertbuffer(int f, int n)
{
char fbuf[NFILEN + 32];
- if (curbp->b_fname[0] == 0) {
- dobeep();
- ewprintf("Cannot revert buffer not associated with any files.");
- return (FALSE);
- }
+ if (curbp->b_fname[0] == 0)
+ return(dobeep_msg("Cannot revert buffer not associated "
+ "with any files."));
snprintf(fbuf, sizeof(fbuf), "Revert buffer from file %s",
curbp->b_fname);
@@ -997,11 +989,9 @@ diffbuffer(int f, int n)
return (FALSE);
}
- if (curbp->b_fname[0] == 0) {
- dobeep();
- ewprintf("Cannot diff buffer not associated with any files.");
- return (FALSE);
- }
+ if (curbp->b_fname[0] == 0)
+ return(dobeep_msg("Cannot diff buffer not associated with "
+ "any files."));
lpend = curbp->b_headp;
for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
@@ -1009,11 +999,9 @@ diffbuffer(int f, int n)
if (lforw(lp) != lpend) /* no implied \n on last line */
len++;
}
- if ((text = calloc(len + 1, sizeof(char))) == NULL) {
- dobeep();
- ewprintf("Cannot allocate memory.");
- return (FALSE);
- }
+ if ((text = calloc(len + 1, sizeof(char))) == NULL)
+ return(dobeep_msg("Cannot allocate memory."));
+
ttext = text;
for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
@@ -1055,8 +1043,7 @@ findbuffer(char *fn)
char bname[NBUFN], fname[NBUFN];
if (strlcpy(fname, fn, sizeof(fname)) >= sizeof(fname)) {
- dobeep();
- ewprintf("filename too long");
+ (void)dobeep_msg("filename too long");
return (NULL);
}
diff --git a/usr.bin/mg/cscope.c b/usr.bin/mg/cscope.c
index 18042d30e54..0beb59a2b6e 100644
--- a/usr.bin/mg/cscope.c
+++ b/usr.bin/mg/cscope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cscope.c,v 1.18 2019/07/03 03:24:02 deraadt Exp $ */
+/* $OpenBSD: cscope.c,v 1.19 2021/02/28 15:30:35 lum Exp $ */
/*
* This file is in the public domain.
@@ -184,31 +184,20 @@ cscreatelist(int f, int n)
else if (bufp[0] == '\0')
return (FALSE);
- if (stat(dir, &sb) == -1) {
- dobeep();
- ewprintf("stat: %s", strerror(errno));
- return (FALSE);
- } else if (S_ISDIR(sb.st_mode) == 0) {
- dobeep();
- ewprintf("%s: Not a directory", dir);
- return (FALSE);
- }
+ if (stat(dir, &sb) == -1)
+ return(dobeep_msgs("stat: %s", strerror(errno)));
+ else if (S_ISDIR(sb.st_mode) == 0)
+ return(dobeep_msgs("%s: Not a directory", dir));
- if (csexists("cscope-indexer") == FALSE) {
- dobeep();
- ewprintf("no such file or directory, cscope-indexer");
- return (FALSE);
- }
+ if (csexists("cscope-indexer") == FALSE)
+ return(dobeep_msg("no such file or directory, cscope-indexer"));
clen = snprintf(cmd, sizeof(cmd), "cscope-indexer -v %s", dir);
if (clen < 0 || clen >= sizeof(cmd))
return (FALSE);
- if ((fpipe = popen(cmd, "r")) == NULL) {
- dobeep();
- ewprintf("problem opening pipe");
- return (FALSE);
- }
+ if ((fpipe = popen(cmd, "r")) == NULL)
+ return(dobeep_msg("problem opening pipe"));
bp = bfind("*cscope*", TRUE);
if (bclear(bp) != TRUE) {
@@ -248,11 +237,10 @@ csnextmatch(int f, int n)
struct csmatch *m;
if (curmatch == NULL) {
- if ((r = TAILQ_FIRST(&csrecords)) == NULL) {
- dobeep();
- ewprintf("The *cscope* buffer does not exist yet");
- return (FALSE);
- }
+ if ((r = TAILQ_FIRST(&csrecords)) == NULL)
+ return(dobeep_msg("The *cscope* buffer does "
+ "not exist yet"));
+
currecord = r;
curmatch = TAILQ_FIRST(&r->matches);
} else {
@@ -260,10 +248,8 @@ csnextmatch(int f, int n)
if (m == NULL) {
r = TAILQ_NEXT(currecord, entry);
if (r == NULL) {
- dobeep();
- ewprintf("The end of *cscope* buffer has been"
- " reached");
- return (FALSE);
+ return(dobeep_msg("The end of *cscope* buffer "
+ "has been reached"));
} else {
currecord = r;
curmatch = TAILQ_FIRST(&currecord->matches);
@@ -293,10 +279,8 @@ csprevmatch(int f, int n)
else {
r = TAILQ_PREV(currecord, csrecords, entry);
if (r == NULL) {
- dobeep();
- ewprintf("The beginning of *cscope* buffer has"
- " been reached");
- return (FALSE);
+ return(dobeep_msg("The beginning of *cscope* "
+ "buffer has been reached"));
} else {
currecord = r;
curmatch = TAILQ_LAST(&currecord->matches,
@@ -316,18 +300,13 @@ csnextfile(int f, int n)
struct csrecord *r;
if (curmatch == NULL) {
- if ((r = TAILQ_FIRST(&csrecords)) == NULL) {
- dobeep();
- ewprintf("The *cscope* buffer does not exist yet");
- return (FALSE);
- }
-
+ if ((r = TAILQ_FIRST(&csrecords)) == NULL)
+ return(dobeep_msg("The *cscope* buffer does not "
+ "exist yet"));
} else {
- if ((r = TAILQ_NEXT(currecord, entry)) == NULL) {
- dobeep();
- ewprintf("The end of *cscope* buffer has been reached");
- return (FALSE);
- }
+ if ((r = TAILQ_NEXT(currecord, entry)) == NULL)
+ return(dobeep_msg("The end of *cscope* buffer has "
+ "been reached"));
}
currecord = r;
curmatch = TAILQ_FIRST(&currecord->matches);
@@ -343,19 +322,13 @@ csprevfile(int f, int n)
struct csrecord *r;
if (curmatch == NULL) {
- if ((r = TAILQ_FIRST(&csrecords)) == NULL) {
- dobeep();
- ewprintf("The *cscope* buffer does not exist yet");
- return (FALSE);
- }
-
+ if ((r = TAILQ_FIRST(&csrecords)) == NULL)
+ return(dobeep_msg("The *cscope* buffer does not"
+ "exist yet"));
} else {
- if ((r = TAILQ_PREV(currecord, csrecords, entry)) == NULL) {
- dobeep();
- ewprintf("The beginning of *cscope* buffer has been"
- " reached");
- return (FALSE);
- }
+ if ((r = TAILQ_PREV(currecord, csrecords, entry)) == NULL)
+ return(dobeep_msg("The beginning of *cscope* buffer "
+ "has been reached"));
}
currecord = r;
curmatch = TAILQ_FIRST(&currecord->matches);
@@ -411,11 +384,8 @@ do_cscope(int i)
sz = 0;
/* If current buffer isn't a source file just return */
- if (fnmatch("*.[chy]", curbp->b_fname, 0) != 0) {
- dobeep();
- ewprintf("C-c s not defined");
- return (FALSE);
- }
+ if (fnmatch("*.[chy]", curbp->b_fname, 0) != 0)
+ return(dobeep_msg("C-c s not defined"));
if (curtoken(0, 1, pattern) == FALSE)
return (FALSE);
@@ -425,11 +395,8 @@ do_cscope(int i)
else if (p[0] == '\0')
return (FALSE);
- if (csexists("cscope") == FALSE) {
- dobeep();
- ewprintf("no such file or directory, cscope");
- return (FALSE);
- }
+ if (csexists("cscope") == FALSE)
+ return(dobeep_msg("no such file or directory, cscope"));
csflush();
clen = snprintf(cmd, sizeof(cmd), "cscope -L -%d %s 2>/dev/null",
@@ -437,11 +404,8 @@ do_cscope(int i)
if (clen < 0 || clen >= sizeof(cmd))
return (FALSE);
- if ((fpipe = popen(cmd, "r")) == NULL) {
- dobeep();
- ewprintf("problem opening pipe");
- return (FALSE);
- }
+ if ((fpipe = popen(cmd, "r")) == NULL)
+ return(dobeep_msg("problem opening pipe"));
bp = bfind("*cscope*", TRUE);
if (bclear(bp) != TRUE) {
@@ -620,11 +584,9 @@ csexists(const char *cmd)
}
if ((tmp = getenv("PATH")) == NULL)
return (FALSE);
- if ((pathc = path = strndup(tmp, NFILEN)) == NULL) {
- dobeep();
- ewprintf("out of memory");
- return (FALSE);
- }
+ if ((pathc = path = strndup(tmp, NFILEN)) == NULL)
+ return(dobeep_msg("out of memory"));
+
while ((dir = strsep(&path, ":")) != NULL) {
if (*dir == '\0')
continue;
@@ -635,8 +597,7 @@ csexists(const char *cmd)
len = snprintf(fname, sizeof(fname), "%s/%s", dir, cmd);
if (len < 0 || len >= sizeof(fname)) {
- dobeep();
- ewprintf("path too long");
+ (void)dobeep_msg("path too long");
goto cleanup;
}
if(access(fname, F_OK) == 0) {