summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2002-03-16 20:29:22 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2002-03-16 20:29:22 +0000
commit8e9a920875130cd41a75cd004e200a248936e81b (patch)
treee65431dee1029a1f00536daacc92ba01bdad2008 /usr.bin/mg
parent5d4f7c2e3362875d0db1af6474d77a0f48ee7baf (diff)
This should've been commited yesterday, before the funmap change.
ok millert@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/undo.c56
2 files changed, 57 insertions, 2 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 603a3f77255..6f4734237bf 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.37 2002/03/16 04:17:36 vincent Exp $ */
+/* $OpenBSD: def.h,v 1.38 2002/03/16 20:29:21 vincent Exp $ */
#include <sys/queue.h>
@@ -578,6 +578,7 @@ int cntnonmatchlines(int, int);
/* undo.c X */
void free_undo_record(struct undo_rec *);
int undo_init(void);
+int undo_dump(void);
int undo_enable(int);
int undo_add_custom(int, LINE *, int, void *, int);
int undo_add_boundary(void);
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index 5bfecff4e89..9e98d8dae92 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: undo.c,v 1.7 2002/02/26 00:45:45 vincent Exp $ */
+/* $OpenBSD: undo.c,v 1.8 2002/03/16 20:29:21 vincent Exp $ */
/*
* Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
* All rights reserved.
@@ -377,6 +377,60 @@ undo_add_change(LINE *lp, int offset, int size)
return TRUE;
}
+/*
+ * Show the undo records for the current buffer in a new buffer.
+ */
+int
+undo_dump(void)
+{
+ struct undo_rec *rec;
+ BUFFER *bp;
+ MGWIN *wp;
+ char buf[4096], tmp[1024];
+ int num;
+
+ /*
+ * Prepare the buffer for insertion.
+ */
+ if ((bp = bfind("*undo*", TRUE)) == NULL)
+ return FALSE;
+
+ bclear(bp);
+ popbuf(bp);
+
+ for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
+ if (wp->w_bufp == bp) {
+ wp->w_dotp = bp->b_linep;
+ wp->w_doto = 0;
+ }
+
+ num = 0;
+ for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL;
+ rec = LIST_NEXT(rec, next)) {
+ num++;
+ snprintf(buf, sizeof buf,
+ "Record %d =>\t %s at %d ", num,
+ (rec->type == DELETE) ? "DELETE":
+ (rec->type == INSERT) ? "INSERT":
+ (rec->type == CHANGE) ? "CHANGE":
+ (rec->type == BOUNDARY) ? "----" : "UNKNOWN",
+ rec->pos);
+ if (rec->type == DELETE || rec->type == CHANGE) {
+
+ strlcat(buf, "\"", sizeof buf);
+ snprintf(tmp, sizeof tmp, "%.*s", rec->region.r_size,
+ rec->content);
+ strlcat(buf, tmp, sizeof buf);
+ strlcat(buf, "\"", sizeof buf);
+ }
+ snprintf(tmp, sizeof buf, " [%d]", rec->region.r_size);
+ strlcat(buf, tmp, sizeof buf);
+
+ addlinef(bp, buf);
+ }
+ return TRUE;
+}
+
int
undo(int f, int n)
{