diff -ur nano/ChangeLog nano-fixed/ChangeLog --- nano/ChangeLog 2003-11-02 19:13:21.000000000 -0500 +++ nano-fixed/ChangeLog 2003-11-02 19:24:02.000000000 -0500 @@ -6,6 +6,16 @@ - global.c: shortcut_init() - Allow WHEREIS_NEXT_KEY to be used in view mode. (DLR) +- rcfile.c: + - Add support for the nanorc command "include". The line + "include " in a nanorc file will now read in + and parse it as an rcfile. New function + parse_include(). (Victor Ananievsky) DLR: Handle tilde + notation via get_full_path(), deal better with some error + conditions, parse the filename as a quoted argument so that + filenames containing e. g. spaces will be handled properly, + and change instances of "insert" to "include" at Brand + Huntsman's suggestion. - search.c: do_replace_loop() - Fix potential infinite loop when doing a forward regex replace diff -ur nano/doc/nanorc.sample nano-fixed/doc/nanorc.sample --- nano/doc/nanorc.sample 2003-09-07 19:54:57.000000000 -0400 +++ nano-fixed/doc/nanorc.sample 2003-11-02 19:23:38.000000000 -0500 @@ -199,10 +199,10 @@ ## #syntax "nanorc" "(\.|/|)nanorc$" ## highlight possible errors and parameters -#color brightwhite "^ *(set|unset|syntax|color).*$" +#color brightwhite "^ *(set|unset|include|syntax|color).*$" ## set, unset and syntax #color cyan "^ *(set|unset) +(autoindent|backup|const|cut|fill|historylog|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smooth|speller|suspend|tabsize|tempfile|view)" -#color green "^ *(set|unset|syntax)\>" +#color green "^ *(set|unset|include|syntax)\>" ## colors #color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" #color magenta "^ *color\>" "\<(start|end)=" diff -ur nano/src/files.c nano-fixed/src/files.c --- nano/src/files.c 2003-10-31 12:58:44.000000000 -0500 +++ nano-fixed/src/files.c 2003-11-02 19:23:38.000000000 -0500 @@ -1017,7 +1017,7 @@ } #endif /* MULTIBUFFER */ -#if !defined(DISABLE_SPELLER) || !defined(DISABLE_OPERATINGDIR) +#if defined(ENABLE_NANORC) || !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, diff -ur nano/src/proto.h nano-fixed/src/proto.h --- nano/src/proto.h 2003-10-03 16:26:25.000000000 -0400 +++ nano-fixed/src/proto.h 2003-11-02 19:23:38.000000000 -0500 @@ -339,6 +339,7 @@ void rcfile_msg(const char *msg, ...); char *parse_next_word(char *ptr); char *parse_argument(char *ptr); +void parse_include(char *ptr); #ifdef ENABLE_COLOR int colortoint(const char *colorname, int *bright); char *parse_next_regex(char *ptr); diff -ur nano/src/rcfile.c nano-fixed/src/rcfile.c --- nano/src/rcfile.c 2003-10-03 16:26:25.000000000 -0400 +++ nano-fixed/src/rcfile.c 2003-11-02 19:23:38.000000000 -0500 @@ -183,6 +183,57 @@ return ptr; } +/* Read and parse additional config files. */ +void parse_include(char *ptr) +{ + FILE *rc; + char *option, *full_option, *err_filename = NULL, *err_message; + char *old_nanorc = nanorc; + int old_lineno = lineno; + + option = ptr; + if (*option == '"') + option++; + ptr = parse_argument(ptr); + + /* Get the specified file's full path. There are three ways in + * which this can go wrong: get_full_path() fails, get_full_path() + * returns a directory, or get_full_path() succeeds and returns a + * filename but fopen() fails. Set the filename and error message + * accordingly in each of these cases. */ + + full_option = get_full_path(option); + + if (full_option == NULL) { + err_filename = option; + err_message = strerror(errno); + } else if (full_option[strlen(full_option) - 1] == '/') { + err_filename = full_option; + err_message = _("Not a file\n"); + } else if ((rc = fopen(full_option, "r")) == NULL) { + err_filename = full_option; + err_message = strerror(errno); + } + + if (err_filename != NULL) + rcfile_error(_("Unable to read file %s, %s"), err_filename, err_message); + else { + /* Use the name and line number position of the file while + * parsing it, so we can know where any errors in it are. */ + nanorc = full_option; + lineno = 0; + + parse_rcfile(rc); + fclose(rc); + free(full_option); + + /* We're done with the file; set the name and line number + * position back to those of the old file. */ + nanorc = old_nanorc; + lineno = old_lineno; + } +} + #ifdef ENABLE_COLOR int colortoint(const char *colorname, int *bright) @@ -507,6 +558,8 @@ set = 1; else if (!strcasecmp(keyword, "unset")) set = -1; + else if (!strcasecmp(keyword, "include")) + parse_include(ptr); #ifdef ENABLE_COLOR else if (!strcasecmp(keyword, "syntax")) parse_syntax(ptr);