X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=retrieval%2Fd1_if.c;h=62facc35d81cab74d667b4709d01092f2d43c648;hb=548d8ab9b0b5930db27643b47fc55afce5511219;hp=65c3b133b0b1cc39fda83f76c8628e87550425f1;hpb=5ebe07935fedc4ce6b2a3bb0aa29425674ce7d08;p=yaz-moved-to-github.git diff --git a/retrieval/d1_if.c b/retrieval/d1_if.c index 65c3b13..62facc3 100644 --- a/retrieval/d1_if.c +++ b/retrieval/d1_if.c @@ -1,17 +1,28 @@ /* - * Copyright (c) 1995-1999, Index Data. + * Copyright (c) 1995-2000, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * - * d1_if.c : A simple interface for extracting strings from data1_node tree structures + * d1_if.c : A simple interface for extracting strings from data1_node + * tree structures * * $Log: d1_if.c,v $ - * Revision 1.1 1999-12-21 14:16:19 ian + * Revision 1.5 2000-02-10 13:42:43 adam + * Removed C++ comment. + * + * Revision 1.4 2000/01/06 14:30:56 adam + * Minor change - to prevent warnings. + * + * Revision 1.3 2000/01/06 11:27:02 adam + * Minor fix so that this source compiles using Visual C++. + * + * Revision 1.2 2000/01/04 17:46:17 ian + * Added function to count occurences of a tag spec in a data1 tree. + * + * Revision 1.1 1999/12/21 14:16:19 ian * Changed retrieval module to allow data1 trees with no associated absyn. * Also added a simple interface for extracting values from data1 trees using * a string based tagpath. * - * */ #include @@ -51,7 +62,7 @@ char data1_ScanNextToken(char* pBuffer, else { if ( strchr(pWhitespaceChars, **pPosInBuffer) != NULL ) - *pPosInBuffer++; + (*pPosInBuffer)++; else *pBuff++ = *((*pPosInBuffer)++); } @@ -101,6 +112,9 @@ char *data1_getNodeValue(data1_node* node, char* pTagPath) } +/* Max length of a tag */ +#define MAX_TAG_SIZE 50 + /* * data1_LookupNode : Try and find a node as specified by a tagpath */ @@ -112,14 +126,11 @@ data1_node *data1_LookupNode(data1_node* node, char* pTagPath) /* Current Child node as we search for nodes matching the pattern in the tagpath */ data1_node* current_child = node->child; - /* Max length of a tag */ - int iMaxTagSize=50; - /* Current position in string */ char* pCurrCharInPath = pTagPath; /* Work buffer */ - char Buffer[iMaxTagSize]; + char Buffer[MAX_TAG_SIZE]; /* The tag type of this node */ int iTagType = 0; @@ -128,7 +139,7 @@ data1_node *data1_LookupNode(data1_node* node, char* pTagPath) int iTagValue = 0; /* for string tags, the tag value */ - char StringTagVal[iMaxTagSize]; + char StringTagVal[MAX_TAG_SIZE]; /* Which occurence of that tag under this node */ int iOccurences=0; @@ -208,12 +219,14 @@ data1_node *data1_LookupNode(data1_node* node, char* pTagPath) { if ( iOccurences ) { - // Everything matched, but not yet found the right occurence of the given tag + /* Everything matched, but not yet found the + right occurence of the given tag */ iOccurences--; } else { - /* We have matched a string tag... Is there more to process? */ + /* We have matched a string tag... Is there more to + process? */ matched_node = current_child; } } @@ -237,3 +250,56 @@ data1_node *data1_LookupNode(data1_node* node, char* pTagPath) return matched_node; } } + +/** + +data1_CountOccurences + +Count the number of occurences of the last instance on a tagpath. + +@param data1_node* node : The root of the tree we wish to look for occurences in +@param const char* pTagPath : The tagpath we want to count the occurences of... + +*/ +int data1_CountOccurences(data1_node* node, char* pTagPath) +{ + int iRetVal = 0; + data1_node* n = NULL; + data1_node* pParent = NULL; + + n = data1_LookupNode(node, pTagPath ); + + + if ( ( n ) && + ( n->which == DATA1N_tag ) && + ( n->parent ) ) + { + data1_node* current_child; + pParent = n->parent; + + for ( current_child = pParent->child; + current_child; + current_child = current_child->next ) + { + if ( current_child->which == DATA1N_tag ) + { + if ( current_child->u.tag.element == NULL ) + { + if ( ( n->u.tag.tag ) && + ( current_child->u.tag.tag ) && + ( strcmp(current_child->u.tag.tag, n->u.tag.tag) == 0 ) ) + { + iRetVal++; + } + } + else if ( current_child->u.tag.element == n->u.tag.element ) + { + /* Hmmm... Is the above right for non string tags???? */ + iRetVal++; + } + } + } + } + + return iRetVal; +}