tweaks: transform the token DISABLE_NANORC to ENABLE_NANORC

Also, allow rebinding the word and block jumping functions
in the tiny version when nanorc files are reenabled.
master
Benno Schulenberg 2017-05-08 19:42:44 +02:00
parent a05180ed2d
commit 858e75e4cf
7 changed files with 52 additions and 48 deletions

View File

@ -193,10 +193,17 @@ fi
AC_ARG_ENABLE(nanorc, AC_ARG_ENABLE(nanorc,
AS_HELP_STRING([--disable-nanorc], [Disable the use of .nanorc files])) AS_HELP_STRING([--disable-nanorc], [Disable the use of .nanorc files]))
if test "x$enable_nanorc" = xno; then if test "x$enable_tiny" = xyes; then
AC_DEFINE(DISABLE_NANORC, 1, [Define this to disable the use of .nanorc files.]) if test "x$enable_nanorc" != xyes; then
else enable_nanorc=no
nanorc_support=yes fi
fi
if test "x$disable_nanorc" != xyes; then
if test "x$enable_nanorc" != xno; then
AC_DEFINE(ENABLE_NANORC, 1, [Define this to enable the use of .nanorc files.])
else
nanorc_support=yes
fi
fi fi
AC_ARG_ENABLE(operatingdir, AC_ARG_ENABLE(operatingdir,
@ -283,9 +290,6 @@ if test "x$enable_tiny" = xyes; then
if test "x$enable_libmagic" != xyes; then if test "x$enable_libmagic" != xyes; then
enable_libmagic=no enable_libmagic=no
fi fi
if test "x$enable_nanorc" != xyes; then
AC_DEFINE(DISABLE_NANORC, 1, [Define this to disable the use of .nanorc files.])
fi
if test "x$enable_operatingdir" != xyes; then if test "x$enable_operatingdir" != xyes; then
AC_DEFINE(DISABLE_OPERATINGDIR, 1, [Define this to disable the setting of an operating directory (a chroot of sorts).]) AC_DEFINE(DISABLE_OPERATINGDIR, 1, [Define this to disable the setting of an operating directory (a chroot of sorts).])
fi fi

View File

@ -686,7 +686,7 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer)
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
#if !defined(DISABLE_NANORC) && (!defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)) #if defined(ENABLE_NANORC) && (!defined(NANO_TINY) || !defined(DISABLE_JUSTIFY))
/* Return TRUE if the string s contains one or more blank characters, /* Return TRUE if the string s contains one or more blank characters,
* and FALSE otherwise. */ * and FALSE otherwise. */
bool has_blank_chars(const char *s) bool has_blank_chars(const char *s)
@ -719,7 +719,7 @@ bool has_blank_mbchars(const char *s)
#endif #endif
return has_blank_chars(s); return has_blank_chars(s);
} }
#endif /* !DISABLE_NANORC && (!NANO_TINY || !DISABLE_JUSTIFY) */ #endif /* ENABLE_NANORC && (!NANO_TINY || !DISABLE_JUSTIFY) */
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
/* Return TRUE if wc is valid Unicode, and FALSE otherwise. */ /* Return TRUE if wc is valid Unicode, and FALSE otherwise. */
@ -732,7 +732,7 @@ bool is_valid_unicode(wchar_t wc)
} }
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
/* Check if the string s is a valid multibyte string. Return TRUE if it /* Check if the string s is a valid multibyte string. Return TRUE if it
* is, and FALSE otherwise. */ * is, and FALSE otherwise. */
bool is_valid_mbstring(const char *s) bool is_valid_mbstring(const char *s)
@ -744,4 +744,4 @@ bool is_valid_mbstring(const char *s)
#endif #endif
return TRUE; return TRUE;
} }
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */

View File

