From: Chris Allegretta Date: Tue, 11 Mar 2003 03:50:40 +0000 (+0000) Subject: DLR's cumulative patch, one minor configure.ac tweak X-Git-Tag: v1.2.1~8 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=d845193a1d1fa4c92b4d3e614559cce92c1f4337;p=nano.git DLR's cumulative patch, one minor configure.ac tweak git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1484 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 42df882b..8657a369 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,34 @@ CVS code - - General: - Translation updates (see po/ChangeLog for details). + - Work around broken regexec() on some systems that segfaults + when passed an empty string. New function regexec_safe(). + (David Benbennick) + - Fix various bugs with search string history logging: don't + print a broken error message and freeze if ~/.nano_history is + unreadable, actually show an error message in save_history() + if ~/.nano_history is unwritable, and prevent ~/.nano_history + from being completely overwritten by save_history() if it's + unreadable but writable. (David Benbennick) +- global.c: + shortcut_init() + - Simplify the #ifdef used to enable file insertion in view mode + if multibuffer support has been compiled in. (DLR) +- nano.c: + justify_format() + - If we shave spaces off the end of the line, make sure totsize + is properly updated. (DLR; much simplified by David + Benbennick) +- nano.h: + - Simplify #ifdefs relating to HAVE_STRCASECMP and + HAVE_STRNCASECMP. (David Benbennick) +- configure.ac: + - Enable autodetection of broken regexec(). (DLR) Re-added + regex.h check to ensure compile under Debian w/autoconf 1.6. +- TODO: + - Fix typo. (David Benbennick) +- faq.html: + - Update RPM links for nano 1.2.x. (DLR) GNU nano 1.2.0 - 2003.02.19 - General: @@ -32,31 +60,32 @@ GNU nano 1.1.99pre3 - 2003.02.13 nano.c:global_init(), window_init(), and handle_sigwinch(). New macro MIN_EDITOR_COLS replaces MIN_FILL_LENGTH (David Benbennick). - - Change ngettext macro to P_(), to avoid a clash with the reserved C - __ identifier (Jordi). + - Change ngettext macro to P_(), to avoid a clash with the + reserved C __ identifier (Jordi). - Memory leak fixes for files.c:do_insertfile(),do_browser(), - nano.c:do_spell(), and search.c:do_replace() (David Benbennick). + nano.c:do_spell(), and search.c:do_replace() (David + Benbennick). - Remove do_preserve_msg, as using -p still gives Pico-style string behavior, so an annoying message every invocation is probably unneeded (all cheer). - - Change resetpos function to be global (now called + - Change resetpos function to be global (now called resetstatuspos. Fixes annoying but small odd problem with - cursor placement when inserting a file. This needs to be done - better in 1.3 (originally by David Lawrence Ramsey). - Added this issue to TODO. + cursor placement when inserting a file. This needs to be done + better in 1.3 (originally by David Lawrence Ramsey). Added + this issue to TODO. - files.c: cwd_tab_completion() - Memory leak fix (David Benbennick). intput_tab() - - Fix assumption that matches is null terminated (David + - Fix assumption that matches is null terminated (David Benbennick). load_history() - - Fix segfault on loading huge strings from history file + - Fix segfault on loading huge strings from history file (David Benbennick). load_history(), save_history() - Changed to look at $HOME before getpwuid(geteuid()), see details in comment for rcfile.c:do_rcfile(). - real_dir_from_tidle() + real_dir_from_tilde() - Change check for the running user's home dir to use getpwuid(geteuid()) rather than a getpwent() loop (suggested by Jordi). @@ -69,7 +98,7 @@ GNU nano 1.1.99pre3 - 2003.02.13 nano.c:line_len(). (David Benbennick). do_justify() - Add regfree() to quote regex (David Benbennick). - - Only copy previous indent if AUTOINDENT is set (David + - Only copy previous indent if AUTOINDENT is set (David Benbennick). do_suspend() - Fix untranslated message (David Benbennick). diff --git a/TODO b/TODO index f7108053..4ce0a2fc 100644 --- a/TODO +++ b/TODO @@ -19,7 +19,7 @@ For version 1.4: - UTF-8 support. - Support for Pico's paragraph searching ability. - Undo/Redo key? -- Remindable keys? +- Rebindable keys? - Keystroke to implement "Add next sequence as raw" like vi's ^V. - Spell check selected text only. - Make "To line" (^W^T) and "Read from Command" (^R^X) re-enter their diff --git a/configure.ac b/configure.ac index 2788c31d..b5c650e0 100644 --- a/configure.ac +++ b/configure.ac @@ -38,12 +38,22 @@ AM_GNU_GETTEXT([external], [need-ngettext]) dnl Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h getopt.h libintl.h limits.h regex.h termio.h termios.h unistd.h) +AC_CHECK_HEADER(regex.h, + AC_MSG_CHECKING([for broken regexec]) + AC_TRY_RUN([ +#include +#include +int main() { regex_t reg; size_t n; regmatch_t r; regcomp(®, ".", 0); regexec(®, "", n, &r, 0); return 0; }], + AC_MSG_RESULT(no), + AC_MSG_RESULT(yes); AC_DEFINE(BROKEN_REGEXEC, 1, [Define this if your regexec() function segfaults when passed an empty string.]) + ) +) dnl options AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging (disabled by default)], [if test x$enableval = xyes; then - AC_DEFINE(DEBUG, 1, [Define this to enable nano debug messages and assert warnings.]) + AC_DEFINE(DEBUG, 1, [Define this to enable nano debug messages and assert warnings.]) debug_support=yes fi]) @@ -125,7 +135,6 @@ AC_ARG_ENABLE(wrapping-as-root, AC_DEFINE(DISABLE_ROOTWRAP, 1, [Define this to disable wrapping as root by default.]) fi]) - AC_ARG_ENABLE(color, [ --enable-color Enable color and syntax highlighting], [if test x$enableval = xyes; then diff --git a/faq.html b/faq.html index a0c6e324..39688803 100644 --- a/faq.html +++ b/faq.html @@ -93,8 +93,8 @@

