X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fsortspec.c;h=4c62193d5237c712ec1e87112250b916e097595b;hp=8d99a6738f01f7f6a573e8a2ad4d78f1c14c1fcc;hb=c21a01f2a1dfff7f62636b251d4d129a9f0fbeec;hpb=05c274ef315384faafcc5900c17468f0ea2474e6 diff --git a/src/sortspec.c b/src/sortspec.c index 8d99a67..4c62193 100644 --- a/src/sortspec.c +++ b/src/sortspec.c @@ -1,25 +1,26 @@ -/* - * Copyright (c) 1995-2004, Index Data. +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. - * - * $Id: sortspec.c,v 1.3 2004-10-15 00:19:00 adam Exp $ */ /** * \file sortspec.c * \brief Implements SortSpec parsing. */ +#if HAVE_CONFIG_H +#include +#endif #include #include #include #include -#include #include +#include Z_SortKeySpecList *yaz_sort_spec (ODR out, const char *arg) { - char sort_string_buf[32], sort_flags[32]; + char sort_string_buf[64], sort_flags[64]; Z_SortKeySpecList *sksl = (Z_SortKeySpecList *) odr_malloc (out, sizeof(*sksl)); int off; @@ -27,53 +28,52 @@ Z_SortKeySpecList *yaz_sort_spec (ODR out, const char *arg) sksl->num_specs = 0; sksl->specs = (Z_SortKeySpec **)odr_malloc (out, sizeof(sksl->specs) * 20); - while ((sscanf (arg, "%31s %31s%n", sort_string_buf, - sort_flags, &off)) == 2 && off > 1) + while ((sscanf (arg, "%63s %63s%n", sort_string_buf, + sort_flags, &off)) == 2 && off > 1) { int i; char *sort_string_sep; - char *sort_string = sort_string_buf; + char *sort_string = sort_string_buf; Z_SortKeySpec *sks = (Z_SortKeySpec *)odr_malloc (out, sizeof(*sks)); Z_SortKey *sk = (Z_SortKey *)odr_malloc (out, sizeof(*sk)); - + arg += off; sksl->specs[sksl->num_specs++] = sks; sks->sortElement = (Z_SortElement *) - odr_malloc (out, sizeof(*sks->sortElement)); + odr_malloc (out, sizeof(*sks->sortElement)); sks->sortElement->which = Z_SortElement_generic; sks->sortElement->u.generic = sk; if ((sort_string_sep = strchr (sort_string, '='))) { - int i = 0; + int i = 0; sk->which = Z_SortKey_sortAttributes; sk->u.sortAttributes = (Z_SortAttributes *) - odr_malloc (out, sizeof(*sk->u.sortAttributes)); - sk->u.sortAttributes->id = - yaz_oidval_to_z3950oid(out, CLASS_ATTSET, VAL_BIB1); + odr_malloc (out, sizeof(*sk->u.sortAttributes)); + sk->u.sortAttributes->id = odr_oiddup(out, yaz_oid_attset_bib_1); sk->u.sortAttributes->list = (Z_AttributeList *) - odr_malloc (out, sizeof(*sk->u.sortAttributes->list)); + odr_malloc (out, sizeof(*sk->u.sortAttributes->list)); sk->u.sortAttributes->list->attributes = (Z_AttributeElement **) - odr_malloc (out, 10 * - sizeof(*sk->u.sortAttributes->list->attributes)); - while (i < 10 && sort_string && sort_string_sep) - { - Z_AttributeElement *el = (Z_AttributeElement *) - odr_malloc (out, sizeof(*el)); - sk->u.sortAttributes->list->attributes[i] = el; - el->attributeSet = 0; - el->attributeType = odr_intdup (out, atoi (sort_string)); - el->which = Z_AttributeValue_numeric; - el->value.numeric = - odr_intdup (out, atoi (sort_string_sep + 1)); - i++; - sort_string = strchr(sort_string, ','); - if (sort_string) - { - sort_string++; - sort_string_sep = strchr (sort_string, '='); - } - } + odr_malloc (out, 10 * + sizeof(*sk->u.sortAttributes->list->attributes)); + while (i < 10 && sort_string && sort_string_sep) + { + Z_AttributeElement *el = (Z_AttributeElement *) + odr_malloc (out, sizeof(*el)); + sk->u.sortAttributes->list->attributes[i] = el; + el->attributeSet = 0; + el->attributeType = odr_intdup (out, atoi (sort_string)); + el->which = Z_AttributeValue_numeric; + el->value.numeric = + odr_intdup (out, atoi (sort_string_sep + 1)); + i++; + sort_string = strchr(sort_string, ','); + if (sort_string) + { + sort_string++; + sort_string_sep = strchr (sort_string, '='); + } + } sk->u.sortAttributes->list->num_attributes = i; } else @@ -86,7 +86,7 @@ Z_SortKeySpecList *yaz_sort_spec (ODR out, const char *arg) sks->which = Z_SortKeySpec_null; sks->u.null = odr_nullval (); - + for (i = 0; sort_flags[i]; i++) { switch (sort_flags[i]) @@ -109,10 +109,33 @@ Z_SortKeySpecList *yaz_sort_spec (ODR out, const char *arg) case 's': *sks->caseSensitivity = Z_SortKeySpec_caseSensitive; break; + case '!': + sks->which = Z_SortKeySpec_abort; + sks->u.abort = odr_nullval(); + break; + case '=': + sks->which = Z_SortKeySpec_missingValueData; + sks->u.missingValueData = (Odr_oct*) + odr_malloc(out, sizeof(Odr_oct)); + i++; + sks->u.missingValueData->len = strlen(sort_flags+i); + sks->u.missingValueData->size = sks->u.missingValueData->len; + sks->u.missingValueData->buf = (unsigned char*) + odr_strdup(out, sort_flags+i); + i += strlen(sort_flags+i); } } } if (!sksl->num_specs) - return 0; + return 0; return sksl; } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +