Commit e8d1b5a1 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

moved argument_t and its functions into their own files

parent 51c009eb
#include "argument.h"
#include "dmemory.h"
#include <string>
#include <iostream>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
argument_t *file_argument_new(const char *filename)
{
argument_t *argument = (argument_t*) Calloc(1, sizeof(argument_t));
argument->argc = 1;
argument->argv = (char **) Calloc(1, sizeof(char *));
argument->argv[0] = (char *) filename;
argument->args = (char *) filename;
return argument;
}
void file_argument_free(argument_t *argument)
{
if ( argument )
{
if ( argument->argc )
{
assert(argument->argc == 1);
Free(argument->argv);
}
Free(argument);
}
}
argument_t *argument_new(size_t argc, size_t len)
{
argument_t *argument = (argument_t*) Calloc(1, sizeof(argument_t));
if ( argc > 0 )
{
argument->argc = argc;
argument->argv = (char **) Calloc(argc, sizeof(char *));
}
if ( len > 0 )
argument->args = (char*) Calloc(len, sizeof(char));
return argument;
}
void argument_free(argument_t *argument)
{
if ( argument )
{
if ( argument->argc )
{
int argc = argument->argc;
for ( int i = 0; i < argc; ++i )
{
if ( argument->argv[i] )
{
Free(argument->argv[i]);
argument->argv[i] = NULL;
}
}
Free(argument->argv);
argument->argv = NULL;
argument->argc = 0;
}
if ( argument->args )
{
Free(argument->args);
argument->args = NULL;
}
Free(argument);
}
}
void argument_fill(argument_t *argument, int argc, char *argv[])
{
assert(argument->argc == argc);
for ( int iarg = 0; iarg < argc; ++iarg )
argument->argv[iarg] = strdup(argv[iarg]);
}
void print_argument(argument_t * p_argument)
{
std::cout << "argv with " << p_argument->argc << " arguments:" << std::endl;
for(int i = 0; i < p_argument->argc; i++)
{
std::cout << p_argument->argv[i] << " ";
}
std::cout << std::endl;
std::cout << "OperatorName: "<< p_argument->operatorName << std::endl;
std::cout << "operatorArguments: " << p_argument->operatorArguments << std::endl;
}
#ifndef ARGUMENT_H
#define ARGUMENT_H
#include <string>
struct argument_t
{
//argument_t();
int process_id;
int argc;
char **argv;
char *args;
std::string operatorName;
char * operatorArguments;
};
argument_t *file_argument_new(const char *filename);
void file_argument_free(argument_t *argument);
argument_t *argument_new(size_t argc, size_t len);
void argument_free(argument_t *argument);
void argument_fill(argument_t *argument, int argc, char *argv[]);
void print_argument(argument_t *argument);
#endif
......@@ -265,92 +265,6 @@ char *getOperatorArg(const char *xoperator)
return operatorArg;
}
argument_t *file_argument_new(const char *filename)
{
argument_t *argument = (argument_t*) Calloc(1, sizeof(argument_t));
argument->argc = 1;
argument->argv = (char **) Calloc(1, sizeof(char *));
argument->argv[0] = (char *) filename;
argument->args = (char *) filename;
return argument;
}
void file_argument_free(argument_t *argument)
{
if ( argument )
{
if ( argument->argc )
{
assert(argument->argc == 1);
Free(argument->argv);
}
Free(argument);
}
}
argument_t *argument_new(size_t argc, size_t len)
{
argument_t *argument = (argument_t*) Calloc(1, sizeof(argument_t));
if ( argc > 0 )
{
argument->argc = argc;
argument->argv = (char **) Calloc(argc, sizeof(char *));
}
if ( len > 0 )
argument->args = (char*) Calloc(len, sizeof(char));
return argument;
}
void argument_free(argument_t *argument)
{
if ( argument )
{
if ( argument->argc )
{
int argc = argument->argc;
for ( int i = 0; i < argc; ++i )
{
if ( argument->argv[i] )
{
Free(argument->argv[i]);
argument->argv[i] = NULL;
}
}
Free(argument->argv);
argument->argv = NULL;
argument->argc = 0;
}
if ( argument->args )
{
Free(argument->args);
argument->args = NULL;
}
Free(argument);
}
}
void argument_fill(argument_t *argument, int argc, char *argv[])
{
assert(argument->argc == argc);
for ( int iarg = 0; iarg < argc; ++iarg )
argument->argv[iarg] = strdup(argv[iarg]);
}
char *getFileArg(char *argument)
{
char *fileArg = NULL;
......@@ -944,16 +858,4 @@ void cdo_check_round(void)
}
}
void print_argument(argument_t * p_argument)
{
std::cout << "argv with " << p_argument->argc << " arguments:" << std::endl;
for(int i = 0; i < p_argument->argc; i++)
{
std::cout << p_argument->argv[i] << " ";
}
std::cout << std::endl;
std::cout << "OperatorName: "<< p_argument->operatorName << std::endl;
std::cout << "operatorArguments: " << p_argument->operatorArguments << std::endl;
}
......@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdbool.h>
#include "percentiles.h"
#include "argument.h"
/* dummy use of unused parameters to silence compiler warnings */
#define UNUSED(x) (void)x
......@@ -112,20 +113,7 @@ extern char CDO_File_Suffix[32]; // refactor: added keyword extern
extern const char *CDO_Version;
typedef struct {
int process_id;
int argc;
char **argv;
char *args;
std::string operatorName;
char * operatorArguments;
} argument_t;
argument_t *file_argument_new(const char *filename);
void file_argument_free(argument_t *argument);
argument_t *argument_new(size_t argc, size_t len);
void argument_free(argument_t *argument);
void argument_fill(argument_t *argument, int argc, char *argv[]);
char *getProgname(char *string);
char *GetOperator(const char *argument);
......@@ -238,5 +226,4 @@ int wildcardmatch(const char *w, const char *s);
void cdo_check_round(void);
void print_argument(argument_t *argument);
#endif /* _UTIL_H */
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