Merged 2.4 branch
r2828 | ffr | 2009-11-25 09:56:49 +1100 (Wed, 25 Nov 2009) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
c58ee9fbcb
commit
2ec6505ef8
164
sicshipadaba.c
164
sicshipadaba.c
@@ -2379,7 +2379,8 @@ static int GetHdbVal(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
memset(&newValue,0,sizeof(hdbValue));
|
||||
GetHipadabaPar(targetNode, &newValue, pCon);
|
||||
if (0 == GetHipadabaPar(targetNode, &newValue, pCon))
|
||||
return 0;
|
||||
parData = formatValue(newValue, targetNode);
|
||||
if(parData == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory formatting data",eError);
|
||||
@@ -3056,6 +3057,27 @@ static int DelSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int HasSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
|
||||
if(argc < 3) {
|
||||
SCWrite(pCon,"ERROR: need path key as parameters",eError);
|
||||
return 0;
|
||||
}
|
||||
targetNode = FindHdbNode(NULL,argv[1],pCon);
|
||||
if(targetNode == NULL){
|
||||
SCWrite(pCon,"ERROR: node not found",eError);
|
||||
return 0;
|
||||
}
|
||||
if (HasHdbProperty(targetNode,argv[2])) {
|
||||
SCPrintf(pCon,eValue,"%s", "true");
|
||||
return 1;
|
||||
} else {
|
||||
SCPrintf(pCon,eValue,"%s", "false");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int GetSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
@@ -3110,10 +3132,13 @@ static int ListSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData
|
||||
char buffer[512];
|
||||
const char *pKey = NULL;
|
||||
pDynString data = NULL;
|
||||
int genTclList = 0;
|
||||
|
||||
if(argc < 2) {
|
||||
SCWrite(pCon,"ERROR: need path as parameter",eError);
|
||||
return 0;
|
||||
} else if (argc == 3) {
|
||||
genTclList = 1;
|
||||
}
|
||||
targetNode = FindHdbNode(NULL,argv[1],pCon);
|
||||
if(targetNode == NULL){
|
||||
@@ -3128,33 +3153,105 @@ static int ListSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData
|
||||
InitHdbPropertySearch(targetNode);
|
||||
while((pKey = GetNextHdbProperty(targetNode, buffer, 511)) != NULL){
|
||||
DynStringConcat(data,(char *)pKey);
|
||||
DynStringConcat(data,"=");
|
||||
DynStringConcat(data,buffer);
|
||||
DynStringConcat(data,"\n");
|
||||
if (genTclList) {
|
||||
DynStringConcat(data," ");
|
||||
DynStringConcat(data,"{");
|
||||
DynStringConcat(data,buffer);
|
||||
DynStringConcat(data,"}");
|
||||
DynStringConcat(data," ");
|
||||
} else {
|
||||
DynStringConcat(data,"=");
|
||||
DynStringConcat(data,buffer);
|
||||
DynStringConcat(data,"\n");
|
||||
}
|
||||
}
|
||||
SCWrite(pCon,GetCharArray(data), eValue);
|
||||
DeleteDynString(data);
|
||||
return 1;
|
||||
}
|
||||
static int ANSTO_ListSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
char buffer[512], *globPtr=NULL;
|
||||
int cmpSize = 0;
|
||||
const char *pKey = NULL;
|
||||
pDynString data = NULL;
|
||||
|
||||
if(argc < 3) {
|
||||
SCWrite(pCon,"ERROR: need path and search string as parameters",eError);
|
||||
return 0;
|
||||
}
|
||||
targetNode = FindHdbNode(NULL,argv[1],pCon);
|
||||
if(targetNode == NULL){
|
||||
SCWrite(pCon,"ERROR: node not found",eError);
|
||||
return 0;
|
||||
}
|
||||
data = CreateDynString(64,64);
|
||||
if(data == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory in ListSICSHdbProperty",eError);
|
||||
return 0;
|
||||
}
|
||||
InitHdbPropertySearch(targetNode);
|
||||
|
||||
/* Allow simple glob matches with '*' as a suffix
|
||||
Eg hfindprop /hpath @*
|
||||
*/
|
||||
if ((globPtr = index(argv[2], '*')) != NULL ) {
|
||||
*globPtr = '\0';
|
||||
}
|
||||
cmpSize = strlen(argv[2]);
|
||||
while((pKey = GetNextHdbProperty(targetNode, buffer, 511)) != NULL) {
|
||||
if (strncasecmp(argv[2], pKey, cmpSize) == 0) {
|
||||
DynStringConcat(data,(char *)pKey);
|
||||
DynStringConcat(data," ");
|
||||
DynStringConcat(data,buffer);
|
||||
DynStringConcat(data,"\n");
|
||||
}
|
||||
}
|
||||
SCWrite(pCon,GetCharArray(data), eValue);
|
||||
DeleteDynString(data);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static pHdb matchHdbProp(pHdb root, char *propname, char *buffer){
|
||||
char value[1024];
|
||||
static pHdb matchHdbProp(SConnection *pCon, pHdb root, char *propname, char *buffer, pDynString result, int invertmatch){
|
||||
char value[1024], *path=NULL;
|
||||
pHdb current = NULL, search;
|
||||
|
||||
memset(value,0,1024);
|
||||
if(GetHdbProperty(root,propname,value,1023) == 1){
|
||||
if(strstr(buffer,value) != NULL){
|
||||
return root;
|
||||
}
|
||||
}
|
||||
if (strcmp(buffer, "*") == 0) {
|
||||
if(GetHdbProperty(root,propname,value,1023) == 1) {
|
||||
if (!invertmatch) {
|
||||
path = GetHipadabaPath(root);
|
||||
DynStringConcat(result, path);
|
||||
DynStringConcat(result, "\n");
|
||||
free(path);
|
||||
}
|
||||
} else if (invertmatch) {
|
||||
path = GetHipadabaPath(root);
|
||||
DynStringConcat(result, path);
|
||||
DynStringConcat(result, "\n");
|
||||
free(path);
|
||||
}
|
||||
} else if(GetHdbProperty(root,propname,value,1023) == 1) {
|
||||
if(strstr(buffer,value) != NULL) {
|
||||
if (!invertmatch) {
|
||||
path = GetHipadabaPath(root);
|
||||
DynStringConcat(result, path);
|
||||
DynStringConcat(result, "\n");
|
||||
free(path);
|
||||
}
|
||||
} else if (invertmatch) {
|
||||
path = GetHipadabaPath(root);
|
||||
DynStringConcat(result, path);
|
||||
DynStringConcat(result, "\n");
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
current = root->child;
|
||||
while(current != NULL){
|
||||
search = matchHdbProp(current,propname,buffer);
|
||||
if(search != NULL){
|
||||
return search;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
while(current != NULL){
|
||||
search = matchHdbProp(pCon, current,propname,buffer, result, invertmatch);
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -3164,31 +3261,36 @@ static int MatchHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
pHdb root = NULL;
|
||||
pHdb foundNode = NULL;
|
||||
char buffer[1024], *path = NULL;
|
||||
int node = 1, prop = 2, propval= 3, invertmatch = 0;
|
||||
pDynString matchList = NULL;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,"ERROR: need root, property name and target string for search",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if (argc >= 5) {
|
||||
if (strcasecmp(argv[1], "invert") == 0) {
|
||||
invertmatch = 1;
|
||||
node++;
|
||||
prop++;
|
||||
propval++;
|
||||
}
|
||||
}
|
||||
memset(buffer,0,1024);
|
||||
Arg2Text(argc-3,&argv[3],buffer,1023);
|
||||
root = GetHipadabaNode(GetHipadabaRoot(), argv[1]);
|
||||
Arg2Text(argc-propval,&argv[propval],buffer,1023);
|
||||
root = GetHipadabaNode(GetHipadabaRoot(), argv[node]);
|
||||
if(root == NULL){
|
||||
SCWrite(pCon,"ERROR: start node for search not found",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strtolower(argv[2]);
|
||||
strtolower(argv[prop]);
|
||||
strtolower(buffer);
|
||||
foundNode = matchHdbProp(root,argv[2],buffer);
|
||||
|
||||
if(foundNode == NULL){
|
||||
SCWrite(pCon,"NONE", eValue);
|
||||
} else {
|
||||
path = GetHipadabaPath(foundNode);
|
||||
SCWrite(pCon,path,eValue);
|
||||
free(path);
|
||||
}
|
||||
matchList = CreateDynString(128,128);
|
||||
foundNode = matchHdbProp(pCon, root,argv[prop],buffer, matchList, invertmatch);
|
||||
SCWrite(pCon,GetCharArray(matchList),eValue);
|
||||
DeleteDynString(matchList);
|
||||
return 1;
|
||||
}
|
||||
/*======================= Factory Functions =================================*/
|
||||
@@ -3230,7 +3332,9 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
AddCommand(pSics,"hgetprop",GetSICSHdbProperty, NULL, NULL);
|
||||
AddCommand(pSics,"hgetpropval",GetSICSHdbPropertyVal, NULL, NULL);
|
||||
AddCommand(pSics,"hmatchprop",MatchHdbProperty, NULL, NULL);
|
||||
AddCommand(pSics,"hpropexists",HasSICSHdbProperty, NULL, NULL);
|
||||
AddCommand(pSics,"hlistprop",ListSICSHdbProperty, NULL, NULL);
|
||||
AddCommand(pSics,"hfindprop",ANSTO_ListSICSHdbProperty, NULL, NULL);
|
||||
|
||||
InstallSICSPoll(pCon,pSics,pData,argc,argv);
|
||||
poller = (pSicsPoll)FindCommandData(pSics,"sicspoll","SicsPoll");
|
||||
|
||||
Reference in New Issue
Block a user