home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume33 / mailagnt / part04 < prev    next >
Encoding:
Text File  |  1992-11-19  |  55.4 KB  |  2,071 lines

  1. Newsgroups: comp.sources.misc
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Subject:  v33i096:  mailagent - Rule Based Mail Filtering, Part04/17
  4. Message-ID: <1992Nov20.050314.13479@sparky.imd.sterling.com>
  5. X-Md4-Signature: d7db0d0f7b07860dba8e47519b4f4e56
  6. Date: Fri, 20 Nov 1992 05:03:14 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: ram@eiffel.com (Raphael Manfredi)
  10. Posting-number: Volume 33, Issue 96
  11. Archive-name: mailagent/part04
  12. Environment: Perl, Sendmail, UNIX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  Configure.a agent/pl/matching.pl agent/test/basic/filter.t
  19. # Wrapped by kent@sparky on Wed Nov 18 22:42:21 1992
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 4 (of 17)."'
  23. if test -f 'Configure.a' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'Configure.a'\"
  25. else
  26.   echo shar: Extracting \"'Configure.a'\" \(36159 characters\)
  27.   sed "s/^X//" >'Configure.a' <<'END_OF_FILE'
  28. X#! /bin/sh
  29. X#
  30. X# If these # comments don't work, trim them. Don't worry about any
  31. X# other shell scripts, Configure will trim # comments from them for you.
  32. X#
  33. X# (If you are trying to port this package to a machine without sh,
  34. X# I would suggest you have a look at the prototypical config.h.SH file
  35. X# and edit it to reflect your system. Some packages may include samples
  36. X# of config.h for certain machines, so you might look for one of those.)
  37. X#
  38. X# Yes, you may rip this off to use in other distribution packages. This
  39. X# script belongs to the public domain and cannot be copyrighted.
  40. X#
  41. X# (Note: this Configure script was generated automatically. Rather than
  42. X# working with this copy of Configure, you may wish to get metaconfig.
  43. X# Write to ram@eiffel.com (Raphael Manfredi) and I will send you the
  44. X# latest revision of the dist package, which includes metaconfig.)
  45. X
  46. X# $Id: Configure,v 2.9 92/07/14 16:46:52 ram Exp $
  47. X#
  48. X# Generated on Tue Jul 14 14:23:38 PDT 1992 [metaconfig 2.8 PL13]
  49. X
  50. Xcat >/tmp/c1$$ <<EOF
  51. X
  52. XARGGGHHHH!!!!!
  53. X
  54. XSCO csh still thinks true is false.  Write to SCO today and tell them that next
  55. Xyear Configure ought to "rm /bin/csh" unless they fix their blasted shell. :-)
  56. X
  57. X(Actually, Configure ought to just patch csh in place.  Hmm.  Hmmmmm.  All
  58. Xwe'd have to do is go in and swap the && and || tokens, wherever they are.)
  59. X
  60. X[End of diatribe.  We now return you to your regularly scheduled programming...]
  61. XEOF
  62. Xcat >/tmp/c2$$ <<EOF
  63. X
  64. XOOPS!  You naughty creature!  You didn't run Configure with sh!
  65. XI will attempt to remedy the situation by running sh for you...
  66. XEOF
  67. X
  68. Xtrue || cat /tmp/c1$$ /tmp/c2$$
  69. Xtrue || exec sh $0
  70. X
  71. Xexport PATH || cat /tmp/c2$$
  72. Xexport PATH || exec sh $0
  73. Xrm -f /tmp/c1$$ /tmp/c2$$
  74. X
  75. X: sanity checks
  76. XPATH=".:$PATH:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin"
  77. XPATH=$PATH:'/usr/5bin:/etc:/usr/gnu/bin:/usr/new:/usr/new/bin:/usr/nbin'
  78. XPATH=$PATH:'/sys5.3/bin:/sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/ucb'
  79. XPATH=$PATH:'/bsd4.3/usr/bin:/usr/bsd:/bsd43/bin:/usr/ccs/bin'
  80. Xexport PATH
  81. X
  82. Xif test ! -t 0; then
  83. X    echo "Say 'sh Configure', not 'sh <Configure'"
  84. X    exit 1
  85. Xfi
  86. X
  87. X(alias) >/dev/null 2>&1 && \
  88. X    echo "(I see you are using the Korn shell.  Some ksh's blow up on Configure," && \
  89. X    echo "especially on exotic machines.  If yours does, try the Bourne shell instead.)"
  90. X
  91. Xtest -d UU || mkdir UU
  92. Xcd UU && rm -f *
  93. X
  94. Xcase "$1" in
  95. X-d) shift; fastread='yes';;
  96. Xesac
  97. X
  98. Xd_bsd=''
  99. Xd_eunice=''
  100. Xd_xenix=''
  101. Xeunicefix=''
  102. XMcc=''
  103. Xawk=''
  104. Xbison=''
  105. Xcat=''
  106. Xchgrp=''
  107. Xchmod=''
  108. Xchown=''
  109. Xcompress=''
  110. Xcp=''
  111. Xcpio=''
  112. Xcpp=''
  113. Xcsh=''
  114. Xdate=''
  115. Xecho=''
  116. Xegrep=''
  117. Xemacs=''
  118. Xexpr=''
  119. Xgrep=''
  120. Xinews=''
  121. Xless=''
  122. Xline=''
  123. Xlint=''
  124. Xln=''
  125. Xlp=''
  126. Xlpr=''
  127. Xls=''
  128. Xmail=''
  129. Xmailx=''
  130. Xmake=''
  131. Xmkdir=''
  132. Xmore=''
  133. Xmv=''
  134. Xnroff=''
  135. Xperl=''
  136. Xpg=''
  137. Xpmake=''
  138. Xpr=''
  139. Xrm=''
  140. Xrmail=''
  141. Xsed=''
  142. Xsendmail=''
  143. Xsleep=''
  144. Xsmail=''
  145. Xsort=''
  146. Xsubmit=''
  147. Xtail=''
  148. Xtar=''
  149. Xtbl=''
  150. Xtest=''
  151. Xtouch=''
  152. Xtr=''
  153. Xtroff=''
  154. Xuname=''
  155. Xuniq=''
  156. Xuuname=''
  157. Xvi=''
  158. Xzcat=''
  159. Xmyuname=''
  160. XAuthor=''
  161. XDate=''
  162. XHeader=''
  163. XId=''
  164. XLocker=''
  165. XLog=''
  166. XRCSfile=''
  167. XRevision=''
  168. XSource=''
  169. XState=''
  170. Xbin=''
  171. Xcc=''
  172. Xccflags=''
  173. Xcppflags=''
  174. Xldflags=''
  175. Xlkflags=''
  176. Xoptimize=''
  177. Xcontains=''
  178. Xcppminus=''
  179. Xcppstdin=''
  180. Xd_bcopy=''
  181. Xaphostname=''
  182. Xd_gethname=''
  183. Xd_phostname=''
  184. Xd_uname=''
  185. Xd_hidnet=''
  186. Xhiddennet=''
  187. Xd_index=''
  188. Xd_portable=''
  189. Xd_rename=''
  190. Xd_strerrm=''
  191. Xd_strerror=''
  192. Xd_sysernlst=''
  193. Xd_syserrlst=''
  194. Xd_time=''
  195. Xtimetype=''
  196. Xd_uwait=''
  197. Xd_vfork=''
  198. Xd_voidsig=''
  199. Xsignal_t=''
  200. Xhostname=''
  201. Xmydomain=''
  202. Xphostname=''
  203. Xi_fcntl=''
  204. Xi_string=''
  205. Xstrings=''
  206. Xi_sysfile=''
  207. Xi_syswait=''
  208. Xi_systime=''
  209. Xi_systimek=''
  210. Xi_time=''
  211. Xtimeincl=''
  212. Xtimezone=''
  213. Xintsize=''
  214. Xlibc=''
  215. Xnm_opt=''
  216. Xlibpth=''
  217. Xplibpth=''
  218. Xlibs=''
  219. Xmaildir=''
  220. Xmailfile=''
  221. Xmanext=''
  222. Xmansrc=''
  223. Xmkdep=''
  224. Xhuge=''
  225. Xlarge=''
  226. Xmedium=''
  227. Xmodels=''
  228. Xsmall=''
  229. Xsplit=''
  230. Xc=''
  231. Xn=''
  232. Xorgname=''
  233. Xpackage=''
  234. Xperlpath=''
  235. Xpidtype=''
  236. Xprivlib=''
  237. Xreg10=''
  238. Xreg11=''
  239. Xreg12=''
  240. Xreg13=''
  241. Xreg14=''
  242. Xreg15=''
  243. Xreg16=''
  244. Xreg1=''
  245. Xreg2=''
  246. Xreg3=''
  247. Xreg4=''
  248. Xreg5=''
  249. Xreg6=''
  250. Xreg7=''
  251. Xreg8=''
  252. Xreg9=''
  253. Xregisters=''
  254. Xscriptdir=''
  255. Xsharpbang=''
  256. Xshsharp=''
  257. Xspitshell=''
  258. Xstartsh=''
  259. Xsysman=''
  260. Xuidtype=''
  261. Xincpath=''
  262. Xmips=''
  263. Xmips_type=''
  264. Xusrinc=''
  265. Xd_whoami=''
  266. Xi_sysselct=''
  267. XCONFIG=''
  268. X: set package name
  269. Xpackage=mailagent
  270. X
  271. X: Eunice requires " " instead of "", can you believe it
  272. Xecho " "
  273. X: Here we go...
  274. Xecho "Beginning of configuration questions for $package kit."
  275. X
  276. Xdefine='define'
  277. Xundef='undef'
  278. Xsmallmach='pdp11 i8086 z8000 i80286 iAPX286'
  279. Xrmlist='ark[1-9]isdone ark[1-9][0-9]isdone'
  280. Xtrap 'echo " "; rm -f $rmlist; exit 1' 1 2 3 15
  281. X
  282. X: We must find out about Eunice early
  283. Xeunicefix=':'
  284. Xif test -f /etc/unixtovms; then
  285. X    eunicefix=/etc/unixtovms
  286. Xfi
  287. Xif test -f /etc/unixtovms.exe; then
  288. X    eunicefix=/etc/unixtovms.exe
  289. Xfi
  290. X
  291. X: Find out which program gives a meaningful exit status
  292. Xif ls blurfl >/dev/null 2>&1; then
  293. X    if awk '' blurfl >/dev/null 2>&1; then
  294. X        check='cat'
  295. X    else
  296. X        check='awk ""'
  297. X    fi
  298. Xelse
  299. X    check='ls'
  300. Xfi
  301. X
  302. X: Now test for existence of everything in MANIFEST
  303. Xecho " "
  304. Xif test -f ../MANIFEST; then
  305. X    echo "First let's make sure your kit is complete.  Checking..."
  306. X    : some grep do not return a proper exit status
  307. X    grep '^---' ../MANIFEST > .grepmani 2>/dev/null
  308. X    if test -s .grepmani; then
  309. X(cd ..; eval $check `awk '!/^.*\/$/{if (b) print $1}
  310. X/^---/{b=1}' MANIFEST` || kill $$) >/dev/null
  311. X    else
  312. X(cd ..; eval $check `awk '!/^.*\/$/{print $1}' MANIFEST` || kill $$) >/dev/null
  313. X    fi
  314. X    echo "Looks good..."
  315. Xelse
  316. X    echo "No MANIFEST found. Hope your kit is complete !"
  317. Xfi
  318. Xrm -f .grepmani
  319. X
  320. X: list of known cpp symbols
  321. Xattrlist="DGUX M_I186 M_I286 M_I386 M_I8086 M_XENIX UTS __DGUX__"
  322. Xattrlist="$attrlist _AIX __STDC__ __m88k__ ansi bsd4_2 gcos gimpel"
  323. Xattrlist="$attrlist hp9000s300 hp9000s500 hp9000s800 hpux"
  324. Xattrlist="$attrlist i186 i386 i486 i8086 iAPX286 ibm interdata"
  325. Xattrlist="$attrlist m88k mc300 mc500 mc68000 mc68k mc700 mert"
  326. Xattrlist="$attrlist mips ns16000 ns32000 nsc32000 os pdp11 posix pyr"
  327. Xattrlist="$attrlist sinix sony sparc sun tower tower32 tower32_600"
  328. Xattrlist="$attrlist tower32_800 tss u3b2 u3b20 u3b200 u3b5 ultrix unix"
  329. Xattrlist="$attrlist vax venix xenix z8000"
  330. X
  331. X: no include file wanted by default
  332. Xinclwanted=''
  333. X
  334. X: change the next line if compiling for Xenix/286 on Xenix/386
  335. Xxlibpath='/usr/lib/386 /lib/386'
  336. Xlibpth='/usr/lib/large /lib '$xlibpth' /lib/large'
  337. Xlibpth=$libpth' /usr/lib/small /lib/small'
  338. X
  339. X
  340. X: some greps do not return status, grrr.
  341. Xecho "grimblepritz" >grimble
  342. Xif grep blurfldyick grimble >/dev/null 2>&1 ; then
  343. X    contains=contains
  344. Xelif grep grimblepritz grimble >/dev/null 2>&1 ; then
  345. X    contains=grep
  346. Xelse
  347. X    contains=contains
  348. Xfi
  349. Xrm -f grimble
  350. X: the following should work in any shell
  351. Xcase "$contains" in
  352. Xcontains*)
  353. X    echo " "
  354. X    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
  355. X    cat >contains <<'EOSS'
  356. Xgrep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
  357. XEOSS
  358. Xchmod +x contains
  359. Xesac
  360. X
  361. X: first determine how to suppress newline on echo command
  362. Xecho " "
  363. Xecho "Checking echo to see how to suppress newlines..."
  364. X(echo "hi there\c" ; echo " ") >.echotmp
  365. Xif $contains c .echotmp >/dev/null 2>&1 ; then
  366. X    echo "...using -n."
  367. X    n='-n'
  368. X    c=''
  369. Xelse
  370. X    cat <<'EOM'
  371. X...using \c
  372. XEOM
  373. X    n=''
  374. X    c='\c'
  375. Xfi
  376. Xecho $n "The star should be here-->$c"
  377. Xecho '*'
  378. Xrm -f .echotmp
  379. X
  380. X: set up the echo used in my read
  381. Xmyecho="case \"\$xxxm\" in
  382. X'') echo $n \"\$rp $c\";;
  383. X*) case \"\$rp\" in
  384. X    '') echo $n \"[\$xxxm] $c\";;
  385. X    *) echo $n \"\$rp [\$xxxm] $c\";;
  386. X    esac;;
  387. Xesac"
  388. X
  389. X: now set up to do reads with possible shell escape and default assignment
  390. Xcat <<EOSC >myread
  391. Xxxxm=\$dflt
  392. X$myecho
  393. Xcase "\$fastread" in
  394. Xyes) case "\$dflt" in
  395. X    '') ans='!';;
  396. X    *) ans=''; echo " " ;;
  397. X    esac;;
  398. X*) ans='!';;
  399. Xesac
  400. Xwhile expr "X\$ans" : "X!" >/dev/null; do
  401. X    read answ
  402. X    set x \$xxxm
  403. X    shift
  404. X    aok=''; eval "ans=\"\$answ\"" && aok=y
  405. X    case  "\$answ" in
  406. X    "\$ans")
  407. X        case "\$ans" in
  408. X        !)
  409. X            sh
  410. X            echo " "
  411. X            $myecho
  412. X            ;;
  413. X        !*)
  414. X            set x \`expr "X\$ans" : "X!\(.*\)\$"\`
  415. X            shift
  416. X            sh -c "\$*"
  417. X            echo " "
  418. X            $myecho
  419. X            ;;
  420. X        esac;;
  421. X    *)
  422. X        case "\$aok" in
  423. X        y)
  424. X            echo "*** Substitution done -- please confirm."
  425. X            xxxm="\$ans"
  426. X            ans=\`echo $n "\$ans$c" | tr '\012' ' '\`
  427. X            xxxm="\$ans"
  428. X            ans=!
  429. X            ;;
  430. X        *)
  431. X            echo "*** Error -- try again."
  432. X            ans=!
  433. X            ;;
  434. X        esac
  435. X        $myecho
  436. X        ;;
  437. X    esac
  438. Xdone
  439. Xcase "\$ans" in
  440. X'') ans="\$xxxm";;
  441. Xesac
  442. XEOSC
  443. X
  444. X: general instructions
  445. Xcat <<EOH
  446. XThis installation shell script will examine your system and ask you questions
  447. Xto determine how the mailagent package should be installed.  If you get stuck
  448. Xon a question, you may use a ! shell escape to start a subshell or execute a
  449. Xcommand.  Many of the questions will have default answers in square brackets;
  450. Xtyping carriage return will give you the default.
  451. X
  452. XOn some of the questions which ask for file or directory names you are allowed
  453. Xto use the ~name construct to specify the login directory belonging to "name",
  454. Xeven if you don't have a shell which knows about that.  Questions where this is
  455. Xallowed will be marked "(~name ok)".
  456. X
  457. XEOH
  458. Xrp=''
  459. Xdflt="Type carriage return to continue"
  460. X. myread
  461. Xcat <<'EOH'
  462. X
  463. XThe prompter used in this script allows you to use shell variables and
  464. Xbackticks in your answers.  You may use $1, $2, etc...  to refer to the words
  465. Xin the default answer, as if the default line was a set of arguments given to a
  466. Xscript shell.  This means you may also use $* to repeat the whole default line,
  467. Xso you do not have to re-type everything to add something to the default.
  468. X
  469. XEverytime there is a substitution, you will have to confirm.  If there is an
  470. Xerror (e.g. an unmatched backtick), the default answer will remain unchanged
  471. Xand you will be prompted again.
  472. X
  473. XIf you are in a hurry, you may run 'Configure -d'.  This will bypass nearly all
  474. Xthe questions and use the computed defaults (or the previous answers if there
  475. Xwas already a config.sh file).
  476. X
  477. XEOH
  478. X. myread
  479. Xcat <<EOH
  480. X
  481. XMuch effort has been expended to ensure that this shell script will run on any
  482. XUnix system.  If despite that it blows up on yours, your best bet is to edit
  483. XConfigure and run it again.  Also, let me (ram@eiffel.com)
  484. Xknow how I blew it.  If you can't run Configure for some reason, you'll have to
  485. Xgenerate a config.sh file by hand.
  486. X
  487. XThis installation script affects things in two ways:
  488. X
  489. X1) it may do direct variable substitutions on some of the files included
  490. X   in this kit.
  491. X2) it builds a config.h file for inclusion in C programs.  You may edit
  492. X   any of these files as the need arises after running this script.
  493. X
  494. XIf you make a mistake on a question, there is no easy way to back up to it
  495. Xcurrently.  The easiest thing to do is to edit config.sh and rerun all the SH
  496. Xfiles.  Configure will offer to let you do this before it runs the SH files.
  497. X
  498. XEOH
  499. Xdflt="Type carriage return to continue"
  500. X. myread
  501. X
  502. X: see if sh knows # comments
  503. Xecho " "
  504. Xecho "Checking your sh to see if it knows about # comments..."
  505. Xif sh -c '#' >/dev/null 2>&1 ; then
  506. X    echo "Your sh handles # comments correctly."
  507. X    shsharp=true
  508. X    spitshell=cat
  509. X    echo " "
  510. X    echo "Okay, let's see if #! works on this system..."
  511. X    echo "#!/bin/cat" >try
  512. X    $eunicefix try
  513. X    chmod +x try
  514. X    try > today
  515. X    if test -s today; then
  516. X        echo "It does."
  517. X        sharpbang='#!'
  518. X    else
  519. X        echo "#! /bin/cat" > try
  520. X        $eunicefix try
  521. X        chmod +x 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 "It doesn't."
  528. X            sharpbang=': use '
  529. X        fi
  530. X    fi
  531. Xelse
  532. X    echo "Your sh doesn't grok # comments--I will strip them later on."
  533. X    shsharp=false
  534. X    echo "exec grep -v '^[     ]*#'" >spitshell
  535. X    chmod +x spitshell
  536. X    $eunicefix spitshell
  537. X    spitshell=`pwd`/spitshell
  538. X    echo "I presume that if # doesn't work, #! won't work either!"
  539. X    sharpbang=': use '
  540. Xfi
  541. Xrm -f try today
  542. X
  543. X: figure out how to guarantee sh startup
  544. Xecho " "
  545. Xecho "Checking out how to guarantee sh startup..."
  546. Xstartsh=$sharpbang'/bin/sh'
  547. Xecho "Let's see if '$startsh' works..."
  548. Xcat >try <<EOSS
  549. X$startsh
  550. Xset abc
  551. Xtest "$?abc" != 1
  552. XEOSS
  553. X
  554. Xchmod +x try
  555. X$eunicefix try
  556. Xif try; then
  557. X    echo "Yup, it does."
  558. Xelse
  559. X    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
  560. Xfi
  561. Xrm -f try
  562. X
  563. X: find out where common programs are
  564. Xecho " "
  565. Xecho "Locating common programs..."
  566. Xcat <<EOSC >loc
  567. X$startsh
  568. Xcase \$# in
  569. X0) exit 1;;
  570. Xesac
  571. Xthing=\$1
  572. Xshift
  573. Xdflt=\$1
  574. Xshift
  575. Xfor dir in \$*; do
  576. X    case "\$thing" in
  577. X    .)
  578. X    if test -d \$dir/\$thing; then
  579. X        echo \$dir
  580. X        exit 0
  581. X    fi
  582. X    ;;
  583. X    *)
  584. X    if test -f \$dir/\$thing; then
  585. X        echo \$dir/\$thing
  586. X        exit 0
  587. X    elif test -f \$dir/\$thing.exe; then
  588. X        : on Eunice apparently
  589. X        echo \$dir/\$thing
  590. X        exit 0
  591. X    fi
  592. X    ;;
  593. X    esac
  594. Xdone
  595. Xecho \$dflt
  596. Xexit 1
  597. XEOSC
  598. Xchmod +x loc
  599. X$eunicefix loc
  600. Xloclist="
  601. Xawk
  602. Xcat
  603. Xchgrp
  604. Xchmod
  605. Xchown
  606. Xecho
  607. Xexpr
  608. Xgrep
  609. Xmv
  610. Xrm
  611. Xsed
  612. Xsleep
  613. Xsort
  614. Xtr
  615. Xuniq
  616. X"
  617. Xtrylist="
  618. XMcc
  619. Xcpp
  620. Xdate
  621. Xinews
  622. Xnroff
  623. Xperl
  624. Xtest
  625. Xuname
  626. Xzcat
  627. X"
  628. Xpth=`echo $PATH | sed -e 's/:/ /g'`
  629. Xpth="$pth /lib /usr/lib"
  630. Xfor file in $loclist; do
  631. X    xxx=`loc $file $file $pth`
  632. X    eval $file=$xxx
  633. X    eval _$file=$xxx
  634. X    case "$xxx" in
  635. X    /*)
  636. X    echo $file is in $xxx.
  637. X    ;;
  638. X    *)
  639. X    echo "I don't know where $file is.  I hope it's in everyone's PATH."
  640. X    ;;
  641. X    esac
  642. Xdone
  643. Xecho " "
  644. Xecho "Don't worry if any of the following aren't found..."
  645. Xans=offhand
  646. Xfor file in $trylist; do
  647. X    xxx=`loc $file $file $pth`
  648. X    eval $file=$xxx
  649. X    eval _$file=$xxx
  650. X    case "$xxx" in
  651. X    /*)
  652. X    echo $file is in $xxx.
  653. X    ;;
  654. X    *)
  655. X    echo "I don't see $file out there, $ans."
  656. X    ans=either
  657. X    ;;
  658. X    esac
  659. Xdone
  660. Xcase "$egrep" in
  661. Xegrep)
  662. X    echo "Substituting grep for egrep."
  663. X    egrep=$grep
  664. X    ;;
  665. Xesac
  666. Xcase "$test" in
  667. Xtest)
  668. X    echo "Hopefully test is built into your sh."
  669. X    ;;
  670. X/bin/test)
  671. X    if sh -c "PATH= test true" >/dev/null 2>&1; then
  672. X    echo "Using the test built into your sh."
  673. X    test=test
  674. X    fi
  675. X    ;;
  676. X*)
  677. X    test=test
  678. X    ;;
  679. Xesac
  680. Xcase "$echo" in
  681. Xecho)
  682. X    echo "Hopefully echo is built into your sh."
  683. X    ;;
  684. X/bin/echo)
  685. X    echo " "
  686. X    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
  687. X    $echo $n "hi there$c" >foo1
  688. X    echo $n "hi there$c" >foo2
  689. X    if cmp foo1 foo2 >/dev/null 2>&1; then
  690. X    echo "They are compatible.  In fact, they may be identical."
  691. X    else
  692. X    case "$n" in
  693. X    '-n') n='' c='\c';;
  694. X    *) n='-n' c='';;
  695. X    esac
  696. X    cat <<FOO
  697. XThey are not compatible!  You are probably running ksh on a non-USG system.
  698. XI'll have to use /bin/echo instead of the builtin, since Bourne shell doesn't
  699. Xhave echo built in and we may have to run some Bourne shell scripts.  That
  700. Xmeans I'll have to use $ans to suppress newlines now.  Life is ridiculous.
  701. X
  702. XFOO
  703. X    $echo $n "The star should be here-->$c"
  704. X    $echo "*"
  705. X    fi
  706. X    $rm -f foo1 foo2
  707. X    ;;
  708. X*)
  709. X    : cross your fingers
  710. X    echo=echo
  711. X    ;;
  712. Xesac
  713. Xrmlist="$rmlist loc"
  714. X
  715. X: try to determine whether config.sh was made on this system
  716. Xmyuname=`( ($uname -a) 2>/dev/null || hostname) 2>&1`
  717. Xdflt=n
  718. Xif test -f ../config.sh; then
  719. X    xxx=$myuname
  720. X    eval "`grep myuname= ../config.sh`"
  721. X    if test "X$xxx" = "X$myuname"; then
  722. X        dflt=y
  723. X    fi
  724. Xfi
  725. X
  726. X: get old answers, if there is a config file out there
  727. Xhint=default
  728. Xif test -f ../config.sh; then
  729. X    echo " "
  730. X    rp="I see a config.sh file.  Did Configure make it on THIS system?"
  731. X    . myread
  732. X    case "$ans" in
  733. X    n*|N*) echo "OK, I'll ignore it.";;
  734. X    *)  echo "Fetching default answers from your old config.sh file..."
  735. X        tmp="$n"
  736. X        ans="$c"
  737. X        . ../config.sh
  738. X        cp ../config.sh .
  739. X        n="$tmp"
  740. X        c="$ans"
  741. X        hint=previous
  742. X        ;;
  743. X    esac
  744. Xfi
  745. X
  746. X: restore computed paths
  747. Xfor file in $loclist $trylist; do
  748. X    eval $file="\$_$file"
  749. Xdone
  750. X
  751. X: preserve RCS keywords in files with variable substitution, grrr
  752. XHeader='$Header'
  753. XId='$Id'
  754. XLog='$Log'
  755. X
  756. X: make some quick guesses about what we are up against
  757. Xecho " "
  758. X$echo $n "Hmm...  $c"
  759. X$cat /usr/include/signal.h /usr/include/sys/signal.h >foo 2>/dev/null
  760. Xif test `echo abc | tr a-z A-Z` = Abc ; then
  761. X    xxx=`./loc addbib blurfl $pth`
  762. X    if $test -f $xxx; then
  763. X        echo "Looks kind of like a USG system with BSD features, but we'll see..."
  764. X        echo exit 0 >bsd
  765. X        echo exit 0 >usg
  766. X        echo exit 1 >v7
  767. X    else
  768. X        if $contains SIGTSTP foo >/dev/null 2>&1 ; then
  769. X            echo "Looks kind of like an extended USG system, but we'll see..."
  770. X        else
  771. X            echo "Looks kind of like a USG system, but we'll see..."
  772. X        fi
  773. X        echo exit 1 >bsd
  774. X        echo exit 0 >usg
  775. X        echo exit 1 >v7
  776. X    fi
  777. X    d_bsd="$undef"
  778. Xelif $contains SIGTSTP foo >/dev/null 2>&1 ; then
  779. X    echo "Looks kind of like a BSD system, but we'll see..."
  780. X    d_bsd="$define"
  781. X    echo exit 0 >bsd
  782. X    echo exit 1 >usg
  783. X    echo exit 1 >v7
  784. Xelse
  785. X    echo "Looks kind of like a Version 7 system, but we'll see..."
  786. X    d_bsd="$undef"
  787. X    echo exit 1 >bsd
  788. X    echo exit 1 >usg
  789. X    echo exit 0 >v7
  790. Xfi
  791. Xcase "$eunicefix" in
  792. X*unixtovms*)
  793. X    cat <<'EOI'
  794. XThere is, however, a strange, musty smell in the air that reminds me of
  795. Xsomething...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
  796. XEOI
  797. X    echo "exit 0" >eunice
  798. X    eunicefix=unixtovms
  799. X    d_eunice="$define"
  800. X: it so happens the Eunice I know will not run shell scripts in Unix format
  801. X    ;;
  802. X*)
  803. X    echo " "
  804. X    echo "Congratulations.  You aren't running Eunice."
  805. X    eunicefix=':'
  806. X    d_eunice="$undef"
  807. X    echo "exit 1" >eunice
  808. X    ;;
  809. Xesac
  810. Xif test -f /xenix; then
  811. X    echo "Actually, this looks more like a XENIX system..."
  812. X    echo "exit 0" >xenix
  813. X    d_xenix="$define"
  814. Xelse
  815. X    echo " "
  816. X    echo "It's not Xenix..."
  817. X    echo "exit 1" >xenix
  818. X    d_xenix="$undef"
  819. Xfi
  820. Xchmod +x xenix
  821. X$eunicefix xenix
  822. Xif test -f /venix; then
  823. X    echo "Actually, this looks more like a VENIX system..."
  824. X    echo "exit 0" >venix
  825. Xelse
  826. X    echo " "
  827. X    if xenix; then
  828. X    : null
  829. X    else
  830. X    echo "Nor is it Venix..."
  831. X    fi
  832. X    echo "exit 1" >venix
  833. Xfi
  834. Xchmod +x bsd usg v7 eunice venix
  835. X$eunicefix bsd usg v7 eunice venix
  836. X$rm -f foo
  837. Xrmlist="$rmlist bsd usg v7 eunice venix xenix"
  838. X
  839. X: set up shell script to do ~ expansion
  840. Xcat >filexp <<EOSS
  841. X$startsh
  842. X: expand filename
  843. Xcase "\$1" in
  844. X ~/*|~)
  845. X    echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
  846. X    ;;
  847. X ~*)
  848. X    if $test -f /bin/csh; then
  849. X    /bin/csh -f -c "glob \$1"
  850. X    echo ""
  851. X    else
  852. X    name=\`$expr x\$1 : '..\([^/]*\)'\`
  853. X    dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
  854. X    if $test ! -d "\$dir"; then
  855. X        me=\`basename \$0\`
  856. X        echo "\$me: can't locate home directory for: \$name" >&2
  857. X        exit 1
  858. X    fi
  859. X    case "\$1" in
  860. X    */*)
  861. X        echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
  862. X        ;;
  863. X    *)
  864. X        echo \$dir
  865. X        ;;
  866. X    esac
  867. X    fi
  868. X    ;;
  869. X*)
  870. X    echo \$1
  871. X    ;;
  872. Xesac
  873. XEOSS
  874. Xchmod +x filexp
  875. X$eunicefix filexp
  876. X
  877. X: determine where manual pages are on this system
  878. Xecho " "
  879. Xcase "$sysman" in
  880. X'') sysman=`loc . /usr/man/man1 /usr/man/man1 /usr/man/mann /usr/man/manl /usr/man/local/man1 /usr/man/u_man/man1 /usr/share/man/man1 /usr/catman/u_man/man1 /usr/man/l_man/man1 /usr/local/man/u_man/man1 /usr/local/man/l_man/man1 /usr/man/man.L`
  881. X    ;;
  882. Xesac
  883. Xif test -d "$sysman"; then
  884. X    echo "System manual is in $sysman."
  885. Xelse
  886. X    echo "Could not find manual pages in source form."
  887. Xfi
  888. X
  889. X: see what memory models we can support
  890. Xcase "$models" in
  891. X'')
  892. X    $cat >pdp11.c <<'EOP'
  893. Xmain() {
  894. X#ifdef pdp11
  895. X    exit(0);
  896. X#else
  897. X    exit(1);
  898. X#endif
  899. X}
  900. XEOP
  901. X    cc -o pdp11 pdp11.c >/dev/null 2>&1
  902. X    if pdp11 2>/dev/null; then
  903. X        dflt='unsplit split'
  904. X    else
  905. X        ans=`loc . X /lib/small /lib/large /usr/lib/small /usr/lib/large /lib/medium /usr/lib/medium /lib/huge`
  906. X        case "$ans" in
  907. X        X) dflt='none';;
  908. X        *) if $test -d /lib/small || $test -d /usr/lib/small; then
  909. X                dflt='small'
  910. X            else
  911. X                dflt=''
  912. X            fi
  913. X            if $test -d /lib/medium || $test -d /usr/lib/medium; then
  914. X                dflt="$dflt medium"
  915. X            fi
  916. X            if $test -d /lib/large || $test -d /usr/lib/large; then
  917. X                dflt="$dflt large"
  918. X            fi
  919. X            if $test -d /lib/huge || $test -d /usr/lib/huge; then
  920. X                dflt="$dflt huge"
  921. X            fi
  922. X        esac
  923. X    fi;;
  924. X*) dflt="$models";;
  925. Xesac
  926. X$cat <<EOM
  927. XSome systems have different model sizes.  On most systems they are called
  928. Xsmall, medium, large, and huge.  On the PDP11 they are called unsplit and
  929. Xsplit.  If your system doesn't support different memory models, say "none".
  930. XIf you wish to force everything to one memory model, say "none" here and
  931. Xput the appropriate flags later when it asks you for other cc and ld flags.
  932. XVenix systems may wish to put "none" and let the compiler figure things out.
  933. X(In the following question multiple model names should be space separated.)
  934. X
  935. XEOM
  936. Xrp="Which models are supported?"
  937. X. myread
  938. Xmodels="$ans"
  939. X
  940. Xcase "$models" in
  941. Xnone)
  942. X    small=''
  943. X    medium=''
  944. X    large=''
  945. X    huge=''
  946. X    unsplit=''
  947. X    split=''
  948. X    ;;
  949. X*split)
  950. X    case "$split" in
  951. X    '') if $contains '\-i' $sysman/ld.1 >/dev/null 2>&1 || \
  952. X             $contains '\-i' $sysman/cc.1 >/dev/null 2>&1; then
  953. X            dflt='-i'
  954. X        else
  955. X            dflt='none'
  956. X        fi;;
  957. X    *) dflt="$split";;
  958. X    esac
  959. X    rp="What flag indicates separate I and D space?"
  960. X    . myread
  961. X    case "$ans" in
  962. X    none) ans='';;
  963. X    esac
  964. X    split="$ans"
  965. X    unsplit='';;
  966. X*large*|*small*|*medium*|*huge*)
  967. X    case "$model" in
  968. X    *large*)
  969. X        case "$large" in
  970. X        '') dflt='-Ml';;
  971. X        *) dflt="$large";;
  972. X        esac
  973. X    rp="What flag indicates large model?"
  974. X    . myread
  975. X    case "$ans" in
  976. X    none) ans='';
  977. X    esac
  978. X    large="$ans";;
  979. X    *) large='';;
  980. X    esac
  981. X    case "$model" in
  982. X    *huge*) case "$huge" in
  983. X        '') dflt='-Mh';;
  984. X        *) dflt="$huge";;
  985. X        esac
  986. X        rp="What flag indicates huge model?"
  987. X        . myread
  988. X        case "$ans" in
  989. X        none) ans='';
  990. X        esac
  991. X        huge="$ans";;
  992. X    *) huge="$large";;
  993. X    esac
  994. X    case "$model" in
  995. X    *medium*) case "$medium" in
  996. X        '') dflt='-Mm';;
  997. X        *) dflt="$medium";;
  998. X        esac
  999. X        rp="What flag indicates medium model?"
  1000. X        . myread
  1001. X        case "$ans" in
  1002. X        none) ans='';
  1003. X        esac
  1004. X        medium="$ans";;
  1005. X    *) medium="$large";;
  1006. X    esac
  1007. X    case "$model" in
  1008. X    *small*) case "$small" in
  1009. X        '') dflt='none';;
  1010. X        *) dflt="$small";;
  1011. X        esac
  1012. X        rp="What flag indicates small model?"
  1013. X        . myread
  1014. X        case "$ans" in
  1015. X        none) ans='';
  1016. X        esac
  1017. X        small="$ans";;
  1018. X    *) small='';;
  1019. X    esac
  1020. X    ;;
  1021. X*)
  1022. X    echo "Unrecognized memory models--you may have to edit Makefile.SH"
  1023. X    ;;
  1024. Xesac
  1025. X
  1026. X: see if we need a special compiler
  1027. Xecho " "
  1028. Xif usg; then
  1029. X    case "$cc" in
  1030. X    '') case "$Mcc" in
  1031. X        /*) dflt='Mcc';;
  1032. X        *) case "$large" in
  1033. X            -M*) dflt='cc';;
  1034. X            *)    if $contains '\-M' $sysman/cc.1 >/dev/null 2>&1 ; then
  1035. X                    if $contains '\-M' $sysman/cpp.1 >/dev/null 2>&1; then
  1036. X                        dflt='cc'
  1037. X                    else
  1038. X                        dflt='cc -M'
  1039. X                    fi
  1040. X                else
  1041. X                    dflt='cc'
  1042. X                fi;;
  1043. X            esac;;
  1044. X        esac;;
  1045. X    *)  dflt="$cc";;
  1046. X    esac
  1047. X    $cat <<'EOM'
  1048. XOn some systems the default C compiler will not resolve multiple global
  1049. Xreferences that happen to have the same name.  On some such systems the "Mcc"
  1050. Xcommand may be used to force these to be resolved.  On other systems a "cc -M"
  1051. Xcommand is required.  (Note that the -M flag on other systems indicates a
  1052. Xmemory model to use!) If you have the Gnu C compiler, you might wish to use
  1053. Xthat instead.
  1054. X
  1055. XEOM
  1056. X    rp="What command will force resolution on this system?"
  1057. X    . myread
  1058. X    cc="$ans"
  1059. Xelse
  1060. X    case "$cc" in
  1061. X    '') dflt=cc;;
  1062. X    *) dflt="$cc";;
  1063. X    esac
  1064. X    rp="Use which C compiler?"
  1065. X    . myread
  1066. X    cc="$ans"
  1067. Xfi
  1068. Xcase "$cc" in
  1069. Xgcc*) cpp=`loc gcc-cpp $cpp $pth`;;
  1070. Xesac
  1071. X
  1072. X: What should the include directory be ?
  1073. Xecho " "
  1074. X$echo $n "Hmm...  $c"
  1075. Xcase "$usrinc" in
  1076. X'') dflt='/usr/include';;
  1077. X*) dflt=$usrinc;;
  1078. Xesac
  1079. Xincpath=''
  1080. Xmips_type=''
  1081. Xif $test -f /bin/mips && /bin/mips; then
  1082. X    echo "Looks like a MIPS system..."
  1083. X    $cat >usr.c <<'EOCP'
  1084. X#ifdef SYSTYPE_BSD43
  1085. X/bsd43
  1086. X#endif
  1087. XEOCP
  1088. X    if $cc -E usr.c > usr.out && $contains / usr.out >/dev/null 2>&1; then
  1089. X        dflt='/bsd43/usr/include'
  1090. X        incpath='/bsd43'
  1091. X        mips_type='BSD 4.3'
  1092. X    else
  1093. X        mips_type='System V'
  1094. X    fi
  1095. X    echo "and you're compiling with the $mips_type compiler and libraries."
  1096. Xelse
  1097. X    echo "Doesn't look like a MIPS system."
  1098. X    echo "exit 1" >mips
  1099. X    chmod +x mips
  1100. X    $eunicefix mips
  1101. Xfi
  1102. Xcont=true
  1103. Xwhile $test "$cont"; do
  1104. X    echo " "
  1105. X    rp="Where are the include files you want to use?"
  1106. X    . myread
  1107. X    usrinc="$ans"
  1108. X    if $test -d "$ans"; then
  1109. X        cont=''
  1110. X    else
  1111. X        if $test "$fastread" = yes; then
  1112. X            dflt=y
  1113. X        else
  1114. X            dflt=n
  1115. X        fi
  1116. X        rp="Directory $ans doesn't exist.  Use that name anyway?"
  1117. X        . myread
  1118. X        dflt=''
  1119. X        case "$ans" in
  1120. X        y*) cont='';;
  1121. X        esac
  1122. X    fi
  1123. Xdone
  1124. X$rm -f usr.c usr.out
  1125. X
  1126. X: now get the host name
  1127. Xecho " "
  1128. Xecho "Figuring out host name..."
  1129. Xcont=true
  1130. Xecho 'Maybe "hostname" will work...'
  1131. Xif ans=`sh -c hostname 2>&1` ; then
  1132. X    hostname=$ans
  1133. X    phostname=hostname
  1134. X    cont=''
  1135. Xfi
  1136. Xif $test "$cont"; then
  1137. X    if xenix; then
  1138. X        echo 'Oh, dear.  Maybe "/etc/systemid" is the key...'
  1139. X        if ans=`cat /etc/systemid 2>&1` ; then
  1140. X            hostname=$ans
  1141. X            phostname='cat /etc/systemid'
  1142. X            echo "Whadyaknow.  Xenix always was a bit strange..."
  1143. X            cont=''
  1144. X        fi
  1145. X    elif $test -r /etc/systemid; then
  1146. X        echo "(What is a non-Xenix system doing with /etc/systemid?)"
  1147. X    fi
  1148. Xfi
  1149. Xif $test "$cont"; then
  1150. X    echo 'No, maybe "uuname -l" will work...'
  1151. X    if ans=`sh -c 'uuname -l' 2>&1` ; then
  1152. X        hostname=$ans
  1153. X        phostname='uuname -l'
  1154. X    else
  1155. X        echo 'Strange.  Maybe "uname -n" will work...'
  1156. X        if ans=`sh -c 'uname -n' 2>&1` ; then
  1157. X            hostname=$ans
  1158. X            phostname='uname -n'
  1159. X        else
  1160. X            echo 'Oh well, maybe I can mine it out of whoami.h...'
  1161. X            if ans=`sh -c $contains' sysname $usrinc/whoami.h' 2>&1` ; then
  1162. X                hostname=`echo "$ans" | $sed 's/^.*"\(.*\)"/\1/'`
  1163. X                phostname="sed -n -e '"'/sysname/s/^.*\"\\(.*\\)\"/\1/{'"' -e p -e q -e '}' <$usrinc/whoami.h"
  1164. X            else
  1165. X                case "$hostname" in
  1166. X                '') echo "Does this machine have an identity crisis or something?"
  1167. X                    phostname='';;
  1168. X                *) echo "Well, you said $hostname before...";;
  1169. X                esac
  1170. X            fi
  1171. X        fi
  1172. X    fi
  1173. Xfi
  1174. X: you do not want to know about this
  1175. Xset $hostname
  1176. Xhostname=$1
  1177. X
  1178. X: translate upper to lower if necessary
  1179. Xcase "$hostname" in
  1180. X*[A-Z]*)
  1181. X    hostname=`echo $hostname | tr '[A-Z]' '[a-z]'`
  1182. X    echo "(Normalizing case in your host name)"
  1183. X    ;;
  1184. Xesac
  1185. X
  1186. X: verify guess
  1187. Xif $test "$hostname" ; then
  1188. X    dflt=y
  1189. X    rp='Your host name appears to be "'$hostname'".'" Right?"
  1190. X    . myread
  1191. X    case "$ans" in
  1192. X    y*) ;;
  1193. X    *) hostname='';;
  1194. X    esac
  1195. Xfi
  1196. X
  1197. X: bad guess or no guess
  1198. Xwhile $test "X$hostname" = X ; do
  1199. X    dflt=''
  1200. X    rp="Please type the (one word) name of your host:"
  1201. X    . myread
  1202. X    hostname="$ans"
  1203. Xdone
  1204. X
  1205. Xcase "$hostname" in
  1206. X*.*)
  1207. X    dflt=`expr "X$hostname" : "X[^.]*\(\..*\)"`
  1208. X    hostname=`expr "X$hostname" : "X\([^.]*\)\."`
  1209. X    echo "(Trimming domain name from host name--host name is now $hostname)"
  1210. X    ;;
  1211. X*) case "$mydomain" in
  1212. X    '') dflt=.`$awk "/[0-9].*$hostname/ {for(i=2; i<=NF;i++) print \\\$i}" /etc/hosts|
  1213. X        $sort|$uniq|$sed -n -e "s/$hostname\.\([a-zA-Z_.]\)/\1/p"`
  1214. X        case "$dflt" in
  1215. X        .) echo "(You do not have fully-qualified names in /etc/hosts)"
  1216. X            dflt='.uucp';;
  1217. X        esac;;
  1218. X    *) dflt="$mydomain";;
  1219. X    esac;;
  1220. Xesac
  1221. Xecho " "
  1222. Xrp="What is your domain name?"
  1223. X. myread
  1224. Xcase "$ans" in
  1225. X'') ;;
  1226. X.*) ;;
  1227. X*) ans=".$ans";;
  1228. Xesac
  1229. Xmydomain="$ans"
  1230. X
  1231. X: a little sanity check here
  1232. Xcase "$phostname" in
  1233. X'') ;;
  1234. X*)
  1235. X    case `$phostname` in
  1236. X    $hostname$mydomain|$hostname) ;;
  1237. X    *)
  1238. X        case "$phostname" in
  1239. X        sed*)
  1240. X            echo "(That doesn't agree with your whoami.h file, by the way.)"
  1241. X            ;;
  1242. X        *)
  1243. X            echo "(That doesn't agree with your $phostname command, by the way.)"
  1244. X            ;;
  1245. X        esac
  1246. X    phostname=''
  1247. X    ;;
  1248. X    esac
  1249. X    ;;
  1250. Xesac
  1251. X
  1252. X: decide how portable to be
  1253. Xcase "$d_portable" in
  1254. X"$define") dflt=y;;
  1255. X*)    dflt=n;;
  1256. Xesac
  1257. X$cat <<'EOH'
  1258. XI can set things up so that your shell scripts and binaries are more portable,
  1259. Xat what may be a noticable cost in performance.  In particular, if you
  1260. Xask to be portable, the following happens:
  1261. X
  1262. X     1) Shell scripts will rely on the PATH variable rather than using
  1263. X    the paths derived above.
  1264. X     2) ~username interpretations will be done at run time rather than
  1265. X    by Configure.
  1266. X     3) The system name will be determined at run time, if at all possible.
  1267. X
  1268. XEOH
  1269. Xrp="Do you expect to run these scripts and binaries on multiple machines?"
  1270. X. myread
  1271. Xcase "$ans" in
  1272. X    y*) d_portable="$define"
  1273. X    for file in $loclist; do
  1274. X        eval $file=$file
  1275. X    done
  1276. X    ;;
  1277. X    *)  d_portable="$undef" ;;
  1278. Xesac
  1279. X
  1280. X: Set private lib path
  1281. Xcase "$plibpth" in
  1282. X'') if mips; then
  1283. X        plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib"
  1284. X    else
  1285. X        plibpth="/usr/ccs/lib /usr/lib /usr/ucblib /usr/local/lib"
  1286. X    fi;;
  1287. Xesac
  1288. Xlibpth="$plibpth $libpth"
  1289. X
  1290. X: Looking for optional libraries
  1291. Xecho " "
  1292. Xecho "Checking for optional libraries..."
  1293. Xcase "$libs" in
  1294. X'') dflt='';;
  1295. X*) dflt="$libs";;
  1296. Xesac
  1297. Xcase "$libswanted" in
  1298. X'') libswanted='c_s';;
  1299. Xesac
  1300. Xfor thislib in $libswanted; do
  1301. X    case "$thislib" in
  1302. X    dbm) thatlib=ndbm;;
  1303. X    *_s) thatlib=NONE;;
  1304. X    *) thatlib="${thislib}_s";;
  1305. X    *) thatlib=NONE;;
  1306. X    esac
  1307. X    yyy="$incpath/usr/ccs/lib $incpath/usr/lib $incpath/usr/ucblib"
  1308. X    yyy="$yyy $incpath/usr/local/lib $incpath/lib"
  1309. X    xxx=`loc lib$thislib.a X $yyy`
  1310. X    if $test -f $xxx; then
  1311. X        echo "Found -l$thislib."
  1312. X        case "$dflt" in
  1313. X        *-l$thislib*|*-l$thatlib*);;
  1314. X        *) dflt="$dflt -l$thislib";;
  1315. X        esac
  1316. X    else
  1317. X        xxx=`loc lib$thislib.a X $libpth`
  1318. X        if $test -f $xxx; then
  1319. X            echo "Found $xxx."
  1320. X            case "$dflt" in
  1321. X            *$xxx*);;
  1322. X            *) dflt="$dflt $xxx";;
  1323. X            esac
  1324. X        else
  1325. X            xxx=`loc Slib$thislib.a X $xlibpth`
  1326. X            if $test -f $xxx; then
  1327. X                echo "Found -l$thislib."
  1328. X                case "$dflt" in
  1329. X                *-l$thislib*|*-l$thatlib*);;
  1330. X                *) dflt="$dflt -l$thislib";;
  1331. X                esac
  1332. X            else
  1333. X                echo "No -l$thislib."
  1334. X            fi
  1335. X        fi
  1336. X    fi
  1337. Xdone
  1338. Xset X $dflt
  1339. Xshift
  1340. Xdflt="$*"
  1341. Xcase "$libs" in
  1342. X'') dflt="$dflt";;
  1343. X*) dflt="$libs";;
  1344. Xesac
  1345. Xcase "$dflt" in
  1346. X'') dflt='none';;
  1347. Xesac
  1348. X
  1349. X$cat <<EOM
  1350. XSome versions of Unix support shared libraries, which make executables smaller
  1351. Xbut make load time slightly longer.
  1352. X
  1353. XOn some systems, mostly newer Unix System V's, the shared library is included
  1354. Xby putting the option "-lc_s" as the last thing on the cc command line when
  1355. Xlinking.  Other systems use shared libraries by default.  There may be other
  1356. Xlibraries needed to compile $package on your machine as well.  If your system
  1357. Xneeds the "-lc_s" option, include it here.  Include any other special libraries
  1358. Xhere as well.  Say "none" for none.
  1359. XEOM
  1360. X
  1361. Xecho " "
  1362. Xrp="Any additional libraries?"
  1363. X. myread
  1364. Xcase "$ans" in
  1365. Xnone) ans='';
  1366. Xesac
  1367. Xlibs="$ans"
  1368. X
  1369. X: get list of predefined functions in a handy place
  1370. Xecho " "
  1371. Xcase "$libc" in
  1372. X'') libc=unknown;;
  1373. Xesac
  1374. Xcase "$nm_opt" in
  1375. X'') if $test -f /mach_boot; then
  1376. X        nm_opt=''
  1377. X    elif $test -d /usr/ccs/lib; then
  1378. X        nm_opt='-p'
  1379. X    elif $test -f /dgux; then
  1380. X        nm_opt='-p'
  1381. X    else
  1382. X        nm_opt=''
  1383. X    fi;;
  1384. Xesac
  1385. Xlibpth="$plibpth $libpth"
  1386. Xcase "$libs" in
  1387. X*-lc_s*) libc=`loc libc_s.a $libc $libpth`
  1388. Xesac
  1389. Xlibnames='';
  1390. Xcase "$libs" in
  1391. X'') ;;
  1392. X*)  for thislib in $libs; do
  1393. X    case "$thislib" in
  1394. X    -l*) thislib=`expr X$thislib : 'X-l\(.*\)'`
  1395. X        try=`loc lib$thislib.a blurfl/dyick $libpth`
  1396. X        if test ! -f $try; then
  1397. X        try=`loc lib$thislib blurfl/dyick $libpth`
  1398. X        if test ! -f $try; then
  1399. X            try=`loc $thislib blurfl/dyick $libpth`
  1400. X            if test ! -f $try; then
  1401. X            try=`loc Slib$thislib.a blurfl/dyick $xlibpth`
  1402. X            if test ! -f $try; then
  1403. X                try=''
  1404. X            fi
  1405. X            fi
  1406. X        fi
  1407. X        fi
  1408. X        libnames="$libnames $try"
  1409. X        ;;
  1410. X    *) libnames="$libnames $thislib" ;;
  1411. X    esac
  1412. X    done
  1413. X    ;;
  1414. Xesac
  1415. Xset /usr/ccs/lib/libc.so
  1416. X$test -f $1 || set /usr/lib/libc.so
  1417. X$test -f $1 || set /usr/lib/libc.so.[0-9]*
  1418. X$test -f $1 || set /lib/libsys_s.a
  1419. Xeval set \$$#
  1420. Xif test -f "$1"; then
  1421. X    echo "Your (shared) C library seems to be in $1."
  1422. X    libc="$1"
  1423. Xelif test -f /lib/libc && test -f /lib/clib; then
  1424. X    echo "Your C library seems to be in both /lib/clib and /lib/libc."
  1425. X    libc='/lib/clib /lib/libc'
  1426. X    if test -f /lib/syslib; then
  1427. X        echo "(Your math library is in /lib/syslib.)"
  1428. X        libc="$libc /lib/syslib"
  1429. X    fi
  1430. Xelif test -f "$libc"; then
  1431. X    echo "Your C library seems to be in $libc, as you said before."
  1432. Xelif test -f $incpath/usr/lib/libc.a; then
  1433. X    libc=$incpath/usr/lib/libc.a;
  1434. X    echo "Your C library seems to be in $libc.  That's fine."
  1435. Xelif test -f /lib/libc.a; then
  1436. X    libc=/lib/libc.a;
  1437. X    echo "Your C library seems to be in $libc.  You're normal."
  1438. Xelse
  1439. X    if ans=`./loc libc.a blurfl/dyick $libpth`; test -f "$ans"; then
  1440. X        :
  1441. X    elif ans=`./loc libc blurfl/dyick $libpth`; test -f "$ans"; then
  1442. X        libnames="$libnames "`./loc clib blurfl/dyick $libpth`
  1443. X    elif ans=`./loc clib blurfl/dyick $libpth`; test -f "$ans"; then
  1444. X        :
  1445. X    elif ans=`./loc Slibc.a blurfl/dyick $xlibpth`; test -f "$ans"; then
  1446. X        :
  1447. X    elif ans=`./loc Mlibc.a blurfl/dyick $xlibpth`; test -f "$ans"; then
  1448. X        :
  1449. X    else
  1450. X        ans=`./loc Llibc.a blurfl/dyick $xlibpth`
  1451. X    fi
  1452. X    if test -f "$ans"; then
  1453. X        echo "Your C library seems to be in $ans, of all places."
  1454. X        libc=$ans
  1455. X    else
  1456. X        libc='blurfl'
  1457. X    fi
  1458. Xfi
  1459. Xif $test -f "$libc"; then
  1460. X    dflt="$libc"
  1461. X    cat <<EOM
  1462. X
  1463. XIf the guess above is wrong (which it might be if you're using a strange
  1464. Xcompiler, or your machine supports multiple models), you can override it here.
  1465. X
  1466. XEOM
  1467. Xelse
  1468. X    dflt=''
  1469. X    echo $libpth | tr ' ' '\012' | sort | uniq > libpath
  1470. X    cat <<EOM
  1471. XI can't seem to find your C library.  I've looked in the following places:
  1472. X
  1473. XEOM
  1474. X    $sed 's/^/    /' libpath
  1475. X    cat <<EOM
  1476. X
  1477. XNone of these seems to contain your C library. I need to get its name...
  1478. X
  1479. XEOM
  1480. Xfi
  1481. Xcont=true
  1482. Xwhile $test "$cont"; do
  1483. X    rp="Where is your C library?"
  1484. X    . myread
  1485. X    libc="$ans"
  1486. X    if $test -f "$libc"; then
  1487. X        cont=''
  1488. X    else
  1489. X        case "$fastread" in
  1490. X        yes) dflt=y;;
  1491. X        *) dflt=n;;
  1492. X        esac
  1493. X        rp="File $libc does not exist. Use that name anyway?"
  1494. X        . myread
  1495. X        case "$ans" in
  1496. X        y*) cont='';;
  1497. X        esac
  1498. X        dflt=''
  1499. X    fi
  1500. Xdone
  1501. Xecho " "
  1502. Xecho $libc $libnames | tr ' ' '\012' | sort | uniq > libnames
  1503. Xset X `cat libnames`
  1504. Xshift
  1505. Xxxx=files
  1506. Xcase $# in 1) xxx=file; esac
  1507. Xecho "Extracting names from the following $xxx for later perusal:"
  1508. Xecho " "
  1509. X$sed 's/^/    /' libnames
  1510. Xecho " "
  1511. X$echo $n "This may take a while...$c"
  1512. Xnm $nm_opt $* 2>/dev/null >libc.tmp
  1513. X$echo $n ".$c"
  1514. X$grep fprintf libc.tmp > libc.ptf
  1515. Xxscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c"'
  1516. Xxrun='eval "<libc.tmp $com >libc.list"; echo "done"'
  1517. Xif com="$sed -n -e 's/^.* [ADTS]  *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
  1518. X    eval $xscan;\
  1519. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1520. X        eval $xrun
  1521. Xelif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
  1522. X    eval $xscan;\
  1523. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1524. X        eval $xrun
  1525. Xelif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
  1526. X    eval $xscan;\
  1527. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1528. X        eval $xrun
  1529. Xelif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
  1530. X    eval $xscan;\
  1531. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1532. X        eval $xrun
  1533. Xelif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
  1534. X    eval $xscan;\
  1535. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1536. X        eval $xrun
  1537. Xelif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
  1538. X    eval $xscan;\
  1539. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1540. X        eval $xrun
  1541. Xelif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
  1542. X                -e '/ file/d' -e 's/^\([^     ]*\).*/\1/p'";\
  1543. X    eval $xscan;\
  1544. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1545. X        eval $xrun
  1546. Xelif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
  1547. X    eval $xscan;\
  1548. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1549. X        eval $xrun
  1550. Xelif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
  1551. X    eval $xscan;\
  1552. X    $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1553. X        eval $xrun
  1554. Xelse
  1555. X    nm -p $* 2>/dev/null >libc.tmp
  1556. X    com="$sed -n -e 's/^.* [ADTS]  *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
  1557. X    eval "<libc.tmp $com >libc.list"
  1558. X    if $contains '^fprintf$' libc.list >/dev/null 2>&1; then
  1559. X        nm_opt='-p'
  1560. X        echo "done"
  1561. X    else
  1562. X        echo " "
  1563. X        echo "nm didn't seem to work right. Trying ar instead..."
  1564. X        com=''
  1565. X        if ar t $libc > libc.tmp; then
  1566. X            for thisname in $libnames; do
  1567. X                ar t $thisname >>libc.tmp
  1568. X            done
  1569. X            $sed -e 's/\.o$//' < libc.tmp > libc.list
  1570. X            echo "Ok."
  1571. X        else
  1572. X            echo "ar didn't seem to work right."
  1573. X            echo "Maybe this is a Cray...trying bld instead..."
  1574. X            if bld t $libc | $sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
  1575. X                for thisname in $libnames; do
  1576. X                    bld t $libnames | \
  1577. X                    $sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
  1578. X                    ar t $thisname >>libc.tmp
  1579. X                done
  1580. X                echo "Ok."
  1581. X            else
  1582. X                echo "That didn't work either.  Giving up."
  1583. X                exit 1
  1584. X            fi
  1585. X        fi
  1586. X    fi
  1587. Xfi
  1588. Xnm_extract="$com"
  1589. Xif test -f /lib/syscalls.exp; then
  1590. X    echo " "
  1591. X    echo "Also extracting names from /lib/syscalls.exp for good ole AIX..."
  1592. X    $sed -n 's/^\([^     ]*\)[     ]*syscall$/\1/p' /lib/syscalls.exp >>libc.list
  1593. Xfi
  1594. X$rm -f libnames libpath
  1595. X
  1596. X: see how we will look up host name
  1597. Xecho " "
  1598. Xd_uname="$undef"
  1599. Xd_gethname="$undef"
  1600. Xd_phostname="$undef"
  1601. Xif xenix; then
  1602. X    echo "(Assuming Xenix uname() is broken.)"
  1603. Xelif $contains '^gethostname$' libc.list >/dev/null 2>&1 ; then
  1604. X    echo "gethostname() found."
  1605. X    d_gethname="$define"
  1606. X    ans=gethostname
  1607. Xelif $contains '^uname$' libc.list >/dev/null 2>&1 ; then
  1608. X    echo "uname() found."
  1609. X    d_uname="$define"
  1610. X    ans=uname
  1611. Xfi
  1612. Xcase "$d_uname$d_gethname" in
  1613. X*define*)
  1614. X    dflt=n
  1615. X    cat <<EOM
  1616. XEvery now and then someone has a $ans() that lies about the hostname
  1617. Xbut can't be fixed for political or economic reasons.  If you wish, I can
  1618. Xpretend $ans() isn't there and maybe compile in the hostname or
  1619. Xcompute it from the '$phostname' command at run-time.
  1620. X
  1621. XEOM
  1622. END_OF_FILE
  1623.  if test 36159 -ne `wc -c <'Configure.a'`; then
  1624.     echo shar: \"'Configure.a'\" unpacked with wrong size!
  1625.  elif test -f 'Configure.b'; then
  1626.     echo shar: Combining  \"'Configure'\" \(70471 characters\)
  1627.     cat 'Configure.a' 'Configure.b' > 'Configure'
  1628.     if test 70471 -ne `wc -c <'Configure'`; then
  1629.       echo shar: \"'Configure'\" combined with wrong size!
  1630.     else
  1631.       chmod u+x Configure
  1632.       rm Configure.a Configure.b
  1633.     fi
  1634.   fi
  1635.   # end of 'Configure.a'
  1636. fi
  1637. if test -f 'agent/pl/matching.pl' -a "${1}" != "-c" ; then 
  1638.   echo shar: Will not clobber existing file \"'agent/pl/matching.pl'\"
  1639. else
  1640.   echo shar: Extracting \"'agent/pl/matching.pl'\" \(13814 characters\)
  1641.   sed "s/^X//" >'agent/pl/matching.pl' <<'END_OF_FILE'
  1642. X;# $Id: matching.pl,v 2.9.1.1 92/08/02 16:11:54 ram Exp $
  1643. X;#
  1644. X;#  Copyright (c) 1992, Raphael Manfredi
  1645. X;#
  1646. X;#  You may redistribute only under the terms of the GNU General Public
  1647. X;#  Licence as specified in the README file that comes with dist.
  1648. X;#
  1649. X;# $Log:    matching.pl,v $
  1650. X;# Revision 2.9.1.1  92/08/02  16:11:54  ram
  1651. X;# patch2: added support for negated selectors
  1652. X;# 
  1653. X;# Revision 2.9  92/07/14  16:50:20  ram
  1654. X;# 3.0 beta baseline.
  1655. X;# 
  1656. X;# 
  1657. X#
  1658. X# Matching functions
  1659. X#
  1660. X
  1661. X# List of special header selector, for which a pattern without / is to be
  1662. X# taken as an equality with the login name of the address. If there are some
  1663. X# metacharacters, then a match will be attempted on that name. For each of
  1664. X# those special headers, we record the name of the subroutine to be called.
  1665. X# If a matching function is not specified, the default is 'match_var'.
  1666. X# The %Amatcher gives the name of the fields which contains an address.
  1667. Xsub init_matcher {
  1668. X    %Matcher = (
  1669. X        'From', 'match_single',
  1670. X        'To', 'match_list',
  1671. X        'Cc', 'match_list',
  1672. X        'Apparently-To', 'match_list',
  1673. X        'Newsgroups', 'match_list'
  1674. X    );
  1675. X    %Amatcher = (
  1676. X        'From', 1,
  1677. X        'To', 1,
  1678. X        'Cc', 1,
  1679. X        'Apparently-To', 1
  1680. X    );
  1681. X}
  1682. X
  1683. X# Take a pattern as written in the rule file and make it suitable for
  1684. X# pattern matching as understood by perl. If the pattern starts with a
  1685. X# leading /, nothing is done. Otherwise, a set of / are added.
  1686. X# match (1st case).
  1687. Xsub make_pattern {
  1688. X    local($_) = shift(@_);
  1689. X    unless (m|^/|) {                # Pattern does not start with a /
  1690. X        # With simple words, patterns have the same form as shell ones
  1691. X        s/\./\\./g;            # Escape .
  1692. X        s/\*/.*/g;            # Transform * into .*
  1693. X        s/\?/./g;            # Transform ? into .
  1694. X        $_ = "/^$_\$/";        # Anchor pattern
  1695. X    }
  1696. X    # The whole pattern is inserted within () to make at least one
  1697. X    # backreference. Otherwise, the following could happen:
  1698. X    #    $_ = '1 for you';
  1699. X    #    @matched = /^\d/;
  1700. X    #    @matched = /^(\d)/;
  1701. X    # In both cases, the @matched array is set to ('1'), with no way to
  1702. X    # determine whether it is due to a backreference (2nd case) or a sucessful
  1703. X    # match. Knowing we have at least one bracketed reference is enough to
  1704. X    # disambiguate.
  1705. X    s|^/(.*)/|/($1)/|;        # Enclose whole pattern within ()
  1706. X    $_;                        # Pattern suitable for eval'ed matching
  1707. X}
  1708. X
  1709. X# Attempt a match of a set of pattern, for each possible selector
  1710. Xsub match {
  1711. X    local($selector) = shift(@_);    # The selector on which pattern applies
  1712. X    local($pattern) = shift(@_);    # The pattern or script to apply
  1713. X    local($matched) = 0;            # Matching status returned
  1714. X    # If the pattern is held within double quotes, it is assumed to be the name
  1715. X    # of a file from which patterns may be found (one per line, shell comments
  1716. X    # being ignored).
  1717. X    if ($pattern !~ /^"/) {
  1718. X        $matched = do apply_match($selector, $pattern);
  1719. X    } else {
  1720. X        local(@filepat) = ();            # File pattern
  1721. X        local($filename);                # Where pattern should be read from
  1722. X        ($filename) =
  1723. X            $pattern =~ /^"(.*)"$/;        # The filename is held within ""
  1724. X        $filename =
  1725. X            &locate_file($filename);    # Path may not be absolute
  1726. X        if ($filename) {
  1727. X            if (open(PATTERN, "$filename")) {
  1728. X                while (<PATTERN>) {
  1729. X                    next if /^\s*#/;    # Skip shell comments
  1730. X                    chop;
  1731. X                    s/^\s*//;            # Remove leading spaces
  1732. X                    push(@filepat, $_);
  1733. X                    do add_log ("loading pattern $_") if $loglvl > 19;
  1734. X                }
  1735. X                close PATTERN;
  1736. X            } else {
  1737. X                do add_log("WARNING couldn't open $filename for patterns")
  1738. X                    if $loglvl > 4;
  1739. X                push(@filepat, "*");    # Ensure anything matches
  1740. X            }
  1741. X        } else {
  1742. X            do add_log("WARNING incorrect file name $pattern") if $loglvl > 4;
  1743. X            push(@filepat, "*");    # Ensure anything matches
  1744. X        }
  1745. X        # Now do the match for all the patterns. Stop as soon as one matches.
  1746. X        foreach (@filepat) {
  1747. X            $matched = do apply_match($selector, $_);
  1748. X            last if $matched;
  1749. X        }
  1750. X    }
  1751. X    $matched ? 1 : 0;        # Return matching status (guaranteed numeric)
  1752. X}
  1753. X
  1754. X# Attempt a pattern match on a set of selectors, and set the special macro %&
  1755. X# to the name of the regexp-specified fields which matched.
  1756. Xsub apply_match {
  1757. X    local($selector) = shift(@_);    # The selector on which pattern applies
  1758. X    local($pattern) = shift(@_);    # The pattern or script to apply
  1759. X    local($matched) = 0;            # True when a matching occurred
  1760. X    local($inverted) = 0;            # True whenever all '!' match succeeded
  1761. X    local($invert) = 1;                # Set to false whenever a '!' match fails
  1762. X    local($match);                    # Matching status reported
  1763. X    local($not) = '';                # Shall we negate matching status?
  1764. X    if ($selector eq 'script') {    # Pseudo header selector
  1765. X        $matched = do evaluate(*pattern);
  1766. X    } else {                        # True header selector
  1767. X
  1768. X        # There can be multiple slectors separated by a white space. As soon as
  1769. X        # one of them matches, we stop and return true. A selector may contain
  1770. X        # metacharacters, in which case a regular pattern matching is attempted
  1771. X        # on the true *header* fields (i.e. we skip the pseudo keys like Body,
  1772. X        # Head, etc..). For instance, Return* would attempt a match on the
  1773. X        # field Return-Receipt-To:, if present. The special macro %& is set
  1774. X        # to the list of all the fields on which the match succeeded
  1775. X        # (alphabetically sorted).
  1776. X
  1777. X        foreach $select (split(/ /, $selector)) {
  1778. X            $not = '';
  1779. X            $select =~ s/^!// && ($not = '!');
  1780. X            # Allowed metacharacters are listed here (no braces wanted)
  1781. X            if ($select =~ /\.|\*|\[|\]|\||\\|\^|\?|\+|\(|\)/) {
  1782. X                $match = &expr_selector_match($select, $pattern);
  1783. X            } else {
  1784. X                $match = &selector_match($select, $pattern);
  1785. X            }
  1786. X            if ($not) {                                # Negated test
  1787. X                $invert = !$match if $invert;
  1788. X                $inverted = $invert if !$match;        # '!' tests AND'ed
  1789. X            } else {
  1790. X                $matched = $match;                    # Normal tests OR'ed
  1791. X            }
  1792. X            last if $matched;        # Stop when matching status known
  1793. X        }
  1794. X    }
  1795. X    $matched || $inverted;            # Return matching status
  1796. X}
  1797. X
  1798. X# Attempt a pattern match on a set of selectors, and set the special macro %&
  1799. X# to the name of the field which matched. If there is more than one such
  1800. X# selector, values are separated using comas. If selector is preceded by a '!',
  1801. X# then the matching status is negated and *all* the tested fields are recorded
  1802. X# within %& when the returned status is 'true'.
  1803. Xsub expr_selector_match {
  1804. X    local($selector) = shift(@_);    # The selector on which pattern applies
  1805. X    local($pattern) = shift(@_);    # The pattern or script to apply
  1806. X    local($matched) = 0;            # True when a matching occurred
  1807. X    local(@keys) = sort keys %Header;
  1808. X    local($match);                    # Local matching status
  1809. X    local($not) = '';                # Shall boolean value be negated?
  1810. X    local($orig_ampersand) = $macro_ampersand;    # Save %&
  1811. X    $selector =~ s/^!// && ($not = '!');
  1812. X    &add_log("field '$selector' has metacharacters") if $loglvl > 18;
  1813. X    field: foreach $key (@keys) {
  1814. X        next if $Pseudokey{$key};        # Skip Body, All...
  1815. X        &add_log("'$select' tried on '$key'") if $loglvl > 19;
  1816. X        next unless eval '$key =~ /' . $select . '/';
  1817. X        $match = &selector_match($key, $pattern);
  1818. X        $matched = 1 if $match;            # Only one match needed
  1819. X        # Record matching field for futher reference if a match occurred and
  1820. X        # the selector does not start with a '!'. Record all the tested fields
  1821. X        # if's starting with a '!' (because that's what is interesting in that
  1822. X        # case). In that last case, the original macro will be restored if any
  1823. X        # match occurs.
  1824. X        if ($not || $match) {
  1825. X            $macro_ampersand .= ',' if $macro_ampersand;
  1826. X            $macro_ampersand =~ s/;,$/;/;
  1827. X            $macro_ampersand .= $key;
  1828. X        }
  1829. X        if ($match) {
  1830. X            &add_log("obtained match with '$key' field")
  1831. X                if $loglvl > 18;
  1832. X            next field;                # Try all the matching selectors
  1833. X        }
  1834. X        &add_log("no match with '$key' field") if $loglvl > 18;
  1835. X    }
  1836. X    $macro_ampersand .= ';';        # Set terminated with a ';'
  1837. X    # No need to negate status if selector was preceded by a '!': this will
  1838. X    # be done by apply match.
  1839. X    $macro_ampersand = $orig_ampersand if $not && $matched;    # Restore %&
  1840. X    &add_log("matching status for '$selector' is '$matched'")
  1841. X        if $loglvl > 18;
  1842. X    $matched;                        # Return matching status
  1843. X}
  1844. X
  1845. X# Attempt a match of a pattern against a selector, return boolean status.
  1846. X# If pattern is preceded by a '!', the boolean status is negated.
  1847. Xsub selector_match {
  1848. X    local($selector) = shift(@_);    # The selector on which pattern applies
  1849. X    local($pattern) = shift(@_);    # The pattern to apply
  1850. X    local($matcher);                # Subroutine used to do the match
  1851. X    local($matched);                # Record matching status
  1852. X    local($not) = '';                # Shall we apply NOT on matching result?
  1853. X    $selector = &header'normalize($selector);    # Normalize case
  1854. X    $matcher = $Matcher{$selector};
  1855. X    $matcher = 'match_var' unless $matcher;
  1856. X    $pattern =~ s/^!// && ($not = '!');
  1857. X    $matched = &$matcher($selector, $pattern);
  1858. X    $matched = !$matched if $not;    # Revert matching status if ! pattern
  1859. X    if ($loglvl > 19) {
  1860. X        local($logmsg) = "matching '$not$pattern' on '$selector' was ";
  1861. X        $logmsg .= $matched ? "true" : "false";
  1862. X        do add_log($logmsg);
  1863. X    }
  1864. X    $matched;                # Return matching status
  1865. X}
  1866. X
  1867. X# Pattern matching functions:
  1868. X#    They are invoked as function($selector, $pattern) and return true if
  1869. X#    the pattern is found in the variable, according to some internal rules
  1870. X#    which are different among the functions. For instance, match_single will
  1871. X#    attempt a match with a login name or a regular pattern matching on the
  1872. X#    whole variable if the pattern was not a single word.
  1873. X
  1874. X# Matching is done in a header which only contains an internet address
  1875. X# If the selector starts with a >, then it is not a selector but a buffer on
  1876. X# which pattern matching is to be done.
  1877. Xsub match_single {
  1878. X    local($selector) = shift(@_);    # The variable which must be tested
  1879. X    local($pattern) = shift(@_);    # The pattern which must be used
  1880. X    local($buffer);                    # Buffer on which pattern matching is done
  1881. X    local($login) = 0;                # Set to true when attempting login match
  1882. X    local(@matched);
  1883. X    if ($selector =~ s/^>([\w\-]+)<//) {    # Already a buffer for matching
  1884. X        $buffer = $selector;                # Remaining is the buffer
  1885. X        $selector = $1;                        # Between > and < was selector
  1886. X    } else {
  1887. X        $buffer = $Header{$selector};
  1888. X    }
  1889. X    # If we attempt a match on a field holding e-mail addresses and the pattern
  1890. X    # is anchored at the beginning with a /^, then we only keep the address
  1891. X    # part and remove the comment if any. Otherwise, the field is left alone.
  1892. X    # Of course, if the pattern is only a single name, we extract the login
  1893. X    # name for matching purposes...
  1894. X    if ($Amatcher{$selector}) {                    # Field holds an e-mail address
  1895. X        $buffer = (&parse_address($buffer))[0] if $pattern =~ m|^/\^|;
  1896. X        if ($pattern =~ m|^[-\w.*?]+\s*$|) {    # Single name may have - or .
  1897. X            $buffer = (&parse_address($buffer))[0];
  1898. X            $buffer = do login_name($buffer);    # Match done only on login name
  1899. X            $pattern =~ tr/A-Z/a-z/;    # Cannonicalize name to lower case
  1900. X        }
  1901. X        $login = 1 unless $pattern =~ m|^/|;    # Ask for case-insensitive match
  1902. X    }
  1903. X    $buffer =~ s/^\s+//;                # Remove leading spaces
  1904. X    $buffer =~ s/\s+$//;                # And trailing ones
  1905. X    $pattern = do make_pattern($pattern);
  1906. X    $pattern .= "i" if $login;            # Login matches are case-insensitive
  1907. X    @matched = eval '($buffer =~ ' . $pattern . ');';
  1908. X    # If buffer is empty, we have to recheck the pattern in a non array context
  1909. X    # to see if there is a match. Otherwise, /(.*)/ does not seem to match an
  1910. X    # empty string as it returns an empty string in $matched[0]...
  1911. X    $matched[0] = eval '$buffer =~ ' . $pattern if $buffer eq '';
  1912. X    &eval_error;                        # Make sure eval worked
  1913. X    &update_backref(*matched);            # Record non-null backreferences
  1914. X    $matched[0];                        # Return matching status
  1915. X}
  1916. X
  1917. X# Matching is done on a header field which may contains multiple addresses
  1918. X# This will not work if there is a ',' in the comment part of the addresses,
  1919. X# but I never saw that and I don't want to write complex code for that--RAM.
  1920. Xsub match_list {
  1921. X    local($selector) = shift(@_);    # The variable which must be tested
  1922. X    local($pattern) = shift(@_);    # The pattern which must be used
  1923. X    local($buffer);                    # Buffer on which pattern matching is done
  1924. X    local($_) = $Header{$selector};    # Work on a copy of the line
  1925. X    $_ = join(' ', split(/\n/, $_));
  1926. X    local($matched) = 0;            # Set to true when matching has occurred
  1927. X    local(@list) = split(/,/);        # List of addresses
  1928. X    foreach $buffer (@list) {
  1929. X        $matched = do match_single(">$selector<$buffer", $pattern);
  1930. X        last if $matched;
  1931. X    }
  1932. X    $matched;
  1933. X}
  1934. X
  1935. X# Look for a pattern in a multi-line context
  1936. Xsub match_var {
  1937. X    local($selector) = shift(@_);        # The variable which must be tested
  1938. X    local($pattern) = shift(@_);        # The pattern we're looking for
  1939. X    local(@matched);
  1940. X    $pattern = do make_pattern($pattern);
  1941. X    $* = 1;                                # Multi-line matching is attempted
  1942. X    local(@dol);                        # To store backward references
  1943. X    @matched = eval '($Header{\'' . $selector . '\'} =~ ' . $pattern . ');';
  1944. X    # If buffer is empty, we have to recheck the pattern in a non array context
  1945. X    # to see if there is a match. Otherwise, /(.*)/ does not seem to match an
  1946. X    # empty string as it returns an empty string in $matched[0]...
  1947. X    $matched[0] = eval '$Header{\'' . $selector . '\'} =~ ' . $pattern
  1948. X        if $Header{$selector} eq '';
  1949. X    &eval_error;                        # Make sure eval worked
  1950. X    &update_backref(*matched);            # Record non-null backreferences
  1951. X    $* = 0;
  1952. X    $matched[0];                        # Return matching status
  1953. X}
  1954. X
  1955. X# Reseet the backreferences at the beginning of each rule match attempt
  1956. X# The backreferences include %& and %1 .. %99.
  1957. Xsub reset_backref {
  1958. X    $macro_ampersand = '';            # List of matched generic selector
  1959. X    @Backref = ();                    # Stores backreferences provided by perl
  1960. X}
  1961. X
  1962. X# Update the backward reference array. There is a maximum of 99 backreferences
  1963. X# per filter rule. The argument list is an array of all the backreferences
  1964. X# found in the pattern matching, but the first item has to be skipped: it is
  1965. X# the whole matching string -- see comment on make_pattern().
  1966. Xsub update_backref {
  1967. X    local(*array) = @_;                # Array holding $1 .. $9, $10 ..
  1968. X    local($i, $val);
  1969. X    for ($i = 1; $i < @array; $i++) {
  1970. X        $val = $array[$i];
  1971. X        push(@Backref, $val);        # Stack backreference for later perusal
  1972. X        &add_log("stacked '$val' as backreference") if $loglvl > 18;
  1973. X    }
  1974. X}
  1975. X
  1976. END_OF_FILE
  1977.   if test 13814 -ne `wc -c <'agent/pl/matching.pl'`; then
  1978.     echo shar: \"'agent/pl/matching.pl'\" unpacked with wrong size!
  1979.   fi
  1980.   # end of 'agent/pl/matching.pl'
  1981. fi
  1982. if test -f 'agent/test/basic/filter.t' -a "${1}" != "-c" ; then 
  1983.   echo shar: Will not clobber existing file \"'agent/test/basic/filter.t'\"
  1984. else
  1985.   echo shar: Extracting \"'agent/test/basic/filter.t'\" \(1706 characters\)
  1986.   sed "s/^X//" >'agent/test/basic/filter.t' <<'END_OF_FILE'
  1987. X# Make sure filter queues messages correctly
  1988. Xdo '../pl/init.pl';
  1989. Xdo '../pl/logfile.pl';
  1990. Xchdir '../out' || exit 0;
  1991. Xopen(WAIT, ">queue/agent.wait") || print "1\n";
  1992. Xclose WAIT;
  1993. X`chmod u-w queue`;
  1994. X$? == 0 || print "2\n";
  1995. X# Use the special undocumented -t option from filter to get HOME directory
  1996. X# via environment instead of /etc/passwd.
  1997. Xopen(FILTER, "|$filter -t >/dev/null 2>&1") || print "3\n";
  1998. Xprint FILTER <<EOF;
  1999. XDummy mail
  2000. XEOF
  2001. Xclose FILTER;
  2002. X$? == 0 || print "4\n";        # Must terminate correctly (stored in agent.wait)
  2003. X&get_log(5);
  2004. X&check_log('memorized', 6);    # Make sure mail has been memorized
  2005. X-s 'queue/agent.wait' || print "7\n";
  2006. X$file = <emerg/*>;
  2007. Xif (-f "$file") {
  2008. X    chop($what = `cat queue/agent.wait`);
  2009. X    chop($pwd = `pwd`);
  2010. X    $what eq "$pwd/$file" || print "8\n";
  2011. X    unlink "$file";
  2012. X} else {
  2013. X    print "8\n";
  2014. X}
  2015. X`chmod u+w queue`;
  2016. Xunlink 'queue/agent.wait', 'agentlog';
  2017. Xopen(FILTER, "|$filter -t >/dev/null 2>&1") || print "9\n";
  2018. Xprint FILTER <<EOF;
  2019. XDummy mail
  2020. XEOF
  2021. Xclose FILTER;
  2022. X$? == 0 || print "10\n";    # Must terminate correctly (queued)
  2023. X&get_log(11);
  2024. X&check_log('QUEUED', 12);    # Mail was queued
  2025. X$file = <queue/qm*>;
  2026. X-f "$file" || print "13\n";    # Must have been left in queue
  2027. Xunlink "$file", 'agentlog';
  2028. X# Make sure file is correctly queued when another filter is running
  2029. X`cp /dev/null filter.lock`;
  2030. X$? == 0 || print "14\n";
  2031. Xopen(FILTER, "|$filter -t >/dev/null 2>&1") || print "15\n";
  2032. Xprint FILTER <<EOF;
  2033. XDummy mail
  2034. XEOF
  2035. Xclose FILTER;
  2036. X$? == 0 || print "16\n";    # Must terminate correctly (queued)
  2037. X&get_log(17);
  2038. X&check_log('QUEUED', 18);    # Mail was queued
  2039. X$file = <queue/fm*>;
  2040. X-f "$file" || print "19\n";    # Must have been left in queue as a 'fm' file
  2041. Xunlink "$file", 'agentlog', 'filter.lock';
  2042. Xprint "0\n";
  2043. END_OF_FILE
  2044.   if test 1706 -ne `wc -c <'agent/test/basic/filter.t'`; then
  2045.     echo shar: \"'agent/test/basic/filter.t'\" unpacked with wrong size!
  2046.   fi
  2047.   # end of 'agent/test/basic/filter.t'
  2048. fi
  2049. echo shar: End of archive 4 \(of 17\).
  2050. cp /dev/null ark4isdone
  2051. MISSING=""
  2052. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; do
  2053.     if test ! -f ark${I}isdone ; then
  2054.     MISSING="${MISSING} ${I}"
  2055.     fi
  2056. done
  2057. if test "${MISSING}" = "" ; then
  2058.     echo You have unpacked all 17 archives.
  2059.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2060. else
  2061.     echo You still must unpack the following archives:
  2062.     echo "        " ${MISSING}
  2063. fi
  2064. exit 0
  2065. exit 0 # Just in case...
  2066.