- minor improvements

This commit is contained in:
zolliker
2009-11-10 10:38:48 +00:00
parent 7e10c5e296
commit 1c6c3c603e
4 changed files with 38 additions and 9 deletions

View File

@ -10,7 +10,6 @@
#include <sicshipadaba.h>
#include "statusfile.h"
#define MAX_HDB_PATH 1024
/*-------------------------------------------------------------------------*/
static pDynString ComposeSicsCommand(pHdb node)
{

View File

@ -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]);
}

View File

@ -13,6 +13,7 @@
#include <sics.h>
#include <dynstring.h>
#include <sicsobj.h>
#define MAX_HDB_PATH 1024
/*======================== callback error codes ===============================*/
#define SICSCBRO -607
#define SICSCBPERM -608

View File

@ -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");
}