From: hades Date: Wed, 16 Aug 2000 13:43:50 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=318311519604870602be46faa2bded09aefb1d04;p=daqdata.git *** empty log message *** --- diff --git a/allParam/file/fileParam.c b/allParam/file/fileParam.c new file mode 100644 index 0000000..139a5aa --- /dev/null +++ b/allParam/file/fileParam.c @@ -0,0 +1,131 @@ +#define _POSIX_C_SOURCE 199509L + +#include "param.h" + +#define BUFFERSIZE 130 + +int conParam(Param *my) +{ + int i = 0; + char fileName[PARAM_MAX_NAME_LEN]; + FILE *f; + char buf[BUFFERSIZE]; + + strcpy(fileName, fn); + if (fileName == NULL) { + strcmp(fileName, "param.tcl"); + } + if (NULL == (f = fopen(fileName, "r"))) { + msglog(LOG_ERR, "opening param file: %s\n", strerror(errno)); + exit (-1); + } else { + int oneMore = 1; + my->overFullParamFile = 0; + while (oneMore) { + oneMore = 0; + if (i < PARAM_MAX_NVALS) { + if (fgets(buf, BUFFERSIZE, f) != NULL) { + oneMore = 1; + } + if (oneMore && (buf[0] != '#')) { + sscanf(buf, "set%s%s", my->pname[i], my->value[i]); + i++; + } + } else { + oneMore = 0; + msglog(LOG_WARNING, "Too many parameters in file, ignoring the rest.\n"); + my->overFullParamFile = 1; + } + } + my->nVals = i; + fclose(f); + } + return 0; +} + +void desParam(Param *my) +{ +} + +int Param_getParamNumber(const Param *my, const char *name, const char *idx, int num) +{ + int retVal = -1; + int i; + char fullName[PARAM_MAX_NAME_LEN]; + + if (num == -1) { + sprintf(fullName, "%s(%s)", name, idx); + } else { + sprintf(fullName, "%s(%s%d)", name, idx, num); + } + for (i = 0; i < my->nVals; i++) { + if (strcmp(my->pname[i], fullName) == 0) { + retVal = i; + } + } + return retVal; +} + +int Param_getInt(const Param *my, const char *name, const char *idx, int *val) +{ + int status; + char valstr[PARAM_MAX_VALUE_LEN]; + char *endptr; + if ((status = Param_getString(my, name, idx, valstr)) != 1) { + msglog(LOG_ERR, "Error: cannot get Parameter %s as a string", idx); + return status; + } + *val = strtoul(valstr, &endptr, 0); + if (*endptr == '\0') { + return PARAM_RV_NO_INT; + } + return 1; +} + +int Param_getString(const Param *my, const char *name, const char *idx, char *val) +{ + int n; + n = Param_getParamNumber(name, index, num); + if (n == -1) { + msglog(LOG_WARNING, "Parameter %s(%s) not found, returning NULL-pointer.\n", name, idx); + return 0; + } else { + strcpy(val[i], my->value[n]); + } + return 1; +} + +int Param_getIntArray(const Param *my, const char *name, const char *idx, int num, int *val) +{ + int status; + int tmp; + char index[PARAM_MAX_NAME_LEN]; + for (int i = 0 ; i < num ; i++) { + sprintf(index,"%s%d", idx, i); + if ((tmp = Param_getInt(my, name, index, val[i]) == 1) && (status >= 0)) { + status++; + } else { + status = tmp; + } + } + + return status; +} + +int Param_getStringArray(const Param *my, const char *name, const char *idx, int num, char **val) +{ + int status; + int tmp; + char index[PARAM_MAX_NAME_LEN]; + for (int i = 0 ; i < num ; i++) { + sprintf(index,"%s%d", idx, i); + if ((tmp = Param_getString(my, name, index, val[i]) == 1) && (status >= 0)) { + status++; + } else { + status = tmp; + } + } + + return status; +} + diff --git a/allParam/file/fileParam.h b/allParam/file/fileParam.h new file mode 100644 index 0000000..e6df724 --- /dev/null +++ b/allParam/file/fileParam.h @@ -0,0 +1,71 @@ +#ifndef PARAM_H +#define PARAM_H + +/************************************************************************** + * Section containing struct Param (different in the different param.h's) * + **************************************************************************/ + +#define PARAM_MAX_NAME_LEN 128 +#define PARAM_MAX_NVALS 1024 + +typedef struct ParamS { + int nVals; + int overFullParamFile; + char pname[PARAM_MAX_NVALS][PARAM_MAX_NAME_LEN]; + char value[PARAM_MAX_NVALS][PARAM_MAX_NAME_LEN]; +}; + +} Param; + +int Param_getParamNumber(const Param *, const char *, const char *, int); + +/****************************************************************** + * Section containing the API for param (common to all param.h's) * + ******************************************************************/ + +int conParam(Param *); +void desParam(Param *); + +/* + * All functions have a status as return value. If the return value is positive, + * it contains the number of array members returned (1 in case of + * Param_getString and Param_getInt, between 1 and num in case of + * Param_getStringArray and Param_getIntArray). + * + * Memory must be allocated for the result before the function is called. + * For example, calling Param_getInt needs + * + * > int status; + * > unsigned long int value; + * > if(status = Param_getInt(param, name, idx, value) != 1) { + * > printf("No parameter 'value' found. Exiting.\n"); + * > exit(-1); + * > } + * + * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the + * above example expands to + * + * > int status; + * > int num = 32; + * > char value[PARAM_MAX_VALUE_LEN][num]; + * > if(status = Param_getStringArray(param, name, idx, num, value) != num) { + * > printf("Not enough elements of 'value' found. Exiting.\n"); + * > exit(-1); + * > } + * + */ + +#define PARAM_RV_NO_SUCH_PARAMETER 0 +#define PARAM_RV_FAILED -1 +#define PARAM_RV_NO_INT -2 + +#define PARAM_MAX_VALUE_LEN 128 + +int Param_getInt(const Param *, const char *, const char *, unsigned long int *); +int Param_getString(const Param *, const char *, const char *, char *); + +int Param_getIntArray(const Param *, const char *, const char *, int, unsigned long int *); +int Param_getStringArray(const Param *, const char *, const char *, int, char **); + +#endif + diff --git a/allParam/ora/Makefile b/allParam/ora/Makefile index 8468a06..ff9adac 100644 --- a/allParam/ora/Makefile +++ b/allParam/ora/Makefile @@ -14,14 +14,22 @@ PROC_INCLUDES = include=/usr/include include=/usr/include/g++-2 \ include=$(ORACLE_HOME)/plsql/public \ include=$(ORACLE_HOME)/network/public +liboraParam.a : param.o + $(AR) $(ARFLAGS) $@ $< + +param.o : param.c param.h + +param.c : param.pc + $(PROC) $(PROCFLAGS) $(PROC_INCLUDES) iname=$< oname=$@ + oraParam.o : oraParam.cc oraParam.h ../param/enhParam.h oraParam.cc : oraParam.pc $(PROC) $(PROCFLAGS) $(PROC_INCLUDES) iname=$< oname=$@ clean : - rm -f *.o oraParam.cc oraParam.lis + rm -f *.o param.c param.lis oraParam.cc oraParam.lis lib_clean : - rm -f *.o *.a oraParam.cc oraParam.lis + rm -f *.o *.a param.c param.lis oraParam.cc oraParam.lis diff --git a/allParam/ora/oraParam.h b/allParam/ora/oraParam.h new file mode 100644 index 0000000..ea8515c --- /dev/null +++ b/allParam/ora/oraParam.h @@ -0,0 +1,59 @@ +#ifndef PARAM_H +#define PARAM_H + +/************************************************************************** + * Section containing struct Param (different in the different param.h's) * + **************************************************************************/ + +typedef struct ParamS { +} Param; + +/****************************************************************** + * Section containing the API for param (common to all param.h's) * + ******************************************************************/ + +int conParam(Param *); +void desParam(Param *); + +/* + * All functions have a status as return value. If the return value is positive, + * it contains the number of array members returned (1 in case of + * Param_getString and Param_getInt, between 1 and num in case of + * Param_getStringArray and Param_getIntArray). + * + * Memory must be allocated for the result before the function is called. + * For example, calling Param_getInt needs + * + * > int status; + * > unsigned long int value; + * > if(status = Param_getInt(param, name, idx, value) != 1) { + * > printf("No parameter 'value' found. Exiting.\n"); + * > exit(-1); + * > } + * + * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the + * above example expands to + * + * > int status; + * > int num = 32; + * > char value[PARAM_MAX_VALUE_LEN][num]; + * > if(status = Param_getStringArray(param, name, idx, num, value) != num) { + * > printf("Not enough elements of 'value' found. Exiting.\n"); + * > exit(-1); + * > } + * + */ + +#define PARAM_RV_NO_SUCH_PARAMETER 0 +#define PARAM_RV_FAILED -1 + +#define PARAM_MAX_VALUE_LEN 128 + +int Param_getInt(const Param *, const char *, const char *, unsigned long int *); +int Param_getString(const Param *, const char *, const char *, char *); + +int Param_getIntArray(const Param *, const char *, const char *, int, unsigned long int *); +int Param_getStringArray(const Param *, const char *, const char *, int, char **); + +#endif + diff --git a/allParam/ora/oraParam.pc b/allParam/ora/oraParam.pc new file mode 100644 index 0000000..8c1819a --- /dev/null +++ b/allParam/ora/oraParam.pc @@ -0,0 +1,44 @@ +#define _POSIX_C_SOURCE 199509L + +/* Oracle communication area */ +#include +/* SQL communication area */ +#include + +#include "param.h" + +int conParam(Param *my) +{ + return 0; +} + +void desParam(Param *my) +{ +} + +int Param_getInt(const Param *my, const char *n, const char *i, int *v) +{ + return Param_getIntArray(my, n, i, 1, v); +} + +int Param_getString(const Param *my, const char *n, const char *i, char *v) +{ + return Param_getStringArray(my, n, i, 1, &v); +} + +int Param_getIntArray(const Param *my, const char *n, const char *i, int num, int *v) +{ + for (int i = 0 ; i