/*
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <getopt.h>

#include "busybox.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=bb_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++]));
		printf("\n");
	}
	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=bb_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[])
{
	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));
}
