#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) *
**************************************************************************/
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 *);
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;
}
#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) *
**************************************************************************/
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 *);
#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) *
**************************************************************************/
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 *);
#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) *
**************************************************************************/
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 *);
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 {
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;
}
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;
}
#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) *
**************************************************************************/
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 *);
# 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))
#include "test18.h"
#include "test19.h"
#include "test20.h"
+#include "test21.h"
+#include "test22.h"
int main(int argc, char *argv[]) {
Param *param;
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);