From: hades Date: Fri, 8 Sep 2000 14:55:07 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=29a9ee5ead57fb7770c5743fd34988e71ca270b2;p=daqdata.git *** empty log message *** --- diff --git a/allParam/ca/caParam.h b/allParam/ca/caParam.h index 4f8b1ff..38eb5ab 100644 --- a/allParam/ca/caParam.h +++ b/allParam/ca/caParam.h @@ -1,6 +1,10 @@ #ifndef PARAM_H #define PARAM_H +#define PARAM_MAX_NVALS 1024 +#define PARAM_MAX_VALUE_LEN 128 +#define PARAM_MAX_NAME_LEN 128 + /************************************************************************** * Section containing struct Param (different in the different param.h's) * **************************************************************************/ @@ -26,48 +30,6 @@ typedef struct ParamResultS { int conParam(Param *); void desParam(Param *); -/* - * All functions have a status as return value. The value i 0 if everything - * worked correctly and -1 if an error occured. In this case, you can get - * the address of an error String via the function Param_getErrStr(). - * - * Memory must be allocated for the result before the function is called. - * In the non-array-functions at &row is filled with 0 or 1 depending on - * whether the Parameter is found or not. - * For example, calling Param_getInt needs - * - * > int row; - * > unsigned long int value; - * > if(Param_getInt(param, name, idx, &row, &value) != 0) { - * > syslog(LOG_ERR, "Error retrieving value of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row == 0) { - * > syslog(LOG_ERR, "Parameter %s(%s) not found. Exiting.\n", name, idx); - * > exit(-1); - * > } - * - * In the array functions maxrows must supply the memory available for the - * result while the actual number of result rows is stored in rows. - * - * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the - * above example expands to - * - * > int rows; - * > int maxrows = 32; - * > char value[PARAM_MAX_VALUE_LEN][maxrows]; - * > if(Param_getStringArray(param, name, idx, maxrows, &rows, value) != 0) { - * > syslog(LOG_ERR, "Error retrieving values of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row != maxrows) { - * > syslog(LOG_WARNING, "%d Parameters %s(%s) found instead of %d.\n", rows, name, idx, maxrows); - * > } - * - */ - -#define PARAM_MAX_NVALS 1024 -#define PARAM_MAX_VALUE_LEN 128 -#define PARAM_MAX_NAME_LEN 128 - int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *); int Param_getString(const Param *, const char *, const char *, int *, char *); int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *); diff --git a/allParam/file/fileParam.c b/allParam/file/fileParam.c index ee68b97..c2bae3f 100644 --- a/allParam/file/fileParam.c +++ b/allParam/file/fileParam.c @@ -61,86 +61,72 @@ void desParam(Param *my) int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val) { - int retVal; - char valstr[PARAM_MAX_VALUE_LEN]; - char *endptr; - - if ((retVal = Param_getString(my, name, idx, row, valstr)) != 0) { - return retVal; - } - *val = strtoul(valstr, &endptr, 0); - if (*endptr != '\0') { - Param_strerror((Param *) my, "Value seems to be no integer.\n"); - *row = 0; - retVal = -1; - } - return retVal; + return Param_getIntArray(my, name, idx, 1, row, val); } int Param_getString(const Param *my, const char *name, const char *idx, int *row, char *val) { - int i; - int n; - char lname[PARAM_MAX_NAME_LEN]; - char lidx[PARAM_MAX_NAME_LEN]; - - for(i = 0 ; i <=strlen(name) ; i++) { - lname[i] = tolower(name[i]); - } - for(i = 0 ; i <=strlen(idx) ; i++) { - lidx[i] = tolower(idx[i]); - } - - - n = Param_getParamNumber(my, lname, lidx); - if (n == -1) { - strcpy(val, ""); - Param_strerror((Param *) my, "Parameter not found.\n"); - *row = 0; - } else { - strcpy(val, my->value[n]); - *row = 1; - } - return 0; + return Param_getStringArray(my, name, idx, 1, row, &val); } int Param_getIntArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, unsigned long int *val) { - int row; int retVal = 0; int i; - char index[PARAM_MAX_NAME_LEN]; + char *endptr; + char *strval[PARAM_MAX_NVALS]; - *rows = 0; for (i = 0 ; i < maxrows ; i++) { - sprintf(index,"%s%d", idx, i); - if(((retVal |= Param_getInt(my, name, index, &row, &val[i])) == 0) && (row == 1)) { - (*rows)++; - } else { - return retVal; + strval[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); + } + *rows = 0; + if((retVal |= Param_getStringArray(my, name, idx, maxrows, rows, strval)) == 0) { + for (i = 0 ; i < *rows ; i++) { + val[i] = strtoul(strval[i], &endptr, 0); + if (*endptr != '\0') { + *rows = 0; + retVal = -1; + Param_strerror((Param *) my, "Value seems to be no integer."); + } } } - + for (i = 0 ; i < maxrows ; i++) { + strval[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); + } return retVal; } int Param_getStringArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val) { - int row; int retVal = 0; int i; - char index[PARAM_MAX_NAME_LEN]; + int n; + char lname[PARAM_MAX_NAME_LEN]; + char lidx[PARAM_MAX_NAME_LEN]; + + for(i = 0 ; i <=strlen(name) ; i++) { + lname[i] = tolower(name[i]); + } + for(i = 0 ; i <=strlen(idx) ; i++) { + lidx[i] = tolower(idx[i]); + } *rows = 0; - for (i = 0 ; i < maxrows ; i++) { - sprintf(index,"%s%d", idx, i); - if(((retVal |= Param_getString(my, name, index, &row, val[i])) == 0) && (row == 1)) { - (*rows)++; - } else { - return retVal; + if((n = Param_getParamNumber(my, lname, lidx)) != -1) { + strcpy(val[0], my->value[n]); + *rows = 1; + } else { + char index[PARAM_MAX_NAME_LEN]; + for (i = 0 ; i < maxrows ; i++) { + sprintf(index,"%s%d", lidx, i); + if((n = Param_getParamNumber(my, lname, index)) != -1) { + strcpy(val[i], my->value[n]); + (*rows)++; + } else { + i = maxrows; + } } } - return retVal; } diff --git a/allParam/file/fileParam.h b/allParam/file/fileParam.h index d503d39..135a1cc 100644 --- a/allParam/file/fileParam.h +++ b/allParam/file/fileParam.h @@ -1,6 +1,10 @@ #ifndef PARAM_H #define PARAM_H +#define PARAM_MAX_NVALS 1024 +#define PARAM_MAX_VALUE_LEN 128 +#define PARAM_MAX_NAME_LEN 128 + /************************************************************************** * Section containing struct Param (different in the different param.h's) * **************************************************************************/ @@ -20,48 +24,6 @@ typedef struct ParamS { int conParam(Param *); void desParam(Param *); -/* - * All functions have a status as return value. The value i 0 if everything - * worked correctly and -1 if an error occured. In this case, you can get - * the address of an error String via the function Param_getErrStr(). - * - * Memory must be allocated for the result before the function is called. - * In the non-array-functions at &row is filled with 0 or 1 depending on - * whether the Parameter is found or not. - * For example, calling Param_getInt needs - * - * > int row; - * > unsigned long int value; - * > if(Param_getInt(param, name, idx, &row, &value) != 0) { - * > syslog(LOG_ERR, "Error retrieving value of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row == 0) { - * > syslog(LOG_ERR, "Parameter %s(%s) not found. Exiting.\n", name, idx); - * > exit(-1); - * > } - * - * In the array functions maxrows must supply the memory available for the - * result while the actual number of result rows is stored in rows. - * - * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the - * above example expands to - * - * > int rows; - * > int maxrows = 32; - * > char value[PARAM_MAX_VALUE_LEN][maxrows]; - * > if(Param_getStringArray(param, name, idx, maxrows, &rows, value) != 0) { - * > syslog(LOG_ERR, "Error retrieving values of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row != maxrows) { - * > syslog(LOG_WARNING, "%d Parameters %s(%s) found instead of %d.\n", rows, name, idx, maxrows); - * > } - * - */ - -#define PARAM_MAX_NVALS 1024 -#define PARAM_MAX_VALUE_LEN 128 -#define PARAM_MAX_NAME_LEN 128 - int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *); int Param_getString(const Param *, const char *, const char *, int *, char *); int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *); diff --git a/allParam/ora/oraParam.h b/allParam/ora/oraParam.h index ef65659..41c000f 100644 --- a/allParam/ora/oraParam.h +++ b/allParam/ora/oraParam.h @@ -1,6 +1,10 @@ #ifndef PARAM_H #define PARAM_H +#define PARAM_MAX_NVALS 1024 +#define PARAM_MAX_VALUE_LEN 128 +#define PARAM_MAX_NAME_LEN 128 + /************************************************************************** * Section containing struct Param (different in the different param.h's) * **************************************************************************/ @@ -18,48 +22,6 @@ typedef struct ParamS { int conParam(Param *); void desParam(Param *); -/* - * All functions have a status as return value. The value i 0 if everything - * worked correctly and -1 if an error occured. In this case, you can get - * the address of an error String via the function Param_getErrStr(). - * - * Memory must be allocated for the result before the function is called. - * In the non-array-functions at &row is filled with 0 or 1 depending on - * whether the Parameter is found or not. - * For example, calling Param_getInt needs - * - * > int row; - * > unsigned long int value; - * > if(Param_getInt(param, name, idx, &row, &value) != 0) { - * > syslog(LOG_ERR, "Error retrieving value of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row == 0) { - * > syslog(LOG_ERR, "Parameter %s(%s) not found. Exiting.\n", name, idx); - * > exit(-1); - * > } - * - * In the array functions maxrows must supply the memory available for the - * result while the actual number of result rows is stored in rows. - * - * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the - * above example expands to - * - * > int rows; - * > int maxrows = 32; - * > char value[PARAM_MAX_VALUE_LEN][maxrows]; - * > if(Param_getStringArray(param, name, idx, maxrows, &rows, value) != 0) { - * > syslog(LOG_ERR, "Error retrieving values of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row != maxrows) { - * > syslog(LOG_WARNING, "%d Parameters %s(%s) found instead of %d.\n", rows, name, idx, maxrows); - * > } - * - */ - -#define PARAM_MAX_NVALS 1024 -#define PARAM_MAX_VALUE_LEN 128 -#define PARAM_MAX_NAME_LEN 128 - int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *); int Param_getString(const Param *, const char *, const char *, int *, char *); int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *); diff --git a/allParam/psql/psqlParam.h b/allParam/psql/psqlParam.h index 060bd9f..d7e9ea6 100644 --- a/allParam/psql/psqlParam.h +++ b/allParam/psql/psqlParam.h @@ -1,6 +1,10 @@ #ifndef PARAM_H #define PARAM_H +#define PARAM_MAX_NVALS 1024 +#define PARAM_MAX_VALUE_LEN 128 +#define PARAM_MAX_NAME_LEN 128 + /************************************************************************** * Section containing struct Param (different in the different param.h's) * **************************************************************************/ @@ -19,48 +23,6 @@ typedef struct ParamS { int conParam(Param *); void desParam(Param *); -/* - * All functions have a status as return value. The value i 0 if everything - * worked correctly and -1 if an error occured. In this case, you can get - * the address of an error String via the function Param_getErrStr(). - * - * Memory must be allocated for the result before the function is called. - * In the non-array-functions at &row is filled with 0 or 1 depending on - * whether the Parameter is found or not. - * For example, calling Param_getInt needs - * - * > int row; - * > unsigned long int value; - * > if(Param_getInt(param, name, idx, &row, &value) != 0) { - * > syslog(LOG_ERR, "Error retrieving value of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row == 0) { - * > syslog(LOG_ERR, "Parameter %s(%s) not found. Exiting.\n", name, idx); - * > exit(-1); - * > } - * - * In the array functions maxrows must supply the memory available for the - * result while the actual number of result rows is stored in rows. - * - * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the - * above example expands to - * - * > int rows; - * > int maxrows = 32; - * > char value[PARAM_MAX_VALUE_LEN][maxrows]; - * > if(Param_getStringArray(param, name, idx, maxrows, &rows, value) != 0) { - * > syslog(LOG_ERR, "Error retrieving values of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row != maxrows) { - * > syslog(LOG_WARNING, "%d Parameters %s(%s) found instead of %d.\n", rows, name, idx, maxrows); - * > } - * - */ - -#define PARAM_MAX_NVALS 1024 -#define PARAM_MAX_VALUE_LEN 128 -#define PARAM_MAX_NAME_LEN 128 - int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *); int Param_getString(const Param *, const char *, const char *, int *, char *); int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *); diff --git a/allParam/tcl/tclParam.c b/allParam/tcl/tclParam.c index 49d18e8..46c3e03 100644 --- a/allParam/tcl/tclParam.c +++ b/allParam/tcl/tclParam.c @@ -28,7 +28,7 @@ int conParam(Param *my) if (*my->interp->result != 0) { Param_strerror(my, my->interp->result); } else { - Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string.\n"); + Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string."); } retVal = -1; } else { @@ -44,69 +44,38 @@ void desParam(Param *my) int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val) { - char valstr[PARAM_MAX_VALUE_LEN]; - char *endptr; - - if (Param_getString(my, name, idx, row, valstr) != 0) { - return -1; - } else if(*row == 0) { - return 0; - } - if(valstr == NULL) { - *row = 0; - } else { - *val = strtoul(valstr, &endptr, 0); - if (*endptr != '\0') { - Param_strerror((Param *) my, "Value seems to be no integer.\n"); - *row = 0; - return -1; - } else { - *row = 1; - } - } - return 0; + return Param_getIntArray(my, name, idx, 1, row, val); } int Param_getString(const Param *my, const char *name, const char *idx, int *row, char *val) { - int retVal; - int i; - char lname[PARAM_MAX_NAME_LEN]; - char lidx[PARAM_MAX_NAME_LEN]; - - for(i = 0 ; i <=strlen(name) ; i++) { - lname[i] = tolower(name[i]); - } - for(i = 0 ; i <=strlen(idx) ; i++) { - lidx[i] = tolower(idx[i]); - } - - if(Tcl_GetVar2(my->interp, lname, lidx, 0) == 0) { - *row = 0; - } else { - strcpy(val, Tcl_GetVar2(my->interp, lname, lidx, 0)); - *row = 1; - } - return 0; + return Param_getStringArray(my, name, idx, 1, row, &val); } int Param_getIntArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, unsigned long int *val) { int retVal = 0; int i; - int row; - char index[PARAM_MAX_NAME_LEN]; + char *endptr; + char *strval[PARAM_MAX_NVALS]; - *rows = 0; for (i = 0 ; i < maxrows ; i++) { - sprintf(index,"%s%d", idx, i); - if(((retVal |= Param_getInt(my, name, index, &row, &val[i])) == 0) && (row == 1)) { - (*rows)++; - } else { - return retVal; + strval[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); + } + *rows = 0; + if((retVal |= Param_getStringArray(my, name, idx, maxrows, rows, strval)) == 0) { + for (i = 0 ; i < *rows ; i++) { + val[i] = strtoul(strval[i], &endptr, 0); + if (*endptr != '\0') { + *rows = 0; + retVal = -1; + Param_strerror((Param *) my, "Value seems to be no integer."); + } } } - + for (i = 0 ; i < maxrows ; i++) { + strval[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); + } return retVal; } @@ -115,18 +84,32 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int int retVal = 0; int i; int row; - char index[PARAM_MAX_NAME_LEN]; + char lname[PARAM_MAX_NAME_LEN]; + char lidx[PARAM_MAX_NAME_LEN]; + + for(i = 0 ; i <=strlen(name) ; i++) { + lname[i] = tolower(name[i]); + } + for(i = 0 ; i <=strlen(idx) ; i++) { + lidx[i] = tolower(idx[i]); + } *rows = 0; - for (i = 0 ; i < maxrows ; i++) { - sprintf(index,"%s%d", idx, i); - if(((retVal |= Param_getString(my, name, index, &row, val[i])) == 0) && (row == 1)) { - (*rows)++; - } else { - return retVal; + if(Tcl_GetVar2(my->interp, lname, lidx, 0) != 0) { + strcpy(val[0], Tcl_GetVar2(my->interp, lname, lidx, 0)); + *rows = 1; + } else { + char index[PARAM_MAX_NAME_LEN]; + for (i = 0 ; i < maxrows ; i++) { + sprintf(index,"%s%d", lidx, i); + if(Tcl_GetVar2(my->interp, lname, index, 0) != 0) { + strcpy(val[i], Tcl_GetVar2(my->interp, lname, index, 0)); + (*rows)++; + } else { + i = maxrows; + } } } - return retVal; } diff --git a/allParam/tcl/tclParam.h b/allParam/tcl/tclParam.h index fbb86d1..003ba05 100644 --- a/allParam/tcl/tclParam.h +++ b/allParam/tcl/tclParam.h @@ -1,6 +1,10 @@ #ifndef PARAM_H #define PARAM_H +#define PARAM_MAX_NVALS 1024 +#define PARAM_MAX_VALUE_LEN 128 +#define PARAM_MAX_NAME_LEN 128 + /************************************************************************** * Section containing struct Param (different in the different param.h's) * **************************************************************************/ @@ -19,48 +23,6 @@ typedef struct ParamS { int conParam(Param *); void desParam(Param *); -/* - * All functions have a status as return value. The value i 0 if everything - * worked correctly and -1 if an error occured. In this case, you can get - * the address of an error String via the function Param_getErrStr(). - * - * Memory must be allocated for the result before the function is called. - * In the non-array-functions at &row is filled with 0 or 1 depending on - * whether the Parameter is found or not. - * For example, calling Param_getInt needs - * - * > int row; - * > unsigned long int value; - * > if(Param_getInt(param, name, idx, &row, &value) != 0) { - * > syslog(LOG_ERR, "Error retrieving value of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row == 0) { - * > syslog(LOG_ERR, "Parameter %s(%s) not found. Exiting.\n", name, idx); - * > exit(-1); - * > } - * - * In the array functions maxrows must supply the memory available for the - * result while the actual number of result rows is stored in rows. - * - * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the - * above example expands to - * - * > int rows; - * > int maxrows = 32; - * > char value[PARAM_MAX_VALUE_LEN][maxrows]; - * > if(Param_getStringArray(param, name, idx, maxrows, &rows, value) != 0) { - * > syslog(LOG_ERR, "Error retrieving values of %s(%s). Exiting.\n", name, idx); - * > exit(-1); - * > } else if(row != maxrows) { - * > syslog(LOG_WARNING, "%d Parameters %s(%s) found instead of %d.\n", rows, name, idx, maxrows); - * > } - * - */ - -#define PARAM_MAX_NVALS 1024 -#define PARAM_MAX_VALUE_LEN 128 -#define PARAM_MAX_NAME_LEN 128 - int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *); int Param_getString(const Param *, const char *, const char *, int *, char *); int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *); diff --git a/allParam/test/Makefile b/allParam/test/Makefile index 61028e1..52a0444 100644 --- a/allParam/test/Makefile +++ b/allParam/test/Makefile @@ -24,10 +24,10 @@ LOADPSQLLIBES = -L$(HOME)/lib/$(SYSTYPE) -lpsqlParam -lpq -lcrypt # Tcl test TCLCFLAGS = -I$(HOME)/include/tcl -LOADTCLLIBES = -L$(HOME)/lib/$(SYSTYPE) -ltclParam -ltcl -lm -ldl +LOADTCLLIBES = -L$(HOME)/lib/$(SYSTYPE) -ltclParam -ltcl8.0 -lm -ldl TESTS = test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 \ - test12 test13 test14 test15 test16 test17 test18 test19 test20 + test12 test13 test14 test15 test16 test17 test18 test19 test20 test21 test22 OBJS = suite.o $(addsuffix .o,$(TESTS)) diff --git a/allParam/test/suite.c b/allParam/test/suite.c index 39e498e..7a4974a 100644 --- a/allParam/test/suite.c +++ b/allParam/test/suite.c @@ -23,6 +23,8 @@ #include "test18.h" #include "test19.h" #include "test20.h" +#include "test21.h" +#include "test22.h" int main(int argc, char *argv[]) { Param *param; @@ -54,6 +56,8 @@ int main(int argc, char *argv[]) { errors -= test18("Test 18", param); errors -= test19("Test 19", param); errors -= test20("Test 20", param); + errors -= test21("Test 21", param); + errors -= test22("Test 22", param); desParam(param); free(param);