-static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/tcl/tclParam.c,v 1.28 2003-02-10 13:43:52 hadaq Exp $";
+static const char rcsId[] =
+ "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/tcl/tclParam.c,v 1.29 2003-02-12 17:05:06 sailer Exp $";
#define _POSIX_C_SOURCE 199509L
#if HAVE_CONFIG_H
#include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <unistd.h>
#include <errno.h>
#ifdef PTHREADS
#include <pthread.h>
-#endif /* PTHREADS */
+#endif /* PTHREADS */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Tcl_Interp *interp;
#ifdef PTHREADS
pthread_mutex_t *interpLock;
-#endif /* PTHREADS */
+#endif /* PTHREADS */
FILE *store;
} TclParam;
my->specParam = malloc(sizeof(TclParam));
#ifdef PTHREADS
- ((TclParam *) (my->specParam))->interpLock = malloc(sizeof(pthread_mutex_t));
+ ((TclParam *) (my->specParam))->interpLock =
+ malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(((TclParam *) (my->specParam))->interpLock, NULL);
-#endif /* PTHREADS */
+#endif /* PTHREADS */
if (setup != NULL) {
my->setup = malloc(strlen(setup) + 1);
} else {
my->setup = NULL;
}
- paramFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_p.tcl") + 1);
- storageFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_s.tcl") + 1);
+ paramFile =
+ malloc(((my->setup ==
+ NULL) ? strlen("default") : strlen(setup)) +
+ strlen("_p.tcl") + 1);
+ storageFile =
+ malloc(((my->setup ==
+ NULL) ? strlen("default") : strlen(setup)) +
+ strlen("_s.tcl") + 1);
sprintf(paramFile, "%s_p.tcl", (my->setup == NULL) ? "default" : setup);
- sprintf(storageFile, "%s_s.tcl", (my->setup == NULL) ? "default" : setup);
+ sprintf(storageFile, "%s_s.tcl",
+ (my->setup == NULL) ? "default" : setup);
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
+#endif /* PTHREADS */
((TclParam *) (my->specParam))->interp = Tcl_CreateInterp();
- code = Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
+ code =
+ Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
if (code != TCL_OK) {
- if (* ((TclParam *) (my->specParam))->interp->result != 0) {
- Param_strerror(my, ((TclParam *) (my->specParam))->interp->result);
+ if (*((TclParam *) (my->specParam))->interp->result != 0) {
+ Param_strerror(my,
+ ((TclParam *) (my->specParam))->interp->
+ result);
} else {
- Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string.");
+ Param_strerror((Param *) my,
+ "Tcl interpreter cannot read file correctly and does not deliver an error string.");
}
retVal = -1;
}
#ifdef PTHREADS
pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
- if (NULL == (((TclParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+ if (NULL ==
+ (((TclParam *) (my->specParam))->store =
+ fopen(storageFile, "a+"))) {
retVal = -1;
}
- if(retVal == 0) {
+ if (retVal == 0) {
my->basedir = malloc(PARAM_MAX_VALUE_LEN);
uname(buffer);
- if(Param_getString(my, buffer->nodename, "basedir", &row, my->basedir) || (row != 1)) {
- if(Param_getString(my, "glob", "basedir", &row, my->basedir) || (row != 1)) {
+ if (Param_getString
+ (my, buffer->nodename, "basedir", &row, my->basedir)
+ || (row != 1)) {
+ if (Param_getString(my, "glob", "basedir", &row, my->basedir)
+ || (row != 1)) {
strcpy(my->basedir, "");
}
}
my->specParam = malloc(sizeof(TclParam));
#ifdef PTHREADS
- ((TclParam *) (my->specParam))->interpLock = malloc(sizeof(pthread_mutex_t));
+ ((TclParam *) (my->specParam))->interpLock =
+ malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(((TclParam *) (my->specParam))->interpLock, NULL);
-#endif /* PTHREADS */
+#endif /* PTHREADS */
p = getenv("DAQSLOW_PARAM_FILE");
if (p == NULL) {
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
+#endif /* PTHREADS */
((TclParam *) (my->specParam))->interp = Tcl_CreateInterp();
- code = Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
+ code =
+ Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
if (code != TCL_OK) {
- if (* ((TclParam *) (my->specParam))->interp->result != 0) {
- Param_strerror(my, ((TclParam *) (my->specParam))->interp->result);
+ if (*((TclParam *) (my->specParam))->interp->result != 0) {
+ Param_strerror(my,
+ ((TclParam *) (my->specParam))->interp->
+ result);
} else {
- Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string.");
+ Param_strerror((Param *) my,
+ "Tcl interpreter cannot read file correctly and does not deliver an error string.");
}
retVal = -1;
}
#ifdef PTHREADS
- pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
+ pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
- if (NULL == (((TclParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+ if (NULL ==
+ (((TclParam *) (my->specParam))->store =
+ fopen(storageFile, "a+"))) {
return -1;
}
- if(retVal == 0) {
+ if (retVal == 0) {
my->basedir = malloc(PARAM_MAX_VALUE_LEN);
uname(buffer);
- if(Param_getString(my, buffer->nodename, "basedir", &row, my->basedir) || (row != 1)) {
- if(Param_getString(my, "glob", "basedir", &row, my->basedir) || (row != 1)) {
+ if (Param_getString
+ (my, buffer->nodename, "basedir", &row, my->basedir)
+ || (row != 1)) {
+ if (Param_getString(my, "glob", "basedir", &row, my->basedir)
+ || (row != 1)) {
strcpy(my->basedir, "");
}
}
{
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
+#endif /* PTHREADS */
Tcl_DeleteInterp(((TclParam *) (my->specParam))->interp);
#ifdef PTHREADS
pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
fclose(((TclParam *) (my->specParam))->store);
#ifdef PTHREADS
pthread_mutex_destroy(((TclParam *) (my->specParam))->interpLock);
free(((TclParam *) (my->specParam))->interpLock);
-#endif /* PTHREADS */
+#endif /* PTHREADS */
free((TclParam *) (my->specParam));
free(my->basedir);
free(my->setup);
}
-int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
+int Param_getInt(const Param *my, const char *name, const char *idx,
+ int *row, unsigned long int *val)
{
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 Param_getString(const Param *my, const char *name, const char *idx,
+ int *row, char *val)
{
return Param_getStringArray(my, name, idx, 1, row, &val);
}
-int Param_getFilename(const Param *my, const char *name, const char *idx, int *row, char *val)
+int Param_getFilename(const Param *my, const char *name, const char *idx,
+ int *row, char *val)
{
int retVal = 0;
int rows = 0;
char value[PARAM_MAX_VALUE_LEN];
- if (((retVal = Param_getString(my, name, idx, &rows, value)) == 0) && (rows == 1)) {
+ if (((retVal = Param_getString(my, name, idx, &rows, value)) == 0)
+ && (rows == 1)) {
if (value[0] == '/') {
strcpy(val, value);
} else {
return retVal;
}
-int Param_getIntArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, unsigned long int *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;
char *endptr;
char *strval[PARAM_MAX_ARRAY_LEN];
- for (i = 0 ; i < maxrows ; i++) {
+ for (i = 0; i < maxrows; i++) {
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++) {
+ 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.");
+ Param_strerror((Param *) my,
+ "Value seems to be no integer.");
}
}
}
- for (i = 0 ; i < maxrows ; i++) {
+ for (i = 0; i < maxrows; i++) {
free(strval[i]);
}
return retVal;
}
-int Param_getStringArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val)
+int Param_getStringArray(const Param *my, const char *name, const char *idx,
+ int maxrows, int *rows, char **val)
{
int retVal = 0;
int i;
char lname[PARAM_MAX_NAME_LEN];
char lidx[PARAM_MAX_NAME_LEN];
- for(i = 0 ; i <=strlen(name) ; i++) {
+ for (i = 0; i <= strlen(name); i++) {
lname[i] = tolower(name[i]);
}
- for(i = 0 ; i <=strlen(idx) ; i++) {
+ for (i = 0; i <= strlen(idx); i++) {
lidx[i] = tolower(idx[i]);
}
*rows = 0;
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
- if(Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, lidx, 0) != 0) {
- strcpy(val[0], Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, lidx, 0));
+#endif /* PTHREADS */
+ if (Tcl_GetVar2
+ (((TclParam *) (my->specParam))->interp, lname, lidx, 0) != 0) {
+ strcpy(val[0],
+ Tcl_GetVar2(((TclParam *) (my->specParam))->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(((TclParam *) (my->specParam))->interp, lname, index, 0) != 0) {
- strcpy(val[i], Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, index, 0));
+ for (i = 0; i < maxrows; i++) {
+ sprintf(index, "%s%d", lidx, i);
+ if (Tcl_GetVar2
+ (((TclParam *) (my->specParam))->interp, lname, index,
+ 0) != 0) {
+ strcpy(val[i],
+ Tcl_GetVar2(((TclParam *) (my->specParam))->
+ interp, lname, index, 0));
(*rows)++;
} else {
i = maxrows;
#ifdef PTHREADS
pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
return retVal;
}
-int Param_getFilenameArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val)
+int Param_getFilenameArray(const Param *my, const char *name,
+ const char *idx, int maxrows, int *rows,
+ char **val)
{
int retVal = 0;
int i;
char *value[PARAM_MAX_ARRAY_LEN];
- for (i = 0 ; i < maxrows ; i++) {
+ for (i = 0; i < maxrows; i++) {
value[i] = malloc(PARAM_MAX_VALUE_LEN);
}
- if (((retVal = Param_getStringArray(my, name, idx, maxrows, rows, value)) == 0) && (*rows > 0)) {
- for (i = 0 ; i < *rows ; i++) {
+ if (((retVal =
+ Param_getStringArray(my, name, idx, maxrows, rows, value)) == 0)
+ && (*rows > 0)) {
+ for (i = 0; i < *rows; i++) {
if (value[i][0] != '/') {
strcpy(val[i], my->basedir);
strcat(val[i], value[i]);
*rows = 0;
}
- for (i = 0 ; i < maxrows ; i++) {
+ for (i = 0; i < maxrows; i++) {
free(value[i]);
}
return retVal;
}
-int Param_getBlob(const Param *my, const char *name, const char *idx, size_t *size, FILE **val)
+int Param_getBlob(const Param *my, const char *name, const char *idx,
+ size_t * size, FILE ** val)
{
int retVal = 0;
char filename[PARAM_MAX_VALUE_LEN];
return retVal;
}
-int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int value)
+int Param_storeInt(const Param *my, const char *name, const char *idx,
+ unsigned long int value)
{
char buf[7 + 2 * PARAM_MAX_NAME_LEN + PARAM_MAX_VALUE_LEN];
sprintf(buf, "set %s(%s)\t%lu\n", name, idx, value);
fflush(((TclParam *) (my->specParam))->store);
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
+#endif /* PTHREADS */
Tcl_Eval(((TclParam *) (my->specParam))->interp, buf);
#ifdef PTHREADS
pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
return 0;
}
-int Param_storeString(const Param *my, const char *name, const char *idx, const char *value)
+int Param_storeString(const Param *my, const char *name, const char *idx,
+ const char *value)
{
char buf[7 + 2 * PARAM_MAX_NAME_LEN + PARAM_MAX_VALUE_LEN];
sprintf(buf, "set %s(%s)\t\"%s\"\n", name, idx, value);
fflush(((TclParam *) (my->specParam))->store);
#ifdef PTHREADS
if (0 == pthread_mutex_lock(((TclParam *) (my->specParam))->interpLock)) {
-#endif /* PTHREADS */
+#endif /* PTHREADS */
Tcl_Eval(((TclParam *) (my->specParam))->interp, buf);
#ifdef PTHREADS
pthread_mutex_unlock(((TclParam *) (my->specParam))->interpLock);
}
-#endif /* PTHREADS */
+#endif /* PTHREADS */
return 0;
}
static void Param_strerror(Param *my, const char *strerror)
{
my->strerror = realloc(my->strerror, strlen(strerror) + 1);
- if(my->strerror != NULL) {
+ if (my->strerror != NULL) {
strcpy(my->strerror, strerror);
}
}
-