home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / perl / part06 < prev    next >
Encoding:
Internet Message Format  |  1988-01-30  |  49.2 KB

  1. Subject:  v13i006:  Perl, a "replacement" for awk and sed, Part06/10
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Larry Wall <lwall@jpl-devvax.jpl.nasa.gov>
  7. Posting-number: Volume 13, Issue 6
  8. Archive-name: perl/part06
  9.  
  10.  
  11.  
  12. #! /bin/sh
  13.  
  14. # Make a new directory for the perl sources, cd to it, and run kits 1
  15. # thru 10 through sh.  When all 10 kits have been run, read README.
  16.  
  17. echo "This is perl 1.0 kit 6 (of 10).  If kit 6 is complete, the line"
  18. echo '"'"End of kit 6 (of 10)"'" will echo at the end.'
  19. echo ""
  20. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  21. mkdir t 2>/dev/null
  22. echo Extracting Configure
  23. sed >Configure <<'!STUFFY!FUNK!' -e 's/X//'
  24. X#! /bin/sh
  25. X#
  26. X# If these # comments don't work, trim them.  Don't worry about any other
  27. X# shell scripts, Configure will trim # comments from them for you.
  28. X#
  29. X# (If you are trying to port this package to a machine without sh, I would
  30. X# suggest you cut out the prototypical config.h from the end of Configure
  31. X# and edit it to reflect your system.  Some packages may include samples
  32. X# of config.h for certain machines, so you might look for one of those.)
  33. X#
  34. X# $Header: Configure,v 1.0 87/12/18 15:05:56 root Exp $
  35. X#
  36. X# Yes, you may rip this off to use in other distribution packages.
  37. X# (Note: this Configure script was generated automatically.  Rather than
  38. X# working with this copy of Configure, you may wish to get metaconfig.)
  39. X
  40. X: sanity checks
  41. XPATH='.:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc'
  42. Xexport PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  43. X
  44. Xif test ! -t 0; then
  45. X    echo "Say 'sh Configure', not 'sh <Configure'"
  46. X    exit 1
  47. Xfi
  48. X
  49. X(alias) >/dev/null 2>&1 && \
  50. X    echo "(I see you are using the Korn shell.  Some ksh's blow up on Configure," && \
  51. X    echo "especially on exotic machines.  If yours does, try the Bourne shell instead.)"
  52. X
  53. Xif test ! -d ../UU; then
  54. X    if test ! -d UU; then
  55. X    mkdir UU
  56. X    fi
  57. X    cd UU
  58. Xfi
  59. X
  60. Xd_eunice=''
  61. Xeunicefix=''
  62. Xdefine=''
  63. Xloclist=''
  64. Xexpr=''
  65. Xsed=''
  66. Xecho=''
  67. Xcat=''
  68. Xrm=''
  69. Xmv=''
  70. Xcp=''
  71. Xtail=''
  72. Xtr=''
  73. Xmkdir=''
  74. Xsort=''
  75. Xuniq=''
  76. Xgrep=''
  77. Xtrylist=''
  78. Xtest=''
  79. Xinews=''
  80. Xegrep=''
  81. Xmore=''
  82. Xpg=''
  83. XMcc=''
  84. Xvi=''
  85. Xmailx=''
  86. Xmail=''
  87. XLog=''
  88. XHeader=''
  89. Xbin=''
  90. Xcc=''
  91. Xcontains=''
  92. Xcpp=''
  93. Xd_charsprf=''
  94. Xd_index=''
  95. Xd_strctcpy=''
  96. Xd_vfork=''
  97. Xlibc=''
  98. Xlibnm=''
  99. Xmansrc=''
  100. Xmanext=''
  101. Xmodels=''
  102. Xsplit=''
  103. Xsmall=''
  104. Xmedium=''
  105. Xlarge=''
  106. Xhuge=''
  107. Xccflags=''
  108. Xldflags=''
  109. Xn=''
  110. Xc=''
  111. Xpackage=''
  112. Xspitshell=''
  113. Xshsharp=''
  114. Xsharpbang=''
  115. Xstartsh=''
  116. Xvoidflags=''
  117. Xdefvoidused=''
  118. XCONFIG=''
  119. X
  120. X: set package name
  121. Xpackage=perl
  122. X
  123. Xecho " "
  124. Xecho "Beginning of configuration questions for $package kit."
  125. X: Eunice requires " " instead of "", can you believe it
  126. Xecho " "
  127. X
  128. Xdefine='define'
  129. Xundef='/*undef'
  130. Xlibpth='/usr/lib /usr/local/lib /lib'
  131. Xsmallmach='pdp11 i8086 z8000 i80286 iAPX286'
  132. Xrmlist='kit[1-9]isdone kit[1-9][0-9]isdone'
  133. Xtrap 'echo " "; rm -f $rmlist; exit 1' 1 2 3
  134. Xattrlist="mc68000 sun gcos unix ibm gimpel interdata tss os mert pyr"
  135. Xattrlist="$attrlist vax pdp11 i8086 z8000 u3b2 u3b5 u3b20 u3b200"
  136. Xattrlist="$attrlist ns32000 ns16000 iAPX286"
  137. Xpth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /etc /usr/lib"
  138. Xdefvoidused=7
  139. X
  140. X: some greps do not return status, grrr.
  141. Xecho "grimblepritz" >grimble
  142. Xif grep blurfldyick grimble >/dev/null 2>&1 ; then
  143. X    contains=contains
  144. Xelif grep grimblepritz grimble >/dev/null 2>&1 ; then
  145. X    contains=grep
  146. Xelse
  147. X    contains=contains
  148. Xfi
  149. Xrm -f grimble
  150. X: the following should work in any shell
  151. Xcase "$contains" in
  152. Xcontains*)
  153. X    echo " "
  154. X    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
  155. X    cat >contains <<'EOSS'
  156. Xgrep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
  157. XEOSS
  158. Xchmod 755 contains
  159. Xesac
  160. X
  161. X: first determine how to suppress newline on echo command
  162. Xecho "Checking echo to see how to suppress newlines..."
  163. X(echo "hi there\c" ; echo " ") >.echotmp
  164. Xif $contains c .echotmp >/dev/null 2>&1 ; then
  165. X    echo "...using -n."
  166. X    n='-n'
  167. X    c=''
  168. Xelse
  169. X    cat <<'EOM'
  170. X...using \c
  171. XEOM
  172. X    n=''
  173. X    c='\c'
  174. Xfi
  175. Xecho $n "Type carriage return to continue.  Your cursor should be here-->$c"
  176. Xread ans
  177. Xrm -f .echotmp
  178. X
  179. X: now set up to do reads with possible shell escape and default assignment
  180. Xcat <<EOSC >myread
  181. Xans='!'
  182. Xwhile expr "X\$ans" : "X!" >/dev/null; do
  183. X    read ans
  184. X    case "\$ans" in
  185. X    !)
  186. X    sh
  187. X    echo " "
  188. X    echo $n "\$rp $c"
  189. X    ;;
  190. X    !*)
  191. X    set \`expr "X\$ans" : "X!\(.*\)\$"\`
  192. X    sh -c "\$*"
  193. X    echo " "
  194. X    echo $n "\$rp $c"
  195. X    ;;
  196. X    esac
  197. Xdone
  198. Xrp='Your answer:'
  199. Xcase "\$ans" in
  200. X'') ans="\$dflt";;
  201. Xesac
  202. XEOSC
  203. X
  204. X: general instructions
  205. Xcat <<EOH
  206. XThis installation shell script will examine your system and ask you questions
  207. Xto determine how the $package package should be installed.  If you get stuck
  208. Xon a question, you may use a ! shell escape to start a subshell or execute
  209. Xa command.  Many of the questions will have default answers in square
  210. Xbrackets--typing carriage return will give you the default.
  211. X
  212. XOn some of the questions which ask for file or directory names you are
  213. Xallowed to use the ~name construct to specify the login directory belonging
  214. Xto "name", even if you don't have a shell which knows about that.  Questions
  215. Xwhere this is allowed will be marked "(~name ok)".
  216. X
  217. XEOH
  218. Xrp="[Type carriage return to continue]"
  219. Xecho $n "$rp $c"
  220. X. myread
  221. Xcat <<EOH
  222. X
  223. XMuch effort has been expended to ensure that this shell script will run
  224. Xon any Unix system.  If despite that it blows up on you, your best bet is
  225. Xto edit Configure and run it again. Also, let me (lwall@sdcrdcf.UUCP) know
  226. Xhow I blew it.  If you can't run Configure for some reason, you'll have
  227. Xto generate a config.sh file by hand.
  228. X
  229. XThis installation script affects things in two ways: 1) it may do direct
  230. Xvariable substitutions on some of the files included in this kit, and
  231. X2) it builds a config.h file for inclusion in C programs.  You may edit
  232. Xany of these files as the need arises after running this script.
  233. X
  234. XIf you make a mistake on a question, there is no easy way to back up to it
  235. Xcurrently.  The easiest thing to do is to edit config.sh and rerun all the
  236. XSH files.  Configure will offer to let you do this before it runs the SH files.
  237. X
  238. XEOH
  239. Xrp="[Type carriage return to continue]"
  240. Xecho $n "$rp $c"
  241. X. myread
  242. X
  243. X: get old answers, if there is a config file out there
  244. Xif test -f ../config.sh; then
  245. X    echo " "
  246. X    dflt=y
  247. X    rp="I see a config.sh file.  Did Configure make it on THIS system? [$dflt]"
  248. X    echo $n "$rp $c"
  249. X    . myread
  250. X    case "$ans" in
  251. X    n*) echo "OK, I'll ignore it.";;
  252. X    *)  echo "Fetching default answers from your old config.sh file..."
  253. X    tmp="$n"
  254. X    ans="$c"
  255. X        . ../config.sh
  256. X    n="$tmp"
  257. X    c="$ans"
  258. X    ;;
  259. X    esac
  260. Xfi
  261. X
  262. X: find out where common programs are
  263. Xecho " "
  264. Xecho "Locating common programs..."
  265. Xcat <<EOSC >loc
  266. X$startsh
  267. Xcase \$# in
  268. X0) exit 1;;
  269. Xesac
  270. Xthing=\$1
  271. Xshift
  272. Xdflt=\$1
  273. Xshift
  274. Xfor dir in \$*; do
  275. X    case "\$thing" in
  276. X    .)
  277. X    if test -d \$dir/\$thing; then
  278. X        echo \$dir
  279. X        exit 0
  280. X    fi
  281. X    ;;
  282. X    *)
  283. X    if test -f \$dir/\$thing; then
  284. X        echo \$dir/\$thing
  285. X        exit 0
  286. X    fi
  287. X    ;;
  288. X    esac
  289. Xdone
  290. Xecho \$dflt
  291. Xexit 1
  292. XEOSC
  293. Xchmod 755 loc
  294. X$eunicefix loc
  295. Xloclist="
  296. Xexpr
  297. Xsed
  298. Xecho
  299. Xcat
  300. Xrm
  301. Xmv
  302. Xcp
  303. Xtr
  304. Xmkdir
  305. Xsort
  306. Xuniq
  307. Xgrep
  308. X"
  309. Xtrylist="
  310. Xtest
  311. Xegrep
  312. XMcc
  313. X"
  314. Xfor file in $loclist; do
  315. X    xxx=`loc $file $file $pth`
  316. X    eval $file=$xxx
  317. X    eval _$file=$xxx
  318. X    case "$xxx" in
  319. X    /*)
  320. X    echo $file is in $xxx.
  321. X    ;;
  322. X    *)
  323. X    echo "I don't know where $file is.  I hope it's in everyone's PATH."
  324. X    ;;
  325. X    esac
  326. Xdone
  327. Xecho " "
  328. Xecho "Don't worry if any of the following aren't found..."
  329. Xans=offhand
  330. Xfor file in $trylist; do
  331. X    xxx=`loc $file $file $pth`
  332. X    eval $file=$xxx
  333. X    eval _$file=$xxx
  334. X    case "$xxx" in
  335. X    /*)
  336. X    echo $file is in $xxx.
  337. X    ;;
  338. X    *)
  339. X    echo "I don't see $file out there, $ans."
  340. X    ans=either
  341. X    ;;
  342. X    esac
  343. Xdone
  344. Xcase "$egrep" in
  345. Xegrep)
  346. X    echo "Substituting grep for egrep."
  347. X    egrep=$grep
  348. X    ;;
  349. Xesac
  350. Xcase "$test" in
  351. Xtest)
  352. X    echo "Hopefully test is built into your sh."
  353. X    ;;
  354. X/bin/test)
  355. X    echo " "
  356. X    dflt=n
  357. X    rp="Is your "'"'"test"'"'" built into sh? [$dflt] (OK to guess)"
  358. X    echo $n "$rp $c"
  359. X    . myread
  360. X    case "$ans" in
  361. X    y*) test=test ;;
  362. X    esac
  363. X    ;;
  364. X*)
  365. X    test=test
  366. X    ;;
  367. Xesac
  368. Xcase "$echo" in
  369. Xecho)
  370. X    echo "Hopefully echo is built into your sh."
  371. X    ;;
  372. X/bin/echo)
  373. X    echo " "
  374. X    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
  375. X    $echo $n "hi there$c" >foo1
  376. X    echo $n "hi there$c" >foo2
  377. X    if cmp foo1 foo2 >/dev/null 2>&1; then
  378. X    echo "They are compatible.  In fact, they may be identical."
  379. X    else
  380. X    case "$n" in
  381. X    '-n') n='' c='\c' ans='\c' ;;
  382. X    *) n='-n' c='' ans='-n' ;;
  383. X    esac
  384. X    cat <<FOO
  385. XThey are not compatible!  You are probably running ksh on a non-USG system.
  386. XI'll have to use /bin/echo instead of the builtin, since Bourne shell doesn't
  387. Xhave echo built in and we may have to run some Bourne shell scripts.  That
  388. Xmeans I'll have to use $ans to suppress newlines now.  Life is ridiculous.
  389. X
  390. XFOO
  391. X    rp="Your cursor should be here-->"
  392. X    $echo $n "$rp$c"
  393. X    . myread
  394. X    fi
  395. X    $rm -f foo1 foo2
  396. X    ;;
  397. X*)
  398. X    : cross your fingers
  399. X    echo=echo
  400. X    ;;
  401. Xesac
  402. Xrmlist="$rmlist loc"
  403. X
  404. X: get list of predefined functions in a handy place
  405. Xecho " "
  406. Xif test -f /lib/libc.a; then
  407. X    echo "Your C library is in /lib/libc.a.  You're normal."
  408. X    libc=/lib/libc.a
  409. Xelse
  410. X    ans=`loc libc.a blurfl/dyick $libpth`
  411. X    if test -f $ans; then
  412. X    echo "Your C library is in $ans, of all places."
  413. X    libc=ans
  414. X    else
  415. X    if test -f "$libc"; then
  416. X        echo "Your C library is in $libc, like you said before."
  417. X    else
  418. X        cat <<EOM
  419. XI can't seem to find your C library.  I've looked in the following places:
  420. X
  421. X    $libpth
  422. X
  423. XNone of these seems to contain your C library.  What is the full name
  424. XEOM
  425. X        dflt=None
  426. X        $echo $n "of your C library? $c"
  427. X        rp='C library full name?'
  428. X        . myread
  429. X        libc="$ans"
  430. X    fi
  431. X    fi
  432. Xfi
  433. Xecho " "
  434. X$echo $n "Extracting names from $libc for later perusal...$c"
  435. Xif ar t $libc > libc.list; then
  436. X    echo "done"
  437. Xelse
  438. X    echo " "
  439. X    echo "The archiver doesn't think $libc is a reasonable library."
  440. X    echo "Trying nm instead..."
  441. X    if nm -g $libc > libc.list; then
  442. X    echo "Done.  Maybe this is Unicos, or an Apollo?"
  443. X    else
  444. X    echo "That didn't work either.  Giving up."
  445. X    exit 1
  446. X    fi
  447. Xfi
  448. Xrmlist="$rmlist libc.list"
  449. X
  450. X: make some quick guesses about what we are up against
  451. Xecho " "
  452. X$echo $n "Hmm...  $c"
  453. Xif $contains SIGTSTP /usr/include/signal.h >/dev/null 2>&1 ; then
  454. X    echo "Looks kind of like a BSD system, but we'll see..."
  455. X    echo exit 0 >bsd
  456. X    echo exit 1 >usg
  457. X    echo exit 1 >v7
  458. Xelif $contains fcntl libc.list >/dev/null 2>&1 ; then
  459. X    echo "Looks kind of like a USG system, but we'll see..."
  460. X    echo exit 1 >bsd
  461. X    echo exit 0 >usg
  462. X    echo exit 1 >v7
  463. Xelse
  464. X    echo "Looks kind of like a version 7 system, but we'll see..."
  465. X    echo exit 1 >bsd
  466. X    echo exit 1 >usg
  467. X    echo exit 0 >v7
  468. Xfi
  469. Xif $contains vmssystem libc.list >/dev/null 2>&1 ; then
  470. X    cat <<'EOI'
  471. XThere is, however, a strange, musty smell in the air that reminds me of
  472. Xsomething...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
  473. XEOI
  474. X    echo "exit 0" >eunice
  475. X    eunicefix=unixtovms
  476. X    d_eunice="$define"
  477. X: it so happens the Eunice I know will not run shell scripts in Unix format
  478. Xelse
  479. X    echo " "
  480. X    echo "Congratulations.  You aren't running Eunice."
  481. X    eunicefix=':'
  482. X    d_eunice="$undef"
  483. X    echo "exit 1" >eunice
  484. Xfi
  485. Xif test -f /xenix; then
  486. X    echo "Actually, this looks more like a XENIX system..."
  487. X    echo "exit 0" >xenix
  488. Xelse
  489. X    echo " "
  490. X    echo "It's not Xenix..."
  491. X    echo "exit 1" >xenix
  492. Xfi
  493. Xchmod 755 xenix
  494. Xif test -f /venix; then
  495. X    echo "Actually, this looks more like a VENIX system..."
  496. X    echo "exit 0" >venix
  497. Xelse
  498. X    echo " "
  499. X    if xenix; then
  500. X    : null
  501. X    else
  502. X    echo "Nor is it Venix..."
  503. X    fi
  504. X    echo "exit 1" >venix
  505. Xfi
  506. Xchmod 755 bsd usg v7 eunice venix xenix
  507. X$eunicefix bsd usg v7 eunice venix xenix
  508. Xrmlist="$rmlist bsd usg v7 eunice venix xenix"
  509. X
  510. X: see if sh knows # comments
  511. Xecho " "
  512. Xecho "Checking your sh to see if it knows about # comments..."
  513. Xif sh -c '#' >/dev/null 2>&1 ; then
  514. X    echo "Your sh handles # comments correctly."
  515. X    shsharp=true
  516. X    spitshell=cat
  517. X    echo " "
  518. X    echo "Okay, let's see if #! works on this system..."
  519. X    echo "#!/bin/echo hi" > try
  520. X    $eunicefix try
  521. X    chmod 755 try
  522. X    try > today
  523. X    if test -s today; then
  524. X    echo "It does."
  525. X    sharpbang='#!'
  526. X    else
  527. X    echo "#! /bin/echo hi" > try
  528. X    $eunicefix try
  529. X    chmod 755 try
  530. X    try > today
  531. X    if test -s today; then
  532. X        echo "It does."
  533. X        sharpbang='#! '
  534. X    else
  535. X        echo "It doesn't."
  536. X        sharpbang=': use '
  537. X    fi
  538. X    fi
  539. Xelse
  540. X    echo "Your sh doesn't grok # comments--I will strip them later on."
  541. X    shsharp=false
  542. X    echo "exec grep -v '^#'" >spitshell
  543. X    chmod 755 spitshell
  544. X    $eunicefix spitshell
  545. X    spitshell=`pwd`/spitshell
  546. X    echo "I presume that if # doesn't work, #! won't work either!"
  547. X    sharpbang=': use '
  548. Xfi
  549. X
  550. X: figure out how to guarantee sh startup
  551. Xecho " "
  552. Xecho "Checking out how to guarantee sh startup..."
  553. Xstartsh=$sharpbang'/bin/sh'
  554. Xecho "Let's see if '$startsh' works..."
  555. Xcat >try <<EOSS
  556. X$startsh
  557. Xset abc
  558. Xtest "$?abc" != 1
  559. XEOSS
  560. X
  561. Xchmod 755 try
  562. X$eunicefix try
  563. Xif try; then
  564. X    echo "Yup, it does."
  565. Xelse
  566. X    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
  567. Xfi
  568. Xrm -f try today
  569. X
  570. X: see if sprintf is declared as int or pointer to char
  571. Xecho " "
  572. Xif $contains 'char.*sprintf' /usr/include/stdio.h >/dev/null 2>&1 ; then
  573. X    echo "Your sprintf() returns (char*)."
  574. X    d_charsprf="$define"
  575. Xelse
  576. X    echo "Your sprintf() returns (int)."
  577. X    d_charsprf="$undef"
  578. Xfi
  579. X
  580. X: index or strcpy
  581. Xecho " "
  582. Xdflt=y
  583. Xif $contains index libc.list >/dev/null 2>&1 ; then
  584. X    echo "Your system appears to use index() and rindex() rather than strchr()"
  585. X    $echo $n "and strrchr().  Is this correct? [$dflt] $c"
  586. X    rp='index() rather than strchr()? [$dflt]'
  587. X    . myread
  588. X    case "$ans" in
  589. X    n*|f*) d_index="$define" ;;
  590. X    *)     d_index="$undef" ;;
  591. X    esac
  592. Xelse
  593. X    echo "Your system appears to use strchr() and strrchr() rather than index()"
  594. X    $echo $n "and rindex().  Is this correct? [$dflt] $c"
  595. X    rp='strchr() rather than index()? [$dflt]'
  596. X    . myread
  597. X    case "$ans" in
  598. X    n*|f*) d_index="$undef" ;;
  599. X    *)     d_index="$define" ;;
  600. X    esac
  601. Xfi
  602. X
  603. X: check for structure copying
  604. Xecho " "
  605. Xecho "Checking to see if your C compiler can copy structs..."
  606. X$cat >try.c <<'EOCP'
  607. Xmain()
  608. X{
  609. X    struct blurfl {
  610. X        int dyick;
  611. X    } foo, bar;
  612. X
  613. X    foo = bar;
  614. X}
  615. XEOCP
  616. Xif cc -c try.c >/dev/null 2>&1 ; then
  617. X    d_strctcpy="$define"
  618. X    echo "Yup, it can."
  619. Xelse
  620. X    d_strctcpy="$undef"
  621. X    echo "Nope, it can't."
  622. Xfi
  623. X$rm -f try.*
  624. X
  625. X: see if there is a vfork
  626. Xecho " "
  627. Xif $contains vfork libc.list >/dev/null 2>&1 ; then
  628. X    echo "vfork() found."
  629. X    d_vfork="$undef"
  630. Xelse
  631. X    echo "No vfork() found--will use fork() instead."
  632. X    d_vfork="$define"
  633. Xfi
  634. X
  635. X: check for void type
  636. Xecho " "
  637. X$cat <<EOM
  638. XChecking to see how well your C compiler groks the void type...
  639. X
  640. X  Support flag bits are:
  641. X    1: basic void declarations.
  642. X    2: arrays of pointers to functions returning void.
  643. X    4: operations between pointers to and addresses of void functions.
  644. X
  645. XEOM
  646. Xcase "$voidflags" in
  647. X'')
  648. X    $cat >try.c <<'EOCP'
  649. X#if TRY & 1
  650. Xvoid main() {
  651. X#else
  652. Xmain() {
  653. X#endif
  654. X    extern void *moo();
  655. X    void (*goo)();
  656. X#if TRY & 2
  657. X    void (*foo[10])();
  658. X#endif
  659. X
  660. X#if TRY & 4
  661. X    if(goo == moo) {
  662. X        exit(0);
  663. X    }
  664. X#endif
  665. X    exit(0);
  666. X}
  667. XEOCP
  668. X    if cc -S -DTRY=7 try.c >.out 2>&1 ; then
  669. X    voidflags=7
  670. X    echo "It appears to support void fully."
  671. X    if $contains warning .out >/dev/null 2>&1; then
  672. X        echo "However, you might get some warnings that look like this:"
  673. X        $cat .out
  674. X    fi
  675. X    else
  676. X    echo "Hmm, you compiler has some difficulty with void.  Checking further..."
  677. X    if cc -S -DTRY=1 try.c >/dev/null 2>&1 ; then
  678. X        echo "It supports 1..."
  679. X        if cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then
  680. X        voidflags=3
  681. X        echo "And it supports 2 but not 4."
  682. X        else
  683. X        echo "It doesn't support 2..."
  684. X        if cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then
  685. X            voidflags=5
  686. X            echo "But it supports 4."
  687. X        else
  688. X            voidflags=1
  689. X            echo "And it doesn't support 4."
  690. X        fi
  691. X        fi
  692. X    else
  693. X        echo "There is no support at all for void."
  694. X        voidflags=0
  695. X    fi
  696. X    fi
  697. Xesac
  698. Xdflt="$voidflags";
  699. Xrp="Your void support flags add up to what? [$dflt]"
  700. X$echo $n "$rp $c"
  701. X. myread
  702. Xvoidflags="$ans"
  703. X$rm -f try.* .out
  704. X
  705. X: preserve RCS keywords in files with variable substitution, grrr
  706. XLog='$Log'
  707. XHeader='$Header'
  708. X
  709. X: set up shell script to do ~ expansion
  710. Xcat >filexp <<EOSS
  711. X$startsh
  712. X: expand filename
  713. Xcase "\$1" in
  714. X ~/*|~)
  715. X    echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
  716. X    ;;
  717. X ~*)
  718. X    if $test -f /bin/csh; then
  719. X    /bin/csh -f -c "glob \$1"
  720. X    echo ""
  721. X    else
  722. X    name=\`$expr x\$1 : '..\([^/]*\)'\`
  723. X    dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
  724. X    if $test ! -d "\$dir"; then
  725. X        me=\`basename \$0\`
  726. X        echo "\$me: can't locate home directory for: \$name" >&2
  727. X        exit 1
  728. X    fi
  729. X    case "\$1" in
  730. X    */*)
  731. X        echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
  732. X        ;;
  733. X    *)
  734. X        echo \$dir
  735. X        ;;
  736. X    esac
  737. X    fi
  738. X    ;;
  739. X*)
  740. X    echo \$1
  741. X    ;;
  742. Xesac
  743. XEOSS
  744. Xchmod 755 filexp
  745. X$eunicefix filexp
  746. X
  747. X: determine where public executables go
  748. Xcase "$bin" in
  749. X'')
  750. X    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
  751. X    ;;
  752. X*)  dflt="$bin"
  753. X    ;;
  754. Xesac
  755. Xcont=true
  756. Xwhile $test "$cont" ; do
  757. X    echo " "
  758. X    rp="Where do you want to put the public executables? [$dflt]"
  759. X    $echo $n "$rp $c"
  760. X    . myread
  761. X    bin="$ans"
  762. X    bin=`filexp $bin`
  763. X    if test -d $bin; then
  764. X    cont=''
  765. X    else
  766. X    dflt=n
  767. X    rp="Directory $bin doesn't exist.  Use that name anyway? [$dflt]"
  768. X    $echo $n "$rp $c"
  769. X    . myread
  770. X    dflt=''
  771. X    case "$ans" in
  772. X    y*) cont='';;
  773. X    esac
  774. X    fi
  775. Xdone
  776. X
  777. X: determine where manual pages go
  778. Xcase "$mansrc" in
  779. X'')
  780. X    dflt=`loc . /usr/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1 /usr/man/man1`
  781. X    ;;
  782. X*)  dflt="$mansrc"
  783. X    ;;
  784. Xesac
  785. Xcont=true
  786. Xwhile $test "$cont" ; do
  787. X    echo " "
  788. X    rp="Where do the manual pages (source) go? [$dflt]"
  789. X    $echo $n "$rp $c"
  790. X    . myread
  791. X    mansrc=`filexp "$ans"`
  792. X    if test -d $mansrc; then
  793. X    cont=''
  794. X    else
  795. X    dflt=n
  796. X    rp="Directory $mansrc doesn't exist.  Use that name anyway? [$dflt]"
  797. X    $echo $n "$rp $c"
  798. X    . myread
  799. X    dflt=''
  800. X    case "$ans" in
  801. X    y*) cont='';;
  802. X    esac
  803. X    fi
  804. Xdone
  805. Xcase "$mansrc" in
  806. X*l)
  807. X    manext=l
  808. X    ;;
  809. X*n)
  810. X    manext=n
  811. X    ;;
  812. X*)
  813. X    manext=1
  814. X    ;;
  815. Xesac
  816. X
  817. X: see how we invoke the C preprocessor
  818. Xecho " "
  819. Xecho "Checking to see how your C preprocessor is invoked..."
  820. Xcat <<'EOT' >testcpp.c
  821. X#define ABC abc
  822. X#define XYZ xyz
  823. XABC.XYZ
  824. XEOT
  825. Xecho 'Maybe "cc -E" will work...'
  826. Xcc -E testcpp.c >testcpp.out 2>&1
  827. Xif $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  828. X    echo "Yup, it does."
  829. X    cpp='cc -E'
  830. Xelse
  831. X    echo 'Nope...maybe "cc -P" will work...'
  832. X    cc -P testcpp.c >testcpp.out 2>&1
  833. X    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  834. X    echo "Yup, that does."
  835. X    cpp='cc -P'
  836. X    else
  837. X    echo 'Nixed again...maybe "/lib/cpp" will work...'
  838. X    /lib/cpp testcpp.c >testcpp.out 2>&1
  839. X    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  840. X        echo "Hooray, it works!  I was beginning to wonder."
  841. X        cpp='/lib/cpp'
  842. X    else
  843. X        echo 'Hmm...maybe you already told me...'
  844. X        case "$cpp" in
  845. X        '') ;;
  846. X        *) $cpp testcpp.c >testcpp.out 2>&1;;
  847. X        esac
  848. X        if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  849. X        echo "Hooray, you did!  I was beginning to wonder."
  850. X        else
  851. X        dflt=blurfl
  852. X        $echo $n "Nope. I can't find a C preprocessor.  Name one: $c"
  853. X        rp='Name a C preprocessor:'
  854. X        . myread
  855. X        cpp="$ans"
  856. X        $cpp testcpp.c >testcpp.out 2>&1
  857. X        if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  858. X            echo "OK, that will do."
  859. X        else
  860. X            echo "Sorry, I can't get that to work.  Go find one."
  861. X            exit 1
  862. X        fi
  863. X        fi
  864. X    fi
  865. X    fi
  866. Xfi
  867. Xrm -f testcpp.c testcpp.out
  868. X
  869. X: get C preprocessor symbols handy
  870. Xecho " "
  871. Xecho $attrlist | $tr '[ ]' '[\012]' >Cppsym.know
  872. X$cat <<EOSS >Cppsym
  873. X$startsh
  874. Xcase "\$1" in
  875. X-l) list=true
  876. X    shift
  877. X    ;;
  878. Xesac
  879. Xunknown=''
  880. Xcase "\$list\$#" in
  881. X1|2)
  882. X    for sym do
  883. X    if $contains "^\$1$" Cppsym.true >/dev/null 2>&1; then
  884. X        exit 0
  885. X    elif $contains "^\$1$" Cppsym.know >/dev/null 2>&1; then
  886. X        :
  887. X    else
  888. X        unknown="\$unknown \$sym"
  889. X    fi
  890. X    done
  891. X    set X \$unknown
  892. X    shift
  893. X    ;;
  894. Xesac
  895. Xcase \$# in
  896. X0) exit 1;;
  897. Xesac
  898. Xecho \$* | $tr '[ ]' '[\012]' | $sed -e 's/\(.*\)/\\
  899. X#ifdef \1\\
  900. Xexit 0; _ _ _ _\1\\     \1\\
  901. X#endif\\
  902. X/' >/tmp/Cppsym\$\$
  903. Xecho exit 1 >>/tmp/Cppsym\$\$
  904. X$cpp /tmp/Cppsym\$\$ >/tmp/Cppsym2\$\$
  905. Xcase "\$list" in
  906. Xtrue) awk '\$6 != "" {print substr(\$6,2,100)}' </tmp/Cppsym2\$\$ ;;
  907. X*)
  908. X    sh /tmp/Cppsym2\$\$
  909. X    status=\$?
  910. X    ;;
  911. Xesac
  912. X$rm -f /tmp/Cppsym\$\$ /tmp/Cppsym2\$\$
  913. Xexit \$status
  914. XEOSS
  915. Xchmod 755 Cppsym
  916. X$eunicefix Cppsym
  917. Xecho "Your C preprocessor defines the following symbols:"
  918. XCppsym -l $attrlist >Cppsym.true
  919. Xcat Cppsym.true
  920. Xrmlist="$rmlist Cppsym Cppsym.know Cppsym.true"
  921. X
  922. X: see what memory models we can support
  923. Xcase "$models" in
  924. X'')
  925. X    if Cppsym pdp11; then
  926. X    dflt='unsplit split'
  927. X    else
  928. X    ans=`loc . X /lib/small /lib/large /usr/lib/small /usr/lib/large /lib/medium /usr/lib/medium /lib/huge`
  929. X    case "$ans" in
  930. X    X) dflt='none';;
  931. X    *)  if $test -d /lib/small || $test -d /usr/lib/small; then
  932. X        dflt='small'
  933. X        else
  934. X        dflt=''
  935. X        fi
  936. X        if $test -d /lib/medium || $test -d /usr/lib/medium; then
  937. X        dflt="$dflt medium"
  938. X        fi
  939. X        if $test -d /lib/large || $test -d /usr/lib/large; then
  940. X        dflt="$dflt large"
  941. X        fi
  942. X        if $test -d /lib/huge || $test -d /usr/lib/huge; then
  943. X        dflt="$dflt huge"
  944. X        fi
  945. X    esac
  946. X    fi
  947. X    ;;
  948. X*)  dflt="$models" ;;
  949. Xesac
  950. X$cat <<EOM
  951. XSome systems have different model sizes.  On most systems they are called
  952. Xsmall, medium, large, and huge.  On the PDP11 they are called unsplit and
  953. Xsplit.  If your system doesn't support different memory models, say "none".
  954. XIf you wish to force everything to one memory model, say "none" here and
  955. Xput the appropriate flags later when it asks you for other cc and ld flags.
  956. XVenix systems may wish to put "none" and let the compiler figure things out.
  957. X(In the following question multiple model names should be space separated.)
  958. X
  959. XEOM
  960. Xrp="Which models are supported? [$dflt]"
  961. X$echo $n "$rp $c"
  962. X. myread
  963. Xmodels="$ans"
  964. X
  965. Xcase "$models" in
  966. Xnone)
  967. X    small=''
  968. X    medium=''
  969. X    large=''
  970. X    huge=''
  971. X    unsplit=''
  972. X    split=''
  973. X    ;;
  974. X*split)
  975. X    case "$split" in
  976. X    '') 
  977. X    if $contains '-i' $mansrc/ld.1 >/dev/null 2>&1 || \
  978. X       $contains '-i' $mansrc/cc.1 >/dev/null 2>&1; then
  979. X        dflt='-i'
  980. X    else
  981. X        dflt='none'
  982. X    fi
  983. X    ;;
  984. X    *) dflt="$split";;
  985. X    esac
  986. X    rp="What flag indicates separate I and D space? [$dflt]"
  987. X    $echo $n "$rp $c"
  988. X    . myread
  989. X    case "$ans" in
  990. X    none) ans='';;
  991. X    esac
  992. X    split="$ans"
  993. X    unsplit=''
  994. X    ;;
  995. X*large*|*small*|*medium*|*huge*)
  996. X    case "$model" in
  997. X    *large*)
  998. X    case "$large" in
  999. X    '') dflt='-Ml';;
  1000. X    *) dflt="$large";;
  1001. X    esac
  1002. X    rp="What flag indicates large model? [$dflt]"
  1003. X    $echo $n "$rp $c"
  1004. X    . myread
  1005. X    case "$ans" in
  1006. X    none) ans='';
  1007. X    esac
  1008. X    large="$ans"
  1009. X    ;;
  1010. X    *) large='';;
  1011. X    esac
  1012. X    case "$model" in
  1013. X    *huge*)
  1014. X    case "$huge" in
  1015. X    '') dflt='-Mh';;
  1016. X    *) dflt="$huge";;
  1017. X    esac
  1018. X    rp="What flag indicates huge model? [$dflt]"
  1019. X    $echo $n "$rp $c"
  1020. X    . myread
  1021. X    case "$ans" in
  1022. X    none) ans='';
  1023. X    esac
  1024. X    huge="$ans"
  1025. X    ;;
  1026. X    *) huge="$large";;
  1027. X    esac
  1028. X    case "$model" in
  1029. X    *medium*)
  1030. X    case "$medium" in
  1031. X    '') dflt='-Mm';;
  1032. X    *) dflt="$medium";;
  1033. X    esac
  1034. X    rp="What flag indicates medium model? [$dflt]"
  1035. X    $echo $n "$rp $c"
  1036. X    . myread
  1037. X    case "$ans" in
  1038. X    none) ans='';
  1039. X    esac
  1040. X    medium="$ans"
  1041. X    ;;
  1042. X    *) medium="$large";;
  1043. X    esac
  1044. X    case "$model" in
  1045. X    *small*)
  1046. X    case "$small" in
  1047. X    '') dflt='none';;
  1048. X    *) dflt="$small";;
  1049. X    esac
  1050. X    rp="What flag indicates small model? [$dflt]"
  1051. X    $echo $n "$rp $c"
  1052. X    . myread
  1053. X    case "$ans" in
  1054. X    none) ans='';
  1055. X    esac
  1056. X    small="$ans"
  1057. X    ;;
  1058. X    *) small='';;
  1059. X    esac
  1060. X    ;;
  1061. X*)
  1062. X    echo "Unrecognized memory models--you may have to edit Makefile.SH"
  1063. X    ;;
  1064. Xesac
  1065. X
  1066. Xcase "$ccflags" in
  1067. X'') dflt='none';;
  1068. X*) dflt="$ccflags";;
  1069. Xesac
  1070. Xecho " "
  1071. Xrp="Any additional cc flags? [$dflt]"
  1072. X$echo $n "$rp $c"
  1073. X. myread
  1074. Xcase "$ans" in
  1075. Xnone) ans='';
  1076. Xesac
  1077. Xccflags="$ans"
  1078. X
  1079. Xcase "$ldflags" in
  1080. X'') if venix; then
  1081. X    dflt='-i -z'
  1082. X    else
  1083. X    dflt='none'
  1084. X    fi
  1085. X    ;;
  1086. X*) dflt="$ldflags";;
  1087. Xesac
  1088. Xecho " "
  1089. Xrp="Any additional ld flags? [$dflt]"
  1090. X$echo $n "$rp $c"
  1091. X. myread
  1092. Xcase "$ans" in
  1093. Xnone) ans='';
  1094. Xesac
  1095. Xldflags="$ans"
  1096. X
  1097. X: see if we need a special compiler
  1098. Xecho " "
  1099. Xif usg; then
  1100. X    case "$cc" in
  1101. X    '')
  1102. X    case "$Mcc" in
  1103. X    /*) dflt='Mcc'
  1104. X        ;;
  1105. X    *)
  1106. X        case "$large" in
  1107. X        -M*)
  1108. X        dflt='cc'
  1109. X        ;;
  1110. X        *)
  1111. X        if $contains '\-M' $mansrc/cc.1 >/dev/null 2>&1 ; then
  1112. X            dflt='cc -M'
  1113. X        else
  1114. X            dflt='cc'
  1115. X        fi
  1116. X        ;;
  1117. X        esac
  1118. X        ;;
  1119. X    esac
  1120. X    ;;
  1121. X    *)  dflt="$cc";;
  1122. X    esac
  1123. X    $cat <<'EOM'
  1124. XOn some systems the default C compiler will not resolve multiple global
  1125. Xreferences that happen to have the same name.  On some such systems the
  1126. X"Mcc" command may be used to force these to be resolved.  On other systems
  1127. Xa "cc -M" command is required.  (Note that the -M flag on other systems
  1128. Xindicates a memory model to use!)  What command will force resolution on
  1129. XEOM
  1130. X    $echo $n "this system? [$dflt] $c"
  1131. X    rp="Command to resolve multiple refs? [$dflt]"
  1132. X    . myread
  1133. X    cc="$ans"
  1134. Xelse
  1135. X    echo "Not a USG system--assuming cc can resolve multiple definitions."
  1136. X    cc=cc
  1137. Xfi
  1138. X
  1139. X: see if we should include -lnm
  1140. Xecho " "
  1141. Xif $test -r /usr/lib/libnm.a || $test -r /usr/local/lib/libnm.a ; then
  1142. X    echo "New math library found."
  1143. X    libnm='-lnm'
  1144. Xelse
  1145. X    ans=`loc libtermlib.a x $libpth`
  1146. X    case "$ans" in
  1147. X    x)
  1148. X    echo "No nm library found--the normal math library will have to do."
  1149. X    libnm=''
  1150. X    ;;
  1151. X    *)
  1152. X    echo "New math library found in $ans."
  1153. X    libnm="$ans"
  1154. X    ;;
  1155. X    esac
  1156. Xfi
  1157. X
  1158. Xecho " "
  1159. Xecho "End of configuration questions."
  1160. Xecho " "
  1161. X
  1162. X: create config.sh file
  1163. Xecho " "
  1164. Xif test -d ../UU; then
  1165. X    cd ..
  1166. Xfi
  1167. Xecho "Creating config.sh..."
  1168. X$spitshell <<EOT >config.sh
  1169. X$startsh
  1170. X# config.sh
  1171. X# This file was produced by running the Configure script.
  1172. X
  1173. Xd_eunice='$d_eunice'
  1174. Xeunicefix='$eunicefix'
  1175. Xdefine='$define'
  1176. Xloclist='$loclist'
  1177. Xexpr='$expr'
  1178. Xsed='$sed'
  1179. Xecho='$echo'
  1180. Xcat='$cat'
  1181. Xrm='$rm'
  1182. Xmv='$mv'
  1183. Xcp='$cp'
  1184. Xtail='$tail'
  1185. Xtr='$tr'
  1186. Xmkdir='$mkdir'
  1187. Xsort='$sort'
  1188. Xuniq='$uniq'
  1189. Xgrep='$grep'
  1190. Xtrylist='$trylist'
  1191. Xtest='$test'
  1192. Xinews='$inews'
  1193. Xegrep='$egrep'
  1194. Xmore='$more'
  1195. Xpg='$pg'
  1196. XMcc='$Mcc'
  1197. Xvi='$vi'
  1198. Xmailx='$mailx'
  1199. Xmail='$mail'
  1200. XLog='$Log'
  1201. XHeader='$Header'
  1202. Xbin='$bin'
  1203. Xcc='$cc'
  1204. Xcontains='$contains'
  1205. Xcpp='$cpp'
  1206. Xd_charsprf='$d_charsprf'
  1207. Xd_index='$d_index'
  1208. Xd_strctcpy='$d_strctcpy'
  1209. Xd_vfork='$d_vfork'
  1210. Xlibc='$libc'
  1211. Xlibnm='$libnm'
  1212. Xmansrc='$mansrc'
  1213. Xmanext='$manext'
  1214. Xmodels='$models'
  1215. Xsplit='$split'
  1216. Xsmall='$small'
  1217. Xmedium='$medium'
  1218. Xlarge='$large'
  1219. Xhuge='$huge'
  1220. Xccflags='$ccflags'
  1221. Xldflags='$ldflags'
  1222. Xn='$n'
  1223. Xc='$c'
  1224. Xpackage='$package'
  1225. Xspitshell='$spitshell'
  1226. Xshsharp='$shsharp'
  1227. Xsharpbang='$sharpbang'
  1228. Xstartsh='$startsh'
  1229. Xvoidflags='$voidflags'
  1230. Xdefvoidused='$defvoidused'
  1231. XCONFIG=true
  1232. XEOT
  1233. XCONFIG=true
  1234. X
  1235. Xecho " "
  1236. Xdflt=''
  1237. Xecho "If you didn't make any mistakes, then just type a carriage return here."
  1238. Xrp="If you need to edit config.sh, do it as a shell escape here:"
  1239. X$echo $n "$rp $c"
  1240. X. UU/myread
  1241. Xcase "$ans" in
  1242. X'') ;;
  1243. X*) : in case they cannot read
  1244. X    eval $ans;;
  1245. Xesac
  1246. X
  1247. Xecho " "
  1248. Xecho "Doing variable substitutions on .SH files..."
  1249. Xset `$grep '\.SH' <MANIFEST | awk '{print $1}'`
  1250. Xfor file in $*; do
  1251. X    case "$file" in
  1252. X    */*)
  1253. X    dir=`$expr X$file : 'X\(.*\)/'`
  1254. X    file=`$expr X$file : 'X.*/\(.*\)'`
  1255. X    (cd $dir && . $file)
  1256. X    ;;
  1257. X    *)
  1258. X    . $file
  1259. X    ;;
  1260. X    esac
  1261. Xdone
  1262. Xif test -f config.h.SH; then
  1263. X    if test ! -f config.h; then
  1264. X    : oops, they left it out of MANIFEST, probably, so do it anyway.
  1265. X    . config.h.SH
  1266. X    fi
  1267. Xfi
  1268. X
  1269. Xif $contains '^depend:' Makefile >/dev/null 2>&1; then
  1270. X    dflt=n
  1271. X    $cat <<EOM
  1272. X
  1273. XNow you need to generate make dependencies by running "make depend".
  1274. XYou might prefer to run it in background: "make depend > makedepend.out &"
  1275. XIt can take a while, so you might not want to run it right now.
  1276. X
  1277. XEOM
  1278. X    rp="Run make depend now? [$dflt]"
  1279. X    $echo $n "$rp $c"
  1280. X    . UU/myread
  1281. X    case "$ans" in
  1282. X    y*) make depend
  1283. X    echo "Now you must run a make."
  1284. X    ;;
  1285. X    *)  echo "You must run 'make depend' then 'make'."
  1286. X    ;;
  1287. X    esac
  1288. Xelif test -f Makefile; then
  1289. X    echo " "
  1290. X    echo "Now you must run a make."
  1291. Xelse
  1292. X    echo "Done."
  1293. Xfi
  1294. X
  1295. X$rm -f kit*isdone
  1296. Xcd UU && $rm -f $rmlist
  1297. X: end of Configure
  1298. !STUFFY!FUNK!
  1299. echo Extracting search.c
  1300. sed >search.c <<'!STUFFY!FUNK!' -e 's/X//'
  1301. X/* $Header: search.c,v 1.0 87/12/18 13:05:59 root Exp $
  1302. X *
  1303. X * $Log:    search.c,v $
  1304. X * Revision 1.0  87/12/18  13:05:59  root
  1305. X * Initial revision
  1306. X * 
  1307. X */
  1308. X
  1309. X/* string search routines */
  1310. X#include <stdio.h>
  1311. X#include <ctype.h>
  1312. X
  1313. X#include "EXTERN.h"
  1314. X#include "handy.h"
  1315. X#include "util.h"
  1316. X#include "INTERN.h"
  1317. X#include "search.h"
  1318. X
  1319. X#define VERBOSE
  1320. X#define FLUSH
  1321. X#define MEM_SIZE int
  1322. X
  1323. X#ifndef BITSPERBYTE
  1324. X#define BITSPERBYTE 8
  1325. X#endif
  1326. X
  1327. X#define BMAPSIZ (127 / BITSPERBYTE + 1)
  1328. X
  1329. X#define    CHAR    0        /*    a normal character */
  1330. X#define    ANY    1        /* .    matches anything except newline */
  1331. X#define    CCL    2        /* [..]    character class */
  1332. X#define    NCCL    3        /* [^..]negated character class */
  1333. X#define BEG    4        /* ^    beginning of a line */
  1334. X#define    END    5        /* $    end of a line */
  1335. X#define    LPAR    6        /* (    begin sub-match */
  1336. X#define    RPAR    7        /* )    end sub-match */
  1337. X#define    REF    8        /* \N    backreference to the Nth submatch */
  1338. X#define WORD    9        /* \w    matches alphanumeric character */
  1339. X#define NWORD    10        /* \W    matches non-alphanumeric character */
  1340. X#define WBOUND    11        /* \b    matches word boundary */
  1341. X#define NWBOUND    12        /* \B    matches non-boundary  */
  1342. X#define    FINIS    13        /*    the end of the pattern */
  1343. X#define CODEMASK 15
  1344. X
  1345. X/* Quantifiers: */
  1346. X
  1347. X#define MINZERO 16        /* minimum is 0, not 1 */
  1348. X#define MAXINF    32        /* maximum is infinity, not 1 */
  1349. X#define ASCSIZ 0200
  1350. Xtypedef char    TRANSTABLE[ASCSIZ];
  1351. X
  1352. Xstatic    TRANSTABLE trans = {
  1353. X0000,0001,0002,0003,0004,0005,0006,0007,
  1354. X0010,0011,0012,0013,0014,0015,0016,0017,
  1355. X0020,0021,0022,0023,0024,0025,0026,0027,
  1356. X0030,0031,0032,0033,0034,0035,0036,0037,
  1357. X0040,0041,0042,0043,0044,0045,0046,0047,
  1358. X0050,0051,0052,0053,0054,0055,0056,0057,
  1359. X0060,0061,0062,0063,0064,0065,0066,0067,
  1360. X0070,0071,0072,0073,0074,0075,0076,0077,
  1361. X0100,0101,0102,0103,0104,0105,0106,0107,
  1362. X0110,0111,0112,0113,0114,0115,0116,0117,
  1363. X0120,0121,0122,0123,0124,0125,0126,0127,
  1364. X0130,0131,0132,0133,0134,0135,0136,0137,
  1365. X0140,0141,0142,0143,0144,0145,0146,0147,
  1366. X0150,0151,0152,0153,0154,0155,0156,0157,
  1367. X0160,0161,0162,0163,0164,0165,0166,0167,
  1368. X0170,0171,0172,0173,0174,0175,0176,0177,
  1369. X};
  1370. Xstatic bool folding = FALSE;
  1371. X
  1372. Xstatic int err;
  1373. X#define NOERR 0
  1374. X#define BEGFAIL 1
  1375. X#define FATAL 2
  1376. X
  1377. Xstatic char *FirstCharacter;
  1378. Xstatic char *matchend;
  1379. Xstatic char *matchtill;
  1380. X
  1381. Xvoid
  1382. Xsearch_init()
  1383. X{
  1384. X#ifdef UNDEF
  1385. X    register int    i;
  1386. X    
  1387. X    for (i = 0; i < ASCSIZ; i++)
  1388. X    trans[i] = i;
  1389. X#else
  1390. X    ;
  1391. X#endif
  1392. X}
  1393. X
  1394. Xvoid
  1395. Xinit_compex(compex)
  1396. Xregister COMPEX *compex;
  1397. X{
  1398. X    /* the following must start off zeroed */
  1399. X
  1400. X    compex->precomp = Nullch;
  1401. X    compex->complen = 0;
  1402. X    compex->subbase = Nullch;
  1403. X}
  1404. X
  1405. X#ifdef NOTUSED
  1406. Xvoid
  1407. Xfree_compex(compex)
  1408. Xregister COMPEX *compex;
  1409. X{
  1410. X    if (compex->complen) {
  1411. X    safefree(compex->compbuf);
  1412. X    compex->complen = 0;
  1413. X    }
  1414. X    if (compex->subbase) {
  1415. X    safefree(compex->subbase);
  1416. X    compex->subbase = Nullch;
  1417. X    }
  1418. X}
  1419. X#endif
  1420. X
  1421. Xstatic char *gbr_str = Nullch;
  1422. Xstatic int gbr_siz = 0;
  1423. X
  1424. Xchar *
  1425. Xgetparen(compex,n)
  1426. Xregister COMPEX *compex;
  1427. Xint n;
  1428. X{
  1429. X    int length = compex->subend[n] - compex->subbeg[n];
  1430. X
  1431. X    if (!n &&
  1432. X    (!compex->numsubs || n > compex->numsubs || !compex->subend[n] || length<0))
  1433. X    return "";
  1434. X    growstr(&gbr_str, &gbr_siz, length+1);
  1435. X    safecpy(gbr_str, compex->subbeg[n], length+1);
  1436. X    return gbr_str;
  1437. X}
  1438. X
  1439. Xvoid
  1440. Xcase_fold(which)
  1441. Xint which;
  1442. X{
  1443. X    register int i;
  1444. X
  1445. X    if (which != folding) {
  1446. X    if (which) {
  1447. X        for (i = 'A'; i <= 'Z'; i++)
  1448. X        trans[i] = tolower(i);
  1449. X    }
  1450. X    else {
  1451. X        for (i = 'A'; i <= 'Z'; i++)
  1452. X        trans[i] = i;
  1453. X    }
  1454. X    folding = which;
  1455. X    }
  1456. X}
  1457. X
  1458. X/* Compile the regular expression into internal form */
  1459. X
  1460. Xchar *
  1461. Xcompile(compex, sp, regex, fold)
  1462. Xregister COMPEX *compex;
  1463. Xregister char   *sp;
  1464. Xint regex;
  1465. Xint fold;
  1466. X{
  1467. X    register int c;
  1468. X    register char  *cp;
  1469. X    char   *lastcp;
  1470. X    char    paren[MAXSUB],
  1471. X       *parenp;
  1472. X    char **alt = compex->alternatives;
  1473. X    char *retmes = "Badly formed search string";
  1474. X    case_fold(compex->do_folding = fold);
  1475. X    if (compex->precomp)
  1476. X    safefree(compex->precomp);
  1477. X    compex->precomp = savestr(sp);
  1478. X    if (!compex->complen) {
  1479. X    compex->compbuf = safemalloc(84);
  1480. X    compex->complen = 80;
  1481. X    }
  1482. X    cp = compex->compbuf;        /* point at compiled buffer */
  1483. X    *alt++ = cp;            /* first alternative starts here */
  1484. X    parenp = paren;            /* first paren goes here */
  1485. X    if (*sp == 0) {            /* nothing to compile? */
  1486. X#ifdef NOTDEF
  1487. X    if (*cp == 0)            /* nothing there yet? */
  1488. X        return "Null search string";
  1489. X#endif
  1490. X    if (*cp)
  1491. X        return Nullch;            /* just keep old expression */
  1492. X    }
  1493. X    compex->numsubs = 0;            /* no parens yet */
  1494. X    lastcp = 0;
  1495. X    for (;;) {
  1496. X    if (cp - compex->compbuf >= compex->complen) {
  1497. X        char *ocompbuf = compex->compbuf;
  1498. X
  1499. X        grow_comp(compex);
  1500. X        if (ocompbuf != compex->compbuf) {    /* adjust pointers? */
  1501. X        char **tmpalt;
  1502. X
  1503. X        cp = compex->compbuf + (cp - ocompbuf);
  1504. X        if (lastcp)
  1505. X            lastcp = compex->compbuf + (lastcp - ocompbuf);
  1506. X        for (tmpalt = compex->alternatives; tmpalt < alt; tmpalt++)
  1507. X            if (*tmpalt)
  1508. X            *tmpalt = compex->compbuf + (*tmpalt - ocompbuf);
  1509. X        }
  1510. X    }
  1511. X    c = *sp++;            /* get next char of pattern */
  1512. X    if (c == 0) {            /* end of pattern? */
  1513. X        if (parenp != paren) {    /* balanced parentheses? */
  1514. X#ifdef VERBOSE
  1515. X        retmes = "Missing right parenthesis";
  1516. X#endif
  1517. X        goto badcomp;
  1518. X        }
  1519. X        *cp++ = FINIS;        /* append a stopper */
  1520. X        *alt++ = 0;            /* terminate alternative list */
  1521. X        /*
  1522. X        compex->complen = cp - compex->compbuf + 1;
  1523. X        compex->compbuf = saferealloc(compex->compbuf,compex->complen+4); */
  1524. X        return Nullch;        /* return success */
  1525. X    }
  1526. X    if (c != '*' && c != '?' && c != '+')
  1527. X        lastcp = cp;
  1528. X    if (!regex) {            /* just a normal search string? */
  1529. X        *cp++ = CHAR;        /* everything is a normal char */
  1530. X        *cp++ = trans[c];
  1531. X    }
  1532. X    else                /* it is a regular expression */
  1533. X        switch (c) {
  1534. X        default:
  1535. X          normal_char:
  1536. X            *cp++ = CHAR;
  1537. X            *cp++ = trans[c];
  1538. X            continue;
  1539. X
  1540. X        case '.':
  1541. X            *cp++ = ANY;
  1542. X            continue;
  1543. X        case '[': {        /* character class */
  1544. X            register int i;
  1545. X            
  1546. X            if (cp - compex->compbuf >= compex->complen - BMAPSIZ) {
  1547. X            char *ocompbuf = compex->compbuf;
  1548. X
  1549. X            grow_comp(compex);    /* reserve bitmap */
  1550. X            if (ocompbuf != compex->compbuf) {/* adjust pointers? */
  1551. X                char **tmpalt;
  1552. X
  1553. X                cp = compex->compbuf + (cp - ocompbuf);
  1554. X                if (lastcp)
  1555. X                lastcp = compex->compbuf + (lastcp - ocompbuf);
  1556. X                for (tmpalt = compex->alternatives; tmpalt < alt;
  1557. X                  tmpalt++)
  1558. X                if (*tmpalt)
  1559. X                    *tmpalt =
  1560. X                    compex->compbuf + (*tmpalt - ocompbuf);
  1561. X            }
  1562. X            }
  1563. X            for (i = BMAPSIZ; i; --i)
  1564. X            cp[i] = 0;
  1565. X            
  1566. X            if ((c = *sp++) == '^') {
  1567. X            c = *sp++;
  1568. X            *cp++ = NCCL;    /* negated */
  1569. X            }
  1570. X            else
  1571. X            *cp++ = CCL;    /* normal */
  1572. X            
  1573. X            i = 0;        /* remember oldchar */
  1574. X            do {
  1575. X            if (c == '\0') {
  1576. X#ifdef VERBOSE
  1577. X                retmes = "Missing ]";
  1578. X#endif
  1579. X                goto badcomp;
  1580. X            }
  1581. X            if (c == '\\' && *sp) {
  1582. X                switch (*sp) {
  1583. X                default:
  1584. X                c = *sp++;
  1585. X                break;
  1586. X                case '0': case '1': case '2': case '3':
  1587. X                case '4': case '5': case '6': case '7':
  1588. X                c = *sp++ - '0';
  1589. X                if (index("01234567",*sp)) {
  1590. X                    c <<= 3;
  1591. X                    c += *sp++ - '0';
  1592. X                }
  1593. X                if (index("01234567",*sp)) {
  1594. X                    c <<= 3;
  1595. X                    c += *sp++ - '0';
  1596. X                }
  1597. X                break;
  1598. X                case 'b':
  1599. X                c = '\b';
  1600. X                sp++;
  1601. X                break;
  1602. X                case 'n':
  1603. X                c = '\n';
  1604. X                sp++;
  1605. X                break;
  1606. X                case 'r':
  1607. X                c = '\r';
  1608. X                sp++;
  1609. X                break;
  1610. X                case 'f':
  1611. X                c = '\f';
  1612. X                sp++;
  1613. X                break;
  1614. X                case 't':
  1615. X                c = '\t';
  1616. X                sp++;
  1617. X                break;
  1618. X                }
  1619. X            }
  1620. X            if (*sp == '-' && *(++sp))
  1621. X                i = *sp++;
  1622. X            else
  1623. X                i = c;
  1624. X            while (c <= i) {
  1625. X                cp[c / BITSPERBYTE] |= 1 << (c % BITSPERBYTE);
  1626. X                if (fold && isalpha(c))
  1627. X                cp[(c ^ 32) / BITSPERBYTE] |=
  1628. X                    1 << ((c ^ 32) % BITSPERBYTE);
  1629. X                    /* set the other bit too */
  1630. X                c++;
  1631. X            }
  1632. X            } while ((c = *sp++) != ']');
  1633. X            if (cp[-1] == NCCL)
  1634. X            cp[0] |= 1;
  1635. X            cp += BMAPSIZ;
  1636. X            continue;
  1637. X        }
  1638. X        case '^':
  1639. X            if (cp != compex->compbuf && cp[-1] != FINIS)
  1640. X            goto normal_char;
  1641. X            *cp++ = BEG;
  1642. X            continue;
  1643. X        case '$':
  1644. X            if (isdigit(*sp)) {
  1645. X            *cp++ = REF;
  1646. X            *cp++ = *sp - '0';
  1647. X            break;
  1648. X            }
  1649. X            if (*sp && *sp != '|')
  1650. X            goto normal_char;
  1651. X            *cp++ = END;
  1652. X            continue;
  1653. X        case '*': case '?': case '+':
  1654. X            if (lastcp == 0 ||
  1655. X            (*lastcp & (MINZERO|MAXINF)) ||
  1656. X            *lastcp == LPAR ||
  1657. X            *lastcp == RPAR ||
  1658. X            *lastcp == BEG ||
  1659. X            *lastcp == END ||
  1660. X            *lastcp == WBOUND ||
  1661. X            *lastcp == NWBOUND )
  1662. X            goto normal_char;
  1663. X            if (c != '+')
  1664. X            *lastcp |= MINZERO;
  1665. X            if (c != '?')
  1666. X            *lastcp |= MAXINF;
  1667. X            continue;
  1668. X        case '(':
  1669. X            if (compex->numsubs >= MAXSUB) {
  1670. X#ifdef VERBOSE
  1671. X            retmes = "Too many parens";
  1672. X#endif
  1673. X            goto badcomp;
  1674. X            }
  1675. X            *parenp++ = ++compex->numsubs;
  1676. X            *cp++ = LPAR;
  1677. X            *cp++ = compex->numsubs;
  1678. X            break;
  1679. X        case ')':
  1680. X            if (parenp <= paren) {
  1681. X#ifdef VERBOSE
  1682. X            retmes = "Unmatched right paren";
  1683. X#endif
  1684. X            goto badcomp;
  1685. X            }
  1686. X            *cp++ = RPAR;
  1687. X            *cp++ = *--parenp;
  1688. X            break;
  1689. X        case '|':
  1690. X            if (parenp>paren) {
  1691. X#ifdef VERBOSE
  1692. X            retmes = "No | in subpattern";    /* Sigh! */
  1693. X#endif
  1694. X            goto badcomp;
  1695. X            }
  1696. X            *cp++ = FINIS;
  1697. X            if (alt - compex->alternatives >= MAXALT) {
  1698. X#ifdef VERBOSE
  1699. X            retmes = "Too many alternatives";
  1700. X#endif
  1701. X            goto badcomp;
  1702. X            }
  1703. X            *alt++ = cp;
  1704. X            break;
  1705. X        case '\\':        /* backslashed thingie */
  1706. X            switch (c = *sp++) {
  1707. X            case '0': case '1': case '2': case '3': case '4':
  1708. X            case '5': case '6': case '7': case '8': case '9':
  1709. X            *cp++ = REF;
  1710. X            *cp++ = c - '0';
  1711. X            break;
  1712. X            case 'w':
  1713. X            *cp++ = WORD;
  1714. X            break;
  1715. X            case 'W':
  1716. X            *cp++ = NWORD;
  1717. X            break;
  1718. X            case 'b':
  1719. X            *cp++ = WBOUND;
  1720. X            break;
  1721. X            case 'B':
  1722. X            *cp++ = NWBOUND;
  1723. X            break;
  1724. X            default:
  1725. X            *cp++ = CHAR;
  1726. X            if (c == '\0')
  1727. X                goto badcomp;
  1728. X            switch (c) {
  1729. X            case 'n':
  1730. X                c = '\n';
  1731. X                break;
  1732. X            case 'r':
  1733. X                c = '\r';
  1734. X                break;
  1735. X            case 'f':
  1736. X                c = '\f';
  1737. X                break;
  1738. X            case 't':
  1739. X                c = '\t';
  1740. X                break;
  1741. X            }
  1742. X            *cp++ = c;
  1743. X            break;
  1744. X            }
  1745. X            break;
  1746. X        }
  1747. X    }
  1748. Xbadcomp:
  1749. X    compex->compbuf[0] = 0;
  1750. X    compex->numsubs = 0;
  1751. X    return retmes;
  1752. X}
  1753. X
  1754. Xvoid
  1755. Xgrow_comp(compex)
  1756. Xregister COMPEX *compex;
  1757. X{
  1758. X    compex->complen += 80;
  1759. X    compex->compbuf = saferealloc(compex->compbuf, (MEM_SIZE)compex->complen + 4);
  1760. X}
  1761. X
  1762. Xchar *
  1763. Xexecute(compex, addr, beginning, minend)
  1764. Xregister COMPEX *compex;
  1765. Xchar *addr;
  1766. Xbool beginning;
  1767. Xint minend;
  1768. X{
  1769. X    register char *p1 = addr;
  1770. X    register char *trt = trans;
  1771. X    register int c;
  1772. X    register int scr;
  1773. X    register int c2;
  1774. X    if (addr == Nullch)
  1775. X    return Nullch;
  1776. X    if (compex->numsubs) {            /* any submatches? */
  1777. X    for (c = 0; c <= compex->numsubs; c++)
  1778. X        compex->subbeg[c] = compex->subend[c] = Nullch;
  1779. X    }
  1780. X    case_fold(compex->do_folding);    /* make sure table is correct */
  1781. X    if (beginning)
  1782. X    FirstCharacter = p1;        /* for ^ tests */
  1783. X    else {
  1784. X    if (multiline || compex->alternatives[1] || compex->compbuf[0] != BEG)
  1785. X        FirstCharacter = Nullch;
  1786. X    else
  1787. X        return Nullch;        /* can't match */
  1788. X    }
  1789. X    matchend = Nullch;
  1790. X    matchtill = addr + minend;
  1791. X    err = 0;
  1792. X    if (compex->compbuf[0] == CHAR && !compex->alternatives[1]) {
  1793. X    if (compex->do_folding) {
  1794. X        c = compex->compbuf[1];    /* fast check for first character */
  1795. X        do {
  1796. X        if (trt[*p1] == c && try(compex, p1, compex->compbuf))
  1797. X            goto got_it;
  1798. X        } while (*p1++ && !err);
  1799. X    }
  1800. X    else {
  1801. X        c = compex->compbuf[1];    /* faster check for first character */
  1802. X        if (compex->compbuf[2] == CHAR)
  1803. X        c2 = compex->compbuf[3];
  1804. X        else
  1805. X        c2 = 0;
  1806. X        do {
  1807. X          false_alarm:
  1808. X        while (scr = *p1++, scr && scr != c) ;
  1809. X        if (!scr)
  1810. X            break;
  1811. X        if (c2 && *p1 != c2)    /* and maybe even second character */
  1812. X            goto false_alarm;
  1813. X        if (try(compex, p1, compex->compbuf+2)) {
  1814. X            p1--;
  1815. X            goto got_it;
  1816. X        }
  1817. X        } while (!err);
  1818. X    }
  1819. X    return Nullch;
  1820. X    }
  1821. X    else {            /* normal algorithm */
  1822. X    do {
  1823. X        register char **alt = compex->alternatives;
  1824. X        while (*alt) {
  1825. X        if (try(compex, p1, *alt++))
  1826. X            goto got_it;
  1827. X        }
  1828. X    } while (*p1++ && err < FATAL);
  1829. X    return Nullch;
  1830. X    }
  1831. X
  1832. Xgot_it:
  1833. X    if (compex->numsubs) {            /* any parens? */
  1834. X    trt = savestr(addr);        /* in case addr is not static */
  1835. X    if (compex->subbase)
  1836. X        safefree(compex->subbase);    /* (may be freeing addr!) */
  1837. X    compex->subbase = trt;
  1838. X    scr = compex->subbase - addr;
  1839. X    p1 += scr;
  1840. X    matchend += scr;
  1841. X    for (c = 0; c <= compex->numsubs; c++) {
  1842. X        if (compex->subend[c]) {
  1843. X        compex->subbeg[c] += scr;
  1844. X        compex->subend[c] += scr;
  1845. X        }
  1846. X    }
  1847. X    }
  1848. X    compex->subend[0] = matchend;
  1849. X    compex->subbeg[0] = p1;
  1850. X    return p1;
  1851. X}
  1852. Xbool
  1853. Xtry(compex, sp, cp)
  1854. XCOMPEX *compex;
  1855. Xregister char *cp;
  1856. Xregister char *sp;
  1857. X{
  1858. X    register char *basesp;
  1859. X    register char *trt = trans;
  1860. X    register int i;
  1861. X    register int backlen;
  1862. X    register int code;
  1863. X    while (*sp || (*cp & MAXINF) || *cp == BEG || *cp == RPAR ||
  1864. X    *cp == WBOUND || *cp == NWBOUND) {
  1865. X    switch ((code = *cp++) & CODEMASK) {
  1866. X        case CHAR:
  1867. X        basesp = sp;
  1868. X        i = *cp++;
  1869. X        if (code & MAXINF)
  1870. X            while (*sp && trt[*sp] == i) sp++;
  1871. X        else
  1872. X            if (*sp && trt[*sp] == i) sp++;
  1873. X        backlen = 1;
  1874. X        goto backoff;
  1875. X      backoff:
  1876. X        while (sp > basesp) {
  1877. X            if (try(compex, sp, cp))
  1878. X            goto right;
  1879. X            sp -= backlen;
  1880. X        }
  1881. X        if (code & MINZERO)
  1882. X            continue;
  1883. X        goto wrong;
  1884. X        case ANY:
  1885. X        basesp = sp;
  1886. X        if (code & MAXINF)
  1887. X            while (*sp && *sp != '\n') sp++;
  1888. X        else
  1889. X            if (*sp && *sp != '\n') sp++;
  1890. X        backlen = 1;
  1891. X        goto backoff;
  1892. X
  1893. X        case CCL:
  1894. X        basesp = sp;
  1895. X        if (code & MAXINF)
  1896. X            while (*sp && cclass(cp, *sp, 1)) sp++;
  1897. X        else
  1898. X            if (*sp && cclass(cp, *sp, 1)) sp++;
  1899. X        cp += BMAPSIZ;
  1900. X        backlen = 1;
  1901. X        goto backoff;
  1902. X        case NCCL:
  1903. X        basesp = sp;
  1904. X        if (code & MAXINF)
  1905. X            while (*sp && cclass(cp, *sp, 0)) sp++;
  1906. X        else
  1907. X            if (*sp && cclass(cp, *sp, 0)) sp++;
  1908. X        cp += BMAPSIZ;
  1909. X        backlen = 1;
  1910. X        goto backoff;
  1911. X        case END:
  1912. X        if (!*sp || *sp == '\n') {
  1913. X            matchtill--;
  1914. X            continue;
  1915. X        }
  1916. X        goto wrong;
  1917. X        case BEG:
  1918. X        if (sp == FirstCharacter || (
  1919. X            *sp && sp[-1] == '\n') ) {
  1920. X            matchtill--;
  1921. X            continue;
  1922. X        }
  1923. X        if (!multiline)        /* no point in advancing more */
  1924. X            err = BEGFAIL;
  1925. X        goto wrong;
  1926. X        case WORD:
  1927. X        basesp = sp;
  1928. X        if (code & MAXINF)
  1929. X            while (*sp && isalnum(*sp)) sp++;
  1930. X        else
  1931. X            if (*sp && isalnum(*sp)) sp++;
  1932. X        backlen = 1;
  1933. X        goto backoff;
  1934. X        case NWORD:
  1935. X        basesp = sp;
  1936. X        if (code & MAXINF)
  1937. X            while (*sp && !isalnum(*sp)) sp++;
  1938. X        else
  1939. X            if (*sp && !isalnum(*sp)) sp++;
  1940. X        backlen = 1;
  1941. X        goto backoff;
  1942. X        case WBOUND:
  1943. X        if ((sp == FirstCharacter || !isalnum(sp[-1])) !=
  1944. X            (!*sp || !isalnum(*sp)) )
  1945. X            continue;
  1946. X        goto wrong;
  1947. X        case NWBOUND:
  1948. X        if ((sp == FirstCharacter || !isalnum(sp[-1])) ==
  1949. X            (!*sp || !isalnum(*sp)))
  1950. X            continue;
  1951. X        goto wrong;
  1952. X        case FINIS:
  1953. X        goto right;
  1954. X        case LPAR:
  1955. X        compex->subbeg[*cp++] = sp;
  1956. X        continue;
  1957. X        case RPAR:
  1958. X        i = *cp++;
  1959. X        compex->subend[i] = sp;
  1960. X        compex->lastparen = i;
  1961. X        continue;
  1962. X        case REF:
  1963. X        if (compex->subend[i = *cp++] == 0) {
  1964. X            fputs("Bad subpattern reference\n",stdout) FLUSH;
  1965. X            err = FATAL;
  1966. X            goto wrong;
  1967. X        }
  1968. X        basesp = sp;
  1969. X        backlen = compex->subend[i] - compex->subbeg[i];
  1970. X        if (code & MAXINF)
  1971. X            while (*sp && subpat(compex, i, sp)) sp += backlen;
  1972. X        else
  1973. X            if (*sp && subpat(compex, i, sp)) sp += backlen;
  1974. X        goto backoff;
  1975. X        default:
  1976. X        fputs("Botched pattern compilation\n",stdout) FLUSH;
  1977. X        err = FATAL;
  1978. X        return -1;
  1979. X    }
  1980. X    }
  1981. X    if (*cp == FINIS || *cp == END) {
  1982. Xright:
  1983. X    if (matchend == Nullch || sp > matchend)
  1984. X        matchend = sp;
  1985. X    return matchend >= matchtill;
  1986. X    }
  1987. Xwrong:
  1988. X    matchend = Nullch;
  1989. X    return FALSE;
  1990. X}
  1991. Xbool
  1992. Xsubpat(compex, i, sp)
  1993. Xregister COMPEX *compex;
  1994. Xregister int i;
  1995. Xregister char *sp;
  1996. X{
  1997. X    register char *bp;
  1998. X    bp = compex->subbeg[i];
  1999. X    while (*sp && *bp == *sp) {
  2000. X    bp++;
  2001. X    sp++;
  2002. X    if (bp >= compex->subend[i])
  2003. X        return TRUE;
  2004. X    }
  2005. X    return FALSE;
  2006. X}
  2007. X
  2008. Xbool
  2009. Xcclass(set, c, af)
  2010. Xregister char  *set;
  2011. Xregister int c;
  2012. X{
  2013. X    c &= 0177;
  2014. X#if BITSPERBYTE == 8
  2015. X    if (set[c >> 3] & 1 << (c & 7))
  2016. X#else
  2017. X    if (set[c / BITSPERBYTE] & 1 << (c % BITSPERBYTE))
  2018. X#endif
  2019. X    return af;
  2020. X    return !af;
  2021. X}
  2022. !STUFFY!FUNK!
  2023. echo Extracting array.c
  2024. sed >array.c <<'!STUFFY!FUNK!' -e 's/X//'
  2025. X/* $Header: array.c,v 1.0 87/12/18 13:04:42 root Exp $
  2026. X *
  2027. X * $Log:    array.c,v $
  2028. X * Revision 1.0  87/12/18  13:04:42  root
  2029. X * Initial revision
  2030. X * 
  2031. X */
  2032. X
  2033. X#include <stdio.h>
  2034. X#include "EXTERN.h"
  2035. X#include "handy.h"
  2036. X#include "util.h"
  2037. X#include "search.h"
  2038. X#include "perl.h"
  2039. X
  2040. XSTR *
  2041. Xafetch(ar,key)
  2042. Xregister ARRAY *ar;
  2043. Xint key;
  2044. X{
  2045. X    if (key < 0 || key > ar->ary_max)
  2046. X    return Nullstr;
  2047. X    return ar->ary_array[key];
  2048. X}
  2049. X
  2050. Xbool
  2051. Xastore(ar,key,val)
  2052. Xregister ARRAY *ar;
  2053. Xint key;
  2054. XSTR *val;
  2055. X{
  2056. X    bool retval;
  2057. X
  2058. X    if (key < 0)
  2059. X    return FALSE;
  2060. X    if (key > ar->ary_max) {
  2061. X    int newmax = key + ar->ary_max / 5;
  2062. X
  2063. X    ar->ary_array = (STR**)saferealloc((char*)ar->ary_array,
  2064. X        (newmax+1) * sizeof(STR*));
  2065. X    bzero((char*)&ar->ary_array[ar->ary_max+1],
  2066. X        (newmax - ar->ary_max) * sizeof(STR*));
  2067. X    ar->ary_max = newmax;
  2068. X    }
  2069. X    if (key > ar->ary_fill)
  2070. X    ar->ary_fill = key;
  2071. X    retval = (ar->ary_array[key] != Nullstr);
  2072. X    if (retval)
  2073. X    str_free(ar->ary_array[key]);
  2074. X    ar->ary_array[key] = val;
  2075. X    return retval;
  2076. X}
  2077. X
  2078. Xbool
  2079. Xadelete(ar,key)
  2080. Xregister ARRAY *ar;
  2081. Xint key;
  2082. X{
  2083. X    if (key < 0 || key > ar->ary_max)
  2084. X    return FALSE;
  2085. X    if (ar->ary_array[key]) {
  2086. X    str_free(ar->ary_array[key]);
  2087. X    ar->ary_array[key] = Nullstr;
  2088. X    return TRUE;
  2089. X    }
  2090. X    return FALSE;
  2091. X}
  2092. X
  2093. XARRAY *
  2094. Xanew()
  2095. X{
  2096. X    register ARRAY *ar = (ARRAY*)safemalloc(sizeof(ARRAY));
  2097. X
  2098. X    ar->ary_array = (STR**) safemalloc(5 * sizeof(STR*));
  2099. X    ar->ary_fill = -1;
  2100. X    ar->ary_max = 4;
  2101. X    bzero((char*)ar->ary_array, 5 * sizeof(STR*));
  2102. X    return ar;
  2103. X}
  2104. X
  2105. Xvoid
  2106. Xafree(ar)
  2107. Xregister ARRAY *ar;
  2108. X{
  2109. X    register int key;
  2110. X
  2111. X    if (!ar)
  2112. X    return;
  2113. X    for (key = 0; key <= ar->ary_fill; key++)
  2114. X    str_free(ar->ary_array[key]);
  2115. X    safefree((char*)ar->ary_array);
  2116. X    safefree((char*)ar);
  2117. X}
  2118. X
  2119. Xbool
  2120. Xapush(ar,val)
  2121. Xregister ARRAY *ar;
  2122. XSTR *val;
  2123. X{
  2124. X    return astore(ar,++(ar->ary_fill),val);
  2125. X}
  2126. X
  2127. XSTR *
  2128. Xapop(ar)
  2129. Xregister ARRAY *ar;
  2130. X{
  2131. X    STR *retval;
  2132. X
  2133. X    if (ar->ary_fill < 0)
  2134. X    return Nullstr;
  2135. X    retval = ar->ary_array[ar->ary_fill];
  2136. X    ar->ary_array[ar->ary_fill--] = Nullstr;
  2137. X    return retval;
  2138. X}
  2139. X
  2140. Xaunshift(ar,num)
  2141. Xregister ARRAY *ar;
  2142. Xregister int num;
  2143. X{
  2144. X    register int i;
  2145. X    register STR **sstr,**dstr;
  2146. X
  2147. X    if (num <= 0)
  2148. X    return;
  2149. X    astore(ar,ar->ary_fill+num,(STR*)0);    /* maybe extend array */
  2150. X    sstr = ar->ary_array + ar->ary_fill;
  2151. X    dstr = sstr + num;
  2152. X    for (i = ar->ary_fill; i >= 0; i--) {
  2153. X    *dstr-- = *sstr--;
  2154. X    }
  2155. X    bzero((char*)(ar->ary_array), num * sizeof(STR*));
  2156. X}
  2157. X
  2158. XSTR *
  2159. Xashift(ar)
  2160. Xregister ARRAY *ar;
  2161. X{
  2162. X    STR *retval;
  2163. X
  2164. X    if (ar->ary_fill < 0)
  2165. X    return Nullstr;
  2166. X    retval = ar->ary_array[0];
  2167. X    bcopy((char*)(ar->ary_array+1),(char*)ar->ary_array,
  2168. X      ar->ary_fill * sizeof(STR*));
  2169. X    ar->ary_array[ar->ary_fill--] = Nullstr;
  2170. X    return retval;
  2171. X}
  2172. X
  2173. Xlong
  2174. Xalen(ar)
  2175. Xregister ARRAY *ar;
  2176. X{
  2177. X    return (long)ar->ary_fill;
  2178. X}
  2179. X
  2180. Xvoid
  2181. Xajoin(ar,delim,str)
  2182. Xregister ARRAY *ar;
  2183. Xchar *delim;
  2184. Xregister STR *str;
  2185. X{
  2186. X    register int i;
  2187. X    register int len;
  2188. X    register int dlen;
  2189. X
  2190. X    if (ar->ary_fill < 0) {
  2191. X    str_set(str,"");
  2192. X    STABSET(str);
  2193. X    return;
  2194. X    }
  2195. X    dlen = strlen(delim);
  2196. X    len = ar->ary_fill * dlen;        /* account for delimiters */
  2197. X    for (i = ar->ary_fill; i >= 0; i--)
  2198. X    len += str_len(ar->ary_array[i]);
  2199. X    str_grow(str,len);            /* preallocate for efficiency */
  2200. X    str_sset(str,ar->ary_array[0]);
  2201. X    for (i = 1; i <= ar->ary_fill; i++) {
  2202. X    str_ncat(str,delim,dlen);
  2203. X    str_scat(str,ar->ary_array[i]);
  2204. X    }
  2205. X    STABSET(str);
  2206. X}
  2207. !STUFFY!FUNK!
  2208. echo Extracting t/op.sleep
  2209. sed >t/op.sleep <<'!STUFFY!FUNK!' -e 's/X//'
  2210. X#!./perl
  2211. X
  2212. X# $Header: op.sleep,v 1.0 87/12/18 13:14:17 root Exp $
  2213. X
  2214. Xprint "1..1\n";
  2215. X
  2216. X$x = sleep 2;
  2217. Xif ($x == 2) {print "ok 1\n";} else {print "not ok 1\n";}
  2218. !STUFFY!FUNK!
  2219. echo ""
  2220. echo "End of kit 6 (of 10)"
  2221. cat /dev/null >kit6isdone
  2222. config=true
  2223. for iskit in 1 2 3 4 5 6 7 8 9 10; do
  2224.     if test -f kit${iskit}isdone; then
  2225.     echo "You have run kit ${iskit}."
  2226.     else
  2227.     echo "You still need to run kit ${iskit}."
  2228.     config=false
  2229.     fi
  2230. done
  2231. case $config in
  2232.     true)
  2233.     echo "You have run all your kits.  Please read README and then type Configure."
  2234.     chmod 755 Configure
  2235.     ;;
  2236. esac
  2237. : Someone might mail this, so...
  2238. exit
  2239.