diff -rup nano-1.3.1/NEWS mod_nano-1.3.1/NEWS --- nano-1.3.1/NEWS 2004-01-09 01:09:46.000000000 +0900 +++ mod_nano-1.3.1/NEWS 2004-03-24 22:10:48.909155900 +0900 @@ -1,3 +1,18 @@ +2004.03.24 - Added to David Ramsey's include patch by putting + a command line option (-C, --includerc) to add rc files. + This was done, so different files can be loaded with + different color code easily (i.e. two .c files where different + color schemes might be wanted for each). The original note: + 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. + 2004.01.09 - GNU nano 1.3.1 is outside the gates. This release features, among other things, fixes for the input routines to deal with some problems they had, a diff -rup nano-1.3.1/doc/man/nano.1 mod_nano-1.3.1/doc/man/nano.1 --- nano-1.3.1/doc/man/nano.1 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/doc/man/nano.1 2004-03-25 19:36:01.505946300 +0900 @@ -39,6 +39,10 @@ Places cursor at \fILINE\fP on startup. When saving a file, back up the previous version of it to the current filename suffixed with a ~. .TP +.B \-C \fIrcfile\fP (\-\-includerc=\fIrcfile\fP) +Include an external \fIrcfile\fP after your nanorc file is processed, +if nanorc support is available. +.TP .B \-D (\-\-dos) Write file in DOS format. .TP diff -rup nano-1.3.1/doc/man/nano.1.html mod_nano-1.3.1/doc/man/nano.1.html --- nano-1.3.1/doc/man/nano.1.html 2004-01-09 01:10:20.000000000 +0900 +++ mod_nano-1.3.1/doc/man/nano.1.html 2004-03-25 19:36:26.663335200 +0900 @@ -123,6 +123,25 @@ the current filename suffixed with a ~.< +

−C rcfile +(−−includerc=rcfile)

+ + + + + + +
+

Include an external rcfile after your nanorc file is processed, +if nanorc support is available.

+
+ + + + +

−F (−−multibuffer)

diff -rup nano-1.3.1/doc/man/nanorc.5 mod_nano-1.3.1/doc/man/nanorc.5 --- nano-1.3.1/doc/man/nanorc.5 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/doc/man/nanorc.5 2004-03-24 21:54:11.387541000 +0900 @@ -124,6 +124,10 @@ Save automatically on exit, don't prompt \fBset/unset view\fP Disallow file modification. .TP +\fBinclude \fIrcfile\fP\fP +Include the contents of \fIrcfile\fP at the point specified in the nanorc +file. +.TP .B syntax "\fIstr\fP" ["\fIfileregex\fP" ... ] Defines a syntax named \fIstr\fP which can be activated via the \fB-Y\fP flag, or will be automatically activated if the current filename matches diff -rup nano-1.3.1/doc/man/nanorc.5.html mod_nano-1.3.1/doc/man/nanorc.5.html --- nano-1.3.1/doc/man/nanorc.5.html 2004-01-09 01:10:20.000000000 +0900 +++ mod_nano-1.3.1/doc/man/nanorc.5.html 2004-03-24 21:54:32.709213300 +0900 @@ -500,6 +500,24 @@ must be greater than 0.

+

include rcfile

+ + + + + + +
+

Include the contents of rcfile at the point specified in the nanorc +file.

+
+ + + + +

syntax str ["fileregex" ... ]

