1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
10 #include "tabcomplete.h"
11 #include <yaz/oid_db.h>
13 /* ***************************************************************************
17 * ***************************************************************************/
19 char *complete_from_list(const char** completions,
20 const char *text, int state)
22 #if HAVE_READLINE_READLINE_H
29 for(; completions[idx]; ++ idx) {
36 (completions[idx],text,strlen(text))) {
37 ++idx; /* skip this entry on the next run */
38 return (char*)strdup(completions[idx-1]);
46 /* ***************************************************************************
48 * code for getting a list of valid strings from the oid subsystem
50 * ***************************************************************************/
61 This is the call back function given to oid_trav... it updates the list
62 of pointers into the oid owned data
65 void oid_loader(const Odr_oid *oid,
66 oid_class oclass, const char *name, void* data_)
68 oid_callback_t* data=(oid_callback_t*) data_;
70 if ((oclass == CLASS_GENERAL) || (oclass == data->oclass))
72 if (data->index==data->max)
74 data->values=(const char**)
75 realloc(data->values,((data->max+1)*2)*sizeof(char*));
76 data->max=(data->max+1)*2 - 1;
78 data->values[data->index] = name;
83 const char** build_list_for_oclass(oid_class oclass)
86 data.values = (const char **) calloc(10,sizeof(char*));
91 yaz_oid_trav(yaz_oid_std(), oid_loader, &data);
93 data.values[data.index]=0;
97 /* ***************************************************************************
99 * the completer functions
101 * ***************************************************************************/
103 char* complete_querytype(const char *text, int state)
105 static const char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl","cql", 0};
106 return complete_from_list(querytypes,text,state);
109 char* complete_auto_reconnect(const char *text, int state)
111 static const char* querytypes[] = {"on","off",0};
112 return complete_from_list(querytypes,text,state);
116 char* complete_format(const char* text, int state)
118 const char** list = build_list_for_oclass(CLASS_RECSYN);
119 char* res=complete_from_list(list,text,state);
125 char* complete_schema(const char* text, int state)
127 const char** list = build_list_for_oclass(CLASS_SCHEMA);
128 char* res = complete_from_list(list,text,state);
135 char* complete_attributeset(const char* text, int state)
137 const char** list = build_list_for_oclass(CLASS_ATTSET);
138 char* res = complete_from_list(list,text,state);
148 * indent-tabs-mode: nil
150 * vim: shiftwidth=4 tabstop=8 expandtab