2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.18 2007-04-12 13:52:57 adam Exp $
12 #include "tabcomplete.h"
13 #include <yaz/oid_db.h>
15 /* ***************************************************************************
19 * ***************************************************************************/
21 char *complete_from_list(const char** completions,
22 const char *text, int state)
24 #if HAVE_READLINE_READLINE_H
31 for(; completions[idx]; ++ idx) {
38 (completions[idx],text,strlen(text))) {
39 ++idx; /* skip this entry on the next run */
40 return (char*)strdup(completions[idx-1]);
48 /* ***************************************************************************
50 * code for getting a list of valid strings from the oid subsystem
52 * ***************************************************************************/
63 This is the call back function given to oid_trav... it updates the list
64 of pointers into the oid owned data
67 void oid_loader(const int *oid,
68 int oclass, const char *name, void* data_)
70 oid_callback_t* data=(oid_callback_t*) data_;
72 if ((oclass == CLASS_GENERAL) || (oclass == data->oclass))
74 if (data->index==data->max)
76 data->values=(const char**)
77 realloc(data->values,((data->max+1)*2)*sizeof(char*));
78 data->max=(data->max+1)*2 - 1;
80 data->values[data->index] = name;
85 const char** build_list_for_oclass(oid_class oclass)
88 data.values = (const char **) calloc(10,sizeof(char*));
93 yaz_oid_trav(yaz_oid_std(), oid_loader, &data);
95 data.values[data.index]=0;
99 /* ***************************************************************************
101 * the completer functions
103 * ***************************************************************************/
105 char* complete_querytype(const char *text, int state)
107 static const char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl","cql", 0};
108 return complete_from_list(querytypes,text,state);
111 char* complete_auto_reconnect(const char *text, int state)
113 static const char* querytypes[] = {"on","off",0};
114 return complete_from_list(querytypes,text,state);
118 char* complete_format(const char* text, int state)
120 const char** list = build_list_for_oclass(CLASS_RECSYN);
121 char* res=complete_from_list(list,text,state);
127 char* complete_schema(const char* text, int state)
129 const char** list = build_list_for_oclass(CLASS_SCHEMA);
130 char* res = complete_from_list(list,text,state);
137 char* complete_attributeset(const char* text, int state)
139 const char** list = build_list_for_oclass(CLASS_ATTSET);
140 char* res = complete_from_list(list,text,state);
150 * indent-tabs-mode: nil
152 * vim: shiftwidth=4 tabstop=8 expandtab