summaryrefslogtreecommitdiff
path: root/usr.bin/mg/paragraph.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-04-13 06:12:19 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-04-13 06:12:19 +0000
commit731317961dd78a8a6a84be2b662b9691fcf40d5a (patch)
tree642f051b45a10e806a55322912dad11e53435ab7 /usr.bin/mg/paragraph.c
parentf54a169ac01105217cbf6e3dfa39f465f0bde571 (diff)
The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...
Diffstat (limited to 'usr.bin/mg/paragraph.c')
-rw-r--r--usr.bin/mg/paragraph.c170
1 files changed, 95 insertions, 75 deletions
diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c
index b09aa7810f3..8e1536dfe0d 100644
--- a/usr.bin/mg/paragraph.c
+++ b/usr.bin/mg/paragraph.c
@@ -4,7 +4,7 @@
*/
#include "def.h"
-static int fillcol = 70 ;
+static int fillcol = 70;
#define MAXWORD 256
/*
@@ -12,40 +12,47 @@ static int fillcol = 70 ;
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the begining of a paragraph
*/
-/*ARGSUSED*/
+/* ARGSUSED */
gotobop(f, n)
{
- if (n < 0) /* the other way...*/
+ if (n < 0) /* the other way... */
return gotoeop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* first scan back until we are in a word */
-
- while (backchar(FFRAND, 1) && !inword()) {}
+
+ while (backchar(FFRAND, 1) && !inword()) {
+ }
curwp->w_doto = 0; /* and go to the B-O-Line */
- /* and scan back until we hit a <NL><SP> <NL><TAB> or <NL><NL> */
+ /*
+ * and scan back until we hit a <NL><SP> <NL><TAB> or
+ * <NL><NL>
+ */
while (lback(curwp->w_dotp) != curbp->b_linep)
if (llength(lback(curwp->w_dotp))
- && lgetc(curwp->w_dotp,0) != ' '
- && lgetc(curwp->w_dotp,0) != '.'
- && lgetc(curwp->w_dotp,0) != '\t')
+ && lgetc(curwp->w_dotp, 0) != ' '
+ && lgetc(curwp->w_dotp, 0) != '.'
+ && lgetc(curwp->w_dotp, 0) != '\t')
curwp->w_dotp = lback(curwp->w_dotp);
else {
- if (llength(lback(curwp->w_dotp))
- && lgetc(curwp->w_dotp,0) == '.') {
- curwp->w_dotp = lforw(curwp->w_dotp);
- if(curwp->w_dotp == curbp->b_linep) {
- /* beond end of buffer, cleanup time */
- curwp->w_dotp = lback(curwp->w_dotp);
- curwp->w_doto = llength(curwp->w_dotp);
- }
- }
- break;
- }
+ if (llength(lback(curwp->w_dotp))
+ && lgetc(curwp->w_dotp, 0) == '.') {
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ if (curwp->w_dotp == curbp->b_linep) {
+ /*
+ * beond end of buffer,
+ * cleanup time
+ */
+ curwp->w_dotp = lback(curwp->w_dotp);
+ curwp->w_doto = llength(curwp->w_dotp);
+ }
+ }
+ break;
+ }
}
- curwp->w_flag |= WFMOVE; /* force screen update */
+ curwp->w_flag |= WFMOVE;/* force screen update */
return TRUE;
}
@@ -54,37 +61,38 @@ gotobop(f, n)
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the begining of a paragraph
*/
-/*ARGSUSED*/
+/* ARGSUSED */
gotoeop(f, n)
{
- if (n < 0) /* the other way...*/
+ if (n < 0) /* the other way... */
return gotobop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* Find the first word on/after the current line */
curwp->w_doto = 0;
- while(forwchar(FFRAND, 1) && !inword()) {}
+ while (forwchar(FFRAND, 1) && !inword()) {
+ }
curwp->w_doto = 0;
curwp->w_dotp = lforw(curwp->w_dotp);
/* and scan forword until we hit a <NL><SP> or ... */
while (curwp->w_dotp != curbp->b_linep) {
if (llength(curwp->w_dotp)
- && lgetc(curwp->w_dotp,0) != ' '
- && lgetc(curwp->w_dotp,0) != '.'
- && lgetc(curwp->w_dotp,0) != '\t')
+ && lgetc(curwp->w_dotp, 0) != ' '
+ && lgetc(curwp->w_dotp, 0) != '.'
+ && lgetc(curwp->w_dotp, 0) != '\t')
curwp->w_dotp = lforw(curwp->w_dotp);
else
break;
}
- if(curwp->w_dotp == curbp->b_linep) {
+ if (curwp->w_dotp == curbp->b_linep) {
/* beond end of buffer, cleanup time */
curwp->w_dotp = lback(curwp->w_dotp);
curwp->w_doto = llength(curwp->w_dotp);
- break;
+ break;
}
}
- curwp->w_flag |= WFMOVE; /* force screen update */
+ curwp->w_flag |= WFMOVE;/* force screen update */
return TRUE;
}
@@ -92,33 +100,35 @@ gotoeop(f, n)
* Fill the current paragraph according to the current
* fill column
*/
-/*ARGSUSED*/
+/* ARGSUSED */
fillpara(f, n)
{
- register int c; /* current char durring scan */
- register int wordlen; /* length of current word */
- register int clength; /* position on line during fill */
- register int i; /* index during word copy */
- register int eopflag; /* Are we at the End-Of-Paragraph? */
- int firstflag; /* first word? (needs no space) */
- int newlength; /* tentative new line length */
- int eolflag; /* was at end of line */
- LINE *eopline; /* pointer to line just past EOP */
- char wbuf[MAXWORD]; /* buffer for current word */
+ register int c; /* current char durring scan */
+ register int wordlen;/* length of current word */
+ register int clength;/* position on line during fill */
+ register int i; /* index during word copy */
+ register int eopflag;/* Are we at the End-Of-Paragraph? */
+ int firstflag; /* first word? (needs no space) */
+ int newlength; /* tentative new line length */
+ int eolflag;/* was at end of line */
+ LINE *eopline;/* pointer to line just past EOP */
+ char wbuf[MAXWORD]; /* buffer for current word */
/* record the pointer to the line just past the EOP */
(VOID) gotoeop(FFRAND, 1);
- if(curwp->w_doto != 0) {
+ if (curwp->w_doto != 0) {
/* paragraph ends at end of buffer */
(VOID) lnewline();
eopline = lforw(curwp->w_dotp);
- } else eopline = curwp->w_dotp;
+ } else
+ eopline = curwp->w_dotp;
/* and back top the begining of the paragraph */
(VOID) gotobop(FFRAND, 1);
/* initialize various info */
- while (!inword() && forwchar(FFRAND, 1)) {}
+ while (!inword() && forwchar(FFRAND, 1)) {
+ }
clength = curwp->w_doto;
wordlen = 0;
@@ -127,7 +137,7 @@ fillpara(f, n)
eopflag = FALSE;
while (!eopflag) {
/* get the next character in the paragraph */
- if (eolflag=(curwp->w_doto == llength(curwp->w_dotp))) {
+ if (eolflag = (curwp->w_doto == llength(curwp->w_dotp))) {
c = ' ';
if (lforw(curwp->w_dotp) == eopline)
eopflag = TRUE;
@@ -143,24 +153,26 @@ fillpara(f, n)
if (wordlen < MAXWORD - 1)
wbuf[wordlen++] = c;
else {
- /* You loose chars beyond MAXWORD if the word
+ /*
+ * You loose chars beyond MAXWORD if the word
* is to long. I'm to lazy to fix it now; it
- * just silently truncated the word before, so
- * I get to feel smug.
+ * just silently truncated the word before,
+ * so I get to feel smug.
*/
ewprintf("Word too long!");
}
} else if (wordlen) {
/* calculate tenatitive new length with word added */
newlength = clength + 1 + wordlen;
- /* if at end of line or at doublespace and previous
+ /*
+ * if at end of line or at doublespace and previous
* character was one of '.','?','!' doublespace here.
*/
- if((eolflag || curwp->w_doto==llength(curwp->w_dotp)
- || (c=lgetc(curwp->w_dotp,curwp->w_doto))==' '
- || c=='\t')
- && ISEOSP(wbuf[wordlen-1])
- && wordlen<MAXWORD-1)
+ if ((eolflag || curwp->w_doto == llength(curwp->w_dotp)
+ || (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
+ || c == '\t')
+ && ISEOSP(wbuf[wordlen - 1])
+ && wordlen < MAXWORD - 1)
wbuf[wordlen++] = ' ';
/* at a word break with a word waiting */
if (newlength <= fillcol) {
@@ -171,8 +183,8 @@ fillpara(f, n)
}
firstflag = FALSE;
} else {
- if(curwp->w_doto > 0 &&
- lgetc(curwp->w_dotp,curwp->w_doto-1)==' ') {
+ if (curwp->w_doto > 0 &&
+ lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') {
curwp->w_doto -= 1;
(VOID) ldelete((RSIZE) 1, KNONE);
}
@@ -182,7 +194,7 @@ fillpara(f, n)
}
/* and add the word in in either case */
- for (i=0; i<wordlen; i++) {
+ for (i = 0; i < wordlen; i++) {
(VOID) linsert(1, wbuf[i]);
++clength;
}
@@ -191,18 +203,20 @@ fillpara(f, n)
}
/* and add a last newline for the end of our new paragraph */
(VOID) lnewline();
- /* we realy should wind up where we started, (which is hard to keep
+ /*
+ * we realy should wind up where we started, (which is hard to keep
* track of) but I think the end of the last line is better than the
- * begining of the blank line. */
+ * begining of the blank line.
+ */
(VOID) backchar(FFRAND, 1);
return TRUE;
}
/* delete n paragraphs starting with the current one */
-/*ARGSUSED*/
+/* ARGSUSED */
killpara(f, n)
{
- register int status; /* returned status of functions */
+ register int status; /* returned status of functions */
while (n--) { /* for each paragraph to delete */
@@ -231,52 +245,58 @@ killpara(f, n)
* check to see if we're past fillcol, and if so,
* justify this line. As a last step, justify the line.
*/
-/*ARGSUSED*/
+/* ARGSUSED */
fillword(f, n)
{
- register char c;
- register int col, i, nce;
+ register char c;
+ register int col, i, nce;
for (i = col = 0; col <= fillcol; ++i, ++col) {
- if (i == curwp->w_doto) return selfinsert(f, n) ;
+ if (i == curwp->w_doto)
+ return selfinsert(f, n);
c = lgetc(curwp->w_dotp, i);
if (c == '\t'
#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
+ && !(curbp->b_flag & BFNOTAB)
#endif
- ) col |= 0x07;
- else if (ISCTRL(c) != FALSE) ++col;
+ )
+ col |= 0x07;
+ else if (ISCTRL(c) != FALSE)
+ ++col;
}
if (curwp->w_doto != llength(curwp->w_dotp)) {
(VOID) selfinsert(f, n);
nce = llength(curwp->w_dotp) - curwp->w_doto;
- } else nce = 0;
+ } else
+ nce = 0;
curwp->w_doto = i;
if ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t')
do {
(VOID) backchar(FFRAND, 1);
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' '
- && c != '\t' && curwp->w_doto > 0);
+ && c != '\t' && curwp->w_doto > 0);
if (curwp->w_doto == 0)
do {
(VOID) forwchar(FFRAND, 1);
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' '
- && c != '\t' && curwp->w_doto < llength(curwp->w_dotp));
+ && c != '\t' && curwp->w_doto < llength(curwp->w_dotp));
(VOID) delwhite(FFRAND, 1);
(VOID) lnewline();
i = llength(curwp->w_dotp) - nce;
- curwp->w_doto = i>0 ? i : 0;
+ curwp->w_doto = i > 0 ? i : 0;
curwp->w_flag |= WFMOVE;
- if (nce == 0 && curwp->w_doto != 0) return fillword(f, n);
+ if (nce == 0 && curwp->w_doto != 0)
+ return fillword(f, n);
return TRUE;
}
/* Set fill column to n. */
-setfillcol(f, n) {
- extern int getcolpos() ;
+setfillcol(f, n)
+{
+ extern int getcolpos();
fillcol = ((f & FFARG) ? n : getcolpos());
ewprintf("Fill column set to %d", fillcol);