/* vi: set sw=4 ts=4: */
/*
 * getopt.c - Enhanced implementation of BSD getopt(1)
 *   Copyright (c) 1997, 1998, 1999, 2000  Frodo Looijaard <frodol@dds.nl>
 *
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */

/*
 * Version 1.0-b4: Tue Sep 23 1997. First public release.
 * Version 1.0: Wed Nov 19 1997.
 *   Bumped up the version number to 1.0
 *   Fixed minor typo (CSH instead of TCSH)
 * Version 1.0.1: Tue Jun 3 1998
 *   Fixed sizeof instead of strlen bug
 *   Bumped up the version number to 1.0.1
 * Version 1.0.2: Thu Jun 11 1998 (not present)
 *   Fixed gcc-2.8.1 warnings
 *   Fixed --version/-V option (not present)
 * Version 1.0.5: Tue Jun 22 1999
 *   Make -u option work (not present)
 * Version 1.0.6: Tue Jun 27 2000
 *   No important changes
 * Version 1.1.0: Tue Jun 30 2000
 *   Added NLS support (partly written by Arkadiusz Mi<B6>kiewicz
 *     <misiek@misiek.eu.org>)
 * Ported to Busybox - Alfred M. Szmidt <ams@trillian.itslinux.org>
 *  Removed --version/-V and --help/-h in
 *  Removed parse_error(), using bb_error_msg() from Busybox instead
 *  Replaced our_malloc with xmalloc and our_realloc with xrealloc
 *
 */

#include "busybox.h"
#include <getopt.h>

/* NON_OPT is the code that is returned when a non-option is found in '+'
   mode */
enum {
	NON_OPT = 1,
/* LONG_OPT is the code that is returned when a long option is found. */
	LONG_OPT = 2
};

/* The shells recognized. */
typedef enum {BASH,TCSH} shell_t;


/* Some global variables that tells us how to parse. */
static shell_t shell=BASH; /* The shell we generate output for. */
static int quiet_errors; /* 0 is not quiet. */
static int quiet_output; /* 0 is not quiet. */
static int quote=1; /* 1 is do quote. */
static int alternative; /* 0 is getopt_long, 1 is getopt_long_only */

/* Function prototypes */
static const char *normalize(const char *arg);
static int generate_output(char * argv[],int argc,const char *optstr,
		const struct option *longopts);
static void add_long_options(char *options);
static void add_longopt(const char *name,int has_arg);
static void set_shell(const char *new_shell);


/*
 * This function 'normalizes' a single argument: it puts single quotes around
 * it and escapes other special characters. If quote is false, it just
 * returns its argument.
 * Bash only needs special treatment for single quotes; tcsh also recognizes
 * exclamation marks within single quotes, and nukes whitespace.
 * This function returns a pointer to a buffer that is overwritten by
 * each call.
 */
const char *normalize(const char *arg)
{
	static char *BUFFER=NULL;
	const char *argptr=arg;
	char *bufptr;

	free(BUFFER);

	if (!quote) { /* Just copy arg */
		BUFFER=xstrdup(arg);
		return BUFFER;
	}

	/* Each character in arg may take up to four characters in the result:
	   For a quote we need a closing quote, a backslash, a quote and an
	   opening quote! We need also the global opening and closing quote,
	   and one extra character for '\0'. */
	BUFFER=xmalloc(strlen(arg)*4+3);

	bufptr=BUFFER;
	*bufptr++='\'';

	while (*argptr) {
		if (*argptr == '\'') {
			/* Quote: replace it with: '\'' */
			*bufptr++='\'';
			*bufptr++='\\';
			*bufptr++='\'';
			*bufptr++='\'';
		} else if (shell==TCSH && *argptr=='!') {
			/* Exclamation mark: replace it with: \! */
			*bufptr++='\'';
			*bufptr++='\\';
			*bufptr++='!';
			*bufptr++='\'';
		} else if (shell==TCSH && *argptr=='\n') {
			/* Newline: replace it with: \n */
			*bufptr++='\\';
			*bufptr++='n';
		} else if (shell==TCSH && isspace(*argptr)) {
			/* Non-newline whitespace: replace it with \<ws> */
			*bufptr++='\'';
			*bufptr++='\\';
			*bufptr++=*argptr;
			*bufptr++='\'';
		} else
			/* Just copy */
			*bufptr++=*argptr;
		argptr++;
	}
	*bufptr++='\'';
	*bufptr++='\0';
	return BUFFER;
}

/*
 * Generate the output. argv[0] is the program name (used for reporting errors).
 * argv[1..] contains the options to be parsed. argc must be the number of
 * elements in argv (ie. 1 if there are no options, only the program name),
 * optstr must contain the short options, and longopts the long options.
 * Other settings are found in global variables.
 */
int generate_output(char * argv[],int argc,const char *optstr,
		const struct option *longopts)
{
	int exit_code = 0; /* We assume everything will be OK */
	int opt;
	int longindex;
	const char *charptr;

	if (quiet_errors) /* No error reporting from getopt(3) */
		opterr=0;
	optind=0; /* Reset getopt(3) */

	while ((opt = (alternative?
			getopt_long_only(argc,argv,optstr,longopts,&longindex):
			getopt_long(argc,argv,optstr,longopts,&longindex)))
	       != EOF)
		if (opt == '?' || opt == ':' )
			exit_code = 1;
		else if (!quiet_output) {
			if (opt == LONG_OPT) {
				printf(" --%s",longopts[longindex].name);
				if (longopts[longindex].has_arg)
					printf(" %s",
						normalize(optarg?optarg:""));
			} else if (opt == NON_OPT)
				printf(" %s",normalize(optarg));
			else {
				printf(" -%c",opt);
				charptr = strchr(optstr,opt);
				if (charptr != NULL && *++charptr == ':')
					printf(" %s",
						normalize(optarg?optarg:""));
			}
		}

	if (! quiet_output) {
		printf(" --");
		while (optind < argc)
			printf(" %s",normalize(argv[optind++]));
		puts("");
	}
	return exit_code;
}

