2002-09-20 21:48:34 +00:00
|
|
|
/*
|
|
|
|
options.c
|
|
|
|
|
|
|
|
command line options handling
|
|
|
|
|
|
|
|
Copyright (C) 2002 Bill Currie
|
|
|
|
|
|
|
|
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
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-09-20 21:48:34 +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>
|
|
|
|
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
|
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
const char *this_program;
|
|
|
|
|
|
|
|
static struct option const long_options[] = {
|
2004-01-15 07:16:44 +00:00
|
|
|
{"quiet", no_argument, 0, 'q'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"draw", no_argument, 0, 'd'},
|
|
|
|
{"notjunc", no_argument, 0, 't'},
|
|
|
|
{"nofill", no_argument, 0, 'f'},
|
|
|
|
{"noclip", no_argument, 0, 'c'},
|
|
|
|
{"onlyents", no_argument, 0, 'e'},
|
|
|
|
{"portal", no_argument, 0, 'p'},
|
2004-04-30 21:51:00 +00:00
|
|
|
{"extract-textures", no_argument, 0, 256},
|
|
|
|
{"extract-entities", no_argument, 0, 257},
|
2009-03-18 03:28:34 +00:00
|
|
|
{"extract-hull", no_argument, 0, 258},
|
2004-01-15 07:16:44 +00:00
|
|
|
{"usehulls", no_argument, 0, 'u'},
|
|
|
|
{"hullnum", required_argument, 0, 'H'},
|
2010-08-27 13:12:13 +00:00
|
|
|
{"subdivide", required_argument, 0, 's'},
|
2004-01-15 07:16:44 +00:00
|
|
|
{"wadpath", required_argument, 0, 'w'},
|
|
|
|
{"watervis", no_argument, 0, 'W'},
|
2002-09-20 21:48:34 +00:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *short_options =
|
|
|
|
"q" // quiet
|
|
|
|
"v" // verbose
|
|
|
|
"h" // help
|
|
|
|
"V" // version
|
|
|
|
"d" // draw
|
|
|
|
"t" // notjunc
|
|
|
|
"f" // nofill
|
|
|
|
"c" // noclip
|
|
|
|
"e" // onlyents
|
2004-05-01 03:39:33 +00:00
|
|
|
"o:" // outputfile
|
2004-01-11 08:48:58 +00:00
|
|
|
"p" // portal
|
2002-09-20 21:48:34 +00:00
|
|
|
"u" // usehulls
|
|
|
|
"H:" // hullnum
|
|
|
|
"s:" // subdivide
|
|
|
|
"w:" // wadpath
|
2003-09-03 23:04:30 +00:00
|
|
|
"W" // watervis
|
2002-09-20 21:48:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
2007-10-08 09:50:02 +00:00
|
|
|
static void
|
2002-09-20 21:48:34 +00:00
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
printf ("%s - QuakeForge PVS/PHS generation tool\n", this_program);
|
|
|
|
printf ("Usage: %s [options]\n", this_program);
|
|
|
|
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"
|
|
|
|
" -d, --draw\n"
|
|
|
|
" -t, --notjunc\n"
|
|
|
|
" -c, --noclip\n"
|
|
|
|
" -e, --onlyents\n"
|
2004-01-11 08:48:58 +00:00
|
|
|
" -p, --portal\n"
|
2004-04-30 21:52:17 +00:00
|
|
|
" --extract-textures\n"
|
|
|
|
" --extract-entities\n"
|
2002-09-20 21:48:34 +00:00
|
|
|
" -u, --usehulls Use the existing hull files\n"
|
|
|
|
" -H, --hullnum [num]\n"
|
|
|
|
" -s, --subdivide [size]\n"
|
2003-09-11 18:11:20 +00:00
|
|
|
" -w, --wadpath [path] semicolon delimited set of dirs to\n"
|
2003-09-03 23:04:30 +00:00
|
|
|
" search for texture wads\n"
|
|
|
|
" -W, --watervis allow transparent liquid surfaces\n"
|
|
|
|
);
|
2002-09-20 21:48:34 +00:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DecodeArgs (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
memset (&options, 0, sizeof (options));
|
|
|
|
options.verbosity = 1;
|
|
|
|
options.subdivide_size = 240;
|
|
|
|
|
|
|
|
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;
|
2010-08-27 13:12:13 +00:00
|
|
|
break;
|
2002-09-20 21:48:34 +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-09-20 21:48:34 +00:00
|
|
|
exit (0);
|
|
|
|
break;
|
|
|
|
case 'd': // draw
|
|
|
|
options.drawflag = true;
|
|
|
|
break;
|
|
|
|
case 't': // notjunc
|
|
|
|
options.notjunc = true;
|
|
|
|
break;
|
|
|
|
case 'f': // nofill
|
|
|
|
options.nofill = true;
|
|
|
|
break;
|
|
|
|
case 'c': // noclip
|
|
|
|
options.noclip = true;
|
|
|
|
break;
|
|
|
|
case 'e': // onlyents
|
|
|
|
options.onlyents = true;
|
|
|
|
break;
|
2004-05-01 03:39:33 +00:00
|
|
|
case 'o':
|
|
|
|
options.output_file = strdup (optarg);
|
|
|
|
break;
|
2004-01-11 08:48:58 +00:00
|
|
|
case 'p': // portal
|
2004-04-30 21:51:00 +00:00
|
|
|
options.extract = true;
|
2004-01-11 08:48:58 +00:00
|
|
|
options.portal = true;
|
|
|
|
break;
|
2004-04-30 21:51:00 +00:00
|
|
|
case 256: // extract-textures
|
|
|
|
options.extract = true;
|
2004-01-15 07:16:44 +00:00
|
|
|
options.extract_textures = true;
|
|
|
|
break;
|
2004-04-30 21:51:00 +00:00
|
|
|
case 257: // extract-entities
|
|
|
|
options.extract = true;
|
|
|
|
options.extract_entities = true;
|
|
|
|
break;
|
2009-03-18 03:28:34 +00:00
|
|
|
case 258: // extract-hull
|
|
|
|
options.extract = true;
|
|
|
|
options.extract_hull = true;
|
|
|
|
break;
|
2002-09-20 21:48:34 +00:00
|
|
|
case 'u': // usehulls
|
|
|
|
options.usehulls = true;
|
|
|
|
break;
|
|
|
|
case 'H': // hullnum
|
|
|
|
options.hullnum = atoi (optarg);
|
|
|
|
break;
|
|
|
|
case 's': // subdivide
|
|
|
|
options.subdivide_size = atoi (optarg);
|
|
|
|
break;
|
|
|
|
case 'w': // wadpath
|
|
|
|
options.wadpath = optarg;
|
|
|
|
break;
|
2003-09-03 23:04:30 +00:00
|
|
|
case 'W': // watervis
|
|
|
|
options.watervis = true;
|
|
|
|
break;
|
2002-09-20 21:48:34 +00:00
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
}
|
2010-08-27 13:12:13 +00:00
|
|
|
|
2004-04-30 21:51:00 +00:00
|
|
|
if (options.extract) {
|
2002-09-20 21:48:34 +00:00
|
|
|
options.bspfile = strdup (argv[optind++]);
|
|
|
|
} else {
|
2004-04-30 21:51:00 +00:00
|
|
|
if (argv[optind] && *(argv[optind])) {
|
|
|
|
options.mapfile = malloc (strlen(argv[optind]) + 5);
|
|
|
|
strcpy (options.mapfile, argv[optind++]);
|
|
|
|
} else {
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
if (argv[optind] && *(argv[optind])) {
|
|
|
|
options.bspfile = strdup (argv[optind++]);
|
|
|
|
} else {
|
|
|
|
options.bspfile = malloc (strlen (options.mapfile) + 5);
|
|
|
|
QFS_StripExtension (options.mapfile, options.bspfile);
|
|
|
|
strcat (options.bspfile, ".bsp");
|
|
|
|
}
|
|
|
|
options.hullfile = malloc (strlen (options.bspfile) + 5);
|
|
|
|
options.portfile = malloc (strlen (options.bspfile) + 5);
|
|
|
|
options.pointfile = malloc (strlen (options.bspfile) + 5);
|
|
|
|
|
|
|
|
// create filenames
|
|
|
|
QFS_StripExtension (options.bspfile, options.hullfile);
|
|
|
|
strcat (options.hullfile, ".h0");
|
|
|
|
|
|
|
|
QFS_StripExtension (options.bspfile, options.portfile);
|
|
|
|
strcat (options.portfile, ".prt");
|
|
|
|
|
|
|
|
QFS_StripExtension (options.bspfile, options.pointfile);
|
|
|
|
strcat (options.pointfile, ".pts");
|
2002-09-20 21:48:34 +00:00
|
|
|
}
|
2004-04-30 21:51:00 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
if (options.wadpath) {
|
|
|
|
char *t = malloc (strlen (options.wadpath) + 2);
|
|
|
|
strcpy (t, ";");
|
|
|
|
strcat (t, options.wadpath);
|
|
|
|
options.wadpath = t;
|
|
|
|
} else {
|
|
|
|
options.wadpath = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return optind;
|
|
|
|
}
|