home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / abc / part09 < prev    next >
Encoding:
Internet Message Format  |  1991-01-08  |  54.8 KB

  1. Subject:  v23i088:  ABC interactive programming environment, Part09/25
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 062f77c0 fd8773f3 795acca7 22333ca1
  5.  
  6. Submitted-by: Steven Pemberton <steven@cwi.nl>
  7. Posting-number: Volume 23, Issue 88
  8. Archive-name: abc/part09
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  abc/Setup abc/bed/e1sugg.c abc/bint2/i2exp.c
  17. #   abc/scripts/mkdep.gen
  18. # Wrapped by rsalz@litchi.bbn.com on Mon Dec 17 13:28:00 1990
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. echo If this archive is complete, you will see the following message:
  21. echo '          "shar: End of archive 9 (of 25)."'
  22. if test -f 'abc/Setup' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'abc/Setup'\"
  24. else
  25.   echo shar: Extracting \"'abc/Setup'\" \(18623 characters\)
  26.   sed "s/^X//" >'abc/Setup' <<'END_OF_FILE'
  27. X: 'Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1988.'
  28. X
  29. Xecho "Configuration questions for the ABC system."
  30. X
  31. X: some greps do not return status, fix this first.
  32. Xecho "grimblepritz" >grimble
  33. Xif grep blurfldyick grimble >/dev/null 2>&1 ; then
  34. X    contains=./contains
  35. Xelse
  36. X    if grep grimblepritz grimble >/dev/null 2>&1 ; then
  37. X        contains=grep
  38. X    else
  39. X        contains=./contains
  40. X    fi
  41. Xfi
  42. Xrm grimble
  43. X: the following should work in any shell
  44. Xcase $contains in
  45. X./contains)
  46. X    echo " "
  47. X    echo "Grep doesn't return a status; attempting remedial action."
  48. X    cat >contains <<'EOF'
  49. X    grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
  50. XEOF
  51. X    chmod 755 ./contains;;
  52. Xesac
  53. X
  54. X: 'Determine if echo -n works'
  55. Xecho -n "bleep" >bleep
  56. Xif $contains n bleep >/dev/null 2>&1
  57. Xthen
  58. X    n=""
  59. Xelse
  60. X    n="-n"
  61. Xfi
  62. Xrm -f bleep
  63. X
  64. X: 'Get answers from previous run'
  65. Xif test -r answers
  66. Xthen
  67. X    . answers
  68. Xelse
  69. X    rootdef="/tmp/abc"
  70. X    abcdef="/usr/new"
  71. X    libdef="/usr/new/lib/abc"
  72. X    mandef="/usr/man/mann"
  73. Xfi
  74. X
  75. X: 'Are we preparing for cross compilation?'
  76. Xecho " "
  77. Xecho $n "Are you going to cross-compile the ABC system to a remote machine? "
  78. Xread ans
  79. Xcase $ans in
  80. Xy*|Y*|t*|T*)
  81. Xremote=" remote"
  82. Xrootdir='blurfl'
  83. Xwhile test ! -d "$rootdir" ; do
  84. X    case $rootdir in
  85. X    blurfl)
  86. X        echo " "
  87. X        echo "Then please type the full pathname of a local directory"
  88. X        echo "where you have write permission"
  89. X        echo "and which we can use as a local root to install"
  90. X        echo "the ABC system for you to copy to the remote machine"
  91. X        echo $n " (default $rootdef) "
  92. X        ;;
  93. X    *)     echo "$rootdir does not appear to exist."
  94. X        echo $n "Are you sure you typed the right name? "
  95. X        read ans
  96. X        case $ans in
  97. X        y*|Y*)    echo "Don't forget to make $rootdir before 'make install'."
  98. X            break
  99. X            ;;
  100. X        *)    echo " "
  101. X            echo $n "Please try again (default $rootdef) "
  102. X            ;;
  103. X        esac
  104. X        ;;
  105. X    esac
  106. X    read rootdir
  107. X    case $rootdir in
  108. X    "") rootdir=$rootdef;;
  109. X    esac
  110. Xdone
  111. X;;
  112. X*)
  113. Xremote=""
  114. Xrootdir=""
  115. X;;
  116. Xesac
  117. X
  118. X: 'What unix?'
  119. Xecho " "
  120. Xecho $n "Finding out about your brand of unix ... "
  121. Xcat >brand.c <<EOF
  122. X#include <stdio.h>
  123. X#include <signal.h>
  124. Xmain() {
  125. X#ifdef SIGCHLD
  126. X#ifdef SIGVTALRM
  127. X    printf("BSD4_2\n");
  128. X#else
  129. X    printf("BSD\n");
  130. X#endif
  131. X#else
  132. X#ifdef SIGCLD
  133. X    printf("ATT\n");
  134. X#else
  135. X    printf("unknown\n"); /* Version 7 we hope ... */
  136. X#endif
  137. X#endif
  138. X}
  139. XEOF
  140. Xcc brand.c -o brand
  141. Xunix=`./brand`
  142. Xrm -f brand*
  143. X
  144. Xecho " "
  145. Xcase $unix in
  146. XBSD4_2)
  147. X    echo "You appear to be running Berkeley's BSD unix, version 4.2 (or later)."
  148. X    echo $n "Is this true? "
  149. X    read ans
  150. X    case $ans in
  151. X    n*|N*|f*|F*)    unix="unknown";;
  152. X    esac
  153. X    ;;
  154. XBSD)
  155. X    echo "You appear to be running Berkeley's BSD unix."
  156. X    echo $n "Is this true? "
  157. X    read ans
  158. X    case $ans in
  159. X    n*|N*|f*|F*)    unix="unknown";;
  160. X    esac
  161. X    ;;
  162. XATT)
  163. X    echo "You appear to be running ATT's System III or System V unix."
  164. X    echo $n "Is this true? "
  165. X    read ans
  166. X    case $ans in
  167. X    n*|N*|f*|F*)    unix="unknown";;
  168. X    esac
  169. X    ;;
  170. Xesac
  171. X
  172. Xcase $unix in
  173. Xunknown)
  174. X    echo "You might be running VERSION 7 unix."
  175. X    echo $n "Is this true? "
  176. X    read ans
  177. X    case $ans in
  178. X    y*|Y*|t*|T*)
  179. X        unix=VERSION7;;
  180. X    *)    echo "We cannot find out what type of unix you are running."
  181. X        echo "See ./uhdrs/*.h and ./Problems in case of problems."
  182. X        unix=""
  183. X        ;;
  184. X    esac
  185. X    ;;
  186. Xesac
  187. X
  188. X: 'termio system?'
  189. Xecho " "
  190. Xecho $n "Checking for termio system ... "
  191. Xtermio=""
  192. Xcase $unix in
  193. XATT)    if test -r /usr/include/termio.h
  194. X    then
  195. X        termio="#define"
  196. X        echo "termio.h found."
  197. X    elif test -r /usr/include/sgtty.h
  198. X    then
  199. X        termio="#undef"
  200. X        echo "sgtty.h found."
  201. X    fi
  202. X    ;;
  203. X*)    if test -r /usr/include/sgtty.h
  204. X    then
  205. X        termio="#undef "
  206. X        echo "sgtty.h found."
  207. X    elif test -r /usr/include/termio.h
  208. X    then
  209. X        termio="#define"
  210. X        echo "termio.h found."
  211. X    fi
  212. X    ;;
  213. Xesac
  214. Xcase $termio in
  215. X'')    echo " "
  216. X    echo "Neither termio.h nor sgtty.h found."
  217. X    echo "See ./unix/u1trm.c, ./unix/u1keys.c and ./keys/abckeys.c"
  218. X    echo "in case of problems."
  219. X    termio="#undef "
  220. Xesac
  221. X
  222. X: 'Include <strings.h> or <string.h>?'
  223. Xecho " "
  224. Xecho $n "Finding include file for string operations ... "
  225. Xif test -r /usr/include/strings.h
  226. Xthen
  227. X    strs="<strings.h>"
  228. X    echo "strings.h found."
  229. Xelse
  230. X    if test -r /usr/include/string.h
  231. X    then
  232. X        strs="<string.h>"
  233. X        echo "string.h found."
  234. X    else
  235. X        strs="no_strs"
  236. X        echo " "
  237. X        echo "Neither strings.h nor string.h found."
  238. X        echo "We will add some external definitions to ./uhdrs/os.h."
  239. X    fi
  240. Xfi
  241. X
  242. X: 'Some ATT System V have <unistd.h> for <sys/file.h>'
  243. X: 'Some systems have both and may need either one, so we must check'
  244. Xecho " "
  245. Xecho $n "Finding include file for access modes ... "
  246. Xif $contains F_OK /usr/include/sys/file.h >/dev/null 2>&1
  247. Xthen
  248. X    modes="<sys/file.h>"
  249. X    echo "proper sys/file.h found."
  250. Xelse
  251. X    if $contains F_OK /usr/include/unistd.h >/dev/null 2>&1
  252. X    then
  253. X        modes="<unistd.h>"
  254. X        echo "proper unistd.h found."
  255. X    else
  256. X        modes="no_modes"
  257. X        echo " "
  258. X        echo "No access mode definitions found in sys/file.h or unistd.h."
  259. X        echo "We will substitute our own definitions in ./uhdrs/os.h."
  260. X    fi
  261. Xfi
  262. X
  263. X: 'Some Berkeley systems (and the PC:-) have ftime(), including <sys/timeb.h>'
  264. Xecho " "
  265. Xecho $n "Finding include file for ftime(3) ... "
  266. Xif test -r /usr/include/sys/timeb.h
  267. Xthen
  268. X    ftime="#define"
  269. X    echo "sys/timeb.h found."
  270. Xelse
  271. X    ftime="#undef "
  272. X    echo " "
  273. X    echo "No sys/timeb.h found."
  274. X    echo "We will assume ftime(3) is not available in ./uhdrs/os.h."
  275. X    echo "The ABC function \"now\" will only return entire seconds."
  276. Xfi
  277. X
  278. X: 'Check for void type'
  279. Xecho " "
  280. Xecho $n "Checking to see if your compiler accepts the void type ... "
  281. Xcat >void.c << EOF
  282. Xvoid main();
  283. XEOF
  284. Xif cc -c void.c >/dev/null 2>&1
  285. Xthen
  286. X    void="(void)"
  287. X    echo "yes, it does."
  288. Xelse
  289. X    void="      "
  290. X    echo "no, it doesn't."
  291. X    echo "We will use an empty VOID in casts."
  292. Xfi
  293. Xrm -f void.c void.o
  294. X
  295. X: 'Determine type for signal handlers'
  296. Xcase $void in
  297. X"(void)")
  298. Xecho " "
  299. Xecho $n "Finding type for signal handlers ... "
  300. Xecho "#include <signal.h>" >sigtype.c
  301. Xecho "main() { void (*oldsig)(); oldsig= signal(SIGINT, SIG_IGN); }" >>sigtype.c
  302. Xcc -c sigtype.c >warnings 2>&1
  303. Xif test -s warnings
  304. Xthen
  305. X    sigtype=int
  306. X    echo "assuming int."
  307. Xelse
  308. X    sigtype=void
  309. X    echo "found void."
  310. Xfi
  311. Xrm -f sigtype.c sigtype.o warnings
  312. X;;
  313. X*)    sigtype=int;;
  314. Xesac
  315. X
  316. X: 'Floating point arithmetic ok?'
  317. Xecho " "
  318. Xcase $remote in
  319. X" remote")
  320. Xecho "Does your C compiler need a special flag for"
  321. Xecho $n "loading (probably software) floating point routines? "
  322. Xread ans
  323. Xcase $ans in
  324. Xy*|Y*)    echo $n "What flag is needed (default -f) "
  325. X    read fflag
  326. X    case $fflag in
  327. X    '')    fflag="-f";;
  328. X    esac
  329. X    echo "We will try $fflag."
  330. X    ;;
  331. X*)    echo "Assuming no flag is needed."
  332. X    fflag=
  333. X    ;;
  334. Xesac
  335. X;;
  336. X*)
  337. Xecho $n "Checking your floating point ... "
  338. Xcat >float.c <<EOF
  339. X#include <stdio.h>
  340. Xdouble dadd(a, b) double a, b; {
  341. X    return a+b;
  342. X}
  343. Xmain() {
  344. X    double a, b, c;
  345. X    double dadd();
  346. X    a = 3.14;
  347. X    b = 2.7 * a;
  348. X    c = dadd(a, b);
  349. X    exit(0);
  350. X}
  351. XEOF
  352. Xcc -O float.c -o float >/dev/null 2>&1
  353. Xecho " "
  354. Xif sh 2>/dev/null <<EOF
  355. X    if ./float
  356. X    then exit 0
  357. X    else exit 1
  358. X    fi
  359. XEOF
  360. Xthen
  361. X    echo "Your floating point seems to be alright."
  362. X    fflag=""
  363. Xelse
  364. X    echo "Your C compiler seems to need a special flag for"
  365. X    echo "loading (probably software) floating point routines."
  366. X    echo $n "What flag is needed (default -f) "
  367. X    read fflag
  368. X    case $fflag in
  369. X    '')    fflag="-f";;
  370. X    esac
  371. X    cc -O $fflag float.c -o float >/dev/null 2>&1
  372. X    until sh 2>/dev/null <<EOF
  373. X        if ./float
  374. X        then echo "Flag $fflag seems to be allright."
  375. X             exit 0
  376. X        else exit 1
  377. X        fi
  378. XEOF
  379. X    do
  380. X        echo "This flag doesn't seem to work."
  381. X        echo "Try again ([RETURN] to give up) "
  382. X        read fflag
  383. X        case $fflag in
  384. X        '')    echo "Giving up on floating point flag"
  385. X            break;;
  386. X        esac
  387. X        cc -O $fflag float.c -o float >/dev/null 2>&1
  388. X    done
  389. Xfi
  390. Xrm -f float* core
  391. X;;
  392. Xesac
  393. X
  394. X: 'termcap library for ABC editor'
  395. Xecho " "
  396. Xecho $n "Searching for your termcap-like library routines ... "
  397. Xif test -r /lib/libtermcap.a -o -r /usr/lib/libtermcap.a
  398. Xthen
  399. X    termlib="-ltermcap"
  400. X    echo "termcap library found."
  401. Xelif test -r /usr/local/lib/libtermcap.a
  402. Xthen
  403. X    termlib="/usr/local/lib/libtermcap.a"
  404. X    echo "local termcap library found."
  405. Xelif test -r /lib/libcurses.a -o -r /usr/lib/libcurses.a
  406. Xthen
  407. X    termlib="-lcurses"
  408. X    echo "terminfo library found."
  409. Xelif test -r /usr/local/lib/libcurses.a
  410. Xthen
  411. X    termlib="/usr/local/lib/libcurses.a"
  412. X    echo "local terminfo library found."
  413. Xelif test -r /lib/libtermlib.a -o -r /usr/lib/libtermlib.a
  414. Xthen
  415. X    termlib="-ltermlib"
  416. X    echo "termlib library found."
  417. Xelif test -r /usr/local/lib/libtermlib.a
  418. Xthen
  419. X    termlib="/usr/local/lib/libtermlib.a"
  420. X    echo "local termlib library found."
  421. Xelse
  422. X    echo " "
  423. X    echo "Your system appears NOT to have any termcap-like library."
  424. X    echo $n "Is this true? "
  425. X    read ans
  426. X    case $ans in
  427. X    n*|N*|f*|F*)    termlib="ask_it"
  428. X        ;;
  429. X    *)    termlib="libtermcap.a"
  430. X        cat <<\EOF
  431. XWe will setup ./Makefile to use the public domain version of the
  432. Xtermcap routines from ./tc. Your users must set the $TERMCAP and
  433. X$TERM environment variables appropriately in their profile; or you
  434. Xcan install shell scripts that arrange these.
  435. XHowever, it would be better if your system administrator installs
  436. Xtermcap in the proper places. You should run Setup again after she
  437. Xhas done so.
  438. XSee ./tc/README for details.
  439. XEOF
  440. X        ;;
  441. X    esac
  442. Xfi
  443. Xwhile test "$termlib" = "ask_it" -o "$termlib" = "try_again"; do
  444. X    case $termlib in
  445. X    ask_it)
  446. X        echo " "
  447. X        echo "Please specify where the termcap-like routines are kept"
  448. X        echo $n " (either full pathname or -lxxx option) "
  449. X        ;;
  450. X    try_again)
  451. X        echo $n "Please try again (full pathname or -lyyy option) "
  452. X        ;;
  453. X    esac
  454. X    read termlib
  455. X    case $termlib in
  456. X    -l*)
  457. X        echo "Hope $termlib will do the job."
  458. X        ;;
  459. X    /*)
  460. X        if test -r $termlib
  461. X        then
  462. X            echo "Ok, we will try $termlib."
  463. X        else
  464. X            echo "$termlib does not appear to exist."
  465. X            termlib="try_again"
  466. X        fi
  467. X        ;;
  468. X    *)
  469. X        echo "$termlib is not a valid library specification."
  470. X        termlib="try_again"
  471. X        ;;
  472. X    esac
  473. Xdone
  474. X
  475. X: 'find C preprocessor for ./scripts/mkdep'
  476. Xecho " "
  477. Xecho 'Checking if we can use "cc -M" for generating dependency information ... '
  478. Xcc -M -Iuhdrs mkconfig.c >testcpp.out 2>&1
  479. Xif $contains 'mkconfig.o: *uhdrs/osconf.h' testcpp.out >/dev/null 2>&1 ; then
  480. X    echo "Yes, we can."
  481. X    cpp='REDUNDANT'
  482. X    mkdep="\$(CC) -M \$(DEFS)"
  483. Xelse
  484. X    echo "No, we can't; we will try to use ./scripts/mkdep for \"make depend\"."
  485. X    mkdep="../scripts/mkdep \$(DEFS)"
  486. X    echo "Checking to see how your C preprocessor is invoked ... "
  487. X    cpp=''
  488. Xcat <<'EOT' >testcpp.c
  489. X#define ABC abc
  490. X#define XYZ xyz
  491. XABC+XYZ
  492. XEOT
  493. X    echo 'Maybe "cc -E" will work ...'
  494. X    cc -E testcpp.c >testcpp.out 2>&1
  495. X    if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
  496. X        echo "Yes, it does."
  497. X        cpp='cc -E'
  498. X    else
  499. X        echo 'No ... maybe "cc -P" will work ...'
  500. X        cc -P testcpp.c >testcpp.out 2>&1
  501. X        if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
  502. X            echo "Yes, that does."
  503. X            cpp='cc -P'
  504. X        else
  505. X            echo 'Wrong again ... maybe "/lib/cpp" will work ...'
  506. X            /lib/cpp testcpp.c >testcpp.out 2>&1
  507. X            if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1
  508. X            then     echo "Hooray, it works!  I was beginning to wonder."
  509. X                cpp='/lib/cpp'
  510. X            else
  511. X    echo $n "No. I can't find a C preprocessor.  Name one: "
  512. X    read cpp
  513. X    until sh 2>/dev/null <<EOF
  514. X$cpp testcpp.c >testcpp.out 2>&1
  515. Xif $contains 'abc+xyz' testcpp.out >/dev/null 2>&1
  516. Xthen exit 0
  517. Xelse exit 1
  518. Xfi
  519. XEOF
  520. X    do
  521. X        echo "Sorry, I can't get that to work."
  522. X        echo "Try again ([RETURN] to give up) "
  523. X        read cpp
  524. X        case $cpp in
  525. X        '')    : giving up
  526. X            break;;
  527. X        esac
  528. X    done
  529. X            fi
  530. X        fi
  531. X    fi
  532. Xfi
  533. Xrm -f testcpp.*
  534. X
  535. Xcase $cpp in
  536. XREDUNDANT) : no mkdep needed
  537. X    ;;
  538. X'')    cat <<EOF
  539. XGiving up on C preprocessor.
  540. XYou have to adapt the shell script ./scripts/mkdep yourself;
  541. Xsee the comment at its head.
  542. XEOF
  543. X    ;;
  544. X*)
  545. X    cat <<EOF
  546. XWe will change the name of the C preprocessor to "$cpp"
  547. Xin ./scripts/mkdep (used by 'make depend').
  548. XBut you still may have problems with the format of the lines that the
  549. Xpreprocessor creates for '#include' statements; see the comment at the
  550. Xstart of ./scripts/mkdep.
  551. XIf you can't get 'make depend' to work see ./Problems for a workaround.
  552. XEOF
  553. X    ;;
  554. Xesac
  555. X
  556. X: 'Shall we make ABC public?'
  557. Xpublic="no"
  558. Xecho " "
  559. Xecho $n "Do you want to make ABC publically available? "
  560. Xread ans
  561. Xcase $ans in
  562. Xy*|Y*)
  563. Xpublic="yes"
  564. Xabcdir='blurfl'
  565. Xwhile test ! -d "$rootdir$abcdir" ; do
  566. X    case $abcdir in
  567. X    blurfl)
  568. X        echo " "
  569. X        echo "Please type the full pathname of a$remote directory"
  570. X        echo "in which you have write permission, and where you"
  571. X        echo "want the binaries 'abc' and 'abckeys' installed"
  572. X        echo $n " (default $abcdef) "
  573. X        ;;
  574. X    *)     echo "$rootdir$abcdir does not appear to exist."
  575. X        echo $n "Are you sure you typed the right name? "
  576. X        read ans
  577. X        case $ans in
  578. X        y*|Y*)    echo "Don't forget to make $rootdir$abcdir before 'make install'."
  579. X            break
  580. X            ;;
  581. X        *)    echo " "
  582. X            echo $n "Please try again (default $abcdef) "
  583. X            ;;
  584. X        esac
  585. X        ;;
  586. X    esac
  587. X    read abcdir
  588. X    case $abcdir in
  589. X    "") abcdir=$abcdef;;
  590. X    esac
  591. Xdone
  592. Xlibdir='blurfl'
  593. Xwhile test ! -d "$rootdir$libdir" ; do
  594. X    case $libdir in
  595. X    blurfl)
  596. X        echo " "
  597. X        echo "Please type the full pathname of the$remote directory"
  598. X        echo "where you want to install the auxiliary datafiles"
  599. X        echo "needed by the ABC system"
  600. X        echo $n " (default $libdef) "
  601. X        ;;
  602. X    *)     echo "$rootdir$libdir does not appear to exist."
  603. X        echo $n "Are you sure you typed the right name? "
  604. X        read ans
  605. X        case $ans in
  606. X        y*|Y*)    echo "Don't forget to make $rootdir$libdir before 'make install'."
  607. X            break
  608. X            ;;
  609. X        *)    echo " "
  610. X            echo $n "Please try again (default $libdef) "
  611. X            ;;
  612. X        esac
  613. X        ;;
  614. X    esac
  615. X    read libdir
  616. X    case $libdir in
  617. X    "") libdir=$libdef;;
  618. X    esac
  619. Xdone
  620. Xmandir='blurfl'
  621. Xwhile test ! -d "$rootdir$mandir" ; do
  622. X    case $mandir in
  623. X    blurfl)
  624. X        echo " "
  625. X        echo "Please type the full pathname of the$remote directory"
  626. X        echo "where you want to install the 'abc.1' manual page"
  627. X        echo $n " (default $mandef) "
  628. X        ;;
  629. X    *)     echo "$rootdir$mandir does not appear to exist."
  630. X        echo $n "Are you sure you typed the right name? "
  631. X        read ans
  632. X        case $ans in
  633. X        y*|Y*)    echo "Don't forget to make $rootdir$mandir before 'make install'."
  634. X            break
  635. X            ;;
  636. X        *)    echo " "
  637. X            echo $n "Please try again (default $mandef) "
  638. X            ;;
  639. X        esac
  640. X        ;;
  641. X    esac
  642. X    read mandir
  643. X    case $mandir in
  644. X    "") mandir=$mandef;;
  645. X    esac
  646. Xdone
  647. X;;
  648. X*)
  649. Xabcdir="$abcdef"
  650. Xlibdir="$libdef"
  651. Xmandir="$mandef"
  652. X;;
  653. Xesac
  654. X
  655. Xcat >answers <<EOF
  656. Xrootdef="$rootdir"
  657. Xabcdef="$abcdir"
  658. Xlibdef="$libdir"
  659. Xmandef="$mandir"
  660. XEOF
  661. X
  662. Xecho " "
  663. Xecho "End of configuration questions for the ABC system."
  664. X
  665. Xrm -f ./contains
  666. X
  667. Xeditor="ed -"
  668. X
  669. X: 'Getting generic copies of Makefile, uhdrs/os.h, and scripts/mkdep.'
  670. X: 'Since some tars leave the owner of the tape as the owner of the files'
  671. X: 'this will make sure the edit scripts will not fail.'
  672. X
  673. Xecho " "
  674. Xecho "Creating Makefile from Makefile.unix."
  675. X
  676. Xcat >Makefile <<EOF
  677. X# This file was generated and edited by the Setup command.
  678. X# To make lasting changes edit the files Makefile.unix and Setup,
  679. X# and run Setup again.
  680. X# 
  681. XEOF
  682. Xchmod 644 Makefile
  683. Xcat Makefile.unix >>Makefile
  684. X
  685. Xecho "Creating uhdrs/os.h from uhdrs/os.h.gen."
  686. X
  687. Xcat >uhdrs/os.h <<EOF
  688. X/* This file was generated and edited by the Setup command. */
  689. X/* To make lasting changes edit the files uhdrs/os.h.gen and Setup, */
  690. X/* and run Setup again. */
  691. X
  692. XEOF
  693. Xchmod 644 uhdrs/os.h
  694. Xcat uhdrs/os.h.gen >>uhdrs/os.h
  695. X
  696. Xecho "Creating scripts/mkdep from scripts/mkdep.gen."
  697. X
  698. Xcat >scripts/mkdep <<EOF
  699. X: This file was generated from scripts/mkdep.gen by Setup
  700. X:
  701. XEOF
  702. Xchmod 755 scripts/mkdep
  703. Xcat scripts/mkdep.gen >>scripts/mkdep
  704. X
  705. Xecho " "
  706. Xecho $n "Editing appropriate definitions in these files ... "
  707. X
  708. Xcase $unix in
  709. XBSD4_2)
  710. X    make="make \$(MFLAGS)"
  711. X    strchr="index"
  712. X    perror="#define"
  713. X    mkdir="#define"
  714. X    getwd="#define"
  715. X    rename="#define"
  716. X    select="#define"
  717. X    readdir="#define"
  718. X    ;;
  719. XBSD)    make="make \$(MFLAGS)"
  720. X    strchr="index"
  721. X    perror="#define"
  722. X    mkdir="#undef "
  723. X    getwd="#undef "
  724. X    rename="#undef "
  725. X    select="#undef "
  726. X    readdir="#undef "
  727. X    ;;
  728. XATT)    make="make -\$(MAKEFLAGS)"
  729. X    strchr="strchr"
  730. X    perror="#define"
  731. X    mkdir="#define"
  732. X    getwd="#define"
  733. X    rename="#undef "
  734. X    select="#undef "
  735. X    readdir="#undef "
  736. X    ;;
  737. XVERSION7|*)
  738. X    make="make"
  739. X    strchr="index"
  740. X    perror="#undef "
  741. X    mkdir="#undef "
  742. X    getwd="#undef "
  743. X    rename="#undef "
  744. X    select="#undef "
  745. X    readdir="#undef "
  746. X    ;;
  747. Xesac
  748. X
  749. X$editor Makefile <<EOF
  750. X/^MAKE=/s?MAKE=.*?MAKE= $make?
  751. X/^FLOAT=/s?FLOAT=.*?FLOAT= $fflag?
  752. X/^MKDEP=/s?MKDEP=.*?MKDEP= $mkdep?
  753. X/^TERMLIB=/s?TERMLIB=.*?TERMLIB= $termlib?
  754. Xw
  755. Xq
  756. XEOF
  757. X
  758. Xcase $public in
  759. Xyes)
  760. X    $editor Makefile <<EOF
  761. X    /^DESTABC=/s?DESTABC=.*?DESTABC= $abcdir?
  762. X    /^DESTLIB=/s?DESTLIB=.*?DESTLIB= $libdir?
  763. X    /^DESTMAN=/s?DESTMAN=.*?DESTMAN= $mandir?
  764. X    w
  765. X    q
  766. XEOF
  767. X    ;;
  768. Xesac
  769. X
  770. X$editor uhdrs/os.h <<EOF
  771. X/^#include <strings.h>/s?<strings.h>?$strs?
  772. X/^#include <sys\/file.h>/s?<sys/file.h>?$modes?
  773. X/^#define VOID/s?(void)?$void?
  774. X/^#define SIGTYPE/s?int?$sigtype?
  775. X/^#undef  TERMIO/s?#undef ?$termio?
  776. X/^#define HAS_FTIME/s?#define?$ftime?
  777. X/^#define HAS_PERROR/s?#define?$perror?
  778. X/^#define HAS_MKDIR/s?#define?$mkdir?
  779. X/^#define HAS_GETWD/s?#define?$getwd?
  780. X/^#define HAS_RENAME/s?#define?$rename?
  781. X/^#define HAS_SELECT/s?#define?$select?
  782. X/^#define HAS_READDIR/s?#define?$readdir?
  783. Xw
  784. Xq
  785. XEOF
  786. X
  787. Xcase $strs in
  788. Xno_strs)
  789. X    case $strchr in
  790. X    "index")    index=index; rindex=rindex;;
  791. X    "strchr")    index=strchr; rindex=strrchr;;
  792. X    esac
  793. X    $editor uhdrs/os.h <<EOF
  794. X/#include no_strs/c
  795. X
  796. Xextern char *strcat();
  797. Xextern int strcmp();
  798. Xextern int strncmp();
  799. Xextern char *strcpy();
  800. Xextern char *strncpy();
  801. Xextern int strlen();
  802. Xextern char *$index();
  803. Xextern char *$rindex();
  804. X
  805. X.
  806. Xw
  807. Xq
  808. XEOF
  809. X;;
  810. Xesac
  811. X
  812. Xcase $modes in
  813. Xno_modes)
  814. X    $editor uhdrs/os.h <<EOF
  815. X/#include no_modes/c
  816. X
  817. X#define R_OK 4
  818. X#define W_OK 2
  819. X#define F_OK 0
  820. X.
  821. Xw
  822. Xq
  823. XEOF
  824. X;;
  825. Xesac
  826. X
  827. Xcase $strchr in
  828. Xstrchr)    $editor uhdrs/os.h <<EOF
  829. X/#define strchr/,/#define strrchr/d
  830. Xw
  831. Xq
  832. XEOF
  833. X;;
  834. Xesac
  835. X
  836. Xcase $unix in
  837. XATT)    $editor uhdrs/os.h <<EOF
  838. X/#define HAS_GETWD/a
  839. X#define getwd(path) getcwd(path, SIZE_PATH)
  840. X.
  841. Xw
  842. Xq
  843. XEOF
  844. X;;
  845. Xesac
  846. X
  847. Xcase $termlib in
  848. Xlibtermcap.a)
  849. X    $editor Makefile <<EOF
  850. X    /TERMLIB=/s?.*?TERMLIB=?
  851. X    /#OWNTLIB=/s?#??
  852. X    /#KOWNTLIB=/s?#??
  853. X    /#OWNTBASE=/s?#??
  854. X    w
  855. X    q
  856. XEOF
  857. X    ;;
  858. Xesac
  859. X
  860. Xcase $cpp in
  861. XREDUNDANT) : no mkdep needed
  862. X    ;;
  863. X'')    : do it yourself message given above
  864. X    ;;
  865. X*)
  866. X    $editor scripts/mkdep <<EOF
  867. X    /^CPP=/s?.*?CPP="$cpp"?
  868. X    w
  869. X    q
  870. XEOF
  871. X    ;;
  872. Xesac
  873. X
  874. Xecho $n " "
  875. Xecho "done."
  876. X
  877. Xecho " "
  878. Xecho "This completes the setup of the ABC system."
  879. X
  880. Xcase $remote in
  881. X' remote')
  882. X    cat <<EOF
  883. XYou should first compile mkconfig (from ./mkconfig.c and ./uhdrs/os.h)
  884. Xwith 'make mkconfig' here, run it on the remote machine and copy the
  885. Xresult to ./uhdrs/config.h.
  886. XAfter that you can proceed here with 'make makefiles'.
  887. XEOF
  888. X    ;;
  889. X*)    echo "You can now try 'make makefiles'."
  890. X    ;;
  891. Xesac
  892. X
  893. Xcase $remote in
  894. X" remote")
  895. X    if test ! -d "$rootdir"
  896. X    then
  897. X        echo " "
  898. X        echo "You should 'mkdir $rootdir' before 'make install'."
  899. X    fi
  900. X    ;;
  901. Xesac
  902. X
  903. Xcase $public in
  904. Xyes)
  905. X    if test ! -d "$rootdir$abcdir"
  906. X    then
  907. X        echo " "
  908. X        echo "You should 'mkdir $rootdir$abcdir' before 'make install'."
  909. X    fi
  910. X    if test ! -d "$rootdir$libdir"
  911. X    then
  912. X        echo "You should 'mkdir $rootdir$libdir' before 'make install'."
  913. X    fi
  914. X    if test ! -d "$rootdir$mandir"
  915. X    then
  916. X        echo "You should 'mkdir $rootdir$mandir' before 'make install'."
  917. X    fi
  918. X    ;;
  919. Xesac
  920. X
  921. Xexit 0
  922. END_OF_FILE
  923.   if test 18623 -ne `wc -c <'abc/Setup'`; then
  924.     echo shar: \"'abc/Setup'\" unpacked with wrong size!
  925.   fi
  926.   chmod +x 'abc/Setup'
  927.   # end of 'abc/Setup'
  928. fi
  929. if test -f 'abc/bed/e1sugg.c' -a "${1}" != "-c" ; then 
  930.   echo shar: Will not clobber existing file \"'abc/bed/e1sugg.c'\"
  931. else
  932.   echo shar: Extracting \"'abc/bed/e1sugg.c'\" \(17893 characters\)
  933.   sed "s/^X//" >'abc/bed/e1sugg.c' <<'END_OF_FILE'
  934. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  935. X
  936. X/*
  937. X * B editor -- Suggestion handling module.
  938. X */
  939. X
  940. X#include "b.h"
  941. X#include "feat.h"
  942. X
  943. X#ifdef USERSUGG
  944. X
  945. X#include "b0lan.h"
  946. X#include "bmem.h"
  947. X#include "bedi.h"
  948. X#include "etex.h"
  949. X#include "defs.h"
  950. X#include "bobj.h"
  951. X#include "bfil.h"
  952. X#include "node.h"
  953. X#include "supr.h"
  954. X#include "gram.h"
  955. X#include "tabl.h"
  956. X#include "queu.h"
  957. X#include "args.h"
  958. X
  959. Xextern bool lefttorite;
  960. X
  961. XHidden value *sugg;
  962. XHidden int *symsugg;
  963. XHidden int nsugg= 0;
  964. XHidden int maxnsugg= 0;
  965. XHidden int nbuiltin= 0;
  966. XHidden bool suggchanges;
  967. X
  968. X/*
  969. X * Read the suggestion table from file.
  970. X */
  971. X
  972. XHidden Procedure
  973. Xgetsugg()
  974. X{
  975. X    char *line;
  976. X    register FILE *fp;
  977. X    register c;
  978. X
  979. X    fp = fopen(suggfile, "r");
  980. X    if (!fp)
  981. X        return;
  982. X    while ((line= f_getline(fp)) != NULL) {
  983. X        addsugg(line, -1);
  984. X    }
  985. X    fclose(fp);
  986. X}
  987. X
  988. X/*
  989. X * Make sure a line looks like a suggestion, return No if not.
  990. X * Replace the trailing newline or comment-sign by a zero byte.
  991. X * ***** Should check more thoroughly. *****
  992. X */
  993. X
  994. XHidden bool
  995. Xchecksugg(bp)
  996. X    string bp;
  997. X{
  998. X    if (!isascii(*bp))
  999. X        return No;
  1000. X    if (isupper(*bp)) {
  1001. X        while (*bp && *bp != '\n' && *bp != '\\') {
  1002. X            if (maycontinue(*bp, KEYWORD)
  1003. X                || strchr(" ?:", *bp) != NULL)
  1004. X                ++bp;
  1005. X            else
  1006. X                return No;
  1007. X        }
  1008. X        *bp = 0;
  1009. X        return Yes;
  1010. X    }
  1011. X    else if (islower(*bp)) {
  1012. X        while (*bp && *bp != '\n' && *bp != '\\') {
  1013. X            if (maycontinue(*bp, NAME))
  1014. X                ++bp;
  1015. X            else
  1016. X                return No;
  1017. X        }
  1018. X        *bp = 0;
  1019. X        return Yes;
  1020. X    }
  1021. X}
  1022. X
  1023. X/*
  1024. X * check that first keyword not forbidden.
  1025. X * slight variation on bint2/i2syn.c
  1026. X */
  1027. X
  1028. XHidden char *firstkw[] = {
  1029. X    K_IF, K_WHILE, K_CHECK, K_HOW, K_RETURN, K_REPORT,
  1030. X    NULL
  1031. X};
  1032. X
  1033. XHidden bool res_firstkeyword(str) string str; {
  1034. X    char *fkw;
  1035. X    char *fkwend;
  1036. X    string *kw;
  1037. X    bool r= No;
  1038. X    
  1039. X    fkw= savestr(str);
  1040. X    if ((fkwend=strchr(fkw, ' ')) != NULL)
  1041. X        *fkwend= '\0';
  1042. X    for (kw= firstkw; *kw != NULL; kw++) {
  1043. X        if (strcmp(fkw, *kw) == 0) {
  1044. X            r= Yes;
  1045. X            break;
  1046. X        }
  1047. X    }
  1048. X    freestr(fkw);
  1049. X    return r;
  1050. X}
  1051. X
  1052. X/*
  1053. X * Procedure to add a suggestion to the suggestion table.
  1054. X * builtin > 0: adding builtin command with this Symbol value;
  1055. X *        these are inserted in order at the start of sugg[] table;
  1056. X * builtin == 0: adding new user defined command;
  1057. X *         these are inserted after builtin's, and kept sorted;
  1058. X * builtin == -1: adding user defined commands from suggestion file
  1059. X *          (already sorted!).
  1060. X */
  1061. X
  1062. XVisible Procedure
  1063. Xaddsugg(str, builtin)
  1064. X    string str;
  1065. X    int builtin;
  1066. X{
  1067. X    int i;
  1068. X    int j;
  1069. X    int len;
  1070. X    int cmp;
  1071. X    string suggi;
  1072. X    int where = (builtin == -1) ? nsugg : nbuiltin;
  1073. X
  1074. X    if (builtin <= 0 && (!checksugg(str) || res_firstkeyword(str)))
  1075. X        return;
  1076. X    for (    len = 0;
  1077. X        str[len] && (str[len] != ' ' || isupper(str[len+1]));
  1078. X        ++len)
  1079. X        ;
  1080. X    for (i = nsugg-1; i >= 0; --i) {
  1081. X        suggi = e_strval(sugg[i]);
  1082. X        cmp = strncmp(str, suggi, len);
  1083. X        if (cmp < 0)
  1084. X            continue;
  1085. X        if (cmp > 0) {
  1086. X            if (i >= where)
  1087. X                where = i+1;
  1088. X            continue;
  1089. X        }
  1090. X        if (suggi[len] 
  1091. X            &&
  1092. X            (suggi[len] != ' '
  1093. X             ||
  1094. X             (isascii(suggi[len+1]) && isupper(suggi[len+1]))
  1095. X            )
  1096. X        )
  1097. X            continue; /* No match, just prefix */
  1098. X        if (!strcmp(str+len, suggi+len))
  1099. X            return; /* Ignore exact duplicates */
  1100. X        if (i < nbuiltin)
  1101. X            return; /* Cannot replace built-in */
  1102. X        /* Replacement */
  1103. X        release(sugg[i]);
  1104. X        sugg[i] = mk_etext(str);
  1105. X        suggchanges = Yes;
  1106. X        return;
  1107. X    }
  1108. X    /* Insertion */
  1109. X    if (nsugg == 0) {
  1110. X        symsugg= (int*) getmem((unsigned) (MAXNBUILTIN * sizeof(int)));
  1111. X        sugg= (value*) getmem((unsigned) (NSUGGSIZE * sizeof(value)));
  1112. X        maxnsugg= NSUGGSIZE;
  1113. X    }
  1114. X    if (nsugg >= maxnsugg) {
  1115. X        regetmem((ptr*)&sugg,
  1116. X             (unsigned) ((maxnsugg+NSUGGSIZE) * sizeof(value)));
  1117. X        maxnsugg += NSUGGSIZE;
  1118. X    }
  1119. X    if (builtin > 0) {
  1120. X        symsugg[nbuiltin] = builtin;
  1121. X        ++nbuiltin;
  1122. X    }
  1123. X    for (j = nsugg; j > where; --j)
  1124. X        sugg[j] = sugg[j-1];
  1125. X    ++nsugg;
  1126. X    sugg[where] = mk_etext(str);
  1127. X    suggchanges = Yes;
  1128. X}
  1129. X
  1130. X
  1131. X/*
  1132. X * Procedure to delete a suggestion from the suggestion table.
  1133. X * Must supply the whole string as argument.
  1134. X */
  1135. X
  1136. XHidden Procedure
  1137. Xdelsugg(str)
  1138. X    string str;
  1139. X{
  1140. X    int i;
  1141. X
  1142. X    for (i = nbuiltin; i < nsugg; ++i) {
  1143. X        if (strcmp(str, e_strval(sugg[i])) == 0) {
  1144. X            release(sugg[i]);
  1145. X            --nsugg;
  1146. X            for (; i < nsugg; ++i)
  1147. X                sugg[i] = sugg[i+1];
  1148. X            suggchanges = Yes;
  1149. X            return;
  1150. X        }
  1151. X    }
  1152. X}
  1153. X
  1154. X#define CANT_FINISH  MESS(7000, "*** can't finish writing suggestion file [%s]")
  1155. X/*
  1156. X * Procedure to save the suggestion file if it has been changed.
  1157. X */
  1158. X
  1159. XHidden Procedure
  1160. Xsavsugg()
  1161. X{
  1162. X    FILE *fp;
  1163. X    int i;
  1164. X
  1165. X    if (!suggchanges)
  1166. X        return;
  1167. X    suggchanges = No;
  1168. X    fp = fopen(suggfile, "w");
  1169. X    if (!fp)
  1170. X        return;
  1171. X    for (i = nbuiltin; i < nsugg; ++i)
  1172. X        fprintf(fp, "%s\n", e_strval(sugg[i]));
  1173. X    if (fclose(fp) == EOF) {
  1174. X        ederrS(CANT_FINISH, suggfile);
  1175. X        return;
  1176. X    }
  1177. X    /* Remove the file if it's empty: */
  1178. X    if (nbuiltin >= nsugg) unlink(suggfile);
  1179. X}
  1180. X
  1181. X/*
  1182. X * Return a suitable suggestion which matches str for len characters,
  1183. X * followed by new_c.
  1184. X * First we lookup the last suggestion given to start the circular
  1185. X * search of the suggestion list from the next entry.
  1186. X * Before starting the search, we check that no entry exactly matches
  1187. X * the new string (only for sugghowname).
  1188. X * Nnil is returned if no entry matches.
  1189. X */
  1190. X
  1191. XHidden node nextsugg(str, len, new_c, in_sugghowname, colon_allowed)
  1192. Xstring str; int len; int new_c; bool in_sugghowname; bool colon_allowed;
  1193. X{
  1194. X    string sg;
  1195. X    int i;
  1196. X    int istop;
  1197. X    int lastisugg;
  1198. X    string sugg_i;
  1199. X    
  1200. X    lastisugg= findsugg(str);
  1201. X    
  1202. X    str[len]= new_c;
  1203. X    
  1204. X    if (in_sugghowname) {
  1205. X        /* if howname matches exactly, return that one */
  1206. X        /* since [newline] acknowledges entire howname */
  1207. X        for (i= nbuiltin; i < nsugg; i++) {
  1208. X            sg= e_strval(sugg[i]);
  1209. X            if (strncmp(str, sg, len+1) == 0) {
  1210. X                if (sg[len+1] == '\0'
  1211. X                    || (sg[len+1] == ' ' && sg[len+2] == '?'))
  1212. X                {
  1213. X                    /* exact match */
  1214. X                    return (node) sugg[i];
  1215. X                }
  1216. X                else 
  1217. X                    break;
  1218. X                    /* to find nextsugg from lastisugg */
  1219. X            }
  1220. X        }
  1221. X    }
  1222. X    i= lastisugg+1;
  1223. X    if (in_sugghowname && i < nbuiltin) {
  1224. X        i= nbuiltin;
  1225. X        istop= nsugg;
  1226. X    }
  1227. X    else if (i == 0)
  1228. X        istop= nsugg;
  1229. X    else
  1230. X        istop= i;
  1231. X    do {
  1232. X        if (i == nsugg) i= (in_sugghowname ? nbuiltin : 0);
  1233. X        sugg_i= e_strval(sugg[i]);
  1234. X        if (strncmp(str, sugg_i, len+1) == 0) {
  1235. X            if (colon_allowed || strchr(sugg_i, ':') == NULL)
  1236. X                return (node) sugg[i];
  1237. X        }
  1238. X        ++i;
  1239. X    } while (i != istop);
  1240. X    return Nnil;
  1241. X}
  1242. X
  1243. X/*
  1244. X * Find the current suggestion in the table (whole string must match).
  1245. X */
  1246. X
  1247. XHidden int findsugg(str) string str; {
  1248. X    int i;
  1249. X    
  1250. X    for (i= 0; i < nsugg; i++) {
  1251. X        if (strcmp(str, e_strval(sugg[i])) == 0)
  1252. X            return i;
  1253. X    }
  1254. X    return -1;
  1255. X}
  1256. X
  1257. X/*
  1258. X * Place an initial suggestion in a node.
  1259. X */
  1260. X
  1261. XHidden node firstsugg(s, startsugg, colon_allowed)
  1262. Xstring s; int startsugg; bool colon_allowed;
  1263. X{
  1264. X    int i;
  1265. X    string sugg_i;
  1266. X    
  1267. X    for (i= startsugg ; i < nsugg; i++) {
  1268. X        sugg_i= e_strval(sugg[i]);
  1269. X        if (strncmp(s, sugg_i, strlen(s)) == 0) {
  1270. X            if (colon_allowed || strchr(sugg_i, ':') == 0)
  1271. X                return (node) sugg[i];
  1272. X        }
  1273. X    }
  1274. X    return Nnil;
  1275. X}
  1276. X
  1277. XVisible bool
  1278. Xsetsugg(pp, c, ep, colon_allowed)
  1279. X    path *pp;
  1280. X    char c;
  1281. X    environ *ep;
  1282. X    bool colon_allowed;
  1283. X{
  1284. X    char buf[2];
  1285. X    node n;
  1286. X    string s;
  1287. X    string lastunitname();
  1288. X
  1289. X    if (lefttorite)
  1290. X        return No;
  1291. X    n= Nnil;
  1292. X    if (c == ':') {
  1293. X        if (nsugg <= nbuiltin)
  1294. X            return No;    /* no suggestions for howtoname */
  1295. X        s= lastunitname();
  1296. X        if (s != NULL) {
  1297. X            n= firstsugg(s, nbuiltin, No);
  1298. X            freestr(s);
  1299. X        }
  1300. X        if (n == Nnil) {
  1301. X            n= (node) mk_etext("");
  1302. X        }
  1303. X    }
  1304. X    else {
  1305. X        buf[0] = islower(c) ? toupper(c) : c;
  1306. X        buf[1] = '\0';
  1307. X        n = firstsugg(buf,
  1308. X            (parent(*pp) == NilPath ? 0 : 1),
  1309. X              /* skip "H?OW TO ?:" if not at root */
  1310. X            colon_allowed);
  1311. X    }
  1312. X    if (n == Nnil)
  1313. X        return No;
  1314. X    n= nodecopy(n);
  1315. X    if (c == ':') {
  1316. X        n= newnode(1, Sugghowname, &n);
  1317. X        n= newnode(1, Edit_unit, &n);
  1318. X    }
  1319. X    else {
  1320. X        n= newnode(1, Suggestion, &n);
  1321. X    }
  1322. X    treereplace(pp,    n);
  1323. X    ep->mode = VHOLE;
  1324. X    ep->s1 = 2;
  1325. X    ep->s2 = (c == ':' ? 0 : 1);
  1326. X    return Yes;
  1327. X}
  1328. X
  1329. XHidden bool fits_how_to(str, pstr, alt_c)
  1330. Xstring str; string *pstr; int alt_c;
  1331. X{
  1332. X    if (strcmp(str, S_HOW_TO) == 0) {
  1333. X        if (alt_c)
  1334. X            **pstr= alt_c;
  1335. X        return Yes;
  1336. X    }
  1337. X    return No;
  1338. X}
  1339. X
  1340. X/*
  1341. X * Find a new suggestion or advance in the current one.
  1342. X * Interface styled like resuggest: string pointer is advanced here.
  1343. X */
  1344. X
  1345. XVisible bool newsugg(ep, pstr, alt_c) environ *ep; string *pstr; int alt_c; {
  1346. X    string str;
  1347. X    node n = tree(ep->focus);
  1348. X    node nn;
  1349. X    int sym = symbol(n);
  1350. X    path pa= parent(ep->focus);
  1351. X    int sympa= pa ? symbol(tree(pa)) : Rootsymbol;
  1352. X
  1353. X    Assert(pstr && *pstr);
  1354. X    if (sym != Suggestion || ep->mode != VHOLE || ep->s1 != 2)
  1355. X        return No;
  1356. X
  1357. X    str= e_sstrval((value) firstchild(n));
  1358. X    
  1359. X    if (str[ep->s2-1] == ' ' 
  1360. X        && (!isupper(**pstr) || res_firstkeyword(str)))
  1361. X    {
  1362. X        /* require CAPITAL after space */
  1363. X        /* uses that Keywords start with such */
  1364. X        if (str[ep->s2] == '?'  /* pattern fits expr or loc */
  1365. X            || fits_how_to(str, pstr, alt_c))
  1366. X        {
  1367. X            /* so acknowledge: */
  1368. X            acksugg(ep);    /* if insertion fails rest of editor */
  1369. X            e_fstrval(str);    /* restores suggestion state */
  1370. X            return Yes;
  1371. X        }
  1372. X        /* else: pattern wrong */
  1373. X        e_fstrval(str);
  1374. X        return No;    /* implies killsugg in caller */
  1375. X    }
  1376. X    
  1377. X    nn= nextsugg(str, ep->s2, (!alt_c ? (int)(**pstr) : alt_c), No,
  1378. X        allows_colon(sympa));
  1379. X    
  1380. X    e_fstrval(str);
  1381. X    
  1382. X    if (!nn)
  1383. X        return No;
  1384. X    
  1385. X    if (nn != firstchild(n)) {
  1386. X        s_down(ep);
  1387. X        treereplace(&ep->focus, nodecopy(nn));
  1388. X        s_up(ep);
  1389. X    }
  1390. X
  1391. X    ++ep->s2;
  1392. X    if (**pstr == ':') {
  1393. X        /* must be "SELECT:" */
  1394. X        acksugg(ep);
  1395. X        Assert(symbol(tree(ep->focus)) == Select);
  1396. X    }
  1397. X    ++*pstr;
  1398. X
  1399. X    return Yes;
  1400. X}
  1401. X
  1402. X
  1403. X/*
  1404. X * Kill suggestion -- only the part to the left of the focus is kept.
  1405. X */
  1406. X
  1407. XVisible Procedure killsugg(ep, pstr) environ *ep; string *pstr;
  1408. X{
  1409. X    node n = tree(ep->focus);
  1410. X    node nc;
  1411. X    value vstr;
  1412. X    
  1413. X    Assert(ep->mode == VHOLE && ep->s1 == 2 && symbol(n) == Suggestion);
  1414. X    Assert(ep->s2 <= Length((value)firstchild(n)));
  1415. X    
  1416. X    nc = (node)e_icurtail((value)firstchild(n), ep->s2);
  1417. X    if (e_ncharval(ep->s2, (value)firstchild(n)) == ' ' 
  1418. X        && pstr != (string*)NULL) {
  1419. X            /* fix for e.g. APPEND WORD >?<TO ?, inserting X */
  1420. X            /* acksugg threw the space after WORD away */
  1421. X        e_concto((value*) &nc, vstr=mk_etext(*pstr));
  1422. X        ep->s2 += e_length(vstr);
  1423. X        release(vstr);
  1424. X        **pstr= '\0';
  1425. X    };
  1426. X    s_down(ep);
  1427. X    treereplace(&ep->focus, nc);
  1428. X    s_up(ep);
  1429. X    acksugg(ep);
  1430. X}
  1431. X
  1432. X/*
  1433. X * Acknowledge a suggestion -- turn it into real nodes.
  1434. X */
  1435. X
  1436. XVisible Procedure acksugg(ep) environ *ep; {
  1437. X    node n = tree(ep->focus);
  1438. X    int s2 = ep->s2;
  1439. X    int isugg;
  1440. X    string str;
  1441. X    node nn;
  1442. X    node n1;
  1443. X    string rest;
  1444. X    queue q = Qnil;
  1445. X    node r;
  1446. X
  1447. X    Assert(symbol(n) == Suggestion && ep->mode == VHOLE && ep->s1 == 2);
  1448. X
  1449. X    str= e_sstrval((value) firstchild(n));
  1450. X    isugg= findsugg(str);
  1451. X    
  1452. X    if (0 <= isugg && isugg < nbuiltin) {    /* builtin command */
  1453. X        nn= gram(symsugg[isugg]);
  1454. X        treereplace(&ep->focus, nodecopy(nn));
  1455. X        ep->mode= FHOLE;
  1456. X        ep->s1= 1;
  1457. X        /* s2 in or at end of repr[0] */
  1458. X        Assert(s2 <= Fwidth(table[symsugg[isugg]].r_repr[0]));
  1459. X    }
  1460. X    else if ((rest= strchr(str, ' ')) == NULL) { /* just one keyword */
  1461. X        nn= gram(Keyword);
  1462. X        setchild(&nn, 1, (node) mk_etext(str));
  1463. X        treereplace(&ep->focus, nn);
  1464. X        /* mode VHOLE and s1, s2 allright */
  1465. X    }
  1466. X    else {            /* Keyword plus ... */
  1467. X        /* split off first keyword */
  1468. X        *rest++ = '\0';
  1469. X        n1= gram(Keyword);
  1470. X        setchild(&n1, 1, (node) mk_etext(str));
  1471. X        
  1472. X        /* hang in Kw_plus */
  1473. X        nn= gram(Kw_plus);
  1474. X        setchild(&nn, 1, n1);
  1475. X        
  1476. X        /* set focus at hole after space after first keyword */
  1477. X        treereplace(&ep->focus, nn);
  1478. X        /* ep->mode= VHOLE; */
  1479. X        ep->s1= 4;
  1480. X        ep->s2= 0;
  1481. X        
  1482. X        /* rest of suggestion to q */
  1483. X        r= (node) mk_etext(rest);
  1484. X        preptoqueue(r, &q);
  1485. X        noderelease(r);
  1486. X        
  1487. X        /* append to first keyword and restore focus position */
  1488. X        app_queue(ep, &q);
  1489. X        fixfocus(ep, s2);
  1490. X    }
  1491. X    
  1492. X    e_fstrval(str);
  1493. X}
  1494. X
  1495. X/*
  1496. X * newsugg, adv_howsugg and acksugg for Sugghowname.
  1497. X * Note that a howsugg is never kiled, just advanced in;
  1498. X * ackhowsugg is only used for [newline] and [accept].
  1499. X */
  1500. X
  1501. XForward node adv_howsugg();
  1502. X
  1503. XVisible bool newhowsugg(ep, pstr, alt_c) environ *ep; string *pstr; int alt_c; {
  1504. X    string str;
  1505. X    string qm;
  1506. X    node n = tree(ep->focus);
  1507. X    int sym = symbol(n);
  1508. X    node nn;
  1509. X    int newc;
  1510. X
  1511. X    Assert(pstr && *pstr);
  1512. X    if (sym != Sugghowname || ep->mode != VHOLE || ep->s1 != 2)
  1513. X        return No;
  1514. X
  1515. X    str= e_sstrval((value) firstchild(n));
  1516. X    
  1517. X    if (isupper(str[0])) {
  1518. X        /* ucmd suggestion */
  1519. X        qm= strchr(str, '?');
  1520. X        if (qm && qm-str < ep->s2) {
  1521. X            e_fstrval(str);
  1522. X            return No; /* refuse insert after questionmark */
  1523. X        }
  1524. X    }
  1525. X    else if (islower(str[0])) {
  1526. X        /* fpr suggestion */
  1527. X        if (**pstr == ' ') {
  1528. X            e_fstrval(str);
  1529. X            return No; /* refuse space in name */
  1530. X        }
  1531. X    }
  1532. X    
  1533. X    if (ep->s2 == 0 || !alt_c || !isupper(str[0]))
  1534. X        newc= (int)(**pstr);
  1535. X    else
  1536. X        newc= alt_c;
  1537. X    
  1538. X    nn = nextsugg(str, ep->s2, newc, Yes, No);
  1539. X    
  1540. X    e_fstrval(str);
  1541. X    
  1542. X    if (!nn) {
  1543. X         if (ep->s2 == 0) {    /* nothing suggested */
  1544. X            treereplace(&ep->focus, gram(Optional));
  1545. X            ep->mode= ATBEGIN;
  1546. X            return Yes;    /* ins_string will continue */
  1547. X        }
  1548. X        nn= adv_howsugg(ep, str[ep->s2-1], (char)newc);
  1549. X        if (!nn)
  1550. X            return No;
  1551. X    }
  1552. X    
  1553. X    if (nn != firstchild(n)) {
  1554. X        s_down(ep);
  1555. X        treereplace(&ep->focus, nodecopy(nn));
  1556. X        s_up(ep);
  1557. X    }
  1558. X
  1559. X    ++ep->s2;
  1560. X    ++*pstr;
  1561. X
  1562. X    return Yes;
  1563. X}
  1564. X
  1565. XHidden node adv_howsugg(ep, prev_c, new_c)
  1566. Xenviron *ep; char prev_c; char new_c;
  1567. X{
  1568. X    int s2= ep->s2;
  1569. X    char buf[2];
  1570. X    value hd;
  1571. X    value tl;
  1572. X    
  1573. X    Assert(ep->s2 <= Length((value)firstchild(tree(ep->focus))));
  1574. X    
  1575. X    if (isalpha(new_c) ||
  1576. X        (prev_c != ' ' && strchr("012345679'\". ", new_c) != NULL))
  1577. X    {
  1578. X        buf[0]= new_c;
  1579. X        buf[1]= '\0';
  1580. X    
  1581. X        hd= e_icurtail((value) firstchild(tree(ep->focus)), s2);
  1582. X        tl= mk_etext(buf);
  1583. X        e_concto(&hd, tl);
  1584. X        release(tl);
  1585. X    
  1586. X        return (node) hd;
  1587. X    }
  1588. X    /* else */
  1589. X    return Nnil;
  1590. X}
  1591. X
  1592. X/*
  1593. X * Acknowledge a how-to name suggestion -- but do NOT turn it into real nodes.
  1594. X */
  1595. X
  1596. XVisible Procedure ackhowsugg(ep) environ *ep; {
  1597. X    ep->mode= VHOLE;
  1598. X    ep->s1= 2;
  1599. X    ep->s2= strlen(e_strval((value) firstchild(tree(ep->focus))));
  1600. X}
  1601. X
  1602. X/*
  1603. X * Leave a single ':' (edit last unit) as immediate command if
  1604. X * the user did not try to edit the suggested last_unit name;
  1605. X * this is done to avoid the which_funpred dialog in the interpreter.
  1606. X */
  1607. X
  1608. XVisible Procedure check_last_unit(ep, curr) environ *ep; int curr; {
  1609. X    if (curr != 1 
  1610. X        || symbol(tree(ep->focus)) != Edit_unit
  1611. X        || symbol(firstchild(tree(ep->focus))) != Sugghowname)
  1612. X            return;
  1613. X    /* else */
  1614. X    s_down(ep);
  1615. X    treereplace(&ep->focus, gram(Optional));
  1616. X    s_up(ep);
  1617. X}
  1618. X
  1619. X
  1620. X/*
  1621. X * Procedure called when a unit is read in.
  1622. X * It tries to update the suggestion database.
  1623. X * It also remembers the suggestion so that it can be removed by writesugg
  1624. X * if that finds the unit was deleted or renamed.
  1625. X */
  1626. X
  1627. XHidden char *lastsugg= NULL;    /* the buffer */
  1628. XHidden char *pbuf;
  1629. XHidden int buflen= 0;
  1630. X
  1631. XVisible Procedure
  1632. Xreadsugg(p)
  1633. X    path p;
  1634. X{
  1635. X    p = pathcopy(p);
  1636. X    top(&p);
  1637. X    if (getpattern(tree(p)))
  1638. X        addsugg(lastsugg, 0);
  1639. X    else {
  1640. X        freemem((ptr) lastsugg);
  1641. X        lastsugg= NULL;
  1642. X    }
  1643. X    pathrelease(p);
  1644. X}
  1645. X
  1646. X
  1647. X/*
  1648. X * Procedure called when a unit is saved.
  1649. X * It tries to update the suggestion database.
  1650. X * Since renaming a unit now deletes to old name, we always delete
  1651. X * 'lastsugg'; we add it again if the unit is not empty.
  1652. X */
  1653. X
  1654. XVisible Procedure
  1655. Xwritesugg(p)
  1656. X    path p;
  1657. X{
  1658. X    p = pathcopy(p);
  1659. X    top(&p);
  1660. X    if (lastsugg != NULL)
  1661. X        delsugg(lastsugg);
  1662. X    if (nodewidth(tree(p)) != 0) {
  1663. X        if (getpattern(tree(p)))
  1664. X            addsugg(lastsugg, 0);
  1665. X    }
  1666. X    if (lastsugg != NULL) {
  1667. X        freemem((ptr) lastsugg);
  1668. X        lastsugg= NULL;
  1669. X    }
  1670. X    pathrelease(p);
  1671. X}
  1672. X
  1673. X
  1674. X/*
  1675. X * Procedure to find out the suggestion that fits the current unit.
  1676. X * For user defined commands it just replaces stretches of non-keywords
  1677. X * with a single '?'; for functions and predicates it tries to
  1678. X * get the name.
  1679. X * It uses intimate knowledge about the abc grammar for formal-cmd and
  1680. X * formal_formula in ../boot/grammar.abc (such as the separation of 
  1681. X * keywords and other stuff by spaces).
  1682. X */
  1683. X
  1684. XHidden bool
  1685. Xgetpattern(n)
  1686. X    node n;
  1687. X{
  1688. X    string *rp = noderepr(n);
  1689. X    int sym;
  1690. X    int sym1;
  1691. X    int sym2;
  1692. X    
  1693. X    if (lastsugg == NULL) {
  1694. X        lastsugg= (char*) getmem(SUGGBUFSIZE);
  1695. X        buflen= SUGGBUFSIZE;
  1696. X    }
  1697. X    pbuf= lastsugg;
  1698. X
  1699. X    while (Fw_zero(rp[0])) {
  1700. X        if (nchildren(n) == 0)
  1701. X            return No;
  1702. X        n = firstchild(n);
  1703. X        rp = noderepr(n);
  1704. X    }
  1705. X    if (strcmp(rp[0], R_HOW_TO) || nchildren(n) < 1)
  1706. X        return No;
  1707. X    n= firstchild(n);
  1708. X    sym= symbol(n);
  1709. X    if (sym == Formal_kw_plus || sym == Keyword) {
  1710. X        for (;;) {
  1711. X            switch (sym) {
  1712. X            case Formal_kw_plus:
  1713. X                addnode(firstchild(n));
  1714. X                addstr(" ");
  1715. X                break;
  1716. X            case Keyword:
  1717. X                addnode(n);
  1718. X                *pbuf= '\0';
  1719. X                return Yes;
  1720. X            case Formal_naming_plus:
  1721. X                addstr("? ");
  1722. X                break;
  1723. X            case Name:
  1724. X            case Multiple_naming:
  1725. X            case Compound_naming:
  1726. X                addstr("?");
  1727. X                *pbuf= '\0';
  1728. X                return Yes;
  1729. X            default:
  1730. X                Assert(No);
  1731. X                return No;
  1732. X            }
  1733. X            n= child(n, 2);
  1734. X            sym= symbol(n);
  1735. X        }
  1736. X        /* NOTREACHED */
  1737. X    }
  1738. X    else {
  1739. X        Assert(sym==Formal_return || sym== Formal_report);
  1740. X        n= firstchild(n);
  1741. X        sym= symbol(n);
  1742. X        if (sym == Blocked_ff || sym == Grouped_ff) {
  1743. X            sym1= symbol(child(n, 1));
  1744. X            sym2= symbol(child(n, 2));
  1745. X            if (sym2 == Name || sym2 == Compound_naming) {
  1746. X                n= child(n, 1);
  1747. X                if (sym1 == Blocked_ff)
  1748. X                    n= child(n, 2);
  1749. X            }
  1750. X            else if (sym1 == Name || sym1 == Compound_naming) {
  1751. X                /* sym2 == Blocked_ff || Grouped_ff */
  1752. X                n= child(n, 2);
  1753. X                n= firstchild(n);
  1754. X            }
  1755. X        }
  1756. X        if (symbol(n) == Name) {
  1757. X            addnode(n);
  1758. X            *pbuf= '\0';
  1759. X            return Yes;
  1760. X        }
  1761. X        /* else */
  1762. X        return No;
  1763. X    }
  1764. X    /*NOTREACHED*/
  1765. X}
  1766. X
  1767. XHidden Procedure addnode(n) node n; {
  1768. X    string s;
  1769. X    
  1770. X    Assert(symbol(n) == Keyword || symbol(n) == Name);
  1771. X    
  1772. X    s= e_strval((value) firstchild(n));
  1773. X    addstr(s);
  1774. X}
  1775. X
  1776. XHidden Procedure addstr(s) string s; {
  1777. X    while (*s) {
  1778. X        *pbuf++ = *s++;
  1779. X        if (pbuf >= lastsugg + buflen) {
  1780. X            regetmem((ptr*)&lastsugg, 
  1781. X                 (unsigned) (buflen+SUGGBUFSIZE));
  1782. X            pbuf= lastsugg+buflen;
  1783. X            buflen += SUGGBUFSIZE;
  1784. X        }
  1785. X    }
  1786. X}
  1787. X
  1788. XVisible Procedure
  1789. Xinitsugg()
  1790. X{
  1791. X    getsugg();
  1792. X    suggchanges= No;
  1793. X}
  1794. X
  1795. XVisible Procedure
  1796. Xendsugg()
  1797. X{
  1798. X    int i;
  1799. X    savsugg();
  1800. X    for (i = nbuiltin; i < nsugg; ++i)
  1801. X        release(sugg[i]);
  1802. X    nsugg= nbuiltin;
  1803. X    if (maxnsugg > NSUGGSIZE) {
  1804. X        regetmem((ptr*)&sugg, (unsigned) (NSUGGSIZE * sizeof(value)));
  1805. X        maxnsugg= NSUGGSIZE;
  1806. X    }
  1807. X}
  1808. X
  1809. XVisible Procedure
  1810. Xendclasses()
  1811. X{
  1812. X    int i;
  1813. X    for (i= 0; i < nbuiltin; ++i)
  1814. X        release(sugg[i]);
  1815. X    nbuiltin= nsugg= 0;
  1816. X    freemem((ptr) sugg);
  1817. X}
  1818. X
  1819. X#endif /* USERSUGG */
  1820. END_OF_FILE
  1821.   if test 17893 -ne `wc -c <'abc/bed/e1sugg.c'`; then
  1822.     echo shar: \"'abc/bed/e1sugg.c'\" unpacked with wrong size!
  1823.   fi
  1824.   # end of 'abc/bed/e1sugg.c'
  1825. fi
  1826. if test -f 'abc/bint2/i2exp.c' -a "${1}" != "-c" ; then 
  1827.   echo shar: Will not clobber existing file \"'abc/bint2/i2exp.c'\"
  1828. else
  1829.   echo shar: Extracting \"'abc/bint2/i2exp.c'\" \(13508 characters\)
  1830.   sed "s/^X//" >'abc/bint2/i2exp.c' <<'END_OF_FILE'
  1831. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1986. */
  1832. X
  1833. X#include "b.h"
  1834. X#include "bint.h"
  1835. X#include "bmem.h"
  1836. X#include "bobj.h"
  1837. X#include "i0err.h"
  1838. X#include "i2par.h"
  1839. X#include "i2nod.h"
  1840. X#include "i2gen.h" /* Must be after i2nod.h */
  1841. X#include "i2exp.h"
  1842. X
  1843. X/************************************************************************/
  1844. X
  1845. XHidden struct prio priorities[] = {
  1846. X    {"", '\0', 1, 13},        /* tag functions */
  1847. X    
  1848. X    {S_ABOUT,    P_mon, 13, 13},
  1849. X    {S_PLUS,    P_mon, 13, 13},
  1850. X    {S_NUMBER,    P_mon, 12, 12},
  1851. X    {S_MINUS,    P_mon, 9, 9},
  1852. X    {S_NUMERATOR,    P_mon, 2, 13},
  1853. X    {S_DENOMINATOR,    P_mon, 2, 13},
  1854. X    {S_NUMBER,    P_dya, 12, 12},
  1855. X    {S_POWER,    P_dya, 10, 11},
  1856. X    {S_TIMES,    P_dya, 8, 8},
  1857. X    {S_OVER,    P_dya, 7, 8},
  1858. X    {S_PLUS,    P_dya, 6, 6},
  1859. X    {S_MINUS,    P_dya, 6, 6},
  1860. X    {S_BEHEAD,    P_dya, 5, 5},
  1861. X    {S_CURTAIL,    P_dya, 5, 5},
  1862. X    {S_REPEAT,    P_dya, 4, 4},
  1863. X    {S_JOIN,    P_dya, 3, 3},
  1864. X    {S_LEFT_ADJUST,    P_dya, 1, 1},
  1865. X    {S_CENTER,    P_dya, 1, 1},
  1866. X    {S_RIGHT_ADJUST, P_dya, 1, 1},
  1867. X    {Bottom,    P_dya, 0, 0}
  1868. X};
  1869. X
  1870. X#define NPRIORITIES (sizeof priorities / sizeof priorities[0])
  1871. X
  1872. XVisible struct prio *pprio(f, adic) value f; char adic; {
  1873. X    struct prio *pp;
  1874. X    string s= strval(f);
  1875. X    
  1876. X    for (pp= priorities+1; pp < &priorities[NPRIORITIES]; ++pp) {
  1877. X        if (strcmp(pp->fun, s) == 0 && pp->adic == adic)
  1878. X            return pp;
  1879. X    }
  1880. X    /* tag */
  1881. X    return priorities;
  1882. X}
  1883. X
  1884. X/************************************************************************/
  1885. X
  1886. X/*
  1887. X * Stack(adm) <= "allocated space" < Top(adm)
  1888. X * Sp(adm) points to the first free entry
  1889. X */
  1890. XHidden Procedure initstack(adm, n) expadm *adm; int n; {
  1891. X    Stack(adm)= Sp(adm)=
  1892. X        (parsetree *) getmem((unsigned) (n * sizeof(parsetree *)));
  1893. X    Top(adm)= Stack(adm) + n;
  1894. X    Nextend(adm)= n;
  1895. X}
  1896. X
  1897. XVisible Procedure initexp(adm, n, level) expadm *adm; int n; char level; {
  1898. X    initstack(adm, n);
  1899. X    push_dya(adm, mk_text(Bottom));
  1900. X    Level(adm)= level;
  1901. X    Prop(adm)= No;
  1902. X    Nfld(adm)= 0;
  1903. X}
  1904. X
  1905. XVisible Procedure endstack(adm) expadm *adm; {
  1906. X    while (Sp(adm) > Stack(adm)) release(Pop(adm));
  1907. X    freemem((ptr) Stack(adm));
  1908. X}
  1909. X
  1910. XVisible Procedure push_item(adm, v) expadm *adm; parsetree v; {
  1911. X    if (Sp(adm) >= Top(adm)) st_extend(adm);
  1912. X    *Sp(adm)++= v;
  1913. X}
  1914. X
  1915. XHidden Procedure st_extend(adm) expadm *adm; {
  1916. X    int syze= (Top(adm) - Stack(adm)) + Nextend(adm);
  1917. X    int n= Sp(adm) - Stack(adm);
  1918. X    
  1919. X    regetmem((ptr *) &Stack(adm),
  1920. X            (unsigned) syze * sizeof(parsetree *));
  1921. X    Sp(adm)= Stack(adm) + n;
  1922. X    Top(adm)= Stack(adm) + syze;
  1923. X}
  1924. X
  1925. X/* to recognize them on the stack, dyadic operators are pushed as compounds */
  1926. X
  1927. XHidden Procedure push_dya(adm, v) expadm *adm; value v; {
  1928. X    value w= mk_compound(1);
  1929. X    *Field(w, 0)= v;
  1930. X    push_item(adm, (parsetree) w);
  1931. X}
  1932. X
  1933. X/* ******************************************************************** */
  1934. X/*        expression                        */
  1935. X/* ******************************************************************** */
  1936. X
  1937. XVisible parsetree expr(q) txptr q; {
  1938. X    return collateral(q, singexpr);
  1939. X}
  1940. X
  1941. XVisible parsetree singexpr(q) txptr q; {
  1942. X    expadm adm;
  1943. X    parsetree v, par_expr();
  1944. X        
  1945. X    if (nothing(q, MESS(2100, "nothing instead of expected expression")))
  1946. X        return NilTree;
  1947. X    initexp(&adm, N_EXP_STACK, PARSER);
  1948. X    v= par_expr(q, &adm);
  1949. X    endstack(&adm);
  1950. X    return v;
  1951. X}
  1952. X
  1953. XHidden bool unparsed= No;
  1954. X
  1955. XVisible parsetree unp_test(q) txptr q; {
  1956. X    unparsed= Yes;
  1957. X    return singexpr(q);
  1958. X}
  1959. X    
  1960. X#define S_tag1    0    /* zer or mon tag */
  1961. X#define S_tag2    1    /* zer, mon or dya tag */
  1962. X#define S_elmt    2    /* element */
  1963. X#define S_dm    3    /* dyamon sign */
  1964. X#define S_mon    4    /* mon sign */
  1965. X#define S_dya    5    /* dya sign */
  1966. X#define S_unp    6    /* unparsed */
  1967. X#define S_err    7    /* error */
  1968. X
  1969. X#define K_tag        0
  1970. X#define K_element    1
  1971. X#define K_dyamon    2
  1972. X#define K_mon        3
  1973. X#define K_dya        4
  1974. X
  1975. XHidden int trans[5][8]= {
  1976. X    {S_tag2, S_unp, S_dya,  S_unp, S_tag1, S_tag1, S_unp, S_err},
  1977. X    {S_elmt, S_unp, S_err,  S_unp, S_elmt, S_elmt, S_unp, S_err},
  1978. X    {S_dm,   S_unp, S_dya,  S_unp, S_mon,  S_mon,  S_unp, S_err},
  1979. X    {S_mon,  S_unp, S_err,  S_unp, S_mon,  S_mon,  S_unp, S_err},
  1980. X    {S_dya,  S_dya, S_dya,  S_err, S_err,  S_err,  S_unp, S_err}
  1981. X};
  1982. X
  1983. XHidden parsetree par_expr(q, adm) txptr q; expadm *adm; {
  1984. X    parsetree v= NilTree;
  1985. X    value w, c;
  1986. X    int state= S_dya;
  1987. X    int kind, n;
  1988. X    txptr tx0, tx1;
  1989. X
  1990. X    if (unparsed) {
  1991. X        state= S_unp;
  1992. X        unparsed= No;
  1993. X    }
  1994. X    skipsp(&tx);
  1995. X    tx0= tx;
  1996. X    while (Text(q)) {
  1997. X        tx1= tx;
  1998. X        if (tag_operator(q, &w)) kind= K_tag;
  1999. X        else if (element(q, &w)) kind= K_element;
  2000. X        else if (dyamon_sign(&w)) kind= K_dyamon;
  2001. X        else if (mon_sign(&w)) kind= K_mon;
  2002. X        else if (dya_sign(&w)) kind= K_dya;
  2003. X        else break;
  2004. X        
  2005. X        state= trans[kind][state];
  2006. X        if (state == S_err) {
  2007. X            release(w);
  2008. X            tx= tx1;
  2009. X            break;
  2010. X        }
  2011. X        else if (state == S_dya) 
  2012. X            do_dya(adm, w);
  2013. X        else
  2014. X            push_item(adm, (parsetree) w);
  2015. X        skipsp(&tx);
  2016. X    }
  2017. X    if (Text(q)) {
  2018. X        if (tx == tx0) parerr(NO_EXPR);
  2019. X        else parerr(UPTO_EXPR);
  2020. X        tx= q;
  2021. X        return NilTree;
  2022. X    }
  2023. X    switch (state) {
  2024. X        case S_mon:
  2025. X        case S_dya:
  2026. X        case S_dm:
  2027. X        case S_err:
  2028. X            parerr(NO_EXPR);
  2029. X            return NilTree;
  2030. X        case S_unp:
  2031. X            n= (Sp(adm) - Stack(adm)) - 1;
  2032. X            c= mk_compound(n);
  2033. X            while (n > 0) *Field(c, --n)= Pop(adm);
  2034. X            for (tx1= tx; Space(Char(tx1-1)); --tx1);
  2035. X            return node3(UNPARSED, c, cr_text(tx0, tx1));
  2036. X        default:
  2037. X            while (Sp(adm) - Stack(adm) > 2)
  2038. X                reduce(adm);
  2039. X            v= Pop(adm);
  2040. X            if (ValidTree(v) && Is_text(v))
  2041. X                v= node2(TAG, v);
  2042. X            return v;
  2043. X    }
  2044. X}
  2045. X
  2046. X#define SHIFT    '1'
  2047. X#define START    '2'
  2048. X
  2049. X#define Prio_err(adm) \
  2050. X        (Level(adm) == PARSER ? pprerr(PRIO) : fixerr(PRIO))
  2051. X
  2052. XVisible Procedure do_dya(adm, v) expadm *adm; value v; {
  2053. X    parsetree *p= Sp(adm) - 2;    /* skip operand */
  2054. X    struct prio *pdya, *popr;
  2055. X    char action= START;
  2056. X
  2057. X    pdya= dprio(v);
  2058. X    for (;;) {
  2059. X        popr= Dya_opr(*p) ? dprio(*Field(*p, 0)) : mprio(*p);
  2060. X        if (popr->L >= pdya->H) {    /* reduce */
  2061. X            if (action == SHIFT)
  2062. X                Prio_err(adm);
  2063. X            reduce(adm);
  2064. X            p= Sp(adm) - 2;
  2065. X            action= START;
  2066. X        }
  2067. X        else if (pdya->L > popr->H) {
  2068. X            if (Dya_opr(*p))
  2069. X                break;
  2070. X            --p;
  2071. X            action= SHIFT;
  2072. X        }
  2073. X        else {
  2074. X            if (action == START)
  2075. X                Prio_err(adm);
  2076. X            break;
  2077. X        }
  2078. X    }
  2079. X    push_dya(adm, v);    /* shift */
  2080. X}
  2081. X
  2082. XVisible Procedure reduce(adm) expadm *adm; {
  2083. X    parsetree x, y;
  2084. X    value opr, f= Vnil, v;
  2085. X    
  2086. X    /* right operand */
  2087. X    y= Pop(adm);
  2088. X    if (Level(adm) == PARSER && ValidTree(y) && Is_text(y))
  2089. X        y= node2(TAG, y);
  2090. X    
  2091. X    /* operator */
  2092. X    opr= (value) Pop(adm);
  2093. X    if (!Dya_opr(opr)) {
  2094. X        if (Level(adm) == FIXER) {
  2095. X            VOID is_monfun(opr, &f);
  2096. X            f= copydef(f);
  2097. X        }
  2098. X        push_item(adm, node4(MONF, opr, y, f));
  2099. X        return;
  2100. X    }
  2101. X    opr= copy(*Field(v= opr, 0));
  2102. X    release(v);
  2103. X
  2104. X    /* left operand */
  2105. X    x= Pop(adm);
  2106. X    if (Level(adm) == PARSER && ValidTree(x) && Is_text(x))
  2107. X        x= node2(TAG, x);
  2108. X    if (Level(adm) == FIXER) {
  2109. X        VOID is_dyafun(opr, &f);
  2110. X        f= copydef(f);
  2111. X    }
  2112. X    push_item(adm, node5(DYAF, x, opr, y, f));
  2113. X}
  2114. X
  2115. X/* ******************************************************************** */
  2116. X/*        element                            */
  2117. X/* ******************************************************************** */
  2118. X
  2119. XHidden bool element(q, v) txptr q; value *v; {
  2120. X    parsetree w;
  2121. X    
  2122. X    if (sel_tag(q, &w) || closed_expr(q, &w) || constant(q, &w) ||
  2123. X            text_dis(q, &w) || tlr_dis(q, &w)) {
  2124. X        selection(q, &w);
  2125. X        *v= (value) w;
  2126. X        return Yes;
  2127. X    }
  2128. X    return No;
  2129. X}
  2130. X
  2131. X/* ******************************************************************** */
  2132. X/*        (sel_tag)                        */
  2133. X/* ******************************************************************** */
  2134. X
  2135. XHidden bool sel_tag(q, v) txptr q; parsetree *v; {
  2136. X    value name; txptr tx0= tx;
  2137. X    if (Text(q) && is_tag(&name)) {
  2138. X        txptr tx1= tx;
  2139. X        skipsp(&tx);
  2140. X        if (Text(q) && sub_sign) {
  2141. X            tx= tx1;
  2142. X            *v= node2(TAG, name);
  2143. X            return Yes;
  2144. X        }
  2145. X        else {
  2146. X            release(name);
  2147. X            tx= tx0;
  2148. X        }
  2149. X    }
  2150. X    return No;
  2151. X}
  2152. X
  2153. X/* ******************************************************************** */
  2154. X/*        (expression)                        */
  2155. X/* ******************************************************************** */
  2156. X
  2157. XHidden bool closed_expr(q, v) txptr q; parsetree *v; {
  2158. X    return open_sign ? (*v= compound(q, expr), Yes) : No;
  2159. X}
  2160. X
  2161. X/* ******************************************************************** */
  2162. X/*        constant                        */
  2163. X/*                                    */
  2164. X/* note: stand_alone e<number> not allowed                */
  2165. X/* ******************************************************************** */
  2166. X
  2167. XHidden bool constant(q, v) txptr q; parsetree *v; {
  2168. X    if (Dig(Char(tx)) || Char(tx) == C_POINT) {
  2169. X        txptr tx0= tx;
  2170. X        bool d= digits(q);
  2171. X        value text;
  2172. X        if (Text(q) && point_sign && !digits(q) && !d)
  2173. X            pprerr(MESS(2101, "point without digits"));
  2174. X        if (Text(q) && Char(tx) == 'e' &&
  2175. X            (Dig(Char(tx+1)) || !Tagmark(tx+1) )
  2176. X           ) {
  2177. X            tx++;
  2178. X            if (Text(q) && (plus_sign || minus_sign));
  2179. X            if (!digits(q)) pprerr(MESS(2102, "e not followed by exponent"));
  2180. X        }
  2181. X        text= cr_text(tx0, tx);
  2182. X        *v= node3(NUMBER, Vnil, text);
  2183. X        return Yes;
  2184. X    }
  2185. X    return No;
  2186. X}
  2187. X
  2188. XHidden bool digits(q) txptr q; {
  2189. X    txptr tx0= tx;
  2190. X    while (Text(q) && Dig(Char(tx))) tx++;
  2191. X    return tx > tx0;
  2192. X}
  2193. X
  2194. X/* ******************************************************************** */
  2195. X/*        textual_display                        */
  2196. X/* ******************************************************************** */
  2197. X
  2198. XForward parsetree text_body();
  2199. X
  2200. XHidden bool text_dis(q, v) txptr q; parsetree *v; {
  2201. X    value aq;
  2202. X    if (texdis_sign(&aq)) {
  2203. X        parsetree w;
  2204. X        w= text_body(q, aq);
  2205. X        if (w == NilTree) w= node3(TEXT_LIT, mk_text(""), NilTree);
  2206. X        *v= node3(TEXT_DIS, aq, w);
  2207. X        return Yes;
  2208. X    }
  2209. X    return No;
  2210. X}
  2211. X
  2212. XHidden parsetree text_body(q, aq) txptr q; value aq; {
  2213. X    value head; parsetree tail;
  2214. X    char quote= strval(aq)[0];
  2215. X    txptr tx0= tx;
  2216. X    while (Text(q)) {
  2217. X        if (Char(tx) == quote || Char(tx) == C_CONVERT) {
  2218. X            head= tx0 < tx ? cr_text(tx0, tx) : Vnil;
  2219. X            if (Char(tx) == Char(tx+1)) {
  2220. X                value spec= cr_text(tx, tx+1);
  2221. X                tx+= 2;
  2222. X                tail= text_body(q, aq);
  2223. X                tail= node3(TEXT_LIT, spec, tail);
  2224. X            }
  2225. X            else {
  2226. X                parsetree v;
  2227. X                if (is_conversion(q, &v)) {
  2228. X                    tail= text_body(q, aq);
  2229. X                    tail= node3(TEXT_CONV, v, tail);
  2230. X                }
  2231. X                else {
  2232. X                    tx++;
  2233. X                    tail= NilTree;
  2234. X                }
  2235. X            }
  2236. X            if (head == Vnil) return tail;
  2237. X            else return node3(TEXT_LIT, head, tail);
  2238. X        }
  2239. X        else tx++;
  2240. X    }
  2241. X    parerrV(MESS(2103, "cannot find matching %s"), aq);
  2242. X    return NilTree;
  2243. X}
  2244. X
  2245. XHidden bool is_conversion(q, v) txptr q; parsetree *v; {
  2246. X    if (conv_sign) {
  2247. X        txptr ftx, ttx;
  2248. X        req(S_CONVERT, q, &ftx, &ttx);
  2249. X        *v= expr(ftx); tx= ttx; 
  2250. X        return Yes;
  2251. X    }
  2252. X    return No;
  2253. X}
  2254. X
  2255. X/* ******************************************************************** */
  2256. X/*        table_display; list_display; range_display;        */
  2257. X/* ******************************************************************** */
  2258. X
  2259. XHidden bool elt_dis(v) parsetree *v; {
  2260. X    if (curlyclose_sign) {
  2261. X        *v= node1(ELT_DIS);
  2262. X        return Yes;
  2263. X    }
  2264. X    return No;
  2265. X}
  2266. X
  2267. XHidden parsetree par_lta(q, adm, lta_item) txptr q; expadm *adm;
  2268. X        int (*lta_item)(); {
  2269. X    txptr ftx, ttx;
  2270. X    int n;
  2271. X    parsetree v;
  2272. X
  2273. X    while (still_ok && find(S_SEMICOLON, q, &ftx, &ttx)) {
  2274. X        (*lta_item)(ftx, adm);
  2275. X        tx= ttx;
  2276. X    }
  2277. X    (*lta_item)(q, adm);
  2278. X    n= Sp(adm) - Stack(adm);
  2279. X    v= mk_compound(n);
  2280. X    while (n>0) *Field(v, --n)= Pop(adm);
  2281. X    return v;
  2282. X}
  2283. X
  2284. XHidden Procedure tab_item(q, adm) txptr q; expadm *adm; {
  2285. X    txptr ftx, ttx;
  2286. X    
  2287. X    need(S_SUB);
  2288. X    req(S_BUS, q, &ftx, &ttx);
  2289. X    push_item(adm, expr(ftx));
  2290. X    tx= ttx;
  2291. X    need(S_COLON);
  2292. X    push_item(adm, singexpr(q));
  2293. X}
  2294. X
  2295. XHidden bool tab_dis(q, v) txptr q; parsetree *v; {
  2296. X    if (Char(tx) == C_SUB) {
  2297. X        expadm adm;
  2298. X        parsetree w;
  2299. X        
  2300. X        initstack(&adm, N_LTA_STACK);
  2301. X        w= par_lta(q, &adm, tab_item);
  2302. X        endstack(&adm);
  2303. X        *v= node2(TAB_DIS, w);
  2304. X        return Yes;
  2305. X    }
  2306. X    return No;
  2307. X}
  2308. X
  2309. XHidden bool range_elem(q, v) txptr q; parsetree *v; {
  2310. X    txptr ftx, ttx;
  2311. X    if (find(S_RANGE, q, &ftx, &ttx)) {
  2312. X        parsetree w;
  2313. X        if (Char(ttx) == '.') { ftx++; ttx++; }
  2314. X        w= singexpr(ftx); tx= ttx;
  2315. X        *v= node3(RANGE_BNDS, w, singexpr(q));
  2316. X        return Yes;
  2317. X    }
  2318. X    return No;
  2319. X}
  2320. X
  2321. XHidden Procedure list_item(q, adm) txptr q; expadm *adm; {
  2322. X    parsetree r;
  2323. X    if (range_elem(q, &r))
  2324. X        push_item(adm, r);
  2325. X    else
  2326. X        push_item(adm, singexpr(q));
  2327. X}
  2328. X
  2329. XHidden Procedure list_dis(q, v) txptr q; parsetree *v; {
  2330. X    expadm adm;
  2331. X    parsetree w;
  2332. X    
  2333. X    initstack(&adm, N_LTA_STACK);
  2334. X    w= par_lta(q, &adm, list_item);
  2335. X    endstack(&adm);
  2336. X    *v= node2(LIST_DIS, w);
  2337. X}
  2338. X
  2339. XHidden bool tlr_dis(q, v) txptr q; parsetree *v; {
  2340. X    if (curlyopen_sign) {
  2341. X        skipsp(&tx);
  2342. X        if (!elt_dis(v)) {
  2343. X            txptr ftx, ttx;
  2344. X            req(S_CURCLOSE, q, &ftx, &ttx);
  2345. X            skipsp(&tx);
  2346. X            if (!tab_dis(ftx, v)) list_dis(ftx, v);
  2347. X            tx= ttx;
  2348. X        }
  2349. X        return Yes;
  2350. X    }
  2351. X    return No;
  2352. X}
  2353. X
  2354. X/* ******************************************************************** */
  2355. X/*        selection                        */
  2356. X/* ******************************************************************** */
  2357. X
  2358. XVisible Procedure selection(q, v) txptr q; parsetree *v; {
  2359. X    txptr ftx, ttx;
  2360. X    skipsp(&tx);
  2361. X    while (Text(q) && sub_sign) {
  2362. X        req(S_BUS, q, &ftx, &ttx);
  2363. X        *v= node3(SELECTION, *v, expr(ftx)); tx= ttx;
  2364. X        skipsp(&tx);
  2365. X    }
  2366. X}
  2367. X
  2368. X/* ******************************************************************** */
  2369. X/*        trim_target                        */
  2370. X/* ******************************************************************** */
  2371. X
  2372. XVisible Procedure trim_target(q, v) txptr q; parsetree *v; {
  2373. X    parsetree w;
  2374. X    value name;
  2375. X    bool beh;
  2376. X    struct prio *ptrim, *pdya;
  2377. X    txptr ftx;
  2378. X
  2379. X    skipsp(&tx);
  2380. X    while (Text(q) && ((beh= behead_sign) || curtl_sign)) {
  2381. X        skipsp(&tx);
  2382. X        if (!findtrim(q, &ftx)) ftx= q;
  2383. X        w= singexpr(ftx); tx= ftx;
  2384. X        if (nodetype(w) == DYAF) {
  2385. X            pdya= dprio(*Branch(w, DYA_NAME));
  2386. X            name= mk_text(beh ? S_BEHEAD : S_CURTAIL);
  2387. X            ptrim= dprio(name);
  2388. X            if (!(pdya->L > ptrim->H))
  2389. X                pprerr(NO_TRIM_TARG);
  2390. X            release(name);
  2391. X        }
  2392. X        *v= node3(beh ? BEHEAD : CURTAIL, *v, w);
  2393. X    }
  2394. X}
  2395. X
  2396. X/* ******************************************************************** */
  2397. X/*        tag_operator                         */
  2398. X/* ******************************************************************** */
  2399. X
  2400. XVisible bool tag_operator(q, v) txptr q; value *v; {
  2401. X    value w;
  2402. X    txptr tx0= tx;
  2403. X    if (Text(q) && is_tag(&w)) {
  2404. X        skipsp(&tx);
  2405. X        if (Text(q) && sub_sign) {
  2406. X            release(w);
  2407. X            tx= tx0;
  2408. X            return No;
  2409. X        }
  2410. X        *v= w;
  2411. X        return Yes;
  2412. X    }
  2413. X    return No;
  2414. X}
  2415. END_OF_FILE
  2416.   if test 13508 -ne `wc -c <'abc/bint2/i2exp.c'`; then
  2417.     echo shar: \"'abc/bint2/i2exp.c'\" unpacked with wrong size!
  2418.   fi
  2419.   # end of 'abc/bint2/i2exp.c'
  2420. fi
  2421. if test -f 'abc/scripts/mkdep.gen' -a "${1}" != "-c" ; then 
  2422.   echo shar: Will not clobber existing file \"'abc/scripts/mkdep.gen'\"
  2423. else
  2424.   echo shar: Extracting \"'abc/scripts/mkdep.gen'\" \(595 characters\)
  2425.   sed "s/^X//" >'abc/scripts/mkdep.gen' <<'END_OF_FILE'
  2426. X: 'Shell script to create dependency lines for inclusion in a Makefile.'
  2427. X: 'This is done by pulling each file through the C preprocessor,'
  2428. X: 'filtering all "#<file> 1" lines out and doing some substitutions'
  2429. X: 'on them.  Since the format of these lines may be different on your'
  2430. X: 'system, you may have to modify the sed command below.'
  2431. X
  2432. X: 'The following should invoke your C preprocessor:'
  2433. XCPP="cc -E"
  2434. X
  2435. XARGS=
  2436. Xwhile :
  2437. Xdo
  2438. X    case $1 in
  2439. X    -*)    ARGS="$ARGS $1"; shift;;
  2440. X    *)    break;;
  2441. X    esac
  2442. Xdone
  2443. X
  2444. Xfor file
  2445. Xdo
  2446. X    obj=`basename $file .c`.o
  2447. X    $CPP $ARGS $file |
  2448. X    sed -n '/^# 1 "\(.*\)".*$/s//'$obj': \1/p'
  2449. Xdone
  2450. END_OF_FILE
  2451.   if test 595 -ne `wc -c <'abc/scripts/mkdep.gen'`; then
  2452.     echo shar: \"'abc/scripts/mkdep.gen'\" unpacked with wrong size!
  2453.   fi
  2454.   chmod +x 'abc/scripts/mkdep.gen'
  2455.   # end of 'abc/scripts/mkdep.gen'
  2456. fi
  2457. echo shar: End of archive 9 \(of 25\).
  2458. cp /dev/null ark9isdone
  2459. MISSING=""
  2460. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ; do
  2461.     if test ! -f ark${I}isdone ; then
  2462.     MISSING="${MISSING} ${I}"
  2463.     fi
  2464. done
  2465. if test "${MISSING}" = "" ; then
  2466.     echo You have unpacked all 25 archives.
  2467.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2468. else
  2469.     echo You still must unpack the following archives:
  2470.     echo "        " ${MISSING}
  2471. fi
  2472. exit 0 # Just in case...
  2473.