X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fpquery.c;h=47ff25b2ec208d64235dc2bce162cc5da71e64d5;hp=80d10311c905213d73b4a601e1a494cf3f024414;hb=559aecba0e61eca34706023436692ba23faa29a7;hpb=6517fa53d35512887780fd07de5667940da18a9e diff --git a/util/pquery.c b/util/pquery.c index 80d1031..47ff25b 100644 --- a/util/pquery.c +++ b/util/pquery.c @@ -4,7 +4,27 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: pquery.c,v $ - * Revision 1.13 1997-09-17 12:10:42 adam + * Revision 1.19 1998-03-05 08:09:03 adam + * Minor change to make C++ happy. + * + * Revision 1.18 1998/02/11 11:53:36 adam + * Changed code so that it compiles as C++. + * + * Revision 1.17 1997/11/24 11:33:57 adam + * Using function odr_nullval() instead of global ODR_NULLVAL when + * appropriate. + * + * Revision 1.16 1997/09/29 13:19:00 adam + * Added function, oid_ent_to_oid, to replace the function + * oid_getoidbyent, which is not thread safe. + * + * Revision 1.15 1997/09/29 07:13:43 adam + * Changed type of a few variables to avoid warnings. + * + * Revision 1.14 1997/09/22 12:33:41 adam + * Fixed bug introduced by previous commit. + * + * Revision 1.13 1997/09/17 12:10:42 adam * YAZ version 1.4. * * Revision 1.12 1997/09/01 08:54:13 adam @@ -62,7 +82,7 @@ static oid_value p_query_dfset = VAL_NONE; struct lex_info { const char *query_buf; const char *lex_buf; - int lex_len; + size_t lex_len; int query_look; char *left_sep; char *right_sep; @@ -74,7 +94,7 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, oid_proto, int num_attr, int max_attr, int *attr_list, oid_value *attr_set); -static int query_oid_getvalbyname (struct lex_info *li) +static enum oid_value query_oid_getvalbyname (struct lex_info *li) { char buf[32]; @@ -85,11 +105,11 @@ static int query_oid_getvalbyname (struct lex_info *li) return oid_getvalbyname (buf); } -static int compare_term (struct lex_info *li, const char *src, int off) +static int compare_term (struct lex_info *li, const char *src, size_t off) { size_t len=strlen(src); - if (li->lex_len == len && !memcmp (li->lex_buf+off, src, len-off)) + if (li->lex_len == len+off && !memcmp (li->lex_buf+off, src, len-off)) return 1; return 0; } @@ -163,9 +183,9 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, Odr_oct *term_octet; Z_Term *term; - zapt = odr_malloc (o, sizeof(*zapt)); - term_octet = odr_malloc (o, sizeof(*term_octet)); - term = odr_malloc (o, sizeof(*term)); + zapt = (Z_AttributesPlusTerm *)odr_malloc (o, sizeof(*zapt)); + term_octet = (Odr_oct *)odr_malloc (o, sizeof(*term_octet)); + term = (Z_Term *)odr_malloc (o, sizeof(*term)); zapt->num_attributes = num_attr; if (num_attr) @@ -173,15 +193,15 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, int i; int *attr_tmp; - zapt->attributeList = odr_malloc (o, num_attr * + zapt->attributeList = (Z_AttributeElement**)odr_malloc (o, num_attr * sizeof(*zapt->attributeList)); - attr_tmp = odr_malloc (o, num_attr * 2 * sizeof(int)); + attr_tmp = (int *)odr_malloc (o, num_attr * 2 * sizeof(int)); memcpy (attr_tmp, attr_list, num_attr * 2 * sizeof(int)); for (i = 0; i < num_attr; i++) { zapt->attributeList[i] = - odr_malloc (o,sizeof(**zapt->attributeList)); + (Z_AttributeElement*)odr_malloc (o,sizeof(**zapt->attributeList)); zapt->attributeList[i]->attributeType = &attr_tmp[2*i]; #ifdef Z_95 if (attr_set[i] == VAL_NONE) @@ -189,13 +209,14 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, else { oident attrid; + int oid[OID_SIZE]; attrid.proto = PROTO_Z3950; attrid.oclass = CLASS_ATTSET; attrid.value = attr_set[i]; zapt->attributeList[i]->attributeSet = - odr_oiddup (o, oid_getoidbyent (&attrid)); + odr_oiddup (o, oid_ent_to_oid (&attrid, oid)); } zapt->attributeList[i]->which = Z_AttributeValue_numeric; zapt->attributeList[i]->value.numeric = &attr_tmp[2*i+1]; @@ -205,11 +226,11 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, } } else - zapt->attributeList = ODR_NULLVAL; + zapt->attributeList = (Z_AttributeElement**)odr_nullval(); zapt->term = term; term->which = Z_Term_general; term->u.general = term_octet; - term_octet->buf = odr_malloc (o, li->lex_len); + term_octet->buf = (unsigned char *)odr_malloc (o, li->lex_len); term_octet->size = term_octet->len = li->lex_len; memcpy (term_octet->buf, li->lex_buf, li->lex_len); return zapt; @@ -221,7 +242,7 @@ static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto, { Z_Operand *zo; - zo = odr_malloc (o, sizeof(*zo)); + zo = (Z_Operand *)odr_malloc (o, sizeof(*zo)); switch (li->query_look) { case 't': @@ -236,7 +257,7 @@ static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto, if (!li->query_look) return NULL; zo->which = Z_Operand_resultSetId; - zo->u.resultSetId = odr_malloc (o, li->lex_len+1); + zo->u.resultSetId = (char *)odr_malloc (o, li->lex_len+1); memcpy (zo->u.resultSetId, li->lex_buf, li->lex_len); zo->u.resultSetId[li->lex_len] = '\0'; lex (li); @@ -249,18 +270,18 @@ static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto, static Z_ProximityOperator *rpn_proximity (struct lex_info *li, ODR o) { - Z_ProximityOperator *p = odr_malloc (o, sizeof(*p)); + Z_ProximityOperator *p = (Z_ProximityOperator *)odr_malloc (o, sizeof(*p)); if (!lex (li)) return NULL; if (*li->lex_buf == '1') { - p->exclusion = odr_malloc (o, sizeof(*p->exclusion)); + p->exclusion = (int *)odr_malloc (o, sizeof(*p->exclusion)); *p->exclusion = 1; } else if (*li->lex_buf == '0') { - p->exclusion = odr_malloc (o, sizeof(*p->exclusion)); + p->exclusion = (int *)odr_malloc (o, sizeof(*p->exclusion)); *p->exclusion = 0; } else @@ -268,17 +289,17 @@ static Z_ProximityOperator *rpn_proximity (struct lex_info *li, ODR o) if (!lex (li)) return NULL; - p->distance = odr_malloc (o, sizeof(*p->distance)); + p->distance = (int *)odr_malloc (o, sizeof(*p->distance)); *p->distance = atoi (li->lex_buf); if (!lex (li)) return NULL; - p->ordered = odr_malloc (o, sizeof(*p->ordered)); + p->ordered = (int *)odr_malloc (o, sizeof(*p->ordered)); *p->ordered = atoi (li->lex_buf); if (!lex (li)) return NULL; - p->relationType = odr_malloc (o, sizeof(*p->relationType)); + p->relationType = (int *)odr_malloc (o, sizeof(*p->relationType)); *p->relationType = atoi (li->lex_buf); if (!lex (li)) @@ -292,7 +313,7 @@ static Z_ProximityOperator *rpn_proximity (struct lex_info *li, ODR o) if (!lex (li)) return NULL; - p->proximityUnitCode = odr_malloc (o, sizeof(*p->proximityUnitCode)); + p->proximityUnitCode = (int *)odr_malloc (o, sizeof(*p->proximityUnitCode)); *p->proximityUnitCode = atoi (li->lex_buf); return p; @@ -305,22 +326,22 @@ static Z_Complex *rpn_complex (struct lex_info *li, ODR o, oid_proto proto, Z_Complex *zc; Z_Operator *zo; - zc = odr_malloc (o, sizeof(*zc)); - zo = odr_malloc (o, sizeof(*zo)); + zc = (Z_Complex *)odr_malloc (o, sizeof(*zc)); + zo = (Z_Operator *)odr_malloc (o, sizeof(*zo)); zc->roperator = zo; switch (li->query_look) { case 'a': zo->which = Z_Operator_and; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; case 'o': zo->which = Z_Operator_or; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; case 'n': zo->which = Z_Operator_and_not; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; case 'p': zo->which = Z_Operator_prox; @@ -351,7 +372,7 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, Z_RPNStructure *sz; const char *cp; - sz = odr_malloc (o, sizeof(*sz)); + sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz)); switch (li->query_look) { case 'a': @@ -379,7 +400,7 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, if (num_attr >= max_attr) return NULL; if (!(cp = strchr (li->lex_buf, '=')) || - (cp-li->lex_buf) > li->lex_len) + (size_t) (cp-li->lex_buf) > li->lex_len) { attr_set[num_attr] = query_oid_getvalbyname (li); lex (li); @@ -435,8 +456,9 @@ Z_RPNQuery *p_query_rpn_mk (ODR o, struct lex_info *li, oid_proto proto, oid_value attr_set[512]; oid_value topSet = VAL_NONE; oident oset; + int oid[OID_SIZE]; - zq = odr_malloc (o, sizeof(*zq)); + zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq)); lex (li); if (li->query_look == 'r') { @@ -455,7 +477,7 @@ Z_RPNQuery *p_query_rpn_mk (ODR o, struct lex_info *li, oid_proto proto, oset.oclass = CLASS_ATTSET; oset.value = topSet; - zq->attributeSetId = odr_oiddup (o, oid_getoidbyent (&oset)); + zq->attributeSetId = odr_oiddup (o, oid_ent_to_oid (&oset, oid)); if (!(zq->RPNStructure = rpn_structure (li, o, proto, 0, 512, attr_array, attr_set))) @@ -488,6 +510,7 @@ Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li, const char *cp; oid_value topSet = VAL_NONE; oident oset; + int oid[OID_SIZE]; lex (li); if (li->query_look == 'r') @@ -505,7 +528,7 @@ Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li, oset.oclass = CLASS_ATTSET; oset.value = topSet; - *attributeSetP = odr_oiddup (o, oid_getoidbyent (&oset)); + *attributeSetP = odr_oiddup (o, oid_ent_to_oid (&oset, oid)); while (li->query_look == 'l') { @@ -516,7 +539,7 @@ Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li, return NULL; if (!(cp = strchr (li->lex_buf, '=')) || - (cp-li->lex_buf) > li->lex_len) + (size_t) (cp-li->lex_buf) > li->lex_len) { attr_set[num_attr] = query_oid_getvalbyname (li); lex (li);