summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2005-10-11 01:08:54 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2005-10-11 01:08:54 +0000
commit84d65e93af5f549a6a231de6c1463310a43308c9 (patch)
tree00c8eb5a04689436c97aa614aef8405e24426ae9 /usr.bin/mg
parent0ecee07d8fe56b1a0133782d5bd5870088af493a (diff)
A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across multiple buffers. Change them back to being associated with the BUFFER struct. (effectively, just revert the original change) ok deraadt@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/buffer.c13
-rw-r--r--usr.bin/mg/def.h10
-rw-r--r--usr.bin/mg/undo.c28
-rw-r--r--usr.bin/mg/window.c26
4 files changed, 35 insertions, 42 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index 9b4eae3019e..6f565281899 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.45 2005/09/28 06:37:52 deraadt Exp $ */
+/* $OpenBSD: buffer.c,v 1.46 2005/10/11 01:08:52 kjell Exp $ */
/* This file is in the public domain. */
@@ -126,6 +126,7 @@ killbuffer(BUFFER *bp)
BUFFER *bp2;
MGWIN *wp;
int s;
+ struct undo_rec *rec, *next;
/*
* Find some other buffer to display. Try the alternate buffer,
@@ -176,6 +177,13 @@ killbuffer(BUFFER *bp)
bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;
bp1 = bp1->b_bufp;
}
+ rec = LIST_FIRST(&bp->b_undo);
+ while (rec != NULL) {
+ next = LIST_NEXT(rec, next);
+ free_undo_record(rec);
+ rec = next;
+ }
+
free((char *)bp->b_bname); /* Release name block */
free(bp); /* Release buffer block */
return (TRUE);
@@ -488,6 +496,9 @@ bfind(const char *bname, int cflag)
bp->b_nwnd = 0;
bp->b_linep = lp;
bp->b_nmodes = defb_nmodes;
+ LIST_INIT(&bp->b_undo);
+ bp->b_undoptr = NULL;
+ memset(&bp->b_undopos, 0, sizeof(bp->b_undopos));
i = 0;
do {
bp->b_modes[i] = defb_modes[i];
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 78c4aff8611..2055a40d206 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.66 2005/10/11 00:50:00 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.67 2005/10/11 01:08:53 kjell Exp $ */
/* This file is in the public domain. */
@@ -203,10 +203,6 @@ typedef struct MGWIN {
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
- LIST_HEAD(, undo_rec) w_undo; /* Undo actions list */
- int w_undopos; /* Where we were during the */
- /* last undo action. */
- struct undo_rec *w_undoptr;
struct LINE *w_wrapline;
} MGWIN;
#define w_wndp w_list.l_p.l_wp
@@ -253,6 +249,10 @@ typedef struct BUFFER {
char b_flag; /* Flags */
char b_fname[NFILEN]; /* File name */
struct fileinfo b_fi; /* File attributes */
+ LIST_HEAD(, undo_rec) b_undo; /* Undo actions list */
+ int b_undopos; /* Where we were during the */
+ /* last undo action. */
+ struct undo_rec *b_undoptr;
} BUFFER;
#define b_bufp b_list.l_p.x_bp
#define b_bname b_list.l_name
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index f5e7d5c3f2e..61f276d3541 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: undo.c,v 1.28 2005/10/06 16:48:00 kjell Exp $ */
+/* $OpenBSD: undo.c,v 1.29 2005/10/11 01:08:53 kjell Exp $ */
/*
* Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
* All rights reserved.
@@ -155,7 +155,7 @@ drop_oldest_undo_record(void)
{
struct undo_rec *rec;
- rec = LIST_END(&curwp->w_undo);
+ rec = LIST_END(&curbp->b_undo);
if (rec != NULL) {
undo_free_num--;
LIST_REMOVE(rec, next);
@@ -170,7 +170,7 @@ lastrectype(void)
{
struct undo_rec *rec;
- if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL)
+ if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL)
return (rec->type);
return (0);
}
@@ -205,7 +205,7 @@ undo_add_boundary(void)
rec = new_undo_record();
rec->type = BOUNDARY;
- LIST_INSERT_HEAD(&curwp->w_undo, rec, next);
+ LIST_INSERT_HEAD(&curbp->b_undo, rec, next);
return (TRUE);
}
@@ -228,7 +228,7 @@ undo_add_insert(LINE *lp, int offset, int size)
/*
* We try to reuse the last undo record to `compress' things.
*/
- rec = LIST_FIRST(&curwp->w_undo);
+ rec = LIST_FIRST(&curbp->b_undo);
if (rec != NULL && rec->type == INSERT) {
if (rec->pos + rec->region.r_size == pos) {
rec->region.r_size += reg.r_size;
@@ -247,7 +247,7 @@ undo_add_insert(LINE *lp, int offset, int size)
undo_add_boundary();
- LIST_INSERT_HEAD(&curwp->w_undo, rec, next);
+ LIST_INSERT_HEAD(&curbp->b_undo, rec, next);
return (TRUE);
}
@@ -273,7 +273,7 @@ undo_add_delete(LINE *lp, int offset, int size)
if (offset == llength(lp)) /* if it's a newline... */
undo_add_boundary();
- else if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL) {
+ else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) {
/*
* Separate this command from the previous one if we're not
* just before the previous record...
@@ -300,7 +300,7 @@ undo_add_delete(LINE *lp, int offset, int size)
if (lastrectype() != DELETE)
undo_add_boundary();
- LIST_INSERT_HEAD(&curwp->w_undo, rec, next);
+ LIST_INSERT_HEAD(&curbp->b_undo, rec, next);
return (TRUE);
}
@@ -352,7 +352,7 @@ undo_dump(int f, int n)
}
num = 0;
- for (rec = LIST_FIRST(&curwp->w_undo); rec != NULL;
+ for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL;
rec = LIST_NEXT(rec, next)) {
num++;
snprintf(buf, sizeof(buf),
@@ -422,11 +422,11 @@ undo(int f, int n)
dot = find_dot(curwp->w_dotp, curwp->w_doto);
- ptr = curwp->w_undoptr;
+ ptr = curbp->b_undoptr;
/* if we moved, make ptr point back to the top of the list */
- if ((ptr == NULL && nulled == TRUE) || curwp->w_undopos != dot) {
- ptr = LIST_FIRST(&curwp->w_undo);
+ if ((ptr == NULL && nulled == TRUE) || curbp->b_undopos != dot) {
+ ptr = LIST_FIRST(&curbp->b_undo);
nulled = TRUE;
}
@@ -513,9 +513,9 @@ undo(int f, int n)
* Record where we are. (we have to save our new position at the end
* since we change the dot when undoing....)
*/
- curwp->w_undoptr = ptr;
+ curbp->b_undoptr = ptr;
- curwp->w_undopos = find_dot(curwp->w_dotp, curwp->w_doto);
+ curbp->b_undopos = find_dot(curwp->w_dotp, curwp->w_doto);
return (rval);
}
diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c
index 9331e54fe51..b56722605b1 100644
--- a/usr.bin/mg/window.c
+++ b/usr.bin/mg/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.17 2005/06/14 18:14:40 kjell Exp $ */
+/* $OpenBSD: window.c,v 1.18 2005/10/11 01:08:53 kjell Exp $ */
/* This file is in the public domain. */
@@ -27,27 +27,9 @@ new_window(BUFFER *bp)
wp->w_wrapline = NULL;
if (bp)
bp->b_nwnd++;
- LIST_INIT(&wp->w_undo);
- wp->w_undoptr = NULL;
- wp->w_undopos = 0;
-
return (wp);
}
-void
-free_window(MGWIN *wp)
-{
- struct undo_rec *rec, *next;
-
- rec = LIST_FIRST(&wp->w_undo);
- while (rec != NULL) {
- next = LIST_NEXT(rec, next);
- free_undo_record(rec);
- rec = next;
- }
- free(wp);
-}
-
/*
* Reposition dot in the current window to line "n". If the argument is
* positive, it is that line. If it is negative it is that line from the
@@ -177,7 +159,7 @@ onlywind(int f, int n)
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
- free_window(wp);
+ free(wp);
}
while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp;
@@ -188,7 +170,7 @@ onlywind(int f, int n)
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
- free_window(wp);
+ free(wp);
}
lp = curwp->w_linep;
i = curwp->w_toprow;
@@ -425,7 +407,7 @@ delwind(int f, int n)
nwp->w_wndp = wp->w_wndp;
break;
}
- free_window(wp);
+ free(wp);
return (TRUE);
}