forked from teamnwah/openmw-tes3coop
Added cell loading option -C to esmtool
This commit is contained in:
parent
5d2394a78b
commit
b68e859b6d
5 changed files with 118 additions and 56 deletions
|
@ -41,10 +41,9 @@ struct CellRef
|
|||
float charge;
|
||||
|
||||
// I have no idea, these are present some times, often along with
|
||||
// owner (ANAM) and sometimes otherwise. Is NAM9 is always 1? INTV
|
||||
// is usually one, but big for lights. Perhaps something to do with
|
||||
// remaining light "charge". I haven't tried reading it as a float
|
||||
// in those cases.
|
||||
// owner (ANAM) and sometimes otherwise. They are often (but not
|
||||
// always) 1. INTV is big for lights (possibly a float?), might have
|
||||
// something to do with remaining light "charge".
|
||||
int intv, nam9;
|
||||
|
||||
// For doors - true if this door teleports to somewhere else, false
|
||||
|
@ -180,8 +179,8 @@ struct Cell
|
|||
esm.getHNT(ref.refnum, "FRMR");
|
||||
ref.refID = esm.getHNString("NAME");
|
||||
|
||||
// getHNOT will not change the existing value (1.0) if the
|
||||
// subrecord is missing
|
||||
// getHNOT will not change the existing value if the subrecord is
|
||||
// missing
|
||||
ref.scale = 1.0;
|
||||
esm.getHNOT(ref.scale, "XSCL");
|
||||
|
||||
|
@ -190,9 +189,10 @@ struct Cell
|
|||
ref.soul = esm.getHNOString("XSOL");
|
||||
|
||||
ref.faction = esm.getHNOString("CNAM");
|
||||
ref.factIndex = -1;
|
||||
esm.getHNOT(ref.factIndex, "INDX");
|
||||
|
||||
ref.charge = 0.0;
|
||||
ref.charge = -1.0;
|
||||
esm.getHNOT(ref.charge, "XCHG");
|
||||
|
||||
ref.intv = 0;
|
||||
|
@ -209,7 +209,8 @@ struct Cell
|
|||
}
|
||||
else ref.teleport = false;
|
||||
|
||||
esm.getHNOT(ref.lockLevel, "FLTV"); // int, despite the name
|
||||
// Integer, despite the name suggesting otherwise
|
||||
esm.getHNOT(ref.lockLevel, "FLTV");
|
||||
ref.key = esm.getHNOString("KNAM");
|
||||
ref.trap = esm.getHNOString("TNAM");
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ using namespace std;
|
|||
using namespace ESM;
|
||||
|
||||
void printRaw(ESMReader &esm);
|
||||
void loadCell(Cell &cell, ESMReader &esm, bool quiet);
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
|
@ -31,6 +32,8 @@ int main(int argc, char**argv)
|
|||
const char* filename = info.inputs[0];
|
||||
cout << "\nFile: " << filename << endl;
|
||||
|
||||
try {
|
||||
|
||||
if(info.raw_given)
|
||||
{
|
||||
cout << "RAW file listing:\n";
|
||||
|
@ -43,6 +46,7 @@ int main(int argc, char**argv)
|
|||
}
|
||||
|
||||
bool quiet = info.quiet_given;
|
||||
bool loadCells = info.loadcells_given;
|
||||
|
||||
esm.open(filename);
|
||||
|
||||
|
@ -139,9 +143,13 @@ int main(int argc, char**argv)
|
|||
{
|
||||
Cell b;
|
||||
b.load(esm);
|
||||
if(quiet) break;
|
||||
cout << " Name: " << b.name << endl;
|
||||
cout << " Region: " << b.region << endl;
|
||||
if(!quiet)
|
||||
{
|
||||
cout << " Name: " << b.name << endl;
|
||||
cout << " Region: " << b.region << endl;
|
||||
}
|
||||
if(loadCells)
|
||||
loadCell(b, esm, quiet);
|
||||
break;
|
||||
}
|
||||
case REC_CLAS:
|
||||
|
@ -250,9 +258,34 @@ int main(int argc, char**argv)
|
|||
}
|
||||
}
|
||||
|
||||
} catch(exception &e)
|
||||
{
|
||||
cout << "\nERROR:\n\n " << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void loadCell(Cell &cell, ESMReader &esm, bool quiet)
|
||||
{
|
||||
// Skip back to the beginning of the reference list
|
||||
cell.restore(esm);
|
||||
|
||||
// Loop through all the references
|
||||
CellRef ref;
|
||||
if(!quiet) cout << " References:\n";
|
||||
while(cell.getNextRef(esm, ref))
|
||||
{
|
||||
if(quiet) continue;
|
||||
|
||||
cout << " Refnum: " << ref.refnum << endl;
|
||||
cout << " ID: '" << ref.refID << "'\n";
|
||||
cout << " Owner: '" << ref.owner << "'\n";
|
||||
cout << " INTV: " << ref.intv << " NAM9: " << ref.intv << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void printRaw(ESMReader &esm)
|
||||
{
|
||||
while(esm.hasMoreRecs())
|
||||
|
|
|
@ -5,5 +5,6 @@ args "--unamed-opts=ES-FILE -F esmtool_cmd -G"
|
|||
|
||||
option "raw" r "Show an unformattet list of all records and subrecords" optional
|
||||
option "quiet" q "Supress all record information. Useful for speed tests." optional
|
||||
option "loadcells" C "Browse through contents of all cells." optional
|
||||
|
||||
text "\nIf no option is given, the default action is to parse the entire archive and diplay diagnostic information."
|
||||
text "\nIf no option is given, the default action is to parse all records in the archive and display diagnostic information."
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
File autogenerated by gengetopt version 2.22.2
|
||||
File autogenerated by gengetopt version 2.22
|
||||
generated with the following command:
|
||||
gengetopt --unamed-opts=ES-FILE -F esmtool_cmd -G
|
||||
|
||||
|
@ -17,10 +17,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef FIX_UNUSED
|
||||
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
|
||||
#endif
|
||||
|
||||
|
||||
#include "esmtool_cmd.h"
|
||||
|
||||
|
@ -31,11 +27,12 @@ const char *gengetopt_args_info_usage = "Usage: esmtool [OPTIONS]... [ES-FILE]..
|
|||
const char *gengetopt_args_info_description = "";
|
||||
|
||||
const char *gengetopt_args_info_help[] = {
|
||||
" -h, --help Print help and exit",
|
||||
" -V, --version Print version and exit",
|
||||
" -r, --raw Show an unformattet list of all records and subrecords",
|
||||
" -q, --quiet Supress all record information. Useful for speed tests.",
|
||||
"\nIf no option is given, the default action is to parse the entire archive and \ndiplay diagnostic information.",
|
||||
" -h, --help Print help and exit",
|
||||
" -V, --version Print version and exit",
|
||||
" -r, --raw Show an unformattet list of all records and subrecords",
|
||||
" -q, --quiet Supress all record information. Useful for speed tests.",
|
||||
" -C, --loadcells Browse through contents of all cells.",
|
||||
"\nIf no option is given, the default action is to parse all records in the \narchive and display diagnostic information.",
|
||||
0
|
||||
};
|
||||
|
||||
|
@ -62,12 +59,12 @@ void clear_given (struct gengetopt_args_info *args_info)
|
|||
args_info->version_given = 0 ;
|
||||
args_info->raw_given = 0 ;
|
||||
args_info->quiet_given = 0 ;
|
||||
args_info->loadcells_given = 0 ;
|
||||
}
|
||||
|
||||
static
|
||||
void clear_args (struct gengetopt_args_info *args_info)
|
||||
{
|
||||
FIX_UNUSED (args_info);
|
||||
|
||||
}
|
||||
|
||||
|
@ -80,15 +77,14 @@ void init_args_info(struct gengetopt_args_info *args_info)
|
|||
args_info->version_help = gengetopt_args_info_help[1] ;
|
||||
args_info->raw_help = gengetopt_args_info_help[2] ;
|
||||
args_info->quiet_help = gengetopt_args_info_help[3] ;
|
||||
args_info->loadcells_help = gengetopt_args_info_help[4] ;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cmdline_parser_print_version (void)
|
||||
{
|
||||
printf ("%s %s\n",
|
||||
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
|
||||
CMDLINE_PARSER_VERSION);
|
||||
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
|
||||
}
|
||||
|
||||
static void print_help_common(void) {
|
||||
|
@ -103,7 +99,7 @@ static void print_help_common(void) {
|
|||
printf("\n");
|
||||
|
||||
if (strlen(gengetopt_args_info_description) > 0)
|
||||
printf("%s\n\n", gengetopt_args_info_description);
|
||||
printf("%s\n", gengetopt_args_info_description);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,7 +118,7 @@ cmdline_parser_init (struct gengetopt_args_info *args_info)
|
|||
clear_args (args_info);
|
||||
init_args_info (args_info);
|
||||
|
||||
args_info->inputs = 0;
|
||||
args_info->inputs = NULL;
|
||||
args_info->inputs_num = 0;
|
||||
}
|
||||
|
||||
|
@ -167,9 +163,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info)
|
|||
|
||||
|
||||
static void
|
||||
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
|
||||
write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
|
||||
{
|
||||
FIX_UNUSED (values);
|
||||
if (arg) {
|
||||
fprintf(outfile, "%s=\"%s\"\n", opt, arg);
|
||||
} else {
|
||||
|
@ -197,6 +192,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
|
|||
write_into_file(outfile, "raw", 0, 0 );
|
||||
if (args_info->quiet_given)
|
||||
write_into_file(outfile, "quiet", 0, 0 );
|
||||
if (args_info->loadcells_given)
|
||||
write_into_file(outfile, "loadcells", 0, 0 );
|
||||
|
||||
|
||||
i = EXIT_SUCCESS;
|
||||
|
@ -233,7 +230,7 @@ cmdline_parser_free (struct gengetopt_args_info *args_info)
|
|||
char *
|
||||
gengetopt_strdup (const char *s)
|
||||
{
|
||||
char *result = 0;
|
||||
char *result = NULL;
|
||||
if (!s)
|
||||
return result;
|
||||
|
||||
|
@ -255,7 +252,7 @@ cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *ar
|
|||
struct cmdline_parser_params *params)
|
||||
{
|
||||
int result;
|
||||
result = cmdline_parser_internal (argc, argv, args_info, params, 0);
|
||||
result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
|
||||
|
||||
if (result == EXIT_FAILURE)
|
||||
{
|
||||
|
@ -278,7 +275,7 @@ cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_
|
|||
params.check_ambiguity = 0;
|
||||
params.print_errors = 1;
|
||||
|
||||
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
|
||||
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, NULL);
|
||||
|
||||
if (result == EXIT_FAILURE)
|
||||
{
|
||||
|
@ -292,8 +289,6 @@ cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_
|
|||
int
|
||||
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
|
||||
{
|
||||
FIX_UNUSED (args_info);
|
||||
FIX_UNUSED (prog_name);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -327,6 +322,37 @@ struct option
|
|||
int val;
|
||||
};
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
static char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
static int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
static int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
static int optopt;
|
||||
|
||||
/* This version of `getopt' appears to the caller like standard Unix `getopt'
|
||||
but it behaves differently for the user, since it allows the user
|
||||
to intersperse the options with the other arguments.
|
||||
|
@ -708,7 +734,7 @@ static int check_short_opt(int argc, char *const *argv, const char *optstring,
|
|||
int print_errors, struct custom_getopt_data *d)
|
||||
{
|
||||
char c = *d->nextchar++;
|
||||
const char *temp = strchr(optstring, c);
|
||||
char *temp = strchr(optstring, c);
|
||||
|
||||
/* Increment `custom_optind' when we start to process its last character. */
|
||||
if (*d->nextchar == '\0')
|
||||
|
@ -913,15 +939,13 @@ static char *package_name = 0;
|
|||
static
|
||||
int update_arg(void *field, char **orig_field,
|
||||
unsigned int *field_given, unsigned int *prev_given,
|
||||
char *value, const char *possible_values[],
|
||||
const char *default_value,
|
||||
char *value, char *possible_values[], const char *default_value,
|
||||
cmdline_parser_arg_type arg_type,
|
||||
int check_ambiguity, int override,
|
||||
int no_free, int multiple_option,
|
||||
const char *long_opt, char short_opt,
|
||||
const char *additional_error)
|
||||
{
|
||||
FIX_UNUSED (field);
|
||||
char *stop_char = 0;
|
||||
const char *val = value;
|
||||
int found;
|
||||
|
@ -942,7 +966,6 @@ int update_arg(void *field, char **orig_field,
|
|||
return 1; /* failure */
|
||||
}
|
||||
|
||||
FIX_UNUSED (default_value);
|
||||
|
||||
if (field_given && *field_given && ! override)
|
||||
return 0;
|
||||
|
@ -980,8 +1003,7 @@ int update_arg(void *field, char **orig_field,
|
|||
|
||||
|
||||
int
|
||||
cmdline_parser_internal (
|
||||
int argc, char * const *argv, struct gengetopt_args_info *args_info,
|
||||
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
|
||||
struct cmdline_parser_params *params, const char *additional_error)
|
||||
{
|
||||
int c; /* Character of the parsed option. */
|
||||
|
@ -993,11 +1015,6 @@ cmdline_parser_internal (
|
|||
int initialize;
|
||||
int check_required;
|
||||
int check_ambiguity;
|
||||
|
||||
char *optarg;
|
||||
int optind;
|
||||
int opterr;
|
||||
int optopt;
|
||||
|
||||
package_name = argv[0];
|
||||
|
||||
|
@ -1025,7 +1042,8 @@ cmdline_parser_internal (
|
|||
{ "version", 0, NULL, 'V' },
|
||||
{ "raw", 0, NULL, 'r' },
|
||||
{ "quiet", 0, NULL, 'q' },
|
||||
{ 0, 0, 0, 0 }
|
||||
{ "loadcells", 0, NULL, 'C' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
custom_optarg = optarg;
|
||||
|
@ -1033,7 +1051,7 @@ cmdline_parser_internal (
|
|||
custom_opterr = opterr;
|
||||
custom_optopt = optopt;
|
||||
|
||||
c = custom_getopt_long (argc, argv, "hVrq", long_options, &option_index);
|
||||
c = custom_getopt_long (argc, argv, "hVrqC", long_options, &option_index);
|
||||
|
||||
optarg = custom_optarg;
|
||||
optind = custom_optind;
|
||||
|
@ -1078,6 +1096,18 @@ cmdline_parser_internal (
|
|||
goto failure;
|
||||
|
||||
break;
|
||||
case 'C': /* Browse through contents of all cells.. */
|
||||
|
||||
|
||||
if (update_arg( 0 ,
|
||||
0 , &(args_info->loadcells_given),
|
||||
&(local_args_info.loadcells_given), optarg, 0, 0, ARG_NO,
|
||||
check_ambiguity, override, 0, 0,
|
||||
"loadcells", 'C',
|
||||
additional_error))
|
||||
goto failure;
|
||||
|
||||
break;
|
||||
|
||||
case 0: /* Long option with no short option */
|
||||
case '?': /* Invalid option. */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/** @file esmtool_cmd.h
|
||||
* @brief The header file for the command line option parser
|
||||
* generated by GNU Gengetopt version 2.22.2
|
||||
* generated by GNU Gengetopt version 2.22
|
||||
* http://www.gnu.org/software/gengetopt.
|
||||
* DO NOT modify this file, since it can be overwritten
|
||||
* @author GNU Gengetopt by Lorenzo Bettini */
|
||||
|
@ -20,15 +20,10 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef CMDLINE_PARSER_PACKAGE
|
||||
/** @brief the program name (used for printing errors) */
|
||||
/** @brief the program name */
|
||||
#define CMDLINE_PARSER_PACKAGE "esmtool"
|
||||
#endif
|
||||
|
||||
#ifndef CMDLINE_PARSER_PACKAGE_NAME
|
||||
/** @brief the complete program name (used for help and version) */
|
||||
#define CMDLINE_PARSER_PACKAGE_NAME "esmtool"
|
||||
#endif
|
||||
|
||||
#ifndef CMDLINE_PARSER_VERSION
|
||||
/** @brief the program version */
|
||||
#define CMDLINE_PARSER_VERSION "1.0"
|
||||
|
@ -41,11 +36,13 @@ struct gengetopt_args_info
|
|||
const char *version_help; /**< @brief Print version and exit help description. */
|
||||
const char *raw_help; /**< @brief Show an unformattet list of all records and subrecords help description. */
|
||||
const char *quiet_help; /**< @brief Supress all record information. Useful for speed tests. help description. */
|
||||
const char *loadcells_help; /**< @brief Browse through contents of all cells. help description. */
|
||||
|
||||
unsigned int help_given ; /**< @brief Whether help was given. */
|
||||
unsigned int version_given ; /**< @brief Whether version was given. */
|
||||
unsigned int raw_given ; /**< @brief Whether raw was given. */
|
||||
unsigned int quiet_given ; /**< @brief Whether quiet was given. */
|
||||
unsigned int loadcells_given ; /**< @brief Whether loadcells was given. */
|
||||
|
||||
char **inputs ; /**< @brief unamed options (options without names) */
|
||||
unsigned inputs_num ; /**< @brief unamed options number */
|
||||
|
|
Loading…
Reference in a new issue