Skip to content

Commit

Permalink
Fix: redo TreeFindNode and TreeFindNodeWild
Browse files Browse the repository at this point in the history
Given that some wildcard searches are broken, and there is ambiguity in the syntax for **** this change makes the following syntax changes:

[[treename::]tagname{.|:}]

Four single character punctuations

'.' the child
':' the member
'^' the parent
'~' wildcard both member and child

and these can be tripled to make breadth first searches

'...' all children
':::' all members
'~~~' all members and children
'^^^' all parent
four of these is a syntax error

a special case would first translate *** to ~~~
(four of these is also a syntax error)
however ****  becomes ~~~* which is OK.

Some examples

a.b*.c  - a child named c of a child starting with b of a member or child called a
a.b*:c - a member named c of a child starting with b of a member or child called a
a.b*~c -a member or child named c of a child starting with b of a member or child called a
a.b...c  - a child called c someplace under the child hierarchy under a.b
a.b:::c - a member called c someplace under the member hierarchy under a.b
a.b\~\~\~c - a child or member called c someplace under the child/member hierarchy under a.b
a.b*\~\~\~
etc...

Fixes issue #417

The new algorithm consists of:
* use flex to scan (parse) the wildcard specification.  Bison was not needed since the syntax is so simple.
* find all the nodes on the initial call and place them in a list in memory. returning the 1st element
* return elements from the list of found nodes until there are no more.
  • Loading branch information
joshStillerman committed Apr 3, 2018
1 parent ae545d9 commit 4de465e
Show file tree
Hide file tree
Showing 15 changed files with 3,416 additions and 1,101 deletions.
1 change: 1 addition & 0 deletions include/treeshr_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@
#define TreeOPENEDITERR 0xfd19082
#define TreeREADONLY_TREE 0xfd1908a
#define TreeWRITETREEERR 0xfd19092
#define TreeNOWILD 0xfd1909a
8 changes: 8 additions & 0 deletions mdsobjects/python/mdsExceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,14 @@ class TreeWRITETREEERR(TreeException):

MDSplusException.statusDict[265392272] = TreeWRITETREEERR


class TreeNOWILD(TreeException):
status=265392282
message="No wildcard characters permitted in node specifier"
msgnam="NOWILD"

MDSplusException.statusDict[265392280] = TreeNOWILD

########################### generated from mdsshr_messages.xml ########################


Expand Down
10 changes: 10 additions & 0 deletions mdsshr/MdsGetStdMsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,16 @@ EXPORT int MdsGetStdMsg(int status, const char **fac_out, const char **msgnam_ou
sts = 1;}
break;

/* TreeNOWILD */
case 0xfd19098:
{static const char *text="No wildcard characters permitted in node specifier";
static const char *msgnam="NOWILD";
*fac_out = FAC_TREE;
*msgnam_out = msgnam;
*text_out = text;
sts = 1;}
break;

