add DB's fix for a problem where quoted justify wouldn't work if

HAVE_REGEX_H wasn't set, and don't treat the return values of the string
comparison functions as boolean anymore


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1877 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2004-07-31 14:10:23 +00:00
parent a6d26d04fd
commit b8c479a9e9
6 changed files with 63 additions and 54 deletions

View File

@ -65,6 +65,8 @@ CVS code -
once for all errors instead of separately for each error. once for all errors instead of separately for each error.
Also make sure that each rcfile error message ends in a Also make sure that each rcfile error message ends in a
newline. (DLR) newline. (DLR)
- Don't treat the return value of strn?(case)?cmp() as boolean.
(DLR and David Benbennick)
- files.c: - files.c:
close_open_file() close_open_file()
- Tweak to no longer rely on the return values of - Tweak to no longer rely on the return values of
@ -98,6 +100,9 @@ CVS code -
terminal_init() to make sure that all the original terminal terminal_init() to make sure that all the original terminal
settings are restored, as a curses-based alternative spell settings are restored, as a curses-based alternative spell
checker (e.g. aspell) can change them. (DLR) checker (e.g. aspell) can change them. (DLR)
quote_length()
- Fix problem where quoted justify wouldn't work if HAVE_REGEX_H
wasn't set. (David Benbennick)
do_justify() do_justify()
- Add allow_respacing flag, used to indicate when we've moved to - Add allow_respacing flag, used to indicate when we've moved to
the next line after justifying the current line, and only run the next line after justifying the current line, and only run

View File

@ -120,7 +120,7 @@ void update_color(void)
if (colorstrings == NULL && syntaxstr != NULL) { if (colorstrings == NULL && syntaxstr != NULL) {
for (tmpsyntax = syntaxes; tmpsyntax != NULL; for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) { tmpsyntax = tmpsyntax->next) {
if (!strcasecmp(tmpsyntax->desc, syntaxstr)) if (strcasecmp(tmpsyntax->desc, syntaxstr) == 0)
colorstrings = tmpsyntax->color; colorstrings = tmpsyntax->color;
} }
} }

View File

