2002-08-25 23:06:23 +00:00
|
|
|
/*
|
|
|
|
options.c
|
|
|
|
|
|
|
|
command line options handling
|
|
|
|
|
|
|
|
Copyright (C) 2002 Colin Thompson
|
|
|
|
|
2002-08-26 15:05:23 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
2002-08-25 23:06:23 +00:00
|
|
|
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
|
|
|
|
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 <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <getopt.h>
|
2013-03-19 03:05:50 +00:00
|
|
|
#include <unistd.h>
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2010-08-24 07:20:07 +00:00
|
|
|
#include "QF/dstring.h"
|
2021-08-13 12:26:48 +00:00
|
|
|
#include "QF/sys.h"
|
2010-08-24 07:20:07 +00:00
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "tools/qfvis/include/options.h"
|
|
|
|
#include "tools/qfvis/include/vis.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
const char *this_program;
|
|
|
|
|
2021-01-01 07:36:01 +00:00
|
|
|
enum {
|
|
|
|
start_opts = 255, // not used, starts the enum.
|
|
|
|
OPT_PORTAL_LIMIT,
|
2021-07-26 13:42:03 +00:00
|
|
|
OPT_FAT_PVS,
|
|
|
|
OPT_FULL_PVS,
|
2021-07-27 12:47:19 +00:00
|
|
|
OPT_UTF8,
|
2021-01-01 07:36:01 +00:00
|
|
|
};
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
static struct option const long_options[] = {
|
2021-07-26 13:42:03 +00:00
|
|
|
{"fat-pvs", no_argument, 0, OPT_FAT_PVS},
|
|
|
|
{"full-pvs", no_argument, 0, OPT_FULL_PVS},
|
2021-07-27 12:47:19 +00:00
|
|
|
{"utf8", no_argument, 0, OPT_UTF8},
|
2002-08-25 23:06:23 +00:00
|
|
|
{"quiet", no_argument, 0, 'q'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
2002-08-26 16:15:19 +00:00
|
|
|
{"threads", required_argument, 0, 't'},
|
2002-08-25 23:06:23 +00:00
|
|
|
{"minimal", no_argument, 0, 'm'},
|
2012-05-21 23:23:22 +00:00
|
|
|
{"level", required_argument, 0, 'l'},
|
|
|
|
{"file", required_argument, 0, 'f'},
|
2021-01-01 07:36:01 +00:00
|
|
|
{"portal-limit", required_argument, 0, OPT_PORTAL_LIMIT},
|
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
|
2002-08-26 16:15:19 +00:00
|
|
|
"t:" // threads
|
2002-08-25 23:06:23 +00:00
|
|
|
"m" // minimal vis
|
2002-08-26 16:15:19 +00:00
|
|
|
"l:" // level
|
|
|
|
"f:" // file
|
2002-08-25 23:06:23 +00:00
|
|
|
;
|
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
printf ("%s - QuakeForge PVS/PHS generation tool\n", this_program);
|
|
|
|
printf ("Usage: %s [options]\n", this_program);
|
|
|
|
printf (
|
2002-09-19 02:37:52 +00:00
|
|
|
"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"
|
|
|
|
" -t, --threads [num] Number of threads to use\n"
|
|
|
|
" -m, --minimal Perform minimal vis'ing\n"
|
|
|
|
" -l, --level [level] Vis level to perform\n"
|
|
|
|
" -f, --file [bspfile] BSP file to vis\n\n");
|
2002-08-25 23:06:23 +00:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
2013-03-19 03:05:50 +00:00
|
|
|
static int
|
|
|
|
default_threads (void)
|
|
|
|
{
|
|
|
|
int threads = 1;
|
|
|
|
#ifdef USE_PTHREADS
|
2021-08-13 12:26:48 +00:00
|
|
|
threads = Sys_ProcessorCount ();
|
2013-03-19 03:05:50 +00:00
|
|
|
#endif
|
|
|
|
return threads;
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
int
|
|
|
|
DecodeArgs (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
options.verbosity = 0;
|
|
|
|
options.bspfile = NULL;
|
2013-03-19 03:05:50 +00:00
|
|
|
options.threads = default_threads ();
|
2013-03-09 06:01:54 +00:00
|
|
|
options.level = 4;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
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;
|
2012-05-21 23:23:22 +00:00
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
case 'h': // help
|
|
|
|
usage (0);
|
|
|
|
break;
|
|
|
|
case 'V': // version
|
2010-08-19 06:01:43 +00:00
|
|
|
printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
|
2002-08-25 23:06:23 +00:00
|
|
|
exit (0);
|
|
|
|
break;
|
|
|
|
case 't': // threads
|
|
|
|
options.threads = atoi (optarg);
|
|
|
|
break;
|
2021-01-01 07:36:01 +00:00
|
|
|
case OPT_PORTAL_LIMIT:
|
|
|
|
options.portal_limit = atoi (optarg);
|
|
|
|
break;
|
2021-07-26 13:42:03 +00:00
|
|
|
case OPT_FAT_PVS:
|
|
|
|
options.fat_pvs = true;
|
|
|
|
options.no_auto_pvs = true;
|
|
|
|
break;
|
|
|
|
case OPT_FULL_PVS:
|
|
|
|
options.fat_pvs = true;
|
|
|
|
break;
|
2021-07-27 12:47:19 +00:00
|
|
|
case OPT_UTF8:
|
|
|
|
options.utf8 = true;
|
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
case 'm': // minimal vis
|
|
|
|
options.minimal = true;
|
|
|
|
break;
|
|
|
|
case 'l': // level
|
|
|
|
options.level = atoi (optarg);
|
|
|
|
break;
|
|
|
|
case 'f': // set filename
|
2010-08-24 07:20:07 +00:00
|
|
|
options.bspfile = dstring_strdup (optarg);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 03:05:50 +00:00
|
|
|
#ifndef USE_PTHREADS
|
|
|
|
if (options.threads != 1) {
|
|
|
|
printf ("NOTE: ignoring thread count (unsupported)\n");
|
|
|
|
options.threads = 1;
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-25 23:06:23 +00:00
|
|
|
if ((!options.bspfile) && argv[optind] && *(argv[optind]))
|
2010-08-24 07:20:07 +00:00
|
|
|
options.bspfile = dstring_strdup (argv[optind++]);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
return optind;
|
|
|
|
}
|