/* LibINSVIRMEM */
case 0x158210:
{static const char *text="Insufficient virtual memory";
Expand Down
20 changes: 14 additions & 6 deletions tditest/testing/do_tditests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ status=0
if [ ! -z $1 ]
then

tmpdir=$(mktemp -d)
trap 'if [ ! -z "${tmpdir}" ]; then rm -Rf ${tmpdir}; fi' EXIT
export main_path="${tmpdir};$(readlink -f ${srcdir}/../../trees)"
export subtree_path="${tmpdir};$(readlink -f ${srcdir}/../../trees/subtree)"
export MDS_PATH="${tmpdir};$(readlink -f ${srcdir}/../../tdi)"
export MDS_PYDEVICE_PATH="${tmpdir};$(readlink -f ${srcdir}/../../pydevices)"

if [ "$2" == "update" ]
then
tmpdir=$(mktemp -d)
trap 'if [ ! -z "${tmpdir}" ]; then rm -Rf ${tmpdir}; fi' EXIT
export main_path="${tmpdir};$(readlink -f ${srcdir}/../../trees)"
export subtree_path="${tmpdir};$(readlink -f ${srcdir}/../../trees/subtree)"
export MDS_PATH="${tmpdir};$(readlink -f ${srcdir}/../../tdi)"
export MDS_PYDEVICE_PATH="${tmpdir};$(readlink -f ${srcdir}/../../pydevices)"
# tmpdir=$(mktemp -d)
# trap 'if [ ! -z "${tmpdir}" ]; then rm -Rf ${tmpdir}; fi' EXIT
# export main_path="${tmpdir};$(readlink -f ${srcdir}/../../trees)"
# export subtree_path="${tmpdir};$(readlink -f ${srcdir}/../../trees/subtree)"
# export MDS_PATH="${tmpdir};$(readlink -f ${srcdir}/../../tdi)"
# export MDS_PYDEVICE_PATH="${tmpdir};$(readlink -f ${srcdir}/../../pydevices)"
$TDITEST $zdrv$srcdir/$test.tdi 2>&1 \
| grep -v 'Data inserted:' \
| grep -v 'Length:' \
Expand Down Expand Up @@ -80,6 +87,7 @@ else
echo "PASS: $test"
rm -f $test-diff.log
fi
rm -Rf ${tmpdir}
fi
exit $status

Expand Down
10 changes: 9 additions & 1 deletion treeshr/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TreeDeleteNode.c \
TreeDeletePulseFile.c \
TreeDoMethod.c \
TreeFindNode.c \
TreeFindTag.c \
TreeFindTagWild.c \
TreeGetDbi.c \
TreeGetNci.c \
Expand All @@ -37,7 +38,8 @@ TreeSetDefault.c \
TreeSetNci.c \
TreeThreadSafe.c \
TreeVerify.c \
RemoteAccess.c
RemoteAccess.c \
lex.yytreepath.c

OBJECTS = $(SOURCES:.c=.o)
EXPORTS = TreeShr.exports
Expand Down Expand Up @@ -70,3 +72,9 @@ install: $(libdir)

TreeShr.exports: TreeShr.def
$(SED) -e /LIBRARY/\;/\;/d TreeShr.def > $@

lex.yytreepath.o: lex.yytreepath.c
$(COMPILE.c) $(CFLAGS) -Wno-sign-compare -Wno-unused-parameter -c $^

#lex.yytreepath.c: TreeFindNodeWild.l
# flex $^
8 changes: 4 additions & 4 deletions treeshr/TreeAddNode.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int _TreeAddNode(void *dbid, char const *name, int *nid_out, char usage)
NODE *parent;
NODE *new_ptr = NULL;
char *node_name;
SEARCH_TYPE node_type;
int is_child;
int nid;
short *conglom_size;
short *conglom_index;
Expand All @@ -130,7 +130,7 @@ int _TreeAddNode(void *dbid, char const *name, int *nid_out, char usage)
See if the node's parent is already in the tree
if not it is an error.
******************************************************/
status = TreeFindParent(dblist, upcase_name, &parent, &node_name, &node_type);
status = TreeFindParent(dblist, upcase_name, &parent, &node_name, &is_child);
if STATUS_OK {
/****************************************************
make sure that the node is not already there
Expand All @@ -156,7 +156,7 @@ int _TreeAddNode(void *dbid, char const *name, int *nid_out, char usage)
If OK so far so grab a new node, Fill in the name
and insert it into the list of brothers.
*************************************************/
if (STATUS_OK && ((node_type == BROTHER_TYPE_NOWILD) || (node_type == MEMBER_TYPE_NOWILD))) {
if (STATUS_OK) {
status = TreeNewNode(dblist, &new_ptr, &parent);
if STATUS_OK {
size_t i;
Expand All @@ -166,7 +166,7 @@ int _TreeAddNode(void *dbid, char const *name, int *nid_out, char usage)
new_ptr->name[i] = ' ';
new_ptr->child = 0;
LoadShort(idx, &new_ptr->conglomerate_elt);
if (node_type == BROTHER_TYPE_NOWILD || usage == TreeUSAGE_STRUCTURE
if (is_child || usage == TreeUSAGE_STRUCTURE
|| usage == TreeUSAGE_SUBTREE) {
status = TreeInsertChild(parent, new_ptr, dblist->tree_info->header->sort_children);
new_ptr->usage = usage == TreeUSAGE_SUBTREE ? TreeUSAGE_SUBTREE : TreeUSAGE_STRUCTURE;
Expand Down
Loading

0 comments on commit 4de465e

Please sign in to comment.