diff -rc --new-file pdksh-4.9_orig/ChangeLog pdksh-4.9/ChangeLog *** pdksh-4.9_orig/ChangeLog Sun Dec 5 21:47:41 1993 --- pdksh-4.9/ChangeLog Fri Dec 3 21:42:27 1993 *************** *** 1,3 **** --- 1,12 ---- + Fri Dec 3 21:39:47 1993 Piercarlo Grandi (pcg@aber.ac.uk) + + * polished 4.9 for linux; corrected a terrible, linux + specific performance bug that caused all streams to + become unbuffered; made emacs.c more understandable. + With 4.9 pdksh is twice as fast and one third the size + of bash 1.13, and has most of the relevant functionality. + To me it is a drop-in replacement. + Sat May 8 15:55:24 1993 Simon J. Gerraty (sjg@zen.void.oz.au) * Ported to 386bsd - sh directory only, stc/* not needed. diff -rc --new-file pdksh-4.9_orig/sh/c_sh.c pdksh-4.9/sh/c_sh.c *** pdksh-4.9_orig/sh/c_sh.c Sun Dec 5 21:47:46 1993 --- pdksh-4.9/sh/c_sh.c Thu Dec 2 00:38:44 1993 *************** *** 12,17 **** --- 12,21 ---- #include #include /* getcwd */ #include + #ifdef __linux__ + #include + #endif + #include "sh.h" static char * clocktos ARGS((clock_t t)); diff -rc --new-file pdksh-4.9_orig/sh/do_ulimit.c pdksh-4.9/sh/do_ulimit.c *** pdksh-4.9_orig/sh/do_ulimit.c Sun Dec 5 21:48:11 1993 --- pdksh-4.9/sh/do_ulimit.c Thu Dec 2 00:40:12 1993 *************** *** 16,22 **** static char *RCSid = "$Id: do_ulimit.c,v 1.4 93/05/05 21:16:21 sjg Exp $"; #endif ! #ifdef _BSDI #define _BSD 1 #endif --- 16,22 ---- static char *RCSid = "$Id: do_ulimit.c,v 1.4 93/05/05 21:16:21 sjg Exp $"; #endif ! #if defined _BSDI || defined __linux__ #define _BSD 1 #endif diff -rc --new-file pdksh-4.9_orig/sh/emacs.c pdksh-4.9/sh/emacs.c *** pdksh-4.9_orig/sh/emacs.c Sun Dec 5 21:47:48 1993 --- pdksh-4.9/sh/emacs.c Sat Dec 4 12:06:19 1993 *************** *** 159,178 **** static int x_prev_histword ARGS((void)); static int x_fold_case ARGS((int c)); static struct x_ftab const x_ftab[] = { ! {x_insert, "auto-insert", 0, 0, 0 }, ! {x_error, "error", 0, 0, 0 }, ! {x_ins_string, "macro-string", 0, 0, XF_NOBIND|XF_ALLOC}, ! {x_del_back, "delete-char-backward", 0, CTRL('H'), 0 }, {x_eot_del, "eot-or-delete", 0, CTRL('D'), 0 }, {x_del_bword, "delete-word-backward", 1, CTRL('H'), 0 }, {x_mv_bword, "backward-word", 1, 'b', 0 }, - {x_del_line, "kill-line", 0, 0, 0 }, - {x_abort, "abort", 0, 0, 0 }, - {x_noop, "no-op", 0, 0, 0 }, - /* Do not move the above! */ {x_mv_fword, "forward-word", 1, 'f', 0 }, - {x_del_char, "delete-char-forward", 0, 0, 0 }, {x_del_fword, "delete-word-forward", 1, 'd', 0 }, {x_mv_back, "backward-char", 0, CTRL('B'), 0 }, {x_mv_forw, "forward-char", 0, CTRL('F'), 0 }, --- 159,192 ---- static int x_prev_histword ARGS((void)); static int x_fold_case ARGS((int c)); + static struct x_ftab const x_ftab[] = { ! ! #define xft_insert &x_ftab[0] ! #define xft_error &x_ftab[1] ! #define xft_erase &x_ftab[2] ! #define xft_werase &x_ftab[3] ! #define xft_kill &x_ftab[4] ! #define xft_intr &x_ftab[5] ! #define xft_quit &x_ftab[6] ! #define xft_ins_string &x_ftab[7] ! ! /*0*/ {x_insert, "auto-insert", 0, 0, 0 }, ! /*1*/ {x_error, "error", 0, 0, 0 }, ! /*2*/ {x_del_back, "delete-char-backward", 0, CTRL('?'), 0 }, ! /*3*/ {x_del_bword, "delete-word-backward", 1, CTRL('?'), 0 }, ! /*4*/ {x_del_line, "kill-line", 0, 0, 0 }, ! /*5*/ {x_abort, "abort", 0, 0, 0 }, ! /*6*/ {x_noop, "no-op", 0, 0, 0 }, ! /*7*/ {x_ins_string, "macro-string", 0, 0, XF_NOBIND|XF_ALLOC}, ! ! /* Do not move the above! */ ! {x_del_char, "delete-char-forward", 0, 0, 0 }, {x_eot_del, "eot-or-delete", 0, CTRL('D'), 0 }, + {x_del_back, "delete-char-backward", 0, CTRL('H'), 0 }, {x_del_bword, "delete-word-backward", 1, CTRL('H'), 0 }, {x_mv_bword, "backward-word", 1, 'b', 0 }, {x_mv_fword, "forward-word", 1, 'f', 0 }, {x_del_fword, "delete-word-forward", 1, 'd', 0 }, {x_mv_back, "backward-char", 0, CTRL('B'), 0 }, {x_mv_forw, "forward-char", 0, CTRL('F'), 0 }, *************** *** 243,257 **** {x_fold_case, "capitalize-word", 1, 'c', 0 }, { 0 } }; - - #define xft_insert &x_ftab[0] - #define xft_error &x_ftab[1] - #define xft_ins_string &x_ftab[2] - #define xft_erase &x_ftab[3] - #define xft_kill &x_ftab[7] - #define xft_werase &x_ftab[5] - #define xft_intr &x_ftab[8] - #define xft_quit &x_ftab[9] int x_emacs(buf, len) --- 257,262 ---- diff -rc --new-file pdksh-4.9_orig/sh/eval.c pdksh-4.9/sh/eval.c *** pdksh-4.9_orig/sh/eval.c Sun Dec 5 21:47:49 1993 --- pdksh-4.9/sh/eval.c Thu Dec 2 00:38:51 1993 *************** *** 460,466 **** --- 460,470 ---- errorf("funny $() command\n"); fi = fopen(evalstr(io->name, DOTILDE), "r"); if (fi != NULL) + #ifdef __linux__ + setfileno (fi, savefd(fileno(fi))); + #else fileno(fi) = savefd(fileno(fi)); + #endif xp->split = 0; /* no waitlast() */ } else { int ofd1, pv[2]; diff -rc --new-file pdksh-4.9_orig/sh/io.c pdksh-4.9/sh/io.c *** pdksh-4.9_orig/sh/io.c Sun Dec 5 21:47:51 1993 --- pdksh-4.9/sh/io.c Sat Dec 4 12:09:04 1993 *************** *** 91,96 **** --- 91,108 ---- */ FILE * shf [NUFILE]; /* map shell fd to FILE * */ + #ifdef __linux__ + /* + * Streams are buffered by default under Linux, and calling + * setvbuf with buf == NULL unbuffers them. So this stub + * just does a noop. + */ + int setvbuf(FILE *stream, char *buf, int mode, size_t size) + { + return 0; + } + #endif + /* open stream for shell fd */ void fopenshf(fd) *************** *** 98,112 **** { if (shf[fd] != NULL) return; if (fd <= 2) ! #if defined(__386BSD__) || defined(_BSDI) /* Chris Torek's stdio replacement */ __sF[fd]._flags = 0; - #else - #ifdef _MINIX - /* ? */; - #else - _iob[fd]._flag = 0; /* re-use stdin, stdout, stderr */ #endif #endif shf[fd] = fdopen(fd, "r+"); --- 110,122 ---- { if (shf[fd] != NULL) return; + #if !defined _MINIX && !defined __linux__ if (fd <= 2) ! #if !defined(__386BSD__) && !defined(_BSDI) ! _iob[fd]._flag = 0; /* re-use stdin, stdout, stderr */ ! #else /* Chris Torek's stdio replacement */ __sF[fd]._flags = 0; #endif #endif shf[fd] = fdopen(fd, "r+"); diff -rc --new-file pdksh-4.9_orig/sh/jobs.c pdksh-4.9/sh/jobs.c *** pdksh-4.9_orig/sh/jobs.c Sun Dec 5 21:47:52 1993 --- pdksh-4.9/sh/jobs.c Thu Dec 2 00:38:59 1993 *************** *** 37,42 **** --- 37,46 ---- #include "termios.h" #endif #endif + #ifdef __linux__ + #include + #endif + #ifdef _BSD /* diff -rc --new-file pdksh-4.9_orig/sh/main.c pdksh-4.9/sh/main.c *** pdksh-4.9_orig/sh/main.c Sun Dec 5 21:47:53 1993 --- pdksh-4.9/sh/main.c Thu Dec 2 00:39:03 1993 *************** *** 220,226 **** --- 220,230 ---- if ((s->u.file = fopen(name, "r")) == NULL) errorf("%s: cannot open\n", name); fflag = 1; + #ifdef __linux__ + setfileno (s->u.file, savefd(fileno(s->u.file))); + #else fileno(s->u.file) = savefd(fileno(s->u.file)); + #endif setvbuf(s->u.file, (char *)NULL, _IOFBF, BUFSIZ); } } *************** *** 310,316 **** --- 314,324 ---- if (f == NULL) return 0; /* todo: the savefd doesn't get popped */ + #ifdef __linux__ + setfileno (f, savefd(fileno(f))); /* questionable */ + #else fileno(f) = savefd(fileno(f)); /* questionable */ + #endif setvbuf(f, (char *)NULL, _IOFBF, BUFSIZ); } else f = stdin; diff -rc --new-file pdksh-4.9_orig/sh/makefile.linux pdksh-4.9/sh/makefile.linux *** pdksh-4.9_orig/sh/makefile.linux --- pdksh-4.9/sh/makefile.linux Fri Dec 3 20:29:34 1993 *************** *** 0 **** --- 1,302 ---- + # PD Bourne/Korn Shell + # $Id: Makefile,v 1.3 1992/08/10 12:02:18 sjg Exp $ + + SHELL = /bin/sh + MAKE = make + + LN = ln -s + + # You _can_ build this shell without the ../std tree if your + # system provides a sufficiently POSIX environment, or if your + # BSD system is a Sun or close. If not try ../std. + + # gcc is good value on most mc68k's and sun386's if nothing else. + # if you don't have gcc cc should do + CC=gcc -pipe + # CC=gcc -V ss-921113 -b i386-linux + + # The following are the defintions used (or thereabouts) + # to build ksh without ../std + # + # sun386 SunOS 4.0.2, sun3 SunOS 4.0.3 + # CONFIG=-D_BSD + # XOPTS=-DNOSTDHDRS + # copy these from ../std/stdc or ensure they are in libstdc.a + # XOBJS = memmove.o strstr.o + # + # sun3 SunOS 4.1.1 + # CONFIG=-D_BSD + # XOPTS=-DNOSTDHDRS + # copy these from ../std/stdc or ensure they are in libstdc.a + # XOBJS = memmove.o + # + # sun4c (sparc) SunOS 4.1.1 + # CC=cc -pipe # don't use gcc + # CONFIG=-D_BSD + # XOPTS=-DNOSTDHDRS + # copy these from ../std/stdc or ensure they are in libstdc.a + # XOBJS = memmove.o + # + # Bull DPX/2 B.O.S. 2.00.45 + # CC=gcc -ansi + # CONFIG=-D_POSIX_SOURCE + # XOPTS= + # XOBJS= + # + # Minix-386 1.5.10 with estdio + # CONFIG= -D_BSD -D_MINIX -D_POSIX_SOURCE + # XOPTS= + # XOBJS= + # + # BSD/386 + # CONFIG= -D_BSDI -D_POSIX_TERM -D_POSIX_SOURCE + # XOPTS= + # XOBJS= + + # Linux, mmap () is not complete. + CONFIG= -D_SYSV -D_POSIX_TERM -DNO_MMAP -D_POSIX_SOURCE + #CONFIG= -D_SYSV + #CONFIG= -D_BSD -DHAVE_SYS_STDTYPES + #CONFIG= -D_BSD -DCOMPLEX_HISTORY + + + STD=../std + INCL=$(STD)/h + XINCL=-I$(INCL) + LDOPTS=-L$(STD) + XOBJS= + + # use -O if you trust it :-) + DBG= -O2 -fomit-frame-pointer -m486 -s + CFLAGS = $(DBG) $(CONFIG) $(XINCL) $(XOPTS) + + LDFLAGS = $(DBG) $(LDOPTS) + + #COMPATLIBS = -lstdc -lposix + #XLIBS = -lc_s + #XLIBS = -ldirent + LDLIBS = $(COMPATLIBS) $(XLIBS) + + HDRS = sh.h table.h expand.h lex.h tree.h tty.h trace.h + SRCS1 = version.c main.c misc.c trap.c alloc.c io.c \ + syn.c lex.c edit.c emacs.c vi.c history.c tree.c + SRCS2 = exec.c jobs.c \ + c_sh.c c_ksh.c c_test.c getopts.c do_ulimit.c \ + var.c table.c eval.c expr.c mail.c sigact.c trace.c + SRCS = Makefile $(HDRS) $(SRCS1) $(SRCS2) + + OBJS = version.o main.o misc.o \ + syn.o lex.o edit.o emacs.o vi.o tree.o \ + exec.o jobs.o trap.o \ + c_sh.o c_ksh.o c_test.o \ + do_ulimit.o getopts.o expr.o history.o \ + var.o table.o alloc.o io.o eval.o mail.o sigact.o trace.o $(XOBJS) + + ksh: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) + + clean: + rm -f *.o *.out core + + clobber: clean + rm -f ksh + + link: + ($(SHELL) ../std/mklinks ../std/h stdh.h) + + + depend: + makedepend $(CFLAGS) $(SRCS1) $(SRCS2) + + install: + @echo "Try:" + @echo "cp ksh /bin" + @echo "strip /bin/ksh" + @echo "chmod 555 /bin/ksh" + + .c.s: + $(CC) $(CFLAGS) -S -o $@ $< + + asms: $(OBJS:.o=.s) + + + # DO NOT DELETE THIS LINE -- make depend depends on it. + # If this runs make out of memory, delete /usr/include lines. + alloc.o: alloc.c + alloc.o: config.h + alloc.o: sh.h + alloc.o: stdh.h + alloc.o: trace.h + c_ksh.o: c_ksh.c + c_ksh.o: config.h + c_ksh.o: sh.h + c_ksh.o: stdh.h + c_ksh.o: table.h + c_ksh.o: trace.h + c_sh.o: c_sh.c + c_sh.o: config.h + c_sh.o: lex.h + c_sh.o: sh.h + c_sh.o: stdh.h + c_sh.o: table.h + c_sh.o: trace.h + c_sh.o: tree.h + c_test.o: c_test.c + c_test.o: config.h + c_test.o: sh.h + c_test.o: stdh.h + c_test.o: trace.h + edit.o: config.h + edit.o: edit.c + edit.o: edit.h + edit.o: lex.h + edit.o: sh.h + edit.o: stdh.h + edit.o: trace.h + edit.o: tty.h + emacs.o: config.h + emacs.o: edit.h + emacs.o: emacs.c + emacs.o: expand.h + emacs.o: lex.h + emacs.o: sh.h + emacs.o: stdh.h + emacs.o: table.h + emacs.o: trace.h + emacs.o: tree.h + eval.o: config.h + eval.o: eval.c + eval.o: expand.h + eval.o: lex.h + eval.o: sh.h + eval.o: stdh.h + eval.o: table.h + eval.o: trace.h + eval.o: tree.h + exec.o: config.h + exec.o: exec.c + exec.o: lex.h + exec.o: sh.h + exec.o: stdh.h + exec.o: table.h + exec.o: trace.h + exec.o: tree.h + expr.o: config.h + expr.o: expr.c + expr.o: sh.h + expr.o: stdh.h + expr.o: table.h + expr.o: trace.h + getopts.o: config.h + getopts.o: getopts.c + getopts.o: sh.h + getopts.o: stdh.h + getopts.o: table.h + getopts.o: trace.h + history.o: config.h + history.o: history.c + history.o: lex.h + history.o: sh.h + history.o: stdh.h + history.o: trace.h + io.o: config.h + io.o: io.c + io.o: sh.h + io.o: stdh.h + io.o: trace.h + jobs.o: config.h + jobs.o: jobs.c + jobs.o: sh.h + jobs.o: stdh.h + jobs.o: trace.h + jobs.o: tree.h + lex.o: config.h + lex.o: expand.h + lex.o: lex.c + lex.o: lex.h + lex.o: sh.h + lex.o: stdh.h + lex.o: table.h + lex.o: trace.h + lex.o: tree.h + mail.o: config.h + mail.o: mail.c + mail.o: sh.h + mail.o: stdh.h + mail.o: table.h + mail.o: trace.h + main.o: config.h + main.o: lex.h + main.o: main.c + main.o: sh.h + main.o: stdh.h + main.o: table.h + main.o: trace.h + main.o: tree.h + memmove.o: memmove.c + memmove.o: stdh.h + misc.o: config.h + misc.o: expand.h + misc.o: misc.c + misc.o: sh.h + misc.o: stdh.h + misc.o: trace.h + strstr.o: stdh.h + strstr.o: strstr.c + syn.o: config.h + syn.o: expand.h + syn.o: lex.h + syn.o: sh.h + syn.o: stdh.h + syn.o: syn.c + syn.o: table.h + syn.o: trace.h + syn.o: tree.h + sigact.o: sigact.h sigact.c + table.o: config.h + table.o: sh.h + table.o: stdh.h + table.o: table.c + table.o: table.h + table.o: trace.h + times.o: times.c + trace.o: trace.c + trap.o: config.h + trap.o: sh.h + trap.o: stdh.h + trap.o: trace.h + trap.o: trap.c + tree.o: config.h + tree.o: sh.h + tree.o: stdh.h + tree.o: trace.h + tree.o: tree.c + tree.o: tree.h + do_ulimit.o: config.h + do_ulimit.o: sh.h + do_ulimit.o: stdh.h + do_ulimit.o: trace.h + do_ulimit.o: do_ulimit.c + var.o: config.h + var.o: expand.h + var.o: sh.h + var.o: stdh.h + var.o: table.h + var.o: trace.h + var.o: var.c + version.o: config.h + version.o: sh.h + version.o: stdh.h + version.o: trace.h + version.o: version.c + vi.o: config.h + vi.o: edit.h + vi.o: expand.h + vi.o: lex.h + vi.o: sh.h + vi.o: stdh.h + vi.o: table.h + vi.o: trace.h + vi.o: tree.h + vi.o: vi.c + # WARNING: Put nothing here or make depend will gobble it up! diff -rc --new-file pdksh-4.9_orig/sh/misc.c pdksh-4.9/sh/misc.c *** pdksh-4.9_orig/sh/misc.c Sun Dec 5 21:47:54 1993 --- pdksh-4.9/sh/misc.c Thu Dec 2 00:39:03 1993 *************** *** 173,178 **** --- 173,179 ---- return (*as == '-') ? -n : n; } + #if !defined __linux__ /* * stripped down strerror for kill and exec */ *************** *** 203,208 **** --- 204,211 ---- return "Unknown system error"; } } + + #endif /* -------- gmatch.c -------- */ diff -rc --new-file pdksh-4.9_orig/sh/sh.h pdksh-4.9/sh/sh.h *** pdksh-4.9_orig/sh/sh.h Sun Dec 5 21:48:06 1993 --- pdksh-4.9/sh/sh.h Thu Dec 2 00:40:06 1993 *************** *** 278,285 **** --- 278,289 ---- */ #include "trace.h" + #if defined __linux__ + #include + #else #ifndef fileno #define fileno(p) ((p)->_file) + #endif #endif /* be sure not to interfere with anyone else's idea about EXTERN */ diff -rc --new-file pdksh-4.9_orig/sh/stdh.h pdksh-4.9/sh/stdh.h *** pdksh-4.9_orig/sh/stdh.h Sun Dec 5 21:44:26 1993 --- pdksh-4.9/sh/stdh.h Mon May 24 19:45:31 1993 *************** *** 40,45 **** --- 40,49 ---- /* if we have std headers then include them here * otherwise make allowances */ + #ifdef __linux__ + extern void setfileno ARGS ((FILE *__fp, int __fd)); + #endif + #ifndef NOSTDHDRS # include # include diff -rc --new-file pdksh-4.9_orig/sh/trap.c pdksh-4.9/sh/trap.c *** pdksh-4.9_orig/sh/trap.c Sun Dec 5 21:48:09 1993 --- pdksh-4.9/sh/trap.c Thu Dec 2 00:40:10 1993 *************** *** 24,33 **** #else {SIGIOT, "IOT", "IOT instruction"}, #endif {SIGEMT, "EMT", "EMT trap"}, {SIGFPE, "FPE", "Floating exception"}, {SIGKILL, "KILL", "Killed"}, ! #ifdef _MINIX {SIGUSR1, "USR1", "User defined signal 1"}, {SIGSEGV, "SEGV", "Memory fault"}, {SIGUSR2, "USR2", "User defined signal 2"}, --- 24,37 ---- #else {SIGIOT, "IOT", "IOT instruction"}, #endif + #ifdef __linux__ + {SIGUNUSED, "UNUSED", "Unused signal"}, + #else {SIGEMT, "EMT", "EMT trap"}, + #endif {SIGFPE, "FPE", "Floating exception"}, {SIGKILL, "KILL", "Killed"}, ! #if defined _MINIX || defined __linux__ {SIGUSR1, "USR1", "User defined signal 1"}, {SIGSEGV, "SEGV", "Memory fault"}, {SIGUSR2, "USR2", "User defined signal 2"}, *************** *** 39,47 **** {SIGPIPE, "PIPE", "Broken pipe"}, {SIGALRM, "ALRM", "Alarm clock"}, {SIGTERM, "TERM", "Terminated"}, ! #ifdef _MINIX {SIGSTKFLT, "STKFLT", "Stack fault"}, #endif #ifdef _SYSV {SIGUSR1, "USR1", "User defined signal 1"}, {SIGUSR2, "USR2", "User defined signal 2"}, --- 43,68 ---- {SIGPIPE, "PIPE", "Broken pipe"}, {SIGALRM, "ALRM", "Alarm clock"}, {SIGTERM, "TERM", "Terminated"}, ! #if defined _MINIX || defined __linux__ {SIGSTKFLT, "STKFLT", "Stack fault"}, #endif + #ifdef __linux__ + {SIGCHLD, "CHLD", "Child exited"}, + {SIGCONT, "CONT", "Continue"}, + {SIGSTOP, "STOP", "Stop (signal)"}, + {SIGTSTP, "TSTP", "Stop"}, + {SIGTTIN, "TTIN", "Stop (tty input)"}, + {SIGTTOU, "TTOU", "Stop (tty output)"}, + {SIGIO, "IO", "Possible I/O"}, + {SIGXCPU, "XCPU", "CPU time limit exceeded"}, + {SIGXFSZ, "XFSZ", "File size limit exceeded"}, + {SIGVTALRM, "VTALRM", "Virtual time alarm"}, + {SIGPROF, "PROF", "Profile signal"}, + {SIGWINCH, "WINCH", "Window size changed"}, + #ifdef SIGLOST + {SIGLOST, "LOST", "File lock lost"}, + #endif + #else #ifdef _SYSV {SIGUSR1, "USR1", "User defined signal 1"}, {SIGUSR2, "USR2", "User defined signal 2"}, *************** *** 67,73 **** {SIGTTIN, "TTIN", "Stop (tty input)"}, {SIGTTOU, "TTOU", "Stop (tty output)"}, #endif ! #endif }; Trap * --- 88,95 ---- {SIGTTIN, "TTIN", "Stop (tty input)"}, {SIGTTOU, "TTOU", "Stop (tty output)"}, #endif ! #endif /* _SYSV */ ! #endif /* __linux__ */ }; Trap *