/* This tab completion is simply to workaround the fact that we throw tecla * off by trying to complete filenames in our "file=" rx/tx command parameters. * * In the future, we could additional command/parameter completions here... */ int tab_completion(WordCompletion *cpl, void *data, const char *line, int w_end) { static const char file_param[] = "file="; char *param = strstr(line, file_param); int ret; if (param != NULL) { /* [0] up to "file=" */ const size_t param_off = param - line; /* Length of everything after "file=" */ const size_t remainder = strlen(param) - strlen(file_param); char *modified_line; modified_line = calloc(strlen(line) - strlen(file_param) + 1, 1); if (modified_line != NULL) { strncpy(modified_line, line, param_off); strncpy(modified_line + strlen(modified_line), line + param_off + strlen(file_param), remainder); ret = cpl_file_completions(cpl, data, modified_line, strlen(modified_line)); free(modified_line); return ret; } else { cpl_record_error(cpl, "calloc() failure"); return 1; } } return cpl_file_completions(cpl, data, line, w_end); }
/*....................................................................... * This completion callback searches for completions of executables in * the user's path when invoked on a word at the start of the path, and * performs normal filename completion elsewhere. */ static CPL_MATCH_FN(demo_cpl_fn) { /* * Get the resource object that was passed to gl_customize_completion(). */ DemoRes *res = (DemoRes *) data; /* * Find the start of the filename prefix to be completed, searching * backwards for the first unescaped space, or the start of the line. */ char *start = start_of_path(line, word_end); /* * Skip spaces preceding the start of the prefix. */ while(start > line && isspace((int)(unsigned char) start[-1])) start--; /* * If the filename prefix is at the start of the line, attempt * to complete the filename as a command in the path. Otherwise * perform normal filename completion. */ return (start == line) ? pca_path_completions(cpl, res->ppc, line, word_end) : cpl_file_completions(cpl, NULL, line, word_end); }
static CPL_MATCH_FN(complete_single_xml_file_arg) { const char *arg1 = data; int arg1end_i, ret; CplFileConf *cfc; arg1end_i = arg1 + strcspn(arg1, whitespace) - line; if (arg1end_i < word_end) return (0); cfc = new_CplFileConf(); if (cfc == NULL) { cpl_record_error(cpl, "Out of memory."); return (1); } cfc_set_check_fn(cfc, check_xml, NULL); ret = cpl_file_completions(cpl, cfc, line, word_end); (void) del_CplFileConf(cfc); return (ret); }