Commit aa5b1a5a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge src/operator_help.h.

parents 7babd2d5 d51c31b9
This diff is collapsed.
......@@ -73,6 +73,8 @@
#define MAX_NUM_VARNAMES 256
#include <string>
static int Debug = 0;
static int Version = 0;
static int Help = 0;
......@@ -332,50 +334,47 @@ void cdo_init_is_tty(void)
}
static
void cdoPrintHelp(const char *phelp[]/*, char *xoperator*/)
void cdoPrintHelp(std::vector<std::string> help/*, char *xoperator*/)
{
if ( phelp == NULL )
if (help.empty())
fprintf(stderr, "No help available for this operator!\n");
else
{
bool lprint;
while ( *phelp )
for(unsigned long i = 0; i < help.size(); i++)
{
lprint = !(*phelp[0] == '\0' && *(phelp+1) && *(phelp+1)[0] == ' ');
lprint = !(help[i][0] == '\0' && help[i+1][0] == ' ');
if ( lprint )
{
if ( COLOR_STDOUT )
{
if ( (strcmp(*phelp, "NAME") == 0) ||
(strcmp(*phelp, "SYNOPSIS") == 0) ||
(strcmp(*phelp, "DESCRIPTION") == 0) ||
(strcmp(*phelp, "OPERATORS") == 0) ||
(strcmp(*phelp, "NAMELIST") == 0) ||
(strcmp(*phelp, "PARAMETER") == 0) ||
(strcmp(*phelp, "ENVIRONMENT") == 0) ||
(strcmp(*phelp, "NOTE") == 0) ||
(strcmp(*phelp, "EXAMPLES") == 0) )
if ( (help[i].compare( "NAME") == 0) ||
(help[i].compare( "SYNOPSIS") == 0) ||
(help[i].compare( "DESCRIPTION") == 0) ||
(help[i].compare( "OPERATORS") == 0) ||
(help[i].compare( "NAMELIST") == 0) ||
(help[i].compare( "PARAMETER") == 0) ||
(help[i].compare( "ENVIRONMENT") == 0) ||
(help[i].compare( "NOTE") == 0) ||
(help[i].compare( "EXAMPLES") == 0) )
{
set_text_color(stdout, BRIGHT, BLACK);
fprintf(stdout, "%s", *phelp);
fprintf(stdout, "%s", help[i].c_str());
reset_text_color(stdout);
fprintf(stdout, "\n");
}
else
fprintf(stdout, "%s\n", *phelp);
fprintf(stdout, "%s\n", help[i].c_str());
}
else
{
fprintf(stdout, "%s\n", *phelp);
fprintf(stdout, "%s\n", help[i].c_str());
}
}
phelp++;
}
}
}
static
void cdoSetDebug(int level)
{
......@@ -1459,7 +1458,7 @@ int main(int argc, char *argv[])
int lstop = FALSE;
int noff = 0;
int status = 0;
char *operatorArg = NULL;
const char *operatorArg = NULL;
argument_t *argument = NULL;
cdo_init_is_tty();
......@@ -1480,7 +1479,7 @@ int main(int argc, char *argv[])
if ( noff ) setDefaultFileType(Progname+noff, 0);
get_env_vars();
init_modules();
status = parse_options_long(argc, argv);
if ( status != 0 ) return -1;
......@@ -1607,7 +1606,14 @@ int main(int argc, char *argv[])
timer_start(timer_total);
#ifdef CUSTOM_MODULES
load_custom_modules("custom_modules");
operatorModule(operatorName)(argument);
close_library_handles();
#else
operatorModule(operatorName)(argument);
#endif
timer_stop(timer_total);
......
This diff is collapsed.
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2017 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
/***
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; version 2 of the License.
Copyright (C) 2003-2017 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
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.
*/
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; version 2 of the License.
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.
*/
#ifndef _MODULES_H
#define _MODULES_H
#define MAX_MOD_OPERATORS 128 // maximum number of operators for a module
#include <iostream>
#include <map>
#include <stdbool.h>
#include <vector>
/***
type definition for module functions loaded from a custom module
*/
typedef void (*dyn_oper_t)(void *arg);
typedef struct {
void *(*func)(void *); // Module
std::vector<std::string> help; // Help
std::vector<const char *> operators; // Operator names
short mode; // Module mode: 0:intern 1:extern
short number; // Allowed number type
short streamInCnt; // Number of input streams
short streamOutCnt; // Number of output streams
} modules_t;
extern int NumModules;
extern int NumAliases;
/***
vector for library handles for loaded custom modules
*/
static std::vector<void *> custom_modules_lib_handles;
/**
* Maps operator names to their module names
*/
static std::map<std::string, std::string> modules_map;
/**
* Contains added modules as values and their names as key
*/
static std::map<std::string, modules_t> modules;
/***
* Key: operator alias / Value: operator original name
*/
static std::map<std::string, std::string> aliases;
void *(*operatorModule(std::string operatorName))(void *);
void *(*operatorModule(const char *operatorName))(void *);
void init_modules();
const char **operatorHelp(const char *operatorName);
void init_aliases();
int add_alias(std::string alias, std::string original);
void add_module(std::string module_name, modules_t new_module);
std::string get_module_name_to(std::string operatorName);
std::vector<std::string> operatorHelp(std::string operatorName);
int operatorStreamInCnt(const char *operatorName);
int operatorStreamOutCnt(const char *operatorName);
int operatorStreamNumber(const char *operatorName);
void operatorPrintAll(void);
void operatorPrintList(bool print_no_output);
#ifdef CUSTOM_MODULES
void load_custom_module(std::string path);
void load_custom_modules(std::string folder_path);
void close_library_handles();
#endif
#endif /* _MODULES_H */
#endif /* _MODULES_H */
This diff is collapsed.
......@@ -221,7 +221,6 @@ char *getOperator(const char *argument)
return operatorArg;
}
const char *operatorAlias(const char *operatorName);
const char *getOperatorName(const char *operatorArg)
{
......@@ -241,7 +240,10 @@ const char *getOperatorName(const char *operatorArg)
}
/* return operatorName; */
return operatorAlias(operatorName);
std::string opName = aliases[std::string(operatorName)];
memcpy(operatorName,opName.c_str(),opName.size() );
return operatorName;
}
......@@ -390,7 +392,15 @@ void input_int(char *arg, int intarr[], int maxint, int *nintfound)
*nintfound = nint;
}
std::string string2lower(std::string str)
{
std::string lower_case_string = str;
for(char c : str)
{
c = tolower(c);
}
return lower_case_string;
}
void strtolower(char *str)
{
if ( str )
......
......@@ -43,6 +43,7 @@
#define UNCHANGED_RECORD (processSelf() == 0 && cdoStreamName(0)->argv[0][0] != '-' && cdoRegulargrid == FALSE && cdoDefaultFileType == -1 && cdoDefaultDataType == -1 && cdoDefaultByteorder == -1 )
#include <string>
extern char *Progname;
extern char *cdoGridSearchDir;
extern int CDO_Reduce_Dim;
......@@ -221,6 +222,7 @@ int zaxisFromName(const char *zaxisname);
/* refactor: moved here from cdo.h */
int cdo_omp_get_thread_num(void);
void cdo_omp_set_num_threads(int nthreads);
std::string string2lower(std::string str);
void strtolower(char *str);
void strtoupper(char *str);
......
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