* file completion
@ 1992-04-05 8:55 Scott Schwartz
1992-04-05 10:09 ` John Mackin
0 siblings, 1 reply; 2+ messages in thread
From: Scott Schwartz @ 1992-04-05 8:55 UTC (permalink / raw)
To: rc
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 */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: file completion
1992-04-05 8:55 file completion Scott Schwartz
@ 1992-04-05 10:09 ` John Mackin
0 siblings, 0 replies; 2+ messages in thread
From: John Mackin @ 1992-04-05 10:09 UTC (permalink / raw)
To: The rc Mailing List
Scott writes:
In honor of daylight savings time, here's a quick kludge to do csh style
file completion in rc.
`In honor of daylight savings time'??
FILENAME COMPLETION!??!?!!?
This _must_ be a four-day-late April Fool's Day message.
OK,
John.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1992-04-05 10:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-04-05 8:55 file completion Scott Schwartz
1992-04-05 10:09 ` John Mackin
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).