@ -1408,7 +1408,7 @@ const char *flagtostr(int flag)
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
/* Interpret a function string given in the rc file, and return a /* Interpret a function string given in the rc file, and return a
* shortcut struct with the corresponding function filled in. */ * shortcut struct with the corresponding function filled in. */
sc *strtosc(const char *input) sc *strtosc(const char *input)
@ -1504,18 +1504,10 @@ sc *strtosc(const char *input)
s->scfunc = do_scroll_up; s->scfunc = do_scroll_up;
else if (!strcasecmp(input, "scrolldown")) else if (!strcasecmp(input, "scrolldown"))
s->scfunc = do_scroll_down; s->scfunc = do_scroll_down;
else if (!strcasecmp(input, "prevword"))
s->scfunc = do_prev_word_void;
else if (!strcasecmp(input, "nextword"))
s->scfunc = do_next_word_void;
else if (!strcasecmp(input, "cutwordleft")) else if (!strcasecmp(input, "cutwordleft"))
s->scfunc = do_cut_prev_word; s->scfunc = do_cut_prev_word;
else if (!strcasecmp(input, "cutwordright")) else if (!strcasecmp(input, "cutwordright"))
s->scfunc = do_cut_next_word; s->scfunc = do_cut_next_word;
else if (!strcasecmp(input, "prevblock"))
s->scfunc = do_prev_block;
else if (!strcasecmp(input, "nextblock"))
s->scfunc = do_next_block;
else if (!strcasecmp(input, "findbracket")) else if (!strcasecmp(input, "findbracket"))
s->scfunc = do_find_bracket; s->scfunc = do_find_bracket;
else if (!strcasecmp(input, "wordcount")) else if (!strcasecmp(input, "wordcount"))
@ -1537,10 +1529,18 @@ sc *strtosc(const char *input)
else if (!strcasecmp(input, "down") || else if (!strcasecmp(input, "down") ||
!strcasecmp(input, "nextline")) !strcasecmp(input, "nextline"))
s->scfunc = do_down_void; s->scfunc = do_down_void;
else if (!strcasecmp(input, "prevword"))
s->scfunc = do_prev_word_void;
else if (!strcasecmp(input, "nextword"))
s->scfunc = do_next_word_void;
else if (!strcasecmp(input, "home")) else if (!strcasecmp(input, "home"))
s->scfunc = do_home_void; s->scfunc = do_home_void;
else if (!strcasecmp(input, "end")) else if (!strcasecmp(input, "end"))
s->scfunc = do_end_void; s->scfunc = do_end_void;
else if (!strcasecmp(input, "prevblock"))
s->scfunc = do_prev_block;
else if (!strcasecmp(input, "nextblock"))
s->scfunc = do_next_block;
else if (!strcasecmp(input, "pageup") || else if (!strcasecmp(input, "pageup") ||
!strcasecmp(input, "prevpage")) !strcasecmp(input, "prevpage"))
s->scfunc = do_page_up; s->scfunc = do_page_up;
@ -1717,7 +1717,7 @@ int strtomenu(const char *input)
#endif #endif
return -1; return -1;
} }
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifdef DEBUG #ifdef DEBUG
@ -1823,7 +1823,7 @@ void thanks_for_all_the_fish(void)
sclist = sclist->next; sclist = sclist->next;
free(s); free(s);
} }
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
free(homedir); free(homedir);
#endif #endif
} }

View File

