4 #include <yaz/diagbib1.h>
6 /* Little helper to extract a string attribute */
7 /* Gets the first string, there is usually only one */
8 /* in case of errors, returns null */
9 const char *stringattr( Z_ComplexAttribute *c ) {
11 Z_StringOrNumeric *son;
12 for ( i = 0; i < c->num_list; i++ ) {
14 if ( son->which == Z_StringOrNumeric_string )
20 /* Use attribute, @attr1, can be numeric or string */
21 void useattr ( Z_AttributeElement *ae,
22 struct attrvalues *av )
25 if ( ae->which == Z_AttributeValue_complex ) {
26 s = stringattr( ae->value.complex );
30 else { /* already seen one, can't have duplicates */
31 av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE_COMBI;
32 av->errstring = "multiple use attributes";
34 } else { /* complex that did not return a string */
35 av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE_COMBI;
36 av->errstring = "non-string complex attribute";
38 } else { /* numeric - could translate 4 to 'title' etc */
39 sprintf(av->useattrbuff, ODR_INT_PRINTF, *ae->value.numeric );
40 av->useattr = av->useattrbuff;
45 /* TODO rename to sortorder attr */
46 void relationattr ( Z_AttributeElement *ae,
47 struct attrvalues *av )
49 if ( ae->which == Z_AttributeValue_numeric ) {
50 if ( *ae->value.numeric == 0 )
51 av->relation = "desc";
52 else if ( *ae->value.numeric == 1 )
55 if ( *ae->value.numeric == 3 ) {
56 av->relation = "unknown/unordered";
58 av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE;
59 sprintf(av->useattrbuff, ODR_INT_PRINTF,
61 av->errstring = av->useattrbuff;
64 av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE;
65 av->errstring = "non-numeric relation attribute";
69 void limitattr ( Z_AttributeElement *ae,
70 struct attrvalues *av )
72 /* TODO - check numeric first, then value! */
73 if ( ae->which == Z_AttributeValue_numeric ) {
74 av->limit = *ae->value.numeric;
76 av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE;
77 av->errstring = "non-numeric limit attribute";
81 /* Get the index to be searched from the attributes.
83 can be either "string", or some well-known value like
85 Returns a null and sets errors in rr,
86 emtpy string if no attr found,
87 or the string itself - always a pointer to the Z-structs,
88 so no need to free that string!
91 void facetattrs( Z_AttributeList *attributes,
92 struct attrvalues *av )
95 Z_AttributeElement *ae;
96 for ( i=0; i < attributes->num_attributes; i++ ) {
97 ae = attributes->attributes[i];
98 /* ignoring the attributeSet here */
99 if ( *ae->attributeType == 1 ) { /* use attribute */
101 } else if ( *ae->attributeType == 2 ) { /* sortorder */
102 relationattr(ae, av);
103 } else if ( *ae->attributeType == 3 ) { /* limit */
105 } else { /* unknown attribute */
106 av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE_TYPE;
107 sprintf(av->useattrbuff, ODR_INT_PRINTF,
108 *ae-> attributeType);
109 av->errstring = av->useattrbuff;
110 yaz_log(YLOG_DEBUG,"Unsupported attribute type %s",
112 /* would like to give a better message, but the standard */
113 /* tells me to return the attribute type */
116 return; /* no need to dig deeper, return on first error */