2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.13 2006-05-07 19:37:23 adam Exp $
13 #include "tabcomplete.h"
15 #if HAVE_READLINE_READLINE_H
16 extern char** curret_global_list;
18 /* ***************************************************************************
22 * ***************************************************************************/
24 char* complete_from_list(char* completions[], const char *text, int state)
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]);
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(struct oident* oid, void* data_)
69 oid_callback_t* data=(oid_callback_t*) data_;
72 if((oid->oclass == CLASS_GENERAL) || (oid->oclass == data->oclass)) {
73 if(data->index==data->max) {
74 data->values=(char**)realloc(data->values,((data->max+1)*2)*sizeof(char*));
75 data->max=(data->max+1)*2 - 1;
77 data->values[data->index]=oid->desc;
82 char** build_list_for_oclass(oid_class oclass) {
84 data.values = (char **) calloc(10,sizeof(char*));
89 oid_trav(oid_loader, &data);
91 data.values[data.index]=0;
95 /* ***************************************************************************
97 * the completer functions
99 * ***************************************************************************/
101 char* complete_querytype(const char *text, int state)
103 char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl","cql", 0};
104 return complete_from_list(querytypes,text,state);
107 char* complete_auto_reconnect(const char *text, int state)
109 char* querytypes[] = {"on","off",0};
110 return complete_from_list(querytypes,text,state);
114 char* complete_format(const char* text, int state)
116 char** list=build_list_for_oclass(CLASS_RECSYN);
117 char* res=complete_from_list(list,text,state);
123 char* complete_schema(const char* text, int state)
125 char** list=build_list_for_oclass(CLASS_SCHEMA);
126 char* res=complete_from_list(list,text,state);
133 char* complete_attributeset(const char* text, int state)
135 char** list=build_list_for_oclass(CLASS_ATTSET);
136 char* res=complete_from_list(list,text,state);
143 char* default_completer(const char* text, int state)
145 return complete_from_list(curret_global_list,text,state);
152 * indent-tabs-mode: nil
154 * vim: shiftwidth=4 tabstop=8 expandtab