Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site osu-dbs.UUCP Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!ihnp4!cbosgd!osu-dbs!paul From: paul@osu-dbs.UUCP (Paul Placeway) Newsgroups: net.sources Subject: tcsh with a command line editor (5 of 5) Message-ID: <554@osu-dbs.UUCP> Date: Fri, 13-Apr-84 14:31:03 EST Article-I.D.: osu-dbs.554 Posted: Fri Apr 13 14:31:03 1984 Date-Received: Tue, 17-Apr-84 06:44:23 EST Organization: Ohio State U., CIS Dept., Columbus Lines: 437 . The following code is my changes to Ken Greer's tcsh. I have added a visual mini-editor to the shell, and cleaned up the expansion routines some what. note that this is the 4.1 version. When we get 4.2 up I'll repost the new changes. Please send any changes back to me so that I can update our version. Note: this is part 5 of 5, you need all of the parts to make tcsh. Paul W. Placeway The Ohio State University IRCC (UUCP: cbosgd!osu-dbs!paul) (CSNet: paul@ohio-state) ================ cut here ================ : This is a shar archive. Extract with sh, not csh. echo x - dir.h cat > dir.h << '!Funky!Stuff!' /* Copyright (c) 1982 Regents of the University of California */ /* @(#)ndir.h 4.4 3/30/82 */ /* * This sets the "page size" for directories. * Requirements are DEV_BSIZE <= DIRBLKSIZ <= MINBSIZE with * DIRBLKSIZ a power of two. * Dennis Ritchie feels that directory pages should be atomic * operations to the disk, so we use DEV_BSIZE. */ #define DIRBLKSIZ 512 /* * This limits the directory name length. Its main constraint * is that it appears twice in the user structure. (u. area) */ #define MAXNAMLEN 255 struct direct { u_long d_ino; short d_reclen; short d_namlen; char d_name[MAXNAMLEN + 1]; /* typically shorter */ }; struct _dirdesc { int dd_fd; long dd_loc; long dd_size; char dd_buf[DIRBLKSIZ]; }; /* * useful macros. */ #undef DIRSIZ #define DIRSIZ(dp) \ ((sizeof(struct direct) - MAXNAMLEN + (dp)->d_namlen + sizeof(ino_t) - 1) &\ ~(sizeof(ino_t) - 1)) typedef struct _dirdesc DIR; #ifndef NULL #define NULL 0 #endif /* * functions defined on directories */ extern DIR *opendir(); extern struct direct *readdir(); extern long telldir(); extern void seekdir(); #define rewinddir(dirp) seekdir((dirp), 0) extern void closedir(); !Funky!Stuff! echo x - dir14.c cat > dir14.c << '!Funky!Stuff!' /* Copyright (c) 1982 Regents of the University of California */ /* @(#)opendir.c 4.2.1.1 7/1/82 - HPL */ #include #include #include /* * open a directory. */ DIR * opendir(name) char *name; { register DIR *dirp; register int fd; struct stat sbuf; if ((fd = open(name, 0)) == -1) return NULL; fstat(fd, &sbuf); if (((sbuf.st_mode & S_IFDIR) == 0) || ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)) { close (fd); return NULL; } dirp->dd_fd = fd; dirp->dd_loc = 0; return dirp; } /* Copyright (c) 1982 Regents of the University of California */ /* @(#)closedir.c 4.2 3/10/82 */ /* * close a directory. */ void closedir(dirp) register DIR *dirp; { close(dirp->dd_fd); dirp->dd_fd = -1; dirp->dd_loc = 0; free(dirp); } /* Copyright (c) 1982 Regents of the University of California */ /* @(#)readdir.c 4.2 3/12/82 */ /* * read an old stlye directory entry and present it as a new one */ #define ODIRSIZ 14 struct olddirect { ino_t d_ino; char d_name[ODIRSIZ]; }; /* * get next entry in a directory. */ struct direct * readdir(dirp) register DIR *dirp; { register struct olddirect *dp; static struct direct dir; for (;;) { if (dirp->dd_loc == 0) { dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ); if (dirp->dd_size <= 0) return NULL; } if (dirp->dd_loc >= dirp->dd_size) { dirp->dd_loc = 0; continue; } dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc); dirp->dd_loc += sizeof(struct olddirect); if (dp->d_ino == 0) continue; dir.d_ino = dp->d_ino; strncpy(dir.d_name, dp->d_name, ODIRSIZ); dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */ dir.d_namlen = strlen(dir.d_name); dir.d_reclen = DIRSIZ(&dir); return (&dir); } } !Funky!Stuff! echo x - sh.nfunc.c cat > sh.nfunc.c << '!Funky!Stuff!' /* static char *sccsid = "@(#)sh.nfunc.c 1.0 84/01/31"; */ #include "sh.h" #include "inputl.h" /* for the function names */ #include "tw.h" #include static char *seech (); /* * Tops-C shell */ /* do a bind command -- 'bind FUNC key' */ /* list structure... */ struct kfuncs { char *name; int ifunc; /* inputl function name */ int tfunc; /* twenex function name */ } fnames[] = { "auto_insert", AUTO_INSERT, NO_OP, "AUTO_INSERT", AUTO_INSERT, NO_OP, "backward_char", BACKWARD_CHAR, NO_OP, "BACKWARD_CHAR", BACKWARD_CHAR, NO_OP, "backward_word", BACKWARD_WORD, NO_OP, "BACKWARD_WORD", BACKWARD_WORD, NO_OP, "beginning_of_line", BEGINNING_OF_LINE, NO_OP, "BEGINNING_OF_LINE", BEGINNING_OF_LINE, NO_OP, "clear_screen", CLEAR_SCREEN, NO_OP, "CLEAR_SCREEN", CLEAR_SCREEN, NO_OP, "complete", SEND_LINE, COMPLETE, "COMPLETE", SEND_LINE, COMPLETE, "delete_char_backward", DELETE_CHAR_BACKWARD, NO_OP, "DELETE_CHAR_BACKWARD", DELETE_CHAR_BACKWARD, NO_OP, "delete_char_forward", DELETE_CHAR_FORWARD, NO_OP, "DELETE_CHAR_FORWARD", DELETE_CHAR_FORWARD, NO_OP, "delete_word_backward", DELETE_WORD_BACKWARD, NO_OP, "DELETE_WORD_BACKWARD", DELETE_WORD_BACKWARD, NO_OP, "delete_word_forward", DELETE_WORD_FORWARD, NO_OP, "DELETE_WORD_FORWARD", DELETE_WORD_FORWARD, NO_OP, "down_history", SEND_LINE, DOWN_HIST, "DOWN_HISTORY", SEND_LINE, DOWN_HIST, "end_of_line", END_OF_LINE, NO_OP, "END_OF_LINE", END_OF_LINE, NO_OP, "send_eof", SEND_EOF, NO_OP, "SEND_EOF", SEND_EOF, NO_OP, "forward_char", FORWARD_CHAR, NO_OP, "FORWARD_CHAR", FORWARD_CHAR, NO_OP, "forward_word", FORWARD_WORD, NO_OP, "FORWARD_WORD", FORWARD_WORD, NO_OP, "kill_to_beginning", KILL_TO_BEGINNING, NO_OP, "KILL_TO_BEGINNING", KILL_TO_BEGINNING, NO_OP, "kill_to_end", KILL_TO_END, NO_OP, "KILL_TO_END", KILL_TO_END, NO_OP, "nl_send_line", NL_SEND_LINE, NO_OP, "NL_SEND_LINE", NL_SEND_LINE, NO_OP, "quote_next", QUOTE_NEXT, NO_OP, "QUOTE_NEXT", QUOTE_NEXT, NO_OP, "redisplay", REDISPLAY, NO_OP, "REDISPLAY", REDISPLAY, NO_OP, "list_options", SEND_LINE, LIST_CHOICES, "LIST_OPTIONS", SEND_LINE, LIST_CHOICES, "send_line", SEND_LINE, ERROR, "SEND_LINE", SEND_LINE, ERROR, "start_over", START_OVER, NO_OP, "START_OVER", START_OVER, NO_OP, "transpose_chars", TRANSPOSE_CHARS, NO_OP, "TRANSPOSE_CHARS", TRANSPOSE_CHARS, NO_OP, "up_history", SEND_LINE, UP_HIST, "UP_HISTORY", SEND_LINE, UP_HIST, "yank_killbuffer", YANK_KILLBUFFER, NO_OP, "YANK_KILLBUFFER", YANK_KILLBUFFER, NO_OP, "yank_last_input", YANK_LAST_INPUT, NO_OP, "YANK_LAST_INPUT", YANK_LAST_INPUT, NO_OP, "tty_dsusp", TTY_DSUSP, NO_OP, "TTY_DSUSP", TTY_DSUSP, NO_OP, "tty_flush_output", TTY_FLUSH_OUTPUT, NO_OP, "TTY_FLUSH_OUTPUT", TTY_FLUSH_OUTPUT, NO_OP, "tty_sigintr", TTY_SIGINTR, NO_OP, "TTY_SIGINTR", TTY_SIGINTR, NO_OP, "tty_sigquit", TTY_SIGQUIT, NO_OP, "TTY_SIGQUIT", TTY_SIGQUIT, NO_OP, "tty_sigtsusp", TTY_SIGTSUSP, NO_OP, "TTY_SIGTSUSP", TTY_SIGTSUSP, NO_OP, "tty_start_output", TTY_START_OUTPUT, NO_OP, "TTY_START_OUTPUT", TTY_START_OUTPUT, NO_OP, "tty_stop_output", TTY_STOP_OUTPUT, NO_OP, "TTY_STOP_OUTPUT", TTY_STOP_OUTPUT, NO_OP, "helpme", SEND_LINE, HELPME, "HELPME", SEND_LINE, HELPME, 0, 0, 0 }; int dobind(v) register char **v; { register char c; register struct kfuncs *fp; register int i; register int isfound; /* assume at this point that i'm given 2 or 3 args - 'bind', the f-name, and the key; or 'bind' key to print the func for that key. */ if (v[1] && v[2]) { for (fp = fnames; fp->name; fp++) { if (strcmp(v[1], fp->name) == 0) { if ((v[2][0] == '^') && v[2][1]) { c = (v[2][1] == '?') ? 0177 : v[2][1] & 037; } else { c = v[2][0]; } tw_bind_to_key (fp->tfunc, c); /* bind for twenex()... */ ilbindtokey (fp->ifunc, c); /* actually bind the thing */ ilreset_tty (); return; } } bferr ("I don't know that function."); } else if (v[1]) { if (strcmp (v[1], "defaults") == 0) { /* reset keys to default */ for (i=0; i<128; i++) { /* assign all the keys */ ilbindtokey (AUTO_INSERT, i); tw_bind_to_key (NO_OP, i); } ilbindtokey (SEND_LINE, 000); tw_bind_to_key (HELPME, 000); ilbindtokey (BEGINNING_OF_LINE, 001); ilbindtokey (BACKWARD_CHAR, 002); ilbindtokey (TTY_SIGINTR, 003); ilbindtokey (DELETE_CHAR_FORWARD, 004); ilbindtokey (END_OF_LINE, 005); ilbindtokey (FORWARD_CHAR, 006); ilbindtokey (START_OVER, 007); ilbindtokey (KILL_TO_END, 013); ilbindtokey (SEND_EOF, 037); ilbindtokey (YANK_LAST_INPUT, 010); ilbindtokey (SEND_LINE, 077); tw_bind_to_key (LIST_CHOICES, 077); ilbindtokey (SEND_LINE, 033); tw_bind_to_key (COMPLETE, 033); ilbindtokey (NL_SEND_LINE, 012); ilbindtokey (NL_SEND_LINE, 015); ilbindtokey (FORWARD_WORD, 016); tw_bind_to_key (NO_OP, 016); ilbindtokey (TTY_FLUSH_OUTPUT, 017); ilbindtokey (BACKWARD_WORD, 020); tw_bind_to_key (NO_OP, 020); ilbindtokey (TTY_START_OUTPUT, 021); ilbindtokey (REDISPLAY, 022); ilbindtokey (TTY_STOP_OUTPUT, 023); ilbindtokey (TRANSPOSE_CHARS, 024); ilbindtokey (KILL_TO_BEGINNING, 025); ilbindtokey (QUOTE_NEXT, 026); ilbindtokey (CLEAR_SCREEN, 014); ilbindtokey (DELETE_WORD_BACKWARD, 027); ilbindtokey (DELETE_WORD_FORWARD, 030); ilbindtokey (YANK_KILLBUFFER, 031); ilbindtokey (TTY_SIGTSUSP, 032); ilbindtokey (TTY_SIGQUIT, 034); ilbindtokey (TTY_DSUSP, 035); ilbindtokey (DELETE_CHAR_BACKWARD, 0177); ilreset_tty(); } else { /* want to know what this key does */ if ((v[1][0] == '^') && v[1][1]) { c = (v[1][1] == '?') ? 0177 : v[1][1] & 037; } else { c = v[1][0]; } for (fp = fnames; fp->name; fp++) { if ((fp->ifunc == ilgetbinding(c)) && (fp->tfunc == tw_get_binding (c))) { printf ("%s is bound to %s.\n", seech(c), fp->name); return; } } printf ("%s isn't bound to anything.\n", seech(c)); printf ("inputl: %d, twenex: %d\n", ilgetbinding (c), tw_get_binding (c)); } } else { /* list all the bindings */ for (i = 0; i < 128; i++) { isfound = 0; for (fp = fnames; fp->name; fp++) { if ((fp->ifunc == ilgetbinding(i)) && (fp->tfunc == tw_get_binding (i))) { printf ("%s is bound to %s.\n", seech(i), fp->name); isfound++; break; } } if (isfound) continue; printf ("%s isn't bound to anything.\n", seech(i)); } } } char * sprlex(buf, sp0) struct wordent *sp0; char *buf; { register struct wordent *sp = sp0->next; buf[0] = '\0'; for (;;) { strcat(buf, sp->word); sp = sp->next; if (sp == sp0) break; strcat(buf, " "); } return(buf); } donhist(av) char **av; { char buf[512]; struct Hist *hp; for (hp = Histlist.Hnext; hp != 0; hp = hp->Hnext) { sprlex (buf, &hp->Hlex); printf ("hist: %s\n", buf); } } static char * seech (c) /* 'c' -> "c", '^C' -> "^" + "C" */ register char c; { static char tmp[3]; if (c >= ' ') { tmp[0] = c; tmp[1] = '\0'; return (tmp); } else { tmp[0] = '^'; if (c == '\177') { tmp[1] = '?'; } else { tmp[1] = '@' + (c & 037); } tmp[2] = '\0'; return (tmp); } } !Funky!Stuff!