Cleaned up ANSTO code to merge with sinqdev.sics

This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c
Conflicts:
	.gitignore
	SICSmain.c
	asynnet.c
	confvirtualmot.c
	counter.c
	devexec.c
	drive.c
	event.h
	exebuf.c
	exeman.c
	histmem.c
	interface.h
	motor.c
	motorlist.c
	motorsec.c
	multicounter.c
	napi.c
	napi.h
	napi4.c
	network.c
	nwatch.c
	nxscript.c
	nxxml.c
	nxxml.h
	ofac.c
	reflist.c
	scan.c
	sicshipadaba.c
	sicsobj.c
	site_ansto/docs/Copyright.txt
	site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl
	site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl
	statusfile.c
	tasdrive.c
	tasub.c
	tasub.h
	tasublib.c
	tasublib.h
This commit is contained in:
Ferdi Franceschini
2015-04-23 20:49:26 +10:00
parent c650788a2c
commit 10d29d597c
1336 changed files with 9430 additions and 226646 deletions

206
sicsobj.c
View File

@@ -36,144 +36,79 @@ void DefaultFree(void *data)
free(data);
}
}
/*---------------------------------------------------------------------------*/
static void saveSICSNodeBroken(pHdb node, char *prefix, FILE * fd)
static void saveSICSNode(pHdb node, char *prefix, char separator, FILE * fd)
{
/*
nodes with the property __save are saved
special cases:
special case:
__save=update: a hupdate command is used instead of a set command
__save=kids: save kids, but not the value of this node
*/
char newprefix[1024], val[20];
char path[MAX_HDB_PATH];
char val[20];
char p[MAX_HDB_PATH];
pHdb child;
hdbValue v;
pDynString data = NULL;
char *cmd;
char *str, *value;
char *str = NULL;
char *value;
cmd = GetHdbProp(node, "creationCmd");
if (cmd != NULL) {
GetHdbPath(node, path, sizeof path);
fprintf(fd, cmd, prefix, path);
fprintf(fd, "\n");
fprintf(fd, "%s\n", cmd);
}
if (GetHdbProperty(node, "__save", val, 20) == 1) {
if (strcasecmp(val, "kids") != 0) {
GetHipadabaPar(node, &v, NULL);
GetHipadabaPar(node, &v, NULL);
if (v.dataType == HIPFUNC) {
fprintf(fd, "%s", prefix);
child = node->child;
while (child != NULL) {
GetHipadabaPar(child, &v, NULL);
data = formatValue(v, child);
if (data != NULL) {
value = GetCharArray(data);
str = Arg2Tcl(1, &value, NULL, 0);
fprintf(fd, " %s", str);
}
DeleteDynString(data);
free(str);
child = child->next;
}
fprintf(fd, "\n");
} else {
data = formatValue(v, node);
if (data != NULL) {
value = GetCharArray(data);
str = Arg2Tcl(1, &value, NULL, 0);
if (strcasecmp(val, "update") == 0) {
GetHdbPath(node, path, sizeof path);
fprintf(fd, "hupdate %s %s\n", path, str);
GetHdbPath(node, p, sizeof p);
fprintf(fd, "hupdate %s %s\n", p, str);
} else {
fprintf(fd, "%s %s\n", prefix, str);
}
DeleteDynString(data);
free(str);
}
ReleaseHdbValue(&v);
}
ReleaseHdbValue(&v);
}
child = node->child;
while (child != NULL) {
snprintf(newprefix, 1024, "%s/%s", prefix, child->name);
saveSICSNodeBroken(child, newprefix, fd);
/* the separator is blank for the first subnode and slash further down */
snprintf(p, sizeof p, "%s%c%s", prefix, separator, child->name);
saveSICSNode(child, p, '/', fd);
child = child->next;
}
}
/*---------------------------------------------------------------------------*/
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);
if (data != NULL) {
fprintf(fd, "%s %s\n", prefix, GetCharArray(data));
DeleteDynString(data);
}
ReleaseHdbValue(&v);
child = node->child;
while (child != NULL) {
snprintf(newprefix, 1024, "%s/%s", prefix, child->name);
saveSICSNode(child, newprefix, fd);
child = child->next;
}
}
}
/*---------------------------------------------------------------------------*/
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);
node = node->next;
}
}
return 1;
}
/*---------------------------------------------------------------------------*/
int SaveSICSOBJBroken(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);
node = node->next;
}
*/
node = self->objectNode;
snprintf(prefix, 1024, "%s %s", name, node->name);
saveSICSNode(node, prefix, fd);
fprintf(fd, "\n");
saveSICSNode(self->objectNode, name, ' ', fd);
fprintf(fd, "\n"); /* make a blank line between objects for prettiness */
}
return 1;
}
@@ -524,7 +459,7 @@ static int ListObj(pSICSOBJ self, SConnection * pCon, int argc,
/*---------------------------------------------------------------------------*/
int InvokeSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
int argc, char *argv[])
{
pSICSOBJ self = NULL;
int status;
@@ -539,46 +474,52 @@ int InvokeSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc == 1) {
parNode = self->objectNode;
if (parNode != NULL && isNodePrintable(parNode)) {
status = GetHipadabaPar(parNode, &data, pCon);
if (status != 1) {
return 0;
}
parData = formatValue(data, parNode);
if (parData == NULL) {
SCWrite(pCon, "ERROR: failed to format data", eError);
return 0;
}
SCPrintf(pCon, eValue, "%s = %s", argv[0], GetCharArray(parData));
DeleteDynString(parData);
return 1;
} else {
SCWrite(pCon, "ERROR: nothing to print", eError);
status = GetHdbProperty(parNode,"geterror",buffer,sizeof(buffer));
if (status == 1 && strstr(buffer,"none") == NULL){
SCPrintf(pCon,eValue,"ERROR: %s on last read of %s", buffer, argv[0]);
SCPrintf(pCon,eValue,"%s = -99999", argv[0]);
return 0;
}
status = GetHipadabaPar(parNode, &data, pCon);
if (status != 1) {
return 0;
}
} else {
parNode = GetHipadabaNode(self->objectNode, argv[1]);
if(parNode == NULL){
strtolower(argv[1]);
parNode = GetHipadabaNode(self->objectNode,argv[1]);
parData = formatValue(data, parNode);
if (parData == NULL) {
SCWrite(pCon, "ERROR: failed to format data", eError);
return 0;
}
}
if (parNode != NULL && parNode->value.dataType == HIPFUNC) {
status = invokeOBJFunction(self, parNode, pCon, argc - 2, &argv[2]);
SCPrintf(pCon, eValue, "%s = %s", argv[0], GetCharArray(parData));
DeleteDynString(parData);
return 1;
} else {
snprintf(buffer, sizeof buffer, "%s ", argv[0]);
status = ProcessSICSHdbPar(self->objectNode, pCon, buffer,
argc - 1, &argv[1]);
SCWrite(pCon, "ERROR: nothing to print", eError);
return 0;
}
} else {
parNode = GetHipadabaNode(self->objectNode, argv[1]);
if(parNode == NULL){
strtolower(argv[1]);
parNode = GetHipadabaNode(self->objectNode,argv[1]);
}
}
if (parNode != NULL && parNode->value.dataType == HIPFUNC) {
status = invokeOBJFunction(self, parNode, pCon, argc - 2, &argv[2]);
} else {
snprintf(buffer, sizeof buffer, "%s ", argv[0]);
status = ProcessSICSHdbPar(self->objectNode, pCon, buffer,
argc - 1, &argv[1]);
}
if (status == -1) {
if (strcmp(argv[1], "makescriptfunc") == 0) {
return MakeScriptFunc(self, pCon, argc, argv);
} else if (strcmp(argv[1], "list") == 0) {
return ListObj(self, pCon, argc, argv);
}
if (status == -1) {
if (strcmp(argv[1], "makescriptfunc") == 0) {
return MakeScriptFunc(self, pCon, argc, argv);
} else if (strcmp(argv[1], "list") == 0) {
return ListObj(self, pCon, argc, argv);
}
/* error message written by the caller */
}
}
return status;
return status;
}
/*---------------------------------------------------------------------------*/
@@ -641,6 +582,7 @@ pSICSOBJ SetupSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData,
if (strcasecmp(argv[0], "DynSicsObj") == 0) {
/* make object dynamic by defining a creation command */
SetDescriptorKey(pNew->pDes, "creationCommand", "0");
SCparChange(pCon);
}
SetHdbProperty(pNew->objectNode, "sicsdev", argv[1]);