brendan@cs.widener.edu (Brendan Kehoe) (03/09/91)
These patches to the pd ksh posted some time ago will let you build it successfully under SunOS 4.1 and above. (I haven't tried 4.0.3, since I don't run it here anymore.) They also fix the problem of ksh hanging when you do ^D at the beginning of the line. Just cd to the directory containing the pd ksh sources and run this through patch -p -N. -- cut -- *** ../oksh/ReadMe Wed Jan 30 11:36:38 1991 --- ./ReadMe Wed Jan 30 14:59:31 1991 *************** *** 1,61 **** Notes on the Standard C / POSIX P1003.1 package ! This package contains header files and library routines ! to provide a standard C (ANSI) and POSIX enviroment for portable programs. ! This allows most OS dependcies to be removed from an application, ! making it much more readable, and isolating them in a small, ! standardized library. It has the disadvantage that it only ! works with fairly stock UNIX versions, but a different approach ! will be used for other systems. ! This package supplements the existing libraries and header files ! of a AT&T-derived Unix system (System V and BSD in particular). ! It also provides function prototypes when the compiler supports them, improving compile-time error checking and improving portability on ! machines where sizeof(int) == sizeof(size_t) == sizeof(void*) does not hold. ! A different approach will be used for the DOS, Atari St, Minix, ! and possibly V7: a complete replacement standard C library will ! be provided as a separate package. This would not be practical ! with BSD or NFS systems because of the conflicts with the host ! stdio and the replacement stdio in libc's getpwent(). Contents: ! stdc/*: The standard C header files and library. ! posix/*: The POSIX header files and library. ! h/*, h/sys/*: Links to the header files in stdc/ and posix/. ! libstdc.a: The standard C library. ! libposix.a: The POSIX emulation library. ! To create the header files and libraries, perform the following ! three steps in the stdc and posix directories: ! One of _BSD, _SYSV, or _V7 should be defined in the Makefile. ! Do "rm stdc/stdio.h", it gets created by make. ! Do "make link" first to set up the links from *.h to ../h. ! Do "make" to create the library. ! Compile applications with -I$STD/h, link them with -L$STD ... -lstdc -lposix. ! Notes on the standard C package ! The files <locale.h>, <assert.h>, and <math.h> don't exist yet. ! Many standard C functions are not implemented yet. ! These include strtol, strtoul, atexit, tempfile(?), etc. ! The string routines are by Henry Spencer. ! Known portability problems include: ! size_t or ptrdiff_t in <stddef.h> may need to be long. ! The method of creating <stdio.h> from /usr/include/stdio.h and stdio.h_std ! may not work on some versions of UNIX. ! Almost definitely not on Xenix, maybe not on merged BSD-SysV systems. ! This package contains a correct version of setvbuf() which ! depends on the contents of FILE in the host stdio.h. ! This will not work if FILE is neither stock System V or BSD. ! You can safely "#if 0" out the body of setvbuf for PD ksh, ! setvbuf is used to decrease the size of buffers to speed up forks. ! Notes on the POSIX package ! Only headers and function required by the PD KornShell are implemented. ! I do not intend to develop this into a full POSIX emulation package. ! You should install Doug Gwyn's <dirent> package if you do not have ! <dirent.h> nor <sys/dir>. If you do have <dirent.h>, unlink h/dirent.h ! (this should be configured automatically by the makefile). --- 1,88 ---- Notes on the Standard C / POSIX P1003.1 package ! This package contains header files and library routines to provide a ! standard C (ANSI) and POSIX enviroment for portable programs. This ! allows most OS dependcies to be removed from an application, making it ! much more readable, and isolating them in a small, standardized ! library. It has the disadvantage that it only works with fairly stock ! UNIX versions, but a different approach will be used for other ! systems. ! This package supplements the existing libraries and header files ! of a AT&T-derived Unix system (System V and BSD in particular). It ! also provides function prototypes when the compiler supports them, improving compile-time error checking and improving portability on ! machines where sizeof(int) == sizeof(size_t) == sizeof(void*) does not ! hold. ! A different approach will be used for the DOS, Atari St, Minix, ! and possibly V7: a complete replacement standard C library will be ! provided as a separate package. This would not be practical with BSD ! or NFS systems because of the conflicts with the host stdio and the ! replacement stdio in libc's getpwent(). Contents: ! stdc/*: The standard C header files and library. ! posix/*: The POSIX header files and library. ! h/*, h/sys/*: Links to the header files in stdc/ and posix/. ! libstdc.a: The standard C library. ! libposix.a: The POSIX emulation library. ! Building PD Ksh ! --------------- ! First, create the header files and libraries: ! - define _BSD, _SYSV, or _V7 in stdc/Makefile and posix/Makefile ! - rm stdc/stdio.h ! - cd stdc; make ! - cd ../posix; make posix ! Now, type: ! ! - cd ../src; make ! ! The executable will be in src/ksh. ! ! Notes on the standard C package ! ! - The files <locale.h>, <assert.h>, and <math.h> don't exist yet. ! - Many standard C functions are not implemented yet, including ! strtol strtoul atexit tempfile et al. ! - The string routines are by Henry Spencer. ! ! Known Portability Problems ! ! - size_t or ptrdiff_t in <stddef.h> may need to be long. ! - some versions of Unix may scream when make stdc tries to create a ! stdio.h from /usr/include/stdio.h and stdc/stdio.h_std .. if this ! is the case (e.g. on Xenix and some BSD/SysV mixes), you can do it ! by hand by simply doing: ! cd stdc ! cp stdio.h_std stdio.h ! edit the new stdio.h and insert /usr/include/stdio.h between the lines ! /* system stdio.h goes here ... %%% */ ! and ! /* ... end system stdio.h */ ! ! - FILE must be in the host stdio.h for setvbuf() to work; also it ! has to be stock System V or BSD, or it'll fail ! - You can safely "#if 0" out the body of setvbuf for PD ksh, setvbuf ! is used to decrease the size of buffers to speed up forks. ! - If the offsetof macro makes your build fail, define BAD_OFFSET in ! the CFLAGS variable in src/Makefile, as such: ! CFLAGS= blahblahblah -DBAD_OFFSET ! - Also previous versions would crash if you did a Ctrl-D (EOF) on ! the line by itself (at least on Suns); this has been fixed (at ! least on Suns :-)). ! ! Notes on the POSIX package ! ! - Only headers and function required by the PD KornShell are ! implemented. I do not intend to develop this into a full POSIX ! emulation package. ! - You should install Doug Gwyn's <dirent> package if you do not have ! <dirent.h> nor <sys/dir>. If you do have <dirent.h>, unlink ! h/dirent.h (this should be configured automatically by the ! makefile). Common subdirectories: ../oksh/posix and ./posix Common subdirectories: ../oksh/src and ./src Common subdirectories: ../oksh/stdc and ./stdc diff -rc ../oksh/posix/Makefile ./posix/Makefile *** ../oksh/posix/Makefile Wed Jan 30 11:36:38 1991 --- ./posix/Makefile Wed Jan 30 14:43:48 1991 *************** *** 4,14 **** # $Header: Makefile,v 1.1 88/03/29 18:28:38 egisin Locked $ SYSTEM=BSD ! CC = gcc -ansi -O -W LN = ln PRINT = lpr -p -Plp26_3018 ! CFLAGS = -I../h -D_$(SYSTEM) MISC = Makefile HDRS = wait.h times.h unistd.h fcntl.h dirent.h --- 4,15 ---- # $Header: Makefile,v 1.1 88/03/29 18:28:38 egisin Locked $ SYSTEM=BSD ! #CC = gcc -ansi -O -W ! CC = cc -O LN = ln PRINT = lpr -p -Plp26_3018 ! CFLAGS = -I../h -D_$(SYSTEM) -I. MISC = Makefile HDRS = wait.h times.h unistd.h fcntl.h dirent.h *************** *** 34,39 **** --- 35,41 ---- $(LIB): $(OBJS) ar r $@ $? + @echo Don't worry if it says fcntl.o has no symbol table ... -ranlib $@ #$(LIB): lib.a($OBJS) *************** *** 57,59 **** --- 59,63 ---- times.o: times.h + clean: + rm -f libposix.a *.o *~ diff -rc ../oksh/posix/io.h ./posix/io.h *** ../oksh/posix/io.h Wed Jan 30 11:36:39 1991 --- ./posix/io.h Wed Jan 30 14:26:50 1991 *************** *** 14,22 **** struct stat; /* create global incompletely-typed structure */ int chdir ARGS ((const char *path)); int umask ARGS ((int mode)); ! int open ARGS ((const char *path, int flags, ... /*mode*/)); int creat ARGS ((const char *path, int mode)); int pipe ARGS ((int pv[2])); int close ARGS ((int fd)); --- 14,26 ---- struct stat; /* create global incompletely-typed structure */ int chdir ARGS ((const char *path)); + #ifndef sun int umask ARGS ((int mode)); + #endif /* sun */ ! #ifndef sun ! int open ARGS ((const char *path, int flags, ... /* mode */)); ! #endif int creat ARGS ((const char *path, int mode)); int pipe ARGS ((int pv[2])); int close ARGS ((int fd)); diff -rc ../oksh/posix/wait.h ./posix/wait.h *** ../oksh/posix/wait.h Wed Jan 30 11:36:41 1991 --- ./posix/wait.h Wed Jan 30 14:38:53 1991 *************** *** 8,15 **** #define ARGS(args) () #endif ! #if 1 ! typedef int pid_t; /* belong in sys/types.h */ #endif /* waitpid options */ --- 8,15 ---- #define ARGS(args) () #endif ! #ifndef sun ! typedef int pid_t; /* belongs in sys/types.h */ #endif /* waitpid options */ diff -rc ../oksh/src/Makefile ./src/Makefile *** ../oksh/src/Makefile Wed Jan 30 11:36:24 1991 --- ./src/Makefile Wed Jan 30 15:00:05 1991 *************** *** 3,13 **** # $Header: /tmp/egisin/src/RCS/Makefile,v 3.2 88/11/06 11:34:12 egisin Exp $ BIN = /u/egisin/bin ! STD = ../std PRINT = lpr -p -Plp26_3018 ! # CC = cc ! CC = gcc # Must define one of _V7, _SYSV, _BSD, _POSIX # may define any of JOBS (have BSD or POSIX job control), --- 3,14 ---- # $Header: /tmp/egisin/src/RCS/Makefile,v 3.2 88/11/06 11:34:12 egisin Exp $ BIN = /u/egisin/bin ! STD = ../stdc ! POSIXD = ../posix PRINT = lpr -p -Plp26_3018 ! CC = cc ! #CC = gcc # Must define one of _V7, _SYSV, _BSD, _POSIX # may define any of JOBS (have BSD or POSIX job control), *************** *** 15,23 **** OPTIONS = -D_BSD -DJOBS -DEDIT ! CFWARN = -ansi -O -W -Wcomment # -Wreturn-type ! CFLAGS = $(CFWARN) -I$(STD)/h $(OPTIONS) $(JUNK) ! LDFLAGS = -L$(STD) $(JUNK) LDLIBS = -lstdc -lposix # compatability libraries HDRS = sh.h table.h expand.h lex.h tree.h tty.h --- 16,26 ---- OPTIONS = -D_BSD -DJOBS -DEDIT ! #CFWARN = -ansi -O -W -Wcomment # -Wreturn-type ! #CFWARN = -g -Bstatic -nostdinc -I/usr/include ! CFWARN = -O ! CFLAGS = $(CFWARN) -I$(STD) -I$(STD)/h -I$(POSIXD) $(OPTIONS) $(JUNK) ! LDFLAGS = -L$(STD) -L$(POSIXD) LDLIBS = -lstdc -lposix # compatability libraries HDRS = sh.h table.h expand.h lex.h tree.h tty.h *************** *** 59,61 **** --- 62,66 ---- tar: ReadMe ksh.1 $(SRCS) tar cf /tmp/egisin/ksh.tar ReadMe ksh.1 $(SRCS) + clean: + rm -f ksh *.o diff -rc ../oksh/src/alloc.c ./src/alloc.c *** ../oksh/src/alloc.c Wed Jan 30 11:36:32 1991 --- ./src/alloc.c Wed Jan 30 14:47:22 1991 *************** *** 87,93 **** /* wrapped around Block list, create new Block */ if (bp == ap->free) { ! bp = malloc(offsetof(Block, cell[ICELLS + cells])); if (bp == NULL) { aerror(ap, "cannot allocate"); return NULL; --- 87,97 ---- /* wrapped around Block list, create new Block */ if (bp == ap->free) { ! #ifdef BAD_OFFSET ! bp = (Block *) malloc((int)&((Block*)NULL)->cell[ICELLS + cells]); ! #else /* !BAD_OFFSET */ ! bp = (Block *) malloc(offsetof(Block, cell[(ICELLS + cells)])); ! #endif /* BAD_OFFSET */ if (bp == NULL) { aerror(ap, "cannot allocate"); return NULL; diff -rc ../oksh/src/c_sh.c ./src/c_sh.c *** ../oksh/src/c_sh.c Wed Jan 30 11:36:36 1991 --- ./src/c_sh.c Wed Jan 30 14:26:44 1991 *************** *** 311,316 **** --- 311,319 ---- register char *cp; int old_fmonitor = flag[FMONITOR]; + /* + * if they only typed 'set', show them all of them + */ if ((cp = *++wp) == NULL) { static char * Const args [] = {"set", "-", NULL}; extern int c_typeset ARGS((char **args)); *************** *** 441,446 **** --- 444,453 ---- return rv; } + + #ifdef sun + #define CLK_TCK 100 + #endif static char * clocktos(t) diff -rc ../oksh/src/exec.c ./src/exec.c *** ../oksh/src/exec.c Wed Jan 30 11:36:36 1991 --- ./src/exec.c Wed Jan 30 11:55:06 1991 *************** *** 48,54 **** runtraps(); if (t->ioact != NULL || t->type == TPIPE) { ! e.savefd = alloc(sizeofN(short, NUFILE), ATEMP); for (i = 0; i < NUFILE; i++) e.savefd[i] = 0; /* not redirected */ } --- 48,54 ---- runtraps(); if (t->ioact != NULL || t->type == TPIPE) { ! e.savefd = (short *) alloc(sizeofN(short, NUFILE), ATEMP); for (i = 0; i < NUFILE; i++) e.savefd[i] = 0; /* not redirected */ } *************** *** 220,226 **** echo(vp, ap); /* create new variable/function block */ ! l = alloc(sizeof(struct block), ATEMP); l->next = e.loc; e.loc = l; newblock(); --- 220,226 ---- echo(vp, ap); /* create new variable/function block */ ! l = (struct block *) alloc(sizeof(struct block), ATEMP); l->next = e.loc; e.loc = l; newblock(); diff -rc ../oksh/src/expr.c ./src/expr.c *** ../oksh/src/expr.c Wed Jan 30 11:36:37 1991 --- ./src/expr.c Wed Jan 30 11:55:45 1991 *************** *** 235,241 **** { register struct tbl *vp; ! vp = alloc(sizeof(struct tbl), ATEMP); lastarea = ATEMP; vp->flag = ISSET|INTEGER; vp->type = 0; --- 235,241 ---- { register struct tbl *vp; ! vp = (struct tbl *) alloc(sizeof(struct tbl), ATEMP); lastarea = ATEMP; vp->flag = ISSET|INTEGER; vp->type = 0; diff -rc ../oksh/src/io.c ./src/io.c *** ../oksh/src/io.c Wed Jan 30 11:36:33 1991 --- ./src/io.c Wed Jan 30 14:26:41 1991 *************** *** 9,15 **** #include <stdio.h> #include <errno.h> #include <unistd.h> ! #include <fcntl.h> #include <signal.h> #include <setjmp.h> #if __STDC__ --- 9,16 ---- #include <stdio.h> #include <errno.h> #include <unistd.h> ! /* #include <fcntl.h> */ ! #include "../posix/fcntl.h" #include <signal.h> #include <setjmp.h> #if __STDC__ diff -rc ../oksh/src/jobs.c ./src/jobs.c *** ../oksh/src/jobs.c Wed Jan 30 11:36:36 1991 --- ./src/jobs.c Wed Jan 30 14:26:40 1991 *************** *** 27,33 **** #include <setjmp.h> #include <sys/types.h> #include <sys/times.h> ! #include <sys/wait.h> #if JOBS #if _BSD #include <sys/ioctl.h> --- 27,34 ---- #include <setjmp.h> #include <sys/types.h> #include <sys/times.h> ! /* #include <sys/wait.h> */ ! #include "wait.h" #if JOBS #if _BSD #include <sys/ioctl.h> *************** *** 201,207 **** for (j = procs; j != NULL; j = j->next) if (j->state == JFREE) goto Found; ! j = alloc(sizeof(Proc), APERM); j->next = procs; j->state = JFREE; procs = j; --- 202,208 ---- for (j = procs; j != NULL; j = j->next) if (j->state == JFREE) goto Found; ! j = (Proc *) alloc(sizeof(Proc), APERM); j->next = procs; j->state = JFREE; procs = j; diff -rc ../oksh/src/lex.c ./src/lex.c *** ../oksh/src/lex.c Wed Jan 30 11:36:34 1991 --- ./src/lex.c Wed Jan 30 14:26:39 1991 *************** *** 25,31 **** static int getsc_ ARGS((void)); /* optimized getsc_() */ ! #define getsc() ((*source->str != 0) ? *source->str++ : getsc_()) #define ungetsc() (source->str--) /* --- 25,36 ---- static int getsc_ ARGS((void)); /* optimized getsc_() */ ! /* ! * if it's == 128 (aka c&0x80 is true), then they put in ^D ! */ ! #define getsc() \ ! ((*source->str == 0) ? getsc_() :\ ! (*source->str & 0x80) ? '\0' : *source->str++) #define ungetsc() (source->str--) /* diff -rc ../oksh/src/main.c ./src/main.c *** ../oksh/src/main.c Wed Jan 30 11:36:31 1991 --- ./src/main.c Wed Jan 30 14:26:38 1991 *************** *** 11,17 **** #include <stdio.h> #include <string.h> #include <unistd.h> ! #include <fcntl.h> #include <signal.h> #include <errno.h> #include <setjmp.h> --- 11,18 ---- #include <stdio.h> #include <string.h> #include <unistd.h> ! /* #include <fcntl.h> */ ! #include "../posix/fcntl.h" #include <signal.h> #include <errno.h> #include <setjmp.h> Only in ./src: memmove.c diff -rc ../oksh/src/misc.c ./src/misc.c *** ../oksh/src/misc.c Wed Jan 30 11:36:32 1991 --- ./src/misc.c Mon Dec 17 10:06:07 1990 *************** *** 201,207 **** Void **vp; register Void **dvp, **svp; ! vp = alloc(sizeofN(Void*, n*2), ATEMP); for (svp = xp->beg, dvp = vp; svp < xp->cur; ) *dvp++ = *svp++; afree((Void*) xp->beg, ATEMP); --- 201,207 ---- Void **vp; register Void **dvp, **svp; ! vp = (Void **) alloc(sizeofN(Void*, n*2), ATEMP); for (svp = xp->beg, dvp = vp; svp < xp->cur; ) *dvp++ = *svp++; afree((Void*) xp->beg, ATEMP); diff -rc ../oksh/src/syn.c ./src/syn.c *** ../oksh/src/syn.c Wed Jan 30 11:36:33 1991 --- ./src/syn.c Wed Jan 30 14:26:37 1991 *************** *** 81,86 **** --- 81,87 ---- register int c; t = pipeline(0); + if (t != NULL) { while ((c = token(0)) == LOGAND || c == LOGOR) { if ((p = pipeline(CONTIN)) == NULL) diff -rc ../oksh/src/table.c ./src/table.c *** ../oksh/src/table.c Wed Jan 30 11:36:45 1991 --- ./src/table.c Wed Jan 30 14:26:35 1991 *************** *** 56,62 **** register struct tbl **ntblp, **otblp = tp->tbls; int osize = tp->size; ! ntblp = alloc(sizeofN(struct tbl *, nsize), tp->areap); for (i = 0; i < nsize; i++) ntblp[i] = NULL; tp->size = nsize; --- 56,62 ---- register struct tbl **ntblp, **otblp = tp->tbls; int osize = tp->size; ! ntblp = (struct tbl **) alloc(sizeofN(struct tbl *, nsize), tp->areap); for (i = 0; i < nsize; i++) ntblp[i] = NULL; tp->size = nsize; *************** *** 130,136 **** /* create new tbl entry */ for (cp = n; *cp != '\0'; cp++) ; ! p = (struct tbl *) alloc(offsetof(struct tbl, name[(cp-n)+1]), tp->areap); p->flag = 0; p->type = 0; for (cp = p->name; *n != '\0';) --- 130,141 ---- /* create new tbl entry */ for (cp = n; *cp != '\0'; cp++) ; ! #ifdef BAD_OFFSET ! p = (struct tbl *) alloc(((size_t)&((struct tbl *)NULL)->name[(cp-n)+1]), tp->areap); ! #else /* !BAD_OFFSET */ ! p = (struct tbl *) alloc(offsetof(struct tbl, name[((cp-n)+1)]), tp->areap); ! #endif /* BAD_OFFSET */ ! p->flag = 0; p->type = 0; for (cp = p->name; *n != '\0';) diff -rc ../oksh/src/tree.c ./src/tree.c *** ../oksh/src/tree.c Wed Jan 30 11:36:35 1991 --- ./src/tree.c Fri Dec 14 16:21:57 1990 *************** *** 350,356 **** Area *ap; { size_t len = wdscan(wp, EOS) - wp; ! return memcpy(alloc(len, ap), wp, len); } /* return the position of prefix c in wp plus 1 */ --- 350,356 ---- Area *ap; { size_t len = wdscan(wp, EOS) - wp; ! return((char *)memcpy(alloc(len, ap), wp, len)); } /* return the position of prefix c in wp plus 1 */ diff -rc ../oksh/stdc/Makefile ./stdc/Makefile *** ../oksh/stdc/Makefile Wed Jan 30 11:36:42 1991 --- ./stdc/Makefile Wed Jan 30 14:26:34 1991 *************** *** 4,10 **** # $Header: Makefile,v 1.1 88/03/29 18:28:38 egisin Locked $ SYSTEM=BSD ! CC = gcc -ansi -O -W LN = ln PRINT = lpr -p -Plp26_3018 --- 4,11 ---- # $Header: Makefile,v 1.1 88/03/29 18:28:38 egisin Locked $ SYSTEM=BSD ! #CC = gcc -ansi -O -W ! CC = cc -O LN = ln PRINT = lpr -p -Plp26_3018 *************** *** 75,78 **** --- 76,82 ---- vprintf.o: stdarg.h stdio.h strstr.o: string.h + + clean: + rm -f libstdc.a *.o diff -rc ../oksh/stdc/setvbuf.c ./stdc/setvbuf.c *** ../oksh/stdc/setvbuf.c Wed Jan 30 11:36:49 1991 --- ./stdc/setvbuf.c Fri Dec 14 16:25:05 1990 *************** *** 46,52 **** return -1; } f->_flag |= type; ! f->_base = f->_ptr = buf; f->_cnt = 0; #if _BSD f->_bufsiz = size; --- 46,52 ---- return -1; } f->_flag |= type; ! f->_base = f->_ptr = (unsigned char *) buf; f->_cnt = 0; #if _BSD f->_bufsiz = size; diff -rc ../oksh/stdc/sprintf.c ./stdc/sprintf.c *** ../oksh/stdc/sprintf.c Wed Jan 30 11:36:48 1991 --- ./stdc/sprintf.c Fri Dec 14 16:26:11 1990 *************** *** 51,57 **** static FILE siob; siob._flag = _IOWRT; ! siob._base = siob._ptr = s; siob._cnt = BUFSIZ; siob._file = -1; --- 51,57 ---- static FILE siob; siob._flag = _IOWRT; ! siob._base = siob._ptr = (unsigned char *) s; siob._cnt = BUFSIZ; siob._file = -1; diff -rc ../oksh/stdc/stddef.h ./stdc/stddef.h *** ../oksh/stdc/stddef.h Wed Jan 30 11:36:42 1991 --- ./stdc/stddef.h Wed Jan 30 14:26:33 1991 *************** *** 25,33 **** --- 25,37 ---- #endif typedef unsigned size_t; /* may need long */ + #ifndef sun typedef int ptrdiff_t; + #endif + #ifndef BAD_OFFSET #define offsetof(type,id) ((size_t)&((type*)NULL)->id) + #endif extern int errno; /* really belongs in <errno.h> */ -- cut -- -- Brendan Kehoe - Widener Sun Network Manager - brendan@cs.widener.edu Widener University in Chester, PA A Bloody Sun-Dec War Zone -- Brendan Kehoe - Widener Sun Network Manager - brendan@cs.widener.edu Widener University in Chester, PA A Bloody Sun-Dec War Zone