static struct option *long_options;
static int long_options_length; /* Length of array */
static int long_options_nr; /* Nr of used elements in array */
enum { LONG_OPTIONS_INCR = 10 };
#define init_longopt() add_longopt(NULL,0)

/* Register a long option. The contents of name is copied. */
void add_longopt(const char *name, int has_arg)
{
	if (!name) { /* init */
		free(long_options);
		long_options=NULL;
		long_options_length=0;
		long_options_nr=0;
	}

	if (long_options_nr == long_options_length) {
		long_options_length += LONG_OPTIONS_INCR;
		long_options=xrealloc(long_options,
					 sizeof(struct option) *
					 long_options_length);
	}

	long_options[long_options_nr].name=NULL;
	long_options[long_options_nr].has_arg=0;
	long_options[long_options_nr].flag=NULL;
	long_options[long_options_nr].val=0;

	if (long_options_nr) { /* Not for init! */
		long_options[long_options_nr-1].has_arg=has_arg;
		long_options[long_options_nr-1].flag=NULL;
		long_options[long_options_nr-1].val=LONG_OPT;
		long_options[long_options_nr-1].name=xstrdup(name);
	}
	long_options_nr++;
}


/*
 * Register several long options. options is a string of long options,
 * separated by commas or whitespace.
 * This nukes options!
 */
void add_long_options(char *options)
{
	int arg_opt, tlen;
	char *tokptr=strtok(options,", \t\n");
	while (tokptr) {
		arg_opt=no_argument;
		tlen=strlen(tokptr);
		if (tlen > 0) {
			if (tokptr[tlen-1] == ':') {
				if (tlen > 1 && tokptr[tlen-2] == ':') {
					tokptr[tlen-2]='\0';
					tlen -= 2;
					arg_opt=optional_argument;
				} else {
					tokptr[tlen-1]='\0';
					tlen -= 1;
					arg_opt=required_argument;
				}
				if (tlen == 0)
					bb_error_msg("empty long option after -l or --long argument");
			}
			add_longopt(tokptr,arg_opt);
		}
		tokptr=strtok(NULL,", \t\n");
	}
}

void set_shell(const char *new_shell)
{
	if (!strcmp(new_shell,"bash"))
		shell=BASH;
	else if (!strcmp(new_shell,"tcsh"))
		shell=TCSH;
	else if (!strcmp(new_shell,"sh"))
		shell=BASH;
	else if (!strcmp(new_shell,"csh"))
		shell=TCSH;
	else
		bb_error_msg("unknown shell after -s or --shell argument");
}


/* Exit codes:
 *   0) No errors, successful operation.
 *   1) getopt(3) returned an error.
 *   2) A problem with parameter parsing for getopt(1).
 *   3) Internal error, out of memory
 *   4) Returned for -T
 */

static const struct option longopts[]=
{
	{"options",required_argument,NULL,'o'},
	{"longoptions",required_argument,NULL,'l'},
	{"quiet",no_argument,NULL,'q'},
	{"quiet-output",no_argument,NULL,'Q'},
	{"shell",required_argument,NULL,'s'},
	{"test",no_argument,NULL,'T'},
	{"unquoted",no_argument,NULL,'u'},
	{"alternative",no_argument,NULL,'a'},
	{"name",required_argument,NULL,'n'},
	{NULL,0,NULL,0}
};

/* Stop scanning as soon as a non-option argument is found! */
static const char shortopts[]="+ao:l:n:qQs:Tu";


int getopt_main(int argc, char *argv[]);
int getopt_main(int argc, char *argv[])
{
	const char *optstr = NULL;
	char *name = NULL;
	int opt;
	int compatible=0;

	init_longopt();

	if (getenv("GETOPT_COMPATIBLE"))
		compatible=1;

	if (argc == 1) {
		if (compatible) {
			/* For some reason, the original getopt gave no error
			   when there were no arguments. */
			printf(" --\n");
			return 0;
		} else
			bb_error_msg_and_die("missing optstring argument");
	}

	if (argv[1][0] != '-' || compatible) {
		char *s;

		quote=0;
		s=xmalloc(strlen(argv[1])+1);
		strcpy(s,argv[1]+strspn(argv[1],"-+"));
		argv[1]=argv[0];
		return generate_output(argv+1,argc-1,s,long_options);
	}

	while ((opt = getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
		switch (opt) {
		case 'a':
			alternative=1;
			break;
		case 'o':
			optstr = optarg;
			break;
		case 'l':
			add_long_options(optarg);
			break;
		case 'n':
			name = optarg;
			break;
		case 'q':
			quiet_errors=1;
			break;
		case 'Q':
			quiet_output=1;
			break;
		case 's':
			set_shell(optarg);
			break;
		case 'T':
			return 4;
		case 'u':
			quote=0;
			break;
		default:
			bb_show_usage();
		}

	if (!optstr) {
		if (optind >= argc)
			bb_error_msg_and_die("missing optstring argument");
		else optstr=argv[optind++];
	}
	if (name)
		argv[optind-1]=name;
	else
		argv[optind-1]=argv[0];
	return generate_output(argv+optind-1,argc-optind+1,optstr,long_options);
}
