2 * Copyright (c) 2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: tabcomplete.c,v 1.2 2002-01-30 14:51:45 adam Exp $
12 #include "tabcomplete.h"
14 /* *****************************************************************************
18 * *****************************************************************************/
20 char* complete_from_list(char* completions[], const char *text, int state)
26 for(; completions[idx]; ++ idx) {
27 if(!strncmp(completions[idx],text,strlen(text))) {
28 ++idx; /* skip this entry on the next run */
29 return (char*)strdup(completions[idx-1]);
36 /* *****************************************************************************
38 * code for getting a list of valid strings from the oid subsystem
40 * *****************************************************************************/
51 This is the call back function given to oid_trav... it updates the list of pointers into the oid
55 void oid_loader(struct oident* oid, void* data_)
57 oid_callback_t* data=(oid_callback_t*) data_;
59 //fprintf(stderr,"ja7: called with %d: %s\n",oid->oclass,oid->desc);
60 if((oid->oclass == CLASS_GENERAL) || (oid->oclass == data->oclass)) {
61 if(data->index==data->max) {
62 data->values=(char**)realloc(data->values,((data->max+1)*2)*sizeof(char*));
63 data->max=(data->max+1)*2 - 1;
65 data->values[data->index]=oid->desc;
70 char** build_list_for_oclass(oid_class oclass) {
72 data.values = calloc(10,sizeof(char*));
77 oid_trav(oid_loader, &data);
79 data.values[data.index]=0;
83 /* *****************************************************************************
85 * the compleater functions
87 * *****************************************************************************/
89 char* complete_querytype(const char *text, int state)
91 char* querytypes[] = {"ccl2rpn","prefix","cclrpn","ccl",0};
92 return complete_from_list(querytypes,text,state);
96 char* complete_format(const char* text, int state)
98 char** list=build_list_for_oclass(CLASS_RECSYN);
99 char* res=complete_from_list(list,text,state);
105 char* complete_schema(const char* text, int state)
107 char** list=build_list_for_oclass(CLASS_SCHEMA);
108 char* res=complete_from_list(list,text,state);
115 char* complete_attributeset(const char* text, int state)
117 char** list=build_list_for_oclass(CLASS_ATTSET);
118 char* res=complete_from_list(list,text,state);