From: David Lawrence Ramsey Date: Fri, 28 Jun 2002 22:45:14 +0000 (+0000) Subject: Carl Drinkwater's backup patch, plus miscellaneous fixes by David X-Git-Tag: v1.1.10~17 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5db0cdc4c9228b5eeee6880eaf8ba989b7961cbd;p=nano.git Carl Drinkwater's backup patch, plus miscellaneous fixes by David Benbennick and me git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1225 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 92d073c8..9ba6553d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,36 @@ CVS Code - and spacing improvements. (David Benbennick) - Make more functions use const variables when possible. (David Benbennick) + - Add Carl Drinkwater's backup file option (-B or --backup on the + command line, M-B in nano's global shortcuts). If the original + file is unchanged from when it was loaded, it is backed up to + filename~; if the original file has been changed or deleted + since it was originally loaded, it isn't backed up. The backup + file retains the permissions, owner/group, and + access/modification times of the original file. This option is + disabled when --enable-tiny is used. It will not back up + temporary files. Minor fixes to it by David Benbennick and + DLR. Changes to open_file(), add_open_file(), + load_open_file(), write_file(), and do_writeout(). + - Add \n's to the ends of "filename is %s" debugging strings. + (Carl Drinkwater) + - Add the long option --quotestr as an alternative for -Q, and + --regexp as an alternative for -R; they were listed in nano's + usage information, but weren't actually in nano. Also, display + "-?" as an alternative for "-h" in nano's usage information, + put the command line options in a more consistent (i. e. mostly + alphabetical) order in nano, put the long options in a more + consistent order in rcfile.c and nanorc.sample, don't include + rcfile options if their equivalent command line options are + disabled, and remove obsolete relative option from + nanorc.sample. (DLR) + - Change "File Name to Append/Prepend" to "File Name to + Append/Prepend to". The original prompt could confusingly + imply that we are appending/prepending another file to the + current file, when we are actually appending/prepending the + current file to another file. (DLR) + - Put nano.1, nano.1.html, and nano.texi up to date. (DLR) + - Typo fixes for the ChangeLog. (David Benbennick) - files.c: read_file(), read_line(): - Rework to properly handle nulls in the input file, fix @@ -31,10 +61,25 @@ CVS Code - writing a marked selection to a file, save and restore totsize so it isn't decreased by the size of the selection afterward. (DLR) + do_writeout(): + - Fix problem with formatstr's being defined as NULL when + --enable-tiny is used. Since formatstr isn't ever used in tiny + mode, don't bother even creating the variable. (David + Benbennick and DLR) append_slash_if_dir(), input_tab(): - Changed a variable name: lastWasTab -> lastwastab. (DLR) - global.c: - shortcut_init() + free_toggles(): + - Only include if we're not using tiny mode. (David Benbennick) + toggle_init(): + - Remove global entries for search toggles, as they aren't really + global. (DLR) + - Don't reinititialize the toggles if they've already been + initialized; it's unnecessary and even causes a segfault in + do_toggle() if Pico emulation mode is the toggle in question. + Don't free the toggles here, either; it's unnecessary after the + above change. (David Benbennick) + shortcut_init(): - Rework IFHELP macro (David Benbennick). - move.c: page_down(), page_up(): @@ -52,6 +97,11 @@ CVS Code - do_int_spell(), do_alt_spell(): - Rework to save the marked selection before doing spell checking and restore it afterward. (DLR) + do_toggle(): + - Since the search mode toggles aren't global anymore, we don't + need to explicitly block them here anymore (which will end up + blocking the global backup mode toggle, which is the same as + the backwards search toggle). (DLR) main(): - Rework to blank out filename manually before doing anything with it, instead of calling clear_filename() in two places. @@ -59,7 +109,15 @@ CVS Code - hold a line number. (DLR) - Properly handle multiple -r settings on the command line. (Carl Drinkwater) +- rcfile.c: + colortoint(): + - Only include if ENABLE_COLOR is defined. (DLR) - search.c: + search_init(): + - Since the search mode toggles aren't global anymore, rework the + part of this function referencing them so that they still work. + (DLR) + - Remove unneeded toggles variable. (David Benbennick) findnextstr(): - Update the current line at current_x if we don't find a match. Also, pass current_x_find to strstrwrapper() so we know whether @@ -95,7 +153,7 @@ CVS Code - better on smaller terminals. (Carl Drinkwater) update_line(): - When marking control characters, make sure the mark moves - forward by two characters inctead of one. Rework control + forward by two characters instead of one. Rework control character display routine to display newlines within the line (which should never occur under normal circumstances; they will only be there if the line had nulls in it and was unsunder()ed @@ -106,6 +164,7 @@ CVS Code - with TERM=ansi). (DLR) - THANKS: - Completed a bit (Jordi). + - Fixed David Benbennick's email address (David Benbennick). GNU nano 1.1.9 - 05/12/2002 - General: - Typos n misspellings all over the place (David Benbennick). @@ -119,7 +178,7 @@ GNU nano 1.1.9 - 05/12/2002 - Preliminary prepend code. This may be a bad idea, but I've been wanting it for awhile now and we'll see how bad it messes everything up. Changes to files.c:do_writeout(), write_file(). - Fixes for O_CREAT & append compatibililty by David Benbennick. + Fixes for O_CREAT & append compatibility by David Benbennick. - Change from read() and write() to file streams by Jay Carlson. Allows OS to implement read and write ahead rather than making us do it. Hopefully merged properly. @@ -133,8 +192,8 @@ GNU nano 1.1.9 - 05/12/2002 to specify the type on the command line, if there's no good filename regex to use. Global variable syntaxstr. - Changed many strcmp()s and strcpy()s to their equivalent - '\0' conterparts (David Lawrence Ramsey). - - Many chanes to allow marked cutting to work with multiple + '\0' counterparts (David Lawrence Ramsey). + - Many changes to allow marked cutting to work with multiple file buffers: changes to openfilestruct type in nano.h and files.c (David Lawrence Ramsey). - Changed NANO_SMALL to ENABLE_NLS for gettext disabling @@ -162,7 +221,7 @@ GNU nano 1.1.9 - 05/12/2002 do_wrap() - Complete rewrite (David Benbennick). help_init() - - A little les readable, a lot shorer :-) (David Benbennick). + - A little less readable, a lot shorter :-) (David Benbennick). - Fix Meta-A not getting capitalized, and convert the ASCII #s to their character equivalent. main() @@ -187,7 +246,7 @@ GNU nano 1.1.9 - 05/12/2002 - Changed some syntax highlight computations for the sake of COLS. - Add in the necessary regfree() calls to stop nano from leaking memory like a sieve when using color syntax highlighting :-) - botombars(), onekey() + bottombars(), onekey() - Cleanups (David Benbennick). - po/gl.po: - Galician translation updates (Jacobo Tarrio). @@ -311,7 +370,7 @@ GNU nano 1.1.7 - 03/05/2002 - malloc->calloc, etc cleanups (DLR). - New option, noconvert (-N, --noconvert) to completely stop the translation of files from DOS or Mac format (DLR). - - New functions wheck_writable_directory() and safe_tempnam() + - New functions check_writable_directory() and safe_tempnam() to get around the tempnam warning. More improvements (DLR) Still needs testing. - Added DOS and Mac format options to write file routine. @@ -346,7 +405,7 @@ GNU nano 1.1.7 - 03/05/2002 - Added call to AM_ACLOCAL_INCLUDE. - files.c: read_byte() - - Added check for conrol characters (indicative of a binary + - Added check for control characters (indicative of a binary file), set NO_CONVERT if found (fixes by DLR). do_insertfile() - Added support for -o in prompt (Steven Kneizys). @@ -380,7 +439,7 @@ GNU nano 1.1.7 - 03/05/2002 - Fixes for various search issues (Ken Tyler) - winio.c: do_cursorpos() - - Rewritten to show col place as well as charcter place, without + - Rewritten to show col place as well as character place, without needing an entirely separate flag. bottombars(), onekey() - Make bottom list dynamic with screen size (Guus Sliepen & Chris). @@ -428,7 +487,7 @@ GNU nano 1.1.7 - 03/05/2002 nano-1.1.6 - 01/25/2002 - General - - Add Meta-A as alternate keyystroke for ^^ for people with + - Add Meta-A as alternate keystroke for ^^ for people with non-US keyboards. - Add Alt-G (NANO_ALT_GOTO_KEY) as alternate for goto dir in browser. @@ -473,7 +532,7 @@ nano-1.1.6 - 01/25/2002 - nano.h: - Changed color struct slightly, because of previous issue with applying color painting in order, the "str" portion was - uselss. Renamed "val" in colortype to "start", added "end" + useless. Renamed "val" in colortype to "start", added "end" for multi-line color strings. - rcfile.c: General @@ -482,7 +541,7 @@ nano-1.1.6 - 01/25/2002 - Re-indented. - Added stdarg.h to includes. rcfile_error() - - Now automatically prpends the "error in line blah at foo" + - Now automatically prepends the "error in line blah at foo" message to error messages. parse_colors() - Added section for computing "end" section. @@ -548,7 +607,7 @@ nano-1.1.5 - 01/05/2002 suspending nano on the Hurd. help_init() - Typo fixes in help strings (Jordi). - - New variable helplen needes cause currslen is not always + - New variable helplen needed cause currslen is not always the length we want (bug found by David Lawrence Ramsey). - Typo in file switch string (found by David Lawrence Ramsey). main() @@ -870,8 +929,8 @@ nano-1.1.0 - 07/15/2001 --enable-nanorc is used. Tons of new funcs, most notably do_rcfile() called from nano.c:main(). Added much needed function ncalloc(), will have to go through source code later - and change the aproproate calls which used nmalloc for lack of - an apropriate calloc function *** FIXME *** + and change the appropriate calls which used nmalloc for lack of + an appropriate calloc function *** FIXME *** - After "Alternate" spell checker is called, cursor is repositioned on the same line as before ^T was pressed. - Moved config.h up in all .c files #include list (Albert Chin). @@ -885,10 +944,10 @@ nano-1.1.0 - 07/15/2001 and justify being disabled. This allows us to compile out the -r flag if neither are set, and will also allow us to comment out -W when it is written. - - Allow fill to take a negative value ot signify a "from right side" + - Allow fill to take a negative value to signify a "from right side" value. This allows the value to vary with the screen size yet still be correct. New static value wrap_at to minimize code - inpact. Updated man page and info file. + impact. Updated man page and info file. - Allow file appending. New shortcut list nano_insertfile_list (since insert and write routines can't share shortcut lists anymore), new args to do_writeout and write_file called append, and of source @@ -963,7 +1022,7 @@ nano-1.1.0 - 07/15/2001 down, etc, and add the consistent ^C to exit (Jim Knoble). do_writeout() - New code to allow writing selected text to a separate file. - When this is done, the current state is prserved. + When this is done, the current state is preserved. write_file() - New arg, nonamechange, means whether or not to update the current filename after writing the file out. diff --git a/THANKS b/THANKS index 67d64285..bb11d8dd 100644 --- a/THANKS +++ b/THANKS @@ -29,8 +29,7 @@ Miquel Vidal Catalan Translator Pauli Virtanen Finnish Translator Ben Armstrong Negative -r value idea, code -David Benbennick dbenbenn@polygon.math.cornell.edu> - Misc fixes and enhancements +David Benbennick Misc fixes and enhancements Thomas Dickey Curses help and advice Sven Guckes Advice and Advocacy Jim Knoble Pico compat for browser diff --git a/TODO b/TODO index 204be398..9f5ffb38 100644 --- a/TODO +++ b/TODO @@ -5,7 +5,7 @@ For version 1.2: - Single line scroll up/down? [DONE] - Color syntax highlighting? (certainly seems like there's a demand for it.) - .nanorc [DONE] -- Backup making (filename~)? +- Backup making (filename~)? [DONE] - Search (etc) string history [1.2] - Implement Pico's -j and -g flags, as they are pretty easy to do. [DONE] - Make mouse support work with clicking on the shortcuts (-m). Must diff --git a/files.c b/files.c index 3ec476d8..781ef0a5 100644 --- a/files.c +++ b/files.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -356,6 +357,9 @@ int open_file(const char *filename, int insert, int quiet) return -1; } read_file(f, filename, quiet); +#ifndef NANO_SMALL + stat(filename, &originalfilestat); +#endif } return 1; @@ -417,7 +421,7 @@ int do_insertfile(int loading_file) if (i != -1) { #ifdef DEBUG - fprintf(stderr, _("filename is %s"), answer); + fprintf(stderr, _("filename is %s\n"), answer); #endif #ifndef DISABLE_TABCOMP @@ -596,7 +600,7 @@ int add_open_file(int update) open_files and splice it in after the current one */ #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif tmp = make_new_opennode(NULL); @@ -607,6 +611,11 @@ int add_open_file(int update) /* save current filename */ open_files->filename = mallocstrcpy(open_files->filename, filename); +#ifndef NANO_SMALL + /* save the file's stat */ + open_files->originalfilestat = originalfilestat; +#endif + /* save current total number of lines */ open_files->file_totlines = totlines; @@ -649,7 +658,7 @@ int add_open_file(int update) } #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif return 0; @@ -668,6 +677,9 @@ int load_open_file(void) /* set up the filename, the file buffer, the total number of lines in the file, and the total file size */ filename = mallocstrcpy(filename, open_files->filename); +#ifndef NANO_SMALL + originalfilestat = open_files->originalfilestat; +#endif fileage = open_files->fileage; current = fileage; filebot = open_files->filebot; @@ -740,7 +752,7 @@ int open_prevfile(int closing_file) open_files = open_files->prev; #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif } @@ -752,7 +764,7 @@ int open_prevfile(int closing_file) open_files = open_files->next; #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif } @@ -804,7 +816,7 @@ int open_nextfile(int closing_file) open_files = open_files->next; #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif } @@ -815,7 +827,7 @@ int open_nextfile(int closing_file) open_files = open_files->prev; #ifdef DEBUG - fprintf(stderr, _("filename is %s"), open_files->filename); + fprintf(stderr, _("filename is %s\n"), open_files->filename); #endif } @@ -873,7 +885,7 @@ int close_open_file(void) } #endif /* MULTIBUFFER */ -#if !defined (DISABLE_SPELLER) || !defined (DISABLE_OPERATINGDIR) +#if !defined(DISABLE_SPELLER) || !defined(DISABLE_OPERATINGDIR) /* * When passed "[relative path]" or "[relative path][filename]" in * origpath, return "[full path]" or "[full path][filename]" on success, @@ -1283,6 +1295,75 @@ int write_file(char *name, int tmp, int append, int nonamechange) /* Save the state of file at the end of the symlink (if there is one) */ realexists = stat(realname, &st); +#ifndef NANO_SMALL + /* We backup only if the backup toggle is set, the file isn't + temporary, and the file already exists. Furthermore, if we aren't + appending, prepending, or writing a selection, also backup only if + the file has not been modified by someone else since nano opened + it. */ + if (ISSET(BACKUP_FILE) && !tmp && realexists == 0 && + (append || ISSET(MARK_ISSET) || + originalfilestat.st_mtime == st.st_mtime)) { + FILE *backup_file; + char *backupname = NULL; + char backupbuf[COPYFILEBLOCKSIZE]; + size_t bytesread; + struct utimbuf filetime; + + /* save the original file's access and modification times */ + filetime.actime = originalfilestat.st_atime; + filetime.modtime = originalfilestat.st_mtime; + + /* open the original file to copy to the backup */ + f = fopen(realname, "rb"); + if (!f) { + statusbar(_("Could not read %s for backup: %s"), realname, + strerror(errno)); + return -1; + } + + backupname = charalloc(strlen(realname) + 2); + sprintf(backupname, "%s~", realname); + + /* get a file descriptor for the destination backup file */ + backup_file = fopen(backupname, "wb"); + if (!backup_file) { + statusbar(_("Couldn't write backup: %s"), strerror(errno)); + free(backupname); + return -1; + } + +#ifdef DEBUG + fprintf(stderr, _("Backing up %s to %s\n"), realname, backupname); +#endif + + /* copy the file */ + while ((bytesread = fread(backupbuf, sizeof(char), + COPYFILEBLOCKSIZE, f)) > 0) + if (fwrite(backupbuf, sizeof(char), bytesread, backup_file) <= 0) + break; + fclose(backup_file); + fclose(f); + + if (chmod(backupname, originalfilestat.st_mode) == -1) + statusbar(_("Could not set permissions %o on backup %s: %s"), + originalfilestat.st_mode, backupname, + strerror(errno)); + + if (chown(backupname, originalfilestat.st_uid, + originalfilestat.st_gid) == -1) + statusbar(_("Could not set owner %d/group %d on backup %s: %s"), + originalfilestat.st_uid, originalfilestat.st_gid, + backupname, strerror(errno)); + + if (utime(backupname, &filetime) == -1) + statusbar(_("Could not set access/modification time on backup %s: %s"), + backupname, strerror(errno)); + + free(backupname); + } +#endif + /* Stat the link itself for the check... */ anyexists = lstat(realname, &lst); @@ -1368,7 +1449,6 @@ int write_file(char *name, int tmp, int append, int nonamechange) else fprintf(stderr, _("Wrote >%s\n"), fileptr->data); #endif - #ifndef NANO_SMALL if (ISSET(DOS_FILE) || ISSET(MAC_FILE)) putc('\r', f); @@ -1424,7 +1504,6 @@ int write_file(char *name, int tmp, int append, int nonamechange) } } - if (fclose(f)) { statusbar(_("Could not close %s: %s"), realname, strerror(errno)); unlink(buf); @@ -1481,7 +1560,6 @@ int write_file(char *name, int tmp, int append, int nonamechange) fclose(f_dest); } - if (realexists == -1 || tmp || (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) { @@ -1489,7 +1567,7 @@ int write_file(char *name, int tmp, int append, int nonamechange) mask = umask(0); umask(mask); - if (tmp) /* We don't want anyone reading our temporary file! */ + if (tmp) /* We don't want anyone reading our temporary file! */ mask = 0600; else mask = 0666 & ~mask; @@ -1529,6 +1607,10 @@ int write_file(char *name, int tmp, int append, int nonamechange) if (!nonamechange) filename = mallocstrcpy(filename, realname); +#ifndef NANO_SMALL + /* Update originalfilestat to reference the file as it is now. */ + stat(filename, &originalfilestat); +#endif statusbar(_("Wrote %d lines"), lineswritten); UNSET(MODIFIED); titlebar(NULL); @@ -1539,8 +1621,9 @@ int write_file(char *name, int tmp, int append, int nonamechange) int do_writeout(char *path, int exiting, int append) { int i = 0; - char *formatstr = NULL; - +#ifndef NANO_SMALL + const char *formatstr, *backupstr; +#endif #ifdef NANO_EXTRA static int did_cred = 0; #endif @@ -1568,7 +1651,6 @@ int do_writeout(char *path, int exiting, int append) while (1) { #ifndef NANO_SMALL - if (ISSET(MAC_FILE)) formatstr = _(" [Mac Format]"); else if (ISSET(DOS_FILE)) @@ -1576,31 +1658,44 @@ int do_writeout(char *path, int exiting, int append) else formatstr = ""; + if (ISSET(BACKUP_FILE)) + backupstr = _(" [Backup]"); + else + backupstr = ""; + /* Be nice to the translation folks */ if (ISSET(MARK_ISSET) && !exiting) { if (append == 2) i = statusq(1, writefile_list, "", - "%s%s", _("Prepend Selection to File"), formatstr); + "%s%s%s", _("Prepend Selection to File"), formatstr, backupstr); else if (append) i = statusq(1, writefile_list, "", - "%s%s", _("Append Selection to File"), formatstr); + "%s%s%s", _("Append Selection to File"), formatstr, backupstr); else i = statusq(1, writefile_list, "", - "%s%s", _("Write Selection to File"), formatstr); - } else -#endif - { + "%s%s%s", _("Write Selection to File"), formatstr, backupstr); + } else { if (append == 2) i = statusq(1, writefile_list, answer, - "%s%s", _("File Name to Prepend"), formatstr); + "%s%s%s", _("File Name to Prepend to"), formatstr, backupstr); else if (append) i = statusq(1, writefile_list, answer, - "%s%s", _("File Name to Append"), formatstr); + "%s%s%s", _("File Name to Append to"), formatstr, backupstr); else i = statusq(1, writefile_list, answer, - "%s%s", _("File Name to Write"), formatstr); - + "%s%s%s", _("File Name to Write"), formatstr, backupstr); } +#else + if (append == 2) + i = statusq(1, writefile_list, answer, + "%s", _("File Name to Prepend to")); + else if (append) + i = statusq(1, writefile_list, answer, + "%s", _("File Name to Append to")); + else + i = statusq(1, writefile_list, answer, + "%s", _("File Name to Write")); +#endif /* !NANO_SMALL */ if (i != -1) { @@ -1627,13 +1722,18 @@ int do_writeout(char *path, int exiting, int append) UNSET(DOS_FILE); TOGGLE(MAC_FILE); return(do_writeout(answer, exiting, append)); +#ifndef NANO_SMALL + } else if (i == TOGGLE_BACKUP_KEY) { + TOGGLE(BACKUP_FILE); + return(do_writeout(answer, exiting, append)); +#endif } else if (i == NANO_PREPEND_KEY) return(do_writeout(answer, exiting, append == 2 ? 0 : 2)); else if (i == NANO_APPEND_KEY) return(do_writeout(answer, exiting, append == 1 ? 0 : 1)); #ifdef DEBUG - fprintf(stderr, _("filename is %s"), answer); + fprintf(stderr, _("filename is %s\n"), answer); #endif #ifdef NANO_EXTRA @@ -1653,8 +1753,8 @@ int do_writeout(char *path, int exiting, int append) continue; } } -#ifndef NANO_SMALL +#ifndef NANO_SMALL /* Here's where we allow the selected text to be written to a separate file. */ if (ISSET(MARK_ISSET) && !exiting) { @@ -1692,7 +1792,8 @@ int do_writeout(char *path, int exiting, int append) if (oldmod) set_modified(); } else -#endif +#endif /* !NANO_SMALL */ + i = write_file(answer, 0, append, 0); #ifdef ENABLE_MULTIBUFFER @@ -2357,7 +2458,7 @@ char *do_browser(char *inpath) blank_statusbar_refresh(); -#if !defined DISABLE_HELP || !defined(DISABLE_MOUSE) +#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE) currshortcut = browser_list; #endif diff --git a/global.c b/global.c index e31373f4..37b569ae 100644 --- a/global.c +++ b/global.c @@ -42,6 +42,11 @@ WINDOW *edit; /* The file portion of the editor */ WINDOW *topwin; /* Top line of screen */ WINDOW *bottomwin; /* Bottom buffer */ char *filename = NULL; /* Name of the file */ + +#ifndef NANO_SMALL +struct stat originalfilestat; /* Stat for the file as we loaded it */ +#endif + int editwinrows = 0; /* How many rows long is the edit window? */ filestruct *current; /* Current buffer pointer */ @@ -114,7 +119,7 @@ shortcut *browser_list = NULL; char *syntaxstr = NULL; #endif -#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP) +#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined(DISABLE_HELP) shortcut *currshortcut; /* Current shortcut list we're using */ #endif @@ -153,7 +158,7 @@ static void sc_init_one(shortcut **shortcutage, int key, const char *desc, #ifndef DISABLE_HELP const char *help, -#endif /* !DISABLE_HELP */ +#endif int alt, int misc1, int misc2, int view, int (*func) (void)) { @@ -173,7 +178,7 @@ static void sc_init_one(shortcut **shortcutage, int key, s->desc = desc; #ifndef DISABLE_HELP s->help = help; -#endif /* !DISABLE_HELP */ +#endif s->altval = alt; s->misc1 = misc1; s->misc2 = misc2; @@ -205,6 +210,7 @@ static void toggle_init_one(int val, const char *desc, int flag) u->next = NULL; } +#ifdef DEBUG /* Deallocate all of the toggles */ static void free_toggles(void) { @@ -217,23 +223,27 @@ static void free_toggles(void) } toggles = NULL; } +#endif static void toggle_init(void) { char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg, *toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg, - *toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_case_msg, - *toggle_backwards_msg, *toggle_noconvert_msg, *toggle_dos_msg, - *toggle_mac_msg, *toggle_smooth_msg; - -#ifdef HAVE_REGEX_H - char *toggle_regexp_msg; -#endif + *toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_noconvert_msg, + *toggle_dos_msg, *toggle_mac_msg, *toggle_backup_msg, + *toggle_smooth_msg; #ifdef ENABLE_MULTIBUFFER char *toggle_load_msg; #endif + /* There is no need to reinitialize the toggles. They can't + change. In fact, reinitializing them causes a segfault in + nano.c:do_toggle() when it is called with the Pico-mode + toggle. */ + if (toggles != NULL) + return; + toggle_const_msg = _("Constant cursor position"); toggle_autoindent_msg = _("Auto indent"); toggle_suspend_msg = _("Suspend"); @@ -241,25 +251,16 @@ static void toggle_init(void) toggle_picomode_msg = _("Pico mode"); toggle_mouse_msg = _("Mouse support"); toggle_cuttoend_msg = _("Cut to end"); - toggle_backwards_msg = _("Backwards search"); - toggle_case_msg = _("Case sensitive search"); - -#ifdef HAVE_REGEX_H - toggle_regexp_msg = _("Regular expression search"); -#endif - toggle_noconvert_msg = _("No conversion from DOS/Mac format"); toggle_dos_msg = _("Writing file in DOS format"); toggle_mac_msg = _("Writing file in Mac format"); + toggle_backup_msg = _("Backing up file"); toggle_smooth_msg = _("Smooth scrolling"); toggle_wrap_msg = _("Auto wrap"); - #ifdef ENABLE_MULTIBUFFER toggle_load_msg = _("Multiple file buffers"); #endif - free_toggles(); - toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE); toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT); toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND); @@ -268,22 +269,17 @@ static void toggle_init(void) toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP); toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE); toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END); - toggle_init_one(TOGGLE_BACKWARDS_KEY, toggle_backwards_msg, REVERSE_SEARCH); - toggle_init_one(TOGGLE_CASE_KEY, toggle_case_msg, CASE_SENSITIVE); -#ifdef HAVE_REGEX_H - toggle_init_one(TOGGLE_REGEXP_KEY, toggle_regexp_msg, USE_REGEXP); -#endif #ifdef ENABLE_MULTIBUFFER toggle_init_one(TOGGLE_LOAD_KEY, toggle_load_msg, MULTIBUFFER); #endif toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT); toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE); toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE); + toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE); toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL); } #endif /* !NANO_SMALL */ - /* Deallocate the given shortcut. */ static void free_shortcutage(shortcut **shortcutage) { @@ -302,42 +298,40 @@ static void free_shortcutage(shortcut **shortcutage) void shortcut_init(int unjustify) { #ifndef DISABLE_HELP - char *nano_help_msg = "", *nano_writeout_msg = "", *nano_exit_msg = "", - *nano_goto_msg = "", *nano_justify_msg = "", *nano_replace_msg = - "", *nano_insert_msg = "", *nano_whereis_msg = - "", *nano_prevpage_msg = "", *nano_nextpage_msg = - "", *nano_cut_msg = "", *nano_uncut_msg = "", *nano_cursorpos_msg = + char *nano_help_msg = "", *nano_writeout_msg = "", *nano_exit_msg = + "", *nano_goto_msg = "", *nano_justify_msg = + "", *nano_replace_msg = "", *nano_insert_msg = + "", *nano_whereis_msg = "", *nano_prevpage_msg = + "", *nano_nextpage_msg = "", *nano_cut_msg = + "", *nano_uncut_msg = "", *nano_cursorpos_msg = "", *nano_spell_msg = "", *nano_up_msg = "", *nano_down_msg = "", *nano_forward_msg = "", *nano_back_msg = "", *nano_home_msg = "", *nano_end_msg = "", *nano_firstline_msg = "", *nano_lastline_msg = "", *nano_refresh_msg = "", *nano_mark_msg = "", *nano_delete_msg = "", *nano_backspace_msg = "", *nano_tab_msg = - "", *nano_enter_msg = "", *nano_cancel_msg = + "", *nano_enter_msg = "", *nano_cancel_msg = "", *nano_unjustify_msg = "", *nano_append_msg = - "", *nano_prepend_msg = ""; + "", *nano_prepend_msg = "", *nano_tofiles_msg = + "", *nano_gotodir_msg = "", *nano_case_msg = + "", *nano_reverse_msg = "", *nano_execute_msg = + "", *nano_dos_msg = "", *nano_mac_msg = + "", *nano_backup_msg = ""; #ifdef ENABLE_MULTIBUFFER char *nano_openprev_msg = "", *nano_opennext_msg = ""; #endif - - char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg = - "", *nano_reverse_msg = "", *nano_execute_msg = ""; - char *nano_dos_msg = "", *nano_mac_msg = ""; - #ifdef HAVE_REGEX_H char *nano_regexp_msg = "", *nano_bracket_msg = ""; #endif nano_help_msg = _("Invoke the help menu"); nano_writeout_msg = _("Write the current file to disk"); - #ifdef ENABLE_MULTIBUFFER nano_exit_msg = _("Close currently loaded file/Exit from nano"); #else nano_exit_msg = _("Exit from nano"); #endif - nano_goto_msg = _("Go to a specific line number"); nano_justify_msg = _("Justify the current paragraph"); nano_unjustify_msg = _("Unjustify after a justify"); @@ -349,7 +343,7 @@ void shortcut_init(int unjustify) nano_cut_msg = _("Cut the current line and store it in the cutbuffer"); nano_uncut_msg = _("Uncut from the cutbuffer into the current line"); nano_cursorpos_msg = _("Show the position of the cursor"); - nano_spell_msg = _("Invoke the spell checker (if available)"); + nano_spell_msg = _("Invoke the spell checker, if available"); nano_up_msg = _("Move up one line"); nano_down_msg = _("Move down one line"); nano_forward_msg = _("Move forward one character"); @@ -376,8 +370,11 @@ void shortcut_init(int unjustify) nano_reverse_msg = _("Search backwards"); nano_dos_msg = _("Write file out in DOS format"); nano_mac_msg = _("Write file out in Mac format"); +#ifndef NANO_SMALL + nano_backup_msg = _("Back up original file when saving"); +#endif #ifdef HAVE_REGEX_H - nano_regexp_msg = _("Use Regular expressions"); + nano_regexp_msg = _("Use regular expressions"); nano_bracket_msg = _("Find other bracket"); #endif #ifdef ENABLE_MULTIBUFFER @@ -408,6 +405,7 @@ void shortcut_init(int unjustify) do_exit); else #endif + sc_init_one(&main_list, NANO_EXIT_KEY, _("Exit"), IFHELP(nano_exit_msg, 0), NANO_EXIT_FKEY, 0, VIEW, do_exit); @@ -445,7 +443,6 @@ void shortcut_init(int unjustify) IFHELP(nano_insert_msg, 0), NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void); #endif - else sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"), IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY), @@ -484,7 +481,6 @@ void shortcut_init(int unjustify) IFHELP(nano_spell_msg, 0), NANO_SPELL_FKEY, 0, NOVIEW, do_spell); - sc_init_one(&main_list, NANO_UP_KEY, _("Up"), IFHELP(nano_up_msg, 0), KEY_UP, 0, VIEW, do_up); @@ -554,13 +550,11 @@ void shortcut_init(int unjustify) IFHELP(_("Move backward one word"), NANO_PREVWORD_KEY), 0, 0, VIEW, do_prev_word_void); #endif - -#if (!defined NANO_SMALL) && (defined HAVE_REGEX_H) +#if !defined(NANO_SMALL) && defined(HAVE_REGEX_H) sc_init_one(&main_list, -9, _("Find Other Bracket"), IFHELP(nano_bracket_msg, NANO_BRACKET_KEY), 0, 0, VIEW, do_find_bracket); #endif - #ifdef ENABLE_MULTIBUFFER sc_init_one(&main_list, -9, _("Previous File"), IFHELP(nano_openprev_msg, NANO_OPENPREV_KEY), @@ -703,6 +697,11 @@ void shortcut_init(int unjustify) sc_init_one(&writefile_list, NANO_PREPEND_KEY, _("Prepend"), IFHELP(nano_prepend_msg, 0), 0, 0, NOVIEW, 0); +#ifndef NANO_SMALL + sc_init_one(&writefile_list, TOGGLE_BACKUP_KEY, _("Backup File"), + IFHELP(nano_backup_msg, 0), 0, 0, NOVIEW, 0); +#endif + sc_init_one(&writefile_list, NANO_CANCEL_KEY, _("Cancel"), IFHELP(nano_cancel_msg, 0), 0, 0, VIEW, 0); @@ -742,7 +741,6 @@ void shortcut_init(int unjustify) #endif #ifndef DISABLE_BROWSER - free_shortcutage(&browser_list); sc_init_one(&browser_list, NANO_HELP_KEY, _("Get Help"), @@ -770,14 +768,11 @@ void shortcut_init(int unjustify) sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"), IFHELP(nano_cancel_msg, 0), 0, 0, VIEW, 0); - #endif - #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP) currshortcut = main_list; #endif - #ifndef NANO_SMALL toggle_init(); #endif diff --git a/nano.1 b/nano.1 index 79f01933..e4852ae3 100644 --- a/nano.1 +++ b/nano.1 @@ -6,7 +6,7 @@ .\" Public License for copying conditions. There is NO warranty. .\" .\" $Id$ -.TH NANO 1 "January 3, 2002" +.TH NANO 1 "June 27, 2002" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -31,11 +31,15 @@ also implements some missing (or disabled by default) features in Pico, such as "search and replace" and "goto line number". .SH OPTIONS .TP +.B \-B (\-\-backup) +When saving a file, back up the previous version of it to the current +filename suffixed with a ~. +.TP .B \-D (\-\-dos) Write file in DOS format. .TP .B \-F (\-\-multibuffer) -Enable multiple file buffers (if available). +Enable multiple file buffers, if available. .TP .B \-K (\-\-keypad) Do not use the ncurses keypad() call unless necessary. Try this flag if @@ -66,7 +70,8 @@ Set the size (width) of a tab. Show the current version number and author. .TP .B \-Y (\-\-syntax=[str]) -Specify a specific syntax highlighting from the .nanorc to use (if available). +Specify a specific syntax highlighting from the .nanorc to use, if +available. .TP .B \-c (\-\-const) Constantly show the cursor position. @@ -89,18 +94,19 @@ a new file, do not follow it. Good for editing files in /tmp, perhaps? Enable mouse support (if available for your system). .TP .B \-o [dir] (\-\-operatingdir=[dir]) -Set operating directory. Makes nano set up something similar to a chroot. +Set operating directory. Makes nano set up something similar to a +chroot. .TP .B \-p (\-\-pico) -Emulate Pico as closely as possible. This affects both the "shortcut list" -at the bottom of the screen, as well as the display and entry of previous -search and replace strings. +Emulate Pico as closely as possible. This affects both the "shortcut +list" at the bottom of the screen, as well as the display and entry of +previous search and replace strings. .TP .B \-r [#cols] (\-\-fill=[#cols]) -Wrap lines at column #cols. By default, this is the width of the screen, -less eight. If this value is negative, wrapping will occur at #cols from -the right of the screen, allowing it to vary along with the screen width -if the screen is resized. +Wrap lines at column #cols. By default, this is the width of the +screen, less eight. If this value is negative, wrapping will occur at +#cols from the right of the screen, allowing it to vary along with the +screen width if the screen is resized. .TP .B \-s [prog] (\-\-speller=[prog]) Enable alternative spell checker command. @@ -128,10 +134,10 @@ Places cursor at LINE on startup. .SH NOTES Nano will try to dump the buffer into an emergency file in some cases. Mainly, this will happen if Nano receives a SIGHUP or runs out of -memory, when it will write the buffer into a file named "nano.save" if the -buffer didn't have a name already, or will add a ".save" suffix to the -current filename. If an emergency file with that name already exists in -the current directory, ".save" and a number (e.g. ".save.1") will be +memory, when it will write the buffer into a file named "nano.save" if +the buffer didn't have a name already, or will add a ".save" suffix to +the current filename. If an emergency file with that name already exists +in the current directory, ".save" and a number (e.g. ".save.1") will be suffixed to the current filename in order to make it unique. In multibuffer mode, nano will write all the open buffers to the respective emergency files. diff --git a/nano.1.html b/nano.1.html index 2d15d649..86aaaa18 100644 --- a/nano.1.html +++ b/nano.1.html @@ -3,7 +3,7 @@ Content-type: text/html Manpage of NANO

