2 * Copyright (c) 2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.6 2002-07-12 13:42:20 adam Exp $
13 #include "tabcomplete.h"
15 extern char** curret_global_list;
17 /* *****************************************************************************
21 * *****************************************************************************/
23 char* complete_from_list(char* completions[], const char *text, int state)
27 if(!completions) return NULL;
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]);
47 /* *****************************************************************************
49 * code for getting a list of valid strings from the oid subsystem
51 * *****************************************************************************/
62 This is the call back function given to oid_trav... it updates the list of pointers into the oid
66 void oid_loader(struct oident* oid, void* data_)
68 oid_callback_t* data=(oid_callback_t*) data_;
71 if((oid->oclass == CLASS_GENERAL) || (oid->oclass == data->oclass)) {
72 if(data->index==data->max) {
73 data->values=(char**)realloc(data->values,((data->max+1)*2)*sizeof(char*));
74 data->max=(data->max+1)*2 - 1;
76 data->values[data->index]=oid->desc;
81 char** build_list_for_oclass(oid_class oclass) {
83 data.values = calloc(10,sizeof(char*));
88 oid_trav(oid_loader, &data);
90 data.values[data.index]=0;
94 /* *****************************************************************************
96 * the compleater functions
98 * *****************************************************************************/
100 char* complete_querytype(const char *text, int state)
102 char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl",0};
103 return complete_from_list(querytypes,text,state);
107 char* complete_format(const char* text, int state)
109 char** list=build_list_for_oclass(CLASS_RECSYN);
110 char* res=complete_from_list(list,text,state);
116 char* complete_schema(const char* text, int state)
118 char** list=build_list_for_oclass(CLASS_SCHEMA);
119 char* res=complete_from_list(list,text,state);
126 char* complete_attributeset(const char* text, int state)
128 char** list=build_list_for_oclass(CLASS_ATTSET);
129 char* res=complete_from_list(list,text,state);
136 char* default_completer(const char* text, int state)
138 return complete_from_list(curret_global_list,text,state);