home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume19 / ash / patch01 < prev    next >
Text File  |  1989-05-30  |  17KB  |  671 lines

  1. Subject:  v19i009:  A reimplmentation of the System V shell, Patch1
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: ka@june.cs.washington.edu (Kenneth Almquist)
  7. Posting-number: Volume 19, Issue 9
  8. Archive-name: ash/patch1
  9.  
  10.  
  11. Ash blows up if you create more than four jobs.
  12.  
  13. Also attached is a config script.  If you've already compiled ash,
  14. you can skip this.
  15.  
  16.                   Kenneth Almquist
  17.  
  18.  
  19. echo extracting jobs.pch
  20. cat > jobs.pch <<\!
  21. *** jobs.28    Fri Apr 21 06:25:53 1989
  22. --- jobs.c    Fri Apr 21 06:28:52 1989
  23. ***************
  24. *** 412,437 ****
  25.         union node *node;
  26.         {
  27.         int i;
  28. !       struct job *jp;
  29.   
  30.         for (i = njobs, jp = jobtab ; ; jp++) {
  31. !             if (--i < 0) {
  32.             INTOFF;
  33. !                   if (njobs == 0) {
  34. !                         jobtab = ckmalloc(4 * sizeof jobtab[0]);
  35. !                   } else {
  36. !                         jp = ckmalloc((njobs + 4) * sizeof jobtab[0]);
  37. !                         bcopy(jobtab, jp, njobs * sizeof jp[0]);
  38. !                         ckfree(jobtab);
  39. !                         jobtab = jp;
  40. !                   }
  41. !                   jp = jobtab + njobs;
  42. !                   for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0);
  43.             INTON;
  44. !                   break;
  45. !             }
  46. !             if (jp->used == 0)
  47. !                   break;
  48.         }
  49.         INTOFF;
  50.         jp->state = 0;
  51. --- 412,448 ----
  52.         union node *node;
  53.         {
  54.         int i;
  55. !       struct job *jp, *jp2;
  56. !       struct job *newtab;
  57.   
  58.         for (i = njobs, jp = jobtab ; ; jp++) {
  59. !         if (--i < 0) {
  60.             INTOFF;
  61. !           if (njobs == 0) {
  62. !             jobtab = ckmalloc(4 * sizeof jobtab[0]);
  63. !           } else {
  64. !             newtab = ckmalloc((njobs + 4) * sizeof newtab[0]);
  65. !             bcopy(jobtab, newtab, njobs * sizeof newtab[0]);
  66. !             jp = jobtab;
  67. !             jp2 = newtab;
  68. !             for (i = njobs ; --i >= 0 ; ) {
  69. !                   if (jp->ps == &jp->ps0)
  70. !                     jp2->ps = &jp2->ps0;
  71. !                   jp++;
  72. !                   jp2++;
  73. !             }
  74. !             ckfree(jobtab);
  75. !             jobtab = newtab;
  76. !           }
  77. !           jp = jobtab + njobs;
  78. !           njobs += 4;
  79. !           jp2 = jp;
  80. !           for (i = 4 ; --i >= 0 ; (jp2++)->used = 0);
  81.             INTON;
  82. !           break;
  83. !         }
  84. !         if (jp->used == 0)
  85. !           break;
  86.         }
  87.         INTOFF;
  88.         jp->state = 0;
  89. EOF
  90. echo extracting README.CONFIG
  91. cat > README.CONFIG <<\!
  92. The config shell procedure is used to configure ash to reflect the
  93. properties of your system.  It will create shell.h for you and edit
  94. the makefile to reflect your choice of C compiler.  To run it, type
  95. "sh config" and answer the questions that it asks you.
  96.                 Kenneth Almquist
  97. !
  98. if test `wc -c < README.CONFIG` -ne 279
  99. then    echo 'README.CONFIG is the wrong size'
  100. fi
  101.  
  102. echo extracting config
  103. cat > config << 'EOF'
  104. : Create shell.h        $#Use_sh_not_csh
  105. : Based on code by Larry Wall.
  106.  
  107. : Copyright 1989 by Kenneth Almquist.  All rights reserved.
  108. : This file is part of ash, which is distributed under the terms specified
  109. : by the Ash General Public License.  See the file named LICENSE.
  110.  
  111. : sanity checks
  112. PATH="/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin:$PATH"
  113.  
  114. if test ! -t 0; then
  115.     echo "Say 'sh config', not 'sh < config'"
  116.     exit 1
  117. fi
  118.  
  119. echo "Config program for ash."
  120. echo " "
  121.  
  122. libpth='/usr/lib /usr/local/lib /lib'
  123. rmlist=
  124. include=/usr/include
  125. fastread=
  126.  
  127. : some greps do not return status, grrr.
  128. echo "grimblepritz" >temp
  129. if grep blurfldyick temp >/dev/null 2>&1 ; then
  130.     contains=contains
  131. elif grep grimblepritz temp >/dev/null 2>&1 ; then
  132.     contains=grep
  133. else
  134.     contains=contains
  135. fi
  136. rm -f temp
  137. : the following should work in any shell
  138. case "$contains" in
  139. contains*)
  140.     echo " "
  141.     echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
  142.     cat >contains <<'EOSS'
  143. grep "$1" "$2" >greptemp && cat greptemp && test -s greptemp
  144. EOSS
  145.     chmod +x contains
  146.     rmlist="$rmlist contains greptemp"
  147.     ;;
  148. esac
  149.  
  150. : first determine how to suppress newline on echo command
  151. echo "Checking echo to see how to suppress newlines..."
  152. (echo "hi there\c" ; echo " ") >temp
  153. if $contains c temp >/dev/null 2>&1 ; then
  154.     echo "...using -n."
  155.     n='-n'
  156.     c=''
  157. else
  158.     cat <<'EOM'
  159. ...using \c
  160. EOM
  161.     n=''
  162.     c='\c'
  163. fi
  164. echo $n "Type carriage return to continue.  Your cursor should be here-->$c"
  165. read ans
  166. rm -f temp
  167.  
  168. : now set up to do reads with possible shell escape and default assignment
  169. cat <<EOSC >myread
  170. case "\$fastread" in
  171. yes) ans=''; echo " " ;;
  172. *) ans='!';;
  173. esac
  174. while expr "X\$ans" : "X!" >/dev/null; do
  175.     read ans
  176.     case "\$ans" in
  177.     !)
  178.     sh
  179.     echo " "
  180.     echo $n "\$rp $c"
  181.     ;;
  182.     !*)
  183.     set \`expr "X\$ans" : "X!\(.*\)\$"\`
  184.     sh -c "\$*"
  185.     echo " "
  186.     echo $n "\$rp $c"
  187.     ;;
  188.     esac
  189. done
  190. rp='Your answer:'
  191. case "\$ans" in
  192. '') ans="\$dflt";;
  193. esac
  194. EOSC
  195.  
  196. : general instructions
  197. cat <<EOH
  198.  
  199. This installation shell script will examine your system and ask you questions
  200. to determine how ash should be installed.  If you get stuck on a question,
  201. you may use a ! shell escape to start a subshell or execute a command.  Many
  202. of the questions will have default answers in square brackets--typing carriage
  203. return will give you the default.
  204.  
  205. If this shell script doesn't work for some reason, you will have to create
  206. shell.h by hand.  This isn't too hard to do; sample versions of shell.h for
  207. for Berkeley UNIX and System V are included in the distribution.  Also, if
  208. you make a mistake in answering a question, you can edit shell.h after this
  209. procedure finishes.
  210.  
  211. EOH
  212. rp="[Type carriage return to continue]"
  213. echo $n "$rp $c"
  214. . ./myread
  215.  
  216. : get list of predefined functions in a handy place
  217. echo " "
  218. if test -f /lib/libc.a; then
  219.     echo "Your C library is in /lib/libc.a.  You're normal."
  220.     libc=/lib/libc.a
  221. else
  222.     libc=
  223.     for dir in $libpth ; do
  224.     if test -f $dir/libc.a ; then
  225.         libc=$dir/libc.a
  226.         break
  227.     fi
  228.     if test -f $dir/clib ; then
  229.         libc=$dir/clib
  230.         break
  231.     fi
  232.     if test -f $dir/libc ; then
  233.         libc=$dir/libc
  234.         break
  235.     fi
  236.     done
  237.     if test $libc ; then
  238.     echo "Your C library is in $libc, of all places."
  239.     else
  240.     cat <<EOM
  241.  
  242. I can't seem to find your C library.  I've looked in the following places:
  243.  
  244.     $libpth
  245.  
  246. None of these seems to contain your C library.  What is the full name
  247. EOM
  248.     dflt=None
  249.     echo $n "of your C library? $c"
  250.     rp='C library full name?'
  251.     . ./myread
  252.     libc="$ans"
  253.     fi
  254. fi
  255. echo " "
  256. echo $n "Extracting names from $libc for later perusal...$c"
  257. nm $libc 2>/dev/null >libc.tmp
  258. sed -n -e 's/^.* [AT] _//p' -e 's/^.* [AT] //p' <libc.tmp >libc.list
  259. if $contains '^printf$' libc.list >/dev/null 2>&1; then
  260.     echo "done"
  261. else
  262.     sed -n -e 's/^.* D _//p' -e 's/^.* D //p' <libc.tmp >libc.list
  263.     $contains '^printf$' libc.list >/dev/null 2>&1 || \
  264.        sed -n -e 's/^_//' \
  265.           -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p' <libc.tmp >libc.list
  266.     if $contains '^printf$' libc.list >/dev/null 2>&1; then
  267.     echo "done"
  268.     else
  269.     echo " "
  270.     echo "nm didn't seem to work right."
  271.     echo "Trying ar instead..."
  272.     if ar t $libc > libc.tmp; then
  273.         sed -e 's/\.o$//' < libc.tmp > libc.list
  274.         echo "Ok."
  275.     else
  276.         echo "ar didn't seem to work right."
  277.         echo "Maybe this is a Cray...trying bld instead..."
  278.         if bld t $libc | sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
  279.         echo "Ok."
  280.         else
  281.             echo "That didn't work either.  Giving up."
  282.             exit 1
  283.         fi
  284.     fi
  285.     fi
  286. fi
  287. rmlist="$rmlist libc.tmp libc.list"
  288.  
  289. : Locate the /usr/include directory
  290. if test ! -d "$include" ; then
  291.     echo " "
  292.     echo "Hey, $include doesn't exist on this system!"
  293.     echo "I need to know the location of your header files to figure out what type"
  294.     echo "of system you are on."
  295.     while test true ; do
  296.     dflt=None
  297.     rp='Where do include files reside on this system?'
  298.     echo $n "$rp $c"
  299.     . ./myread
  300.     include="$ans"
  301.     if test ! -d "$ans" ; then
  302.         echo "$ans does not exist."
  303.     elif test ! -f "$ans/stdio.h" ; then
  304.         echo "$ans is a pretty pathetic excuse for an include directory"
  305.         echo $n "since it doesn't include stdio.h.  Use it anyway? [n] $c"
  306.         dflt=n
  307.         rp="Include files are in $ans? [$dflt]"
  308.         . ./myread
  309.         if test "X$ans" = Xy -o "X$ans" = Xyes ; then
  310.         break
  311.         fi
  312.     else
  313.         break
  314.     fi
  315.     done
  316. fi
  317.  
  318. : make some quick guesses about what we are up against
  319. echo " "
  320. echo $n "Hmm...  $c"
  321. if test -f $include/sys/socket.h -a \( -f /usr/bin/ranlib -o -f /usr/ucb/ranlib \) ; then
  322.     echo "Looks kind of like a BSD system, but we'll see..."
  323.     systype=bsd
  324. elif $contains '^fcntl$' libc.list >/dev/null 2>&1 ; then
  325.     echo "Looks kind of like a USG system, but we'll see..."
  326.     systype=sys5
  327. else
  328.     echo "Looks kind of like a version 7 system, but we'll see..."
  329.     systype=v7
  330. fi
  331. if $contains '^vmssystem$' libc.list >/dev/null 2>&1 ; then
  332.     cat <<'EOI'
  333. You appear to be running Eunice.  Lucky you.  I haven't tested ash
  334. under Eunice; let me know if it works.
  335. EOI
  336.     eunicefix=unixtovms
  337.     eunice=yes
  338. : it so happens the Eunice I know will not run shell scripts in Unix format
  339. else
  340.     echo " "
  341.     echo "Congratulations.  You aren't running Eunice."
  342.     eunicefix=':'
  343.     eunice=no
  344. fi
  345. if test -f /xenix; then
  346.     echo "Actually, this looks more like a XENIX system..."
  347.     xenix=yes
  348. else
  349.     echo " "
  350.     echo "It's not Xenix..."
  351.     xenix=no
  352. fi
  353. if test -f /venix; then
  354.     echo "Actually, this looks more like a VENIX system..."
  355.     venix=yes
  356. else
  357.     echo " "
  358.     if test "$xenix" = yes; then
  359.     : null
  360.     else
  361.     echo "Nor is it Venix."
  362.     fi
  363.     venix=yes
  364. fi
  365.  
  366. : Now determine the C compiler.  Default is gcc if present.
  367. dflt=cc
  368. for dir in `echo $PATH | tr : ' '` ; do
  369.     if test -f "$dir/gcc" ; then
  370.     dflt=gcc
  371.     fi
  372. done
  373. echo " "
  374. rp="What is the name of your C compiler? [$dflt]"
  375. echo $n "$rp $c"
  376. . ./myread
  377. cc=$ans
  378.  
  379. echo " "
  380. if $contains SIGTSTP $include/sys/signal.h >/dev/null 2>&1 ; then
  381.     echo "I see you have Berkeley job control."
  382.     jobs=1
  383. elif $contains SIGTSTP $include/signal.h >/dev/null 2>&1 ; then
  384.     echo "I see you have Berkeley job control."
  385.     jobs=1
  386. else
  387.     echo "You don't seem to have Berkeley job control.  Too bad."
  388.     jobs=0
  389. fi
  390.  
  391. : see if symlink exists
  392. echo " "
  393. if $contains '^symlink$' libc.list >/dev/null 2>&1; then
  394.     echo 'Your system has symbolic links.'
  395.     symlinks=1
  396. else
  397.     echo 'No symbolic links on your system.'
  398.     symlinks=0
  399. fi
  400.  
  401. : test for system V directory routines
  402. echo " "
  403. if test -f $include/dirent.h ; then
  404.     echo 'You appear to have the System V directory access routines.'
  405.     dirent=1
  406. elif test "$systype" = bsd ; then
  407.     echo 'I assume you have the Berkeley directory access routines.'
  408.     dirent=0
  409. else
  410.     echo "Your system doesn't contain directory access routines, which is"
  411.     echo "fine if you have Version 7 format directories."
  412.     dirent=0
  413. fi
  414.  
  415. : Tell user whether atty will be supported
  416. echo " "
  417. if test "$systype" = bsd ; then
  418.     echo "Since you are on a BSD system, I'll compile in support for atty."
  419.     atty=1
  420. else
  421.     echo "Since atty only works on BSD systems, I assume you don't want it."
  422.     atty=0
  423. fi
  424.  
  425. if test $symlinks = 1 -a -d /u ; then
  426.     echo " "
  427.     echo "You appear to have the /u directory on your system."
  428.     if test ! -d /u/root ; then
  429.     echo "However, there is no entry for root.  If you have questions"
  430.     echo "about the /u directory, read the DIFFERENCES file."
  431.     fi
  432.     udir=0
  433. else
  434.     if test $symlinks = 1 ; then
  435.     cat <<\!
  436.  
  437. By convention, the home directory of a user is referred to using the
  438. name /u/user.  Since you have symbolic links on your system, you can
  439. create /u and place symbolic links in it pointing to the home directories
  440. of the users of the system.  However, ash does contain code to replace
  441. /u/user with the name of the home directory of the user, and you can use
  442. this code instead of creating /u if you want to.
  443. !
  444.     dflt=n
  445.     else
  446.     cat <<\!
  447.  
  448. By convention, the home directory of a user is referred to using the
  449. name /u/user.  Unfortunately, the /u directory is typically implemented
  450. using symbolic links, which your system appears not to have.  To support
  451. systems like yours, ash contains code to replace /u/user with the name
  452. of the home directory of the user.
  453. !
  454.     dflt=y
  455.     fi
  456.     udir=unset
  457.     while test $udir = unset ; do
  458.     rp="Do you want ash to include this code? [$dflt]"
  459.     echo $n "$rp $c"
  460.     . ./myread
  461.     case "$ans" in
  462.     y*)  udir=1 ;;
  463.     n*)  udir=0 ;;
  464.     *)   echo "Please answer 'y' or 'n'" ;;
  465.     esac
  466.     done
  467. fi
  468.  
  469. echo " "
  470. echo "Now let's test out your C compiler..."
  471.  
  472. cat > ctemp1.c <<\!
  473. main() {
  474. #ifdef __STDC__
  475.     exit(0);
  476. #else
  477.     exit(1);
  478. #endif
  479. }
  480.  
  481. verylongname1() {
  482.     return 1;
  483. }
  484. !
  485. cat > ctemp2.c <<\!
  486. verylongname2() {
  487.     return 2;
  488. }
  489. !
  490. if $cc -c ctemp1.c ctemp2.c ; then
  491.     :
  492. else
  493.     echo "What's with your compiler?  I'm giving up!"
  494.     rm -f myread $rmlist
  495.     exit 1
  496. fi
  497. if $cc -o ctemp ctemp1.o ctemp2.o >/dev/null 2>&1 ; then
  498.     echo 'Good, your C compiler understands long names.'
  499.     shortnames=0
  500. else
  501.     cat <<\!
  502. Your C compiler    appears to truncate external identifiers, so we will
  503. have to make sure all global identifiers are unique when truncated to
  504. six characters.
  505. !
  506.     shortnames=1
  507.     $cc -o ctemp ctemp1.o
  508. fi
  509.  
  510. : if not ansi C, check for volatile support
  511. if ./ctemp ; then
  512.     echo "Your C compiler claims to be ANSI, so I'll assume it understands volatile"
  513.     volatile=ansi
  514. else
  515.     cat > ctemp2.c <<\!
  516. main() {
  517.     volatile int x;
  518.     x = 0;
  519.     return x;
  520. }
  521. !
  522.     echo " "
  523.     if $cc -c ctemp2.c >/dev/null 2>&1 ; then
  524.     echo "Your C compiler accepts the volatile keyword even though it's not ANSI."
  525.     volatile=yes
  526.     else
  527.     echo "Your C compiler doesn't have (and presumably doesn't need) the"
  528.     echo "volatile keyword."
  529.     volatile=no
  530.     fi
  531. fi
  532. rm -f ctemp1.c ctemp2.c ctemp1.o ctemp2.o ctemp
  533.  
  534. echo " "
  535. if test "`(cd //; pwd)`" = / ; then
  536.     echo "You appear to have a fairly normal UNIX file system."
  537. else
  538.     cat <<\!
  539. Your file system appears to interpret // at the start of a file name
  540. differently from a single slash at the start of the file name, which
  541. will probably cause the pwd command to malfunction.  This problem hasn't
  542. been fixed because the writer of ash (Kenneth Almquist) doesn't have
  543. access to any systems that behave this way.  You can probably get a
  544. version of pwd for your system in return for a description of how your
  545. system interprets file names and a promise to test out the code.  In
  546. !
  547.     echo $n "the mean time, type return to continue...$c"
  548.     rp="Type return to continue:"
  549.     . myread
  550. fi
  551.  
  552.  
  553. : Now create shell.h
  554. echo " "
  555. echo $n "Creating shell.h...$c"
  556.  
  557. cat > shell.h <<\!
  558. /*
  559.  * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
  560.  * This file is part of ash, which is distributed under the terms specified
  561.  * by the Ash General Public License.  See the file named LICENSE.
  562.  */
  563.  
  564. /*
  565.  * The follow should be set to reflect the type of system you have:
  566.  *    JOBS -> 1 if you have Berkeley job control, 0 otherwise.
  567.  *    SYMLINKS -> 1 if your system includes symbolic links, 0 otherwise.
  568.  *    DIRENT -> 1 if your system has the SVR3 directory(3X) routines.
  569.  *    UDIR -> 1 if you want the shell to simulate the /u directory.
  570.  *    ATTY -> 1 to include code for atty(1).
  571.  *    SHORTNAMES -> 1 if your linker cannot handle long names.
  572.  *    define BSD if you are running 4.2 BSD or later.
  573.  *    define SYSV if you are running under System V.
  574.  *    define DEBUG to turn on debugging.
  575.  *
  576.  * When debugging is on, debugging info will be written to $HOME/trace and
  577.  * a quit signal will generate a core dump.
  578.  */
  579.  
  580.  
  581. !
  582. echo "#define JOBS $jobs" >>shell.h
  583. echo "#define SYMLINKS $symlinks" >>shell.h
  584. echo "#define DIRENT $dirent" >>shell.h
  585. echo "#define UDIR $udir" >>shell.h
  586. echo "#define ATTY $atty" >>shell.h
  587. echo "#define SHORTNAMES $shortnames" >>shell.h
  588. if test $systype = bsd ; then
  589.     echo "#define BSD" >>shell.h
  590. else
  591.     echo "/* #define BSD */" >>shell.h
  592. fi
  593. if test $systype = sys5 ; then
  594.     echo "#define SYSV" >>shell.h
  595. else
  596.     echo "/* #define SYSV */" >>shell.h
  597. fi
  598. cat >> shell.h <<\!
  599. /* #define DEBUG */
  600.  
  601.  
  602.  
  603. #if SHORTNAMES
  604. #include "shortnames.h"
  605. #endif
  606.  
  607.  
  608. #ifdef __STDC__
  609. typedef void *pointer;
  610. #ifndef NULL
  611. #define NULL (void *)0
  612. #endif
  613. #else /* not __STDC__ */
  614. #define const
  615. !
  616. if test $volatile = yes ; then
  617.     echo "/* #define volatile */" >>shell.h
  618. else
  619.     echo "#define volatile" >>shell.h
  620. fi
  621. cat >> shell.h <<\!
  622. typedef char *pointer;
  623. #ifndef NULL
  624. #define NULL 0
  625. #endif
  626. #endif /* __STDC__ */
  627. #ifdef __GNUC__ /* Gcc lets us declare that functions don't return */
  628. #define noreturn volatile
  629. #else
  630. #define noreturn
  631. #endif
  632. #define STATIC    /* empty */
  633. #define MKINIT    /* empty */
  634.  
  635. extern char nullstr[1];        /* null string */
  636.  
  637.  
  638. #ifdef DEBUG
  639. #define TRACE(param)    trace param
  640. #else
  641. #define TRACE(param)
  642. #endif
  643. !
  644. echo done
  645.  
  646. : Now update the makefile
  647. echo " "
  648. echo "Editing makefile to reflect your choice of C compiler..."
  649.  
  650. chmod u+w makefile
  651. ed - makefile <<!
  652. /^#*CC=/s/.*/CC=$cc/p
  653. w
  654. q
  655. !
  656. echo done
  657.  
  658. echo " "
  659. echo "Edit shell.h by hand if you want to make any changes."
  660. echo "Then run make."
  661.  
  662. rm -f myread $rmlist
  663. EOF
  664. if test `wc -c < config` -ne 14098
  665. then    echo 'config is the wrong size'
  666. fi
  667. chmod +x config
  668.  
  669. echo 'Archive unpacked'
  670. exit 0
  671.