summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2006-07-08 17:50:31 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2006-07-08 17:50:31 +0000
commit2272f7dfceb16faa7ca53610182b64068e7b5fe4 (patch)
treee4a88f177872258ab061497f40c4d6ef64ecc456 /usr.bin/mg
parentfc417ff94a0519f2959aa37c615a981aa033e2fc (diff)
Fix a trio of bugs in line numbering: adjusting linenos after undo,
cutting a block, and off-by-one linecount. Initial bug discovered by jason
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/buffer.c6
-rw-r--r--usr.bin/mg/region.c7
-rw-r--r--usr.bin/mg/undo.c16
3 files changed, 20 insertions, 9 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index e8e9417723a..db77f912b59 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.60 2006/06/01 09:00:50 kjell Exp $ */
+/* $OpenBSD: buffer.c,v 1.61 2006/07/08 17:50:30 kjell Exp $ */
/* This file is in the public domain. */
@@ -532,7 +532,7 @@ bnew()
bp->b_bufp = bheadp;
bheadp = bp;
bp->b_dotline = bp->b_markline = 1;
- bp->b_lines = 0;
+ bp->b_lines = 1;
return (bp);
}
@@ -564,7 +564,7 @@ bclear(struct buffer *bp)
bp->b_markp = NULL; /* Invalidate "mark" */
bp->b_marko = 0;
bp->b_dotline = bp->b_markline = 1;
- bp->b_lines = 0;
+ bp->b_lines = 1;
return (TRUE);
}
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
index d225ea691ef..769cad5c252 100644
--- a/usr.bin/mg/region.c
+++ b/usr.bin/mg/region.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: region.c,v 1.22 2006/05/28 23:30:16 kjell Exp $ */
+/* $OpenBSD: region.c,v 1.23 2006/07/08 17:50:30 kjell Exp $ */
/* This file is in the public domain. */
@@ -33,7 +33,10 @@ killregion(int f, int n)
thisflag |= CFKILL;
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
- return (ldelete(region.r_size, KFORW));
+ s = ldelete(region.r_size, KFORW);
+ if (s == TRUE && curwp->w_dotline > curwp->w_markline)
+ curwp->w_dotline = curwp->w_markline;
+ return (s);
}
/*
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index b6600d441e9..f0059b13020 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,6 +1,7 @@
-/* $OpenBSD: undo.c,v 1.38 2005/12/20 05:04:28 kjell Exp $ */
+/* $OpenBSD: undo.c,v 1.39 2006/07/08 17:50:30 kjell Exp $ */
/*
* Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
+ * Copyright (c) 2005, 2006 Kjell Wooding <kjell@openbsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +51,7 @@ int undo_disable_flag;
* Local functions
*/
static int find_dot(struct line *, int);
-static int find_lo(int, struct line **, int *);
+static int find_lo(int, struct line **, int *, int *);
static struct undo_rec *new_undo_record(void);
static int drop_oldest_undo_record(void);
@@ -84,11 +85,13 @@ find_dot(struct line *lp, int off)
}
static int
-find_lo(int pos, struct line **olp, int *offset)
+find_lo(int pos, struct line **olp, int *offset, int *lnum)
{
struct line *p;
+ int lineno;
p = curbp->b_linep;
+ lineno = 0;
while (pos > llength(p)) {
pos -= llength(p) + 1;
if ((p = lforw(p)) == curbp->b_linep) {
@@ -96,9 +99,11 @@ find_lo(int pos, struct line **olp, int *offset)
*offset = 0;
return (FALSE);
}
+ lineno++;
}
*olp = p;
*offset = pos;
+ *lnum = lineno;
return (TRUE);
}
@@ -438,6 +443,7 @@ undo(int f, int n)
struct line *lp;
int offset, save, dot;
static int nulled = FALSE;
+ int lineno;
dot = find_dot(curwp->w_dotp, curwp->w_doto);
@@ -492,13 +498,15 @@ undo(int f, int n)
*/
if (ptr->type != BOUNDARY) {
if (find_lo(ptr->pos, &lp,
- &offset) == FALSE) {
+ &offset, &lineno) == FALSE) {
ewprintf("Internal error in Undo!");
rval = FALSE;
break;
}
curwp->w_dotp = lp;
curwp->w_doto = offset;
+ curwp->w_markline = curwp->w_dotline;
+ curwp->w_dotline = lineno;
}
/*