diff -u -r nano/src/files.c nano-boo/src/files.c --- nano/src/files.c 2004-08-02 18:37:54.000000000 -0400 +++ nano-boo/src/files.c 2004-08-05 17:02:49.000000000 -0400 @@ -338,8 +338,9 @@ return; } -/* Open the file (and decide if it exists). */ -int open_file(const char *filename, int insert, int quiet) +/* Open the file (and decide if it exists). Return TRUE on success, + * FALSE on failure. */ +bool open_file(const char *filename, int insert, int quiet) { int fd; FILE *f; @@ -348,7 +349,7 @@ if (filename[0] == '\0' || stat(filename, &fileinfo) == -1) { if (insert && !quiet) { statusbar(_("\"%s\" not found"), filename); - return -1; + return FALSE; } else { /* We have a new file */ statusbar(_("New File")); @@ -361,7 +362,7 @@ _("File \"%s\" is a device file"), filename); if (!insert) new_file(); - return -1; + return FALSE; } else if ((fd = open(filename, O_RDONLY)) == -1) { /* If we're in multibuffer mode, don't be quiet when an error occurs while opening a file */ @@ -373,7 +374,7 @@ statusbar("%s: %s", strerror(errno), filename); if (!insert) new_file(); - return -1; + return FALSE; } else { /* File is A-OK */ if (!quiet) statusbar(_("Reading File")); @@ -381,7 +382,7 @@ if (f == NULL) { nperror("fdopen"); close(fd); - return -1; + return FALSE; } read_file(f, filename, quiet); #ifndef NANO_SMALL @@ -389,7 +390,7 @@ #endif } - return 1; + return TRUE; } /* This function will return the name of the first available extension @@ -426,6 +427,8 @@ void do_insertfile(int loading_file) { int i, old_current_x = current_x; + bool opened; + /* True if the file opened successfully. */ char *realname = NULL; static char *inspath = NULL; @@ -550,14 +553,13 @@ #ifndef NANO_SMALL if (i == NANO_EXTCMD_KEY) { realname = mallocstrcpy(realname, ""); - i = open_pipe(answer); - } else { + opened = open_pipe(answer); + } else #endif + { realname = real_dir_from_tilde(answer); - i = open_file(realname, TRUE, loading_file); -#ifndef NANO_SMALL + opened = open_file(realname, TRUE, loading_file); } -#endif #ifdef ENABLE_MULTIBUFFER if (loading_file) { @@ -566,7 +568,7 @@ created to hold the file), reload the buffer we had open before, and skip the insertion; otherwise, save realname in filename and continue the insertion */ - if (i == -1) { + if (!opened) { free(realname); free(fileage); load_open_file(); @@ -597,20 +599,11 @@ /* And re-init the shortcut list */ shortcut_init(FALSE); - } -#endif - -#ifdef ENABLE_MULTIBUFFER - if (!loading_file) { + } else #endif - /* Restore the old x-coordinate position */ current_x = old_current_x; -#ifdef ENABLE_MULTIBUFFER - } -#endif - /* If we've gone off the bottom, recenter; otherwise, just redraw */ edit_refresh(); diff -u -r nano/src/nano.c nano-boo/src/nano.c --- nano/src/nano.c 2004-08-05 16:01:39.000000000 -0400 +++ nano-boo/src/nano.c 2004-08-05 17:02:49.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 @@ -159,7 +159,7 @@ void die_save_file(const char *die_filename) { char *ret; - int i = -1; + bool succeeded = FALSE; /* If we're using restricted mode, don't write any emergency backup * files, since that would allow reading from or writing to files @@ -180,9 +180,9 @@ free(buf); } if (ret[0] != '\0') - i = write_file(ret, TRUE, FALSE, TRUE); + succeeded = -1 != write_file(ret, TRUE, FALSE, TRUE); - if (i != -1) + if (succeeded) fprintf(stderr, _("\nBuffer written to %s\n"), ret); else fprintf(stderr, _("\nNo %s written (too many backup files?)\n"), ret); @@ -203,8 +203,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; @@ -393,12 +393,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")); @@ -420,18 +420,18 @@ /* Now add our shortcut info. */ for (s = currshortcut; s != NULL; s = s->next) { - int meta_shortcut = FALSE; + bool meta_shortcut = FALSE; /* TRUE if the character in s->metaval is shown in the * first column. */ 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 @@ -441,7 +441,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)); } @@ -794,26 +794,25 @@ nperror("kill"); } -int open_pipe(const char *command) +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. - * - * I use this variable since it is important to put things back when - * we finish, even if we get errors. */ + 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. */ /* Make our pipes. */ if (pipe(fd) == -1) { statusbar(_("Could not pipe")); - return 1; + return FALSE; } /* Fork a child. */ @@ -823,7 +822,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); } @@ -835,7 +834,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 @@ -846,12 +845,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"); } } @@ -860,9 +859,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)) @@ -871,14 +870,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 */ @@ -891,7 +890,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; @@ -938,7 +937,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 @@ -1026,7 +1025,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()? */ @@ -1248,7 +1247,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. */ @@ -1264,7 +1263,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) */ @@ -1447,8 +1446,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; @@ -1456,12 +1455,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. */ @@ -1493,7 +1492,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 @@ -1501,7 +1500,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); @@ -1534,12 +1533,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; @@ -1735,7 +1734,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 @@ -1791,25 +1790,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. */ @@ -1856,11 +1853,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 */ @@ -1904,7 +1900,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') @@ -1969,7 +1965,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 ^. */ @@ -1987,7 +1983,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)); @@ -1997,7 +1993,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)); @@ -2153,13 +2149,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; @@ -2171,10 +2167,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. */ @@ -2333,7 +2329,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. @@ -2881,7 +2877,7 @@ siglongjmp(jmpbuf, 1); } -void allow_pending_sigwinch(int allow) +void allow_pending_sigwinch(bool allow) { sigset_t winch; sigemptyset(&winch); @@ -2896,7 +2892,7 @@ #ifndef NANO_SMALL void do_toggle(const toggle *which) { - int enabled; + bool enabled; /* Even easier! */ TOGGLE(which->flag); @@ -3006,9 +3002,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; diff -u -r nano/src/proto.h nano-boo/src/proto.h --- nano/src/proto.h 2004-08-04 18:47:34.000000000 -0400 +++ nano-boo/src/proto.h 2004-08-05 17:02:49.000000000 -0400 @@ -165,7 +165,7 @@ filestruct *read_line(char *buf, filestruct *prev, int *line1ins, size_t len); void read_file(FILE *f, const char *filename, int quiet); -int open_file(const char *filename, int insert, int quiet); +bool open_file(const char *filename, int insert, int quiet); char *get_next_filename(const char *name); void do_insertfile(int loading_file); void do_insertfile_void(void); @@ -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);