diff options
Diffstat (limited to 'usr.bin/vi/mark.c')
-rw-r--r-- | usr.bin/vi/mark.c | 130 |
1 files changed, 72 insertions, 58 deletions
diff --git a/usr.bin/vi/mark.c b/usr.bin/vi/mark.c index c510a22002fcf..26c02afb42265 100644 --- a/usr.bin/vi/mark.c +++ b/usr.bin/vi/mark.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1992, 1993 + * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,18 +32,28 @@ */ #ifndef lint -static char sccsid[] = "@(#)mark.c 8.12 (Berkeley) 12/27/93"; +static char sccsid[] = "@(#)mark.c 8.17 (Berkeley) 3/15/94"; #endif /* not lint */ #include <sys/types.h> +#include <queue.h> +#include <sys/time.h> +#include <bitstring.h> #include <errno.h> +#include <limits.h> +#include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <termios.h> + +#include <db.h> +#include <regex.h> #include "vi.h" -static MARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T)); +static LMARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T)); /* * Marks are maintained in a key sorted doubly linked list. We can't @@ -69,7 +79,7 @@ static MARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T)); * deleted, we delete (and log) any marks on that line. An undo will create * the mark. Any mark creations are noted as to whether the user created * it or if it was created by an undo. The former cannot be reset by another - * undo, but the latter may. + * undo, but the latter may. * * All of these routines translate ABSMARK2 to ABSMARK1. Setting either of * the absolute mark locations sets both, so that "m'" and "m`" work like @@ -85,18 +95,18 @@ mark_init(sp, ep) SCR *sp; EXF *ep; { - MARK *mp; + LMARK *lmp; /* * Make sure the marks have been set up. If they * haven't, do so, and create the absolute mark. */ - MALLOC_RET(sp, mp, MARK *, sizeof(MARK)); - mp->lno = 1; - mp->cno = 0; - mp->name = ABSMARK1; - mp->flags = 0; - LIST_INSERT_HEAD(&ep->marks, mp, q); + MALLOC_RET(sp, lmp, LMARK *, sizeof(LMARK)); + lmp->lno = 1; + lmp->cno = 0; + lmp->name = ABSMARK1; + lmp->flags = 0; + LIST_INSERT_HEAD(&ep->marks, lmp, q); return (0); } @@ -109,11 +119,11 @@ mark_end(sp, ep) SCR *sp; EXF *ep; { - MARK *mp; + LMARK *lmp; - while ((mp = ep->marks.lh_first) != NULL) { - LIST_REMOVE(mp, q); - FREE(mp, sizeof(MARK)); + while ((lmp = ep->marks.lh_first) != NULL) { + LIST_REMOVE(lmp, q); + FREE(lmp, sizeof(LMARK)); } return (0); } @@ -122,36 +132,38 @@ mark_end(sp, ep) * mark_get -- * Get the location referenced by a mark. */ -MARK * -mark_get(sp, ep, key) +int +mark_get(sp, ep, key, mp) SCR *sp; EXF *ep; ARG_CHAR_T key; -{ MARK *mp; +{ + LMARK *lmp; size_t len; - char *p; if (key == ABSMARK2) key = ABSMARK1; - mp = mark_find(sp, ep, key); - if (mp == NULL || mp->name != key) { + lmp = mark_find(sp, ep, key); + if (lmp == NULL || lmp->name != key) { msgq(sp, M_BERR, "Mark %s: not set.", charname(sp, key)); - return (NULL); + return (1); } - if (F_ISSET(mp, MARK_DELETED)) { + if (F_ISSET(lmp, MARK_DELETED)) { msgq(sp, M_BERR, "Mark %s: the line was deleted.", charname(sp, key)); - return (NULL); + return (1); } - if ((p = file_gline(sp, ep, mp->lno, &len)) == NULL || - mp->cno > len || mp->cno == len && len != 0) { + if (file_gline(sp, ep, lmp->lno, &len) == NULL || + lmp->cno > len || lmp->cno == len && len != 0) { msgq(sp, M_BERR, "Mark %s: cursor position no longer exists.", charname(sp, key)); - return (NULL); + return (1); } - return (mp); + mp->lno = lmp->lno; + mp->cno = lmp->cno; + return (0); } /* @@ -166,7 +178,7 @@ mark_set(sp, ep, key, value, userset) MARK *value; int userset; { - MARK *mp, *mt; + LMARK *lmp, *lmt; if (key == ABSMARK2) key = ABSMARK1; @@ -177,22 +189,22 @@ mark_set(sp, ep, key, value, userset) * an undo, and we set it if it's not already set or if it was set * by a previous undo. */ - mp = mark_find(sp, ep, key); - if (mp == NULL || mp->name != key) { - MALLOC_RET(sp, mt, MARK *, sizeof(MARK)); - if (mp == NULL) { - LIST_INSERT_HEAD(&ep->marks, mt, q); + lmp = mark_find(sp, ep, key); + if (lmp == NULL || lmp->name != key) { + MALLOC_RET(sp, lmt, LMARK *, sizeof(LMARK)); + if (lmp == NULL) { + LIST_INSERT_HEAD(&ep->marks, lmt, q); } else - LIST_INSERT_AFTER(mp, mt, q); - mp = mt; + LIST_INSERT_AFTER(lmp, lmt, q); + lmp = lmt; } else if (!userset && - !F_ISSET(mp, MARK_DELETED) && F_ISSET(mp, MARK_USERSET)) + !F_ISSET(lmp, MARK_DELETED) && F_ISSET(lmp, MARK_USERSET)) return (0); - mp->lno = value->lno; - mp->cno = value->cno; - mp->name = key; - mp->flags = userset ? MARK_USERSET : 0; + lmp->lno = value->lno; + lmp->cno = value->cno; + lmp->name = key; + lmp->flags = userset ? MARK_USERSET : 0; return (0); } @@ -201,23 +213,23 @@ mark_set(sp, ep, key, value, userset) * Find the requested mark, or, the slot immediately before * where it would go. */ -static MARK * +static LMARK * mark_find(sp, ep, key) SCR *sp; EXF *ep; ARG_CHAR_T key; { - MARK *mp, *lastmp; + LMARK *lmp, *lastlmp; /* * Return the requested mark or the slot immediately before * where it should go. */ - for (lastmp = NULL, mp = ep->marks.lh_first; - mp != NULL; lastmp = mp, mp = mp->q.le_next) - if (mp->name >= key) - return (mp->name == key ? mp : lastmp); - return (lastmp); + for (lastlmp = NULL, lmp = ep->marks.lh_first; + lmp != NULL; lastlmp = lmp, lmp = lmp->q.le_next) + if (lmp->name >= key) + return (lmp->name == key ? lmp : lastlmp); + return (lastlmp); } /* @@ -231,24 +243,26 @@ mark_insdel(sp, ep, op, lno) enum operation op; recno_t lno; { - MARK *mp; + LMARK *lmp; switch (op) { case LINE_APPEND: return; case LINE_DELETE: - for (mp = ep->marks.lh_first; mp != NULL; mp = mp->q.le_next) - if (mp->lno >= lno) - if (mp->lno == lno) { - F_SET(mp, MARK_DELETED); - (void)log_mark(sp, ep, mp); + for (lmp = ep->marks.lh_first; + lmp != NULL; lmp = lmp->q.le_next) + if (lmp->lno >= lno) + if (lmp->lno == lno) { + F_SET(lmp, MARK_DELETED); + (void)log_mark(sp, ep, lmp); } else - --mp->lno; + --lmp->lno; return; case LINE_INSERT: - for (mp = ep->marks.lh_first; mp != NULL; mp = mp->q.le_next) - if (mp->lno >= lno) - ++mp->lno; + for (lmp = ep->marks.lh_first; + lmp != NULL; lmp = lmp->q.le_next) + if (lmp->lno >= lno) + ++lmp->lno; return; case LINE_RESET: return; |