@ -45,7 +45,7 @@
static int oldinterval = -1; static int oldinterval = -1;
/* Used to store the user's original mouse click interval. */ /* Used to store the user's original mouse click interval. */
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
static bool no_rcfiles = FALSE; static bool no_rcfiles = FALSE;
/* Should we ignore all rcfiles? */ /* Should we ignore all rcfiles? */
#endif #endif
@ -804,7 +804,7 @@ void usage(void)
print_opt("-H", "--historylog", print_opt("-H", "--historylog",
N_("Log & read search/replace string history")); N_("Log & read search/replace string history"));
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
if (!ISSET(RESTRICTED)) if (!ISSET(RESTRICTED))
print_opt("-I", "--ignorercfiles", N_("Don't look at nanorc files")); print_opt("-I", "--ignorercfiles", N_("Don't look at nanorc files"));
#endif #endif
@ -869,7 +869,7 @@ void usage(void)
N_("Set operating directory")); N_("Set operating directory"));
#endif #endif
print_opt("-p", "--preserve", N_("Preserve XON (^Q) and XOFF (^S) keys")); print_opt("-p", "--preserve", N_("Preserve XON (^Q) and XOFF (^S) keys"));
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
if (!ISSET(RESTRICTED)) if (!ISSET(RESTRICTED))
print_opt("-q", "--quiet", print_opt("-q", "--quiet",
N_("Silently ignore startup issues like rc file errors")); N_("Silently ignore startup issues like rc file errors"));
@ -943,7 +943,7 @@ void version(void)
#ifdef ENABLE_MOUSE #ifdef ENABLE_MOUSE
printf(" --enable-mouse"); printf(" --enable-mouse");
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
printf(" --enable-nanorc"); printf(" --enable-nanorc");
#endif #endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
@ -995,7 +995,7 @@ void version(void)
#ifndef ENABLE_MULTIBUFFER #ifndef ENABLE_MULTIBUFFER
printf(" --disable-multibuffer"); printf(" --disable-multibuffer");
#endif #endif
#ifdef DISABLE_NANORC #ifndef ENABLE_NANORC
printf(" --disable-nanorc"); printf(" --disable-nanorc");
#endif #endif
#ifdef DISABLE_OPERATINGDIR #ifdef DISABLE_OPERATINGDIR
@ -1917,7 +1917,7 @@ int main(int argc, char **argv)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
{"multibuffer", 0, NULL, 'F'}, {"multibuffer", 0, NULL, 'F'},
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
{"ignorercfiles", 0, NULL, 'I'}, {"ignorercfiles", 0, NULL, 'I'},
#endif #endif
{"rebindkeypad", 0, NULL, 'K'}, {"rebindkeypad", 0, NULL, 'K'},
@ -2013,7 +2013,7 @@ int main(int argc, char **argv)
" -- please report a bug\n", (int)MB_CUR_MAX); " -- please report a bug\n", (int)MB_CUR_MAX);
#endif #endif
#if defined(DISABLE_NANORC) && defined(DISABLE_ROOTWRAPPING) #if !defined(ENABLE_NANORC) && defined(DISABLE_ROOTWRAPPING)
/* If we don't have rcfile support, --disable-wrapping-as-root is /* If we don't have rcfile support, --disable-wrapping-as-root is
* used, and we're root, turn wrapping off. */ * used, and we're root, turn wrapping off. */
if (geteuid() == NANO_ROOT_UID) if (geteuid() == NANO_ROOT_UID)
@ -2070,7 +2070,7 @@ int main(int argc, char **argv)
SET(HISTORYLOG); SET(HISTORYLOG);
break; break;
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
case 'I': case 'I':
no_rcfiles = TRUE; no_rcfiles = TRUE;
break; break;
@ -2166,7 +2166,7 @@ int main(int argc, char **argv)
case 'p': case 'p':
SET(PRESERVE); SET(PRESERVE);
break; break;
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
case 'q': case 'q':
SET(QUIET); SET(QUIET);
break; break;
@ -2239,7 +2239,7 @@ int main(int argc, char **argv)
if (ISSET(RESTRICTED)) { if (ISSET(RESTRICTED)) {
UNSET(SUSPEND); UNSET(SUSPEND);
UNSET(BACKUP_FILE); UNSET(BACKUP_FILE);
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
no_rcfiles = TRUE; no_rcfiles = TRUE;
UNSET(HISTORYLOG); UNSET(HISTORYLOG);
UNSET(POS_HISTORY); UNSET(POS_HISTORY);
@ -2250,11 +2250,9 @@ int main(int argc, char **argv)
* before reading the rcfile, to be able to rebind/unbind keys. */ * before reading the rcfile, to be able to rebind/unbind keys. */
shortcut_init(); shortcut_init();
/* We've read through the command line options. Now back up the flags #ifdef ENABLE_NANORC
* and values that are set, and read the rcfile(s). If the values
* haven't changed afterward, restore the backed-up values. */
#ifndef DISABLE_NANORC
if (!no_rcfiles) { if (!no_rcfiles) {
/* Back up the command-line options, then read the rcfile(s). */
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
char *operating_dir_cpy = operating_dir; char *operating_dir_cpy = operating_dir;
#endif #endif
@ -2298,6 +2296,7 @@ int main(int argc, char **argv)
print_sclist(); print_sclist();
#endif #endif
/* If the backed-up command-line options have a value, restore them. */
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
if (operating_dir_cpy != NULL) { if (operating_dir_cpy != NULL) {
free(operating_dir); free(operating_dir);
@ -2333,6 +2332,7 @@ int main(int argc, char **argv)
if (tabsize_cpy != -1) if (tabsize_cpy != -1)
tabsize = tabsize_cpy; tabsize = tabsize_cpy;
/* Simply OR the boolean flags from rcfile and command line. */
for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++)
flags[i] |= flags_cpy[i]; flags[i] |= flags_cpy[i];
} }
@ -2342,7 +2342,7 @@ int main(int argc, char **argv)
else if (geteuid() == NANO_ROOT_UID) else if (geteuid() == NANO_ROOT_UID)
SET(NO_WRAP); SET(NO_WRAP);
#endif #endif
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
/* Override a "set nowrap" in an rcfile (or a --disable-wrapping-as-root) /* Override a "set nowrap" in an rcfile (or a --disable-wrapping-as-root)

View File

@ -404,7 +404,7 @@ typedef struct openfilestruct {
/* The preceding open file, if any. */ /* The preceding open file, if any. */
} openfilestruct; } openfilestruct;
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
typedef struct rcoption { typedef struct rcoption {
const char *name; const char *name;
/* The name of the rcfile option. */ /* The name of the rcfile option. */

View File

@ -225,13 +225,13 @@ char *mbstrpbrk(const char *s, const char *accept);
char *revstrpbrk(const char *head, const char *accept, const char *index); char *revstrpbrk(const char *head, const char *accept, const char *index);
char *mbrevstrpbrk(const char *head, const char *accept, const char *index); char *mbrevstrpbrk(const char *head, const char *accept, const char *index);
#endif #endif
#if !defined(DISABLE_NANORC) && (!defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)) #if defined(ENABLE_NANORC) && (!defined(NANO_TINY) || !defined(DISABLE_JUSTIFY))
bool has_blank_mbchars(const char *s); bool has_blank_mbchars(const char *s);
#endif #endif
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
bool is_valid_unicode(wchar_t wc); bool is_valid_unicode(wchar_t wc);
#endif #endif
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
bool is_valid_mbstring(const char *s); bool is_valid_mbstring(const char *s);
#endif #endif
@ -466,14 +466,14 @@ int do_prompt(bool allow_tabs, bool allow_files,
int do_yesno_prompt(bool all, const char *msg); int do_yesno_prompt(bool all, const char *msg);
/* Most functions in rcfile.c. */ /* Most functions in rcfile.c. */
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright); bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright);
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage); void grab_and_store(const char *kind, char *ptr, regexlisttype **storage);
#endif #endif
void parse_rcfile(FILE *rcstream, bool syntax_only); void parse_rcfile(FILE *rcstream, bool syntax_only);
void do_rcfiles(void); void do_rcfiles(void);
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */
/* Most functions in search.c. */ /* Most functions in search.c. */
void not_found_msg(const char *str); void not_found_msg(const char *str);

View File

@ -30,7 +30,7 @@
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
#ifndef RCFILE_NAME #ifndef RCFILE_NAME
#define RCFILE_NAME ".nanorc" #define RCFILE_NAME ".nanorc"
@ -159,9 +159,9 @@ void rcfile_error(const char *msg, ...)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */
#if !defined(DISABLE_NANORC) || !defined(DISABLE_HISTORIES) #if defined(ENABLE_NANORC) || !defined(DISABLE_HISTORIES)
/* Parse the next word from the string, null-terminate it, and return /* Parse the next word from the string, null-terminate it, and return
* a pointer to the first character after the null terminator. The * a pointer to the first character after the null terminator. The
* returned pointer will point to '\0' if we hit the end of the line. */ * returned pointer will point to '\0' if we hit the end of the line. */
@ -181,9 +181,9 @@ char *parse_next_word(char *ptr)
return ptr; return ptr;
} }
#endif /* !DISABLE_NANORC || !DISABLE_HISTORIES */ #endif /* ENABLE_NANORC || !DISABLE_HISTORIES */
#ifndef DISABLE_NANORC #ifdef ENABLE_NANORC
/* Parse an argument, with optional quotes, after a keyword that takes /* Parse an argument, with optional quotes, after a keyword that takes
* one. If the next word starts with a ", we say that it ends with the * one. If the next word starts with a ", we say that it ends with the
* last " of the line. Otherwise, we interpret it as usual, so that the * last " of the line. Otherwise, we interpret it as usual, so that the
@ -1300,4 +1300,4 @@ void do_rcfiles(void)
} }
} }
#endif /* !DISABLE_NANORC */ #endif /* ENABLE_NANORC */