NANO

-Section: User Commands (1)
Updated: January 3, 2002
Index +Section: User Commands (1)
Updated: June 27, 2002
Index Return to Main Contents
@@ -44,6 +44,11 @@ such as "search and replace" and "goto line number".

OPTIONS

+
-B (--backup) + +
+When saving a file, back up the previous version of it to the current +filename suffixed with a ~.
-D (--dos)
@@ -51,7 +56,7 @@ Write file in DOS format.
-F (--multibuffer)
-Enable multiple file buffers (if available). +Enable multiple file buffers, if available.
-K (--keypad)
@@ -91,7 +96,8 @@ Show the current version number and author.
-Y (--syntax=[str])
-Specify a specific syntax highlighting from the .nanorc to use (if available). +Specify a specific syntax highlighting from the .nanorc to use, if +available.
-c (--const)
@@ -121,20 +127,21 @@ Enable mouse support (if available for your system).
-o [dir] (--operatingdir=[dir])
-Set operating directory. Makes nano set up something similar to a chroot. +Set operating directory. Makes nano set up something similar to a +chroot.
-p (--pico)
-Emulate Pico as closely as possible. This affects both the "shortcut list" -at the bottom of the screen, as well as the display and entry of previous -search and replace strings. +Emulate Pico as closely as possible. This affects both the "shortcut +list" at the bottom of the screen, as well as the display and entry of +previous search and replace strings.
-r [#cols] (--fill=[#cols])
-Wrap lines at column #cols. By default, this is the width of the screen, -less eight. If this value is negative, wrapping will occur at #cols from -the right of the screen, allowing it to vary along with the screen width -if the screen is resized. +Wrap lines at column #cols. By default, this is the width of the +screen, less eight. If this value is negative, wrapping will occur at +#cols from the right of the screen, allowing it to vary along with the +screen width if the screen is resized.
-s [prog] (--speller=[prog])
@@ -173,10 +180,10 @@ Places cursor at LINE on startup. Nano will try to dump the buffer into an emergency file in some cases. Mainly, this will happen if Nano receives a SIGHUP or runs out of -memory, when it will write the buffer into a file named "nano.save" if the -buffer didn't have a name already, or will add a ".save" suffix to the -current filename. If an emergency file with that name already exists in -the current directory, ".save" and a number (e.g. ".save.1") will be +memory, when it will write the buffer into a file named "nano.save" if +the buffer didn't have a name already, or will add a ".save" suffix to +the current filename. If an emergency file with that name already exists +in the current directory, ".save" and a number (e.g. ".save.1") will be suffixed to the current filename in order to make it unique. In multibuffer mode, nano will write all the open buffers to the respective emergency files. @@ -227,6 +234,6 @@ used by others). This document was created by man2html, using the manual pages.
-Time: 19:17:30 GMT, May 08, 2002 +Time: 21:45:15 GMT, June 27, 2002 diff --git a/nano.c b/nano.c index 25f94a2f..104e35cd 100644 --- a/nano.c +++ b/nano.c @@ -464,7 +464,9 @@ void usage(void) printf(_("Option Meaning\n")); #endif /* HAVE_GETOPT_LONG */ + print1opt("-h, -?", "--help", _("Show this message")); #ifndef NANO_SMALL + print1opt("-B", "--backup", _("Backup existing files on save")); print1opt("-D", "--dos", _("Write file in DOS format")); #endif #ifdef ENABLE_MULTIBUFFER @@ -478,7 +480,9 @@ void usage(void) #ifndef DISABLE_JUSTIFY print1opt(_("-Q [str]"), _("--quotestr [str]"), _("Quoting string, default \"> \"")); #endif - +#ifdef HAVE_REGEX_H + print1opt("-R", "--regexp", _("Do regular expression searches")); +#endif #ifndef NANO_SMALL print1opt("-S", "--smooth", _("Smooth scrolling")); #endif @@ -488,7 +492,6 @@ void usage(void) print1opt(_("-Y [str]"), _("--syntax [str]"), _("Syntax definition to use")); #endif print1opt("-c", "--const", _("Constantly show cursor position")); - print1opt("-h", "--help", _("Show this message")); #ifndef NANO_SMALL print1opt("-i", "--autoindent", _("Automatically indent new lines")); print1opt("-k", "--cut", _("Let ^K cut from cursor to end of line")); @@ -503,7 +506,6 @@ void usage(void) print1opt(_("-o [dir]"), _("--operatingdir=[dir]"), _("Set operating directory")); #endif print1opt("-p", "--pico", _("Emulate Pico as closely as possible")); - #ifndef DISABLE_WRAPJUSTIFY print1opt(_("-r [#cols]"), _("--fill=[#cols]"), _("Set fill cols to (wrap lines at) #cols")); #endif @@ -2395,7 +2397,7 @@ int do_justify(void) strcpy(&tmpline->data[j], quotestr); /* Skip the white space in current. */ - memcpy(&tmpline->data[qdepth], current->data + i + 1, slen-qdepth); + memcpy(&tmpline->data[qdepth], current->data + i + 1, slen - qdepth); tmpline->data[slen] = '\0'; current->data = nrealloc(current->data, i + 1); @@ -2700,13 +2702,6 @@ void do_toggle(toggle *which) char *enabled = _("enabled"); char *disabled = _("disabled"); - switch (which->val) { - case TOGGLE_BACKWARDS_KEY: - case TOGGLE_CASE_KEY: - case TOGGLE_REGEXP_KEY: - return; - } - /* Even easier! */ TOGGLE(which->flag); @@ -2809,49 +2804,49 @@ int main(int argc, char *argv[]) #ifdef HAVE_GETOPT_LONG int option_index = 0; struct option long_options[] = { + {"help", 0, 0, 'h'}, +#ifdef ENABLE_MULTIBUFFER + {"multibuffer", 0, 0, 'F'}, +#endif + {"keypad", 0, 0, 'K'}, +#ifndef DISABLE_JUSTIFY + {"quotestr", 1, 0, 'Q'}, +#endif #ifdef HAVE_REGEX_H {"regexp", 0, 0, 'R'}, #endif + {"tabsize", 1, 0, 'T'}, {"version", 0, 0, 'V'}, - {"const", 0, 0, 'c'}, - {"suspend", 0, 0, 'z'}, - {"nowrap", 0, 0, 'w'}, - {"nohelp", 0, 0, 'x'}, - {"help", 0, 0, 'h'}, - {"view", 0, 0, 'v'}, -#ifndef NANO_SMALL - {"cut", 0, 0, 'k'}, - {"dos", 0, 0, 'D'}, - {"mac", 0, 0, 'M'}, - {"noconvert", 0, 0, 'N'}, - {"autoindent", 0, 0, 'i'}, -#endif - {"tempfile", 0, 0, 't'}, -#ifndef DISABLE_SPELLER - {"speller", 1, 0, 's'}, -#endif - -#ifndef DISABLE_WRAPJUSTIFY - {"fill", 1, 0, 'r'}, +#ifdef ENABLE_COLOR + {"syntax", 1, 0, 'Y'}, #endif + {"const", 0, 0, 'c'}, + {"nofollow", 0, 0, 'l'}, {"mouse", 0, 0, 'm'}, #ifndef DISABLE_OPERATINGDIR {"operatingdir", 1, 0, 'o'}, #endif {"pico", 0, 0, 'p'}, - {"nofollow", 0, 0, 'l'}, - {"tabsize", 1, 0, 'T'}, - -#ifdef ENABLE_MULTIBUFFER - {"multibuffer", 0, 0, 'F'}, +#ifndef DISABLE_WRAPJUSTIFY + {"fill", 1, 0, 'r'}, +#endif +#ifndef DISABLE_SPELLER + {"speller", 1, 0, 's'}, #endif + {"tempfile", 0, 0, 't'}, + {"view", 0, 0, 'v'}, + {"nowrap", 0, 0, 'w'}, + {"nohelp", 0, 0, 'x'}, + {"suspend", 0, 0, 'z'}, #ifndef NANO_SMALL + {"backup", 0, 0, 'B'}, + {"dos", 0, 0, 'D'}, + {"mac", 0, 0, 'M'}, + {"noconvert", 0, 0, 'N'}, {"smooth", 0, 0, 'S'}, + {"autoindent", 0, 0, 'i'}, + {"cut", 0, 0, 'k'}, #endif -#ifdef ENABLE_COLOR - {"syntax", 1, 0, 'Y'}, -#endif - {"keypad", 0, 0, 'K'}, {0, 0, 0, 0} }; #endif @@ -2872,16 +2867,31 @@ int main(int argc, char *argv[]) #endif /* ENABLE_NANORC */ #ifdef HAVE_GETOPT_LONG - while ((optchr = getopt_long(argc, argv, "h?DFKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz", + while ((optchr = getopt_long(argc, argv, "h?BDFKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz", long_options, &option_index)) != EOF) { #else while ((optchr = - getopt(argc, argv, "h?DFKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz")) != EOF) { + getopt(argc, argv, "h?BDFKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz")) != EOF) { #endif switch (optchr) { + case 'h': + case '?': + usage(); + exit(0); + case 'a': + case 'b': + case 'e': + case 'f': + case 'g': + case 'j': + /* Pico compatibility flags */ + break; #ifndef NANO_SMALL + case 'B': + SET(BACKUP_FILE); + break; case 'D': SET(DOS_FILE); break; @@ -2935,21 +2945,9 @@ int main(int argc, char *argv[]) syntaxstr = mallocstrcpy(syntaxstr, optarg); break; #endif - case 'a': - case 'b': - case 'e': - case 'f': - case 'g': - case 'j': - /* Pico compatibility flags */ - break; case 'c': SET(CONSTUPDATE); break; - case 'h': - case '?': - usage(); - exit(0); #ifndef NANO_SMALL case 'i': SET(AUTOINDENT); @@ -3026,7 +3024,6 @@ int main(int argc, char *argv[]) usage(); exit(0); } - } /* Clear the filename we'll be using */ diff --git a/nano.h b/nano.h index 1fb406f8..7cb9d477 100644 --- a/nano.h +++ b/nano.h @@ -36,6 +36,10 @@ #define ISSET(bit) (flags & bit) #define TOGGLE(bit) flags ^= bit +#ifndef NANO_SMALL + /* For the backup file copy ... */ +# define COPYFILEBLOCKSIZE 1024 +#endif #ifdef USE_SLANG /* Slang support enabled */ #include @@ -50,6 +54,8 @@ #include #endif +#include +#include #include "config.h" #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) @@ -79,6 +85,9 @@ typedef struct filestruct { #ifdef ENABLE_MULTIBUFFER typedef struct openfilestruct { char *filename; +#ifndef NANO_SMALL + struct stat originalfilestat; +#endif struct openfilestruct *next; /* Next node */ struct openfilestruct *prev; /* Previous node */ struct filestruct *fileage; /* Current file */ @@ -190,6 +199,7 @@ typedef struct syntaxtype { #define DISABLE_CURPOS (1<<24) /* Damn, we still need it */ #define ALT_KEYPAD (1<<25) #define NO_CONVERT (1<<26) +#define BACKUP_FILE (1<<27) /* Control key sequences, changing these would be very very bad */ @@ -259,9 +269,7 @@ typedef struct syntaxtype { #define NANO_ALT_LCARAT '<' #define NANO_ALT_RCARAT '>' #define NANO_ALT_BRACKET ']' -#ifndef NANO_SMALL -# define NANO_ALT_SPACE ' ' -#endif +#define NANO_ALT_SPACE ' ' /* Some semi-changeable keybindings; don't play with unless you're sure you know what you're doing */ @@ -325,10 +333,8 @@ know what you're doing */ #define NANO_OPENNEXT_ALTKEY NANO_ALT_PERIOD #define NANO_BRACKET_KEY NANO_ALT_BRACKET #define NANO_EXTCMD_KEY NANO_CONTROL_X -#ifndef NANO_SMALL -# define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE -# define NANO_PREVWORD_KEY NANO_ALT_SPACE -#endif +#define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE +#define NANO_PREVWORD_KEY NANO_ALT_SPACE #define TOGGLE_CONST_KEY NANO_ALT_C #define TOGGLE_AUTOINDENT_KEY NANO_ALT_I @@ -346,6 +352,7 @@ know what you're doing */ #define TOGGLE_MAC_KEY NANO_ALT_O #define TOGGLE_SMOOTH_KEY NANO_ALT_S #define TOGGLE_NOCONVERT_KEY NANO_ALT_N +#define TOGGLE_BACKUP_KEY NANO_ALT_B #define MAIN_VISIBLE 12 diff --git a/nano.texi b/nano.texi index 1dddca21..2b664648 100644 --- a/nano.texi +++ b/nano.texi @@ -9,7 +9,7 @@ @smallbook @set EDITION 0.1 @set VERSION 1.1.9 -@set UPDATED 4 Jan 2002 +@set UPDATED 27 Jun 2002 @dircategory Editors @direntry @@ -106,13 +106,18 @@ Email bug reports to @email{nano@@nano-editor.org}. @section Command Line Options @code{nano} takes the following options from the command line: + @table @code +@item -B, --backup +When saving a file, back up the previous version of it to the current +filename suffixed with a ~. + @item -D, --dos Write file in DOS format. @item -F, --multibuffer -Enable multiple file buffers. +Enable multiple file buffers, if available. @item -K, --keypad Do not use the ncurses keypad() call unless necessary. Try this flag if @@ -140,6 +145,10 @@ Set the displayed tab length to [num] columns. @item -V, --version Print the version number and copyright and quit. +@item -Y, --syntax=[str] +Specify a specific syntax highlighting from the .nanorc to use, if +available. + @item -c, --const Constantly display the cursor position and line number on the statusbar. @@ -270,22 +279,22 @@ will display the current directory instead of the filename. @node The Statusbar, Shortcut Lists, The Titlebar, Editor Basics @section The Statusbar -The statusbar is located three lines from the bottom of the screen (or the -bottom line in Expert Mode. @xref{Expert Mode}, for more info. +The statusbar is located three lines from the bottom of the screen (or +the bottom line in Expert Mode. @xref{Expert Mode}, for more info. The Statusbar shows important and informational messages. Any error messages that occur from using the editor will appear on the statusbar. Any questions that are asked of the user will be asked on the statusbar, -and any user input (search strings, file names, etc) will be input on the -statusbar. +and any user input (search strings, file names, etc) will be input on +the statusbar. @node Shortcut Lists, , The Statusbar, Editor Basics @section Shortcut Lists -The Shortcut Lists are the two lines at the bottom of the screen which show -some of the more commonly used functions in the editor. The exact -functions which are displayed depend on whether Pico Compatibility Mode mode -is enabled. @xref{Pico Compatibility}, for more info. +The Shortcut Lists are the two lines at the bottom of the screen which +show some of the more commonly used functions in the editor. The exact +functions which are displayed depend on whether Pico Compatibility Mode +mode is enabled. @xref{Pico Compatibility}, for more info. @node Online Help, Feature Toggles, Editor Basics, Top @chapter Online Help @@ -302,25 +311,16 @@ and ^V (Page Down) keys. ^X exits the help system. Toggles allow you to change certain aspects of the editor that would normally be done via command line flags. They are invoked via certain Meta key sequenced. @xref{Special Functions}, for more info. -The following toggles are available: +The following global toggles are available: @table @code -@item Case Sensitive Search Toggle (Meta-A) -toggles case sensistive searching functionality on/off. - -@item Backwards Search Toggle (Meta-B) -toggles backwards searching fuctionality on/off. - -@item Constant Update Toggle (Meta-C) -toggles the -c (--const) command line flag. +@item Backup File Toggle (Meta-B) +toggles the -B (--backup) command line flag. @item DOS Format Toggle (Meta-D) toggles the -D (--dos) command line flag. -@item Regular Expressions Toggle (Meta-E) -toggles the -R (--regexp) command line flag. - @item Multiple Files Toggle (Meta-F) toggles the -F (--multibuffer) command line flag. @@ -365,21 +365,21 @@ changes buffer to next loaded file. @chapter The File Browser When reading or writing files, pressing ^T will invoke the file browser. -Here, one can navigate directories in a graphical manner in order to find -the desired file. +Here, one can navigate directories in a graphical manner in order to +find the desired file. Basic movement in the file browser is accomplished with he arrow keys -and page up/down. The behavior of the enter (or 's') key varies by what -is currently selected. If the currently selected object is a directory, -the file browser will enter and display the contents of the directory. If -the object is a file, this filename and path are copied to the statusbar -and the file browser is exited. +and page up/down. The behavior of the enter (or 's') key varies by what +is currently selected. If the currently selected object is a directory, +the file browser will enter and display the contents of the directory. +If the object is a file, this filename and path are copied to the +statusbar and the file browser is exited. @node Pico Compatibility, Building and Configure Options, The File Browser, Top @chapter Pico Compatibility -Nano does not completely emulate Pico by default. The following differences -apply to the default mode and Pico Compatibility mode: +Nano does not completely emulate Pico by default. The following +differences apply to the default mode and Pico Compatibility mode: @table @code @item Displayed Shortcuts @@ -466,24 +466,22 @@ Disables all word wrapping in the editor. This also eliminates the -w command line flag, as nonwrapping is then the default behavior. @item --disable-mouse -Disables all mouse functionality. This also disables the -m commands line +Disables all mouse functionality. This also disables the -m command line flag which enables the mouse functions. @item --disable-operatingdir -Disables setting of operating directory. This also disables the -o command -line flag. +Disables setting of operating directory. This also disables the -o +command line flag. @item --disable-nls Disables Native Language support. This will make the available GNU nano translations unusable. @item --with-slang -Compiling GNU nano with Slang is supported, and will make the binary notably -smaller than if compiled with ncurses or other curses libraries. +Compiling GNU nano with Slang is supported, and will make the binary +notably smaller than if compiled with ncurses or other curses libraries. @end table @contents @bye - - diff --git a/nanorc.sample b/nanorc.sample index bc230262..951b8ff6 100644 --- a/nanorc.sample +++ b/nanorc.sample @@ -4,74 +4,73 @@ # # To make sure a value is not enabled, use "unset