From 1c6c3c603e95842b892b2289330762d16b619399 Mon Sep 17 00:00:00 2001 From: zolliker Date: Tue, 10 Nov 2009 10:38:48 +0000 Subject: [PATCH] - minor improvements --- sicshdbfactory.c | 1 - sicshipadaba.c | 22 +++++++++++++++++----- sicshipadaba.h | 1 + sicsobj.c | 23 ++++++++++++++++++++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/sicshdbfactory.c b/sicshdbfactory.c index c2f8d411..4cdf4e97 100644 --- a/sicshdbfactory.c +++ b/sicshdbfactory.c @@ -10,7 +10,6 @@ #include #include "statusfile.h" -#define MAX_HDB_PATH 1024 /*-------------------------------------------------------------------------*/ static pDynString ComposeSicsCommand(pHdb node) { diff --git a/sicshipadaba.c b/sicshipadaba.c index efa3eec0..689995d0 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -1776,7 +1776,8 @@ int ProcessSICSHdbPar(pHdb root, SConnection * pCon, pHdb parNode = NULL; pDynString parData = NULL; char error[512]; - int i, status; + int i, status, firstValueArg; + float value; assert(root != NULL && pCon != NULL); @@ -1785,7 +1786,18 @@ int ProcessSICSHdbPar(pHdb root, SConnection * pCon, return -1; } - parNode = GetHipadabaNode(root, argv[0]); + /* if the single argument is a number and the type of the root is a number + then we want to set the root itself to this number */ + if (argc == 1 + && (root->value.dataType == HIPINT || root->value.dataType == HIPFLOAT) + && sscanf(argv[0], "%f", &value) == 1) { + parNode = root; + firstValueArg = 0; + } else { + parNode = GetHipadabaNode(root, argv[0]); + firstValueArg = 1; + } + if (parNode == NULL) { /* no error reporting here, upper level code might wish to continue * processing commands after having tested for parameters. @@ -1793,7 +1805,7 @@ int ProcessSICSHdbPar(pHdb root, SConnection * pCon, return -1; } - if (argc > 1) { + if (argc > firstValueArg) { /* * setting the value is attempted. */ @@ -1805,8 +1817,8 @@ int ProcessSICSHdbPar(pHdb root, SConnection * pCon, SCWrite(pCon, "ERROR: out of memory processing parameter", eError); return 0; } - DynStringConcat(parData, argv[1]); - for (i = 2; i < argc; i++) { + DynStringConcat(parData, argv[firstValueArg]); + for (i = firstValueArg + 1; i < argc; i++) { DynStringConcat(parData, " "); DynStringConcat(parData, argv[i]); } diff --git a/sicshipadaba.h b/sicshipadaba.h index 26cb089f..ad8efee0 100644 --- a/sicshipadaba.h +++ b/sicshipadaba.h @@ -13,6 +13,7 @@ #include #include #include +#define MAX_HDB_PATH 1024 /*======================== callback error codes ===============================*/ #define SICSCBRO -607 #define SICSCBPERM -608 diff --git a/sicsobj.c b/sicsobj.c index ac560375..4c030b9b 100644 --- a/sicsobj.c +++ b/sicsobj.c @@ -41,10 +41,18 @@ void DefaultFree(void *data) static void saveSICSNode(pHdb node, char *prefix, FILE * fd) { char newprefix[1024], val[20]; + char path[MAX_HDB_PATH]; pHdb child; hdbValue v; pDynString data = NULL; - + char *cmd; + + cmd = GetHdbProp(node, "creationCmd"); + if (cmd != NULL) { + GetHdbPath(node, path, sizeof path); + fprintf(fd, cmd, prefix, path); + fprintf(fd, "\n"); + } if (GetHdbProperty(node, "__save", val, 20) == 1) { GetHipadabaPar(node, &v, NULL); data = formatValue(v, node); @@ -67,10 +75,18 @@ int SaveSICSOBJ(void *data, char *name, FILE * fd) { pSICSOBJ self = (pSICSOBJ) data; char prefix[1024]; + char path[MAX_HDB_PATH]; pHdb node; - + char *cmd; + if (self != NULL && self->objectNode != NULL) { node = self->objectNode->child; + cmd = GetHdbProp(self->objectNode, "creationCmd"); + if (cmd != NULL) { + GetHdbPath(self->objectNode, path, sizeof path); + fprintf(fd, cmd, name, path); + fprintf(fd, "\n"); + } while (node != NULL) { snprintf(prefix, 1024, "%s %s", name, node->name); saveSICSNode(node, prefix, fd); @@ -138,6 +154,7 @@ pSICSOBJ MakeSICSOBJv(char *name, char *class, int type, int priv) pNew->objectNode = MakeSICSHdbPar(name, priv, val); ReleaseHdbValue(&val); } + SetHdbProperty(pNew->objectNode, "sicscommand", name); if (pNew->pDes == NULL || pNew->objectNode == NULL) { free(pNew); return (NULL); @@ -536,7 +553,7 @@ pSICSOBJ SetupSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData, return NULL; } if (strcasecmp(argv[0], "DynSicsObj") == 0) { - /* make object dynamic by defining a descriptor command */ + /* make object dynamic by defining a creation command */ SetDescriptorKey(pNew->pDes, "creationCommand", "0"); }