1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 Index Data
3 * See the file LICENSE for details.
13 #include "tabcomplete.h"
14 #include <yaz/oid_db.h>
16 /* ***************************************************************************
20 * ***************************************************************************/
22 char *complete_from_list(const char** completions,
23 const char *text, int state)
25 #if HAVE_READLINE_READLINE_H
32 for(; completions[idx]; ++ idx) {
39 (completions[idx],text,strlen(text))) {
40 ++idx; /* skip this entry on the next run */
41 return (char*)strdup(completions[idx-1]);
49 /* ***************************************************************************
51 * code for getting a list of valid strings from the oid subsystem
53 * ***************************************************************************/
64 This is the call back function given to oid_trav... it updates the list
65 of pointers into the oid owned data
68 void oid_loader(const Odr_oid *oid,
69 oid_class oclass, const char *name, void* data_)
71 oid_callback_t* data=(oid_callback_t*) data_;
73 if ((oclass == CLASS_GENERAL) || (oclass == data->oclass))
75 if (data->index==data->max)
77 data->values=(const char**)
78 realloc(data->values,((data->max+1)*2)*sizeof(char*));
79 data->max=(data->max+1)*2 - 1;
81 data->values[data->index] = name;
86 const char** build_list_for_oclass(oid_class oclass)
89 data.values = (const char **) calloc(10,sizeof(char*));
94 yaz_oid_trav(yaz_oid_std(), oid_loader, &data);
96 data.values[data.index]=0;
100 /* ***************************************************************************
102 * the completer functions
104 * ***************************************************************************/
106 char* complete_querytype(const char *text, int state)
108 static const char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl","cql", "cql2rpn", 0};
109 return complete_from_list(querytypes,text,state);
112 char* complete_auto_reconnect(const char *text, int state)
114 static const char* querytypes[] = {"on","off",0};
115 return complete_from_list(querytypes,text,state);
119 char* complete_format(const char* text, int state)
121 const char** list = build_list_for_oclass(CLASS_RECSYN);
122 char* res=complete_from_list(list,text,state);
128 char* complete_schema(const char* text, int state)
130 const char** list = build_list_for_oclass(CLASS_SCHEMA);
131 char* res = complete_from_list(list,text,state);
138 char* complete_attributeset(const char* text, int state)
140 const char** list = build_list_for_oclass(CLASS_ATTSET);
141 char* res = complete_from_list(list,text,state);
151 * c-file-style: "Stroustrup"
152 * indent-tabs-mode: nil
154 * vim: shiftwidth=4 tabstop=8 expandtab