summaryrefslogtreecommitdiff
path: root/usr.bin/mg/echo.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-05-23 16:25:25 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-05-23 16:25:25 +0000
commitaca90a638214fdc937cb8a15caf9e7bed409886d (patch)
treeaf94481065d32735d3f45c0f7d134b7507df455b /usr.bin/mg/echo.c
parentb8b21e8cd7ce707eec67a2818ddcd77546630766 (diff)
complt already has code to finish the completion from a list.
No point in duplicating that code in complete_function.
Diffstat (limited to 'usr.bin/mg/echo.c')
-rw-r--r--usr.bin/mg/echo.c120
1 files changed, 49 insertions, 71 deletions
diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c
index dad76f4b134..d5a2b70c07c 100644
--- a/usr.bin/mg/echo.c
+++ b/usr.bin/mg/echo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: echo.c,v 1.5 2001/05/03 12:57:22 art Exp $ */
+/* $OpenBSD: echo.c,v 1.6 2001/05/23 16:25:24 art Exp $ */
/*
* Echo line reading and writing.
@@ -356,80 +356,58 @@ complt(flags, c, buf, cpos)
if ((flags & EFFUNC) != 0) {
buf[cpos] = '\0';
- i = complete_function(buf, c);
- if (i > 0) {
- eputs(&buf[cpos]);
- ttflush();
- return i;
- }
- switch (i) {
- case -3:
- msg = " [Ambiguous]";
- break;
- case -2:
- i = 0;
- msg = " [No match]";
- break;
- case -1:
- case 0:
- return i;
- default:
- msg = " [Internal error]";
- break;
- }
- } else {
- if ((flags & EFBUF) != 0)
- lh = &(bheadp->b_list);
- else if ((flags & EFFILE) != 0) {
- buf[cpos] = '\0';
- wholelist = lh = make_file_list(buf);
- } else
- panic("broken complt call: flags");
+ wholelist = lh = complete_function_list(buf, c);
+ } else if ((flags & EFBUF) != 0)
+ lh = &(bheadp->b_list);
+ else if ((flags & EFFILE) != 0) {
+ buf[cpos] = '\0';
+ wholelist = lh = make_file_list(buf);
+ } else
+ panic("broken complt call: flags");
- if (c == ' ')
- wflag = TRUE;
- else if (c != '\t' && c != CCHR('M'))
- panic("broken complt call: c");
-
- nhits = 0;
- nxtra = HUGE;
-
- for (; lh != NULL; lh = lh->l_next) {
- if (memcmp(buf, lh->l_name, cpos) != 0)
- continue;
- if (nhits == 0)
- lh2 = lh;
- ++nhits;
- if (lh->l_name[cpos] == '\0')
- nxtra = -1;
- else {
- bxtra = getxtra(lh, lh2, cpos, wflag);
- if (bxtra < nxtra)
- nxtra = bxtra;
- lh2 = lh;
- }
- }
+ if (c == ' ')
+ wflag = TRUE;
+ else if (c != '\t' && c != CCHR('M'))
+ panic("broken complt call: c");
+
+ nhits = 0;
+ nxtra = HUGE;
+
+ for (; lh != NULL; lh = lh->l_next) {
+ if (memcmp(buf, lh->l_name, cpos) != 0)
+ continue;
if (nhits == 0)
- msg = " [No match]";
- else if (nhits > 1 && nxtra == 0)
- msg = " [Ambiguous]";
+ lh2 = lh;
+ ++nhits;
+ if (lh->l_name[cpos] == '\0')
+ nxtra = -1;
else {
- /*
- * Being lazy - ought to check length, but all things
- * autocompleted have known types/lengths.
- */
- if (nxtra < 0 && nhits > 1 && c == ' ')
- nxtra = 1;
- for (i = 0; i < nxtra; ++i) {
- buf[cpos] = lh2->l_name[cpos];
- eputc(buf[cpos++]);
- }
- ttflush();
- free_file_list(wholelist);
- if (nxtra < 0 && c != CCHR('M'))
- return 0;
- return nxtra;
+ bxtra = getxtra(lh, lh2, cpos, wflag);
+ if (bxtra < nxtra)
+ nxtra = bxtra;
+ lh2 = lh;
+ }
+ }
+ if (nhits == 0)
+ msg = " [No match]";
+ else if (nhits > 1 && nxtra == 0)
+ msg = " [Ambiguous]";
+ else {
+ /*
+ * Being lazy - ought to check length, but all things
+ * autocompleted have known types/lengths.
+ */
+ if (nxtra < 0 && nhits > 1 && c == ' ')
+ nxtra = 1;
+ for (i = 0; i < nxtra; ++i) {
+ buf[cpos] = lh2->l_name[cpos];
+ eputc(buf[cpos++]);
}
+ ttflush();
+ free_file_list(wholelist);
+ if (nxtra < 0 && c != CCHR('M'))
+ return 0;
+ return nxtra;
}
/*