diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2006-07-25 08:27:10 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2006-07-25 08:27:10 +0000 |
commit | 6fa69567b7af822d74014fa4cbf3f5d3d8f34ffc (patch) | |
tree | 5ce76eb7ce91f51b9dd1960fbe251c0aa0c1e1b7 /usr.bin | |
parent | b27fa2f6a9aae6a0a87897200334b193aa2882dd (diff) |
Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/basic.c | 6 | ||||
-rw-r--r-- | usr.bin/mg/buffer.c | 10 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 6 | ||||
-rw-r--r-- | usr.bin/mg/dired.c | 6 | ||||
-rw-r--r-- | usr.bin/mg/extend.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/grep.c | 10 | ||||
-rw-r--r-- | usr.bin/mg/line.c | 5 | ||||
-rw-r--r-- | usr.bin/mg/random.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/search.c | 6 |
10 files changed, 32 insertions, 29 deletions
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c index 8160966cdf9..4a6d0782e05 100644 --- a/usr.bin/mg/basic.c +++ b/usr.bin/mg/basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: basic.c,v 1.25 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: basic.c,v 1.26 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain */ @@ -107,7 +107,7 @@ int gotobob(int f, int n) { (void) setmark(f, n); - curwp->w_dotp = lforw(curbp->b_headp); + curwp->w_dotp = bfirstlp(curbp); curwp->w_doto = 0; curwp->w_flag |= WFFULL; curwp->w_dotline = 1; @@ -123,7 +123,7 @@ int gotoeob(int f, int n) { (void) setmark(f, n); - curwp->w_dotp = lback(curbp->b_headp); + curwp->w_dotp = blastlp(curbp); curwp->w_doto = llength(curwp->w_dotp); curwp->w_dotline = curwp->w_bufp->b_lines; curwp->w_flag |= WFFULL; diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 1649d458ecb..1bb99367dd0 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.62 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: buffer.c,v 1.63 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -299,7 +299,7 @@ makelist(void) nbytes = 0; /* Count bytes in buf. */ if (bp != blp) { - lp = lforw(bp->b_headp); + lp = bfirstlp(bp); while (lp != bp->b_headp) { nbytes += llength(lp) + 1; lp = lforw(lp); @@ -321,7 +321,7 @@ makelist(void) bp->b_fname) == FALSE) return (NULL); } - blp->b_dotp = lforw(blp->b_headp); /* put dot at beginning of + blp->b_dotp = bfirstlp(blp); /* put dot at beginning of * buffer */ blp->b_doto = 0; return (blp); /* All done */ @@ -700,7 +700,7 @@ bufferinsert(int f, int n) } /* insert the buffer */ nline = 0; - clp = lforw(bp->b_headp); + clp = bfirstlp(bp); for (;;) { for (clo = 0; clo < llength(clp); clo++) if (linsert(1, lgetc(clp, clo)) == FALSE) @@ -756,7 +756,7 @@ popbuftop(struct buffer *bp) { struct mgwin *wp; - bp->b_dotp = lforw(bp->b_headp); + bp->b_dotp = bfirstlp(bp); bp->b_doto = 0; if (bp->b_nwnd != 0) { for (wp = wheadp; wp != NULL; wp = wp->w_wndp) diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 78083f12d39..d4e5016393a 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.94 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: def.h,v 1.95 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -263,6 +263,10 @@ struct buffer { #define b_bufp b_list.l_p.x_bp #define b_bname b_list.l_name +/* Some helper macros, in case they ever change to functions */ +#define bfirstlp(buf) (lforw((buf)->b_headp)) +#define blastlp(buf) (lback((buf)->b_headp)) + #define BFCHG 0x01 /* Changed. */ #define BFBAK 0x02 /* Need to make a backup. */ #ifdef NOTAB diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 8aeffa6a1a2..2243b7f71ce 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.40 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: dired.c,v 1.41 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -336,7 +336,7 @@ d_expunge(int f, int n) struct line *lp, *nlp; char fname[NFILEN]; - for (lp = lforw(curbp->b_headp); lp != curbp->b_headp; lp = nlp) { + for (lp = bfirstlp(curbp); lp != curbp->b_headp; lp = nlp) { nlp = lforw(lp); if (llength(lp) && lgetc(lp, 0) == 'D') { switch (d_makename(lp, fname, sizeof(fname))) { @@ -630,7 +630,7 @@ dired_(char *dname) strerror(errno)); return (NULL); } - bp->b_dotp = lforw(bp->b_headp); /* go to first line */ + bp->b_dotp = bfirstlp(bp); (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname)); (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd)); if ((bp->b_modes[1] = name_mode("dired")) == NULL) { diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c index 7080486f2a4..54f551c1134 100644 --- a/usr.bin/mg/extend.c +++ b/usr.bin/mg/extend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extend.c,v 1.47 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: extend.c,v 1.48 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -621,7 +621,7 @@ evalbuffer(int f, int n) int s; static char excbuf[128]; - for (lp = lforw(bp->b_headp); lp != bp->b_headp; lp = lforw(lp)) { + for (lp = bfirstlp(bp); lp != bp->b_headp; lp = lforw(lp)) { if (llength(lp) >= 128) return (FALSE); (void)strncpy(excbuf, ltext(lp), llength(lp)); diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 75b3b006f88..234d310a54c 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.61 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: file.c,v 1.62 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -218,7 +218,7 @@ readin(char *fname) for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { - wp->w_dotp = wp->w_linep = lforw(curbp->b_headp); + wp->w_dotp = wp->w_linep = bfirstlp(curbp); wp->w_doto = 0; wp->w_markp = NULL; wp->w_marko = 0; diff --git a/usr.bin/mg/grep.c b/usr.bin/mg/grep.c index 8fe20157b9a..b2258760324 100644 --- a/usr.bin/mg/grep.c +++ b/usr.bin/mg/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.31 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: grep.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */ /* * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. * Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>. @@ -269,7 +269,7 @@ compile_mode(const char *name, const char *command) else addlinef(bp, "Command finished at %s", timestr); - bp->b_dotp = lforw(bp->b_headp); /* go to first line */ + bp->b_dotp = bfirstlp(bp); bp->b_modes[0] = name_mode("fundamental"); bp->b_modes[1] = name_mode("compile"); bp->b_nmodes = 1; @@ -297,7 +297,7 @@ compile_goto_error(int f, int n) compile_win = curwp; compile_buffer = curbp; - last = lback(compile_buffer->b_headp); + last = blastlp(compile_buffer); retry: /* last line is compilation result */ @@ -340,7 +340,7 @@ compile_goto_error(int f, int n) return (TRUE); fail: free(line); - if (curwp->w_dotp != lback(curbp->b_headp)) { + if (curwp->w_dotp != blastlp(curbp)) { curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_flag |= WFMOVE; goto retry; @@ -359,7 +359,7 @@ next_error(int f, int n) } curwp = compile_win; curbp = compile_buffer; - if (curwp->w_dotp == lback(curbp->b_headp)) { + if (curwp->w_dotp == blastlp(curbp)) { ewprintf("No more hits"); return (FALSE); } diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c index 12d55c2851e..4710c57d8e2 100644 --- a/usr.bin/mg/line.c +++ b/usr.bin/mg/line.c @@ -1,4 +1,4 @@ -/* $OpenBSD: line.c,v 1.41 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: line.c,v 1.42 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -426,8 +426,7 @@ ldelete(RSIZE n, int kflag) chunk = n; /* End of line, merge */ if (chunk == 0) { - if (dotp == lback(curbp->b_headp)) - /* End of buffer */ + if (dotp == blastlp(curbp)) return (FALSE); lchange(WFFULL); if (ldelnewline() == FALSE) diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c index f7bb587037b..6daeec30152 100644 --- a/usr.bin/mg/random.c +++ b/usr.bin/mg/random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: random.c,v 1.21 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: random.c,v 1.22 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -31,7 +31,7 @@ showcpos(int f, int n) int ratio; /* collect the data */ - clp = lforw(curbp->b_headp); + clp = bfirstlp(curbp); cchar = 0; cline = 0; cbyte = 0; diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c index 0e049b12d86..ef83211a148 100644 --- a/usr.bin/mg/search.c +++ b/usr.bin/mg/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.31 2006/07/25 08:22:32 kjell Exp $ */ +/* $OpenBSD: search.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */ /* This file is in the public domain. */ @@ -230,7 +230,7 @@ isearch(int dir) } if (success == FALSE && dir == SRCH_FORW) { /* wrap the search to beginning */ - clp = lforw(curbp->b_headp); + clp = bfirstlp(curbp); curwp->w_dotp = clp; curwp->w_doto = 0; curwp->w_dotline = 1; @@ -262,7 +262,7 @@ isearch(int dir) } if (success == FALSE && dir == SRCH_BACK) { /* wrap the search to end */ - clp = lback(curbp->b_headp); + clp = blastlp(curbp); curwp->w_dotp = clp; curwp->w_doto = llength(curwp->w_dotp); |