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:
/* 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
}
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
# 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
#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);
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)
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 {
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;
}
void not_found_msg(const char *str)
{
- if (strlen(str) <= COLS / 2)
- statusbar(_("\"%s\" not found"), str);
- else {
- char *foo = mallocstrcpy(NULL, str);
-
- foo[COLS / 2] = '\0';
- statusbar(_("\"%s...\" not found"), foo);
- free(foo);
- }
+ int numchars = actual_x(str, COLS / 2);
+
+ assert(str != NULL);
+ statusbar(_("\"%.*s%s\" not found"), numchars, str, str[numchars] ==
+ '\0' ? "" : "...");
}
void search_abort(void)
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);
* continue. */
else {
if (current == real_current)
- begin_line = 1;
- bol_or_eol = 0;
+ begin_line = TRUE;
+ bol_or_eol = FALSE;
}
#endif
* 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!!!! */
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
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;
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;
}
#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
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
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)
{