X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=data1%2Fd1_espec.c;h=ea73ee4495366a5cd33eead30b05cd2bef8971ab;hp=18ce961ef1f951770edf8abd6cb05151d5c9c984;hb=85ad68ab178a261dc548284ee68aae9107cbfaaf;hpb=519fefb91135ad52134b9fc4e82b3874f5525a2b diff --git a/data1/d1_espec.c b/data1/d1_espec.c index 18ce961..ea73ee4 100644 --- a/data1/d1_espec.c +++ b/data1/d1_espec.c @@ -1,33 +1,43 @@ -/* - * Copyright (c) 1995-2002, Index Data. - * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss - * - * $Id: d1_espec.c,v 1.1 2002-10-22 12:53:33 adam Exp $ - */ +/* This file is part of the Zebra server. + Copyright (C) 1994-2011 Index Data + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#if HAVE_CONFIG_H +#include +#endif #include #include #include +#include +#include #include #include -#include -#include +#include +#include static Z_Variant *read_variant(int argc, char **argv, NMEM nmem, const char *file, int lineno) { Z_Variant *r = (Z_Variant *)nmem_malloc(nmem, sizeof(*r)); - oident var1; int i; - int oid[OID_SIZE]; - - var1.proto = PROTO_Z3950; - var1.oclass = CLASS_VARSET; - var1.value = VAL_VAR1; - r->globalVariantSetId = odr_oiddup_nmem(nmem, oid_ent_to_oid(&var1, oid)); + r->globalVariantSetId = odr_oiddup_nmem(nmem, yaz_oid_varset_variant_1); if (argc) r->triples = (Z_Triple **)nmem_malloc(nmem, sizeof(Z_Triple*) * argc); else @@ -41,16 +51,14 @@ static Z_Variant *read_variant(int argc, char **argv, NMEM nmem, if (sscanf(argv[i], "(%d,%d,%511[^)])", &zclass, &type, value) < 3) { - yaz_log(LOG_WARN, "%s:%d: Syntax error in variant component '%s'", + yaz_log(YLOG_WARN, "%s:%d: Syntax error in variant component '%s'", file, lineno, argv[i]); return 0; } t = r->triples[i] = (Z_Triple *)nmem_malloc(nmem, sizeof(Z_Triple)); t->variantSetId = 0; - t->zclass = (int *)nmem_malloc(nmem, sizeof(int)); - *t->zclass = zclass; - t->type = (int *)nmem_malloc(nmem, sizeof(int)); - *t->type = type; + t->zclass = nmem_intdup(nmem, zclass); + t->type = nmem_intdup(nmem, type); /* * This is wrong.. we gotta look up the correct type for the * variant, I guess... damn this stuff. @@ -63,16 +71,12 @@ static Z_Variant *read_variant(int argc, char **argv, NMEM nmem, else if (d1_isdigit(*value)) { t->which = Z_Triple_integer; - t->value.integer = (int *) - nmem_malloc(nmem, sizeof(*t->value.integer)); - *t->value.integer = atoi(value); + t->value.integer = nmem_intdup(nmem, atoi(value)); } else { t->which = Z_Triple_internationalString; - t->value.internationalString = (char *) - nmem_malloc(nmem, strlen(value)+1); - strcpy(t->value.internationalString, value); + t->value.internationalString = nmem_strdup(nmem, value); } } return r; @@ -89,8 +93,7 @@ static Z_Occurrences *read_occurrences(char *occ, NMEM nmem, op->which = Z_Occurrences_values; op->u.values = (Z_OccurValues *) nmem_malloc(nmem, sizeof(Z_OccurValues)); - op->u.values->start = (int *)nmem_malloc(nmem, sizeof(int)); - *op->u.values->start = 1; + op->u.values->start = nmem_intdup(nmem, 1); op->u.values->howMany = 0; } else if (!strcmp(occ, "all")) @@ -109,19 +112,15 @@ static Z_Occurrences *read_occurrences(char *occ, NMEM nmem, if (!d1_isdigit(*occ)) { - yaz_log(LOG_WARN, "%s:%d: Bad occurrences-spec %s", + yaz_log(YLOG_WARN, "%s:%d: Bad occurrences-spec %s", file, lineno, occ); return 0; } op->which = Z_Occurrences_values; op->u.values = ov; - ov->start = (int *)nmem_malloc(nmem, sizeof(*ov->start)); - *ov->start = atoi(occ); + ov->start = nmem_intdup(nmem, atoi(occ)); if ((p = strchr(occ, '+'))) - { - ov->howMany = (int *)nmem_malloc(nmem, sizeof(*ov->howMany)); - *ov->howMany = atoi(p + 1); - } + ov->howMany = nmem_intdup(nmem, atoi(p + 1)); else ov->howMany = 0; } @@ -162,30 +161,48 @@ static Z_ETagUnit *read_tagunit(char *buf, NMEM nmem, { valp++; force_string = 1; + if (*valp && valp[strlen(valp)-1] == '\'') + *valp = '\0'; } u->which = Z_ETagUnit_specificTag; u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem, sizeof(*t)); - t->tagType = (int *)nmem_malloc(nmem, sizeof(*t->tagType)); - *t->tagType = type; + t->tagType = nmem_intdup(nmem, type); t->tagValue = (Z_StringOrNumeric *) nmem_malloc(nmem, sizeof(*t->tagValue)); - if (!force_string && (numval = atoi(valp))) + if (!force_string && isdigit(*(unsigned char *)valp)) { + numval = atoi(valp); t->tagValue->which = Z_StringOrNumeric_numeric; - t->tagValue->u.numeric = (int *)nmem_malloc(nmem, sizeof(int)); - *t->tagValue->u.numeric = numval; + t->tagValue->u.numeric = nmem_intdup(nmem, numval); } else { t->tagValue->which = Z_StringOrNumeric_string; - t->tagValue->u.string = (char *)nmem_malloc(nmem, strlen(valp)+1); - strcpy(t->tagValue->u.string, valp); + t->tagValue->u.string = nmem_strdup(nmem, valp); } if (terms > 2) /* an occurrences-spec exists */ t->occurrences = read_occurrences(occ, nmem, file, lineno); else t->occurrences = 0; } + else if ((terms = sscanf(buf, "%511[^)]", value)) >= 1) + { + Z_SpecificTag *t; + char *valp = value; + + u->which = Z_ETagUnit_specificTag; + u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem, sizeof(*t)); + t->tagType = nmem_intdup(nmem, 3); + t->tagValue = (Z_StringOrNumeric *) + nmem_malloc(nmem, sizeof(*t->tagValue)); + t->tagValue->which = Z_StringOrNumeric_string; + t->tagValue->u.string = nmem_strdup(nmem, valp); + t->occurrences = read_occurrences("all", nmem, file, lineno); + } + else + { + return 0; + } return u; } @@ -203,10 +220,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem, sizeof(*res)); if (!(f = data1_path_fopen(dh, file, "r"))) - { - yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; - } res->num_elementSetNames = 0; res->elementSetNames = 0; @@ -223,7 +237,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) if (!nnames) { - yaz_log(LOG_WARN, "%s:%d: Empty elementsetnames directive", + yaz_log(YLOG_WARN, "%s:%d: Empty elementsetnames directive", file, lineno); continue; } @@ -232,9 +246,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) (char **)nmem_malloc(nmem, sizeof(char**)*nnames); for (i = 0; i < nnames; i++) { - res->elementSetNames[i] = (char *) - nmem_malloc(nmem, strlen(argv[i+1])+1); - strcpy(res->elementSetNames[i], argv[i+1]); + res->elementSetNames[i] = nmem_strdup(nmem, argv[i+1]); } res->num_elementSetNames = nnames; } @@ -242,14 +254,14 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) { if (argc != 2) { - yaz_log(LOG_WARN, "%s:%d: Bad # of args for %s", + yaz_log(YLOG_WARN, "%s:%d: Bad # of args for %s", file, lineno, argv[0]); continue; } if (!(res->defaultVariantSetId = odr_getoidbystr_nmem(nmem, argv[1]))) { - yaz_log(LOG_WARN, "%s:%d: Bad defaultvariantsetid", + yaz_log(YLOG_WARN, "%s:%d: Bad defaultvariantsetid", file, lineno); continue; } @@ -258,19 +270,18 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) { if (argc != 2) { - yaz_log(LOG_WARN, "%s:%d: Bad # of args for %s", + yaz_log(YLOG_WARN, "%s:%d: Bad # of args for %s", file, lineno, argv[0]); continue; } - res->defaultTagType = (int *)nmem_malloc(nmem, sizeof(int)); - *res->defaultTagType = atoi(argv[1]); + res->defaultTagType = nmem_intdup(nmem, atoi(argv[1])); } else if (!strcmp(argv[0], "defaultvariantrequest")) { if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, nmem, file, lineno))) { - yaz_log(LOG_WARN, "%s:%d: Bad defaultvariantrequest", + yaz_log(YLOG_WARN, "%s:%d: Bad defaultvariantrequest", file, lineno); continue; } @@ -297,7 +308,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) } if (argc < 2) { - yaz_log(LOG_WARN, "%s:%d: Bad # of args for %s", + yaz_log(YLOG_WARN, "%s:%d: Bad # of args for %s", file, lineno, argv[0]); continue; } @@ -329,7 +340,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) tagunit = read_tagunit(path, nmem, file, lineno); if (!tagunit) { - yaz_log (LOG_WARN, "%s%d: Bad tag unit at %s", + yaz_log (YLOG_WARN, "%s%d: Bad tag unit at %s", file, lineno, path); break; } @@ -341,8 +352,17 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) read_variant(argc-3, argv+3, nmem, file, lineno); } else - yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'", + yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno, argv[0]); fclose (f); return res; } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +