Disabled the sending of a facet list (as Otherinformation) when (re)connecting
[yaz-moved-to-github.git] / client / tabcomplete.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <string.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "tabcomplete.h"
11 #include <yaz/oid_db.h>
12
13 /* ***************************************************************************
14  *
15  * generic completer 
16  * 
17  * ***************************************************************************/
18
19 char *complete_from_list(const char** completions,
20                          const char *text, int state)
21 {       
22 #if HAVE_READLINE_READLINE_H
23     static int idx;
24     
25     if (!completions) 
26         return NULL;
27     if (state==0) 
28         idx = 0;
29     for(; completions[idx]; ++ idx) {
30         if(!
31 #ifdef WIN32
32            _strnicmp
33 #else
34            strncasecmp
35 #endif              
36            (completions[idx],text,strlen(text))) {
37             ++idx; /* skip this entry on the next run */ 
38             return (char*)strdup(completions[idx-1]);
39         };
40     };
41 #endif
42     return NULL;
43 }
44
45
46 /* ***************************************************************************
47  * 
48  * code for getting a list of valid strings from the oid subsystem
49  * 
50  * ***************************************************************************/
51    
52
53 typedef struct {
54     int oclass;
55     const char** values;
56     size_t index;
57     size_t max;
58 } oid_callback_t;
59
60 /*!
61   This is the call back function given to oid_trav... it updates the list
62   of pointers into the oid owned data 
63 */
64
65 void oid_loader(const Odr_oid *oid,
66                 oid_class oclass, const char *name, void* data_)
67 {
68     oid_callback_t* data=(oid_callback_t*) data_;
69     
70     if ((oclass == CLASS_GENERAL) || (oclass == data->oclass))
71     {
72         if (data->index==data->max) 
73         {
74             data->values=(const char**)
75                 realloc(data->values,((data->max+1)*2)*sizeof(char*));
76             data->max=(data->max+1)*2 - 1;
77         }
78         data->values[data->index] = name;
79         ++data->index;          
80     }
81 }
82
83 const char** build_list_for_oclass(oid_class oclass)
84
85     oid_callback_t data;        
86     data.values = (const char **) calloc(10,sizeof(char*));
87     data.index = 0;
88     data.max = 9;
89     data.oclass = oclass;
90
91     yaz_oid_trav(yaz_oid_std(), oid_loader, &data);
92
93     data.values[data.index]=0;
94     return data.values;    
95 }
96
97 /* ***************************************************************************
98  * 
99  * the completer functions 
100  * 
101  * ***************************************************************************/
102
103 char* complete_querytype(const char *text, int state)
104 {
105     static const char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl","cql", "cql2rpn", 0};
106     return complete_from_list(querytypes,text,state);  
107 }
108
109 char* complete_auto_reconnect(const char *text, int state)
110 {
111     static const char* querytypes[] = {"on","off",0};
112     return complete_from_list(querytypes,text,state);  
113 }
114
115
116 char* complete_format(const char* text, int state)
117 {
118     const char** list = build_list_for_oclass(CLASS_RECSYN);
119     char* res=complete_from_list(list,text,state);  
120     
121     free(list); 
122     return res;
123 }
124
125 char* complete_schema(const char* text, int state)
126 {
127     const char** list = build_list_for_oclass(CLASS_SCHEMA);
128     char* res = complete_from_list(list,text,state);  
129     
130     free(list); 
131     return res;
132 }
133
134
135 char* complete_attributeset(const char* text, int state)
136 {
137     const char** list = build_list_for_oclass(CLASS_ATTSET);
138     char* res = complete_from_list(list,text,state);  
139     
140     free(list); 
141     return res;
142 }
143
144
145 /*
146  * Local variables:
147  * c-basic-offset: 4
148  * c-file-style: "Stroustrup"
149  * indent-tabs-mode: nil
150  * End:
151  * vim: shiftwidth=4 tabstop=8 expandtab
152  */
153