2.2. RedHat and derivatives (.rpm) packages.

Additionally, check out the RedHat contribs section at:

    @@ -233,6 +233,7 @@

    8. ChangeLog

    +2003/02/23 - Updated RPM links for nano 1.2.x. (DLR).
    2003/01/16 - Split section 4.5 into 4.5a and 4.5b for search string behavior. Added --enable-all docs.
    2002/12/28 - More misc. fixes (David Benbennick, DLR).
    2002/10/25 - Misc. fixes and link updates (DLR).
    diff --git a/files.c b/files.c index 12ae08ce..db825008 100644 --- a/files.c +++ b/files.c @@ -1898,8 +1898,8 @@ char *real_dir_from_tilde(const char *buf) for (i = 1; buf[i] != '/' && buf[i] != '\0'; i++) ; - /* Determine home directory using getpwent(), don't rely on - $HOME */ + /* Determine home directory using getpwuid() or getpwent(), + don't rely on $HOME */ if (i == 1) userdata = getpwuid(geteuid()); else { @@ -2892,8 +2892,11 @@ void load_history(void) if (homenv != NULL || userage != NULL) { hist = fopen(nanohist, "r"); if (!hist) { - if (errno != ENOENT) + if (errno != ENOENT) { + /* Don't save history when we quit. */ + UNSET(HISTORYLOG); rcfile_error(_("Unable to open ~/.nano_history file, %s"), strerror(errno)); + } free(nanohist); } else { buf = charalloc(1024); diff --git a/global.c b/global.c index 3850a613..0173cd8b 100644 --- a/global.c +++ b/global.c @@ -439,16 +439,15 @@ void shortcut_init(int unjustify) IFHELP(nano_justify_msg, 0), NANO_JUSTIFY_FKEY, 0, NOVIEW, do_justify); + /* this is so we can view multiple files */ + sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"), + IFHELP(nano_insert_msg, 0), NANO_INSERTFILE_FKEY, 0, #ifdef ENABLE_MULTIBUFFER - /* this is so we can view multiple files */ - sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"), - IFHELP(nano_insert_msg, 0), - NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void); + VIEW #else - sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"), - IFHELP(nano_insert_msg, 0), - NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void); + NOVIEW #endif + , do_insertfile_void); sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"), IFHELP(nano_whereis_msg, 0), diff --git a/nano.c b/nano.c index db83a997..9ab79b1e 100644 --- a/nano.c +++ b/nano.c @@ -66,18 +66,6 @@ static sigjmp_buf jmpbuf; /* Used to return to mainloop after SIGWINCH */ /* What we do when we're all set to exit */ RETSIGTYPE finish(int sigage) { - -#ifndef NANO_SMALL -#ifdef ENABLE_NANORC - /* do here so errors about ./nano_history - don't confuse user */ - if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG)) - save_history(); -#endif - free_history(&search_history); - free_history(&replace_history); -#endif - keypad(edit, TRUE); keypad(bottomwin, TRUE); @@ -93,6 +81,11 @@ RETSIGTYPE finish(int sigage) /* Restore the old term settings */ tcsetattr(0, TCSANOW, &oldterm); +#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) + if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG)) + save_history(); +#endif + #ifdef DEBUG thanks_for_all_the_fish(); #endif @@ -2042,7 +2035,7 @@ int justify_format(int changes_allowed, filestruct *line, size_t skip) /* These four asserts are assumptions about the input data. */ assert(line != NULL); assert(line->data != NULL); - assert(skip <= strlen(line->data)); + assert(skip < strlen(line->data)); assert(line->data[skip] != ' ' && line->data[skip] != '\t'); back = line->data + skip; @@ -2091,14 +2084,14 @@ int justify_format(int changes_allowed, filestruct *line, size_t skip) } back--; - assert(*back == '\0'); + assert(*back == '\0' && *front == '\0'); /* This assert merely documents a fact about the loop above. */ assert(changes_allowed != 0 || back == front); /* Now back is the new end of line->data. */ if (back != front) { - totsize += back - line->data - strlen(line->data); + totsize -= front - back; null_at(&line->data, back - line->data); #ifndef NANO_SMALL if (mark_beginbuf == line && back - line->data < mark_beginx) @@ -3317,6 +3310,14 @@ int main(int argc, char *argv[]) #endif #endif /* ENABLE_NANORC */ +#ifndef NANO_SMALL + history_init(); +#ifdef ENABLE_NANORC + if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG)) + load_history(); +#endif +#endif + #ifndef DISABLE_OPERATINGDIR /* Set up the operating directory. This entails chdir()ing there, so that file reads and writes will be based there. */ @@ -3396,17 +3397,6 @@ int main(int argc, char *argv[]) keypad(bottomwin, TRUE); } -#ifndef NANO_SMALL - history_init(); -#ifdef ENABLE_NANORC - if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG)) - load_history(); -#endif -#endif - - - - #ifdef DEBUG fprintf(stderr, _("Main: bottom win\n")); #endif diff --git a/nano.h b/nano.h index 275c5316..a69ffe34 100644 --- a/nano.h +++ b/nano.h @@ -35,6 +35,9 @@ /* Define charalloc as a macro rather than duplicating code */ #define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char)) #define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char)) +#ifdef BROKEN_REGEXEC +#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags) +#endif #ifndef NANO_SMALL /* For the backup file copy ... */ @@ -76,13 +79,12 @@ # endif #endif -#if !defined(HAVE_STRCASECMP) || !defined(HAVE_STRNCASECMP) -# ifndef HAVE_STRCASECMP -# define strcasecmp strcmp -# endif -# ifndef HAVE_STRNCASECMP -# define strncasecmp strncmp -# endif +#ifndef HAVE_STRCASECMP +#define strcasecmp strcmp +#endif + +#ifndef HAVE_STRNCASECMP +#define strncasecmp strncmp #endif /* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */ diff --git a/proto.h b/proto.h index b8149fd6..bc9015a4 100644 --- a/proto.h +++ b/proto.h @@ -391,6 +391,10 @@ void save_history(void); #endif /* Public functions in utils.c */ +#ifdef BROKEN_REGEXEC +int regexec_safe(const regex_t *preg, const char *string, size_t nmatch, + regmatch_t pmatch[], int eflags); +#endif int is_cntrl_char(int c); int num_of_digits(int n); void align(char **strp); diff --git a/rcfile.c b/rcfile.c index 6b2204fe..aac5d678 100644 --- a/rcfile.c +++ b/rcfile.c @@ -676,6 +676,7 @@ void do_rcfile(void) fclose(rcstream); } } + lineno = 0; free(nanorc); #ifdef ENABLE_COLOR diff --git a/utils.c b/utils.c index 6d3f8f11..261c03a2 100644 --- a/utils.c +++ b/utils.c @@ -30,6 +30,18 @@ #include "proto.h" #include "nano.h" +#ifdef BROKEN_REGEXEC +#undef regexec +int regexec_safe(const regex_t *preg, const char *string, size_t nmatch, + regmatch_t pmatch[], int eflags) +{ + if (string != NULL && *string != '\0') + return regexec(preg, string, nmatch, pmatch, eflags); + return REG_NOMATCH; +} +#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags) +#endif + int is_cntrl_char(int c) { return (-128 <= c && c < -96) || (0 <= c && c < 32) ||