From: Chris Allegretta Date: Fri, 14 Aug 2009 03:18:29 +0000 (+0000) Subject: 2009-08-13 Chris Allegretta X-Git-Tag: v2.1.11~11 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=a48507d32a9c1a96b8390de8a25c1c537d5a914d;p=nano.git 2009-08-13 Chris Allegretta * New global flag implementation courtesy of Adam Wysocki , allows previous undo flag to be implemented consistent with other flags. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4400 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 857b98af..397b7f13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ +2009-08-13 Chris Allegretta + * New global flag implementation courtesy of Adam Wysocki , allows + previous undo flag to be implemented consistent with other flags. + GNU nano 2.1.10 - 2009.07.28 + 2009-07-27 Chris Allegretta * text.c (undo_cut, redo_cut): Don't actually try and undo/redo an empty cut, i.e. the magicline. Fixes crash on cutting last line discovered by Eitan Adler . diff --git a/src/global.c b/src/global.c index 69a4ea78..f6826d7f 100644 --- a/src/global.c +++ b/src/global.c @@ -36,9 +36,6 @@ sigjmp_buf jump_buf; bool jump_buf_main = FALSE; /* Have we set jump_buf so that we return to main() after a * SIGWINCH? */ -bool use_undo = FALSE; - /* Are we actually using the undo code - disabled by default - as the undo code is too unstable */ #endif #ifndef DISABLE_WRAPJUSTIFY @@ -55,7 +52,7 @@ char *last_search = NULL; char *last_replace = NULL; /* The last replacement string we searched for. */ -long flags = 0; +unsigned flags[4] = {0, 0, 0, 0}; /* Our flag containing the states of all global options. */ WINDOW *topwin; /* The top portion of the window, where we display the version @@ -781,7 +778,7 @@ void shortcut_init(bool unjustify) add_to_funcs(DO_UNINDENT, MMAIN, N_("Unindent Text"), IFSCHELP(nano_unindent_msg), FALSE, NOVIEW); - if (use_undo) { + if (ISSET(UNDOABLE)) { add_to_funcs(DO_UNDO, MMAIN, N_("Undo"), IFSCHELP(nano_undo_msg), FALSE, NOVIEW); @@ -1069,7 +1066,7 @@ void shortcut_init(bool unjustify) add_to_sclist(MMAIN, "M-6", DO_COPY_TEXT, 0, TRUE); add_to_sclist(MMAIN, "M-}", DO_INDENT_VOID, 0, TRUE); add_to_sclist(MMAIN, "M-{", DO_UNINDENT, 0, TRUE); - if (use_undo) { + if (ISSET(UNDOABLE)) { add_to_sclist(MMAIN, "M-U", DO_UNDO, 0, TRUE); add_to_sclist(MMAIN, "M-E", DO_REDO, 0, TRUE); } diff --git a/src/nano.c b/src/nano.c index 8e7846c6..7ef21b17 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2213,7 +2213,7 @@ int main(int argc, char **argv) break; #ifndef NANO_TINY case 'u': - use_undo = TRUE; + SET(UNDOABLE); break; #endif case 'v': @@ -2277,7 +2277,10 @@ int main(int argc, char **argv) char *alt_speller_cpy = alt_speller; #endif ssize_t tabsize_cpy = tabsize; - long flags_cpy = flags; + unsigned flags_cpy[sizeof(flags) / sizeof(flags[0])]; + size_t i; + + memcpy(flags_cpy, flags, sizeof(flags_cpy)); #ifndef DISABLE_OPERATINGDIR operating_dir = NULL; @@ -2329,7 +2332,9 @@ int main(int argc, char **argv) #endif if (tabsize_cpy != -1) tabsize = tabsize_cpy; - flags |= flags_cpy; + + for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) + flags[i] |= flags_cpy[i]; } #ifdef DISABLE_ROOTWRAPPING /* If we don't have any rcfiles, --disable-wrapping-as-root is used, diff --git a/src/nano.h b/src/nano.h index 1eb2a1fc..9400fe05 100644 --- a/src/nano.h +++ b/src/nano.h @@ -55,10 +55,13 @@ #endif /* Macros for flags. */ -#define SET(bit) flags |= bit -#define UNSET(bit) flags &= ~bit -#define ISSET(bit) ((flags & bit) != 0) -#define TOGGLE(bit) flags ^= bit +#define FLAGOFF(flag) ((flag) / (sizeof(unsigned) * 8)) +#define FLAGMASK(flag) (1 << ((flag) % (sizeof(unsigned) * 8))) +#define FLAGS(flag) flags[FLAGOFF(flag)] +#define SET(flag) FLAGS(flag) |= FLAGMASK(flag) +#define UNSET(flag) FLAGS(flag) &= ~FLAGMASK(flag) +#define ISSET(flag) ((FLAGS(flag) & FLAGMASK(flag)) != 0) +#define TOGGLE(flag) FLAGS(flag) ^= FLAGMASK(flag) /* Macros for character allocation and more. */ #define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char)) @@ -450,40 +453,44 @@ typedef struct subnfunc { } subnfunc; -/* Bitwise flags so that we can save space (or, more correctly, not - * waste it). */ -#define CASE_SENSITIVE (1<<0) -#define CONST_UPDATE (1<<1) -#define NO_HELP (1<<2) -#define NOFOLLOW_SYMLINKS (1<<3) -#define SUSPEND (1<<4) -#define NO_WRAP (1<<5) -#define AUTOINDENT (1<<6) -#define VIEW_MODE (1<<7) -#define USE_MOUSE (1<<8) -#define USE_REGEXP (1<<9) -#define TEMP_FILE (1<<10) -#define CUT_TO_END (1<<11) -#define BACKWARDS_SEARCH (1<<12) -#define MULTIBUFFER (1<<13) -#define SMOOTH_SCROLL (1<<14) -#define REBIND_DELETE (1<<15) -#define REBIND_KEYPAD (1<<16) -#define NO_CONVERT (1<<17) -#define BACKUP_FILE (1<<18) -#define NO_COLOR_SYNTAX (1<<19) -#define PRESERVE (1<<20) -#define HISTORYLOG (1<<21) -#define RESTRICTED (1<<22) -#define SMART_HOME (1<<23) -#define WHITESPACE_DISPLAY (1<<24) -#define MORE_SPACE (1<<25) -#define TABS_TO_SPACES (1<<26) -#define QUICK_BLANK (1<<27) -#define WORD_BOUNDS (1<<28) -#define NO_NEWLINES (1<<29) -#define BOLD_TEXT (1<<30) -#define QUIET (1<<31) +/* Enumeration to be used in flags table. See FLAGBIT and FLAGOFF + * definitions. */ +enum +{ + CASE_SENSITIVE, + CONST_UPDATE, + NO_HELP, + NOFOLLOW_SYMLINKS, + SUSPEND, + NO_WRAP, + AUTOINDENT, + VIEW_MODE, + USE_MOUSE, + USE_REGEXP, + TEMP_FILE, + CUT_TO_END, + BACKWARDS_SEARCH, + MULTIBUFFER, + SMOOTH_SCROLL, + REBIND_DELETE, + REBIND_KEYPAD, + NO_CONVERT, + BACKUP_FILE, + NO_COLOR_SYNTAX, + PRESERVE, + HISTORYLOG, + RESTRICTED, + SMART_HOME, + WHITESPACE_DISPLAY, + MORE_SPACE, + TABS_TO_SPACES, + QUICK_BLANK, + WORD_BOUNDS, + NO_NEWLINES, + BOLD_TEXT, + QUIET, + UNDOABLE, +}; /* Flags for which menus in which a given function should be present */ #define MMAIN (1<<0) diff --git a/src/proto.h b/src/proto.h index 700a5ceb..3e83f1ba 100644 --- a/src/proto.h +++ b/src/proto.h @@ -41,7 +41,7 @@ extern ssize_t wrap_at; extern char *last_search; extern char *last_replace; -extern long flags; +extern unsigned flags[4]; extern WINDOW *topwin; extern WINDOW *edit; extern WINDOW *bottomwin; diff --git a/src/rcfile.c b/src/rcfile.c index 565632fe..60a9f3dd 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -909,15 +909,6 @@ void parse_rcfile(FILE *rcstream option = ptr; ptr = parse_next_word(ptr); -#ifndef NANO_TINY - /* FIXME: Hack which should go away ASAP */ - if (strcasecmp(option, "undo") == 0) { - use_undo = TRUE; - shortcut_init(0); - continue; - } -#endif - for (i = 0; rcopts[i].name != NULL; i++) { if (strcasecmp(option, rcopts[i].name) == 0) { #ifdef DEBUG diff --git a/src/text.c b/src/text.c index a225eaa1..a3683f40 100644 --- a/src/text.c +++ b/src/text.c @@ -837,7 +837,7 @@ void add_undo(undo_type current_action) static undo *last_cutu = NULL; /* Last thing we cut to set up the undo for uncut */ ssize_t wrap_loc; /* For calculating split beginning */ - if (!use_undo) + if (!ISSET(UNDOABLE)) return; /* Ugh, if we were called while cutting not-to-end, non-marked and on the same lineno, @@ -962,7 +962,7 @@ void update_undo(undo_type action) int len = 0; openfilestruct *fs = openfile; - if (!use_undo) + if (!ISSET(UNDOABLE)) return; #ifdef DEBUG