diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-10-17 19:12:17 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-10-17 19:12:17 +0000 |
commit | fc91c16f0414890757292add34af8bee286c868f (patch) | |
tree | cae7aadb7c382702828e9adfc895f1537896aa47 /usr.bin/vi | |
parent | 8728eaba8fdf623ad4a0e57bddd7a3237166a42a (diff) |
Use queue macros instead of directly accessing fields. ok pat@ "put it
in" deraadt@
Diffstat (limited to 'usr.bin/vi')
36 files changed, 228 insertions, 248 deletions
diff --git a/usr.bin/vi/cl/cl_read.c b/usr.bin/vi/cl/cl_read.c index 8b3db162f65..0d49c42bb58 100644 --- a/usr.bin/vi/cl/cl_read.c +++ b/usr.bin/vi/cl/cl_read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_read.c,v 1.12 2003/09/02 22:44:06 dhartmei Exp $ */ +/* $OpenBSD: cl_read.c,v 1.13 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -156,8 +156,7 @@ cl_read(sp, flags, bp, blen, nrp, tp) /* Allocate space for rdfd. */ maxfd = STDIN_FILENO; - for (tsp = gp->dq.cqh_first; - tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next) + CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT) && sp->script->sh_master > maxfd) maxfd = sp->script->sh_master; rdfd = (fd_set *)malloc(howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); @@ -240,8 +239,7 @@ cl_read(sp, flags, bp, blen, nrp, tp) if (F_ISSET(gp, G_SCRWIN)) { loop: memset(rdfd, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); FD_SET(STDIN_FILENO, rdfd); - for (tsp = gp->dq.cqh_first; - tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next) + CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT)) FD_SET(sp->script->sh_master, rdfd); switch (select(maxfd + 1, rdfd, NULL, NULL, NULL)) { diff --git a/usr.bin/vi/cl/cl_screen.c b/usr.bin/vi/cl/cl_screen.c index 22fac8f8249..a870d1bc63e 100644 --- a/usr.bin/vi/cl/cl_screen.c +++ b/usr.bin/vi/cl/cl_screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_screen.c,v 1.15 2005/04/21 09:00:25 otto Exp $ */ +/* $OpenBSD: cl_screen.c,v 1.16 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -93,7 +93,7 @@ cl_screen(sp, flags) if (F_ISSET(sp, SC_SCR_VI)) { F_CLR(sp, SC_SCR_VI); - if (sp->q.cqe_next != (void *)&gp->dq) { + if (CIRCLEQ_NEXT(sp, q) != CIRCLEQ_END(&gp->dq)) { (void)move(RLNO(sp, sp->rows), 0); clrtobot(); } diff --git a/usr.bin/vi/cl/cl_term.c b/usr.bin/vi/cl/cl_term.c index 6a945ef5b9f..cbfb8119168 100644 --- a/usr.bin/vi/cl/cl_term.c +++ b/usr.bin/vi/cl/cl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_term.c,v 1.12 2002/02/16 21:27:56 millert Exp $ */ +/* $OpenBSD: cl_term.c,v 1.13 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -144,7 +144,7 @@ cl_term_init(sp) * Rework any function key mappings that were set before the * screen was initialized. */ - for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) + LIST_FOREACH(qp, & sp->gp->seqq, q) if (F_ISSET(qp, SEQ_FUNCMAP)) (void)cl_pfmap(sp, qp->stype, qp->input, qp->ilen, qp->output, qp->olen); @@ -164,8 +164,8 @@ cl_term_end(gp) SEQ *qp, *nqp; /* Delete screen specific mappings. */ - for (qp = gp->seqq.lh_first; qp != NULL; qp = nqp) { - nqp = qp->q.le_next; + for (qp = LIST_FIRST(&gp->seqq); qp != NULL; qp = nqp) { + nqp = LIST_NEXT(qp, q); if (F_ISSET(qp, SEQ_SCREEN)) (void)seq_mdel(qp); } diff --git a/usr.bin/vi/common/cut.c b/usr.bin/vi/common/cut.c index 32a5fb512f1..c5beeb8fb0d 100644 --- a/usr.bin/vi/common/cut.c +++ b/usr.bin/vi/common/cut.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cut.c,v 1.7 2002/02/16 21:27:56 millert Exp $ */ +/* $OpenBSD: cut.c,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -198,7 +198,7 @@ cb_rotate(sp) CB *cbp, *del_cbp; del_cbp = NULL; - for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) + LIST_FOREACH(cbp, &sp->gp->cutq, q) switch(cbp->name) { case '1': cbp->name = '2'; @@ -291,8 +291,8 @@ cut_close(gp) CB *cbp; /* Free cut buffer list. */ - while ((cbp = gp->cutq.lh_first) != NULL) { - if (cbp->textq.cqh_first != (void *)&cbp->textq) + while ((cbp = LIST_FIRST(&gp->cutq)) != NULL) { + if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq)) text_lfree(&cbp->textq); LIST_REMOVE(cbp, q); free(cbp); @@ -300,7 +300,7 @@ cut_close(gp) /* Free default cut storage. */ cbp = &gp->dcb_store; - if (cbp->textq.cqh_first != (void *)&cbp->textq) + if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq)) text_lfree(&cbp->textq); } @@ -347,7 +347,7 @@ text_lfree(headp) { TEXT *tp; - while ((tp = headp->cqh_first) != (void *)headp) { + while ((tp = CIRCLEQ_FIRST(headp)) != CIRCLEQ_END(headp)) { CIRCLEQ_REMOVE(headp, tp, q); text_free(tp); } diff --git a/usr.bin/vi/common/cut.h b/usr.bin/vi/common/cut.h index 1202004193b..8ea31d58040 100644 --- a/usr.bin/vi/common/cut.h +++ b/usr.bin/vi/common/cut.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cut.h,v 1.4 2002/01/31 11:10:39 hugh Exp $ */ +/* $OpenBSD: cut.h,v 1.5 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -67,8 +67,7 @@ struct _text { /* Text: a linked list of lines. */ #define CBNAME(sp, cbp, nch) { \ CHAR_T L__name; \ L__name = isupper(nch) ? tolower(nch) : (nch); \ - for (cbp = sp->gp->cutq.lh_first; \ - cbp != NULL; cbp = cbp->q.le_next) \ + LIST_FOREACH((cbp), &(sp)->gp->cutq, q) \ if (cbp->name == L__name) \ break; \ } diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c index 94046cc8392..065ac0d8af9 100644 --- a/usr.bin/vi/common/exf.c +++ b/usr.bin/vi/common/exf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exf.c,v 1.20 2003/12/31 18:18:22 millert Exp $ */ +/* $OpenBSD: exf.c,v 1.21 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -79,10 +79,9 @@ file_add(sp, name) */ gp = sp->gp; if (name != NULL) - for (frp = gp->frefq.cqh_first; - frp != (FREF *)&gp->frefq; frp = frp->q.cqe_next) { + CIRCLEQ_FOREACH(frp, &gp->frefq, q) { if (frp->name == NULL) { - tfrp = frp->q.cqe_next; + tfrp = CIRCLEQ_NEXT(frp, q); CIRCLEQ_REMOVE(&gp->frefq, frp, q); if (frp->name != NULL) free(frp->name); diff --git a/usr.bin/vi/common/gs.h b/usr.bin/vi/common/gs.h index c0674b63b6c..eca92f90ee5 100644 --- a/usr.bin/vi/common/gs.h +++ b/usr.bin/vi/common/gs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gs.h,v 1.7 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: gs.h,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -91,7 +91,7 @@ struct _gs { * Ex command structures (EXCMD). Defined here because ex commands * exist outside of any particular screen or file. */ -#define EXCMD_RUNNING(gp) ((gp)->ecq.lh_first->clen != 0) +#define EXCMD_RUNNING(gp) (LIST_FIRST(&(gp)->ecq)->clen != 0) LIST_HEAD(_excmdh, _excmd) ecq; /* Ex command linked list. */ EXCMD excmd; /* Default ex command structure. */ char *if_name; /* Current associated file. */ diff --git a/usr.bin/vi/common/key.c b/usr.bin/vi/common/key.c index d23dccda1d0..f08a2039c5a 100644 --- a/usr.bin/vi/common/key.c +++ b/usr.bin/vi/common/key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key.c,v 1.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: key.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -753,9 +753,9 @@ v_sync(sp, flags) GS *gp; gp = sp->gp; - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->dq, q) rcv_sync(sp, flags); - for (sp = gp->hq.cqh_first; sp != (void *)&gp->hq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->hq, q) rcv_sync(sp, flags); } diff --git a/usr.bin/vi/common/line.c b/usr.bin/vi/common/line.c index b1075923451..0e64f8c761b 100644 --- a/usr.bin/vi/common/line.c +++ b/usr.bin/vi/common/line.c @@ -1,4 +1,4 @@ -/* $OpenBSD: line.c,v 1.5 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: line.c,v 1.6 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -115,14 +115,14 @@ db_get(sp, lno, flags, pp, lenp) * is there. */ if (F_ISSET(sp, SC_TINPUT)) { - l1 = ((TEXT *)sp->tiq.cqh_first)->lno; - l2 = ((TEXT *)sp->tiq.cqh_last)->lno; + l1 = ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno; + l2 = ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno; if (l1 <= lno && l2 >= lno) { #if defined(DEBUG) && 0 TRACE(sp, "retrieve TEXT buffer line %lu\n", (u_long)lno); #endif - for (tp = sp->tiq.cqh_first; - tp->lno != lno; tp = tp->q.cqe_next); + for (tp = CIRCLEQ_FIRST(&sp->tiq); + tp->lno != lno; tp = CIRCLEQ_NEXT(tp, q)); if (lenp != NULL) *lenp = tp->len; if (pp != NULL) @@ -467,7 +467,7 @@ db_exist(sp, lno) if (ep->c_nlines != OOBLNO) return (lno <= (F_ISSET(sp, SC_TINPUT) ? ep->c_nlines + (((TEXT *)sp->tiq.cqh_last)->lno - - ((TEXT *)sp->tiq.cqh_first)->lno) : ep->c_nlines)); + ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno) : ep->c_nlines)); /* Go get the line. */ return (!db_get(sp, lno, 0, NULL, NULL)); @@ -502,7 +502,7 @@ db_last(sp, lnop) *lnop = ep->c_nlines; if (F_ISSET(sp, SC_TINPUT)) *lnop += ((TEXT *)sp->tiq.cqh_last)->lno - - ((TEXT *)sp->tiq.cqh_first)->lno; + ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno; return (0); } @@ -569,8 +569,7 @@ scr_update(sp, lno, op, current) ep = sp->ep; if (ep->refcnt != 1) - for (tsp = sp->gp->dq.cqh_first; - tsp != (void *)&sp->gp->dq; tsp = tsp->q.cqe_next) + CIRCLEQ_FOREACH(tsp, &sp->gp->dq, q) if (sp != tsp && tsp->ep == ep) if (vs_change(tsp, lno, op)) return (1); diff --git a/usr.bin/vi/common/main.c b/usr.bin/vi/common/main.c index aa81444c60f..d776e6153a3 100644 --- a/usr.bin/vi/common/main.c +++ b/usr.bin/vi/common/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.10 2003/04/17 02:22:56 itojun Exp $ */ +/* $OpenBSD: main.c,v 1.11 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -450,9 +450,9 @@ v_end(gp) (void)file_end(gp->ccl_sp, NULL, 1); (void)screen_end(gp->ccl_sp); } - while ((sp = gp->dq.cqh_first) != (void *)&gp->dq) + while ((sp = CIRCLEQ_FIRST(&gp->dq)) != CIRCLEQ_END(&gp->dq)) (void)screen_end(sp); - while ((sp = gp->hq.cqh_first) != (void *)&gp->hq) + while ((sp = CIRCLEQ_FIRST(&gp->hq)) != CIRCLEQ_END(&gp->hq)) (void)screen_end(sp); #ifdef HAVE_PERL_INTERP @@ -499,7 +499,7 @@ v_end(gp) * it's possible that the user is sourcing a file that exits from the * editor). */ - while ((mp = gp->msgq.lh_first) != NULL) { + while ((mp = LIST_FIRST(&gp->msgq)) != NULL) { (void)fprintf(stderr, "%s%.*s", mp->mtype == M_ERR ? "ex/vi: " : "", (int)mp->len, mp->buf); LIST_REMOVE(mp, q); diff --git a/usr.bin/vi/common/mark.c b/usr.bin/vi/common/mark.c index e18183732c9..53427bf0580 100644 --- a/usr.bin/vi/common/mark.c +++ b/usr.bin/vi/common/mark.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mark.c,v 1.5 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: mark.c,v 1.6 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -98,7 +98,7 @@ mark_end(sp, ep) * !!! * ep MAY NOT BE THE SAME AS sp->ep, DON'T USE THE LATTER. */ - while ((lmp = ep->marks.lh_first) != NULL) { + while ((lmp = LIST_FIRST(&ep->marks)) != NULL) { LIST_REMOVE(lmp, q); free(lmp); } @@ -209,8 +209,8 @@ mark_find(sp, key) * Return the requested mark or the slot immediately before * where it should go. */ - for (lastlmp = NULL, lmp = sp->ep->marks.lh_first; - lmp != NULL; lastlmp = lmp, lmp = lmp->q.le_next) + for (lastlmp = NULL, lmp = LIST_FIRST(&sp->ep->marks); + lmp != NULL; lastlmp = lmp, lmp = LIST_NEXT(lmp, q)) if (lmp->name >= key) return (lmp->name == key ? lmp : lastlmp); return (lastlmp); @@ -236,8 +236,7 @@ mark_insdel(sp, op, lno) /* All insert/append operations are done as inserts. */ abort(); case LINE_DELETE: - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->lno >= lno) if (lmp->lno == lno) { F_SET(lmp, MARK_DELETED); @@ -267,8 +266,7 @@ mark_insdel(sp, op, lno) return (0); } - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->lno >= lno) ++lmp->lno; break; diff --git a/usr.bin/vi/common/put.c b/usr.bin/vi/common/put.c index 08ee3b79240..9e855818ac2 100644 --- a/usr.bin/vi/common/put.c +++ b/usr.bin/vi/common/put.c @@ -1,4 +1,4 @@ -/* $OpenBSD: put.c,v 1.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: put.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -65,7 +65,7 @@ put(sp, cbp, namep, cp, rp, append) return (1); } } - tp = cbp->textq.cqh_first; + tp = CIRCLEQ_FIRST(&cbp->textq); /* * It's possible to do a put into an empty file, meaning that the cut @@ -87,7 +87,8 @@ put(sp, cbp, namep, cp, rp, append) return (1); if (lno == 0) { for (; tp != (void *)&cbp->textq; - ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next) + ++lno, ++sp->rptlines[L_ADDED], + tp = CIRCLEQ_NEXT(tp, q)) if (db_append(sp, 1, lno, tp->lb, tp->len)) return (1); rp->lno = 1; @@ -100,8 +101,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 != (void *)&cbp->textq; - ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next) + for (; tp != CIRCLEQ_END(&cbp->textq); + ++lno, ++sp->rptlines[L_ADDED], tp = CIRCLEQ_NEXT(tp, q)) if (db_append(sp, 1, lno, tp->lb, tp->len)) return (1); rp->cno = 0; @@ -163,7 +164,7 @@ put(sp, cbp, namep, cp, rp, append) * the intermediate lines, because the line changes will lose * the cached line. */ - if (tp->q.cqe_next == (void *)&cbp->textq) { + if (CIRCLEQ_NEXT(tp, q) == CIRCLEQ_END(&cbp->textq)) { if (clen > 0) { memcpy(t, p, clen); t += clen; @@ -213,9 +214,9 @@ put(sp, cbp, namep, cp, rp, append) } /* Output any intermediate lines in the CB. */ - for (tp = tp->q.cqe_next; - tp->q.cqe_next != (void *)&cbp->textq; - ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next) + for (tp = CIRCLEQ_NEXT(tp, q); + CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(&cbp->textq); + ++lno, ++sp->rptlines[L_ADDED], tp = CIRCLEQ_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 78a7283ed83..d82fb005c5c 100644 --- a/usr.bin/vi/common/screen.c +++ b/usr.bin/vi/common/screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.c,v 1.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: screen.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -146,7 +146,7 @@ screen_end(sp) * If a created screen failed during initialization, it may not * be linked into the chain. */ - if (sp->q.cqe_next != NULL) + if (CIRCLEQ_NEXT(sp, q) != NULL) CIRCLEQ_REMOVE(&sp->gp->dq, sp, q); /* The screen is no longer real. */ @@ -172,7 +172,7 @@ screen_end(sp) } /* Free any text input. */ - if (sp->tiq.cqh_first != NULL) + if (CIRCLEQ_FIRST(&sp->tiq) != NULL) text_lfree(&sp->tiq); /* Free alternate file name. */ @@ -217,16 +217,15 @@ screen_next(sp) /* Try the display queue, without returning the current screen. */ gp = sp->gp; - for (next = gp->dq.cqh_first; - next != (void *)&gp->dq; next = next->q.cqe_next) + CIRCLEQ_FOREACH(next, &gp->dq, q) if (next != sp) break; if (next != (void *)&gp->dq) return (next); /* Try the hidden queue; if found, move screen to the display queue. */ - if (gp->hq.cqh_first != (void *)&gp->hq) { - next = gp->hq.cqh_first; + if (CIRCLEQ_FIRST(&gp->hq) != CIRCLEQ_END(&gp->hq)) { + next = CIRCLEQ_FIRST(&gp->hq); CIRCLEQ_REMOVE(&gp->hq, next, q); CIRCLEQ_INSERT_HEAD(&gp->dq, next, q); return (next); diff --git a/usr.bin/vi/common/seq.c b/usr.bin/vi/common/seq.c index 6c4c05917ed..268c46c5b3d 100644 --- a/usr.bin/vi/common/seq.c +++ b/usr.bin/vi/common/seq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: seq.c,v 1.6 2002/02/17 19:42:34 millert Exp $ */ +/* $OpenBSD: seq.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -202,8 +202,8 @@ seq_find(sp, lastqp, e_input, c_input, ilen, stype, ispartialp) */ if (ispartialp != NULL) *ispartialp = 0; - for (lqp = NULL, qp = sp->gp->seqq.lh_first; - qp != NULL; lqp = qp, qp = qp->q.le_next) { + for (lqp = NULL, qp = LIST_FIRST(&sp->gp->seqq); + qp != NULL; lqp = qp, qp = LIST_NEXT(qp, q)) { /* * Fast checks on the first character and type, and then * a real comparison. @@ -268,7 +268,7 @@ seq_close(gp) { SEQ *qp; - while ((qp = gp->seqq.lh_first) != NULL) { + while ((qp = LIST_FIRST(&gp->seqq)) != NULL) { if (qp->name != NULL) free(qp->name); if (qp->input != NULL) @@ -299,7 +299,7 @@ seq_dump(sp, stype, isname) cnt = 0; gp = sp->gp; - for (qp = gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) { + LIST_FOREACH(qp, &gp->seqq, q) { if (stype != qp->stype || F_ISSET(qp, SEQ_FUNCMAP)) continue; ++cnt; @@ -347,7 +347,7 @@ seq_save(sp, fp, prefix, stype) int ch; /* Write a sequence command for all keys the user defined. */ - for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) { + LIST_FOREACH(qp, &sp->gp->seqq, q) { if (stype != qp->stype || !F_ISSET(qp, SEQ_USERDEF)) continue; if (prefix) diff --git a/usr.bin/vi/ex/ex.c b/usr.bin/vi/ex/ex.c index 0fda351ba1e..68d82bc8bb1 100644 --- a/usr.bin/vi/ex/ex.c +++ b/usr.bin/vi/ex/ex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex.c,v 1.11 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex.c,v 1.12 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -69,7 +69,7 @@ ex(spp) return (1); /* Flush any saved messages. */ - while ((mp = gp->msgq.lh_first) != NULL) { + while ((mp = LIST_FIRST(&gp->msgq)) != NULL) { gp->scr_msg(sp, mp->mtype, mp->buf, mp->len); LIST_REMOVE(mp, q); free(mp->buf); @@ -122,7 +122,7 @@ ex(spp) * If the user entered a single carriage return, send * ex_cmd() a separator -- it discards single newlines. */ - tp = sp->tiq.cqh_first; + tp = CIRCLEQ_FIRST(&sp->tiq); if (tp->len == 0) { gp->excmd.cp = " "; /* __TK__ why not |? */ gp->excmd.clen = 1; @@ -219,7 +219,7 @@ ex_cmd(sp) * This means that *everything* must be resolved when we leave * this function for any reason. */ -loop: ecp = gp->ecq.lh_first; +loop: ecp = LIST_FIRST(&gp->ecq); /* If we're reading a command from a file, set up error information. */ if (ecp->if_name != NULL) { @@ -323,7 +323,7 @@ loop: ecp = gp->ecq.lh_first; (!notempty || F_ISSET(sp, SC_VI) || F_ISSET(ecp, E_BLIGNORE))) { if (ex_load(sp)) goto rfail; - ecp = gp->ecq.lh_first; + ecp = LIST_FIRST(&gp->ecq); if (ecp->clen == 0) goto rsuccess; goto loop; @@ -1529,8 +1529,7 @@ addr_verify: */ if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE | SC_FSWITCH | SC_SSWITCH)) { at_found = gv_found = 0; - for (ecp = sp->gp->ecq.lh_first; - ecp != NULL; ecp = ecp->q.le_next) + LIST_FOREACH(ecp, &sp->gp->ecq, q) switch (ecp->agv_flags) { case 0: case AGV_AT_NORANGE: @@ -1582,7 +1581,7 @@ err: /* break; } } - if (ecp->save_cmdlen != 0 || gp->ecq.lh_first != &gp->excmd) { + if (ecp->save_cmdlen != 0 || LIST_FIRST(&gp->ecq) != &gp->excmd) { discard: msgq(sp, M_BERR, "092|Ex command failed: pending commands discarded"); ex_discard(sp); @@ -2083,7 +2082,7 @@ ex_load(sp) * but discard any allocated source name, we've returned to * the beginning of the command stack. */ - if ((ecp = gp->ecq.lh_first) == &gp->excmd) { + if ((ecp = LIST_FIRST(&gp->ecq)) == &gp->excmd) { if (F_ISSET(ecp, E_NAMEDISCARD)) { free(ecp->if_name); ecp->if_name = NULL; @@ -2107,7 +2106,7 @@ ex_load(sp) */ if (FL_ISSET(ecp->agv_flags, AGV_ALL)) { /* Discard any exhausted ranges. */ - while ((rp = ecp->rq.cqh_first) != (void *)&ecp->rq) + while ((rp = CIRCLEQ_FIRST(&ecp->rq)) != (void *)&ecp->rq) if (rp->start > rp->stop) { CIRCLEQ_REMOVE(&ecp->rq, rp, q); free(rp); @@ -2169,9 +2168,9 @@ ex_discard(sp) * We know the first command can't be an AGV command, so we don't * process it specially. We do, however, nail the command itself. */ - for (gp = sp->gp; (ecp = gp->ecq.lh_first) != &gp->excmd;) { + for (gp = sp->gp; (ecp = LIST_FIRST(&gp->ecq)) != &gp->excmd;) { if (FL_ISSET(ecp->agv_flags, AGV_ALL)) { - while ((rp = ecp->rq.cqh_first) != (void *)&ecp->rq) { + while ((rp = CIRCLEQ_FIRST(&ecp->rq)) != CIRCLEQ_END(&ecp->rq)) { CIRCLEQ_REMOVE(&ecp->rq, rp, q); free(rp); } @@ -2180,7 +2179,7 @@ ex_discard(sp) LIST_REMOVE(ecp, q); free(ecp); } - gp->ecq.lh_first->clen = 0; + LIST_FIRST(&gp->ecq)->clen = 0; return (0); } diff --git a/usr.bin/vi/ex/ex_append.c b/usr.bin/vi/ex/ex_append.c index 88e2a8c5344..1016d319c5d 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.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_append.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -262,8 +262,8 @@ ex_aci(sp, cmdp, cmd) if (ex_txt(sp, &tiq, 0, flags)) return (1); - for (cnt = 0, tp = tiq.cqh_first; - tp != (TEXT *)&tiq; ++cnt, tp = tp->q.cqe_next) + for (cnt = 0, tp = CIRCLEQ_FIRST(&tiq); + tp != (TEXT *)&tiq; ++cnt, tp = CIRCLEQ_NEXT(tp, q)) if (db_append(sp, 1, lno++, tp->lb, tp->len)) return (1); diff --git a/usr.bin/vi/ex/ex_at.c b/usr.bin/vi/ex/ex_at.c index ec51fb28dc1..71ce279f696 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.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_at.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -106,8 +106,8 @@ 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 = cbp->textq.cqh_last; - tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) + for (len = 0, tp = CIRCLEQ_LAST(&cbp->textq); + tp != CIRCLEQ_END(&cbp->textq); tp = CIRCLEQ_PREV(tp, q)) len += tp->len + 1; MALLOC_RET(sp, ecp->cp, char *, len * 2); @@ -116,8 +116,8 @@ ex_at(sp, cmdp) ecp->cp[len] = '\0'; /* Copy the buffer into the command space. */ - for (p = ecp->cp + len, tp = cbp->textq.cqh_last; - tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) { + for (p = ecp->cp + len, tp = CIRCLEQ_LAST(&cbp->textq); + tp != CIRCLEQ_END(&cbp->textq); tp = CIRCLEQ_PREV(tp, 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 bdd11124079..83b5ca5a3dd 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.10 2003/07/09 20:01:31 millert Exp $ */ +/* $OpenBSD: ex_cscope.c,v 1.11 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1994, 1996 @@ -447,7 +447,7 @@ cscope_find(sp, cmdp, pattern) exp = EXP(sp); /* Check for connections. */ - if (exp->cscq.lh_first == NULL) { + if (LIST_FIRST(&exp->cscq) == NULL) { msgq(sp, M_ERR, "310|No cscope connections running"); return (1); } @@ -459,7 +459,7 @@ cscope_find(sp, cmdp, pattern) */ rtp = NULL; rtqp = NULL; - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { /* Initialize the `local context' tag queue structure. */ CALLOC_GOTO(sp, rtqp, TAGQ *, 1, sizeof(TAGQ)); CIRCLEQ_INIT(&rtqp->tagq); @@ -485,9 +485,9 @@ cscope_find(sp, cmdp, pattern) /* Search all open connections for a match. */ matches = 0; - for (csc = exp->cscq.lh_first; csc != NULL; csc = csc_next) { + for (csc = LIST_FIRST(&exp->cscq); csc != NULL; csc = csc_next) { /* Copy csc->q.lh_next here in case csc is killed. */ - csc_next = csc->q.le_next; + csc_next = LIST_NEXT(csc, q); /* * Send the command to the cscope program. (We skip the @@ -512,7 +512,7 @@ cscope_find(sp, cmdp, pattern) return (0); } - tqp->current = tqp->tagq.cqh_first; + tqp->current = CIRCLEQ_FIRST(&tqp->tagq); /* Try to switch to the first tag. */ force = FL_ISSET(cmdp->iflags, E_C_FORCE); @@ -532,10 +532,10 @@ cscope_find(sp, cmdp, pattern) * in place, so we can pop all the way back to the current mark. * Note, it doesn't point to much of anything, it's a placeholder. */ - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { CIRCLEQ_INSERT_HEAD(&exp->tq, rtqp, q); } else - rtqp = exp->tq.cqh_first; + rtqp = CIRCLEQ_FIRST(&exp->tq); /* Link the current TAGQ structure into place. */ CIRCLEQ_INSERT_HEAD(&exp->tq, tqp, q); @@ -624,8 +624,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 = cbp->textq.cqh_first->lb; - tlen = cbp->textq.cqh_first->len; + p = CIRCLEQ_FIRST(&cbp->textq)->lb; + tlen = CIRCLEQ_FIRST(&cbp->textq)->len; } else tlen = strlen(p); @@ -877,8 +877,8 @@ terminate(sp, csc, n) if (csc == NULL) { if (n < 1) goto badno; - for (i = 1, csc = exp->cscq.lh_first; - csc != NULL; csc = csc->q.le_next, i++) + for (i = 1, csc = LIST_FIRST(&exp->cscq); + csc != NULL; csc = LIST_NEXT(csc, q), i++) if (i == n) break; if (csc == NULL) { @@ -923,7 +923,7 @@ cscope_reset(sp, cmdp, notusedp) { EX_PRIVATE *exp; - for (exp = EXP(sp); exp->cscq.lh_first != NULL;) + for (exp = EXP(sp); LIST_FIRST(&exp->cscq) != NULL;) if (cscope_kill(sp, cmdp, "1")) return (1); return (0); @@ -944,12 +944,12 @@ cscope_display(sp) int i; exp = EXP(sp); - if (exp->cscq.lh_first == NULL) { + if (LIST_FIRST(&exp->cscq) == NULL) { ex_printf(sp, "No cscope connections.\n"); return (0); } for (i = 1, - csc = exp->cscq.lh_first; csc != NULL; ++i, csc = csc->q.le_next) + csc = LIST_FIRST(&exp->cscq); csc != NULL; ++i, csc = LIST_NEXT(csc, q)) ex_printf(sp, "%2d %s (process %ld)\n", i, csc->dname, (long)csc->pid); return (0); diff --git a/usr.bin/vi/ex/ex_display.c b/usr.bin/vi/ex/ex_display.c index 64b9333bca8..13ebe8af77d 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.4 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_display.c,v 1.5 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -87,25 +87,25 @@ bdisplay(sp) { CB *cbp; - if (sp->gp->cutq.lh_first == NULL && sp->gp->dcbp == NULL) { + if (LIST_FIRST(&sp->gp->cutq) == NULL && sp->gp->dcbp == NULL) { msgq(sp, M_INFO, "123|No cut buffers to display"); return (0); } /* Display regular cut buffers. */ - for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { + LIST_FOREACH(cbp, &sp->gp->cutq, q) { if (isdigit(cbp->name)) continue; - if (cbp->textq.cqh_first != (void *)&cbp->textq) + if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq)) db(sp, cbp, NULL); if (INTERRUPTED(sp)) return (0); } /* Display numbered buffers. */ - for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { + LIST_FOREACH(cbp, &sp->gp->cutq, q) { if (!isdigit(cbp->name)) continue; - if (cbp->textq.cqh_first != (void *)&cbp->textq) + if (CIRCLEQ_FIRST(&cbp->textq) != CIRCLEQ_END(&cbp->textq)) db(sp, cbp, NULL); if (INTERRUPTED(sp)) return (0); @@ -135,8 +135,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)"); - for (tp = cbp->textq.cqh_first; - tp != (void *)&cbp->textq; tp = tp->q.cqe_next) { + CIRCLEQ_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_global.c b/usr.bin/vi/ex/ex_global.c index eae27259fcb..8c55c211d8b 100644 --- a/usr.bin/vi/ex/ex_global.c +++ b/usr.bin/vi/ex/ex_global.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_global.c,v 1.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_global.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -274,11 +274,12 @@ ex_g_insdel(sp, op, lno) if (op == LINE_RESET) return (0); - for (ecp = sp->gp->ecq.lh_first; ecp != NULL; ecp = ecp->q.le_next) { + LIST_FOREACH(ecp, &sp->gp->ecq, q) { if (!FL_ISSET(ecp->agv_flags, AGV_AT | AGV_GLOBAL | AGV_V)) continue; - for (rp = ecp->rq.cqh_first; rp != (void *)&ecp->rq; rp = nrp) { - nrp = rp->q.cqe_next; + for (rp = CIRCLEQ_FIRST(&ecp->rq); rp != CIRCLEQ_END(&ecp->rq); + rp = nrp) { + nrp = CIRCLEQ_NEXT(rp, q); /* If range less than the line, ignore it. */ if (rp->stop < lno) diff --git a/usr.bin/vi/ex/ex_move.c b/usr.bin/vi/ex/ex_move.c index be901fcf888..5155f4889db 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.6 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_move.c,v 1.7 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -128,7 +128,7 @@ ex_move(sp, cmdp) /* Log the old positions of the marks. */ mark_reset = 0; - for (lmp = sp->ep->marks.lh_first; lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno >= fl && lmp->lno <= tl) { mark_reset = 1; @@ -152,8 +152,7 @@ ex_move(sp, cmdp) if (db_append(sp, 1, tl, bp, len)) return (1); if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno == fl) lmp->lno = tl + 1; @@ -171,8 +170,7 @@ ex_move(sp, cmdp) if (db_append(sp, 1, tl++, bp, len)) return (1); if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno == fl) lmp->lno = tl; @@ -188,8 +186,7 @@ ex_move(sp, cmdp) /* Log the new positions of the marks. */ if (mark_reset) - for (lmp = sp->ep->marks.lh_first; - lmp != NULL; lmp = lmp->q.le_next) + LIST_FOREACH(lmp, &sp->ep->marks, q) if (lmp->name != ABSMARK1 && lmp->lno >= mfl && lmp->lno <= mtl) (void)log_mark(sp, lmp); diff --git a/usr.bin/vi/ex/ex_screen.c b/usr.bin/vi/ex/ex_screen.c index 70361d936cf..1684fef2b5f 100644 --- a/usr.bin/vi/ex/ex_screen.c +++ b/usr.bin/vi/ex/ex_screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_screen.c,v 1.5 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_screen.c,v 1.6 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -114,14 +114,14 @@ ex_sdisplay(sp) int cnt, col, len, sep; gp = sp->gp; - if ((tsp = gp->hq.cqh_first) == (void *)&gp->hq) { + if ((tsp = CIRCLEQ_FIRST(&gp->hq)) == CIRCLEQ_END(&gp->hq)) { msgq(sp, M_INFO, "149|No background screens to display"); return (0); } col = len = sep = 0; for (cnt = 1; tsp != (void *)&gp->hq && !INTERRUPTED(sp); - tsp = tsp->q.cqe_next) { + tsp = CIRCLEQ_NEXT(tsp, q)) { col += len = strlen(tsp->frp->name) + sep; if (col >= sp->cols - 1) { col = len; diff --git a/usr.bin/vi/ex/ex_script.c b/usr.bin/vi/ex/ex_script.c index 50692c2899e..a98bc633fa1 100644 --- a/usr.bin/vi/ex/ex_script.c +++ b/usr.bin/vi/ex/ex_script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_script.c,v 1.11 2003/09/02 22:44:06 dhartmei Exp $ */ +/* $OpenBSD: ex_script.c,v 1.12 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -385,7 +385,7 @@ sscr_input(sp) /* Allocate space for rdfd. */ maxfd = STDIN_FILENO; - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT) && sp->script->sh_master > maxfd) maxfd = sp->script->sh_master; rdfd = (fd_set *)malloc(howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); @@ -399,7 +399,7 @@ loop: memset(rdfd, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); tv.tv_usec = 0; /* Set up the input mask. */ - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT)) FD_SET(sp->script->sh_master, rdfd); @@ -417,7 +417,7 @@ loop: memset(rdfd, 0, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); } /* Read the input. */ - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT) && FD_ISSET(sp->script->sh_master, rdfd) && sscr_insert(sp)) { free(rdfd); @@ -626,7 +626,7 @@ sscr_check(sp) GS *gp; gp = sp->gp; - for (sp = gp->dq.cqh_first; sp != (void *)&gp->dq; sp = sp->q.cqe_next) + CIRCLEQ_FOREACH(sp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT)) { F_SET(gp, G_SCRWIN); return; diff --git a/usr.bin/vi/ex/ex_subst.c b/usr.bin/vi/ex/ex_subst.c index bb10bcea575..454f1d2f85e 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.12 2002/02/17 19:42:34 millert Exp $ */ +/* $OpenBSD: ex_subst.c,v 1.13 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -662,7 +662,7 @@ nextmatch: match[0].rm_so = 0; goto lquit; if (ex_txt(sp, &tiq, 0, TXT_CR)) goto err; - ev.e_c = tiq.cqh_first->lb[0]; + ev.e_c = CIRCLEQ_FIRST(&tiq)->lb[0]; } switch (ev.e_c) { diff --git a/usr.bin/vi/ex/ex_tag.c b/usr.bin/vi/ex/ex_tag.c index 21188ed30f2..56022d9b051 100644 --- a/usr.bin/vi/ex/ex_tag.c +++ b/usr.bin/vi/ex/ex_tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_tag.c,v 1.10 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_tag.c,v 1.11 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -149,7 +149,7 @@ ex_tag_push(sp, cmdp) */ rtp = NULL; rtqp = NULL; - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { /* Initialize the `local context' tag queue structure. */ CALLOC_GOTO(sp, rtqp, TAGQ *, 1, sizeof(TAGQ)); CIRCLEQ_INIT(&rtqp->tagq); @@ -174,14 +174,14 @@ ex_tag_push(sp, cmdp) /* Try to switch to the tag. */ force = FL_ISSET(cmdp->iflags, E_C_FORCE); if (F_ISSET(cmdp, E_NEWSCREEN)) { - if (ex_tag_Nswitch(sp, tqp->tagq.cqh_first, force)) + if (ex_tag_Nswitch(sp, CIRCLEQ_FIRST(&tqp->tagq), force)) goto err; /* Everything else gets done in the new screen. */ sp = sp->nextdisp; exp = EXP(sp); } else - if (ex_tag_nswitch(sp, tqp->tagq.cqh_first, force)) + if (ex_tag_nswitch(sp, CIRCLEQ_FIRST(&tqp->tagq), force)) goto err; /* @@ -189,10 +189,10 @@ ex_tag_push(sp, cmdp) * in place, so we can pop all the way back to the current mark. * Note, it doesn't point to much of anything, it's a placeholder. */ - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { CIRCLEQ_INSERT_HEAD(&exp->tq, rtqp, q); } else - rtqp = exp->tq.cqh_first; + rtqp = CIRCLEQ_FIRST(&exp->tq); /* Link the new TAGQ structure into place. */ CIRCLEQ_INSERT_HEAD(&exp->tq, tqp, q); @@ -246,11 +246,11 @@ ex_tag_next(sp, cmdp) TAGQ *tqp; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if ((tqp = CIRCLEQ_FIRST(&exp->tq)) == CIRCLEQ_END(&exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } - if ((tp = tqp->current->q.cqe_next) == (void *)&tqp->tagq) { + if ((tp = CIRCLEQ_NEXT(tqp->current, q)) == CIRCLEQ_END(&tqp->tagq)) { msgq(sp, M_ERR, "282|Already at the last tag of this group"); return (1); } @@ -281,11 +281,11 @@ ex_tag_prev(sp, cmdp) TAGQ *tqp; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if ((tqp = CIRCLEQ_FIRST(&exp->tq)) == CIRCLEQ_END(&exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (0); } - if ((tp = tqp->current->q.cqe_prev) == (void *)&tqp->tagq) { + if ((tp = CIRCLEQ_PREV(tqp->current, q)) == CIRCLEQ_END(&tqp->tagq)) { msgq(sp, M_ERR, "255|Already at the first tag of this group"); return (1); } @@ -413,7 +413,7 @@ ex_tag_pop(sp, cmdp) /* Check for an empty stack. */ exp = EXP(sp); - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } @@ -421,7 +421,7 @@ ex_tag_pop(sp, cmdp) /* Find the last TAG structure that we're going to DISCARD! */ switch (cmdp->argc) { case 0: /* Pop one tag. */ - dtqp = exp->tq.cqh_first; + dtqp = CIRCLEQ_FIRST(&exp->tq); break; case 1: /* Name or number. */ arg = cmdp->argv[0]->bp; @@ -432,9 +432,9 @@ ex_tag_pop(sp, cmdp) /* Number: pop that many queue entries. */ if (off < 1) return (0); - for (tqp = exp->tq.cqh_first; - tqp != (void *)&exp->tq && --off > 1; - tqp = tqp->q.cqe_next); + for (tqp = CIRCLEQ_FIRST(&exp->tq); + tqp != CIRCLEQ_END(&exp->tq) && --off > 1; + tqp = CIRCLEQ_NEXT(tqp, q)); if (tqp == (void *)&exp->tq) { msgq(sp, M_ERR, "159|Less than %s entries on the tags stack; use :display t[ags]", @@ -446,11 +446,11 @@ ex_tag_pop(sp, cmdp) /* File argument: pop to that queue entry. */ filearg: arglen = strlen(arg); - for (tqp = exp->tq.cqh_first; - tqp != (void *)&exp->tq; - dtqp = tqp, tqp = tqp->q.cqe_next) { + for (tqp = CIRCLEQ_FIRST(&exp->tq); + tqp != CIRCLEQ_END(&exp->tq); + dtqp = tqp, tqp = CIRCLEQ_NEXT(tqp, q)) { /* Don't pop to the current file. */ - if (tqp == exp->tq.cqh_first) + if (tqp == CIRCLEQ_FIRST(&exp->tq)) continue; p = tqp->current->frp->name; if ((t = strrchr(p, '/')) == NULL) @@ -465,7 +465,7 @@ filearg: arglen = strlen(arg); "160|No file %s on the tags stack to return to; use :display t[ags]"); return (1); } - if (tqp == exp->tq.cqh_first) + if (tqp == CIRCLEQ_FIRST(&exp->tq)) return (0); break; default: @@ -491,14 +491,15 @@ ex_tag_top(sp, cmdp) exp = EXP(sp); /* Check for an empty stack. */ - if (exp->tq.cqh_first == (void *)&exp->tq) { + if (CIRCLEQ_FIRST(&exp->tq) == CIRCLEQ_END(&exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (1); } /* Return to the oldest information. */ return (tag_pop(sp, - exp->tq.cqh_last->q.cqe_prev, FL_ISSET(cmdp->iflags, E_C_FORCE))); + CIRCLEQ_PREV(CIRCLEQ_LAST(&exp->tq), q), + FL_ISSET(cmdp->iflags, E_C_FORCE))); } /* @@ -521,7 +522,7 @@ tag_pop(sp, dtqp, force) * Update the cursor from the saved TAG information of the TAG * structure we're moving to. */ - tp = dtqp->q.cqe_next->current; + tp = CIRCLEQ_NEXT(dtqp, q)->current; if (tp->frp == sp->frp) { sp->lno = tp->lno; sp->cno = tp->cno; @@ -540,7 +541,7 @@ tag_pop(sp, dtqp, force) /* Pop entries off the queue up to and including dtqp. */ do { - tqp = exp->tq.cqh_first; + tqp = CIRCLEQ_FIRST(&exp->tq); if (tagq_free(sp, tqp)) return (0); } while (tqp != dtqp); @@ -549,8 +550,8 @@ tag_pop(sp, dtqp, force) * If only a single tag left, we've returned to the first tag point, * and the stack is now empty. */ - if (exp->tq.cqh_first->q.cqe_next == (void *)&exp->tq) - tagq_free(sp, exp->tq.cqh_first); + if (CIRCLEQ_NEXT(CIRCLEQ_FIRST(&exp->tq), q) == CIRCLEQ_END(&exp->tq)) + tagq_free(sp, CIRCLEQ_FIRST(&exp->tq)); return (0); } @@ -573,7 +574,7 @@ ex_tag_display(sp) char *p, *sep; exp = EXP(sp); - if ((tqp = exp->tq.cqh_first) == (void *)&exp->tq) { + if ((tqp = CIRCLEQ_FIRST(&exp->tq)) == CIRCLEQ_END(&exp->tq)) { tag_msg(sp, TAG_EMPTY, NULL); return (0); } @@ -601,11 +602,10 @@ ex_tag_display(sp) * Display the list of tags for each queue entry. The first entry * is numbered, and the current tag entry has an asterisk appended. */ - for (cnt = 1, tqp = exp->tq.cqh_first; !INTERRUPTED(sp) && - tqp != (void *)&exp->tq; ++cnt, tqp = tqp->q.cqe_next) - for (tp = tqp->tagq.cqh_first; - tp != (void *)&tqp->tagq; tp = tp->q.cqe_next) { - if (tp == tqp->tagq.cqh_first) + for (cnt = 1, tqp = CIRCLEQ_FIRST(&exp->tq); !INTERRUPTED(sp) && + tqp != CIRCLEQ_END(&exp->tq); ++cnt, tqp = CIRCLEQ_NEXT(tqp, q)) + CIRCLEQ_FOREACH(tp, &tqp->tagq, q) { + if (tp == CIRCLEQ_FIRST(&tqp->tagq)) (void)ex_printf(sp, "%2d ", cnt); else (void)ex_printf(sp, " "); @@ -620,7 +620,7 @@ ex_tag_display(sp) if (tqp->current == tp) (void)ex_printf(sp, "*"); - if (tp == tqp->tagq.cqh_first && tqp->tag != NULL && + if (tp == CIRCLEQ_FIRST(&tqp->tagq) && tqp->tag != NULL && (sp->cols - L_NAME) >= L_TAG + L_SPACE) { len = strlen(tqp->tag); if (len > sp->cols - (L_NAME + L_SPACE)) @@ -653,12 +653,10 @@ ex_tag_copy(orig, sp) nexp = EXP(sp); /* Copy tag queue and tags stack. */ - for (aqp = oexp->tq.cqh_first; - aqp != (void *)&oexp->tq; aqp = aqp->q.cqe_next) { + CIRCLEQ_FOREACH(aqp, &oexp->tq, q) { if (tagq_copy(sp, aqp, &tqp)) return (1); - for (ap = aqp->tagq.cqh_first; - ap != (void *)&aqp->tagq; ap = ap->q.cqe_next) { + CIRCLEQ_FOREACH(ap, &aqp->tagq, q) { if (tag_copy(sp, ap, &tp)) return (1); /* Set the current pointer. */ @@ -670,8 +668,7 @@ ex_tag_copy(orig, sp) } /* Copy list of tag files. */ - for (atfp = oexp->tagfq.tqh_first; - atfp != NULL; atfp = atfp->q.tqe_next) { + TAILQ_FOREACH(atfp, &oexp->tagfq, q) { if (tagf_copy(sp, atfp, &tfp)) return (1); TAILQ_INSERT_TAIL(&nexp->tagfq, tfp, q); @@ -797,7 +794,7 @@ tagq_free(sp, tqp) TAG *tp; exp = EXP(sp); - while ((tp = tqp->tagq.cqh_first) != (void *)&tqp->tagq) { + while ((tp = CIRCLEQ_FIRST(&tqp->tagq)) != CIRCLEQ_END(&tqp->tagq)) { CIRCLEQ_REMOVE(&tqp->tagq, tp, q); free(tp); } @@ -806,7 +803,7 @@ tagq_free(sp, tqp) * If allocated and then the user failed to switch files, the TAGQ * structure was never attached to any list. */ - if (tqp->q.cqe_next != NULL) + if (CIRCLEQ_NEXT(tqp, q) != NULL) CIRCLEQ_REMOVE(&exp->tq, tqp, q); free(tqp); return (0); @@ -858,7 +855,7 @@ ex_tagf_alloc(sp, str) /* Free current queue. */ exp = EXP(sp); - while ((tfp = exp->tagfq.tqh_first) != NULL) + while ((tfp = TAILQ_FIRST(&exp->tagfq)) != NULL) tagf_free(sp, tfp); /* Create new queue. */ @@ -900,9 +897,9 @@ ex_tag_free(sp) /* Free up tag information. */ exp = EXP(sp); - while ((tqp = exp->tq.cqh_first) != (void *)&exp->tq) + while ((tqp = CIRCLEQ_FIRST(&exp->tq)) != CIRCLEQ_END(&exp->tq)) tagq_free(sp, tqp); - while ((tfp = exp->tagfq.tqh_first) != NULL) + while ((tfp = TAILQ_FIRST(&exp->tagfq)) != NULL) tagf_free(sp, tfp); if (exp->tag_last != NULL) free(exp->tag_last); @@ -999,8 +996,8 @@ ctag_slist(sp, tag) * Find the tag, only display missing file messages once, and * then only if we didn't find the tag. */ - for (echk = 0, - tfp = exp->tagfq.tqh_first; tfp != NULL; tfp = tfp->q.tqe_next) + echk = 0; + TAILQ_FOREACH(tfp, &exp->tagfq, q) if (ctag_sfile(sp, tfp, tqp, tag)) { echk = 1; F_SET(tfp, TAGF_ERR); @@ -1008,11 +1005,10 @@ ctag_slist(sp, tag) F_CLR(tfp, TAGF_ERR | TAGF_ERR_WARN); /* Check to see if we found anything. */ - if (tqp->tagq.cqh_first == (void *)&tqp->tagq) { + if (CIRCLEQ_FIRST(&tqp->tagq) == CIRCLEQ_END(&tqp->tagq)) { msgq_str(sp, M_ERR, tag, "162|%s: tag not found"); if (echk) - for (tfp = exp->tagfq.tqh_first; - tfp != NULL; tfp = tfp->q.tqe_next) + TAILQ_FOREACH(tfp, &exp->tagfq, q) if (F_ISSET(tfp, TAGF_ERR) && !F_ISSET(tfp, TAGF_ERR_WARN)) { errno = tfp->errnum; @@ -1023,7 +1019,7 @@ ctag_slist(sp, tag) return (NULL); } - tqp->current = tqp->tagq.cqh_first; + tqp->current = CIRCLEQ_FIRST(&tqp->tagq); return (tqp); alloc_err: diff --git a/usr.bin/vi/ex/ex_txt.c b/usr.bin/vi/ex/ex_txt.c index 84f6fac05fc..b13c5990da0 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.7 2002/02/16 21:27:57 millert Exp $ */ +/* $OpenBSD: ex_txt.c,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -74,9 +74,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 (tiqh->cqh_first != (void *)tiqh) { - tp = tiqh->cqh_first; - if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < 32) { + if (CIRCLEQ_FIRST(tiqh) != CIRCLEQ_END(tiqh)) { + tp = CIRCLEQ_FIRST(tiqh); + if (CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(tiqh) || tp->lb_len < 32) { text_lfree(tiqh); goto newtp; } diff --git a/usr.bin/vi/vi/v_at.c b/usr.bin/vi/vi/v_at.c index 10674d2d893..62a65cc1999 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.4 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: v_at.c,v 1.5 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -89,10 +89,9 @@ v_at(sp, vp) * together. We don't get this right; I'm waiting for the new DB * logging code to be available. */ - for (tp = cbp->textq.cqh_last; - tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) + CIRCLEQ_FOREACH_REVERSE(tp, &cbp->textq, q) if ((F_ISSET(cbp, CB_LMODE) || - tp->q.cqe_next != (void *)&cbp->textq) && + CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(&cbp->textq)) && 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 42fbb6cbb94..325e0a1d917 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.5 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: v_ex.c,v 1.6 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -308,7 +308,7 @@ v_filter(sp, vp) * Entering <escape> on an empty line was historically an error, * this implementation doesn't bother. */ - tp = sp->tiq.cqh_first; + tp = CIRCLEQ_FIRST(&sp->tiq); if (tp->term != TERM_OK) { vp->m_final.lno = sp->lno; vp->m_final.cno = sp->cno; @@ -407,7 +407,7 @@ v_ex(sp, vp) if (v_tcmd(sp, vp, ':', TXT_BS | TXT_CEDIT | TXT_FILEC | TXT_PROMPT)) return (1); - tp = sp->tiq.cqh_first; + tp = CIRCLEQ_FIRST(&sp->tiq); /* * If the user entered a single <esc>, they want to diff --git a/usr.bin/vi/vi/v_screen.c b/usr.bin/vi/vi/v_screen.c index e6bf6d99bb8..b28cb7d1f5c 100644 --- a/usr.bin/vi/vi/v_screen.c +++ b/usr.bin/vi/vi/v_screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: v_screen.c,v 1.4 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: v_screen.c,v 1.5 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -53,13 +53,13 @@ v_screen(sp, vp) * Try for the next lower screen, or, go back to the first * screen on the stack. */ - if (sp->q.cqe_next != (void *)&sp->gp->dq) - sp->nextdisp = sp->q.cqe_next; - else if (sp->gp->dq.cqh_first == sp) { + if (CIRCLEQ_NEXT(sp, q) != CIRCLEQ_END(&sp->gp->dq)) + sp->nextdisp = CIRCLEQ_NEXT(sp, q); + else if (CIRCLEQ_FIRST(&sp->gp->dq) == sp) { msgq(sp, M_ERR, "187|No other screen to switch to"); return (1); } else - sp->nextdisp = sp->gp->dq.cqh_first; + sp->nextdisp = CIRCLEQ_FIRST(&sp->gp->dq); F_SET(sp->nextdisp, SC_STATUS); F_SET(sp, SC_SSWITCH | SC_STATUS); diff --git a/usr.bin/vi/vi/v_search.c b/usr.bin/vi/vi/v_search.c index 2b497d77527..1cb1a24b819 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.7 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: v_search.c,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -95,7 +95,7 @@ v_exaddr(sp, vp, dir) (O_ISSET(sp, O_SEARCHINCR) ? TXT_SEARCHINCR : 0))) return (1); - tp = sp->tiq.cqh_first; + tp = CIRCLEQ_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 29948fb1a6f..f73fd7ba0ee 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.15 2005/01/08 05:20:34 pvalchev Exp $ */ +/* $OpenBSD: v_txt.c,v 1.16 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -301,9 +301,9 @@ v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags) * copy it into the TEXT buffer. */ tiqh = &sp->tiq; - if (tiqh->cqh_first != (void *)tiqh) { - tp = tiqh->cqh_first; - if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < len + 32) { + if (CIRCLEQ_FIRST(tiqh) != CIRCLEQ_END(tiqh)) { + tp = CIRCLEQ_FIRST(tiqh); + if (CIRCLEQ_NEXT(tp, q) != CIRCLEQ_END(tiqh) || tp->lb_len < len + 32) { text_lfree(tiqh); goto newtp; } @@ -1835,7 +1835,7 @@ txt_backup(sp, tiqh, tp, flagsp) TEXT *ntp; /* Get a handle on the previous TEXT structure. */ - if ((ntp = tp->q.cqe_prev) == (void *)tiqh) { + if ((ntp = CIRCLEQ_PREV(tp, q)) == CIRCLEQ_END(tiqh)) { if (!FL_ISSET(*flagsp, TXT_REPLAY)) msgq(sp, M_BERR, "193|Already at the beginning of the insert"); @@ -2342,7 +2342,7 @@ txt_err(sp, tiqh) * We depend on at least one line number being set in the text * chain. */ - for (lno = tiqh->cqh_first->lno; + for (lno = CIRCLEQ_FIRST(tiqh)->lno; !db_exist(sp, lno) && lno > 0; --lno); sp->lno = lno == 0 ? 1 : lno; @@ -2700,7 +2700,7 @@ txt_resolve(sp, tiqh, flags) * about the line will be wrong. */ vip = VIP(sp); - tp = tiqh->cqh_first; + tp = CIRCLEQ_FIRST(tiqh); if (LF_ISSET(TXT_AUTOINDENT)) txt_ai_resolve(sp, tp, &changed); @@ -2710,7 +2710,7 @@ txt_resolve(sp, tiqh, flags) changed && vs_change(sp, tp->lno, LINE_RESET)) return (1); - for (lno = tp->lno; (tp = tp->q.cqe_next) != (void *)&sp->tiq; ++lno) { + for (lno = tp->lno; (tp = CIRCLEQ_NEXT(tp, q)) != (void *)&sp->tiq; ++lno) { if (LF_ISSET(TXT_AUTOINDENT)) txt_ai_resolve(sp, tp, &changed); else @@ -2909,9 +2909,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 = tiqh->cqh_first, input_len = 0;;) { + for (ttp = CIRCLEQ_FIRST(tiqh), input_len = 0;;) { input_len += ttp == tp ? tp->cno : ttp->len + ttp->R_erase; - if ((ttp = ttp->q.cqe_next) == (void *)&sp->tiq) + if ((ttp = CIRCLEQ_NEXT(ttp, q)) == CIRCLEQ_END(&sp->tiq)) break; } @@ -2932,7 +2932,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, - tiqh->cqh_first->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL)) + CIRCLEQ_FIRST(tiqh)->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL)) return; memcpy(tp->lb + tp->cno, p + input_len, retain); tp->len -= tp->owrite - retain; diff --git a/usr.bin/vi/vi/vi.c b/usr.bin/vi/vi/vi.c index ebf121ec4e8..d67e2a93215 100644 --- a/usr.bin/vi/vi/vi.c +++ b/usr.bin/vi/vi/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.10 2005/01/08 05:22:25 pvalchev Exp $ */ +/* $OpenBSD: vi.c,v 1.11 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -1012,7 +1012,7 @@ v_dtoh(sp) /* Move all screens to the hidden queue, tossing screen maps. */ for (hidden = 0, gp = sp->gp; - (tsp = gp->dq.cqh_first) != (void *)&gp->dq; ++hidden) { + (tsp = CIRCLEQ_FIRST(&gp->dq)) != CIRCLEQ_END(&gp->dq); ++hidden) { if (_HMAP(tsp) != NULL) { free(_HMAP(tsp)); _HMAP(tsp) = NULL; diff --git a/usr.bin/vi/vi/vi.h b/usr.bin/vi/vi/vi.h index 71233457bef..8e90e6af3c1 100644 --- a/usr.bin/vi/vi/vi.h +++ b/usr.bin/vi/vi/vi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.h,v 1.4 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: vi.h,v 1.5 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -355,8 +355,8 @@ typedef struct _vi_private { /* If more than one screen being shown. */ #define IS_SPLIT(sp) \ - ((sp)->q.cqe_next != (void *)&(sp)->gp->dq || \ - (sp)->q.cqe_prev != (void *)&(sp)->gp->dq) + (CIRCLEQ_NEXT((sp), q) != (void *)&(sp)->gp->dq || \ + CIRCLEQ_PREV((sp), q) != (void *)&(sp)->gp->dq) /* Screen adjustment operations. */ typedef enum { A_DECREASE, A_INCREASE, A_SET } adj_t; diff --git a/usr.bin/vi/vi/vs_msg.c b/usr.bin/vi/vi/vs_msg.c index 8fe633f2c8c..6ac0236691b 100644 --- a/usr.bin/vi/vi/vs_msg.c +++ b/usr.bin/vi/vi/vs_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_msg.c,v 1.7 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: vs_msg.c,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -600,7 +600,7 @@ vs_ex_resolve(sp, continuep) * If we're not the bottom of the split screen stack, the screen * image itself is wrong, so redraw everything. */ - if (sp->q.cqe_next != (void *)&sp->gp->dq) + if (CIRCLEQ_NEXT(sp, q) != CIRCLEQ_END(&sp->gp->dq)) F_SET(sp, SC_SCR_REDRAW); /* If ex changed the underlying file, the map itself is wrong. */ @@ -698,10 +698,10 @@ vs_resolve(sp, csp, forcewait) * messages.) Once this is done, don't trust the cursor. That * extra refresh screwed the pooch. */ - if (gp->msgq.lh_first != NULL) { + if (LIST_FIRST(&gp->msgq) != NULL) { if (!F_ISSET(sp, SC_SCR_VI) && vs_refresh(sp, 1)) return (1); - while ((mp = gp->msgq.lh_first) != NULL) { + while ((mp = LIST_FIRST(&gp->msgq)) != NULL) { gp->scr_msg(sp, mp->mtype, mp->buf, mp->len); LIST_REMOVE(mp, q); free(mp->buf); @@ -781,7 +781,7 @@ vs_scroll(sp, continuep, wtype) (void)gp->scr_deleteln(sp); /* If there are screens below us, push them back into place. */ - if (sp->q.cqe_next != (void *)&sp->gp->dq) { + if (CIRCLEQ_NEXT(sp, q) != CIRCLEQ_END(&sp->gp->dq)) { (void)gp->scr_move(sp, LASTLINE(sp), 0); (void)gp->scr_insertln(sp); } @@ -914,10 +914,10 @@ vs_msgsave(sp, mt, p, len) mp_n->mtype = mt; gp = sp->gp; - if ((mp_c = gp->msgq.lh_first) == NULL) { + if ((mp_c = LIST_FIRST(&gp->msgq)) == NULL) { LIST_INSERT_HEAD(&gp->msgq, mp_n, q); } else { - for (; mp_c->q.le_next != NULL; mp_c = mp_c->q.le_next); + for (; LIST_NEXT(mp_c, q) != NULL; mp_c = LIST_NEXT(mp_c, q)); LIST_INSERT_AFTER(mp_c, mp_n, q); } return; diff --git a/usr.bin/vi/vi/vs_refresh.c b/usr.bin/vi/vi/vs_refresh.c index 0a5c949014f..e842cc79dd0 100644 --- a/usr.bin/vi/vi/vs_refresh.c +++ b/usr.bin/vi/vi/vs_refresh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_refresh.c,v 1.9 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: vs_refresh.c,v 1.10 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -82,8 +82,7 @@ vs_refresh(sp, forcepaint) * that we can find, including status lines. */ if (F_ISSET(sp, SC_SCR_REDRAW)) - for (tsp = gp->dq.cqh_first; - tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next) + CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (tsp != sp) F_SET(tsp, SC_SCR_REDRAW | SC_STATUS); @@ -100,8 +99,7 @@ vs_refresh(sp, forcepaint) priv_paint = VIP_CUR_INVALID | VIP_N_REFRESH; if (O_ISSET(sp, O_NUMBER)) priv_paint |= VIP_N_RENUMBER; - for (tsp = gp->dq.cqh_first; - tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next) + CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (tsp != sp && !F_ISSET(tsp, SC_EXIT | SC_EXIT_FORCE) && (F_ISSET(tsp, pub_paint) || F_ISSET(VIP(tsp), priv_paint))) { @@ -136,8 +134,8 @@ vs_refresh(sp, forcepaint) * And, finally, if we updated any status lines, make sure the cursor * gets back to where it belongs. */ - for (need_refresh = 0, tsp = gp->dq.cqh_first; - tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next) + need_refresh = 0; + CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (F_ISSET(tsp, SC_STATUS)) { need_refresh = 1; vs_resolve(tsp, sp, 0); diff --git a/usr.bin/vi/vi/vs_split.c b/usr.bin/vi/vi/vs_split.c index f281b1a702a..0442e79ace3 100644 --- a/usr.bin/vi/vi/vs_split.c +++ b/usr.bin/vi/vi/vs_split.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vs_split.c,v 1.7 2002/02/16 21:27:58 millert Exp $ */ +/* $OpenBSD: vs_split.c,v 1.8 2005/10/17 19:12:16 otto Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -223,11 +223,11 @@ vs_discard(sp, spp) * they're the closest to the current screen. If that doesn't work, * there was no screen to join. */ - if ((nsp = sp->q.cqe_prev) != (void *)&sp->gp->dq) { + if ((nsp = CIRCLEQ_PREV(sp, q)) != CIRCLEQ_END(&sp->gp->dq)) { nsp->rows += sp->rows; sp = nsp; dir = FORWARD; - } else if ((nsp = sp->q.cqe_next) != (void *)&sp->gp->dq) { + } else if ((nsp = CIRCLEQ_NEXT(sp, q)) != CIRCLEQ_END(&sp->gp->dq)) { nsp->woff = sp->woff; nsp->rows += sp->rows; sp = nsp; @@ -503,15 +503,15 @@ vs_resize(sp, count, adj) s = sp; if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count) goto toosmall; - if ((g = sp->q.cqe_prev) == (void *)&gp->dq) { - if ((g = sp->q.cqe_next) == (void *)&gp->dq) + if ((g = CIRCLEQ_PREV(sp, q)) == CIRCLEQ_END(&gp->dq)) { + if ((g = CIRCLEQ_NEXT(sp, q)) == CIRCLEQ_END(&gp->dq)) goto toobig; g_off = -count; } else s_off = count; } else { g = sp; - if ((s = sp->q.cqe_next) != (void *)&gp->dq) + if ((s = CIRCLEQ_NEXT(sp, q)) != CIRCLEQ_END(&gp->dq)) if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count) s = NULL; else @@ -519,7 +519,7 @@ vs_resize(sp, count, adj) else s = NULL; if (s == NULL) { - if ((s = sp->q.cqe_prev) == (void *)&gp->dq) { + if ((s = CIRCLEQ_PREV(sp, q)) == CIRCLEQ_END(&gp->dq)) { toobig: msgq(sp, M_BERR, adj == A_DECREASE ? "227|The screen cannot shrink" : "228|The screen cannot grow"); @@ -580,21 +580,19 @@ vs_getbg(sp, name) /* If name is NULL, return the first background screen on the list. */ if (name == NULL) { - nsp = gp->hq.cqh_first; + nsp = CIRCLEQ_FIRST(&gp->hq); return (nsp == (void *)&gp->hq ? NULL : nsp); } /* Search for a full match. */ - for (nsp = gp->hq.cqh_first; - nsp != (void *)&gp->hq; nsp = nsp->q.cqe_next) + CIRCLEQ_FOREACH(nsp, &gp->hq, q) if (!strcmp(nsp->frp->name, name)) break; if (nsp != (void *)&gp->hq) return (nsp); /* Search for a last-component match. */ - for (nsp = gp->hq.cqh_first; - nsp != (void *)&gp->hq; nsp = nsp->q.cqe_next) { + CIRCLEQ_FOREACH(nsp, &gp->hq, q) { if ((p = strrchr(nsp->frp->name, '/')) == NULL) p = nsp->frp->name; else |