undo.c (157184) | undo.c (165670) |
---|---|
1/* readline.c -- a general facility for reading lines of input 2 with emacs style editing and completion. */ 3 | 1/* readline.c -- a general facility for reading lines of input 2 with emacs style editing and completion. */ 3 |
4/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. | 4/* Copyright (C) 1987, 1989, 1992, 2006 Free Software Foundation, Inc. |
5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2, or 12 (at your option) any later version. --- 32 unchanged lines hidden (view full) --- 45 46/* Some standard library routines. */ 47#include "readline.h" 48#include "history.h" 49 50#include "rlprivate.h" 51#include "xmalloc.h" 52 | 5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2, or 12 (at your option) any later version. --- 32 unchanged lines hidden (view full) --- 45 46/* Some standard library routines. */ 47#include "readline.h" 48#include "history.h" 49 50#include "rlprivate.h" 51#include "xmalloc.h" 52 |
53extern void replace_history_data PARAMS((int, histdata_t *, histdata_t *)); 54 |
|
53/* Non-zero tells rl_delete_text and rl_insert_text to not add to 54 the undo list. */ 55int _rl_doing_an_undo = 0; 56 57/* How many unclosed undo groups we currently have. */ 58int _rl_undo_group_level = 0; 59 60/* The current undo list for THE_LINE. */ 61UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL; 62 63/* **************************************************************** */ 64/* */ 65/* Undo, and Undoing */ 66/* */ 67/* **************************************************************** */ 68 | 55/* Non-zero tells rl_delete_text and rl_insert_text to not add to 56 the undo list. */ 57int _rl_doing_an_undo = 0; 58 59/* How many unclosed undo groups we currently have. */ 60int _rl_undo_group_level = 0; 61 62/* The current undo list for THE_LINE. */ 63UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL; 64 65/* **************************************************************** */ 66/* */ 67/* Undo, and Undoing */ 68/* */ 69/* **************************************************************** */ 70 |
69/* Remember how to undo something. Concatenate some undos if that 70 seems right. */ 71void 72rl_add_undo (what, start, end, text) | 71static UNDO_LIST * 72alloc_undo_entry (what, start, end, text) |
73 enum undo_code what; 74 int start, end; 75 char *text; 76{ | 73 enum undo_code what; 74 int start, end; 75 char *text; 76{ |
77 UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST)); | 77 UNDO_LIST *temp; 78 79 temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST)); |
78 temp->what = what; 79 temp->start = start; 80 temp->end = end; 81 temp->text = text; | 80 temp->what = what; 81 temp->start = start; 82 temp->end = end; 83 temp->text = text; |
84 85 temp->next = (UNDO_LIST *)NULL; 86 return temp; 87} 88 89/* Remember how to undo something. Concatenate some undos if that 90 seems right. */ 91void 92rl_add_undo (what, start, end, text) 93 enum undo_code what; 94 int start, end; 95 char *text; 96{ 97 UNDO_LIST *temp; 98 99 temp = alloc_undo_entry (what, start, end, text); |
|
82 temp->next = rl_undo_list; 83 rl_undo_list = temp; 84} 85 86/* Free the existing undo list. */ 87void 88rl_free_undo_list () 89{ | 100 temp->next = rl_undo_list; 101 rl_undo_list = temp; 102} 103 104/* Free the existing undo list. */ 105void 106rl_free_undo_list () 107{ |
108 UNDO_LIST *release, *orig_list; 109 110 orig_list = rl_undo_list; |
|
90 while (rl_undo_list) 91 { | 111 while (rl_undo_list) 112 { |
92 UNDO_LIST *release = rl_undo_list; | 113 release = rl_undo_list; |
93 rl_undo_list = rl_undo_list->next; 94 95 if (release->what == UNDO_DELETE) 96 free (release->text); 97 98 free (release); 99 } 100 rl_undo_list = (UNDO_LIST *)NULL; | 114 rl_undo_list = rl_undo_list->next; 115 116 if (release->what == UNDO_DELETE) 117 free (release->text); 118 119 free (release); 120 } 121 rl_undo_list = (UNDO_LIST *)NULL; |
122 replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL); |
|
101} 102 | 123} 124 |
125UNDO_LIST * 126_rl_copy_undo_entry (entry) 127 UNDO_LIST *entry; 128{ 129 UNDO_LIST *new; 130 131 new = alloc_undo_entry (entry->what, entry->start, entry->end, (char *)NULL); 132 new->text = entry->text ? savestring (entry->text) : 0; 133 return new; 134} 135 136UNDO_LIST * 137_rl_copy_undo_list (head) 138 UNDO_LIST *head; 139{ 140 UNDO_LIST *list, *new, *roving, *c; 141 142 list = head; 143 new = 0; 144 while (list) 145 { 146 c = _rl_copy_undo_entry (list); 147 if (new == 0) 148 roving = new = c; 149 else 150 { 151 roving->next = c; 152 roving = roving->next; 153 } 154 list = list->next; 155 } 156 157 roving->next = 0; 158 return new; 159} 160 |
|
103/* Undo the next thing in the list. Return 0 if there 104 is nothing to undo, or non-zero if there was. */ 105int 106rl_do_undo () 107{ 108 UNDO_LIST *release; 109 int waiting_for_begin, start, end; 110 --- 45 unchanged lines hidden (view full) --- 156 break; 157 } 158 159 _rl_doing_an_undo = 0; 160 RL_UNSETSTATE(RL_STATE_UNDOING); 161 162 release = rl_undo_list; 163 rl_undo_list = rl_undo_list->next; | 161/* Undo the next thing in the list. Return 0 if there 162 is nothing to undo, or non-zero if there was. */ 163int 164rl_do_undo () 165{ 166 UNDO_LIST *release; 167 int waiting_for_begin, start, end; 168 --- 45 unchanged lines hidden (view full) --- 214 break; 215 } 216 217 _rl_doing_an_undo = 0; 218 RL_UNSETSTATE(RL_STATE_UNDOING); 219 220 release = rl_undo_list; 221 rl_undo_list = rl_undo_list->next; |
222 replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list); 223 |
|
164 free (release); 165 } 166 while (waiting_for_begin); 167 168 return (1); 169} 170#undef TRANS 171 --- 97 unchanged lines hidden --- | 224 free (release); 225 } 226 while (waiting_for_begin); 227 228 return (1); 229} 230#undef TRANS 231 --- 97 unchanged lines hidden --- |