+void
+pcomp_set_readline_variables (flags, nval)
+ int flags, nval;
+{
+ /* If the user specified that the compspec returns filenames, make
+ sure that readline knows it. */
+ if (flags & COPT_FILENAMES)
+ rl_filename_completion_desired = nval;
+ /* If the user doesn't want a space appended, tell readline. */
+ if (flags & COPT_NOSPACE)
+ rl_completion_suppress_append = nval;
+ /* The value here is inverted, since the default is on and the `noquote'
+ option is supposed to turn it off */
+ if (flags & COPT_NOQUOTE)
+ rl_filename_quoting_desired = 1 - nval;
+}
+
+/* Set or unset FLAGS in the options word of the current compspec.
+ SET_OR_UNSET is 1 for setting, 0 for unsetting. */
+void
+pcomp_set_compspec_options (cs, flags, set_or_unset)
+ COMPSPEC *cs;
+ int flags, set_or_unset;
+{
+ if (cs == 0 && ((cs = pcomp_curcs) == 0))
+ return;
+ if (set_or_unset)
+ cs->options |= flags;
+ else
+ cs->options &= ~flags;
+}
+
+static STRINGLIST *
+gen_progcomp_completions (ocmd, cmd, word, start, end, foundp, retryp, lastcs)
+ const char *ocmd;
+ const char *cmd;
+ const char *word;
+ int start, end;
+ int *foundp, *retryp;
+ COMPSPEC **lastcs;
+{
+ COMPSPEC *cs, *oldcs;
+ const char *oldcmd, *oldtxt;
+ STRINGLIST *ret;
+
+ cs = progcomp_search (ocmd);
+
+ if (cs == 0 || cs == *lastcs)
+ {
+#if 0
+ if (foundp)
+ *foundp = 0;
+#endif
+ return (NULL);
+ }
+
+ if (*lastcs)
+ compspec_dispose (*lastcs);
+ cs->refcount++; /* XXX */
+ *lastcs = cs;
+
+ cs = compspec_copy (cs);
+
+ oldcs = pcomp_curcs;
+ oldcmd = pcomp_curcmd;
+ oldtxt = pcomp_curtxt;
+
+ pcomp_curcs = cs;
+ pcomp_curcmd = cmd;
+ pcomp_curtxt = word;
+
+ ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
+
+ pcomp_curcs = oldcs;
+ pcomp_curcmd = oldcmd;
+ pcomp_curtxt = oldtxt;
+
+ /* We need to conditionally handle setting *retryp here */
+ if (retryp)
+ *retryp = foundp && (*foundp & PCOMP_RETRYFAIL);
+
+ if (foundp)
+ {
+ *foundp &= ~PCOMP_RETRYFAIL;
+ *foundp |= cs->options;
+ }
+
+ compspec_dispose (cs);
+ return ret;
+}
+