Let all .asn depend on yaz-asncomp
[yaz-moved-to-github.git] / src / initopt.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: initopt.c,v 1.6 2005-06-25 15:46:04 adam Exp $
6  */
7
8 /**
9  * \file initopt.c
10  * \brief Implements Z39.50 Init Options Utility
11  */
12
13 #if HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <yaz/proto.h>
18
19 static struct {
20     char *name;
21     int opt;
22 } opt_array[] = {
23     {"search", Z_Options_search},
24     {"present", Z_Options_present},
25     {"delSet", Z_Options_delSet},
26     {"resourceReport", Z_Options_resourceReport},
27     {"triggerResourceCtrl", Z_Options_triggerResourceCtrl},
28     {"resourceCtrl", Z_Options_resourceCtrl},
29     {"accessCtrl", Z_Options_accessCtrl},
30     {"scan", Z_Options_scan},
31     {"sort", Z_Options_sort},
32     {"extendedServices", Z_Options_extendedServices},
33     {"level_1Segmentation", Z_Options_level_1Segmentation},
34     {"level_2Segmentation", Z_Options_level_2Segmentation},
35     {"concurrentOperations", Z_Options_concurrentOperations},
36     {"namedResultSets", Z_Options_namedResultSets},
37     {"encapsulation", Z_Options_encapsulation},
38     {"resultCount", Z_Options_resultCount},
39     {"negotiationModel", Z_Options_negotiationModel},
40     {"duplicationDetection", Z_Options_duplicateDetection},
41     {"queryType104", Z_Options_queryType104},
42     {"pQESCorrection", Z_Options_pQESCorrection},
43     {"stringSchema", Z_Options_stringSchema},
44     {0, 0}
45 };
46
47 int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos)
48 {
49     const char *cp = opt_str;
50     
51     ODR_MASK_ZERO(opt);
52     while (*cp)
53     {
54         char this_opt[42];
55         int i, j;
56         if (*cp == ' ' || *cp == ',')
57         {
58             cp++;
59             continue;
60         }
61         for (i = 0; i < (sizeof(this_opt)-1) &&
62                  cp[i] && cp[i] != ' ' && cp[i] != ','; i++)
63             this_opt[i] = cp[i];
64         this_opt[i] = 0;
65         for (j = 0; opt_array[j].name; j++)
66         {
67             if (yaz_matchstr(this_opt, opt_array[j].name) == 0)
68             {
69                 ODR_MASK_SET(opt, opt_array[j].opt);
70                 break;
71             }
72         }
73         if (!opt_array[j].name)
74         {
75             if (error_pos)
76             {
77                 *error_pos = cp - opt_str;
78                 return -1;
79             }
80         }
81         cp += i;
82     }
83     return 0;
84 }
85
86 void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name,
87                                                     void *clientData),
88                          void *clientData)
89 {
90     int i;
91     for (i = 0; opt_array[i].name; i++)
92         if (ODR_MASK_GET(opt, opt_array[i].opt))
93             (*pr)(opt_array[i].name, clientData);
94 }
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * indent-tabs-mode: nil
99  * End:
100  * vim: shiftwidth=4 tabstop=8 expandtab
101  */
102