Fix to parsing getopt args for -I/--ignorercfiles (DLR)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1239 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2002-07-23 00:33:07 +00:00
parent 87104114bd
commit 1c5c338f95
3 changed files with 22 additions and 32 deletions

View File

@ -85,7 +85,8 @@ CVS Code -
printed as-is and be interpreted as commands by xterm, which printed as-is and be interpreted as commands by xterm, which
will corrupt the display.) (DLR) will corrupt the display.) (DLR)
- Add command line option -I/--ignorercfiles to ignore - Add command line option -I/--ignorercfiles to ignore
/etc/nanorc and ~/.nanorc. (Carl Drinkwater) /etc/nanorc and ~/.nanorc. (Carl Drinkwater). Fix to parsing
getopt args (DLR).
- Fix minor bugs with importing certain text files in Mac - Fix minor bugs with importing certain text files in Mac
format. (DLR) format. (DLR)
- files.c: - files.c:

41
nano.c
View File

@ -2916,35 +2916,26 @@ int main(int argc, char *argv[])
#endif #endif
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
/* scan through the options and handle -I/--ignorercfiles first, so {
that it's handled before we call do_rcfile() and read the other /* scan through the options and handle -I/--ignorercfiles
options */ first, so that it's handled before we call do_rcfile() and
read the other options; don't use getopt()/getopt_long()
/* stop getopt throwing up an error if we supply other options here, because there's no way to reset it properly
as arguments */ afterward */
opterr = 0; int i;
for (i = 1; i < argc; i++) {
#ifdef HAVE_GETOPT_LONG if (!strcmp(argv[i], "--"))
while ((optchr = getopt_long(argc, argv, "I",
long_options, &option_index)) != EOF) {
#else
while ((optchr =
getopt(argc, argv, "I")) != EOF) {
#endif
switch (optchr) {
case 'I':
SET(NO_RCFILE);
break; break;
else if (!strcmp(argv[i], "-I"))
SET(NO_RCFILE);
#ifdef HAVE_GETOPT_LONG
else if (!strcmp(argv[i], "--ignorercfiles"))
SET(NO_RCFILE);
#endif
} }
} }
if (!ISSET(NO_RCFILE)) if (!ISSET(NO_RCFILE))
do_rcfile(); do_rcfile();
/* reset the getopt variables so we can read through the command line
arguments again */
optind = 1;
opterr = 1;
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
@ -2983,8 +2974,6 @@ int main(int argc, char *argv[])
break; break;
#endif #endif
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
/* we need -I/--ignorercfiles again to stop getopt giving us an
error if we've already supplied it */
case 'I': case 'I':
break; break;
#endif #endif