2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.15 2006-05-07 19:43:00 adam Exp $
13 #include "tabcomplete.h"
15 extern char** current_global_list;
17 /* ***************************************************************************
21 * ***************************************************************************/
23 char* complete_from_list(char* completions[], const char *text, int state)
25 #if HAVE_READLINE_READLINE_H
28 if(!completions) return NULL;
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(struct oident* oid, void* data_)
70 oid_callback_t* data=(oid_callback_t*) data_;
73 if((oid->oclass == CLASS_GENERAL) || (oid->oclass == data->oclass)) {
74 if(data->index==data->max) {
75 data->values=(char**)realloc(data->values,((data->max+1)*2)*sizeof(char*));
76 data->max=(data->max+1)*2 - 1;
78 data->values[data->index]=oid->desc;
83 char** build_list_for_oclass(oid_class oclass)
86 data.values = (char **) calloc(10,sizeof(char*));
91 oid_trav(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 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 char* querytypes[] = {"on","off",0};
112 return complete_from_list(querytypes,text,state);
116 char* complete_format(const char* text, int state)
118 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 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 char** list = build_list_for_oclass(CLASS_ATTSET);
138 char* res = complete_from_list(list,text,state);
145 char* default_completer(const char* text, int state)
147 return complete_from_list(current_global_list, text, state);
153 * indent-tabs-mode: nil
155 * vim: shiftwidth=4 tabstop=8 expandtab