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.
Also make sure that each rcfile error message ends in a
newline. (DLR)
- Don't treat the return value of strn?(case)?cmp() as boolean.
(DLR and David Benbennick)
- files.c:
close_open_file()
- 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
settings are restored, as a curses-based alternative spell
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()
- Add allow_respacing flag, used to indicate when we've moved to
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) {
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
tmpsyntax = tmpsyntax->next) {
if (!strcasecmp(tmpsyntax->desc, syntaxstr))
if (strcasecmp(tmpsyntax->desc, syntaxstr) == 0)
colorstrings = tmpsyntax->color;
}
}

View File

@ -444,7 +444,7 @@ void do_insertfile(int loading_file)
#endif
#ifndef DISABLE_OPERATINGDIR
if (operating_dir != NULL && strcmp(operating_dir, "."))
if (operating_dir != NULL && strcmp(operating_dir, ".") != 0)
#ifdef ENABLE_MULTIBUFFER
if (ISSET(MULTIBUFFER))
i = statusq(TRUE, insertfile_list, inspath,
@ -1039,7 +1039,7 @@ char *get_full_path(const char *origpath)
if (d_here != NULL) {
align(&d_here);
if (strcmp(d_here, "/")) {
if (strcmp(d_here, "/") != 0) {
d_here = charealloc(d_here, strlen(d_here) + 2);
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
case we don't need it */
if (strcmp(d_there, "/")) {
if (strcmp(d_there, "/") != 0) {
d_there = charealloc(d_there, strlen(d_there) + 2);
strcat(d_there, "/");
}
@ -1908,14 +1908,14 @@ int do_writeout(int exiting)
#endif
#ifdef NANO_EXTRA
if (exiting && !ISSET(TEMP_FILE) && !strcasecmp(answer, "zzy")
if (exiting && !ISSET(TEMP_FILE) && strcasecmp(answer, "zzy") == 0
&& !did_cred) {
do_credits();
did_cred = TRUE;
return -1;
}
#endif
if (append == 0 && strcmp(answer, filename)) {
if (append == 0 && strcmp(answer, filename) != 0) {
struct stat st;
if (!stat(answer, &st)) {
@ -1987,7 +1987,7 @@ char *real_dir_from_tilde(const char *buf)
do {
userdata = getpwent();
} while (userdata != NULL &&
strncmp(userdata->pw_name, buf + 1, i - 1));
strncmp(userdata->pw_name, buf + 1, i - 1) != 0);
}
endpwent();
@ -2290,7 +2290,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace,
} else
tmp = buf;
if (!strcmp(tmp, matches[0]))
if (strcmp(tmp, matches[0]) == 0)
is_dir = append_slash_if_dir(buf, lastwastab, newplace);
if (is_dir != 0)
@ -2514,7 +2514,7 @@ char **browser_init(const char *path, int *longest, int *numents)
*numents = 0;
while ((next = readdir(dir)) != NULL) {
if (!strcmp(next->d_name, "."))
if (strcmp(next->d_name, ".") == 0)
continue;
(*numents)++;
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 *));
if (!strcmp(path, "/"))
if (strcmp(path, "/") == 0)
path = "";
path_len = strlen(path);
while ((next = readdir(dir)) != NULL) {
if (!strcmp(next->d_name, "."))
if (strcmp(next->d_name, ".") == 0)
continue;
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
dir as an arg. We free it here so it will be copied from
inpath below */
if (path != NULL && strcmp(path, inpath)) {
if (path != NULL && strcmp(path, inpath) != 0) {
free(path);
path = NULL;
}
@ -2682,7 +2682,8 @@ char *do_browser(const char *inpath)
case 'S': /* Pico compatibility */
case 's':
/* 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"));
beep();
break;

View File

@ -1494,7 +1494,7 @@ int do_int_spell_fix(const char *word)
do_replace_highlight(FALSE, word);
if (i != -1 && strcmp(word, answer)) {
if (i != -1 && strcmp(word, answer) != 0) {
search_last_line = FALSE;
current_x--;
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;
/* Compute quote depth level. */
while (!strcmp(line + qdepth, quotestr))
while (strncmp(line + qdepth, quotestr, quotelen) == 0)
qdepth += quotelen;
return qdepth;
#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: */
assert(a_quote == quote_length(a_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
@ -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(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?

View File

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