summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/HPM.c4
-rw-r--r--src/common/core.c35
-rw-r--r--src/common/core.h4
3 files changed, 22 insertions, 21 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 454da9fbb..77c7e3fa2 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -347,9 +347,9 @@ bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecF
return false;
}
- ARR_FIND(0, cmdline->args_data_count, i, strcmp(cmdline->args_data[i].name, name) == 0);
+ ARR_FIND(0, VECTOR_LENGTH(cmdline->args_data), i, strcmp(VECTOR_INDEX(cmdline->args_data, i).name, name) == 0);
- if (i < cmdline->args_data_count) {
+ if (i != VECTOR_LENGTH(cmdline->args_data)) {
ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID));
return false;
}
diff --git a/src/common/core.c b/src/common/core.c
index dcc96fa41..8564b8acc 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -207,8 +207,9 @@ const char *cmdline_arg_source(struct CmdlineArgData *arg) {
bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) {
struct CmdlineArgData *data = NULL;
- RECREATE(cmdline->args_data, struct CmdlineArgData, ++cmdline->args_data_count);
- data = &cmdline->args_data[cmdline->args_data_count-1];
+ VECTOR_ENSURE(cmdline->args_data, 1, 1);
+ VECTOR_PUSHZEROED(cmdline->args_data);
+ data = &VECTOR_LAST(cmdline->args_data);
data->pluginID = pluginID;
data->name = aStrdup(name);
data->shortname = shortname;
@@ -228,8 +229,8 @@ static CMDLINEARG(help)
ShowInfo("\n");
ShowInfo("Options:\n");
- for (i = 0; i < cmdline->args_data_count; i++) {
- struct CmdlineArgData *data = &cmdline->args_data[i];
+ for (i = 0; i < VECTOR_LENGTH(cmdline->args_data); i++) {
+ struct CmdlineArgData *data = &VECTOR_INDEX(cmdline->args_data, i);
char altname[16], paramnames[256];
if (data->shortname) {
snprintf(altname, sizeof(altname), " [-%c]", data->shortname);
@@ -288,8 +289,9 @@ bool cmdline_arg_next_value(const char *name, int current_arg, int argc)
*/
int cmdline_exec(int argc, char **argv, unsigned int options)
{
- int count = 0, i, j;
+ int count = 0, i;
for (i = 1; i < argc; i++) {
+ int j;
struct CmdlineArgData *data = NULL;
const char *arg = argv[i];
if (arg[0] != '-') { // All arguments must begin with '-'
@@ -297,17 +299,17 @@ int cmdline_exec(int argc, char **argv, unsigned int options)
exit(EXIT_FAILURE);
}
if (arg[1] != '-' && strlen(arg) == 2) {
- ARR_FIND(0, cmdline->args_data_count, j, cmdline->args_data[j].shortname == arg[1]);
+ ARR_FIND(0, VECTOR_LENGTH(cmdline->args_data), j, VECTOR_INDEX(cmdline->args_data, j).shortname == arg[1]);
} else {
- ARR_FIND(0, cmdline->args_data_count, j, strcmpi(cmdline->args_data[j].name, arg) == 0);
+ ARR_FIND(0, VECTOR_LENGTH(cmdline->args_data), j, strcmpi(VECTOR_INDEX(cmdline->args_data, j).name, arg) == 0);
}
- if (j == cmdline->args_data_count) {
+ if (j == VECTOR_LENGTH(cmdline->args_data)) {
if (options&(CMDLINE_OPT_SILENT|CMDLINE_OPT_PREINIT))
continue;
ShowError("Unknown option '%s'.\n", arg);
exit(EXIT_FAILURE);
}
- data = &cmdline->args_data[j];
+ data = &VECTOR_INDEX(cmdline->args_data, j);
if (data->options&CMDLINE_OPT_PARAM) {
if (!cmdline->arg_next_value(arg, i, argc))
exit(EXIT_FAILURE);
@@ -346,15 +348,15 @@ void cmdline_init(void)
#endif // !MINICORE
cmdline_args_init_local();
}
+
void cmdline_final(void)
{
- int i;
- for (i = 0; i < cmdline->args_data_count; i++) {
- aFree(cmdline->args_data[i].name);
- aFree(cmdline->args_data[i].help);
+ while (VECTOR_LENGTH(cmdline->args_data) > 0) {
+ struct CmdlineArgData *data = &VECTOR_POP(cmdline->args_data);
+ aFree(data->name);
+ aFree(data->help);
}
- if (cmdline->args_data)
- aFree(cmdline->args_data);
+ VECTOR_CLEAR(cmdline->args_data);
}
struct cmdline_interface cmdline_s;
@@ -364,8 +366,7 @@ void cmdline_defaults(void)
{
cmdline = &cmdline_s;
- cmdline->args_data = NULL;
- cmdline->args_data_count = 0;
+ VECTOR_INIT(cmdline->args_data);
cmdline->init = cmdline_init;
cmdline->final = cmdline_final;
diff --git a/src/common/core.h b/src/common/core.h
index c92bf4fa6..f8e748db4 100644
--- a/src/common/core.h
+++ b/src/common/core.h
@@ -6,6 +6,7 @@
#define COMMON_CORE_H
#include "common/hercules.h"
+#include "common/db.h"
/* so that developers with --enable-debug can raise signals from any section of the code they'd like */
#ifdef DEBUG
@@ -46,8 +47,7 @@ struct CmdlineArgData {
};
struct cmdline_interface {
- struct CmdlineArgData *args_data;
- int args_data_count;
+ VECTOR_DECL(struct CmdlineArgData) args_data;
void (*init) (void);
void (*final) (void);