1 /* $Id: undo.h,v 1.7 2000/11/05 01:59:20 amura Exp $ */
2 /*
3  * Undo supports: Ng 1.4(upto beta4) support undo like emacs.
4  * This undo is not support redo. and not perfect now.
5  *
6  * by MURAMATSU Atsushi
7  */
8 
9 /*
10  * $Log: undo.h,v $
11  * Revision 1.7  2000/11/05 01:59:20  amura
12  * ploblem with big undo is fixed
13  *
14  * Revision 1.6  2000/11/04 13:44:58  amura
15  * undo memory exception is more safety
16  *
17  * Revision 1.5  2000/07/22 20:49:38  amura
18  * more secure run insert
19  *
20  * Revision 1.4  2000/07/20 12:45:18  amura
21  * support undo with auto-fill mode
22  *
23  * Revision 1.3  2000/07/16 15:50:32  amura
24  * undo bug on autofill fixed
25  * rewrite macro functions
26  *
27  * Revision 1.2  2000/06/27 01:49:45  amura
28  * import to CVS
29  *
30  * Revision 1.1  2000/06/01 05:21:24  amura
31  * Initial revision
32  *
33  */
34 
35 #define UDNONE		0
36 #define	UDDEL		1
37 #define UDBS		2
38 #define UDINS		3
39 #define	UDINSNL		3	/* this is backward compatibirity */
40 #define UDOVER		5
41 #define UDTWIDDLE	6
42 #define	UDREPL		7
43 
44 #define UDMASK		0x0F
45 #define	UDFIRST		0x10
46 
47 typedef struct UNDO_DATA {
48     int    u_type;
49     int    u_dotlno;
50     short  u_doto;
51     RSIZE  u_size;
52     char   u_code[2];
53     struct UNDO_DATA* u_next;
54     RSIZE  u_used;
55     char   *u_buffer;
56 } UNDO_DATA;
57 
58 extern UNDO_DATA** undoptr;
59 extern UNDO_DATA** undostart;
60 extern UNDO_DATA** undobefore;
61 
62 /* undo support functions */
63 
64 VOID ublock_open  pro((register BUFFER *));
65 VOID ublock_close pro((register BUFFER *));
66 VOID ublock_clear pro((register UNDO_DATA **));
67 VOID undo_clean   pro((BUFFER*));
68 int  undo_balloc pro((register UNDO_DATA*, register RSIZE));
69 int  undo_bgrow  pro((register UNDO_DATA*, register RSIZE));
70 
71 /* undo support functions (implemented by macro for SPEED) */
72 
73 #define isundo() (undoptr  != NULL)
74 #define undo_check(_bp)	((_bp)->b_utop != (_bp)->b_ubottom)
75 #define undo_reset(_bp)	((void)((_bp)->b_ubottom = (_bp)->b_utop = 0, \
76 				(_bp)->b_ulast = NULL))
77 #define undo_setup(_u) do {				\
78     if (undoptr != NULL) {				\
79 	if (*undoptr == NULL) {				\
80 	    *undoptr = malloc(sizeof(UNDO_DATA));	\
81 	    if (*undoptr == NULL) {			\
82 		ewprintf("undo_setup: No memory");	\
83 		ttwait();				\
84 		undo_clean(curbp);			\
85 		undoptr = NULL;				\
86 		(_u) = NULL;				\
87 	    } else					\
88 		bzero(*undoptr, sizeof(UNDO_DATA));	\
89 	}						\
90 	if (undoptr != NULL)				\
91 	    (_u) = *undoptr;				\
92     }							\
93 } while (/*CONSTCOND*/0)
94 #define undo_finish(_n) do {				\
95     undobefore = undoptr;				\
96     undoptr = (_n);					\
97 } while (/*CONSTCOND*/0)
98 #define	undo_type(_u) ((_u)->u_type & UDMASK)
99 #define undo_bfree(_u) do {				\
100     if ((_u)->u_size) {					\
101 	free((_u)->u_buffer);				\
102 	(_u)->u_size = 0;				\
103     }							\
104 } while (/*CONSTCOND*/0)
105 
106 /* in line.c */
107 int get_lineno   pro((BUFFER*, LINE*));
108