diff --git a/alias.c b/alias.c index 62bf3840..45155e15 100644 --- a/alias.c +++ b/alias.c @@ -212,3 +212,22 @@ } return 1; } +/*-------------------------------------------------------------------------------*/ +int LocateAliasAction(SConnection *pCon, SicsInterp *pSics, + void *pData, int argc, char *argv[]){ + char *aliases = NULL; + + if(argc < 2){ + SCWrite(pCon,"ERROR: missing argument aliasname for locating aliases",eError); + return 0; + } + + strtolower(argv[1]); + aliases = FindAliases(pSics,argv[1]); + if(aliases == NULL){ + SCWrite(pCon,"NONE", eValue); + } else { + SCPrintf(pCon,eValue,"%s = %s",argv[1], aliases); + } + return 1; +} diff --git a/alias.h b/alias.h index 88b327e4..4a70827c 100644 --- a/alias.h +++ b/alias.h @@ -16,5 +16,7 @@ int argc, char *argv[]); int MakeAlias(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); + int LocateAliasAction(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); #endif diff --git a/exeman.c b/exeman.c index 2b1b2ac7..6f62d3c6 100644 --- a/exeman.c +++ b/exeman.c @@ -1068,11 +1068,14 @@ static int printBuffer(pExeMan self, SConnection *pCon, DeleteDynString(filePath); return 0; } + DeleteDynString(filePath); + SCStartBuffering(pCon); while(fgets(pLine,511,fd) != NULL){ SCWrite(pCon,pLine,eValue); } fclose(fd); - DeleteDynString(filePath); + filePath = SCEndBuffering(pCon); + SCWrite(pCon,GetCharArray(filePath),eValue); return 1; } /*========================== run stack ===============================*/ diff --git a/hipadaba.h b/hipadaba.h index 2f5b9d70..33489736 100644 --- a/hipadaba.h +++ b/hipadaba.h @@ -324,7 +324,7 @@ int SetHipadabaPar(pHdb node, hdbValue v, void *callData); */ int UpdateHipadabaPar(pHdb node, hdbValue v, void *callData); /** - * notify any update listeners that this node has been internally modidifed. + * notify any update listeners that this node has been internally modifed. * @param node The node modified * @param callData Addtional data for the callback * @return 1 on success, 0 on failure diff --git a/ofac.c b/ofac.c index 966b5da6..34c5e703 100644 --- a/ofac.c +++ b/ofac.c @@ -247,6 +247,7 @@ AddCommand(pInter,"commandlog",CommandLog,CommandLogClose,NULL); AddCommand(pInter,"udpquieck",QuieckAction,KillQuieck,NULL); AddCommand(pInter,"alias",MakeAlias,NULL,NULL); + AddCommand(pInter,"findalias",LocateAliasAction,NULL,NULL); AddCommand(pInter,"sicscron",MakeCron,NULL,NULL); AddCommand(pInter,"dolater",MakeCron,NULL,NULL); AddCommand(pInter,"sicsdatafactory",SICSDataFactory,NULL,NULL); diff --git a/sicshipadaba.c b/sicshipadaba.c index 7e6d4f12..387ed5f3 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -11,6 +11,8 @@ * * Added property functions, Mark Koennecke, January 2007 * + * Added hmatchprop function. Mark Koennecke, February 2008 + * * TODO: separate this into two modules: sicshipadaba proper and sicshipadabaint for the * interpreter interface. */ @@ -2353,7 +2355,7 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, return 0; } - if(strchr(argv[1],'-') != NULL){ + if(argv[1][0] == '-'){ pathArg = 2; if(argc < 3){ SCWrite(pCon,"ERROR: need path to node to print",eError); @@ -2789,6 +2791,61 @@ static int ListSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData DeleteDynString(data); return 1; } +/*---------------------------------------------------------------------------*/ +static pHdb matchHdbProp(pHdb root, char *propname, char *buffer){ + char value[1024]; + pHdb current = NULL, search; + + memset(value,0,1024); + if(GetHdbProperty(root,propname,value,1023) == 1){ + if(strstr(buffer,value) != NULL){ + return root; + } + } + current = root->child; + while(current != NULL){ + search = matchHdbProp(current,propname,buffer); + if(search != NULL){ + return search; + } + current = current->next; + } + + return NULL; +} +/*---------------------------------------------------------------------------*/ +static int MatchHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb root = NULL; + pHdb foundNode = NULL; + char buffer[1024], *path = NULL; + + if(argc < 4){ + SCWrite(pCon,"ERROR: need root, property name and target string for search", + eError); + return 0; + } + memset(buffer,0,1024); + Arg2Text(argc-3,&argv[3],buffer,1023); + root = GetHipadabaNode(GetHipadabaRoot(), argv[1]); + if(root == NULL){ + SCWrite(pCon,"ERROR: start node for search not found",eError); + return 0; + } + + strtolower(argv[2]); + 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); + } + return 1; +} /*======================= Factory Functions =================================*/ void killSICSHipadaba(){ if(root != NULL){ @@ -2820,7 +2877,8 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData, AddCommand(pSics,"hcommand",SicsCommandNode, NULL, NULL); AddCommand(pSics,"hsetprop",SetSICSHdbProperty, NULL, NULL); AddCommand(pSics,"hgetprop",GetSICSHdbProperty, NULL, NULL); - AddCommand(pSics,"hgetpropval",GetSICSHdbPropertyVal, NULL, NULL); + AddCommand(pSics,"hgetprop",GetSICSHdbProperty, NULL, NULL); + AddCommand(pSics,"hmatchprop",MatchHdbProperty, NULL, NULL); AddCommand(pSics,"hlistprop",ListSICSHdbProperty, NULL, NULL); InstallSICSPoll(pCon,pSics,pData,argc,argv);