]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhadaq <hadaq>
Fri, 17 May 2002 20:04:58 +0000 (20:04 +0000)
committerhadaq <hadaq>
Fri, 17 May 2002 20:04:58 +0000 (20:04 +0000)
allParam/examples/Makefile [new file with mode: 0644]
allParam/examples/paget.c [new file with mode: 0644]
allParam/examples/pastore.c [new file with mode: 0644]

diff --git a/allParam/examples/Makefile b/allParam/examples/Makefile
new file mode 100644 (file)
index 0000000..67bf8d1
--- /dev/null
@@ -0,0 +1,13 @@
+CFLAGS = -I$(HOME)/include
+LOADLIBES = -L$(HOME)/lib/$(SYSTYPE) -ltclParam -ltcl -lm -ldl
+
+all : paget pastore
+
+install : all
+       cp paget $(HOME)/bin/$(SYSTYPE)
+
+clean :
+       rm -f *.o
+
+paget : paget.o
+pastore : pastore.o
diff --git a/allParam/examples/paget.c b/allParam/examples/paget.c
new file mode 100644 (file)
index 0000000..ca2568d
--- /dev/null
@@ -0,0 +1,137 @@
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/examples/paget.c,v 1.1 2002-05-17 20:04:58 hadaq Exp $";
+#define _POSIX_C_SOURCE 199506L
+
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <allParam.h>
+
+static void usage(const char *name) {
+       fprintf(stderr, "%s [-s setup]\n", name);
+}
+
+static void cleanup(Param *param) {
+       desParam(param);
+       free(param);
+}
+
+int main(int argc, char * const argv[]) {
+       Param *param;
+       char mode[4];
+       char *setup = NULL;
+       char *endptr;
+       int c;
+       int i;
+       char name[PARAM_MAX_NAME_LEN];
+       char idx[PARAM_MAX_NAME_LEN];
+       char scount[PARAM_MAX_NAME_LEN];
+       int count;
+       int rows;
+       char svalue[PARAM_MAX_VALUE_LEN];
+       unsigned long int ivalue;
+       char *savalue[PARAM_MAX_ARRAY_LEN];
+       unsigned long int iavalue[PARAM_MAX_ARRAY_LEN];
+
+       while((c = getopt(argc, argv, "s:")) != -1) {
+               switch(c) {
+                       case('s'):
+                               setup = optarg;
+                               break;
+                       default:
+                               usage(argv[0]);
+                               exit(EXIT_FAILURE);
+                               break;
+               }
+       }
+
+       param = malloc(sizeof(Param));
+       if(conSetupParam(param, setup)) {
+               fprintf(stderr, "%s: Cannot create parameter source with setup %s\n", argv[0], setup);
+               exit(EXIT_FAILURE);
+       }
+
+       fputs("Mode: ", stdout);
+       while (NULL != fgets(mode, 4, stdin)) {
+               mode[strlen(mode) - 1] = '\0';
+               fputs("Name: ", stdout);
+               if(NULL == fgets(name, PARAM_MAX_NAME_LEN, stdin)) {
+                       cleanup(param);
+                       exit(EXIT_SUCCESS);
+               }
+               name[strlen(name) - 1] = '\0';
+               fputs("Idx: ", stdout);
+               if(NULL == fgets(idx, PARAM_MAX_NAME_LEN, stdin)) {
+                       cleanup(param);
+                       exit(EXIT_SUCCESS);
+               }
+               idx[strlen(idx) - 1] = '\0';
+               if (strcmp(mode, "s") == 0) {
+                       if (Param_getString(param, name, idx, &rows, svalue) || (rows != 1)) {
+                               fprintf(stderr, "%s: Parameter name=%s, idx=%s not found\n", argv[0], name, idx);
+                       } else {
+                               fprintf(stdout, "%s\n", svalue);
+                       }
+               } else if (strcmp(mode, "i") == 0) {
+                       if (Param_getInt(param, name, idx, &rows, &ivalue) || (rows != 1)) {
+                               fprintf(stderr, "%s: Parameter name=%s, idx=%s not found\n", argv[0], name, idx);
+                       } else {
+                               fprintf(stdout, "%u\n", ivalue);
+                       }
+               } else if (strcmp(mode, "sa") == 0) {
+                       fputs("Count: ", stdout);
+                       if(NULL == fgets(scount, PARAM_MAX_NAME_LEN, stdin)) {
+                               cleanup(param);
+                               exit(EXIT_SUCCESS);
+                       }
+                       count = strtoul(scount, &endptr, 0);
+                       if(*endptr != '\n') {
+                               fprintf(stderr, "%s: %s is not a valid number\n", argv[0], scount);
+                       } else {
+                               for (i = 0 ; i < count ; i++) {
+                                       savalue[i] = malloc(PARAM_MAX_VALUE_LEN);
+                               }
+                               if (Param_getStringArray(param, name, idx, count, &rows, savalue)) {
+                                       fprintf(stderr, "%s: Parameter name=%s, idx=%s not found\n", argv[0], name, idx);
+                               } else {
+                                       if (rows != count) {
+                                               fprintf(stderr, "%s: %d, not %d items found\n", argv[0], rows, count);
+                                       }
+                                       for (i = 0 ; i < rows ; i++) {
+                                               fprintf(stdout, "%d: %s\n", i, savalue[i]);
+                                       }
+                               }
+                               for (i = 0 ; i < count ; i++) {
+                                       free(savalue[i]);
+                               }
+                       }
+               } else if (strcmp(mode, "ia") == 0) {
+                       fputs("Count: ", stdout);
+                       if(NULL == fgets(scount, PARAM_MAX_NAME_LEN, stdin)) {
+                               cleanup(param);
+                               exit(EXIT_SUCCESS);
+                       }
+                       count = strtoul(scount, &endptr, 0);
+                       if(*endptr != '\n') {
+                               fprintf(stderr, "%s: %s is not a valid number\n", argv[0], scount);
+                       } else {
+                               if (Param_getIntArray(param, name, idx, count, &rows, iavalue)) {
+                                       fprintf(stderr, "%s: Parameter name=%s, idx=%s not found\n", argv[0], name, idx);
+                               } else {
+                                       if (rows != count) {
+                                               fprintf(stderr, "%s: %d, not %d items found\n", argv[0], rows, count);
+                                       }
+                                       for (i = 0 ; i < rows ; i++) {
+                                               fprintf(stdout, "%d: %u\n", i, iavalue[i]);
+                                       }
+                               }
+                       }
+               } else {
+                       fprintf(stderr, "%s: Mode must be one of 's', 'i', 'sa', 'ia', not %s\n", mode);
+               }
+               fputs("Mode: ", stdout);
+       }
+       cleanup(param);
+       return 0;
+}
diff --git a/allParam/examples/pastore.c b/allParam/examples/pastore.c
new file mode 100644 (file)
index 0000000..f03d7b5
--- /dev/null
@@ -0,0 +1,90 @@
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/examples/pastore.c,v 1.1 2002-05-17 20:04:58 hadaq Exp $";
+#define _POSIX_C_SOURCE 199506L
+
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <allParam.h>
+
+static void usage(const char *name) {
+       fprintf(stderr, "%s [-s setup]\n", name);
+}
+
+static void cleanup(Param *param) {
+       desParam(param);
+       free(param);
+}
+
+int main(int argc, char * const argv[]) {
+       Param *param;
+       char mode[4];
+       char *setup = NULL;
+       char *endptr;
+       int c;
+       char name[PARAM_MAX_NAME_LEN];
+       char idx[PARAM_MAX_NAME_LEN];
+       char svalue[PARAM_MAX_VALUE_LEN];
+       unsigned long int ivalue;
+
+       while((c = getopt(argc, argv, "s:")) != -1) {
+               switch(c) {
+                       case('s'):
+                               setup = optarg;
+                               break;
+                       default:
+                               usage(argv[0]);
+                               exit(EXIT_FAILURE);
+                               break;
+               }
+       }
+
+       param = malloc(sizeof(Param));
+       if(conSetupParam(param, setup)) {
+               fprintf(stderr, "%s: Cannot create parameter source with setup %s\n", argv[0], setup);
+               exit(EXIT_FAILURE);
+       }
+
+       fputs("Mode: ", stdout);
+       while (NULL != fgets(mode, 4, stdin)) {
+               mode[strlen(mode) - 1] = '\0';
+               fputs("Name: ", stdout);
+               if(NULL == fgets(name, PARAM_MAX_NAME_LEN, stdin)) {
+                       cleanup(param);
+                       exit(EXIT_SUCCESS);
+               }
+               name[strlen(name) - 1] = '\0';
+               fputs("Idx: ", stdout);
+               if(NULL == fgets(idx, PARAM_MAX_NAME_LEN, stdin)) {
+                       cleanup(param);
+                       exit(EXIT_SUCCESS);
+               }
+               idx[strlen(idx) - 1] = '\0';
+               fputs("Value: ", stdout);
+               if(NULL == fgets(svalue, PARAM_MAX_VALUE_LEN, stdin)) {
+                       cleanup(param);
+                       exit(EXIT_SUCCESS);
+               }
+               svalue[strlen(svalue) - 1] = '\0';
+               if (strcmp(mode, "s") == 0) {
+                       if (Param_storeString(param, name, idx, svalue)) {
+                               fprintf(stderr, "%s: Failed\n", argv[0]);
+                       }
+               } else if (strcmp(mode, "i") == 0) {
+                       ivalue = strtoul(svalue, &endptr, 0);
+                       if(*endptr != '\0') {
+                               fprintf(stderr, "%s: %s is not a valid number\n", argv[0], svalue);
+                       } else {
+                               if (Param_storeInt(param, name, idx, ivalue)) {
+                                       fprintf(stderr, "%s: Failed\n", argv[0]);
+                               }
+                       }
+               } else {
+                       fprintf(stderr, "%s: Mode must be either 's' or 'i', not %s\n", mode);
+               }
+               fputs("Mode: ", stdout);
+       }
+       cleanup(param);
+       return 0;
+}