=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/undo.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- src/usr.bin/mg/undo.c 2009/06/05 18:02:06 1.49 +++ src/usr.bin/mg/undo.c 2010/06/30 19:12:54 1.50 @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.49 2009/06/05 18:02:06 kjell Exp $ */ +/* $OpenBSD: undo.c,v 1.50 2010/06/30 19:12:54 oga Exp $ */ /* * This file is in the public domain */ @@ -11,7 +11,7 @@ /* * Local variables */ -static LIST_HEAD(, undo_rec) undo_free; +static struct undoq undo_free; static int undo_free_num; static int boundary_flag = TRUE; static int undo_enable_flag = TRUE; @@ -82,9 +82,10 @@ { struct undo_rec *rec; - rec = LIST_FIRST(&undo_free); + rec = TAILQ_FIRST(&undo_free); if (rec != NULL) { - LIST_REMOVE(rec, next); /* Remove it from the free-list */ + /* Remove it from the free-list */ + TAILQ_REMOVE(&undo_free, rec, next); undo_free_num--; } else { if ((rec = malloc(sizeof(*rec))) == NULL) @@ -104,7 +105,7 @@ * On the first run, do initialisation of the free list. */ if (initialised == 0) { - LIST_INIT(&undo_free); + TAILQ_INIT(&undo_free); initialised = 1; } if (rec->content != NULL) { @@ -117,7 +118,7 @@ } undo_free_num++; - LIST_INSERT_HEAD(&undo_free, rec, next); + TAILQ_INSERT_HEAD(&undo_free, rec, next); } /* @@ -129,10 +130,10 @@ { struct undo_rec *rec; - rec = LIST_END(&curbp->b_undo); + rec = TAILQ_LAST(&curbp->b_undo, undoq); if (rec != NULL) { undo_free_num--; - LIST_REMOVE(rec, next); + TAILQ_REMOVE(&curbp->b_undo, rec, next); free_undo_record(rec); return (1); } @@ -144,7 +145,7 @@ { struct undo_rec *rec; - if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) + if ((rec = TAILQ_FIRST(&curbp->b_undo)) != NULL) return (rec->type); return (0); } @@ -227,7 +228,7 @@ rec = new_undo_record(); rec->type = BOUNDARY; - LIST_INSERT_HEAD(&curbp->b_undo, rec, next); + TAILQ_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -243,7 +244,7 @@ rec = new_undo_record(); rec->type = MODIFIED; - LIST_INSERT_HEAD(&curbp->b_undo, rec, next); + TAILQ_INSERT_HEAD(&curbp->b_undo, rec, next); return; } @@ -266,7 +267,7 @@ /* * We try to reuse the last undo record to `compress' things. */ - rec = LIST_FIRST(&curbp->b_undo); + rec = TAILQ_FIRST(&curbp->b_undo); if (rec != NULL && rec->type == INSERT) { if (rec->pos + rec->region.r_size == pos) { rec->region.r_size += reg.r_size; @@ -285,7 +286,7 @@ undo_add_boundary(FFRAND, 1); - LIST_INSERT_HEAD(&curbp->b_undo, rec, next); + TAILQ_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -311,7 +312,7 @@ if (offset == llength(lp)) /* if it's a newline... */ undo_add_boundary(FFRAND, 1); - else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) { + else if ((rec = TAILQ_FIRST(&curbp->b_undo)) != NULL) { /* * Separate this command from the previous one if we're not * just before the previous record... @@ -340,7 +341,7 @@ if (isreg || lastrectype() != DELETE) undo_add_boundary(FFRAND, 1); - LIST_INSERT_HEAD(&curbp->b_undo, rec, next); + TAILQ_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -393,8 +394,7 @@ } num = 0; - for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL; - rec = LIST_NEXT(rec, next)) { + TAILQ_FOREACH(rec, &curbp->b_undo, next) { num++; snprintf(buf, sizeof(buf), "%d:\t %s at %d ", num, @@ -477,7 +477,7 @@ /* first invocation, make ptr point back to the top of the list */ if ((ptr == NULL && nulled == TRUE) || rptcount == 0) { - ptr = LIST_FIRST(&curbp->b_undo); + ptr = TAILQ_FIRST(&curbp->b_undo); nulled = TRUE; } @@ -485,8 +485,8 @@ while (n--) { /* if we have a spurious boundary, free it and move on.... */ while (ptr && ptr->type == BOUNDARY) { - nptr = LIST_NEXT(ptr, next); - LIST_REMOVE(ptr, next); + nptr = TAILQ_NEXT(ptr, next); + TAILQ_REMOVE(&curbp->b_undo, ptr, next); free_undo_record(ptr); ptr = nptr; } @@ -565,7 +565,7 @@ } /* And move to next record */ - ptr = LIST_NEXT(ptr, next); + ptr = TAILQ_NEXT(ptr, next); } while (ptr != NULL && !done); boundary_flag = save;