From: Scott Schwartz <schwartz@groucho.cs.psu.edu>
To: rc@archone.tamu.edu
Subject: file completion
Date: Sun, 5 Apr 1992 03:55:49 -0500 [thread overview]
Message-ID: <92Apr5.045558edt.2581@groucho.cs.psu.edu> (raw)
In honor of daylight savings time, here's a quick kludge to do csh style
file completion in rc. Feeback solicited.
*** 1.1 1992/04/05 08:49:55
--- comp.c 1992/04/05 08:47:41
***************
*** 0 ****
--- 1,52 ----
+ #include "comp.h"
+ #include <sys/termios.h>
+
+ static int fdunread (int fd, char* buf, SIZE_T len);
+
+ /* read_with_completion -- if a line doesn't end with newline,
+ try and expand the last item to match things in the filesystem.
+ this function does it incorrectly, by looking for a whitespace
+ to delimit the final 'item'. we really should parse the expression
+ and do completion on the last item computed in that way, and taking
+ error recovery into account. Sanjeev is writing his dissertation on
+ an incremental parser --- ask him how to do it. */
+
+ extern int read_with_completion (int fd, char* buf, SIZE_T len) {
+ int r, n, i;
+ List* list;
+ char* meta;
+ char* p;
+
+ while (1) {
+ r = rc_read (fd, buf, len);
+ if (r <= 0 || buf[r-1] == '\n')
+ return r;
+ else {
+ buf[r] = '*'; /* XXX - caller has to make sure buf is big enough */
+ buf[r+1] = 0;
+ p = strrchr(buf, ' ');
+ if (p == 0) p = buf; else ++p;
+ n = r - (p-buf);
+ meta = ealloc(n+2);
+ clear(meta, n+2);
+ meta[n] = 1;
+ list = glob(word(p, meta)); /* XXX - what to return on failure? */
+ fprint (1, " # (%L)\n", list, " ");
+ efree(meta);
+ fdunread (fd, buf, r);
+ }
+ }
+ /* NOTREACHED */
+ }
+
+ static int fdunread (int fd, char* buf, SIZE_T len) {
+ int r;
+ while (len--) {
+ r = ioctl (fd, TIOCSTI, buf++);
+ if (r < 0) {
+ uerror("ioctl/TIOCSTI");
+ return r;
+ }
+ }
+ return 0;
+ }
*** 1.1 1992/04/04 20:14:03
--- input.c 1992/04/04 20:16:51
***************
*** 111,117 ****
--- 111,121 ----
} else
#endif
{
+ #ifdef COMPLETION
+ long /*ssize_t*/ r = read_with_completion(istack->fd, inbuf + 2, BUFSIZE);
+ #else
long /*ssize_t*/ r = rc_read(istack->fd, inbuf + 2, BUFSIZE);
+ #endif
if (r < 0) {
if (errno == EINTR)
continue; /* Suppose it was interrupted by a signal */
next reply other threads:[~1992-04-05 8:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-04-05 8:55 Scott Schwartz [this message]
1992-04-05 10:09 ` John Mackin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92Apr5.045558edt.2581@groucho.cs.psu.edu \
--to=schwartz@groucho.cs.psu.edu \
--cc=rc@archone.tamu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).