Commit 481b8046 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

changed type of argument_t's argv from char ** to std::vector<char *>

parent 6c9d0dda
......@@ -13,7 +13,7 @@ argument_t *file_argument_new(const char *filename)
argument_t *argument = new argument_t();
argument->argc = 1;
argument->argv = (char **) Calloc(1, sizeof(char *));
argument->argv.resize(argument->argc);
argument->argv[0] = (char *) filename;
argument->args = (char *) filename;
......@@ -27,9 +27,8 @@ void file_argument_free(argument_t *argument)
if ( argument->argc )
{
assert(argument->argc == 1);
Free(argument->argv);
}
Free(argument);
delete(argument);
}
}
......@@ -40,7 +39,7 @@ argument_t *argument_new(size_t argc, size_t len)
if ( argc > 0 )
{
argument->argc = argc;
argument->argv = (char **) Calloc(argc, sizeof(char *));
argument->argv.resize(argc);
}
if ( len > 0 )
......@@ -60,13 +59,10 @@ void argument_free(argument_t *argument)
{
if ( argument->argv[i] )
{
Free(argument->argv[i]);
argument->argv[i] = NULL;
argument->argv[i] = NULL;
}
}
Free(argument->argv);
argument->argv = NULL;
argument->argc = 0;
}
......
......@@ -2,13 +2,14 @@
#define ARGUMENT_H
#include <string>
#include <vector>
struct argument_t
{
//argument_t();
int process_id;
int argc;
char **argv;
std::vector<char *> argv;
char *args;
std::string operatorName;
char * operatorArguments;
......
......@@ -406,10 +406,10 @@ processOperator(void)
return processSelf().xoperator;
}
static int skipInputStreams(int argc, char *argv[], int globArgc, int nstreams);
static int skipInputStreams(int argc, std::vector<char *> &argv, int globArgc, int nstreams);
static int
getGlobArgc(int argc, char *argv[], int globArgc)
getGlobArgc(int argc, std::vector<char *> &argv, int globArgc)
{
char *opername = &argv[globArgc][1];
char *comma_position = strchr(opername, ',');
......@@ -436,7 +436,7 @@ getGlobArgc(int argc, char *argv[], int globArgc)
}
static int
skipInputStreams(int argc, char *argv[], int globArgc, int nstreams)
skipInputStreams(int argc, std::vector<char*>& argv, int globArgc, int nstreams)
{
while (nstreams > 0)
{
......@@ -459,7 +459,7 @@ skipInputStreams(int argc, char *argv[], int globArgc, int nstreams)
}
static int
getStreamCnt(int argc, char *argv[])
getStreamCnt(int argc, std::vector<char *>& argv)
{
int streamCnt = 0;
int globArgc = 1;
......@@ -480,7 +480,7 @@ getStreamCnt(int argc, char *argv[])
}
static void
setStreamNames(int argc, char *argv[])
setStreamNames(int argc, std::vector<char *> &argv)
{
process_t &process = processSelf();
int i, ac;
......@@ -512,7 +512,7 @@ setStreamNames(int argc, char *argv[])
process.streamNames[process.streamCnt].args = streamname;
ac = globArgc - globArgcStart;
// printf("setStreamNames: ac %d streamname1: %s\n", ac, streamname);
process.streamNames[process.streamCnt].argv = (char **) Malloc(ac * sizeof(char *));
process.streamNames[process.streamCnt].argv.resize(ac);
for (i = 0; i < ac; ++i)
process.streamNames[process.streamCnt].argv[i] = argv[i + globArgcStart];
process.streamNames[process.streamCnt].argc = ac;
......@@ -526,7 +526,7 @@ setStreamNames(int argc, char *argv[])
strcpy(streamname, argv[globArgc]);
process.streamNames[process.streamCnt].args = streamname;
ac = 1;
process.streamNames[process.streamCnt].argv = (char **) Malloc(ac * sizeof(char *));
process.streamNames[process.streamCnt].argv.resize(ac);
process.streamNames[process.streamCnt].argv[0] = argv[globArgc];
process.streamNames[process.streamCnt].argc = ac;
process.streamNames[process.streamCnt].args = streamname;
......@@ -605,7 +605,6 @@ expand_wildcards(process_t &process, int streamCnt)
streamCnt = streamCnt - 1 + glob_arg->argc;
Free(process.streamNames[0].argv);
Free(process.streamNames[0].args);
process.streamNames.resize(streamCnt);
......@@ -616,10 +615,11 @@ expand_wildcards(process_t &process, int streamCnt)
for (int i = 0; i < glob_arg->argc; ++i)
{
process.streamNames[i].argv = (char **) Malloc(sizeof(char *));
process.streamNames[i].argc = 1;
process.streamNames[i].argv[0] = strdupx(glob_arg->argv[i]);
process.streamNames[i].args = strdupx(glob_arg->argv[i]);
argument_t &current_argument = process.streamNames[i];
current_argument.argc = 1;
current_argument.argv.resize(current_argument.argc);
current_argument.argv[0] = strdupx(glob_arg->argv[i]);
current_argument.args = strdupx(glob_arg->argv[i]);
if (cdoVerbose)
cdoPrint(" >%s<", glob_arg->argv[i]);
}
......@@ -713,7 +713,7 @@ checkStreamCnt(void)
}
static void
setStreams(int argc, char *argv[])
setStreams(int argc, std::vector<char *> &argv)
{
process_t &process = processSelf();
int streamCnt = getStreamCnt(argc, argv);
......@@ -728,7 +728,6 @@ setStreams(int argc, char *argv[])
for (int i = 0; i < streamCnt; i++)
{
process.streamNames[i].argc = 0;
process.streamNames[i].argv = NULL;
process.streamNames[i].args = NULL;
}
......@@ -753,7 +752,7 @@ processDefArgument(void *vargument)
int oargc = 0;
char **oargv = process.oargv;
int argc = ((argument_t *) vargument)->argc;
char **argv = ((argument_t *) vargument)->argv;
std::vector<char *> &argv = ((argument_t *) vargument)->argv;
process.xoperator = argv[0];
process.operatorName = getOperatorName(process.xoperator);
......
......@@ -391,7 +391,7 @@ pstream_t::pstreamOpenReadPipe(const argument_t *argument)
argument_t *newargument = argument_new(argument->argc + 1, argument->argc *sizeof(char *));
newargument->operatorName = "";
memcpy(newargument->argv, argument->argv, argument->argc * sizeof(char *));
newargument->argv = argument->argv;
char *operatorArg = argument->argv[0];
const char *operatorName = getOperatorName(operatorArg);
......@@ -947,8 +947,6 @@ pstreamCloseChildStream(pstream_t *pstreamptr)
if (pstreamptr->argument)
{
argument_t *argument = (argument_t *) (pstreamptr->argument);
if (argument->argv)
Free(argument->argv);
if (argument->args)
Free(argument->args);
delete (argument);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment