diff --git a/ChangeLog b/ChangeLog index 0b227a00..f13f9a79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,29 @@ CVS code - +- General: + - Minor comment cleanups. (DLR) +- files.c: + add_open_file() + - Rearrange the NANO_SMALL #ifdef so that the code to set the + MODIFIED flag in open_files->flags is included only once. + (DLR) +- search.c: + not_found_msg() + - Convert to properly handle strings generated by + display_string() that have been used in the search prompt + since 1.3.0. (David Benbennick) + do_replace_loop() + - Convert more ints used as boolean values to use TRUE and + FALSE. (David Benbennick) +- utils.c: + nstricmp(), nstrnicmp() + - Add extra blank lines for greater readability, and remove + unneeded test for n's being less than zero (since it's already + been tested for being greater than zero or equal to zero at + that point) from nstrnicmp(). (DLR) + stristr() + - Rename to nstristr() to avoid a potential conflict with an + existing stristr() function, and move up to just after + nstrnicmp(). (DLR) David Benbennick: Tweak for efficiency. GNU nano 1.3.2 - 2004.03.31 - General: diff --git a/src/files.c b/src/files.c index eb2adfc8..b534d22a 100644 --- a/src/files.c +++ b/src/files.c @@ -785,17 +785,14 @@ int add_open_file(int update) /* if we're updating, save current modification status (and marking status, if available) */ if (update) { -#ifndef NANO_SMALL if (ISSET(MODIFIED)) open_files->file_flags |= MODIFIED; +#ifndef NANO_SMALL if (ISSET(MARK_ISSET)) { open_files->file_mark_beginbuf = mark_beginbuf; open_files->file_mark_beginx = mark_beginx; open_files->file_flags |= MARK_ISSET; } -#else - if (ISSET(MODIFIED)) - open_files->file_flags |= MODIFIED; #endif } diff --git a/src/nano.c b/src/nano.c index 3b1c1eb6..7174462c 100644 --- a/src/nano.c +++ b/src/nano.c @@ -125,7 +125,7 @@ void die(const char *msg, ...) while (open_files->next != NULL) { - /* if we already saved the file above (i. e. if it was the + /* if we already saved the file above (i.e, if it was the currently loaded file), don't save it again */ if (tmp != open_files) { /* make sure open_files->fileage and fileage, and diff --git a/src/nano.h b/src/nano.h index 2649ed3f..0d259a52 100644 --- a/src/nano.h +++ b/src/nano.h @@ -91,7 +91,7 @@ # endif #endif -/* If no strcasecmp()/strncasecmp(), use the versions we have. */ +/* If no strcasecmp() or strncasecmp(), use the versions we have. */ #ifndef HAVE_STRCASECMP #define strcasecmp nstricmp #endif diff --git a/src/proto.h b/src/proto.h index 70556739..53817ed3 100644 --- a/src/proto.h +++ b/src/proto.h @@ -428,13 +428,13 @@ int nstricmp(const char *s1, const char *s2); #ifndef HAVE_STRNCASECMP int nstrnicmp(const char *s1, const char *s2, size_t n); #endif +const char *nstristr(const char *haystack, const char *needle); #ifndef NANO_SMALL -const char *revstrstr(const char *haystack, const char *needle, - const char *rev_start); -const char *revstristr(const char *haystack, const char *needle, - const char *rev_start); +const char *revstrstr(const char *haystack, const char *needle, const + char *rev_start); +const char *revstristr(const char *haystack, const char *needle, const + char *rev_start); #endif -const char *stristr(const char *haystack, const char *needle); const char *strstrwrapper(const char *haystack, const char *needle, const char *start); void nperror(const char *s); diff --git a/src/rcfile.c b/src/rcfile.c index 5749c288..43c204f1 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -326,7 +326,7 @@ void parse_syntax(char *ptr) ptr = parse_next_regex(ptr); newext = (exttype *)nmalloc(sizeof(exttype)); - if (nregcomp(&newext->val, fileregptr, REG_NOSUB)) + if (nregcomp(&newext->val, fileregptr, REG_NOSUB) != 0) free(newext); else { if (endext == NULL) @@ -413,7 +413,7 @@ void parse_colors(char *ptr) newcolor = (colortype *)nmalloc(sizeof(colortype)); fgstr = ptr; ptr = parse_next_regex(ptr); - if (nregcomp(&newcolor->start, fgstr, 0)) { + if (nregcomp(&newcolor->start, fgstr, 0) != 0) { free(newcolor); cancelled = 1; } else { @@ -464,7 +464,7 @@ void parse_colors(char *ptr) if (cancelled) continue; newcolor->end = (regex_t *)nmalloc(sizeof(regex_t)); - if (nregcomp(newcolor->end, fgstr, 0)) { + if (nregcomp(newcolor->end, fgstr, 0) != 0) { free(newcolor->end); newcolor->end = NULL; } diff --git a/src/search.c b/src/search.c index 7575d584..03d30e06 100644 --- a/src/search.c +++ b/src/search.c @@ -56,15 +56,11 @@ void regexp_cleanup(void) void not_found_msg(const char *str) { - if (strlen(str) <= COLS / 2) - statusbar(_("\"%s\" not found"), str); - else { - char *foo = mallocstrcpy(NULL, str); + int numchars = actual_x(str, COLS / 2); - foo[COLS / 2] = '\0'; - statusbar(_("\"%s...\" not found"), foo); - free(foo); - } + assert(str != NULL); + statusbar(_("\"%.*s%s\" not found"), numchars, str, str[numchars] == + '\0' ? "" : "..."); } void search_abort(void) @@ -580,7 +576,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, size_t current_x_save = current_x; #ifdef HAVE_REGEX_H /* The starting-line match and bol/eol regex flags. */ - int begin_line = 0, bol_or_eol = 0; + int begin_line = FALSE, bol_or_eol = FALSE; #endif #ifndef NANO_SMALL int mark_set = ISSET(MARK_ISSET); @@ -617,8 +613,8 @@ int do_replace_loop(const char *needle, const filestruct *real_current, * continue. */ else { if (current == real_current) - begin_line = 1; - bol_or_eol = 0; + begin_line = TRUE; + bol_or_eol = FALSE; } #endif @@ -660,7 +656,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, * replace ("^", "$", or "^$"). */ if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, needle)) - bol_or_eol = 1; + bol_or_eol = TRUE; #endif if (i > 0 || replaceall) { /* Yes, replace it!!!! */ diff --git a/src/utils.c b/src/utils.c index 5110fdb1..da414305 100644 --- a/src/utils.c +++ b/src/utils.c @@ -116,10 +116,12 @@ void sunder(char *str) int nstricmp(const char *s1, const char *s2) { assert(s1 != NULL && s2 != NULL); + for (; *s1 != '\0' && *s2 != '\0'; s1++, s2++) { if (tolower(*s1) != tolower(*s2)) break; } + return (tolower(*s1) - tolower(*s2)); } #endif @@ -129,23 +131,45 @@ int nstricmp(const char *s1, const char *s2) int nstrnicmp(const char *s1, const char *s2, size_t n) { assert(s1 != NULL && s2 != NULL); + for (; n > 0 && *s1 != '\0' && *s2 != '\0'; n--, s1++, s2++) { if (tolower(*s1) != tolower(*s2)) break; } + if (n > 0) return (tolower(*s1) - tolower(*s2)); else if (n == 0) return 0; - else if (n < 0) + else return -1; } #endif +/* This function is equivalent to strcasestr(). It was adapted from + * mutt's mutt_stristr() function. */ +const char *nstristr(const char *haystack, const char *needle) +{ + assert(haystack != NULL && needle != NULL); + + for (; *haystack != '\0'; haystack++) { + const char *p = haystack; + const char *q = needle; + + for (; tolower(*p) == tolower(*q) && *q != '\0'; p++, q++) + ; + + if (*q == '\0') + return haystack; + } + + return NULL; +} + /* None of this is needed if we're using NANO_SMALL! */ #ifndef NANO_SMALL -const char *revstrstr(const char *haystack, const char *needle, - const char *rev_start) +const char *revstrstr(const char *haystack, const char *needle, const + char *rev_start) { for (; rev_start >= haystack; rev_start--) { const char *r, *q; @@ -158,8 +182,8 @@ const char *revstrstr(const char *haystack, const char *needle, return NULL; } -const char *revstristr(const char *haystack, const char *needle, - const char *rev_start) +const char *revstristr(const char *haystack, const char *needle, const + char *rev_start) { for (; rev_start >= haystack; rev_start--) { const char *r = rev_start, *q = needle; @@ -173,27 +197,6 @@ const char *revstristr(const char *haystack, const char *needle, } #endif /* !NANO_SMALL */ -/* This is now mutt's version (called mutt_stristr) because it doesn't - * use memory allocation to do a simple search (yuck). */ -const char *stristr(const char *haystack, const char *needle) -{ - const char *p, *q; - - if (haystack == NULL) - return NULL; - if (needle == NULL) - return haystack; - - while (*(p = haystack) != '\0') { - for (q = needle; *p != 0 && *q != 0 && tolower(*p) == tolower(*q); p++, q++) - ; - if (*q == 0) - return haystack; - haystack++; - } - return NULL; -} - /* If we are searching backwards, we will find the last match that * starts no later than start. Otherwise we find the first match * starting no earlier than start. If we are doing a regexp search, we @@ -253,7 +256,7 @@ const char *strstrwrapper(const char *haystack, const char *needle, else if (ISSET(REVERSE_SEARCH)) return revstristr(haystack, needle, start); #endif - return stristr(start, needle); + return nstristr(start, needle); } /* This is a wrapper for the perror() function. The wrapper takes care diff --git a/src/winio.c b/src/winio.c index d4252186..27317dc1 100644 --- a/src/winio.c +++ b/src/winio.c @@ -905,7 +905,7 @@ size_t actual_x(const char *str, size_t xplus) return i; } -/* A strlen with tabs factored in, similar to xplustabs(). How many +/* A strlen() with tabs factored in, similar to xplustabs(). How many * columns wide are the first size characters of buf? */ size_t strnlenpt(const char *buf, size_t size) {