summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/def.h5
-rw-r--r--usr.bin/mg/file.c6
-rw-r--r--usr.bin/mg/line.c6
-rw-r--r--usr.bin/mg/paragraph.c6
-rw-r--r--usr.bin/mg/random.c6
-rw-r--r--usr.bin/mg/undo.c61
-rw-r--r--usr.bin/mg/yank.c6
7 files changed, 50 insertions, 46 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index e2311a1063d..a7bb7c62cf7 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.96 2006/08/01 22:16:03 jason Exp $ */
+/* $OpenBSD: def.h,v 1.97 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -599,12 +599,13 @@ int cntnonmatchlines(int, int);
/* undo.c X */
void free_undo_record(struct undo_rec *);
int undo_dump(int, int);
+int undo_enabled(void);
int undo_enable(int);
void undo_add_boundary(void);
void undo_add_modified(void);
int undo_add_insert(struct line *, int, int);
int undo_add_delete(struct line *, int, int);
-void undo_no_boundary(int);
+void undo_boundary_enable(int);
int undo_add_change(struct line *, int, int);
int undo(int, int);
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 234d310a54c..8b245c57de2 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.62 2006/07/25 08:27:09 kjell Exp $ */
+/* $OpenBSD: file.c,v 1.63 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -283,12 +283,14 @@ insertfile(char *fname, char *newname, int replacebuf)
struct line *lp1, *lp2;
struct line *olp; /* line we started at */
struct mgwin *wp;
- int nbytes, s, nline = 0, siz, x = -1, x2;
+ int nbytes, s, nline = 0, siz, x, x2;
int opos; /* offset we started at */
int oline; /* original line number */
if (replacebuf == TRUE)
x = undo_enable(FALSE);
+ else
+ x = undo_enabled();
lp1 = NULL;
if (line == NULL) {
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 4710c57d8e2..47b341c0cc2 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.42 2006/07/25 08:27:09 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.43 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -559,7 +559,7 @@ lreplace(RSIZE plen, char *st)
return (FALSE);
}
undo_add_boundary();
- undo_no_boundary(TRUE);
+ undo_boundary_enable(FALSE);
(void)backchar(FFARG | FFRAND, (int)plen);
(void)ldelete(plen, KNONE);
@@ -568,7 +568,7 @@ lreplace(RSIZE plen, char *st)
region_put_data(st, rlen);
lchange(WFFULL);
- undo_no_boundary(FALSE);
+ undo_boundary_enable(TRUE);
undo_add_boundary();
return (TRUE);
}
diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c
index 22fbf60061b..31e8facfeb1 100644
--- a/usr.bin/mg/paragraph.c
+++ b/usr.bin/mg/paragraph.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paragraph.c,v 1.14 2006/07/25 08:22:32 kjell Exp $ */
+/* $OpenBSD: paragraph.c,v 1.15 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -131,7 +131,7 @@ fillpara(int f, int n)
char wbuf[MAXWORD]; /* buffer for current word */
undo_add_boundary();
- undo_no_boundary(TRUE);
+ undo_boundary_enable(FALSE);
/* record the pointer to the line just past the EOP */
(void)gotoeop(FFRAND, 1);
@@ -237,7 +237,7 @@ fillpara(int f, int n)
(void)backchar(FFRAND, 1);
retval = TRUE;
cleanup:
- undo_no_boundary(FALSE);
+ undo_boundary_enable(TRUE);
undo_add_boundary();
return (retval);
}
diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c
index 6daeec30152..4cb097fb70f 100644
--- a/usr.bin/mg/random.c
+++ b/usr.bin/mg/random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: random.c,v 1.22 2006/07/25 08:27:09 kjell Exp $ */
+/* $OpenBSD: random.c,v 1.23 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -120,7 +120,7 @@ twiddle(int f, int n)
dotp = curwp->w_dotp;
doto = curwp->w_doto;
undo_add_boundary();
- undo_no_boundary(TRUE);
+ undo_boundary_enable(FALSE);
if (doto == llength(dotp)) {
if (--doto <= 0)
return (FALSE);
@@ -136,7 +136,7 @@ twiddle(int f, int n)
linsert(1, cr);
if (fudge != TRUE)
(void)backchar(FFRAND, 1);
- undo_no_boundary(FALSE);
+ undo_boundary_enable(TRUE);
undo_add_boundary();
lchange(WFEDIT);
return (TRUE);
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index 0ddf81023e9..c7703d194c8 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: undo.c,v 1.41 2006/07/25 08:22:32 kjell Exp $ */
+/* $OpenBSD: undo.c,v 1.42 2006/11/17 08:45:31 kjell Exp $ */
/*
* Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
* Copyright (c) 2005, 2006 Kjell Wooding <kjell@openbsd.org>
@@ -35,17 +35,8 @@
*/
static LIST_HEAD(, undo_rec) undo_free;
static int undo_free_num;
-static int nobound;
-
-/*
- * Global variables
- */
-/*
- * undo_disable_flag: Stop doing undo (useful when we know are
- * going to deal with huge deletion/insertions
- * that we don't plan to undo)
- */
-int undo_disable_flag;
+static int boundary_flag = TRUE;
+static int undo_enable_flag = TRUE;
/*
* Local functions
@@ -181,33 +172,43 @@ lastrectype(void)
}
/*
+ * Returns TRUE if undo is enabled, FALSE otherwise.
+ */
+int
+undo_enabled(void)
+{
+ return (undo_enable_flag);
+}
+
+/*
* undo_enable(TRUE/FALSE) will enable / disable the undo mechanism.
* Returns TRUE if previously enabled, FALSE otherwise.
*/
int
undo_enable(int on)
{
- int pon = undo_disable_flag;
+ int pon = undo_enable_flag;
- undo_disable_flag = (on == TRUE) ? 0 : 1;
- return ((pon == TRUE) ? FALSE : TRUE);
+ undo_enable_flag = on;
+ return (pon);
}
/*
* If undo is enabled, then:
- * undo_no_boundary(TRUE) stops recording undo boundaries between actions.
- * undo_no_boundary(FALSE) enables undo boundaries.
+ * undo_boundary_enable(FALS) stops recording undo boundaries between actions.
+ * undo_boundary_enable(TRUE) enables undo boundaries.
* If undo is disabled, this function has no effect.
*/
+
void
-undo_no_boundary(int flag)
+undo_boundary_enable(int flag)
{
- if (undo_disable_flag == FALSE)
- nobound = flag;
+ if (undo_enable_flag == TRUE)
+ boundary_flag = flag;
}
/*
- * Record an undo boundary, unless 'nobound' is set via undo_no_boundary.
+ * Record an undo boundary, unless boundary_flag == FALSE.
* Does nothing if previous undo entry is already a boundary or 'modified' flag.
*/
void
@@ -216,7 +217,7 @@ undo_add_boundary(void)
struct undo_rec *rec;
int last;
- if (nobound)
+ if (boundary_flag == FALSE)
return;
last = lastrectype();
@@ -254,7 +255,7 @@ undo_add_insert(struct line *lp, int offset, int size)
struct undo_rec *rec;
int pos;
- if (undo_disable_flag)
+ if (undo_enable_flag == FALSE)
return (TRUE);
reg.r_linep = lp;
reg.r_offset = offset;
@@ -299,7 +300,7 @@ undo_add_delete(struct line *lp, int offset, int size)
struct undo_rec *rec;
int pos;
- if (undo_disable_flag)
+ if (undo_enable_flag == FALSE)
return (TRUE);
reg.r_linep = lp;
@@ -348,13 +349,13 @@ undo_add_delete(struct line *lp, int offset, int size)
int
undo_add_change(struct line *lp, int offset, int size)
{
- if (undo_disable_flag)
+ if (undo_enable_flag == FALSE)
return (TRUE);
undo_add_boundary();
- nobound = TRUE;
+ boundary_flag = FALSE;
undo_add_delete(lp, offset, size);
undo_add_insert(lp, offset, size);
- nobound = FALSE;
+ boundary_flag = TRUE;
undo_add_boundary();
return (TRUE);
@@ -503,8 +504,8 @@ undo(int f, int n)
undo_add_boundary();
- save = nobound;
- nobound = TRUE;
+ save = boundary_flag;
+ boundary_flag = FALSE;
done = 0;
do {
@@ -553,7 +554,7 @@ undo(int f, int n)
ptr = LIST_NEXT(ptr, next);
} while (ptr != NULL && !done);
- nobound = save;
+ boundary_flag = save;
undo_add_boundary();
ewprintf("Undo!");
diff --git a/usr.bin/mg/yank.c b/usr.bin/mg/yank.c
index d3668203256..12710331d1a 100644
--- a/usr.bin/mg/yank.c
+++ b/usr.bin/mg/yank.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: yank.c,v 1.4 2006/07/25 08:22:32 kjell Exp $ */
+/* $OpenBSD: yank.c,v 1.5 2006/11/17 08:45:31 kjell Exp $ */
/* This file is in the public domain. */
@@ -223,7 +223,7 @@ yank(int f, int n)
nline = 0;
undo_add_boundary();
- undo_no_boundary(TRUE);
+ undo_boundary_enable(FALSE);
while (n--) {
/* mark around last yank */
isetmark();
@@ -251,7 +251,7 @@ yank(int f, int n)
curwp->w_linep = lp;
curwp->w_flag |= WFFULL;
}
- undo_no_boundary(FALSE);
+ undo_boundary_enable(TRUE);
undo_add_boundary();
return (TRUE);
}