4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "stringfile.inc"
31 #define UNDOLEVELS 500
32 #define UNDO_KEY_INTERVAL 100
36 #define hash_sz (1<<hash_sz2)
37 #define hash_sz1 (hash_sz-1)
44 UndoHash(char *txt, int len, UndoHash *nxt);
49 int line[2], occurs[2];
57 UndoHash *add(char *txt, int len);
59 UndoHash *table[hash_sz];
66 UndoLine(UndoHash *hash, char *tp);
67 UndoLine(UndoHashTable *hash, char *txt, int len);
75 class UndoVersion : public ArrayList<UndoLine *>
78 UndoVersion(int v) { ver = v; }
79 ~UndoVersion() { remove_all_objects(); }
82 void scan_lines(UndoHashTable *hash, char *sp, char *ep);
86 class UndoStackItem : public ListItem<UndoStackItem>
92 // Must be inserted into the list before calling this, so it can get the
93 // previous key buffer.
94 void set_data(char *data);
95 void set_description(char *description);
96 void set_filename(char *filename);
97 const char* get_description();
98 void set_flags(uint64_t flags);
100 // Decompress the buffers and return them in a newly allocated string.
101 // The string must be deleted by the user.
103 char* get_filename();
106 uint64_t get_flags();
108 void set_creator(void *creator);
114 // command description for the menu item
117 // key undo buffer or incremental undo buffer
120 // type of modification
123 // data after the modification for redos
127 // pointer to the object which set this undo buffer
130 char *session_filename;
133 class UndoStack : public List<UndoStackItem>
139 // get current undo/redo stack item
140 UndoStackItem *get_current_undo();
141 UndoStackItem *get_current_redo();
143 // Create a new undo entry and put on the stack.
144 // The current pointer points to the new entry.
145 // delete future undos if in the middle
146 // delete undos older than UNDOLEVELS if last
147 UndoStackItem* push();
149 // move to the next undo entry for a redo
150 UndoStackItem* pull_next();
154 void dump(FILE *fp=stdout);
156 UndoStackItem* current;