2002-08-25 23:06:23 +00:00
|
|
|
/*
|
|
|
|
options.c
|
|
|
|
|
|
|
|
command line options handling
|
|
|
|
|
|
|
|
Copyright (C) 2002 Colin Thompson
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/qtypes.h"
|
|
|
|
|
2003-09-10 15:48:46 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2004-01-26 07:39:29 +00:00
|
|
|
#include "entities.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
#include "options.h"
|
2004-01-27 08:31:34 +00:00
|
|
|
#include "properties.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
const char *this_program;
|
|
|
|
|
|
|
|
static struct option const long_options[] = {
|
|
|
|
{"quiet", no_argument, 0, 'q'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
2002-08-26 16:24:46 +00:00
|
|
|
{"threads", required_argument, 0, 't'},
|
2004-01-27 08:31:34 +00:00
|
|
|
{"properties", required_argument, 0, 'P'},
|
2004-01-26 07:39:29 +00:00
|
|
|
{"attenuation", required_argument, 0, 'a'},
|
|
|
|
{"noise", required_argument, 0, 'n'},
|
|
|
|
{"cutoff", required_argument, 0, 'c'},
|
2003-09-10 15:48:46 +00:00
|
|
|
{"extra", required_argument, 0, 'e'},
|
2003-09-09 08:13:33 +00:00
|
|
|
{"novis", no_argument, 0, 'N'},
|
2002-08-26 16:24:46 +00:00
|
|
|
{"distance", required_argument, 0, 'd'},
|
|
|
|
{"range", required_argument, 0, 'r'},
|
|
|
|
{"file", required_argument, 0, 'f'},
|
2002-08-25 23:06:23 +00:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *short_options =
|
|
|
|
"q" // quiet
|
|
|
|
"v" // verbose
|
|
|
|
"h" // help
|
|
|
|
"V" // version
|
2003-09-09 08:13:33 +00:00
|
|
|
"N" // novis
|
2002-08-26 16:24:46 +00:00
|
|
|
"t:" // threads
|
2004-01-26 07:39:29 +00:00
|
|
|
"a:" // attenuation
|
|
|
|
"n:" // noise
|
|
|
|
"c:" // cutoff
|
2003-09-10 15:48:46 +00:00
|
|
|
"e:" // extra sampling
|
2002-08-26 16:24:46 +00:00
|
|
|
"d:" // scale distance
|
|
|
|
"r:" // scale range
|
2004-01-27 08:31:34 +00:00
|
|
|
"P:" // properties file
|
2002-08-26 16:24:46 +00:00
|
|
|
"f:"
|
2002-08-25 23:06:23 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
printf ("%s - QuakeForge light tool\n", this_program);
|
|
|
|
printf ("Usage: %s [options] bspfile\n", this_program);
|
2002-09-19 02:37:52 +00:00
|
|
|
printf (
|
|
|
|
"Options:\n"
|
|
|
|
" -q, --quiet Inhibit usual output\n"
|
|
|
|
" -v, --verbose Display more output than usual\n"
|
|
|
|
" -h, --help Display this help and exit\n"
|
|
|
|
" -V, --version Output version information and exit\n"
|
2003-09-09 08:13:33 +00:00
|
|
|
" -N, --novis Don't use vis data\n"
|
2002-09-19 02:37:52 +00:00
|
|
|
" -t, --threads [num] Number of threads to use\n"
|
2003-09-10 15:48:46 +00:00
|
|
|
" -e, --extra [num] Apply extra sampling\n"
|
2002-09-19 02:37:52 +00:00
|
|
|
" -d, --distance [scale] Scale distance\n"
|
|
|
|
" -r, --range [scale] Scale range\n"
|
2004-01-26 07:39:29 +00:00
|
|
|
" -a, --attenuation [type] linear,radius,inverse,realistic,none,\n"
|
|
|
|
" havoc\n"
|
|
|
|
" -n, --noise [factor] Scale noise. 0 (default) to disable\n"
|
|
|
|
" -c, --cutoff [scale] Scale cutoff. 0 to disable\n"
|
2004-01-27 08:31:34 +00:00
|
|
|
" -P, --properties [file] Properties file\n"
|
2002-09-19 02:37:52 +00:00
|
|
|
" -f, --file [bspfile] BSP file\n\n");
|
2002-08-25 23:06:23 +00:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DecodeArgs (int argc, char **argv)
|
|
|
|
{
|
2003-09-12 16:43:44 +00:00
|
|
|
int c;
|
|
|
|
char *eptr;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-09-09 08:13:33 +00:00
|
|
|
memset (&options, 0, sizeof (options));
|
2002-08-25 23:06:23 +00:00
|
|
|
options.verbosity = 0;
|
|
|
|
options.threads = 1;
|
|
|
|
options.distance = 1.0;
|
|
|
|
options.range = 0.5;
|
2003-09-09 08:13:33 +00:00
|
|
|
options.globallightscale = 1.0;
|
2004-01-26 07:39:29 +00:00
|
|
|
options.cutoff = 1.0;
|
|
|
|
options.attenuation = LIGHT_LINEAR;
|
2002-08-25 23:06:23 +00:00
|
|
|
bspfile = NULL;
|
|
|
|
|
|
|
|
while ((c = getopt_long (argc, argv, short_options, long_options, 0))
|
|
|
|
!= EOF) {
|
|
|
|
switch (c) {
|
|
|
|
case 'q': // quiet
|
|
|
|
options.verbosity -= 1;
|
|
|
|
break;
|
|
|
|
case 'v': // verbose
|
|
|
|
options.verbosity += 1;
|
|
|
|
break;
|
|
|
|
case 'h': // help
|
|
|
|
usage (0);
|
|
|
|
break;
|
2003-09-09 08:13:33 +00:00
|
|
|
case 'N': // novis
|
|
|
|
options.novis = 1;
|
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
case 'V': // version
|
|
|
|
printf ("%s version %s\n", PACKAGE, VERSION);
|
|
|
|
exit (0);
|
|
|
|
break;
|
|
|
|
case 't': // threads
|
2003-09-12 16:43:44 +00:00
|
|
|
options.threads = strtol (optarg, &eptr, 10);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
2004-01-26 07:39:29 +00:00
|
|
|
case 'a':
|
2004-01-27 08:31:34 +00:00
|
|
|
if ((options.attenuation = parse_attenuation (optarg)) == -1)
|
|
|
|
usage (1);
|
2004-01-26 07:39:29 +00:00
|
|
|
break;
|
|
|
|
case 'n': // noise
|
|
|
|
options.noise = strtod (optarg, &eptr);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
|
|
|
options.noise = bound (0, options.extrabit, 2);
|
|
|
|
break;
|
|
|
|
case 'c': // cutoff
|
|
|
|
options.cutoff = strtod (optarg, &eptr);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
|
|
|
options.cutoff = bound (0, options.extrabit, 2);
|
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
case 'e': // extra
|
2003-09-12 16:43:44 +00:00
|
|
|
options.extrabit = strtol (optarg, &eptr, 10);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
2003-09-10 15:48:46 +00:00
|
|
|
options.extrabit = bound (0, options.extrabit, 2);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
|
|
|
case 'd': // scale distance
|
2003-09-12 16:43:44 +00:00
|
|
|
options.distance = strtod (optarg, &eptr);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
|
|
|
case 'r': // scale range
|
2003-09-12 16:43:44 +00:00
|
|
|
options.range = strtod (optarg, &eptr);
|
|
|
|
if (eptr == optarg || *eptr)
|
|
|
|
usage (1);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
bspfile = strdup (optarg);
|
|
|
|
break;
|
2004-01-27 08:31:34 +00:00
|
|
|
case 'P':
|
|
|
|
options.properties_filename = strdup (optarg);
|
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
}
|
2003-09-10 15:48:46 +00:00
|
|
|
options.extrascale = 1.0 / (1 << (options.extrabit * 2));
|
2002-08-25 23:06:23 +00:00
|
|
|
if ((!bspfile) && argv[optind] && *(argv[optind]))
|
|
|
|
bspfile = strdup (argv[optind++]);
|
|
|
|
|
|
|
|
return optind;
|
|
|
|
}
|