diff -rup nano-1.3.1/doc/nanorc.sample mod_nano-1.3.1/doc/nanorc.sample --- nano-1.3.1/doc/nanorc.sample 2003-12-28 01:49:26.000000000 +0900 +++ mod_nano-1.3.1/doc/nanorc.sample 2004-03-24 21:36:25.474276400 +0900 @@ -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 -rup nano-1.3.1/doc/texinfo/nano.info mod_nano-1.3.1/doc/texinfo/nano.info --- nano-1.3.1/doc/texinfo/nano.info 2004-01-09 01:10:22.000000000 +0900 +++ mod_nano-1.3.1/doc/texinfo/nano.info 2004-03-25 19:37:58.059192600 +0900 @@ -63,6 +63,11 @@ Command Line Options When saving a file, back up the previous version of it to the current filename suffixed with a ~. +`-C [rcfile], --includerc [rcfile]' + Use this to include an rc file after the nanorc file is processed. If + -I is set, then this setting will be ignored. Also, if nanorc support + is disabled, this feature will not exist. + `-D, --dos' Write file in DOS format. diff -rup nano-1.3.1/doc/texinfo/nano.texi mod_nano-1.3.1/doc/texinfo/nano.texi --- nano-1.3.1/doc/texinfo/nano.texi 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/doc/texinfo/nano.texi 2004-03-25 19:37:14.043767100 +0900 @@ -111,6 +111,11 @@ Email bug reports to @email{nano@@nano-e When saving a file, back up the previous version of it to the current filename suffixed with a ~. +@item -C [rcfile], --includerc [rcfile] +Use this to include an rc file after the nanorc file is processed. If +-I is set, then this setting will be ignored. Also, if nanorc support +is disabled, this feature will not exist. + @item -D, --dos Write file in DOS format. diff -rup nano-1.3.1/src/global.c mod_nano-1.3.1/src/global.c --- nano-1.3.1/src/global.c 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/src/global.c 2004-03-25 19:18:21.641603900 +0900 @@ -126,6 +126,12 @@ shortcut *browser_list = NULL; shortcut *gotodir_list = NULL; #endif +#ifdef ENABLE_NANORC +/*#ifdef ENABLE_INCLUDERC*/ +char *includercstr = NULL; /* Commandline rc file, if included */ +/*#endif /* ENABLE_INCLUDERC */ +#endif /* ENABLE_NANORC */ + #ifdef ENABLE_COLOR const colortype *colorstrings = NULL; syntaxtype *syntaxes = NULL; @@ -995,6 +1001,12 @@ void thanks_for_all_the_fish(void) free_filestruct(fileage); #endif +#ifdef ENABLE_NANORC +/*#ifdef ENABLE_INCLUDERC*/ + free(includercstr); +/*#endif /* ENABLE_INCLUDERC */ +#endif /* ENABLE_NANORC */ + #ifdef ENABLE_COLOR free(syntaxstr); while (syntaxes != NULL) { diff -rup nano-1.3.1/src/nano.c mod_nano-1.3.1/src/nano.c --- nano-1.3.1/src/nano.c 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/src/nano.c 2004-03-25 19:30:05.857557500 +0900 @@ -639,6 +639,9 @@ void usage(void) #endif print1opt("-I", "--ignorercfiles", _("Don't look at nanorc files")); #endif +/*#ifdef ENABLE_INCLUDERC */ + print1opt("-C [rcfile]", "--includerc=[rcfile]", _("Include another RC file after nanorc")); +/*#endif /*ENABLE_INCLUDERC */ #ifndef NANO_SMALL print1opt("-M", "--mac", _("Write file in Mac format")); print1opt("-N", "--noconvert", _("Don't convert files from DOS/Mac format")); @@ -3071,6 +3074,9 @@ int main(int argc, char *argv[]) {"multibuffer", 0, 0, 'F'}, #endif #ifdef ENABLE_NANORC +/*#ifdef ENABLE_INCLUDERC*/ + {"includerc", 1, 0, 'C'}, +/*#endif /* ENABLE_INCLUDERC */ #ifndef NANO_SMALL {"historylog", 0, 0, 'H'}, #endif @@ -3137,11 +3143,11 @@ int main(int argc, char *argv[]) #endif #ifdef HAVE_GETOPT_LONG - while ((optchr = getopt_long(argc, argv, "h?BDFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz", + while ((optchr = getopt_long(argc, argv, "h?BC:DFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz", long_options, NULL)) != -1) { #else while ((optchr = - getopt(argc, argv, "h?BDFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz")) != -1) { + getopt(argc, argv, "h?BC:DFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz")) != -1) { #endif switch (optchr) { @@ -3168,6 +3174,11 @@ int main(int argc, char *argv[]) break; #endif #ifdef ENABLE_NANORC +/*#ifdef ENABLE_INCLUDERC*/ + case 'C': + includercstr = mallocstrcpy(includercstr, optarg); + break; +/*#endif /* ENABLE_INCLUDERC */ #ifndef NANO_SMALL case 'H': SET(HISTORYLOG); diff -rup nano-1.3.1/src/nano.h mod_nano-1.3.1/src/nano.h --- nano-1.3.1/src/nano.h 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/src/nano.h 2004-03-24 21:08:15.053228300 +0900 @@ -464,6 +464,12 @@ typedef enum { TOP, CENTER, NONE } topmidnone; +/*#ifdef ENABLE_INCLUDERC*/ +typedef enum { + CMDLNE, NANORC, OTHER +} includerctype; +/*#endif /* ENABLE_INCLUDERC */ + /* Minimum editor window rows required for nano to work correctly. */ #define MIN_EDITOR_ROWS 3 diff -rup nano-1.3.1/src/proto.h mod_nano-1.3.1/src/proto.h --- nano-1.3.1/src/proto.h 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/src/proto.h 2004-03-25 19:25:39.521937200 +0900 @@ -80,6 +80,12 @@ extern filestruct *mark_beginbuf; extern openfilestruct *open_files; #endif +#ifdef ENABLE_NANORC +/*#ifdef ENABLE_INCLUDERC*/ +char *includercstr; +/*#endif /* ENABLE_INCLUDERC */ +#endif + #ifdef ENABLE_COLOR extern const colortype *colorstrings; extern syntaxtype *syntaxes; @@ -339,6 +345,9 @@ void rcfile_error(const char *msg, ...); void rcfile_msg(const char *msg, ...); char *parse_next_word(char *ptr); char *parse_argument(char *ptr); +/*#ifdef ENABLE_INCLUDERC*/ +void parse_include(char *ptr, includerctype location); +/*#endif /* ENABLE_INCLUDERC */ #ifdef ENABLE_COLOR int colortoint(const char *colorname, int *bright); char *parse_next_regex(char *ptr); diff -rup nano-1.3.1/src/rcfile.c mod_nano-1.3.1/src/rcfile.c --- nano-1.3.1/src/rcfile.c 2004-01-09 01:10:02.000000000 +0900 +++ mod_nano-1.3.1/src/rcfile.c 2004-03-25 19:20:51.974928300 +0900 @@ -183,6 +183,63 @@ char *parse_argument(char *ptr) return ptr; } +/*#ifdef ENABLE_INCLUDERC*/ + +/* Read and parse additional config files. */ +void parse_include(char *ptr, includerctype location) +{ + FILE *rc; + char *option, *full_option, *err_filename = NULL, *err_message; + char *old_nanorc = nanorc; + int old_lineno = lineno; + + option = ptr; + if (location == NANORC) { + 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; + } +} + +/*#endif /* ENABLE_INCLUDERC */ + #ifdef ENABLE_COLOR int colortoint(const char *colorname, int *bright) @@ -507,6 +564,10 @@ void parse_rcfile(FILE *rcstream) set = 1; else if (!strcasecmp(keyword, "unset")) set = -1; +/*#ifdef ENABLE_INCLUDERC */ + else if (!strcasecmp(keyword, "include")) + parse_include(ptr, NANORC); +/*#endif /* ENABLE_INCLUDERC */ #ifdef ENABLE_COLOR else if (!strcasecmp(keyword, "syntax")) parse_syntax(ptr); @@ -684,7 +745,15 @@ void do_rcfile(void) fclose(rcstream); } } - lineno = 0; + +/*#ifdef ENABLE_INCLUDERC*/ + /* If -I is set, it applies to this file too, and we won't process it. */ + if (includercstr != NULL) { + parse_include(includercstr, CMDLNE); + } +/*#endif /* ENABLE_INCLUDERC */ + + lineno = 0; free(nanorc); #ifdef ENABLE_COLOR