summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2013-11-25 23:27:11 +0000
committerkrw <krw@openbsd.org>2013-11-25 23:27:11 +0000
commit6afab947b5b059a2dbb5ddd50457e36cd678808a (patch)
tree4b40be8d4ad54253711a11bd212dbd24fdfe5615
parentFix infinite loop pointed out by clang/brad. (diff)
downloadwireguard-openbsd-6afab947b5b059a2dbb5ddd50457e36cd678808a.tar.xz
wireguard-openbsd-6afab947b5b059a2dbb5ddd50457e36cd678808a.zip
Replace _texth CIRCLEQ with TAILQ. One down, five to go.
Read, tested, fixed and ok'd zhuk@ pelikan@ millert@
-rw-r--r--usr.bin/vi/common/cut.c14
-rw-r--r--usr.bin/vi/common/cut.h6
-rw-r--r--usr.bin/vi/common/line.c24
-rw-r--r--usr.bin/vi/common/main.c4
-rw-r--r--usr.bin/vi/common/put.c22
-rw-r--r--usr.bin/vi/common/screen.c6
-rw-r--r--usr.bin/vi/ex/ex.c4
-rw-r--r--usr.bin/vi/ex/ex_append.c10
-rw-r--r--usr.bin/vi/ex/ex_at.c11
-rw-r--r--usr.bin/vi/ex/ex_cscope.c6
-rw-r--r--usr.bin/vi/ex/ex_display.c8
-rw-r--r--usr.bin/vi/ex/ex_move.c4
-rw-r--r--usr.bin/vi/ex/ex_subst.c6
-rw-r--r--usr.bin/vi/ex/ex_txt.c14
-rw-r--r--usr.bin/vi/vi/v_at.c7
-rw-r--r--usr.bin/vi/vi/v_ex.c6
-rw-r--r--usr.bin/vi/vi/v_search.c4
-rw-r--r--usr.bin/vi/vi/v_txt.c28
18 files changed, 93 insertions, 91 deletions
diff --git a/usr.bin/vi/common/cut.c b/usr.bin/vi/common/cut.c
index 5c59fb713ae..a5d7eea4417 100644
--- a/usr.bin/vi/common/cut.c
+++ b/usr.bin/vi/common/cut.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cut.c,v 1.11 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: cut.c,v 1.12 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -125,7 +125,7 @@ copyloop:
if (cbp == NULL) {
CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB));
cbp->name = name;
- CIRCLEQ_INIT(&cbp->textq);
+ TAILQ_INIT(&cbp->textq);
LIST_INSERT_HEAD(&sp->gp->cutq, cbp, q);
} else if (!append) {
text_lfree(&cbp->textq);
@@ -267,7 +267,7 @@ cut_line(sp, lno, fcno, clen, cbp)
}
/* Append to the end of the cut buffer. */
- CIRCLEQ_INSERT_TAIL(&cbp->textq, tp, q);
+ TAILQ_INSERT_TAIL(&cbp->textq, tp, q);
cbp->len += tp->len;
return (0);
@@ -287,7 +287,7 @@ cut_close(gp)
/* Free cut buffer list. */
while ((cbp = LIST_FIRST(&gp->cutq)) != NULL) {
- if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq))
+ if (!TAILQ_EMPTY(&cbp->textq))
text_lfree(&cbp->textq);
LIST_REMOVE(cbp, q);
free(cbp);
@@ -295,7 +295,7 @@ cut_close(gp)
/* Free default cut storage. */
cbp = &gp->dcb_store;
- if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq))
+ if (!TAILQ_EMPTY(&cbp->textq))
text_lfree(&cbp->textq);
}
@@ -342,8 +342,8 @@ text_lfree(headp)
{
TEXT *tp;
- while ((tp = CIRCLEQ_FIRST(headp)) != CIRCLEQ_END(headp)) {
- CIRCLEQ_REMOVE(headp, tp, q);
+ while ((tp = TAILQ_FIRST(headp))) {
+ TAILQ_REMOVE(headp, tp, q);
text_free(tp);
}
}
diff --git a/usr.bin/vi/common/cut.h b/usr.bin/vi/common/cut.h
index 7433453b306..237b3151d60 100644
--- a/usr.bin/vi/common/cut.h
+++ b/usr.bin/vi/common/cut.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cut.h,v 1.6 2006/01/08 21:05:39 miod Exp $ */
+/* $OpenBSD: cut.h,v 1.7 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -12,7 +12,7 @@
*/
typedef struct _texth TEXTH; /* TEXT list head structure. */
-CIRCLEQ_HEAD(_texth, _text);
+TAILQ_HEAD(_texth, _text);
/* Cut buffers. */
struct _cb {
@@ -27,7 +27,7 @@ struct _cb {
/* Lines/blocks of text. */
struct _text { /* Text: a linked list of lines. */
- CIRCLEQ_ENTRY(_text) q; /* Linked list of text structures. */
+ TAILQ_ENTRY(_text) q; /* Linked list of text structures. */
char *lb; /* Line buffer. */
size_t lb_len; /* Line buffer length. */
size_t len; /* Line length. */
diff --git a/usr.bin/vi/common/line.c b/usr.bin/vi/common/line.c
index b536c829c7e..52c94956fbe 100644
--- a/usr.bin/vi/common/line.c
+++ b/usr.bin/vi/common/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.9 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: line.c,v 1.10 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -111,14 +111,16 @@ db_get(sp, lno, flags, pp, lenp)
* is there.
*/
if (F_ISSET(sp, SC_TINPUT)) {
- l1 = ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno;
- l2 = ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno;
+ l1 = ((TEXT *)TAILQ_FIRST(&sp->tiq))->lno;
+ l2 = ((TEXT *)TAILQ_LAST(&sp->tiq, _texth))->lno;
if (l1 <= lno && l2 >= lno) {
#if defined(DEBUG) && 0
TRACE(sp, "retrieve TEXT buffer line %lu\n", (u_long)lno);
#endif
- for (tp = CIRCLEQ_FIRST(&sp->tiq);
- tp->lno != lno; tp = CIRCLEQ_NEXT(tp, q));
+ TAILQ_FOREACH(tp, &sp->tiq, q) {
+ if (tp->lno == lno)
+ break;
+ }
if (lenp != NULL)
*lenp = tp->len;
if (pp != NULL)
@@ -462,8 +464,8 @@ db_exist(sp, lno)
*/
if (ep->c_nlines != OOBLNO)
return (lno <= (F_ISSET(sp, SC_TINPUT) ?
- ep->c_nlines + (((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno -
- ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno) : ep->c_nlines));
+ ep->c_nlines + (((TEXT *)TAILQ_LAST(&sp->tiq, _texth))->lno
+ - ((TEXT *)TAILQ_FIRST(&sp->tiq))->lno) : ep->c_nlines));
/* Go get the line. */
return (!db_get(sp, lno, 0, NULL, NULL));
@@ -497,8 +499,8 @@ db_last(sp, lnop)
if (ep->c_nlines != OOBLNO) {
*lnop = ep->c_nlines;
if (F_ISSET(sp, SC_TINPUT))
- *lnop += ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno -
- ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno;
+ *lnop += ((TEXT *)TAILQ_LAST(&sp->tiq, _texth))->lno -
+ ((TEXT *)TAILQ_FIRST(&sp->tiq))->lno;
return (0);
}
@@ -525,8 +527,8 @@ db_last(sp, lnop)
/* Return the value. */
*lnop = (F_ISSET(sp, SC_TINPUT) &&
- ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno > lno ?
- ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno : lno);
+ ((TEXT *)TAILQ_LAST(&sp->tiq, _texth))->lno > lno ?
+ ((TEXT *)TAILQ_LAST(&sp->tiq, _texth))->lno : lno);
return (0);
}
diff --git a/usr.bin/vi/common/main.c b/usr.bin/vi/common/main.c
index 73957ef3e11..435e6d81596 100644
--- a/usr.bin/vi/common/main.c
+++ b/usr.bin/vi/common/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.19 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.20 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -86,7 +86,7 @@ editor(gp, argc, argv)
/* Structures shared by screens so stored in the GS structure. */
CIRCLEQ_INIT(&gp->frefq);
- CIRCLEQ_INIT(&gp->dcb_store.textq);
+ TAILQ_INIT(&gp->dcb_store.textq);
LIST_INIT(&gp->cutq);
LIST_INIT(&gp->seqq);
diff --git a/usr.bin/vi/common/put.c b/usr.bin/vi/common/put.c
index 4aa8a7fae92..61f99cac74e 100644
--- a/usr.bin/vi/common/put.c
+++ b/usr.bin/vi/common/put.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: put.c,v 1.10 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: put.c,v 1.11 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -62,7 +62,7 @@ put(sp, cbp, namep, cp, rp, append)
}
}
}
- tp = CIRCLEQ_FIRST(&cbp->textq);
+ tp = TAILQ_FIRST(&cbp->textq);
/*
* It's possible to do a put into an empty file, meaning that the cut
@@ -83,9 +83,8 @@ put(sp, cbp, namep, cp, rp, append)
if (db_last(sp, &lno))
return (1);
if (lno == 0) {
- for (; tp != (void *)&cbp->textq;
- ++lno, ++sp->rptlines[L_ADDED],
- tp = CIRCLEQ_NEXT(tp, q))
+ for (; tp; ++lno, ++sp->rptlines[L_ADDED],
+ tp = TAILQ_NEXT(tp, q))
if (db_append(sp, 1, lno, tp->lb, tp->len))
return (1);
rp->lno = 1;
@@ -98,8 +97,8 @@ put(sp, cbp, namep, cp, rp, append)
if (F_ISSET(cbp, CB_LMODE)) {
lno = append ? cp->lno : cp->lno - 1;
rp->lno = lno + 1;
- for (; tp != CIRCLEQ_END(&cbp->textq);
- ++lno, ++sp->rptlines[L_ADDED], tp = CIRCLEQ_NEXT(tp, q))
+ for (; tp;
+ ++lno, ++sp->rptlines[L_ADDED], tp = TAILQ_NEXT(tp, q))
if (db_append(sp, 1, lno, tp->lb, tp->len))
return (1);
rp->cno = 0;
@@ -161,7 +160,7 @@ put(sp, cbp, namep, cp, rp, append)
* the intermediate lines, because the line changes will lose
* the cached line.
*/
- if (CIRCLEQ_NEXT(tp, q) == CIRCLEQ_END(&cbp->textq)) {
+ if (TAILQ_EMPTY(&cbp->textq)) {
if (clen > 0) {
memcpy(t, p, clen);
t += clen;
@@ -183,7 +182,7 @@ put(sp, cbp, namep, cp, rp, append)
* Last part of original line; check for space, reset
* the pointer into the buffer.
*/
- ltp = CIRCLEQ_LAST(&cbp->textq);
+ ltp = TAILQ_LAST(&cbp->textq, _texth);
len = t - bp;
ADD_SPACE_RET(sp, bp, blen, ltp->len + clen);
t = bp + len;
@@ -211,9 +210,8 @@ put(sp, cbp, namep, cp, rp, append)
}
/* Output any intermediate lines in the CB. */
- for (tp = CIRCLEQ_NEXT(tp, q);
- CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(&cbp->textq);
- ++lno, ++sp->rptlines[L_ADDED], tp = CIRCLEQ_NEXT(tp, q))
+ for (tp = TAILQ_NEXT(tp, q); TAILQ_NEXT(tp, q);
+ ++lno, ++sp->rptlines[L_ADDED], tp = TAILQ_NEXT(tp, q))
if (db_append(sp, 1, lno, tp->lb, tp->len))
goto err;
diff --git a/usr.bin/vi/common/screen.c b/usr.bin/vi/common/screen.c
index d248e39b5e5..2f5e747d66b 100644
--- a/usr.bin/vi/common/screen.c
+++ b/usr.bin/vi/common/screen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen.c,v 1.8 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: screen.c,v 1.9 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -58,7 +58,7 @@ screen_init(gp, orig, spp)
* we don't have the option information yet.
*/
- CIRCLEQ_INIT(&sp->tiq);
+ TAILQ_INIT(&sp->tiq);
/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
if (orig == NULL) {
@@ -168,7 +168,7 @@ screen_end(sp)
}
/* Free any text input. */
- if (CIRCLEQ_FIRST(&sp->tiq) != NULL)
+ if (TAILQ_FIRST(&sp->tiq) != NULL)
text_lfree(&sp->tiq);
/* Free alternate file name. */
diff --git a/usr.bin/vi/ex/ex.c b/usr.bin/vi/ex/ex.c
index 6c352e3b7c7..5da0f2cf5b5 100644
--- a/usr.bin/vi/ex/ex.c
+++ b/usr.bin/vi/ex/ex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex.c,v 1.16 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex.c,v 1.17 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -116,7 +116,7 @@ ex(spp)
* If the user entered a single carriage return, send
* ex_cmd() a separator -- it discards single newlines.
*/
- tp = CIRCLEQ_FIRST(&sp->tiq);
+ tp = TAILQ_FIRST(&sp->tiq);
if (tp->len == 0) {
gp->excmd.cp = " "; /* __TK__ why not |? */
gp->excmd.clen = 1;
diff --git a/usr.bin/vi/ex/ex_append.c b/usr.bin/vi/ex/ex_append.c
index 686ed84b370..b3d78061714 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.8 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_append.c,v 1.9 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -253,15 +253,17 @@ ex_aci(sp, cmdp, cmd)
* into the file, above.)
*/
memset(&tiq, 0, sizeof(TEXTH));
- CIRCLEQ_INIT(&tiq);
+ TAILQ_INIT(&tiq);
if (ex_txt(sp, &tiq, 0, flags))
return (1);
- for (cnt = 0, tp = CIRCLEQ_FIRST(&tiq);
- tp != (TEXT *)&tiq; ++cnt, tp = CIRCLEQ_NEXT(tp, q))
+ cnt = 0;
+ TAILQ_FOREACH(tp, &tiq, q) {
if (db_append(sp, 1, lno++, tp->lb, tp->len))
return (1);
+ cnt++;
+ }
/*
* Set sp->lno to the final line number value (correcting for a
diff --git a/usr.bin/vi/ex/ex_at.c b/usr.bin/vi/ex/ex_at.c
index e3fd1832146..e695189847e 100644
--- a/usr.bin/vi/ex/ex_at.c
+++ b/usr.bin/vi/ex/ex_at.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_at.c,v 1.8 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_at.c,v 1.9 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -102,9 +102,10 @@ ex_at(sp, cmdp)
* Build two copies of the command. We need two copies because the
* ex parser may step on the command string when it's parsing it.
*/
- for (len = 0, tp = CIRCLEQ_LAST(&cbp->textq);
- tp != CIRCLEQ_END(&cbp->textq); tp = CIRCLEQ_PREV(tp, q))
+ len = 0;
+ TAILQ_FOREACH_REVERSE(tp, &cbp->textq, _texth, q) {
len += tp->len + 1;
+ }
MALLOC_RET(sp, ecp->cp, char *, len * 2);
ecp->o_cp = ecp->cp;
@@ -112,8 +113,8 @@ ex_at(sp, cmdp)
ecp->cp[len] = '\0';
/* Copy the buffer into the command space. */
- for (p = ecp->cp + len, tp = CIRCLEQ_LAST(&cbp->textq);
- tp != CIRCLEQ_END(&cbp->textq); tp = CIRCLEQ_PREV(tp, q)) {
+ p = ecp->cp + len;
+ TAILQ_FOREACH_REVERSE(tp, &cbp->textq, _texth, q) {
memcpy(p, tp->lb, tp->len);
p += tp->len;
*p++ = '\n';
diff --git a/usr.bin/vi/ex/ex_cscope.c b/usr.bin/vi/ex/ex_cscope.c
index 060bee19f6f..8c2fd7511a9 100644
--- a/usr.bin/vi/ex/ex_cscope.c
+++ b/usr.bin/vi/ex/ex_cscope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_cscope.c,v 1.17 2013/08/22 04:43:40 guenther Exp $ */
+/* $OpenBSD: ex_cscope.c,v 1.18 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1994, 1996
@@ -625,8 +625,8 @@ usage: (void)csc_help(sp, "find");
if (p[0] == '"' && p[1] != '\0' && p[2] == '\0')
CBNAME(sp, cbp, p[1]);
if (cbp != NULL) {
- p = CIRCLEQ_FIRST(&cbp->textq)->lb;
- tlen = CIRCLEQ_FIRST(&cbp->textq)->len;
+ p = TAILQ_FIRST(&cbp->textq)->lb;
+ tlen = TAILQ_FIRST(&cbp->textq)->len;
} else
tlen = strlen(p);
diff --git a/usr.bin/vi/ex/ex_display.c b/usr.bin/vi/ex/ex_display.c
index ce5c0ed4520..bb717e48ced 100644
--- a/usr.bin/vi/ex/ex_display.c
+++ b/usr.bin/vi/ex/ex_display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_display.c,v 1.7 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_display.c,v 1.8 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -92,7 +92,7 @@ bdisplay(sp)
LIST_FOREACH(cbp, &sp->gp->cutq, q) {
if (isdigit(cbp->name))
continue;
- if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq))
+ if (!TAILQ_EMPTY(&cbp->textq))
db(sp, cbp, NULL);
if (INTERRUPTED(sp))
return (0);
@@ -101,7 +101,7 @@ bdisplay(sp)
LIST_FOREACH(cbp, &sp->gp->cutq, q) {
if (!isdigit(cbp->name))
continue;
- if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq))
+ if (!TAILQ_EMPTY(&cbp->textq))
db(sp, cbp, NULL);
if (INTERRUPTED(sp))
return (0);
@@ -129,7 +129,7 @@ db(sp, cbp, name)
(void)ex_printf(sp, "********** %s%s\n",
name == NULL ? KEY_NAME(sp, cbp->name) : name,
F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
- CIRCLEQ_FOREACH(tp, &cbp->textq, q) {
+ TAILQ_FOREACH(tp, &cbp->textq, q) {
for (len = tp->len, p = tp->lb; len--; ++p) {
(void)ex_puts(sp, KEY_NAME(sp, *p));
if (INTERRUPTED(sp))
diff --git a/usr.bin/vi/ex/ex_move.c b/usr.bin/vi/ex/ex_move.c
index 95e8261e529..7a7651a88be 100644
--- a/usr.bin/vi/ex/ex_move.c
+++ b/usr.bin/vi/ex/ex_move.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_move.c,v 1.8 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_move.c,v 1.9 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -50,7 +50,7 @@ ex_copy(sp, cmdp)
fm1 = cmdp->addr1;
fm2 = cmdp->addr2;
memset(&cb, 0, sizeof(cb));
- CIRCLEQ_INIT(&cb.textq);
+ TAILQ_INIT(&cb.textq);
for (cnt = fm1.lno; cnt <= fm2.lno; ++cnt)
if (cut_line(sp, cnt, 0, CUT_LINE_TO_EOL, &cb)) {
rval = 1;
diff --git a/usr.bin/vi/ex/ex_subst.c b/usr.bin/vi/ex/ex_subst.c
index 3b2053bac3a..c52ab9d0bea 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.17 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_subst.c,v 1.18 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -444,7 +444,7 @@ s(sp, cmdp, s, re, flags)
/* Ex text structure initialization. */
if (F_ISSET(sp, SC_EX)) {
memset(&tiq, 0, sizeof(TEXTH));
- CIRCLEQ_INIT(&tiq);
+ TAILQ_INIT(&tiq);
}
break;
case 'g':
@@ -659,7 +659,7 @@ nextmatch: match[0].rm_so = 0;
goto lquit;
if (ex_txt(sp, &tiq, 0, TXT_CR))
goto err;
- ev.e_c = CIRCLEQ_FIRST(&tiq)->lb[0];
+ ev.e_c = TAILQ_FIRST(&tiq)->lb[0];
}
switch (ev.e_c) {
diff --git a/usr.bin/vi/ex/ex_txt.c b/usr.bin/vi/ex/ex_txt.c
index 5d6e7b5c776..ed2bb3f1b70 100644
--- a/usr.bin/vi/ex/ex_txt.c
+++ b/usr.bin/vi/ex/ex_txt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ex_txt.c,v 1.10 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: ex_txt.c,v 1.11 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -70,9 +70,9 @@ ex_txt(sp, tiqh, prompt, flags)
* last one if it's big enough. (All TEXT bookkeeping fields default
* to 0 -- text_init() handles this.)
*/
- if (CIRCLEQ_FIRST(tiqh) != CIRCLEQ_END(tiqh)) {
- tp = CIRCLEQ_FIRST(tiqh);
- if (CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(tiqh) || tp->lb_len < 32) {
+ if (!TAILQ_EMPTY(tiqh)) {
+ tp = TAILQ_FIRST(tiqh);
+ if (TAILQ_NEXT(tp, q) || tp->lb_len < 32) {
text_lfree(tiqh);
goto newtp;
}
@@ -80,7 +80,7 @@ ex_txt(sp, tiqh, prompt, flags)
} else {
newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL)
goto err;
- CIRCLEQ_INSERT_HEAD(tiqh, tp, q);
+ TAILQ_INSERT_HEAD(tiqh, tp, q);
}
/* Set the starting line number. */
@@ -187,7 +187,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL)
*/
if (LF_ISSET(TXT_DOTTERM) && tp->len == tp->ai + 1 &&
tp->lb[tp->len - 1] == '.') {
-notlast: CIRCLEQ_REMOVE(tiqh, tp, q);
+notlast: TAILQ_REMOVE(tiqh, tp, q);
text_free(tp);
goto done;
}
@@ -224,7 +224,7 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q);
* into the queue.
*/
tp = ntp;
- CIRCLEQ_INSERT_TAIL(tiqh, tp, q);
+ TAILQ_INSERT_TAIL(tiqh, tp, q);
break;
case K_CARAT: /* Delete autoindent chars. */
if (tp->len <= tp->ai && LF_ISSET(TXT_AUTOINDENT))
diff --git a/usr.bin/vi/vi/v_at.c b/usr.bin/vi/vi/v_at.c
index 233f9a73189..fb777e6895d 100644
--- a/usr.bin/vi/vi/v_at.c
+++ b/usr.bin/vi/vi/v_at.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: v_at.c,v 1.7 2009/10/27 23:59:47 deraadt Exp $ */
+/* $OpenBSD: v_at.c,v 1.8 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -85,9 +85,8 @@ v_at(sp, vp)
* together. We don't get this right; I'm waiting for the new DB
* logging code to be available.
*/
- CIRCLEQ_FOREACH_REVERSE(tp, &cbp->textq, q)
- if (((F_ISSET(cbp, CB_LMODE) ||
- CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(&cbp->textq)) &&
+ TAILQ_FOREACH_REVERSE(tp, &cbp->textq, _texth, q)
+ if (((F_ISSET(cbp, CB_LMODE) || TAILQ_NEXT(tp, q)) &&
v_event_push(sp, NULL, "\n", 1, 0)) ||
v_event_push(sp, NULL, tp->lb, tp->len, 0))
return (1);
diff --git a/usr.bin/vi/vi/v_ex.c b/usr.bin/vi/vi/v_ex.c
index d2f287bf49c..2d1dce24364 100644
--- a/usr.bin/vi/vi/v_ex.c
+++ b/usr.bin/vi/vi/v_ex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: v_ex.c,v 1.10 2009/11/14 17:44:53 jsg Exp $ */
+/* $OpenBSD: v_ex.c,v 1.11 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -310,7 +310,7 @@ v_filter(sp, vp)
* Entering <escape> on an empty line was historically an error,
* this implementation doesn't bother.
*/
- tp = CIRCLEQ_FIRST(&sp->tiq);
+ tp = TAILQ_FIRST(&sp->tiq);
if (tp->term != TERM_OK) {
vp->m_final.lno = sp->lno;
vp->m_final.cno = sp->cno;
@@ -409,7 +409,7 @@ v_ex(sp, vp)
if (v_tcmd(sp, vp, ':',
TXT_BS | TXT_CEDIT | TXT_FILEC | TXT_PROMPT))
return (1);
- tp = CIRCLEQ_FIRST(&sp->tiq);
+ tp = TAILQ_FIRST(&sp->tiq);
/*
* If the user entered a single <esc>, they want to
diff --git a/usr.bin/vi/vi/v_search.c b/usr.bin/vi/vi/v_search.c
index 4c3599ae064..388a5b234a0 100644
--- a/usr.bin/vi/vi/v_search.c
+++ b/usr.bin/vi/vi/v_search.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: v_search.c,v 1.11 2009/10/27 23:59:48 deraadt Exp $ */
+/* $OpenBSD: v_search.c,v 1.12 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -91,7 +91,7 @@ v_exaddr(sp, vp, dir)
(O_ISSET(sp, O_SEARCHINCR) ? TXT_SEARCHINCR : 0)))
return (1);
- tp = CIRCLEQ_FIRST(&sp->tiq);
+ tp = TAILQ_FIRST(&sp->tiq);
/* If the user backspaced over the prompt, do nothing. */
if (tp->term == TERM_BS)
diff --git a/usr.bin/vi/vi/v_txt.c b/usr.bin/vi/vi/v_txt.c
index a4efd36b08f..0e26ef2aafc 100644
--- a/usr.bin/vi/vi/v_txt.c
+++ b/usr.bin/vi/vi/v_txt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: v_txt.c,v 1.23 2013/05/14 11:51:41 millert Exp $ */
+/* $OpenBSD: v_txt.c,v 1.24 2013/11/25 23:27:11 krw Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -297,9 +297,9 @@ v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags)
* copy it into the TEXT buffer.
*/
tiqh = &sp->tiq;
- if (CIRCLEQ_FIRST(tiqh) != CIRCLEQ_END(tiqh)) {
- tp = CIRCLEQ_FIRST(tiqh);
- if (CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(tiqh) || tp->lb_len < len + 32) {
+ if (!TAILQ_EMPTY(tiqh)) {
+ tp = TAILQ_FIRST(tiqh);
+ if (TAILQ_NEXT(tp, q) || tp->lb_len < len + 32) {
text_lfree(tiqh);
goto newtp;
}
@@ -312,7 +312,7 @@ v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags)
} else {
newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
return (1);
- CIRCLEQ_INSERT_HEAD(tiqh, tp, q);
+ TAILQ_INSERT_HEAD(tiqh, tp, q);
}
/* Set default termination condition. */
@@ -787,7 +787,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
if ((ntp = text_init(sp, p,
insert + owrite, insert + owrite + 32)) == NULL)
goto err;
- CIRCLEQ_INSERT_TAIL(&sp->tiq, ntp, q);
+ TAILQ_INSERT_TAIL(&sp->tiq, ntp, q);
/* Set up bookkeeping for the new line. */
ntp->insert = insert;
@@ -1844,7 +1844,7 @@ txt_backup(sp, tiqh, tp, flagsp)
TEXT *ntp;
/* Get a handle on the previous TEXT structure. */
- if ((ntp = CIRCLEQ_PREV(tp, q)) == CIRCLEQ_END(tiqh)) {
+ if ((ntp = TAILQ_PREV(tp, _texth, q))) {
if (!FL_ISSET(*flagsp, TXT_REPLAY))
msgq(sp, M_BERR,
"193|Already at the beginning of the insert");
@@ -1864,7 +1864,7 @@ txt_backup(sp, tiqh, tp, flagsp)
FL_CLR(*flagsp, TXT_APPENDEOL);
/* Release the current TEXT. */
- CIRCLEQ_REMOVE(tiqh, tp, q);
+ TAILQ_REMOVE(tiqh, tp, q);
text_free(tp);
/* Update the old line on the screen. */
@@ -2352,7 +2352,7 @@ txt_err(sp, tiqh)
* We depend on at least one line number being set in the text
* chain.
*/
- for (lno = CIRCLEQ_FIRST(tiqh)->lno;
+ for (lno = TAILQ_FIRST(tiqh)->lno;
!db_exist(sp, lno) && lno > 0; --lno);
sp->lno = lno == 0 ? 1 : lno;
@@ -2708,7 +2708,7 @@ txt_resolve(sp, tiqh, flags)
* change, we have to redisplay it, otherwise the information cached
* about the line will be wrong.
*/
- tp = CIRCLEQ_FIRST(tiqh);
+ tp = TAILQ_FIRST(tiqh);
if (LF_ISSET(TXT_AUTOINDENT))
txt_ai_resolve(sp, tp, &changed);
@@ -2718,7 +2718,7 @@ txt_resolve(sp, tiqh, flags)
(changed && vs_change(sp, tp->lno, LINE_RESET)))
return (1);
- for (lno = tp->lno; (tp = CIRCLEQ_NEXT(tp, q)) != (void *)&sp->tiq; ++lno) {
+ for (lno = tp->lno; (tp = TAILQ_NEXT(tp, q)); ++lno) {
if (LF_ISSET(TXT_AUTOINDENT))
txt_ai_resolve(sp, tp, &changed);
else
@@ -2910,9 +2910,9 @@ txt_Rresolve(sp, tiqh, tp, orig_len)
* Calculate how many characters the user has entered,
* plus the blanks erased by <carriage-return>/<newline>s.
*/
- for (ttp = CIRCLEQ_FIRST(tiqh), input_len = 0;;) {
+ for (ttp = TAILQ_FIRST(tiqh), input_len = 0;;) {
input_len += ttp == tp ? tp->cno : ttp->len + ttp->R_erase;
- if ((ttp = CIRCLEQ_NEXT(ttp, q)) == CIRCLEQ_END(&sp->tiq))
+ if (!(ttp = TAILQ_NEXT(ttp, q)))
break;
}
@@ -2933,7 +2933,7 @@ txt_Rresolve(sp, tiqh, tp, orig_len)
if (input_len < orig_len) {
retain = MIN(tp->owrite, orig_len - input_len);
if (db_get(sp,
- CIRCLEQ_FIRST(tiqh)->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL))
+ TAILQ_FIRST(tiqh)->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL))
return;
memcpy(tp->lb + tp->cno, p + input_len, retain);
tp->len -= tp->owrite - retain;