#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#else
#include "getopt.h"
#endif
#ifndef HAVE_STRDUP
char *strdup( const char *s ) ;
char *
strdup( const char *s )
{
char *res ;
res = (char *) malloc( strlen( s ) + 1 ) ;
strcpy( res, s ) ;
return res ;
}
#else
#include <string.h>
#endif
#include "cmdline.h"
int
cmdline ( int argc, char **argv, cmdline_info *cmdinfo )
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"tab", 1, 0, 't'},
{"doc", 0, 0, 'd'},
{"css", 1, 0, 'c'},
{"title", 1, 0, 'T'},
{"input", 1, 0, 'i'},
{"output", 1, 0, 'o'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "vht:dc:T:i:o:V",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 'v':
cmdinfo->verbose = 1 ;
break;
case 'h':
cmdinfo->help = 1 ;
break;
case 't':
cmdinfo->tab = atoi( optarg ) ;
break;
case 'd':
cmdinfo->doc = 1 ;
break;
case 'c':
if ( optarg )
cmdinfo->css = strdup( optarg ) ;
break;
case 'T':
if ( optarg )
cmdinfo->title = strdup( optarg ) ;
break;
case 'i':
if ( optarg )
cmdinfo->input = strdup( optarg ) ;
break;
case 'o':
if ( optarg )
cmdinfo->output = strdup( optarg ) ;
break;
case 'V':
cmdinfo->version = 1 ;
break;
case '?':
break;
default:
fprintf (stderr, "?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
int i = 0 ;
cmdinfo->inputs_size = argc - optind ;
cmdinfo->inputs =
(char **)( malloc ( (cmdinfo->inputs_size)*sizeof(char *) ) ) ;
while (optind < argc)
cmdinfo->inputs[ i++ ] = strdup (argv[optind++]) ;
}
return -1 ;
}