@ -444,7 +444,7 @@ void do_insertfile(int loading_file)
#endif #endif
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
if (operating_dir != NULL && strcmp(operating_dir, ".")) if (operating_dir != NULL && strcmp(operating_dir, ".") != 0)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (ISSET(MULTIBUFFER)) if (ISSET(MULTIBUFFER))
i = statusq(TRUE, insertfile_list, inspath, i = statusq(TRUE, insertfile_list, inspath,
@ -1039,7 +1039,7 @@ char *get_full_path(const char *origpath)
if (d_here != NULL) { if (d_here != NULL) {
align(&d_here); align(&d_here);
if (strcmp(d_here, "/")) { if (strcmp(d_here, "/") != 0) {
d_here = charealloc(d_here, strlen(d_here) + 2); d_here = charealloc(d_here, strlen(d_here) + 2);
strcat(d_here, "/"); strcat(d_here, "/");
} }
@ -1111,7 +1111,7 @@ char *get_full_path(const char *origpath)
/* add a slash to d_there, unless it's "/", in which /* add a slash to d_there, unless it's "/", in which
case we don't need it */ case we don't need it */
if (strcmp(d_there, "/")) { if (strcmp(d_there, "/") != 0) {
d_there = charealloc(d_there, strlen(d_there) + 2); d_there = charealloc(d_there, strlen(d_there) + 2);
strcat(d_there, "/"); strcat(d_there, "/");
} }
@ -1908,14 +1908,14 @@ int do_writeout(int exiting)
#endif #endif
#ifdef NANO_EXTRA #ifdef NANO_EXTRA
if (exiting && !ISSET(TEMP_FILE) && !strcasecmp(answer, "zzy") if (exiting && !ISSET(TEMP_FILE) && strcasecmp(answer, "zzy") == 0
&& !did_cred) { && !did_cred) {
do_credits(); do_credits();
did_cred = TRUE; did_cred = TRUE;
return -1; return -1;
} }
#endif #endif
if (append == 0 && strcmp(answer, filename)) { if (append == 0 && strcmp(answer, filename) != 0) {
struct stat st; struct stat st;
if (!stat(answer, &st)) { if (!stat(answer, &st)) {
@ -1987,7 +1987,7 @@ char *real_dir_from_tilde(const char *buf)
do { do {
userdata = getpwent(); userdata = getpwent();
} while (userdata != NULL && } while (userdata != NULL &&
strncmp(userdata->pw_name, buf + 1, i - 1)); strncmp(userdata->pw_name, buf + 1, i - 1) != 0);
} }
endpwent(); endpwent();
@ -2290,7 +2290,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace,
} else } else
tmp = buf; tmp = buf;
if (!strcmp(tmp, matches[0])) if (strcmp(tmp, matches[0]) == 0)
is_dir = append_slash_if_dir(buf, lastwastab, newplace); is_dir = append_slash_if_dir(buf, lastwastab, newplace);
if (is_dir != 0) if (is_dir != 0)
@ -2514,7 +2514,7 @@ char **browser_init(const char *path, int *longest, int *numents)
*numents = 0; *numents = 0;
while ((next = readdir(dir)) != NULL) { while ((next = readdir(dir)) != NULL) {
if (!strcmp(next->d_name, ".")) if (strcmp(next->d_name, ".") == 0)
continue; continue;
(*numents)++; (*numents)++;
if (strlen(next->d_name) > *longest) if (strlen(next->d_name) > *longest)
@ -2525,12 +2525,12 @@ char **browser_init(const char *path, int *longest, int *numents)
filelist = (char **)nmalloc(*numents * sizeof (char *)); filelist = (char **)nmalloc(*numents * sizeof (char *));
if (!strcmp(path, "/")) if (strcmp(path, "/") == 0)
path = ""; path = "";
path_len = strlen(path); path_len = strlen(path);
while ((next = readdir(dir)) != NULL) { while ((next = readdir(dir)) != NULL) {
if (!strcmp(next->d_name, ".")) if (strcmp(next->d_name, ".") == 0)
continue; continue;
filelist[i] = charalloc(strlen(next->d_name) + path_len + 2); filelist[i] = charalloc(strlen(next->d_name) + path_len + 2);
@ -2564,7 +2564,7 @@ char *do_browser(const char *inpath)
/* If path isn't the same as inpath, we are being passed a new /* If path isn't the same as inpath, we are being passed a new
dir as an arg. We free it here so it will be copied from dir as an arg. We free it here so it will be copied from
inpath below */ inpath below */
if (path != NULL && strcmp(path, inpath)) { if (path != NULL && strcmp(path, inpath) != 0) {
free(path); free(path);
path = NULL; path = NULL;
} }
@ -2682,7 +2682,8 @@ char *do_browser(const char *inpath)
case 'S': /* Pico compatibility */ case 'S': /* Pico compatibility */
case 's': case 's':
/* You can't cd up from / */ /* You can't cd up from / */
if (!strcmp(filelist[selected], "/..") && !strcmp(path, "/")) { if (strcmp(filelist[selected], "/..") == 0 &&
strcmp(path, "/") == 0) {
statusbar(_("Can't move up a directory")); statusbar(_("Can't move up a directory"));
beep(); beep();
break; break;

View File

@ -1494,7 +1494,7 @@ int do_int_spell_fix(const char *word)
do_replace_highlight(FALSE, word); do_replace_highlight(FALSE, word);
if (i != -1 && strcmp(word, answer)) { if (i != -1 && strcmp(word, answer) != 0) {
search_last_line = FALSE; search_last_line = FALSE;
current_x--; current_x--;
do_replace_loop(word, current_save, &current_x_save, TRUE); do_replace_loop(word, current_save, &current_x_save, TRUE);
@ -1971,7 +1971,7 @@ size_t quote_length(const char *line)
size_t qdepth = 0; size_t qdepth = 0;
/* Compute quote depth level. */ /* Compute quote depth level. */
while (!strcmp(line + qdepth, quotestr)) while (strncmp(line + qdepth, quotestr, quotelen) == 0)
qdepth += quotelen; qdepth += quotelen;
return qdepth; return qdepth;
#endif /* !HAVE_REGEX_H */ #endif /* !HAVE_REGEX_H */
@ -1985,7 +1985,7 @@ int quotes_match(const char *a_line, size_t a_quote, const char *b_line)
/* Here is the assumption about a_quote: */ /* Here is the assumption about a_quote: */
assert(a_quote == quote_length(a_line)); assert(a_quote == quote_length(a_line));
return a_quote == quote_length(b_line) && return a_quote == quote_length(b_line) &&
!strncmp(a_line, b_line, a_quote); strncmp(a_line, b_line, a_quote) == 0;
} }
/* We assume a_line and b_line have no quote part. Then, we return /* We assume a_line and b_line have no quote part. Then, we return
@ -1996,7 +1996,8 @@ size_t indents_match(const char *a_line, size_t a_indent, const char
assert(a_indent == indent_length(a_line)); assert(a_indent == indent_length(a_line));
assert(b_indent == indent_length(b_line)); assert(b_indent == indent_length(b_line));
return b_indent <= a_indent && !strncmp(a_line, b_line, b_indent); return b_indent <= a_indent &&
strncmp(a_line, b_line, b_indent) == 0;
} }
/* Is foo the beginning of a paragraph? /* Is foo the beginning of a paragraph?

View File

@ -186,26 +186,26 @@ int colortoint(const char *colorname, int *bright)
if (colorname == NULL) if (colorname == NULL)
return -1; return -1;
if (!strncasecmp(colorname, "bright", 6)) { if (strncasecmp(colorname, "bright", 6) == 0) {
*bright = 1; *bright = 1;
colorname += 6; colorname += 6;
} }
if (!strcasecmp(colorname, "green")) if (strcasecmp(colorname, "green") == 0)
mcolor = COLOR_GREEN; mcolor = COLOR_GREEN;
else if (!strcasecmp(colorname, "red")) else if (strcasecmp(colorname, "red") == 0)
mcolor = COLOR_RED; mcolor = COLOR_RED;
else if (!strcasecmp(colorname, "blue")) else if (strcasecmp(colorname, "blue") == 0)
mcolor = COLOR_BLUE; mcolor = COLOR_BLUE;
else if (!strcasecmp(colorname, "white")) else if (strcasecmp(colorname, "white") == 0)
mcolor = COLOR_WHITE; mcolor = COLOR_WHITE;
else if (!strcasecmp(colorname, "yellow")) else if (strcasecmp(colorname, "yellow") == 0)
mcolor = COLOR_YELLOW; mcolor = COLOR_YELLOW;
else if (!strcasecmp(colorname, "cyan")) else if (strcasecmp(colorname, "cyan") == 0)
mcolor = COLOR_CYAN; mcolor = COLOR_CYAN;
else if (!strcasecmp(colorname, "magenta")) else if (strcasecmp(colorname, "magenta") == 0)
mcolor = COLOR_MAGENTA; mcolor = COLOR_MAGENTA;
else if (!strcasecmp(colorname, "black")) else if (strcasecmp(colorname, "black") == 0)
mcolor = COLOR_BLACK; mcolor = COLOR_BLACK;
else { else {
rcfile_error(N_("Color %s not understood.\n" rcfile_error(N_("Color %s not understood.\n"
@ -353,7 +353,7 @@ void parse_colors(char *ptr)
char *bgcolorname; char *bgcolorname;
strtok(fgstr, ","); strtok(fgstr, ",");
bgcolorname = strtok(NULL, ","); bgcolorname = strtok(NULL, ",");
if (!strncasecmp(bgcolorname, "bright", 6)) { if (strncasecmp(bgcolorname, "bright", 6) == 0) {
rcfile_error(N_("Background color %s cannot be bright\n"), bgcolorname); rcfile_error(N_("Background color %s cannot be bright\n"), bgcolorname);
return; return;
} }
@ -391,7 +391,7 @@ void parse_colors(char *ptr)
if (*ptr == '\n' || *ptr == '\0') if (*ptr == '\n' || *ptr == '\0')
break; break;
if (!strncasecmp(ptr, "start=", 6)) { if (strncasecmp(ptr, "start=", 6) == 0) {
ptr += 6; ptr += 6;
expectend = 1; expectend = 1;
} }
@ -433,7 +433,7 @@ void parse_colors(char *ptr)
} }
if (expectend) { if (expectend) {
if (ptr == NULL || strncasecmp(ptr, "end=", 4)) { if (ptr == NULL || strncasecmp(ptr, "end=", 4) != 0) {
rcfile_error(N_("\"start=\" requires a corresponding \"end=\"\n")); rcfile_error(N_("\"start=\" requires a corresponding \"end=\"\n"));
return; return;
} }
@ -494,14 +494,14 @@ void parse_rcfile(FILE *rcstream)
continue; continue;
/* Else try to parse the keyword */ /* Else try to parse the keyword */
if (!strcasecmp(keyword, "set")) if (strcasecmp(keyword, "set") == 0)
set = 1; set = 1;
else if (!strcasecmp(keyword, "unset")) else if (strcasecmp(keyword, "unset") == 0)
set = -1; set = -1;
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
else if (!strcasecmp(keyword, "syntax")) else if (strcasecmp(keyword, "syntax") == 0)
parse_syntax(ptr); parse_syntax(ptr);
else if (!strcasecmp(keyword, "color")) else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr); parse_colors(ptr);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
else { else {
@ -515,32 +515,32 @@ void parse_rcfile(FILE *rcstream)
if (set != 0) { if (set != 0) {
for (i = 0; rcopts[i].name != NULL; i++) { for (i = 0; rcopts[i].name != NULL; i++) {
if (!strcasecmp(option, rcopts[i].name)) { if (strcasecmp(option, rcopts[i].name) == 0) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Parsing option %s\n", fprintf(stderr, "%s: Parsing option %s\n",
"parse_rcfile()", rcopts[i].name); "parse_rcfile()", rcopts[i].name);
#endif #endif
if (set == 1) { if (set == 1) {
if (!strcasecmp(rcopts[i].name, "tabsize") if (strcasecmp(rcopts[i].name, "tabsize") == 0
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
|| !strcasecmp(rcopts[i].name, "operatingdir") || strcasecmp(rcopts[i].name, "operatingdir") == 0
#endif #endif
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
|| !strcasecmp(rcopts[i].name, "fill") || strcasecmp(rcopts[i].name, "fill") == 0
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
|| !strcasecmp(rcopts[i].name, "whitespace") || strcasecmp(rcopts[i].name, "whitespace") == 0
#endif #endif
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
|| !strcasecmp(rcopts[i].name, "punct") || strcasecmp(rcopts[i].name, "punct") == 0
|| !strcasecmp(rcopts[i].name, "brackets") || strcasecmp(rcopts[i].name, "brackets") == 0
|| !strcasecmp(rcopts[i].name, "quotestr") || strcasecmp(rcopts[i].name, "quotestr") == 0
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
|| !strcasecmp(rcopts[i].name, "backupdir") || strcasecmp(rcopts[i].name, "backupdir") == 0
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
|| !strcasecmp(rcopts[i].name, "speller") || strcasecmp(rcopts[i].name, "speller") == 0
#endif #endif
) { ) {
if (*ptr == '\n' || *ptr == '\0') { if (*ptr == '\n' || *ptr == '\0') {
@ -555,12 +555,12 @@ void parse_rcfile(FILE *rcstream)
fprintf(stderr, "option = %s\n", option); fprintf(stderr, "option = %s\n", option);
#endif #endif
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
if (!strcasecmp(rcopts[i].name, "operatingdir")) if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
operating_dir = mallocstrcpy(NULL, option); operating_dir = mallocstrcpy(NULL, option);
else else
#endif #endif
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
if (!strcasecmp(rcopts[i].name, "fill")) { if (strcasecmp(rcopts[i].name, "fill") == 0) {
if (parse_num(option, &wrap_at) == -1) { if (parse_num(option, &wrap_at) == -1) {
rcfile_error(N_("Requested fill size %s invalid\n"), option); rcfile_error(N_("Requested fill size %s invalid\n"), option);
wrap_at = -CHARS_FROM_EOL; wrap_at = -CHARS_FROM_EOL;
@ -568,7 +568,7 @@ void parse_rcfile(FILE *rcstream)
} else } else
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (!strcasecmp(rcopts[i].name, "whitespace")) { if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
size_t ws_len; size_t ws_len;
whitespace = mallocstrcpy(NULL, option); whitespace = mallocstrcpy(NULL, option);
ws_len = strlen(whitespace); ws_len = strlen(whitespace);
@ -580,35 +580,35 @@ void parse_rcfile(FILE *rcstream)
} else } else
#endif #endif
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
if (!strcasecmp(rcopts[i].name, "punct")) { if (strcasecmp(rcopts[i].name, "punct") == 0) {
punct = mallocstrcpy(NULL, option); punct = mallocstrcpy(NULL, option);
if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) { if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) {
rcfile_error(N_("Non-tab and non-space characters required\n")); rcfile_error(N_("Non-tab and non-space characters required\n"));
free(punct); free(punct);
punct = NULL; punct = NULL;
} }
} else if (!strcasecmp(rcopts[i].name, "brackets")) { } else if (strcasecmp(rcopts[i].name, "brackets") == 0) {
brackets = mallocstrcpy(NULL, option); brackets = mallocstrcpy(NULL, option);
if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) { if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) {
rcfile_error(N_("Non-tab and non-space characters required\n")); rcfile_error(N_("Non-tab and non-space characters required\n"));
free(brackets); free(brackets);
brackets = NULL; brackets = NULL;
} }
} else if (!strcasecmp(rcopts[i].name, "quotestr")) } else if (strcasecmp(rcopts[i].name, "quotestr") == 0)
quotestr = mallocstrcpy(NULL, option); quotestr = mallocstrcpy(NULL, option);
else else
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (!strcasecmp(rcopts[i].name, "backupdir")) if (strcasecmp(rcopts[i].name, "backupdir") == 0)
backup_dir = mallocstrcpy(NULL, option); backup_dir = mallocstrcpy(NULL, option);
else else
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
if (!strcasecmp(rcopts[i].name, "speller")) if (strcasecmp(rcopts[i].name, "speller") == 0)
alt_speller = mallocstrcpy(NULL, option); alt_speller = mallocstrcpy(NULL, option);
else else
#endif #endif
if (!strcasecmp(rcopts[i].name, "tabsize")) { if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
if (parse_num(option, &tabsize) == -1 || tabsize <= 0) if (parse_num(option, &tabsize) == -1 || tabsize <= 0)
rcfile_error(N_("Requested tab size %s invalid\n"), option); rcfile_error(N_("Requested tab size %s invalid\n"), option);
tabsize = -1; tabsize = -1;

View File

@ -1736,7 +1736,8 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
search history, and we need to save the current search history, and we need to save the current
answer in currentbuf; do this and reset use_cb to answer in currentbuf; do this and reset use_cb to
0 */ 0 */
if (currentbuf == NULL || (use_cb == 1 && strcmp(currentbuf, answer))) { if (currentbuf == NULL || (use_cb == 1 &&
strcmp(currentbuf, answer) != 0)) {
currentbuf = mallocstrcpy(currentbuf, answer); currentbuf = mallocstrcpy(currentbuf, answer);
use_cb = 0; use_cb = 0;
} }
@ -1747,7 +1748,8 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
we need to make the string in currentbuf the current we need to make the string in currentbuf the current
answer; do this, blow away currentbuf since we don't answer; do this, blow away currentbuf since we don't
need it anymore, and reset use_cb to 0 */ need it anymore, and reset use_cb to 0 */
if (currentbuf != NULL && use_cb == 2 && strcmp(currentbuf, answer)) { if (currentbuf != NULL && use_cb == 2 &&
strcmp(currentbuf, answer) != 0) {
answer = mallocstrcpy(answer, currentbuf); answer = mallocstrcpy(answer, currentbuf);
free(currentbuf); free(currentbuf);
currentbuf = NULL; currentbuf = NULL;