getopt: fix whitespace damage

This commit is contained in:
Denis Vlasenko 2006-09-22 08:42:06 +00:00
parent cad36681d2
commit f47ff100cc

View File

@ -56,7 +56,7 @@ static int alternative; /* 0 is getopt_long, 1 is getopt_long_only */
/* Function prototypes */ /* Function prototypes */
static const char *normalize(const char *arg); static const char *normalize(const char *arg);
static int generate_output(char * argv[],int argc,const char *optstr, static int generate_output(char * argv[],int argc,const char *optstr,
const struct option *longopts); const struct option *longopts);
static void add_long_options(char *options); static void add_long_options(char *options);
static void add_longopt(const char *name,int has_arg); static void add_longopt(const char *name,int has_arg);
static void set_shell(const char *new_shell); static void set_shell(const char *new_shell);
@ -80,7 +80,7 @@ const char *normalize(const char *arg)
free(BUFFER); free(BUFFER);
if (!quote) { /* Just copy arg */ if (!quote) { /* Just copy arg */
BUFFER=xstrdup(arg); BUFFER=xstrdup(arg);
return BUFFER; return BUFFER;
} }
@ -134,7 +134,7 @@ const char *normalize(const char *arg)
* Other settings are found in global variables. * Other settings are found in global variables.
*/ */
int generate_output(char * argv[],int argc,const char *optstr, int generate_output(char * argv[],int argc,const char *optstr,
const struct option *longopts) const struct option *longopts)
{ {
int exit_code = 0; /* We assume everything will be OK */ int exit_code = 0; /* We assume everything will be OK */
int opt; int opt;
@ -146,8 +146,8 @@ int generate_output(char * argv[],int argc,const char *optstr,
optind=0; /* Reset getopt(3) */ optind=0; /* Reset getopt(3) */
while ((opt = (alternative? while ((opt = (alternative?
getopt_long_only(argc,argv,optstr,longopts,&longindex): getopt_long_only(argc,argv,optstr,longopts,&longindex):
getopt_long(argc,argv,optstr,longopts,&longindex))) getopt_long(argc,argv,optstr,longopts,&longindex)))
!= EOF) != EOF)
if (opt == '?' || opt == ':' ) if (opt == '?' || opt == ':' )
exit_code = 1; exit_code = 1;
@ -156,7 +156,7 @@ int generate_output(char * argv[],int argc,const char *optstr,
printf(" --%s",longopts[longindex].name); printf(" --%s",longopts[longindex].name);
if (longopts[longindex].has_arg) if (longopts[longindex].has_arg)
printf(" %s", printf(" %s",
normalize(optarg?optarg:"")); normalize(optarg?optarg:""));
} else if (opt == NON_OPT) } else if (opt == NON_OPT)
printf(" %s",normalize(optarg)); printf(" %s",normalize(optarg));
else { else {
@ -164,7 +164,7 @@ int generate_output(char * argv[],int argc,const char *optstr,
charptr = strchr(optstr,opt); charptr = strchr(optstr,opt);
if (charptr != NULL && *++charptr == ':') if (charptr != NULL && *++charptr == ':')
printf(" %s", printf(" %s",
normalize(optarg?optarg:"")); normalize(optarg?optarg:""));
} }
} }
@ -209,7 +209,7 @@ void add_longopt(const char *name,int has_arg)
long_options[long_options_nr-1].has_arg=has_arg; long_options[long_options_nr-1].has_arg=has_arg;
long_options[long_options_nr-1].flag=NULL; long_options[long_options_nr-1].flag=NULL;
long_options[long_options_nr-1].val=LONG_OPT; long_options[long_options_nr-1].val=LONG_OPT;
long_options[long_options_nr-1].name=xstrdup(name); long_options[long_options_nr-1].name=xstrdup(name);
} }
long_options_nr++; long_options_nr++;
} }
@ -305,7 +305,7 @@ int getopt_main(int argc, char *argv[])
/* For some reason, the original getopt gave no error /* For some reason, the original getopt gave no error
when there were no arguments. */ when there were no arguments. */
printf(" --\n"); printf(" --\n");
return 0; return 0;
} else } else
bb_error_msg_and_die("missing optstring argument"); bb_error_msg_and_die("missing optstring argument");
} }
@ -317,7 +317,7 @@ int getopt_main(int argc, char *argv[])
s=xmalloc(strlen(argv[1])+1); s=xmalloc(strlen(argv[1])+1);
strcpy(s,argv[1]+strspn(argv[1],"-+")); strcpy(s,argv[1]+strspn(argv[1],"-+"));
argv[1]=argv[0]; argv[1]=argv[0];
return (generate_output(argv+1,argc-1,s,long_options)); return (generate_output(argv+1,argc-1,s,long_options));
} }
while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF) while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
@ -326,13 +326,13 @@ int getopt_main(int argc, char *argv[])
alternative=1; alternative=1;
break; break;
case 'o': case 'o':
optstr = optarg; optstr = optarg;
break; break;
case 'l': case 'l':
add_long_options(optarg); add_long_options(optarg);
break; break;
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'q': case 'q':
quiet_errors=1; quiet_errors=1;
@ -344,7 +344,7 @@ int getopt_main(int argc, char *argv[])
set_shell(optarg); set_shell(optarg);
break; break;
case 'T': case 'T':
return 4; return 4;
case 'u': case 'u':
quote=0; quote=0;
break; break;
@ -361,5 +361,5 @@ int getopt_main(int argc, char *argv[])
argv[optind-1]=name; argv[optind-1]=name;
else else
argv[optind-1]=argv[0]; argv[optind-1]=argv[0];
return (generate_output(argv+optind-1,argc-optind+1,optstr,long_options)); return generate_output(argv+optind-1,argc-optind+1,optstr,long_options);
} }