diff -ur nano.1 nano.1 --- nano.1 Sun Jun 29 04:25:46 2003 +++ nano.1 Fri Dec 31 16:44:48 2004 @@ -39,6 +39,11 @@ When saving a file, back up the previous version of it to the current filename suffixed with a ~. .TP +.B \-C (\-\-config\-file) +Use another nanorc file instead of +.IR ~/.nanorc , +if nanorc support is available. +.TP .B \-D (\-\-dos) Write file in DOS format. .TP diff -ur nano.c nano.c --- nano.c Sat Jun 26 02:12:19 2004 +++ nano.c Fri Dec 31 16:21:37 2004 @@ -638,6 +638,9 @@ print1opt(_("+LINE"), "", _("Start at line number LINE")); #ifndef NANO_SMALL print1opt("-B", "--backup", _("Backup existing files on save")); +#ifdef ENABLE_NANORC + print1opt("-C", "--config-file", _("Use an alternate nanorc file")); +#endif print1opt("-D", "--dos", _("Write file in DOS format")); #endif #ifdef ENABLE_MULTIBUFFER @@ -3039,6 +3042,7 @@ #endif #ifdef ENABLE_NANORC #ifndef NANO_SMALL + {"config-file", 1, 0, 'C'}, {"historylog", 0, 0, 'H'}, #endif {"ignorercfiles", 0, 0, 'I'}, @@ -3104,11 +3108,11 @@ #endif #ifdef HAVE_GETOPT_LONG - while ((optchr = getopt_long(argc, argv, "h?BDFHIKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz", + while ((optchr = getopt_long(argc, argv, "h?BC:DFHIKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz", long_options, &option_index)) != -1) { #else while ((optchr = - getopt(argc, argv, "h?BDFHIKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz")) != -1) { + getopt(argc, argv, "h?BC:DFHIKMNQ:RST:VY:abcefgijklmo:pr:s:tvwxz")) != -1) { #endif switch (optchr) { @@ -3136,6 +3140,11 @@ #endif #ifdef ENABLE_NANORC #ifndef NANO_SMALL + case 'C': + nanorc=mallocstrcpy(nanorc,optarg); + have_alternate_nanorc=1; + break; + case 'H': SET(HISTORYLOG); break; diff -ur nano.h nano.h --- nano.h Sat Jun 26 02:12:19 2004 +++ nano.h Fri Dec 31 16:26:09 2004 @@ -179,10 +179,17 @@ #endif /* !NANO_SMALL */ #ifdef ENABLE_NANORC +char *nanorc; +#ifdef SYSCONFDIR +char *nanorc_default; +#endif +int have_alternate_nanorc; + typedef struct rcoption { const char *name; int flag; } rcoption; + #endif /* ENABLE_NANORC */ #ifdef ENABLE_COLOR @@ -438,5 +445,4 @@ /* Maximum number of search history strings saved, same value used for replace history */ #define MAX_SEARCH_HISTORY 100 - #endif /* !NANO_H */ diff -ur rcfile.c rcfile.c --- rcfile.c Sat Jun 26 02:12:19 2004 +++ rcfile.c Fri Dec 31 16:30:06 2004 @@ -92,7 +92,6 @@ static int errors = 0; static int lineno = 0; -static char *nanorc; /* We have an error in some part of the rcfile; put it on stderr and make the user hit return to continue starting up nano. */ @@ -626,20 +625,23 @@ uid_t euid = geteuid(); char *homenv = getenv("HOME"); + #ifdef SYSCONFDIR assert(sizeof(SYSCONFDIR) == strlen(SYSCONFDIR) + 1); - nanorc = charalloc(sizeof(SYSCONFDIR) + 7); - sprintf(nanorc, "%s/nanorc", SYSCONFDIR); + nanorc_default = charalloc(sizeof(SYSCONFDIR) + 7); + sprintf(nanorc_default, "%s/nanorc", SYSCONFDIR); /* Try to open system nanorc */ - if ((rcstream = fopen(nanorc, "r")) != NULL) { + if ((rcstream = fopen(nanorc_default, "r")) != NULL) { /* Parse it! */ parse_rcfile(rcstream); fclose(rcstream); } + free(nanorc_default); #endif lineno = 0; +if (!have_alternate_nanorc) { /* Rely on $HOME, fall back on getpwuid() */ if (homenv != NULL) { nanorc = charealloc(nanorc, strlen(homenv) + 10); @@ -657,6 +659,7 @@ } } +} if (!ISSET(NO_RCFILE)) { @@ -668,9 +671,9 @@ #endif if ((rcstream = fopen(nanorc, "r")) == NULL) { /* Don't complain about the file not existing */ - if (errno != ENOENT) { - rcfile_error(_("Unable to open ~/.nanorc file, %s"), - strerror(errno)); + if (errno != ENOENT || (have_alternate_nanorc)) { + rcfile_error(_("Unable to open %s file, %s"), + nanorc, strerror(errno)); SET(NO_RCFILE); } } else {