1 /**********************************************************
3 ** $VER: UndoRedo.h 1.2 (3.2.2001) **
4 ** Datatypes for journalized buffer **
6 ** © T.Pierron, C.Guilaume. Free software under **
7 ** terms of GNU public license. **
9 **********************************************************/
18 /* Size of one chunk of undo/redo buf (must be a power of 2) */
21 /** Structure holding modifications data (operations) **/
25 UWORD size
; /* Nb. of bytes in the array data */
26 UBYTE data
[ UNDO_CHUNK
]; /* Buffer for operation data */
29 /** Rollback segment (text) **/
32 struct _RBSeg
*prev
, *next
;
33 ULONG max
; /* Max data in data array */
34 UBYTE data
[1]; /* Removed characters */
37 /** Internal values per Project **/
38 typedef struct _JBuf
/* Journalized buffer */
40 LINE
*line
; /* Last line modified */
41 ULONG nbc
; /* Last character modified */
42 RBOps ops
; /* Stack of operations */
43 RBSeg rbseg
; /* Rollback segment */
44 ULONG size
; /* Nb. of bytes in modif buffer */
45 ULONG rbsz
; /* Nb. of bytes in rollback segment */
46 UBYTE op
; /* Type of last operation */
47 UBYTE rbtype
; /* 0:undo 1:redo */
48 APTR prj
; /* Link to project struct */
51 typedef JBUF
* JBuf
; /* Main type pointer */
53 /** Get Project struct **/
54 #define PRJ(jbuf) ((Project)jbuf->prj)
56 /** Operations journalized **/
57 #define ADD_CHAR 1 /* Add chars on a new line */
58 #define REM_CHAR 2 /* Remove chars */
59 #define REM_LINE 3 /* Remove whole content of a line */
60 #define JOIN_LINE 4 /* Line joined */
61 #define GROUP_BY 5 /* Group of operation */
63 #define LAST_TYPE(x) ((STRPTR)(x))[-1]
64 #define IS_COMMIT(x) ((STRPTR)(x))[-2]
65 #define OUT_OF_DATE ((STRPTR)-1)
66 #define NO_MEANING_VAL ((STRPTR)-2)
68 /** Datatypes specific to an operation (must be WORD aligned) **/
69 typedef struct _AddChar
71 LINE
*line
; /* Line where operation occured */
72 UWORD pos
; /* Position in this line */
73 UWORD nbc
; /* Nb. of char inserted */
75 UWORD pad
; /* to get multiple-of-4 structure sizeof */
77 UBYTE commit
; /* Savepoint */
78 UBYTE type
; /* ADD_CHAR */
81 /** Yes, no meaning changes, except type == REM_CHAR **/
82 typedef struct _AddChar
*RemChar
;
84 typedef struct _RemLine
86 LINE
*line
; /* Line removed */
87 LINE
*after
; /* Insert the line after this one */
89 UWORD pad
; /* to get multiple-of-4 structure sizeof */
91 UBYTE commit
; /* Savepoint */
92 UBYTE type
; /* REM_LINE */
95 typedef struct _JoinLine
97 LINE
*line
; /* First line concerned */
98 LINE
*old
; /* Old line removed */
99 ULONG pos
; /* Joined position */
101 UWORD pad
; /* to get multiple-of-4 structure sizeof */
103 UBYTE commit
; /* Savepoint */
104 UBYTE type
; /* JOIN_LINE */
107 typedef struct _GroupBy
/* Gather multiple operations */
110 UWORD pad
; /* to get multiple-of-4 structure sizeof */
112 UBYTE commit
; /* Savepoint */
113 UBYTE type
; /* GROUP_BY */
116 void flush_undo_buf ( JBuf
);
117 void rollback ( JBuf
);
118 void last_modif ( JBuf
, char );
120 void commit_work ( Project
);
123 STRPTR
pop_last_op ( JBuf
, char, char ); /* Update JBuf values */
125 void reg_add_chars ( JBuf
, LINE
*, ULONG pos
, UWORD nb
);
126 void reg_rem_chars ( JBuf
, LINE
*, ULONG s
, ULONG e
);
127 void reg_join_lines ( JBuf
, LINE
*, LINE
* );
128 void reg_rem_line ( JBuf
, LINE
* );
129 void reg_group_by ( JBuf
);