2 * Copyright (c) 2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.4 2002-02-24 12:24:40 adam Exp $
13 #include "tabcomplete.h"
15 /* *****************************************************************************
19 * *****************************************************************************/
21 char* complete_from_list(char* completions[], const char *text, int state)
27 for(; completions[idx]; ++ idx) {
28 if(!strncmp(completions[idx],text,strlen(text))) {
29 ++idx; /* skip this entry on the next run */
30 return (char*)strdup(completions[idx-1]);
37 /* *****************************************************************************
39 * code for getting a list of valid strings from the oid subsystem
41 * *****************************************************************************/
52 This is the call back function given to oid_trav... it updates the list of pointers into the oid
56 void oid_loader(struct oident* oid, void* data_)
58 oid_callback_t* data=(oid_callback_t*) data_;
61 if((oid->oclass == CLASS_GENERAL) || (oid->oclass == data->oclass)) {
62 if(data->index==data->max) {
63 data->values=(char**)realloc(data->values,((data->max+1)*2)*sizeof(char*));
64 data->max=(data->max+1)*2 - 1;
66 data->values[data->index]=oid->desc;
71 char** build_list_for_oclass(oid_class oclass) {
73 data.values = calloc(10,sizeof(char*));
78 oid_trav(oid_loader, &data);
80 data.values[data.index]=0;
84 /* *****************************************************************************
86 * the compleater functions
88 * *****************************************************************************/
90 char* complete_querytype(const char *text, int state)
92 char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl",0};
93 return complete_from_list(querytypes,text,state);
97 char* complete_format(const char* text, int state)
99 char** list=build_list_for_oclass(CLASS_RECSYN);
100 char* res=complete_from_list(list,text,state);
106 char* complete_schema(const char* text, int state)
108 char** list=build_list_for_oclass(CLASS_SCHEMA);
109 char* res=complete_from_list(list,text,state);
116 char* complete_attributeset(const char* text, int state)
118 char** list=build_list_for_oclass(CLASS_ATTSET);
119 char* res=complete_from_list(list,text,state);