int _TreeGetDefaultNid(void *dbid, int *nid_in) { PINO_DATABASE *dblist = (PINO_DATABASE *)dbid; NID *nid = (NID *)nid_in; if (!(IS_OPEN(dblist))) return TreeNOT_OPEN; if (dblist->remote) return GetDefaultNidRemote(dblist,nid_in); node_to_nid(dblist, (dblist->default_node), nid); return TreeNORMAL; }
STATIC_ROUTINE void check_nid(PINO_DATABASE *dblist, NID *nid, int *count) { int bitnum = nid->node; if (!getbit(bitnum)) { NODE *node; NODE *descendent; nid_to_node(dblist, nid, node); if (count) (*count)++; setbit(bitnum); for (descendent = member_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } for (descendent = child_of(node); descendent; descendent = brother_of(descendent)) { NID nid; node_to_nid(dblist, descendent, (&nid)); check_nid(dblist, &nid, count); } if (swapshort((char *)&node->conglomerate_elt)) { NID elt_nid; NODE *elt_node; unsigned short elt_num = 1; elt_nid.node = nid->node - swapshort((char *)&node->conglomerate_elt) + 1; elt_nid.tree = nid->tree; nid_to_node(dblist, (&elt_nid), elt_node); for (; swapshort((char *)&elt_node->conglomerate_elt) == elt_num; elt_nid.node++, elt_num++, elt_node++) check_nid(dblist, &elt_nid, count); } } }
char *_TreeFindTagWild(void *dbid, char *wild, int *nidout, void **ctx_inout) { PINO_DATABASE *dblist = (PINO_DATABASE *)dbid; /*************************** check that there is a tree open. ****************************/ if (!IS_OPEN(dblist)) return NULL; if (dblist->remote) return FindTagWildRemote(dblist,wild,nidout,ctx_inout); else { NID *nid_ptr = (NID *)nidout; TAG_SEARCH **ctx = (TAG_SEARCH **)ctx_inout; int status = 1; unsigned char found,done; static char answer[128]; /********************************** If this is the first time then allocate a context block and fill it in with a parse of the tagname. ***********************************/ if (*ctx == (TAG_SEARCH *) 0) { *ctx = NewTagSearch(wild); if (*ctx == (TAG_SEARCH *) 0) status = TreeNMT; else status = NextTagTree(dblist, *ctx); } /************************************* Loop looking for a tag that matches **************************************/ for (found = 0, done = 0; (status & 1) && !found && !done;) { /************************************* if out of tags in this tree then see if there is another one **************************************/ if ((*ctx)->next_tag >= (*ctx)->this_tree_info->header->tags) { status = NextTagTree(dblist, *ctx); if (status & 1) (*ctx)->next_tag = -1; else { done = 1; break; } } else { /********************************************** else if this is the first time for this tree try to return the \TOP tag. otherwise - move on to next tag for next time through the loop. ***********************************************/ if ((*ctx)->next_tag == -1) { if ((*ctx)->top_match) { done = 1; found = 1; } else ((*ctx)->next_tag)++; } else { /**************************************** Else loop looking for a tag that matches *****************************************/ for (; !done && ((*ctx)->next_tag < (*ctx)->this_tree_info->header->tags);) { unsigned short len; static struct descriptor_s s_tag_dsc = { sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0}; static struct descriptor_d tag_dsc = {0, DTYPE_T, CLASS_D, 0}; s_tag_dsc.pointer = (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name; StrTrim(&tag_dsc, &s_tag_dsc,&len); if (StrMatchWild(&tag_dsc, &((*ctx)->search_tag)) & 1) { done = 1; found = 1; } else ((*ctx)->next_tag)++; } } } } /******************************************** If done and found then fill in the answer *********************************************/ if (found) { NODE *nptr = (*ctx)->this_tree_info->node; static char tagname[sizeof(TAG_NAME)+1]; if ((*ctx)->next_tag != -1) { static struct descriptor_s s_tag_name = {sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0}; static struct descriptor_s tag_name = {sizeof(TAG_NAME), DTYPE_T, CLASS_S, tagname}; unsigned short len; s_tag_name.pointer = (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name; StrTrim(&tag_name, &s_tag_name,&len); tagname[len]='\0'; nptr += swapint(&(*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].node_idx); } else strcpy(tagname,"TOP"); strcpy(answer,"\\"); strcat(answer,(*ctx)->this_tree_info->treenam); strcat(answer,"::"); strcat(answer,tagname); if (nid_ptr) node_to_nid(dblist, nptr, nid_ptr); ((*ctx)->next_tag)++; status = 1; } else { TreeFindTagEnd(ctx_inout); status = TreeNMT; } return (status & 1) ? answer : NULL; } }