summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
{