diff -u -r nano/src/nano.c nano-test/src/nano.c --- nano/src/nano.c 2004-08-02 18:38:38.000000000 -0400 +++ nano-test/src/nano.c 2004-08-02 19:51:41.000000000 -0400 @@ -61,7 +61,7 @@ basically */ #endif #ifndef DISABLE_WRAPPING -static int same_line_wrap = FALSE; /* Whether wrapped text should +static bool same_line_wrap = FALSE; /* Whether wrapped text should be prepended to the next line */ #endif @@ -155,7 +155,7 @@ void die_save_file(const char *die_filename) { char *ret; - int i = -1; + bool failed = TRUE; /* If we're using restricted mode, don't write any emergency backup * files, since that would allow reading from or writing to files @@ -176,9 +176,9 @@ free(buf); } if (ret[0] != '\0') - i = write_file(ret, TRUE, FALSE, TRUE); + failed = -1 == write_file(ret, TRUE, FALSE, TRUE); - if (i != -1) + if (!failed) fprintf(stderr, _("\nBuffer written to %s\n"), ret); else fprintf(stderr, _("\nNo %s written (too many backup files?)\n"), ret); @@ -199,8 +199,8 @@ } /* Initialize global variables -- no better way for now. If - * save_cutbuffer is nonzero, don't set cutbuffer to NULL. */ -void global_init(int save_cutbuffer) + * save_cutbuffer is TRUE, don't set cutbuffer to NULL. */ +void global_init(bool save_cutbuffer) { current_x = 0; current_y = 0; @@ -385,12 +385,12 @@ /* The space needed for the shortcut lists, at most COLS characters, * plus '\n'. */ - allocsize += (COLS + 1) * length_of_list(currshortcut); + allocsize += (COLS < 21 ? 21 : COLS + 1) * length_of_list(currshortcut); #ifndef NANO_SMALL /* If we're on the main list, we also count the toggle help text. - * Each line has "M-%c\t\t\t", which fills 24 columns, plus at most - * COLS - 24 characters, plus '\n'.*/ + * Each line has "M-%c\t\t\t", which fills 24 columns, plus a space, + * plus translated text, plus '\n'.*/ if (currshortcut == main_list) { size_t endislen = strlen(_("enable/disable")); @@ -413,16 +413,16 @@ /* Now add our shortcut info */ for (s = currshortcut; s != NULL; s = s->next) { /* true if the character in s->metaval is shown in first column */ - int meta_shortcut = FALSE; + bool meta_shortcut = FALSE; if (s->ctrlval != NANO_NO_KEY) { #ifndef NANO_SMALL if (s->ctrlval == NANO_HISTORY_KEY) - ptr += sprintf(ptr, "%.2s", _("Up")); + ptr += sprintf(ptr, "%.7s", _("Up")); else #endif if (s->ctrlval == NANO_CONTROL_SPACE) - ptr += sprintf(ptr, "^%.5s", _("Space")); + ptr += sprintf(ptr, "^%.6s", _("Space")); else if (s->ctrlval == NANO_CONTROL_8) ptr += sprintf(ptr, "^?"); else @@ -432,7 +432,7 @@ else if (s->metaval != NANO_NO_KEY) { meta_shortcut = TRUE; if (s->metaval == NANO_ALT_SPACE) - ptr += snprintf(ptr, 8, "M-%.5s", _("Space")); + ptr += sprintf(ptr, "M-%.5s", _("Space")); else ptr += sprintf(ptr, "M-%c", toupper(s->metaval)); } @@ -788,16 +788,16 @@ nperror("kill"); } -int open_pipe(const char *command) +/* Return TRUE on success. */ +bool open_pipe(const char *command) { int fd[2]; FILE *f; struct sigaction oldaction, newaction; /* original and temporary handlers for SIGINT */ - int cancel_sigs = 0; - /* cancel_sigs == 1 means that sigaction() failed without changing - * the signal handlers. cancel_sigs == 2 means the signal handler - * was changed, but the tcsetattr() didn't succeed. + bool sig_failed = FALSE; + /* sig_failed means that sigaction() failed without changing + * the signal handlers. * * I use this variable since it is important to put things back when * we finish, even if we get errors. */ @@ -806,7 +806,7 @@ if (pipe(fd) == -1) { statusbar(_("Could not pipe")); - return 1; + return FALSE; } /* Fork a child. */ @@ -816,7 +816,7 @@ dup2(fd[1], fileno(stdout)); dup2(fd[1], fileno(stderr)); /* If execl() returns at all, there was an error. */ - + execl("/bin/sh", "sh", "-c", command, 0); exit(0); } @@ -828,7 +828,7 @@ if (pid == -1) { close(fd[0]); statusbar(_("Could not fork")); - return 1; + return FALSE; } /* Before we start reading the forked command's output, we set @@ -839,12 +839,12 @@ enable_signals(); if (sigaction(SIGINT, NULL, &newaction) == -1) { - cancel_sigs = 1; + sig_failed = TRUE; nperror("sigaction"); } else { newaction.sa_handler = cancel_fork; if (sigaction(SIGINT, &newaction, &oldaction) == -1) { - cancel_sigs = 1; + sig_failed = TRUE; nperror("sigaction"); } } @@ -853,9 +853,9 @@ f = fdopen(fd[0], "rb"); if (f == NULL) - nperror("fdopen"); - - read_file(f, "stdin", 0); + nperror("fdopen"); + + read_file(f, "stdin", FALSE); /* if multibuffer mode is on, we could be here in view mode; if so, don't set the modification flag */ if (!ISSET(VIEW_MODE)) @@ -864,14 +864,14 @@ if (wait(NULL) == -1) nperror("wait"); - if (cancel_sigs != 1 && sigaction(SIGINT, &oldaction, NULL) == -1) + if (!sig_failed && sigaction(SIGINT, &oldaction, NULL) == -1) nperror("sigaction"); /* Disable interpretation of the special control keys so that we can * use Ctrl-C for other things. */ disable_signals(); - return 0; + return TRUE; } #endif /* !NANO_SMALL */ @@ -884,7 +884,7 @@ /* Click in the edit window to move the cursor, but only when we're not in a subfunction. */ if (wenclose(edit, mouse_y, mouse_x) && currshortcut == main_list) { - int sameline; + bool sameline; /* Did they click on the line with the cursor? If they clicked on the cursor, we set the mark. */ size_t xcur; @@ -931,7 +931,7 @@ { size_t current_len = strlen(current->data); #if !defined(DISABLE_WRAPPING) || defined(ENABLE_COLOR) - int do_refresh = FALSE; + bool do_refresh = FALSE; /* Do we have to call edit_refresh(), or can we get away with * update_line()? */ #endif @@ -1019,7 +1019,7 @@ void do_delete(void) { - int do_refresh = FALSE; + bool do_refresh = FALSE; /* Do we have to call edit_refresh(), or can we get away with * update_line()? */ @@ -1241,7 +1241,7 @@ /* We wrap the given line. Precondition: we assume the cursor has been * moved forward since the last typed character. Return value: whether * we wrapped. */ -int do_wrap(filestruct *inptr) +bool do_wrap(filestruct *inptr) { size_t len = strlen(inptr->data); /* Length of the line we wrap. */ @@ -1257,7 +1257,7 @@ #endif const char *after_break; /* Text after the wrap point. */ size_t after_break_len; /* strlen(after_break) */ - int wrapping = FALSE; /* Do we prepend to the next line? */ + bool wrapping = FALSE; /* Do we prepend to the next line? */ const char *wrap_line = NULL; /* The next line, minus indentation. */ size_t wrap_line_len = 0; /* strlen(wrap_line) */ @@ -1440,8 +1440,8 @@ #ifndef DISABLE_SPELLER /* A word is misspelled in the file. Let the user replace it. We - * return zero if the user cancels. */ -int do_int_spell_fix(const char *word) + * return FALSE if the user cancels. */ +bool do_int_spell_fix(const char *word) { char *save_search; char *save_replace; @@ -1449,12 +1449,12 @@ filestruct *current_save = current; filestruct *edittop_save = edittop; /* Save where we are. */ - int i = 0; + bool accepted = TRUE; /* The return value. */ - int reverse_search_set = ISSET(REVERSE_SEARCH); + bool reverse_search_set = ISSET(REVERSE_SEARCH); #ifndef NANO_SMALL - int case_sens_set = ISSET(CASE_SENSITIVE); - int mark_set = ISSET(MARK_ISSET); + bool case_sens_set = ISSET(CASE_SENSITIVE); + bool mark_set = ISSET(MARK_ISSET); SET(CASE_SENSITIVE); /* Make sure the marking highlight is off during spell-check. */ @@ -1486,7 +1486,7 @@ do_replace_highlight(TRUE, word); /* Allow the replace word to be corrected. */ - i = statusq(FALSE, spell_list, word, + accepted = -1 != statusq(FALSE, spell_list, word, #ifndef NANO_SMALL NULL, #endif @@ -1494,7 +1494,7 @@ do_replace_highlight(FALSE, word); - if (i != -1 && strcmp(word, answer) != 0) { + if (accepted && strcmp(word, answer) != 0) { search_last_line = FALSE; current_x--; do_replace_loop(word, current_save, ¤t_x_save, TRUE); @@ -1527,12 +1527,12 @@ SET(MARK_ISSET); #endif - return i != -1; + return accepted; } /* Integrated spell checking using 'spell' program. Return value: NULL * for normal termination, otherwise the error string. */ -const char *do_int_speller(char *tempfile_name) +const char *do_int_speller(const char *tempfile_name) { char *read_buff, *read_buff_ptr, *read_buff_word; size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread; @@ -1728,7 +1728,7 @@ static int arglen = 3; static char **spellargs = (char **)NULL; #ifndef NANO_SMALL - int mark_set = ISSET(MARK_ISSET); + bool mark_set = ISSET(MARK_ISSET); int mbb_lineno_cur = 0; /* We're going to close the current file, and open the output of * the alternate spell command. The line that mark_beginbuf @@ -1784,25 +1784,23 @@ } refresh(); -#ifndef NANO_SMALL - if (!mark_set) { - /* Only reload the temp file if it isn't a marked selection. */ -#endif - free_filestruct(fileage); - terminal_init(); - global_init(TRUE); - open_file(tempfile_name, FALSE, TRUE); -#ifndef NANO_SMALL - } +#ifndef NANO_SMALL if (mark_set) { do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0); mark_beginbuf = current; /* In case the line got shorter, assign mark_beginx. */ mark_beginx = current_x; SET(MARK_ISSET); - } + } else #endif + { + /* Only reload the temp file if it isn't a marked selection. */ + free_filestruct(fileage); + terminal_init(); + global_init(TRUE); + open_file(tempfile_name, FALSE, TRUE); + } /* Go back to the old position, mark the file as modified, and make * sure that the titlebar is refreshed. */ @@ -1849,11 +1847,10 @@ unlink(temp); free(temp); - if (spell_msg != NULL) { + if (spell_msg != NULL) statusbar(_("Spell checking failed: %s: %s"), spell_msg, strerror(errno)); - return; - } else + else statusbar(_("Finished checking spelling")); } #endif /* !DISABLE_SPELLER */ @@ -1897,7 +1894,7 @@ back = line->data + skip; for (front = back; ; front++) { - int remove_space = FALSE; + bool remove_space = FALSE; /* Do we want to remove this space? */ if (*front == '\t') @@ -1962,7 +1959,7 @@ regmatch_t matches; int rc = regexec("ereg, line, 1, &matches, 0); - if (rc == REG_NOMATCH || matches.rm_so == (regoff_t)-1) + if (rc == REG_NOMATCH || matches.rm_so == (regoff_t) -1) return 0; /* matches.rm_so should be 0, since the quote string should start * with the caret ^. */ @@ -1980,7 +1977,7 @@ /* a_line and b_line are lines of text. The quotation part of a_line is * the first a_quote characters. Check that the quotation part of * b_line is the same. */ -int quotes_match(const char *a_line, size_t a_quote, const char *b_line) +bool 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)); @@ -1990,7 +1987,7 @@ /* We assume a_line and b_line have no quote part. Then, we return * whether b_line could follow a_line in a paragraph. */ -size_t indents_match(const char *a_line, size_t a_indent, const char +bool indents_match(const char *a_line, size_t a_indent, const char *b_line, size_t b_indent) { assert(a_indent == indent_length(a_line)); @@ -2146,13 +2143,13 @@ } /* Is it possible to break line at or before goal? */ -int breakable(const char *line, int goal) +bool breakable(const char *line, int goal) { for (; *line != '\0' && goal >= 0; line++) { if (isblank(*line)) return TRUE; - if (is_cntrl_char(*line) != 0) + if (is_cntrl_char(*line)) goal -= 2; else goal -= 1; @@ -2164,10 +2161,10 @@ /* We are trying to break a chunk off line. We find the last space such * that the display length to there is at most goal + 1. If there is no - * such space, and force is not 0, then we find the first space. + * such space, and force is TRUE, then we find the first space. * Anyway, we then take the last space in that group of spaces. The * terminating '\0' counts as a space. */ -int break_line(const char *line, int goal, int force) +int break_line(const char *line, int goal, bool force) { /* Note that we use int instead of size_t, since goal is at most * COLS, the screen width, which will always be reasonably small. */ @@ -2326,7 +2323,7 @@ /* If full_justify is TRUE, justify the entire file. Otherwise, justify * the current paragraph. */ -void do_justify(int full_justify) +void do_justify(bool full_justify) { filestruct *first_par_line = NULL; /* Will be the first line of the resulting justified paragraph. @@ -2874,7 +2871,7 @@ siglongjmp(jmpbuf, 1); } -void allow_pending_sigwinch(int allow) +void allow_pending_sigwinch(bool allow) { sigset_t winch; sigemptyset(&winch); @@ -2889,7 +2886,7 @@ #ifndef NANO_SMALL void do_toggle(const toggle *which) { - int enabled; + bool enabled; /* Even easier! */ TOGGLE(which->flag); @@ -2999,9 +2996,9 @@ { int optchr; int startline = 0; /* Line to try and start at */ - int fill_flag_used = FALSE; /* Was the fill option used? */ + bool fill_flag_used = FALSE; /* Was the fill option used? */ const shortcut *s; - int keyhandled = FALSE; /* Have we handled the keystroke yet? */ + bool keyhandled = FALSE; /* Have we handled the keystroke yet? */ int kbinput; /* Input from keyboard */ int meta_key; @@ -3154,7 +3151,7 @@ break; #endif case 'T': - if (parse_num(optarg, &tabsize) == -1 || tabsize <= 0) { + if (!parse_num(optarg, &tabsize) || tabsize <= 0) { fprintf(stderr, _("Requested tab size %s invalid\n"), optarg); exit(1); } @@ -3202,7 +3199,7 @@ break; #ifndef DISABLE_WRAPJUSTIFY case 'r': - if (parse_num(optarg, &wrap_at) == -1) { + if (!parse_num(optarg, &wrap_at)) { fprintf(stderr, _("Requested fill size %s invalid\n"), optarg); exit(1); } diff -u -r nano/src/proto.h nano-test/src/proto.h --- nano/src/proto.h 2004-08-02 18:37:54.000000000 -0400 +++ nano-test/src/proto.h 2004-08-02 19:51:41.000000000 -0400 @@ -265,7 +265,7 @@ void die_save_file(const char *die_filename); void die_too_small(void); void print_view_warning(void); -void global_init(int save_cutbuffer); +void global_init(bool save_cutbuffer); void window_init(void); #ifndef DISABLE_MOUSE void mouse_init(void); @@ -291,7 +291,7 @@ void nano_disabled_msg(void); #ifndef NANO_SMALL RETSIGTYPE cancel_fork(int signal); -int open_pipe(const char *command); +bool open_pipe(const char *command); #endif #ifndef DISABLE_MOUSE void do_mouse(void); @@ -309,11 +309,11 @@ #endif #ifndef DISABLE_WRAPPING void wrap_reset(void); -int do_wrap(filestruct *inptr); +bool do_wrap(filestruct *inptr); #endif #ifndef DISABLE_SPELLER -int do_int_spell_fix(const char *word); -const char *do_int_speller(char *tempfile_name); +bool do_int_spell_fix(const char *word); +const char *do_int_speller(const char *tempfile_name); const char *do_alt_speller(char *tempfile_name); void do_spell(void); #endif @@ -323,8 +323,8 @@ #ifndef DISABLE_JUSTIFY void justify_format(filestruct *line, size_t skip); size_t quote_length(const char *line); -int quotes_match(const char *a_line, size_t a_quote, const char *b_line); -size_t indents_match(const char *a_line, size_t a_indent, const char +bool quotes_match(const char *a_line, size_t a_quote, const char *b_line); +bool indents_match(const char *a_line, size_t a_indent, const char *b_line, size_t b_indent); bool begpar(const filestruct *const foo); void do_para_begin(void); @@ -332,10 +332,10 @@ void do_para_end(void); filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t quote_len); -int breakable(const char *line, int goal); -int break_line(const char *line, int goal, int force); +bool breakable(const char *line, int goal); +int break_line(const char *line, int goal, bool force); bool do_para_search(size_t *const quote, size_t *const par); -void do_justify(int full_justify); +void do_justify(bool full_justify); void do_justify_void(void); void do_full_justify(void); #endif /* !DISABLE_JUSTIFY */ @@ -346,7 +346,7 @@ RETSIGTYPE do_cont(int signal); #ifndef NANO_SMALL void handle_sigwinch(int s); -void allow_pending_sigwinch(int allow); +void allow_pending_sigwinch(bool allow); #endif #ifndef NANO_SMALL void do_toggle(const toggle *which);