Added -space option to hlist command. This is useful for processing hlist outpu in Tcl.

r1691 | ffr | 2007-03-20 16:06:24 +1100 (Tue, 20 Mar 2007) | 2 lines
This commit is contained in:
Ferdi Franceschini
2007-03-20 16:06:24 +11:00
committed by Douglas Clowes
parent efb997cd16
commit 78905ca695

View File

@@ -33,6 +33,12 @@ typedef enum {
normal_protocol, normal_protocol,
json_protocol, json_protocol,
} Protocol; } Protocol;
typedef enum {
linefeed,
space,
} RecSep;
char *trim(char *str); char *trim(char *str);
/*=============== common callback functions used for SICS ===========================*/ /*=============== common callback functions used for SICS ===========================*/
static int SICSCheckPermissionCallback(void *userData, void *callData, pHdb node, static int SICSCheckPermissionCallback(void *userData, void *callData, pHdb node,
@@ -1943,7 +1949,7 @@ int isSICSHdbRO(pHdb node){
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static pDynString formatPlainList(pHdb node){ static pDynString formatPlainList(pHdb node, RecSep recsep){
pHdb current; pHdb current;
pDynString result = NULL; pDynString result = NULL;
@@ -1955,7 +1961,14 @@ static pDynString formatPlainList(pHdb node){
current = node->child; current = node->child;
while(current != NULL){ while(current != NULL){
DynStringConcat(result,current->name); DynStringConcat(result,current->name);
switch (recsep) {
case space:
DynStringConcat(result," ");
break;
case linefeed:
default:
DynStringConcat(result,"\n"); DynStringConcat(result,"\n");
}
current = current->next; current = current->next;
} }
return result; return result;
@@ -2132,12 +2145,16 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
listData = formatListWithVal(node); listData = formatListWithVal(node);
} else if(strcmp(argv[1],"-cli") == 0){ } else if(strcmp(argv[1],"-cli") == 0){
listData = formatClientList(node); listData = formatClientList(node);
} else if(strcmp(argv[1],"-space") == 0){
listData = formatPlainList(node, space);
} else if(strcmp(argv[1],"-linefeed") == 0){
listData = formatPlainList(node, linefeed);
} else { } else {
if ((protocol = isJSON(pCon)) == 1) { if ((protocol = isJSON(pCon)) == 1) {
listData = formatJSONList(node); listData = formatJSONList(node);
outCode = eHdbEvent; outCode = eHdbEvent;
} else { } else {
listData = formatPlainList(node); listData = formatPlainList(node, linefeed);
outCode = eEvent; outCode = eEvent;
} }
} }