home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1463 < prev    next >
Internet Message Format  |  1990-12-28  |  63KB

  1. From: sob@lib.tmc.edu (Stan Barber)
  2. Newsgroups: alt.sources
  3. Subject: rrn/rn combo kit part 6 of 9
  4. Message-ID: <432@lib.tmc.edu>
  5. Date: 14 Jun 90 03:28:30 GMT
  6.  
  7. #! /bin/sh
  8.  
  9. # Make a new directory for the rn sources, cd to it, and run kits 1 thru 9 
  10. # through sh.  When all 9 kits have been run, read README.
  11.  
  12. echo "This is rn kit 6 (of 9).  If kit 6 is complete, the line"
  13. echo '"'"End of kit 6 (of 9)"'" will echo at the end.'
  14. echo ""
  15. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  16. echo Extracting Pnews.SH
  17. cat >Pnews.SH <<'!STUFFY!FUNK!'
  18. case $CONFIG in
  19.     '') . config.sh ;;
  20. esac
  21. echo "Extracting Pnews (with variable substitutions)"
  22. $spitshell >Pnews <<!GROK!THIS!
  23. $startsh
  24. # $Header: Pnews.SH,v 4.3.2.7 90/05/04 23:14:45 sob Exp $
  25. #
  26. # $Log:    Pnews.SH,v $
  27. # Revision 4.3.2.7  90/05/04  23:14:45  sob
  28. # Expires: line removed from Pnews.header.
  29. # Revision 4.3.2.6  90/04/21  16:53:43  sob
  30. # Corrected a typo pointed out by Bill Aten.
  31. # Revision 4.3.2.5  89/12/17  01:53:48  sob
  32. # Changed from using ypcat to using ypmatch
  33. # Revision 4.3.2.4  89/12/09  01:48:30  sob
  34. # Reply-To: field removed. This makes all the headers created by rn
  35. # look roughly the same.
  36. # Revision 4.3.2.3  89/11/26  22:20:04  sob
  37. # Added support for some of the top level names that are not part of
  38. # the mainstream.
  39. # Revision 4.3.2.2  89/11/06  00:25:39  sob
  40. # Some minor changes to make the help messages more accurate
  41. # Revision 4.3.2.1  89/11/06  00:21:30  sob
  42. # Added RRN support from NNTP 1.5
  43. # Revision 4.3.1.4  86/09/05  15:21:10  lwall
  44. # Changes for new top-level newsgroup names.
  45. # Revision 4.3.1.3  85/08/01  14:24:06  lwall
  46. # Added AUTHORCOPY.  Temp file is no longer in /tmp.  'e editor' added.
  47. # Revision 4.3.1.2  85/05/17  10:36:46  lwall
  48. # Removed some extra backslashes.
  49. # Revision 4.3.1.1  85/05/10  11:30:21  lwall
  50. # Branch for patches.
  51. # Revision 4.3  85/05/01  12:20:33  lwall
  52. # Baseline for release with 4.3bsd.
  53. #
  54. # syntax: Pnews -h headerfile            or
  55. #      Pnews -h headerfile oldarticle    or
  56. #         Pnews newsgroup title            or just
  57. #         Pnews
  58.  
  59. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh \$0; kill \$\$)
  60.  
  61. # System dependencies
  62.  
  63. mailer="${mailer-/bin/mail}"
  64. # if you change this to something that does signatures, take out signature code
  65.  
  66. case $portable in
  67. define)
  68. # your site name
  69. sitename=\`$hostcmd\`
  70. case \$sitename in
  71.     *.*)
  72.         ;;
  73.     *)
  74.         sitename=\${sitename}.$domain
  75.         ;;
  76. esac
  77. # where recordings, distributions and moderators are kept
  78. lib=\`$filexp $lib\`
  79. # where important rn things are kept
  80. rnlib=\`$filexp $rnlib\`
  81. ;;
  82. undef)
  83. # your site name
  84. sitename="$sitename"
  85. # where recordings, distributions and moderators are kept
  86. lib="$lib"
  87. # where important rn things are kept
  88. rnlib="$rnlib"
  89. ;;
  90. esac
  91.  
  92. # your organization name
  93. orgname="$orgname"
  94. # what pager you use--if you have kernal paging use cat
  95. pager="\${PAGER-$pager}"
  96. # how you derive full names, bsd, usg, or other
  97. nametype="$nametype"
  98. # default editor
  99. defeditor="$defeditor"
  100. # how not to echo with newline
  101. n="$n"
  102. c="$c"
  103.  
  104. # You should also look at the distribution warnings below marked !DIST!
  105. # to make sure any distribution regions you are a member of are included.
  106. # The following are some prototypical distribution groups.  If you do not
  107. # use them all set the unused ones to a non-null string such as 'none'.
  108. loc="$locpref"
  109. org="$orgpref"
  110. city="$citypref"
  111. state="$statepref"
  112. cntry="$cntrypref"
  113. cont="$contpref"
  114.  
  115. test=${test-test}
  116. sed=${sed-sed}
  117. echo=${echo-echo}
  118. cat=${cat-cat}
  119. egrep=${egrep-egrep}
  120. grep=${grep-grep}
  121. rm=${rm-rm}
  122. tr=${tr-tr}
  123. inews=${inews-inews}
  124. ypmatch=${ypmatch}
  125.  
  126. !GROK!THIS!
  127. $spitshell >>Pnews <<'!NO!SUBS!'
  128. dotdir=${DOTDIR-${HOME-$LOGDIR}}
  129. tmpart=$dotdir/.article
  130.  
  131. if $test -f $dotdir/.pnewsexpert; then
  132.     expertise=expert
  133. else
  134.     $cat <<'EOM'
  135. I see you've never used this version of Pnews before.  I will give you extra
  136. help this first time through, but then you must remember what you learned.
  137. If you don't understand any question, type h and a CR (carriage return) for
  138. help.
  139.  
  140. If you've never posted an article to the net before, it is HIGHLY recommended
  141. that you read the netiquette document found in news.announce.newusers so
  142. that you'll know to avoid the commonest blunders.  To do that, interrupt
  143. Pnews, and get to the top-level prompt of rn.  Type "g news.announce.newusers"
  144. and you are on your way.
  145.  
  146. EOM
  147.     expertise=beginner
  148. fi
  149.  
  150. case $cntry in
  151.   can) stpr=Province ;;
  152.   *)   stpr=State ;;
  153. esac
  154.  
  155. headerfile=""
  156. case $# in
  157. 0) ;;
  158. *)  case $1 in
  159.     -h)
  160.     headerfile="$2"
  161.     shift
  162.     shift
  163.     case $# in
  164.     0)
  165.         oldart=""
  166.         ;;
  167.     *)
  168.         oldart="$1"
  169.         shift
  170.         ;;
  171.     esac
  172.     ;;
  173.     esac
  174.     ;;
  175. esac
  176.  
  177. case $headerfile in
  178. '')
  179.     . $rnlib/Pnews.header
  180.     ;;
  181. *)
  182.     $cat < $headerfile  > $tmpart
  183.     ;;
  184. esac
  185.     rescue="sleep 1; $cat $tmpart >>${HOME-$LOGDIR}/dead.article ; $echo Article appended to ${HOME-$LOGDIR}/dead.article ; exit"
  186.     trap "$rescue" 1
  187.     trap "$rescue" 2
  188.  
  189. $echo ""
  190. #: play recorded message
  191. set X `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
  192. shift
  193. case $# in
  194. 0|1)
  195.     ;;
  196. *)
  197.     shift
  198.     if $test -s ${lib}/recording ; then
  199.      ng=`$echo $1 | $sed "s/,.*//"`
  200.     _rec1=${lib}/`$sed -n "/^$ng/s/^.*    //p" ${lib}/recording`
  201.     _tmp=`$echo $ng |$sed "s/\..*//"`
  202.     _rec2=${lib}/`$cat -s ${lib}/recording|$grep ${_tmp}.all|$sed "s/^.*    //"`
  203.     if $test -f ${_rec1} ; then
  204.         $cat -s ${_rec1}
  205.     fi
  206.     if $test -f ${_rec2} ; then
  207.         $cat -s ${_rec2}
  208.     fi
  209.     fi
  210.     ;;
  211. esac
  212.  
  213. set X `$sed < $tmpart -n -e '/^Distribution: /{' -e p -e q -e '}' -e '/^$/q'`
  214. shift
  215. case $# in
  216. 0|1)
  217.     set X `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
  218.     shift
  219.     case $# in
  220.     0|1)
  221.     set "x misc.whatever"
  222.     ;;
  223.     esac
  224.     ;;
  225. *)
  226.     set $1 $2.whatever
  227.     ;;
  228. esac
  229. shift
  230.  
  231. #: play recorded message
  232. #if $test -s ${lib}/recording ; then
  233. #     ng=`$echo $1 | $sed "s/,.*//"`
  234. #    _rec1=${lib}/`$sed -n "/^$ng/s/^.*    //p" ${lib}/recording`
  235. #    _tmp=`$echo $ng |$sed "s/\..*//"`
  236. #    _rec2=${lib}/`$cat -s ${lib}/recording|$grep ${_tmp}.all|$sed "s/^.*    //"`
  237. #    if $test -f ${_rec1} ; then
  238. #    $cat -s ${_rec1}
  239. #    fi
  240. #    if $test -f ${_rec2} ; then
  241. #    $cat -s ${_rec2}
  242. #    fi
  243. #fi
  244.  
  245. # tell them what we think they are doing... !DIST!
  246. case $1 in
  247. world.*|comp.*|news.*|sci.*|rec.*|misc.*|soc.*|talk.*|alt.*)
  248.     $cat <<'EOM'
  249. This program posts news to thousands of machines throughout the entire
  250. civilized world.  Your message will cost the net hundreds if not thousands of
  251. dollars to send everywhere.  Please be sure you know what you are doing.
  252.  
  253. EOM
  254.     ;;
  255. vmsnet.*)
  256.     $echo 'This program posts news to many machines.'
  257.     ;;
  258. bit.*)
  259.     $echo 'This program posts news to many machines on BITNET.'
  260.     ;;
  261. ddn.*)
  262.     $echo 'This program posts news to many machines throughout the internet.'
  263.     ;;
  264. $cont.*)
  265.     $echo 'This program posts news to many machines throughout the continent.'
  266.     ;;
  267. $cntry.*)
  268.     $echo 'This program posts news to many machines throughout the country.'
  269.     ;;
  270. $state.*)
  271.     $echo 'This program posts news to many machines throughout the state.'
  272.     ;;
  273. $city.*)
  274.     $echo 'This program posts news to many machines throughout the city.'
  275.     ;;
  276. $org.*)
  277.     $echo 'This program posts news to machines throughout the organization.'
  278.     ;;
  279. $loc.*)
  280.     $echo 'This program posts news to machines throughout the local organization.'
  281.     ;;
  282. *.*)
  283.     $echo 'This program may post news to many machines.'
  284.     ;;
  285. to.*)
  286.     $echo 'This program may post news to a partcular machine.'
  287.     ;;
  288. *)
  289.     $echo 'This program posts news to everyone on the machine.'
  290.     ;;
  291. esac
  292. ans=""
  293. while $test "$ans" = "" ; do
  294.     $echo $n "Are you absolutely sure that you want to do this? [ny] $c"
  295.     read ans
  296.     case $ans in
  297.     y*) ;;
  298.     f*) suppressmess=y ;;
  299.     h*) $cat <<'EOH'
  300.  
  301. Type n or CR to exit, y to post.
  302.  
  303. EOH
  304.     ans="" ;;
  305.     *) exit ;;
  306.     esac
  307. done
  308.  
  309. file=h
  310. while $test "$file" = h ; do
  311.     $echo ""
  312.     $echo $n "Prepared file to include [none]: $c"
  313.     read file
  314.     case $file in
  315.     h)
  316.     $cat <<'EOH'
  317.  
  318. If you have already produced the body of your article, type the filename
  319. for it here.  If you just want to proceed directly to the editor, type a
  320. RETURN.  In any event, you will be allowed to edit as many times as you
  321. want before you send off the article.
  322. EOH
  323.     ;;
  324.     '')
  325.     $echo "" >> $tmpart
  326.     state=edit
  327.     ;;
  328.     *)
  329.     $cat $file >>$tmpart
  330.     state=ask
  331.     ;;
  332.     esac
  333. done
  334.  
  335. $echo ""
  336.  
  337. while true ; do
  338.     case $state in
  339.     edit)
  340.     case $expertise in
  341.     beginner)
  342.         $cat </dev/null >$dotdir/.pnewsexpert
  343.         $cat <<'EOMessage'
  344. A temporary file has been created for you to edit.  Be sure to leave at
  345. least one blank line between the header and the body of your message.
  346. (And until a certain bug is fixed all over the net, don't start the body of
  347. your message with any indentation, or it may get eaten.)
  348.  
  349. Within the header may be fields that you don't understand.  If you don't
  350. understand a field (or even if you do), you can simply leave it blank, and
  351. it will go away when the article is posted.
  352.  
  353. Type return to get the default editor, or type the name of your favorite
  354. editor.
  355.  
  356. EOMessage
  357.         ;;
  358.     esac
  359.     case "${VISUAL-${EDITOR-}}" in
  360.     '')
  361.         tmp=h
  362.         ;;
  363.     *)
  364.         tmp=''
  365.         ;;
  366.     esac
  367.     while $test "$tmp" = h ; do
  368.         $echo $n "Editor [${VISUAL-${EDITOR-$defeditor}}]: $c"
  369.         read tmp
  370.         case $tmp in
  371.         h)
  372.         $cat <<'EOH'
  373.  
  374. Type a return to get the default editor, or type the name of the editor you
  375. prefer.  The default editor depends on the VISUAL and EDITOR environment
  376. variables.
  377.  
  378. EOH
  379.         ;;
  380.         '')
  381.         ;;
  382.         *)
  383.         VISUAL=$tmp
  384.         export VISUAL
  385.         ;;
  386.         esac
  387.     done
  388.     trap : 2
  389.     ${VISUAL-${EDITOR-$defeditor}} $tmpart $oldart
  390.     trap "$rescue" 2
  391.     state=ask
  392.     ;;
  393.     
  394.     ask)
  395.     $echo ""
  396.     $echo $n "Send, abort, edit, or list? $c"
  397.     read ans
  398.     
  399.     case "$ans" in
  400.     a*)
  401.         state=rescue
  402.         ;;
  403.     e*)
  404.         set $ans
  405.         case $# in
  406.         2)  VISUAL="$2" ;;
  407.         esac
  408.         state=edit
  409.         ;;
  410.     l*)
  411.         $pager $tmpart
  412.         state=ask
  413.         ;;
  414.     s*)
  415.         state=send
  416.         ;;
  417.     h*)
  418.         $cat <<'EOH'
  419.  
  420. Type s to send the article, a to abort and append the article to dead.article,
  421. e to edit the article again, or l to list the article.
  422.  
  423. To invoke an alternate editor, type 'e editor'.
  424. EOH
  425.     esac
  426.     ;;
  427.     
  428.     send)
  429.     set X `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
  430.     shift
  431.     case $# in
  432.     2)
  433.         state=cleanup
  434.         if $test -f $lib/moderators; then
  435.         tryinews=no
  436.         shift
  437.         case "$1" in
  438.         *,*) set `$echo $1 | tr ',' ' '`;;
  439.         esac
  440.         for newsgroup in $*; do
  441. # the following screwy sed should prevent Eunice from hanging on no match
  442.             moderator=`$sed <$lib/moderators \
  443.             -e "/^$newsgroup[     ]/!s/.*//" \
  444.             -e "s/^$newsgroup[     ]//"`
  445.             case ${moderator}X in
  446.             X)  tryinews=yes
  447.             ;;
  448.             *)
  449.             $echo Mailing to moderator $moderator
  450.             case "$sign" in
  451.             n*) ;;
  452.             *)
  453.                 if $test -f $dotdir/.signature; then
  454.                 echo $n "Append .signature file? [y] $c"
  455.                 read ans
  456.                 case $ans in
  457.                 ''|y*)
  458.                     echo "-- " >> $tmpart
  459.                     cat $dotdir/.signature >> $tmpart
  460.                     ;;
  461.                 esac
  462.                 fi
  463.                 sign=no
  464.                 ;;
  465.             esac
  466.             case "$mailer" in
  467.             *recmail)
  468.                 $echo To: $moderator | $cat - $tmpart | $mailer
  469.                 ;;
  470.             *)
  471.                 $mailer $moderator < $tmpart
  472.                 ;;
  473.             esac
  474.             case $? in
  475.             0) ;;
  476.             *)
  477.                 $echo Unable to mail to moderator $moderator
  478.                 state=rescue
  479.                 ;;
  480.             esac
  481.             ;;
  482.             esac
  483.         done
  484.         else
  485.         tryinews=yes
  486.         fi
  487.         case "$tryinews" in
  488.         yes)
  489.         if $inews -h < $tmpart ; then
  490.             : null
  491.         else
  492.             state=rescue
  493.         fi
  494.         ;;
  495.         esac
  496.         ;;
  497.     *)
  498.         $echo ""
  499.         $echo "Malformed Newsgroups line."
  500.         $echo ""
  501.         sleep 1
  502.         state=edit
  503.         ;;
  504.     esac
  505.     ;;
  506.     rescue)
  507.     $cat $tmpart >> ${HOME-$LOGDIR}/dead.article
  508.     $echo "Article appended to ${HOME-$LOGDIR}/dead.article"
  509.     $echo "A copy may be temporarily found in $tmpart"
  510.     exit
  511.     ;;
  512.     cleanup)
  513.     case "${AUTHORCOPY-none}" in
  514.     none)
  515.         ;;
  516.     *)  if $echo From $USER `date` >> $AUTHORCOPY; then
  517.         $cat $tmpart >> $AUTHORCOPY
  518.         $echo "Article appended to $AUTHORCOPY"
  519.         $echo "" >> $AUTHORCOPY
  520.         $echo "" >> $AUTHORCOPY
  521.         else
  522.         $echo "Cannot append to $AUTHORCOPY"
  523.         fi
  524.         ;;
  525.     esac
  526.     exit
  527.     ;;
  528.     esac
  529. done
  530. !NO!SUBS!
  531. $eunicefix Pnews
  532. chmod 755 Pnews
  533. $spitshell >Pnews.header <<'!NO!SUBS!'
  534. case $# in
  535. 0)
  536.     ng=h
  537.     while $test "$ng" = h ; do
  538.     $echo ""
  539.     $echo $n "Newsgroup(s): $c"
  540.     read ng
  541.     case $ng in
  542.     h)
  543.         $cat <<'EOH'
  544.  
  545. Type the name of one or more newsgroups to which you wish to post an article.
  546. If you want to post to multiple newsgroups, it is better to do them all at
  547. once than to post to each newsgroup individually, which defeats the news
  548. reading programs' strategies of eliminating duplicates.
  549.  
  550. Separate multiple newsgroup names with commas.
  551. EOH
  552.         ;;
  553.     esac
  554.     done
  555.     ;;
  556. *)
  557.     ng=$1
  558.     shift
  559.     ;;
  560. esac
  561. case $ng in
  562. *\ *)
  563.     ng=`$echo "$ng" | $sed 's/[, ] */,/g'`
  564.     ;;
  565. esac
  566. case $ng in
  567. bit.*|pubnet.*|bionet.*|vmsnet.*|comp.*|news.*|sci.*|rec.*|misc.*|soc.*|talk.*|alt.*)
  568.     defdist=world
  569.     dist=h
  570.     ;;
  571. ddn.*)
  572.     defdist=inet
  573.     dist=h
  574.     ;;
  575. to.*)
  576.     defdist=''
  577.     dist=''
  578.     ;;
  579. *.*)
  580.     defdist=`expr "X$ng" : 'X\([a-z0-9]*\)'`
  581.     dist=h
  582.     ;;
  583. *)
  584.     defdist=''
  585.     dist=''
  586.     ;;
  587. esac
  588.  
  589. while $test "$dist" = h ; do
  590.     if $test -f $lib/distributions; then
  591.     $echo " "
  592.     $echo "Your local distribution prefixes are:"
  593.     $cat $lib/distributions
  594.     $echo " "
  595.     else
  596.     $egrep -v '[     ]none$' <<EOM
  597.  
  598. Your local distribution prefixes are:
  599.     Local organization:    $loc
  600.     Organization:    $org
  601.     City:        $city
  602.     $stpr:          $state
  603.     Country:        $cntry
  604.     Continent:        $cont
  605.     Everywhere:        world
  606.  
  607. EOM
  608.     fi
  609.     $echo $n "Distribution ($defdist): $c"
  610.     read dist
  611.     case $dist in
  612.     '') dist=$defdist ;;
  613.     esac
  614.     case $dist in
  615.     h)
  616.     $cat <<'EOH'
  617.  
  618. The Distribution line may be used to limit the distribution of an article
  619. to some subset of the systems that would receive the article based only on
  620. the Newsgroups line.  For example, if you want to sell your car in talk.auto,
  621. and you live in New Jersey, you might want to put "nj" on the Distribution
  622. line to avoid advertising in California, which has enough problems of its own.
  623. The actual area designators to use depend on where you are, of course.
  624. EOH
  625.     ;;
  626.     ''|$loc*|$org*|$city*|$state*|$cntry*|$cont*|$defdist)
  627.     ;;
  628.     world*|comp*|news*|sci*|rec*|misc*|soc*|talk*|alt*)
  629.     dist=''
  630.     ;;
  631.     *)  
  632.     if $test -f $lib/distributions && \
  633.       $egrep "^$dist[     ]" $lib/distributions >$tmpart && \
  634.       $test -s $tmpart; then
  635.         : null
  636.     else
  637.         $echo "Unrecognized distribution prefix--type h for help, CR to use anyway."
  638.         defdist=$dist
  639.         dist=h
  640.     fi
  641.     ;;
  642.     esac
  643. done
  644.  
  645. follow=""
  646.  
  647. case $# in
  648. 0)
  649.     title=h
  650.     while $test "$title" = h ; do
  651.     $echo ""
  652.     $echo $n "Title/Subject: $c"
  653.     read title
  654.     case $title in
  655.     h)
  656.         $cat <<'EOH'
  657.  
  658. Type the title for your article.  Please make it as informative as possible
  659. (within reason) so that people who aren't interested won't have to read the
  660. article to find out they aren't interested.  This includes marking movie
  661. spoilers as (spoiler), and rotated jokes as (rot 13).
  662. EOH
  663.     ;;
  664.     esac
  665.     done
  666.     ;;
  667. *)
  668.     title="$*"
  669.     ;;
  670. esac
  671.  
  672. # now build a file with a header for them to edit
  673.  
  674. set X ${USER-${LOGNAME-`who am i`}}
  675. shift
  676. logname=$1
  677. case $logname in
  678. *!*) logname=`expr "$logname" : '!\(.*\)$'` ;;
  679. esac
  680. case ${NAME-$nametype} in
  681. bsd)
  682.      if $test "$ypmatch" != ""; then
  683.          fullname=`$ypmatch $logname passwd 2>/dev/null | $sed "s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:;]*\).*"'$'"/\1/"`
  684.      fi
  685.      if $test "$fullname" = ""; then
  686.          fullname=`$sed </etc/passwd -e "/^$logname:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:;]*\).*"'$'"/\1/" -e "q" -e "}" -e "d"`
  687.      fi
  688.     case $fullname in
  689.     *'&'*) : GACK
  690.     lname=`$echo $logname | $tr 'a-z' 'A-Z'`
  691.     lname=`$echo $lname $logname | $sed 's/^\(.\)[^ ]* ./\1/'`
  692.     fullname=`$echo "$fullname" | $sed "s/&/${lname}/"`
  693.     ;;
  694.     esac
  695.     ;;
  696. usg)
  697.      if $test "$ypmatch" != ""; then
  698.          fullname=`$ypmatch $logname passwd 2>/dev/null | $sed "s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^(:]*\).*"'$'"/\1/" -e "s/^.*-//" -e "q"`
  699.      fi
  700.      if $test "$fullname" = ""; then
  701.     fullname=`$sed </etc/passwd -e "/^$logname:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^(:]*\).*"'$'"/\1/" -e "s/^.*-//" -e "q" -e "}" -e "d"`
  702.      fi
  703.     ;;
  704. *)
  705.     fullname=${NAME-`$cat $dotdir/.fullname`}
  706.     ;;
  707. esac
  708.  
  709. orgname=${ORGANIZATION-$orgname}
  710. case $orgname in
  711. /*) orgname=`$cat $orgname` ;;
  712. esac
  713.  
  714. $cat > $tmpart <<EOHeader
  715. From: $logname@$sitename ($fullname)
  716. Newsgroups: $ng
  717. Subject: $title
  718. References: 
  719. Sender: 
  720. Followup-To: $follow
  721. Distribution: $dist
  722. Organization: $orgname
  723. Keywords: 
  724.  
  725. EOHeader
  726.  
  727. !NO!SUBS!
  728. case "$isrrn" in
  729. define) sed < Pnews.header -e '/^#NORMAL/d' > Pnews.h.new ;;
  730. *)  sed < Pnews.header -e '/^#NORMAL/s/^#NORMAL//' > Pnews.h.new ;;
  731. esac
  732. mv Pnews.h.new Pnews.header
  733. $eunicefix Pnews.header
  734. !STUFFY!FUNK!
  735. echo Extracting rn.c
  736. cat >rn.c <<'!STUFFY!FUNK!'
  737. /*  rn -- new readnews program
  738.  *
  739.  *  Original Author: lwall@sdcrdcf.UUCP (Larry Wall)
  740.  *  Organization: System Development Corporation, Santa Monica
  741.  *
  742.  *  begun:   01/14/83
  743.  *    1.0: 04/08/83
  744.  *      2.0: 09/01/83
  745.  *      RRN/RN: 11/01/89
  746. */
  747.  
  748. static char rnid[] = "@(#)$Header: rn.c,v 4.3.2.4 90/04/03 23:11:33 sob Exp $";
  749. static char patchlevel[] = "Patch #: 47";
  750.  
  751. /* $Log:    rn.c,v $
  752.  * Revision 4.3.2.4  90/04/03  23:11:33  sob
  753.  * Added more information to the version command.
  754.  * 
  755.  * Revision 4.3.2.3  90/03/22  23:05:23  sob
  756.  * Fixes provided by Wayne Davison <drivax!davison>
  757.  * 
  758.  * Revision 4.3.2.2  89/11/28  01:51:25  sob
  759.  * Removed redundant #include directive.
  760.  * 
  761.  * Revision 4.3.2.1  89/11/08  02:27:38  sob
  762.  * Release of RN 4.3 with RRN that can be compiled from the same
  763.  * sources as either version of the program.
  764.  * 
  765.  * Revision 4.3.1.4  85/09/10  11:05:13  lwall
  766.  * Improved %m in in_char().
  767.  * 
  768.  * Revision 4.3.1.3  85/05/16  16:47:10  lwall
  769.  * Catchup confirmation didn't grok -t.
  770.  * 
  771.  * Revision 4.3.1.2  85/05/13  09:34:53  lwall
  772.  * Fixed default after do_newsgroup() returns from Q command.
  773.  * 
  774.  * Revision 4.3.1.1  85/05/10  11:38:08  lwall
  775.  * Branch for patches.
  776.  * 
  777.  * Revision 4.3  85/05/01  11:47:56  lwall
  778.  * Baseline for release with 4.3bsd.
  779.  * 
  780.  */
  781.  
  782. #include "INTERN.h"
  783. #include "common.h"
  784. #include "rn.h"
  785. #include "EXTERN.h"
  786. #include "rcstuff.h"
  787. #include "term.h"
  788. #include "final.h"
  789. #include "ngdata.h"
  790. #include "util.h"
  791. #include "only.h"
  792. #include "ngsrch.h"
  793. #include "help.h"
  794. #include "last.h"
  795. #include "init.h"
  796. #include "intrp.h"
  797. #include "rcln.h"
  798. #include "sw.h"
  799. #include "addng.h"
  800. #include "ng.h"
  801.  
  802. void
  803. rn_init()
  804. {
  805.     ;
  806. }
  807.  
  808. void
  809. main(argc,argv)
  810. int argc;
  811. char *argv[];
  812. {
  813.     bool foundany = initialize(argc,argv);
  814.     register char *s;
  815.     bool oh_for_the_good_old_days = FALSE;
  816.     
  817.     if (maxngtodo)
  818.     starthere = 0;
  819.     else if (!foundany) {        /* nothing to do? */
  820. #ifdef VERBOSE
  821.     if (verbose)
  822.         fputs("\
  823. No unread news in subscribed-to newsgroups.  To subscribe to a new\n\
  824. newsgroup use the g<newsgroup> command.\n\
  825. ",stdout) FLUSH;
  826. #endif
  827.     starthere = nextrcline;
  828.     }
  829.  
  830.     /* loop through all unread news */
  831.  
  832.     {
  833.     char promptbuf[80];
  834.     bool special = FALSE;        /* temporarily allow newsgroup */
  835.                     /*   with no unread news? */
  836.     bool retry;            /* cycle back to top of list? */
  837.     NG_NUM recent_ng = 0;
  838.     
  839.     current_ng = 0;
  840.     do {
  841.         retry = FALSE;
  842.         if (findlast) {
  843.         findlast = FALSE;
  844.         starthere = 0;
  845.         if (*lastngname) {
  846.             if ((ng = find_ng(lastngname)) == nextrcline)
  847.             ng = 0;
  848.             else {
  849.             set_ngname(lastngname);
  850.                 set_toread(ng);
  851.             if (toread[ng] <= TR_NONE)
  852.                 ng = 0;
  853.             }
  854.         }
  855.         }
  856.         else {
  857.         ng = starthere;
  858.         starthere = 0;
  859.         }
  860.         while (ng <= nextrcline) {    /* for each newsgroup */
  861.         mode = 'n';
  862.         if (ng >= nextrcline) {    /* after the last newsgroup? */
  863.             ng = nextrcline;    /* force it to 1 after */
  864. #ifdef ONLY
  865.             if (maxngtodo) {
  866.             if (retry)
  867. #ifdef VERBOSE
  868.                 IF(verbose)
  869.                 printf("\nRestriction %s%s still in effect.\n",
  870.                     ngtodo[0],
  871.                     maxngtodo > 1 ? ", etc." : nullstr) FLUSH;
  872.                 ELSE
  873. #endif
  874. #ifdef TERSE
  875.                 fputs("\n(\"Only\" mode.)\n",stdout) FLUSH;
  876. #endif
  877.             else {
  878. #ifdef VERBOSE
  879.                 IF(verbose)
  880.                 fputs("\nNo articles under restriction.",
  881.                   stdout) FLUSH;
  882.                 ELSE
  883. #endif
  884. #ifdef TERSE
  885.                 fputs("\nNo \"only\" articles.",stdout) FLUSH;
  886. #endif
  887.                 end_only();    /* release the restriction */
  888.                 retry = TRUE;
  889.             }
  890.             }
  891. #endif
  892.             dfltcmd = (retry ? "npq" : "qnp");
  893. #ifdef VERBOSE
  894.             IF(verbose)
  895.             sprintf(promptbuf,
  896.                 "\n******** End of newsgroups--what next? [%s] ",
  897.                 dfltcmd);
  898.             ELSE
  899. #endif
  900. #ifdef TERSE
  901.             sprintf(promptbuf,
  902.                 "\n**** End--next? [%s] ", dfltcmd);
  903. #endif
  904.         }
  905.         else {
  906.             bool shoe_fits;    /* newsgroup matches restriction? */
  907.  
  908.             if (toread[ng] >= TR_NONE) {    /* recalc toread? */
  909.             set_ngname(rcline[ng]);
  910.             if (shoe_fits = (special || inlist(ngname)))
  911.                 set_toread(ng);
  912.             if (paranoid) {
  913.                 recent_ng = current_ng;
  914.                 current_ng = ng;
  915.                 cleanup_rc();
  916.                     /* this may move newsgroups around */
  917.                 ng = current_ng;
  918.                 set_ngname(rcline[ng]);
  919.             }
  920.             }
  921.             if (toread[ng] < (maxngtodo||special ? TR_NONE : TR_ONE) || !shoe_fits) {
  922.                     /* unwanted newsgroup? */
  923.             ng++;        /* then skip it */
  924.             continue;
  925.             }
  926.     reprompt_newsgroup:
  927.             dfltcmd = "ynq";
  928. #ifdef VERBOSE
  929.             IF(verbose)
  930.             sprintf(promptbuf,
  931.                 "\n******** %3ld unread article%c in %s--read now? [%s] ",
  932.                 (long)toread[ng], (toread[ng]==TR_ONE ? ' ' : 's'),
  933.                 ngname, dfltcmd);    /* format prompt string */
  934.             ELSE
  935. #endif
  936. #ifdef TERSE
  937.             sprintf(promptbuf,
  938.                 "\n**** %3ld in %s--read? [%s] ",
  939.                 (long)toread[ng],
  940.                 ngname,dfltcmd);    /* format prompt string */
  941. #endif
  942.         }
  943.         special = FALSE;    /* go back to normal mode */
  944.         if (ng != current_ng) {
  945.             recent_ng = current_ng;
  946.                     /* remember previous newsgroup */
  947.             current_ng = ng;    /* remember current newsgroup */
  948.         }
  949.     reask_newsgroup:
  950.         unflush_output();    /* disable any ^O in effect */
  951.         fputs(promptbuf,stdout) FLUSH;/* print prompt */
  952.         fflush(stdout);
  953.     reinp_newsgroup:
  954.         eat_typeahead();
  955.         getcmd(buf);
  956.         if (errno || *buf == '\f') {
  957.             putchar('\n') FLUSH; /* if return from stop signal */
  958.             goto reask_newsgroup;    /* give them a prompt again */
  959.         }
  960.         setdef(buf,dfltcmd);
  961. #ifdef VERIFY
  962.         printcmd();
  963. #endif
  964.         switch (*buf) {
  965.         case 'p':        /* find previous unread newsgroup */
  966.             do {
  967.             if (ng <= 0)
  968.                 break;
  969.             ng--;
  970.             if (toread[ng] == TR_NONE)
  971.                 set_toread(ng);
  972.             } while (toread[ng] <= TR_NONE);
  973.             break;
  974.         case 'P':        /* goto previous newsgroup */
  975.             do {
  976.             if (ng <= 0)
  977.                 break;
  978.             ng--;
  979.             } while (toread[ng] < TR_NONE);
  980.             special = TRUE;    /* don't skip it if toread==0 */
  981.             break;
  982.         case '-':
  983.             ng = recent_ng;    /* recall previous newsgroup */
  984.             special = TRUE;    /* don't skip it if toread==0 */
  985.             break;
  986.         case 'q': case 'Q': case 'x':    /* quit? */
  987.             oh_for_the_good_old_days = (*buf == 'x');
  988.             putchar('\n') FLUSH;
  989.             ng = nextrcline+1;    /* satisfy */
  990.             retry = FALSE;    /*   loop conditions */
  991.             break;
  992.         case '^':
  993.             putchar('\n') FLUSH;
  994.             ng = 0;
  995.             break;
  996.         case 'n': case '+':    /* find next unread newsgroup */
  997.             if (ng == nextrcline) {
  998.             putchar('\n') FLUSH;
  999.             retry = TRUE;
  1000.             }
  1001.             else if (toread[ng] > TR_NONE)
  1002.             retry = TRUE;
  1003.             ng++;
  1004.             break;
  1005.         case 'N':        /* goto next newsgroup */
  1006.             ng++;
  1007.             special = TRUE;    /* and don't skip it if toread==0 */
  1008.             break;
  1009.         case '1':        /* goto 1st newsgroup */
  1010.             ng = 0;
  1011.             special = TRUE;    /* and don't skip it if toread==0 */
  1012.             break;
  1013.         case '$':
  1014.             ng = nextrcline;    /* goto last newsgroup */
  1015.             retry = TRUE;
  1016.             break;
  1017.         case 'L':
  1018.             list_newsgroups();
  1019.             goto reask_newsgroup;
  1020.         case '/': case '?':    /* scan for newsgroup pattern */
  1021. #ifdef NGSEARCH
  1022.             switch (ng_search(buf,TRUE)) {
  1023.             case NGS_ABORT:
  1024.             goto reinp_newsgroup;
  1025.             case NGS_INTR:
  1026. #ifdef VERBOSE
  1027.             IF(verbose)
  1028.                 fputs("\n(Interrupted)\n",stdout) FLUSH;
  1029.             ELSE
  1030. #endif
  1031. #ifdef TERSE
  1032.                 fputs("\n(Intr)\n",stdout) FLUSH;
  1033. #endif
  1034.             ng = current_ng;
  1035.             goto reask_newsgroup;
  1036.             case NGS_FOUND:
  1037.             special = TRUE;    /* don't skip it if toread==0 */
  1038.             break;
  1039.             case NGS_NOTFOUND:
  1040. #ifdef VERBOSE
  1041.             IF(verbose)
  1042.                 fputs("\n\nNot found--use g to add newsgroups\n",
  1043.                 stdout) FLUSH;
  1044.             ELSE
  1045. #endif
  1046. #ifdef TERSE
  1047.                 fputs("\n\nNot found\n",stdout) FLUSH;
  1048. #endif
  1049.             goto reask_newsgroup;
  1050.             }
  1051. #else
  1052.             notincl("/");
  1053. #endif
  1054.             break;
  1055.         case 'm':
  1056. #ifndef RELOCATE
  1057.             notincl("m");
  1058.             break;
  1059. #endif            
  1060.         case 'g':    /* goto named newsgroup */
  1061.             if (!finish_command(FALSE))
  1062.                     /* if they didn't finish command */
  1063.             goto reinp_newsgroup;    /* go try something else */
  1064.             for (s = buf+1; *s == ' '; s++);
  1065.                     /* skip leading spaces */
  1066.             if (!*s)
  1067.             strcpy(s,ngname);
  1068. #ifdef RELOCATE
  1069.             if (!get_ng(s,*buf=='m'))    /* try to find newsgroup */
  1070. #else
  1071.             if (!get_ng(s,FALSE))    /* try to find newsgroup */
  1072. #endif
  1073.             ng = current_ng;/* if not found, go nowhere */
  1074.             special = TRUE;    /* don't skip it if toread==0 */
  1075.             break;
  1076. #ifdef DEBUGGING
  1077.         case 'D':
  1078.             printf("\nTries: %d Hits: %d\n",
  1079.             softtries,softtries-softmisses) FLUSH;
  1080.             goto reask_newsgroup;
  1081. #endif
  1082.         case '!':        /* shell escape */
  1083.             if (escapade())     /* do command */
  1084.             goto reinp_newsgroup;
  1085.                     /* if rubbed out, re input */
  1086.             goto reask_newsgroup;
  1087.         case Ctl('k'):        /* edit global KILL file */
  1088.             edit_kfile();
  1089.             goto reask_newsgroup;
  1090.         case 'c':        /* catch up */
  1091. #ifdef CATCHUP
  1092. reask_catchup:
  1093. #ifdef VERBOSE
  1094.         IF(verbose)
  1095.             in_char("\nDo you really want to mark everything as read? [yn] ", 'C');
  1096.         ELSE
  1097. #endif
  1098. #ifdef TERSE
  1099.             in_char("\nReally? [ynh] ", 'C');
  1100. #endif
  1101.             putchar('\n') FLUSH;
  1102.             setdef(buf,"y");
  1103.             if (*buf == 'h') {
  1104. #ifdef VERBOSE
  1105.             printf("Type y or SP to mark all articles as read.\n");
  1106.             printf("Type n to leave articles marked as they are.\n");
  1107. #else
  1108.             printf("y or SP to mark all read.\n");
  1109.             printf("n to forget it.\n");
  1110. #endif
  1111.             goto reask_catchup;
  1112.             }
  1113.             else if (*buf!=' ' && *buf!='y' && *buf!='n' && *buf!='q') {
  1114.             printf(hforhelp);
  1115.             settle_down();
  1116.             goto reask_catchup;
  1117.             } else if ( (*buf == ' ' || *buf == 'y') && ng<nextrcline )
  1118.             catch_up(ng);
  1119.             else
  1120.             retry = TRUE;
  1121.             ng++;
  1122. #else
  1123.             notincl("c");
  1124. #endif
  1125.             break;
  1126.         case 'u':        /* unsubscribe */
  1127.             if (ng < nextrcline && toread[ng] >= TR_NONE) {
  1128.                     /* unsubscribable? */
  1129.             printf(unsubto,rcline[ng]) FLUSH;
  1130.             rcchar[ng] = NEGCHAR;
  1131.                     /* unsubscribe to (from?) it */
  1132.             toread[ng] = TR_UNSUB;
  1133.                     /* and make line invisible */
  1134.             ng++;        /* do an automatic 'n' */
  1135.             }
  1136.             break;
  1137.         case 'h': {        /* help */
  1138.             int cmd;
  1139.  
  1140.             if ((cmd = help_ng()) > 0)
  1141.             pushchar(cmd);
  1142.             goto reask_newsgroup;
  1143.         }
  1144.         case 'a':
  1145. #ifndef FINDNEWNG
  1146.             notincl("a");
  1147.             goto reask_newsgroup;
  1148. #else
  1149.             /* FALL THROUGH */
  1150. #endif
  1151.         case 'o':
  1152. #ifdef ONLY
  1153.         {
  1154. #ifdef FINDNEWNG
  1155.             bool doscan = (*buf == 'a');
  1156. #endif
  1157.  
  1158.             if (!finish_command(TRUE)) /* get rest of command */
  1159.             goto reinp_newsgroup;    /* if rubbed out, try something else */
  1160.             end_only();
  1161.             if (buf[1]) {
  1162.             bool minusd = instr(buf+1,"-d") != Nullch;
  1163.  
  1164.             sw_list(buf+1);
  1165.             if (minusd)
  1166.                 cwd_check();
  1167.             putchar('\n') FLUSH;
  1168. #ifdef FINDNEWNG
  1169.             if (doscan && maxngtodo)
  1170.                 scanactive();
  1171. #endif
  1172.             }
  1173.             ng = 0;        /* simulate ^ */
  1174.             retry = FALSE;
  1175.             break;
  1176.         }
  1177. #else
  1178.             notincl("o");
  1179.             goto reask_newsgroup;
  1180. #endif
  1181.         case '&':
  1182.             if (switcheroo()) /* get rest of command */
  1183.             goto reinp_newsgroup;    /* if rubbed out, try something else */
  1184.             goto reask_newsgroup;
  1185.         case 'l': {        /* list other newsgroups */
  1186.             if (!finish_command(TRUE)) /* get rest of command */
  1187.             goto reinp_newsgroup;    /* if rubbed out, try something else */
  1188.             for (s = buf+1; *s == ' '; s++);
  1189.                         /* skip leading spaces */
  1190.             sprintf(cmd_buf,"%s '%s'",filexp(NEWSGROUPS),s);
  1191.             resetty();
  1192.             if (doshell(sh,cmd_buf))
  1193. #ifdef VERBOSE
  1194.             IF(verbose)
  1195.                 fputs("    (Error from newsgroups program)\n",
  1196.                 stdout) FLUSH;
  1197.             ELSE
  1198. #endif
  1199. #ifdef TERSE
  1200.                 fputs("(Error)\n",stdout) FLUSH;
  1201. #endif
  1202.             noecho();
  1203.             crmode();
  1204.             goto reask_newsgroup;
  1205.         }
  1206.         case '.': case '=':
  1207.         case 'y': case 'Y': /* do normal thing */
  1208.             if (ng >= nextrcline) {
  1209.             fputs("\nNot on a newsgroup.",stdout) FLUSH;
  1210.             goto reask_newsgroup;
  1211.             }
  1212.             if (*buf == '=')
  1213.             s = savestr("=");
  1214.             else if (*buf == '.') {    /* start command? */
  1215.             if (!finish_command(FALSE)) /* get rest of command */
  1216.                 goto reinp_newsgroup;
  1217.             s = savestr(buf+1);
  1218.                     /* do_newsgroup will free it */
  1219.             }
  1220.             else
  1221.             s = Nullch;
  1222.             if (toread[ng])
  1223.             retry = TRUE;
  1224.             switch (do_newsgroup(s)) {
  1225.             case NG_ERROR:
  1226.             case NG_NORM:
  1227.             ng++;
  1228.             break;
  1229.             case NG_ASK:
  1230.             goto reprompt_newsgroup;
  1231.             case NG_MINUS:
  1232.             ng = recent_ng;    /* recall previous newsgroup */
  1233.             special = TRUE;    /* don't skip it if toread==0 */
  1234.             break;
  1235.             }
  1236.             break;
  1237. #ifdef STRICTCR
  1238.         case '\n':
  1239.             fputs(badcr,stdout) FLUSH;
  1240.             goto reask_newsgroup;
  1241. #endif
  1242.         case 'v':
  1243.             printf("\n%s",rnid);
  1244.             printf("\n%s",patchlevel);
  1245.             printf("\nSend bugs to rrn@lib.tmc.edu\n") FLUSH;
  1246.             goto reask_newsgroup;
  1247.         default:
  1248.             printf("\n%s",hforhelp) FLUSH;
  1249.             settle_down();
  1250.             goto reask_newsgroup;
  1251.         }
  1252.         }
  1253.     } while (retry);
  1254.     }
  1255.  
  1256.     /* now write .newsrc back out */
  1257.  
  1258.     write_rc();
  1259.  
  1260.     if (oh_for_the_good_old_days)
  1261.     get_old_rc();
  1262.  
  1263.     finalize(0);            /* and exit */
  1264. }
  1265.  
  1266. /* set current newsgroup */
  1267.  
  1268. void
  1269. set_ngname(what)
  1270. char *what;
  1271. {
  1272.     int len = strlen(what)+1;
  1273.  
  1274.     growstr(&ngname,&ngnlen,len);
  1275.     strcpy(ngname,what);
  1276.     growstr(&ngdir,&ngdlen,len);
  1277.     strcpy(ngdir,getngdir(ngname));
  1278. }
  1279.  
  1280. static char *myngdir;
  1281. static int ngdirlen = 0;
  1282.  
  1283. char *
  1284. getngdir(ngnam)
  1285. char *ngnam;
  1286. {
  1287.     register char *s;
  1288.  
  1289.     growstr(&myngdir,&ngdirlen,strlen(ngnam)+1);
  1290.     strcpy(myngdir,ngnam);
  1291.     for (s = myngdir; *s; s++)
  1292.     if (*s == '.')
  1293.         *s = '/';
  1294.     return myngdir;
  1295. }
  1296.  
  1297. !STUFFY!FUNK!
  1298. echo Extracting sw.c
  1299. cat >sw.c <<'!STUFFY!FUNK!'
  1300. /* $Header: sw.c,v 4.3.2.3 90/05/08 22:06:00 sob Exp $
  1301.  *
  1302.  * $Log:    sw.c,v $
  1303.  * Revision 4.3.2.3  90/05/08  22:06:00  sob
  1304.  * Added quick startup (-q) flag.
  1305.  * 
  1306.  * Revision 4.3.2.2  90/03/22  23:05:34  sob
  1307.  * Fixes provided by Wayne Davison <drivax!davison>
  1308.  * 
  1309.  * Revision 4.3.2.1  89/12/09  00:52:40  sob
  1310.  * Now handles SIGWINCH correctly.
  1311.  * 
  1312.  * Revision 4.3.1.2  85/05/21  13:36:23  lwall
  1313.  * Sped up "rn -c" by not doing unnecessary initialization.
  1314.  * 
  1315.  * Revision 4.3.1.1  85/05/10  11:40:38  lwall
  1316.  * Branch for patches.
  1317.  * 
  1318.  * Revision 4.3  85/05/01  11:50:54  lwall
  1319.  * Baseline for release with 4.3bsd.
  1320.  * 
  1321.  */
  1322.  
  1323. #include "EXTERN.h"
  1324. #include "common.h"
  1325. #include "util.h"
  1326. #include "head.h"
  1327. #include "only.h"
  1328. #include "term.h"
  1329. #include "ng.h"
  1330. #include "intrp.h"
  1331. #include "INTERN.h"
  1332. #include "sw.h"
  1333.  
  1334. void
  1335. sw_init(argc,argv,tcbufptr)
  1336. int argc;
  1337. char *argv[];
  1338. char **tcbufptr;
  1339. {
  1340.     register int i;
  1341.  
  1342.     if (argc >= 2 && strEQ(argv[1],"-c"))
  1343.     checkflag=TRUE;            /* so we can optimize for -c */
  1344.     interp(*tcbufptr,1024,GLOBINIT);
  1345.     sw_file(tcbufptr,FALSE);
  1346.     safecpy(*tcbufptr,getenv("RNINIT"),1024);
  1347.     if (**tcbufptr) {
  1348.     if (**tcbufptr == '/') {
  1349.         sw_file(tcbufptr,TRUE);
  1350.     }
  1351.     else
  1352.         sw_list(*tcbufptr);
  1353.     }
  1354.  
  1355.     for (i = 1; i < argc; i++)
  1356.     decode_switch(argv[i]);
  1357. }
  1358.  
  1359. void
  1360. sw_file(tcbufptr,bleat)
  1361. char **tcbufptr;
  1362. bool bleat;
  1363. {
  1364.     int initfd = open(*tcbufptr,0);
  1365.     
  1366.     if (initfd >= 0) {
  1367.     fstat(initfd,&filestat);
  1368.     if (filestat.st_size > 1024)
  1369.         *tcbufptr = saferealloc(*tcbufptr,(MEM_SIZE)filestat.st_size);
  1370.     if (filestat.st_size) {
  1371.         read(initfd,*tcbufptr,(int)filestat.st_size);
  1372.         (*tcbufptr)[filestat.st_size-1] = '\0';
  1373.                 /* wipe out last newline */
  1374.         sw_list(*tcbufptr);
  1375.     }
  1376.     else
  1377.         **tcbufptr = '\0';
  1378.     close(initfd);
  1379.     }
  1380.     else {
  1381.     if (bleat)
  1382.         printf(cantopen,*tcbufptr) FLUSH;
  1383.     **tcbufptr = '\0';
  1384.     }
  1385. }
  1386.  
  1387. /* decode a list of space separated switches */
  1388.  
  1389. void
  1390. sw_list(swlist)
  1391. char *swlist;
  1392. {
  1393.     char *tmplist = safemalloc((MEM_SIZE) strlen(swlist) + 2);
  1394.                     /* semi-automatic string */
  1395.     register char *p, inquote = 0;
  1396.  
  1397.     strcpy(tmplist,swlist);
  1398.     for (p=tmplist; isspace(*p); p++) ;    /* skip any initial spaces */
  1399.     while (*p) {            /* "String, or nothing" */
  1400.     if (!inquote && isspace(*p)) {    /* word delimiter? */
  1401.         *p++ = '\0';        /* chop here */
  1402.         while (isspace(*p))        /* these will be ignored later */
  1403.         p++;
  1404.     }
  1405.     else if (inquote == *p) {
  1406.         strcpy(p,p+1);        /* delete trailing quote */
  1407.         inquote = 0;        /* no longer quoting */
  1408.     }
  1409.     else if (!inquote && *p == '"' || *p == '\'') {
  1410.                     /* OK, I know when I am not wanted */
  1411.         inquote = *p;        /* remember single or double */
  1412.         strcpy(p,p+1);        /* delete the quote */
  1413.     }                /* (crude, but effective) */
  1414.     else if (*p == '\\') {        /* quoted something? */
  1415.         if (p[1] == '\n')        /* newline? */
  1416.         strcpy(p,p+2);        /* "I didn't see anything" */
  1417.         else {
  1418.         strcpy(p,p+1);        /* delete the backwhack */
  1419.         p++;            /* leave the whatever alone */
  1420.         }
  1421.     }
  1422.     else
  1423.         p++;            /* normal char, leave it alone */
  1424.     }
  1425.     *++p = '\0';            /* put an extra null on the end */
  1426.     if (inquote)
  1427.     printf("Unmatched %c in switch\n",inquote) FLUSH;
  1428.     for (p = tmplist; *p; /* p += strlen(p)+1 */ ) {
  1429.     decode_switch(p);
  1430.     while (*p++) ;            /* point at null + 1 */
  1431.     }
  1432.     free(tmplist);            /* this oughta be in Ada */
  1433. }
  1434.  
  1435. /* decode a single switch */
  1436.  
  1437. void
  1438. decode_switch(s)
  1439. register char *s;
  1440. {
  1441.     while (isspace(*s))            /* ignore leading spaces */
  1442.     s++;
  1443. #ifdef DEBUGGING
  1444.     if (debug)
  1445.     printf("Switch: %s\n",s) FLUSH;
  1446. #endif
  1447.     if (*s != '-' && *s != '+') {    /* newsgroup pattern */
  1448.     setngtodo(s);
  1449.     }
  1450.     else {                /* normal switch */
  1451.     bool upordown = *s == '-' ? TRUE : FALSE;
  1452.     char tmpbuf[LBUFLEN];
  1453.  
  1454.     s++;
  1455.     switch (*s) {
  1456. #ifdef TERMMOD
  1457.     case '=': {
  1458.         char *beg = s+1;
  1459.  
  1460.         while (*s && *s != '-' && *s != '+') s++;
  1461.         cpytill(tmpbuf,beg,*s);
  1462.         if (upordown ? strEQ(getenv("TERM"),tmpbuf)
  1463.                  : strNE(getenv("TERM"),tmpbuf) ) {
  1464.         decode_switch(s);
  1465.         }
  1466.         break;
  1467.     }
  1468. #endif
  1469. #ifdef BAUDMOD
  1470.     case '0': case '1': case '2': case '3': case '4':
  1471.     case '5': case '6': case '7': case '8': case '9':
  1472.         if (upordown ? (just_a_sec*10 <= atoi(s))
  1473.                  : (just_a_sec*10 >= atoi(s)) ) {
  1474.         while (isdigit(*s)) s++;
  1475.         decode_switch(s);
  1476.         }
  1477.         break;
  1478. #endif
  1479.     case '/':
  1480.         if (checkflag)
  1481.         break;
  1482. #ifdef SETENV
  1483.         setenv("SAVEDIR",  upordown ? "%p/%c" : "%p" );
  1484.         setenv("SAVENAME", upordown ? "%a"    : "%^C");
  1485. #else
  1486.         notincl("-/");
  1487. #endif
  1488.         break;
  1489.     case 'c':
  1490.         checkflag = upordown;
  1491.         break;
  1492.     case 'C':
  1493.         s++;
  1494.         if (*s == '=') s++;
  1495.         docheckwhen = atoi(s);
  1496.         break;
  1497.     case 'd': {
  1498.         if (checkflag)
  1499.         break;
  1500.         s++;
  1501.         if (*s == '=') s++;
  1502.         if (cwd) {
  1503.         chdir(cwd);
  1504.         free(cwd);
  1505.         }
  1506.         cwd = savestr(s);
  1507.         break;
  1508.     }
  1509. #ifdef DEBUGGING
  1510.     case 'D':
  1511.         s++;
  1512.         if (*s == '=') s++;
  1513.         if (*s)
  1514.         if (upordown)
  1515.             debug |= atoi(s);
  1516.         else
  1517.             debug &= ~atoi(s);
  1518.         else
  1519.         if (upordown)
  1520.             debug |= 1;
  1521.         else
  1522.             debug = 0;
  1523.         break;
  1524. #endif
  1525.     case 'e':
  1526.         erase_screen = upordown;
  1527.         break;
  1528.     case 'E':
  1529. #ifdef SETENV
  1530.         s++;
  1531.         if (*s == '=')
  1532.         s++;
  1533.         strcpy(tmpbuf,s);
  1534.         s = index(tmpbuf,'=');
  1535.         if (s) {
  1536.         *s++ = '\0';
  1537.         setenv(tmpbuf,s);
  1538.         }
  1539.         else
  1540.         setenv(tmpbuf,nullstr);
  1541. #else
  1542.         notincl("-E");
  1543. #endif
  1544.         break;
  1545.     case 'F':
  1546.         s++;
  1547.         indstr = savestr(s);
  1548.         break;
  1549. #ifdef INNERSEARCH
  1550.     case 'g':
  1551.         gline = atoi(s+1)-1;
  1552.         break;
  1553. #endif
  1554.     case 'H':
  1555.     case 'h': {
  1556.         register int len, i;
  1557.         char *t;
  1558.         int flag = (*s == 'h' ? HT_HIDE : HT_MAGIC);
  1559.         
  1560.         if (checkflag)
  1561.         break;
  1562.         s++;
  1563.         len = strlen(s);
  1564.         for (t=s; *t; t++)
  1565.         if (isupper(*t))
  1566.            *t = tolower(*t);
  1567.         for (i=HEAD_FIRST; i<HEAD_LAST; i++)
  1568.         if (!len || strnEQ(s,htype[i].ht_name,len))
  1569.             if (upordown)
  1570.             htype[i].ht_flags |= flag;
  1571.             else
  1572.             htype[i].ht_flags &= ~flag;
  1573.         break;
  1574.     }
  1575.     case 'i':
  1576.         s++;
  1577.         if (*s == '=') s++;
  1578.         initlines = atoi(s);
  1579.         initlines_specified = TRUE;
  1580.         break;
  1581.     case 'l':
  1582.         muck_up_clear = upordown;
  1583.         break;
  1584.     case 'L':
  1585. #ifdef CLEAREOL
  1586.         can_home_clear = upordown;
  1587. #else
  1588.         notincl("-L");
  1589. #endif
  1590.         break;
  1591.     case 'M':
  1592.         mbox_always = upordown;
  1593.         break;
  1594.     case 'm':
  1595.         s++;
  1596.         if (*s == '=') s++;
  1597.         if (!upordown)
  1598.         marking = NOMARKING;
  1599.         else if (*s == 'u')
  1600.         marking = UNDERLINE;
  1601.         else {
  1602.         marking = STANDOUT;
  1603.         }
  1604.         break;
  1605.     case 'N':
  1606.         norm_always = upordown;
  1607.         break;
  1608. #ifdef VERBOSE
  1609.     case 'n':
  1610.         fputs("This isn't readnews.  Don't use -n.\n\n",stdout) FLUSH;
  1611.         break;
  1612. #endif
  1613.     case 'r':
  1614.         findlast = upordown;
  1615.         break;
  1616.     case 's':
  1617.         s++;
  1618.         if (*s == '=') s++;
  1619.         if (*s) {
  1620.         countdown = atoi(s);
  1621.         suppress_cn = FALSE;
  1622.         }
  1623.         else {
  1624.         if (!upordown)
  1625.             countdown = 5;
  1626.         suppress_cn = upordown;
  1627.         }
  1628.         break;
  1629.     case 'S':
  1630. #ifdef ARTSEARCH
  1631.         s++;
  1632.         if (*s == '=') s++;
  1633.         if (*s)
  1634.         scanon = atoi(s);
  1635.         else
  1636.         scanon = upordown*3;
  1637. #else
  1638.         notincl("-S");
  1639. #endif
  1640.         break;
  1641.     case 't':
  1642. #ifdef VERBOSE
  1643. #ifdef TERSE
  1644.         verbose = !upordown;
  1645. #else
  1646.         notincl("+t");
  1647. #endif
  1648. #else
  1649.         notincl("+t");
  1650. #endif
  1651.         break;
  1652.     case 'T':
  1653.         typeahead = upordown;
  1654.         break;
  1655.     case 'v':
  1656. #ifdef VERIFY
  1657.         verify = upordown;
  1658. #else
  1659.         notincl("-v");
  1660. #endif
  1661.         break;
  1662.     /*
  1663.      * People want a way to avoid checking for new newsgroups on startup.
  1664.      */
  1665.     case 'q':
  1666.         quickstart = upordown;
  1667.         break;
  1668.     default:
  1669. #ifdef VERBOSE
  1670.         IF(verbose)
  1671.         printf("\nIgnoring unrecognized switch: -%c\n", *s) FLUSH;
  1672.         ELSE
  1673. #endif
  1674. #ifdef TERSE
  1675.         printf("\nIgnoring -%c\n", *s) FLUSH;
  1676. #endif
  1677.         break;
  1678.     }
  1679.     }
  1680. }
  1681.  
  1682. /* print current switch values */
  1683.  
  1684. void
  1685. pr_switches()
  1686. {
  1687.     static char mp[2] = {'+','-'};
  1688.     register int i;
  1689.     
  1690.     fputs("\nCurrent switch settings:\n",stdout);
  1691.     printf("%c/ ", mp[strEQ(getval("SAVEDIR",SAVEDIR),"%p/%c")]);
  1692.     printf("%cc ", mp[checkflag]);
  1693.     printf("-C%d ", docheckwhen);
  1694.     printf("-d%s ", cwd);
  1695. #ifdef DEBUGGING
  1696.     if (debug)
  1697.     printf("-D%d ", debug);
  1698. #endif
  1699.     printf("%ce ", mp[erase_screen]);
  1700.     printf("-F\"%s\" ", indstr);
  1701. #ifdef INNERSEARCH
  1702.     printf("-g%d", gline);
  1703. #endif
  1704.     putchar('\n');
  1705. #ifdef VERBOSE
  1706.     if (verbose) {
  1707.     for (i=HEAD_FIRST; i<HEAD_LAST; i++)
  1708.         printf("%ch%s%c",
  1709.         mp[htype[i].ht_flags & HT_HIDE], htype[i].ht_name,
  1710.         (! (i % 5) ? '\n' : ' ') );
  1711.     }
  1712. #endif
  1713.     printf("-i%d ", initlines);
  1714.     printf("%cl ", mp[muck_up_clear]);
  1715. #ifdef CLEAREOL
  1716.     printf("%cL ", mp[can_home_clear]);
  1717. #endif CLEAREOL
  1718.     if (marking)
  1719.     printf("-m%c ",marking==UNDERLINE?'u':'s');
  1720.     else
  1721.     printf("+m ");
  1722.     printf("%cM ", mp[mbox_always]);
  1723.     printf("%cN ", mp[norm_always]);
  1724.     printf("%cr ", mp[findlast]);
  1725.     if (countdown)
  1726.     printf("-s%d ", countdown);
  1727.     else
  1728.     printf("%cs ", mp[suppress_cn]);
  1729. #ifdef ARTSEARCH
  1730.     if (scanon)
  1731.     printf("-S%d ",scanon);
  1732.     else
  1733.     printf("+S ");
  1734. #endif
  1735. #ifdef VERBOSE
  1736. #ifdef TERSE
  1737.     printf("%ct ", mp[!verbose]);
  1738. #endif
  1739. #endif
  1740.     printf("%cT ", mp[typeahead]);
  1741. #ifdef VERIFY
  1742.     printf("%cv ", mp[verify]);
  1743. #endif
  1744.     fputs("\n\n",stdout) FLUSH;
  1745. #ifdef ONLY
  1746.     if (maxngtodo) {
  1747. #ifdef VERBOSE
  1748.     IF(verbose)
  1749.         fputs("Current restriction:",stdout);
  1750.     ELSE
  1751. #endif
  1752. #ifdef TERSE
  1753.         fputs("Only:",stdout);
  1754. #endif
  1755.     for (i=0; i<maxngtodo; i++)
  1756.         printf(" %s",ngtodo[i]);
  1757.     fputs("\n\n",stdout) FLUSH;
  1758.     }
  1759. #ifdef VERBOSE
  1760.     else if (verbose)
  1761.     fputs("No restriction.\n\n",stdout) FLUSH;
  1762. #endif
  1763. #endif
  1764. }
  1765.  
  1766. void
  1767. cwd_check()
  1768. {
  1769.     char tmpbuf[LBUFLEN];
  1770.  
  1771.     if (!cwd)
  1772.     cwd = savestr(filexp("~/News"));
  1773.     strcpy(tmpbuf,cwd);
  1774.     if (chdir(cwd)) {
  1775.     safecpy(tmpbuf,filexp(cwd),sizeof tmpbuf);
  1776.     if (makedir(tmpbuf,MD_DIR) < 0 || chdir(tmpbuf) < 0) {
  1777.         interp(cmd_buf, (sizeof cmd_buf), "%~/News");
  1778.         if (makedir(cmd_buf,MD_DIR) < 0)
  1779.         strcpy(tmpbuf,homedir);
  1780.         else
  1781.         strcpy(tmpbuf,cmd_buf);
  1782.         chdir(tmpbuf);
  1783. #ifdef VERBOSE
  1784.         IF(verbose)
  1785.         printf("\
  1786. Cannot make directory %s--\n\
  1787.     articles will be saved to %s\n\
  1788. \n\
  1789. ",cwd,tmpbuf) FLUSH;
  1790.         ELSE
  1791. #endif
  1792. #ifdef TERSE
  1793.         printf("\
  1794. Can't make %s--\n\
  1795.     using %s\n\
  1796. \n\
  1797. ",cwd,tmpbuf) FLUSH;
  1798. #endif
  1799.     }
  1800.     }
  1801.     free(cwd);
  1802.     getwd(tmpbuf);
  1803.     if (eaccess(tmpbuf,2)) {
  1804. #ifdef VERBOSE
  1805.     IF(verbose)
  1806.         printf("\
  1807. Current directory %s is not writeable--\n\
  1808.     articles will be saved to home directory\n\n\
  1809. ",tmpbuf) FLUSH;
  1810.     ELSE
  1811. #endif
  1812. #ifdef TERSE
  1813.         printf("%s not writeable--using ~\n\n",tmpbuf) FLUSH;
  1814. #endif
  1815.     strcpy(tmpbuf,homedir);
  1816.     }
  1817.     cwd = savestr(tmpbuf);
  1818. }
  1819. !STUFFY!FUNK!
  1820. echo Extracting respond.c
  1821. cat >respond.c <<'!STUFFY!FUNK!'
  1822. /* $Header: respond.c,v 4.3.2.3 90/03/22 23:05:19 sob Exp $
  1823.  *
  1824.  * $Log:    respond.c,v $
  1825.  * Revision 4.3.2.3  90/03/22  23:05:19  sob
  1826.  * Fixes provided by Wayne Davison <drivax!davison>
  1827.  * 
  1828.  * Revision 4.3.2.2  89/11/26  18:25:10  sob
  1829.  * Enlarged the size of the header buffer to accomodate long references lines.
  1830.  * Fix provided by Joe Buck.
  1831.  * 
  1832.  * Revision 4.3.2.1  89/11/06  01:00:26  sob
  1833.  * Added RRN support from NNTP 1.5
  1834.  * 
  1835.  * Revision 4.3.1.5  85/09/10  11:05:00  lwall
  1836.  * Improved %m in in_char().
  1837.  * 
  1838.  * Revision 4.3.1.4  85/05/23  17:24:49  lwall
  1839.  * Now allows 'r' and 'f' on null articles.
  1840.  * 
  1841.  * Revision 4.3.1.3  85/05/15  14:42:32  lwall
  1842.  * Removed duplicate include of intrp.h.
  1843.  * 
  1844.  * Revision 4.3.1.2  85/05/14  08:55:15  lwall
  1845.  * Default for normal/mailbox question was applied to wrong buffer.
  1846.  * 
  1847.  * Revision 4.3.1.1  85/05/10  11:37:33  lwall
  1848.  * Branch for patches.
  1849.  * 
  1850.  * Revision 4.3  85/05/01  11:47:04  lwall
  1851.  * Baseline for release with 4.3bsd.
  1852.  * 
  1853.  */
  1854.  
  1855. #include "EXTERN.h"
  1856. #include "common.h"
  1857. #include "intrp.h"
  1858. #include "head.h"
  1859. #include "term.h"
  1860. #include "ng.h"
  1861. #include "util.h"
  1862. #include "rn.h"
  1863. #include "artio.h"
  1864. #include "final.h"
  1865. #include "INTERN.h"
  1866. #include "respond.h"
  1867.  
  1868. static char nullart[] = "\nNull article\n";
  1869.  
  1870. void
  1871. respond_init()
  1872. {
  1873.     ;
  1874. }
  1875.  
  1876. int
  1877. save_article()
  1878. {
  1879.     bool use_pref;
  1880.     register char *s, *c;
  1881.     char altbuf[CBUFLEN];
  1882.     int iter;
  1883.     bool interactive = (buf[1] == FINISHCMD);
  1884.     
  1885.     if (!finish_command(interactive))    /* get rest of command */
  1886.     return SAVE_ABORT;
  1887.     use_pref = isupper(*buf);
  1888. #ifdef ASYNC_PARSE
  1889.     parse_maybe(art);
  1890. #endif
  1891.     savefrom = (*buf=='w' || *buf=='W' ? htype[PAST_HEADER].ht_minpos : 0);
  1892.     if (artopen(art) == Nullfp) {
  1893. #ifdef VERBOSE
  1894.     IF(verbose)
  1895.         fputs("\n\
  1896. Saving null articles is not very productive!  :-)\n\
  1897. ",stdout) FLUSH;
  1898.     ELSE
  1899. #endif
  1900. #ifdef TERSE
  1901.         fputs(nullart,stdout) FLUSH;
  1902. #endif
  1903.     return SAVE_DONE;
  1904.     }
  1905.     if (chdir(cwd)) {
  1906.     printf(nocd,cwd) FLUSH;
  1907.     sig_catcher(0);
  1908.     }
  1909.     if (savedest)
  1910.     free(savedest);
  1911.     if ((s = index(buf,'|')) != Nullch) {
  1912.                 /* is it a pipe command? */
  1913.     s++;            /* skip the | */
  1914.     while (*s == ' ') s++;
  1915.     safecpy(altbuf,filexp(s),sizeof altbuf);
  1916.     savedest = altbuf;
  1917.     interp(cmd_buf, (sizeof cmd_buf), getval("PIPESAVER",PIPESAVER));
  1918.                 /* then set up for command */
  1919.     resetty();        /* restore tty state */
  1920.     if (use_pref)        /* use preferred shell? */
  1921.         doshell(Nullch,cmd_buf);
  1922.                 /* do command with it */
  1923.     else
  1924.         doshell(sh,cmd_buf);    /* do command with sh */
  1925.     noecho();        /* and stop echoing */
  1926.     crmode();        /* and start cbreaking */
  1927.     savedest = savestr(savedest);
  1928.     }
  1929.     else {            /* normal save */
  1930.     bool there, mailbox;
  1931.     char *savename = getval("SAVENAME",SAVENAME);
  1932.  
  1933.     s = buf+1;        /* skip s or S */
  1934.     if (*s == '-') {    /* if they are confused, skip - also */
  1935. #ifdef VERBOSE
  1936.         IF(verbose)
  1937.         fputs("Warning: '-' ignored.  This isn't readnews.\n",stdout)
  1938.           FLUSH;
  1939.         ELSE
  1940. #endif
  1941. #ifdef TERSE
  1942.         fputs("'-' ignored.\n",stdout) FLUSH;
  1943. #endif
  1944.         s++;
  1945.     }
  1946.     for (; *s == ' '; s++);    /* skip spaces */
  1947.     safecpy(altbuf,filexp(s),sizeof altbuf);
  1948.     s = altbuf;
  1949.     if (! index(s,'/')) {
  1950.         interp(buf, (sizeof buf), getval("SAVEDIR",SAVEDIR));
  1951.         if (makedir(buf,MD_DIR))    /* ensure directory exists */
  1952.         strcpy(buf,cwd);
  1953.         if (*s) {
  1954.         for (c = buf; *c; c++) ;
  1955.         *c++ = '/';
  1956.         strcpy(c,s);        /* add filename */
  1957.         }
  1958.         s = buf;
  1959.     }
  1960.     for (iter = 0;
  1961.         (there = stat(s,&filestat) >= 0) &&
  1962.         (filestat.st_mode & S_IFDIR);
  1963.         iter++) {            /* is it a directory? */
  1964.  
  1965.         c = (s+strlen(s));
  1966.         *c++ = '/';            /* put a slash before filename */
  1967.         interp(c, s==buf?(sizeof buf):(sizeof altbuf),
  1968.         iter ? "News" : savename );
  1969.                 /* generate a default name somehow or other */
  1970.         if (index(c,'/')) {        /* yikes, a '/' in the filename */
  1971.         makedir(s,MD_FILE);
  1972.         }
  1973.     }
  1974.     if (*s != '/') {        /* relative path? */
  1975.         c = (s==buf ? altbuf : buf);
  1976.         sprintf(c, "%s/%s", cwd, s);
  1977.         s = c;            /* absolutize it */
  1978.     }
  1979.     s = savedest = savestr(s);    /* doesn't move any more */
  1980.                     /* make it handy for %b */
  1981.     if (!there) {
  1982.         if (mbox_always)
  1983.         mailbox = TRUE;
  1984.         else if (norm_always)
  1985.         mailbox = FALSE;
  1986.         else {
  1987.         char *dflt = (instr(savename,"%a") ? "nyq" : "ynq");
  1988.         
  1989.         sprintf(cmd_buf,
  1990.         "\nFile %s doesn't exist--\n    use mailbox format? [%s] ",
  1991.           s,dflt);
  1992.           reask_save:
  1993.         in_char(cmd_buf, 'M');
  1994.         putchar('\n') FLUSH;
  1995.         setdef(buf,dflt);
  1996. #ifdef VERIFY
  1997.         printcmd();
  1998. #endif
  1999.         if (*buf == 'h') {
  2000. #ifdef VERBOSE
  2001.             IF(verbose)
  2002.             printf("\n\
  2003. Type y to create %s as a mailbox.\n\
  2004. Type n to create it as a normal file.\n\
  2005. Type q to abort the save.\n\
  2006. ",s) FLUSH;
  2007.             ELSE
  2008. #endif
  2009. #ifdef TERSE
  2010.             fputs("\n\
  2011. y to create mailbox.\n\
  2012. n to create normal file.\n\
  2013. q to abort.\n\
  2014. ",stdout) FLUSH;
  2015. #endif
  2016.             goto reask_save;
  2017.         }
  2018.         else if (*buf == 'n') {
  2019.             mailbox = FALSE;
  2020.         }
  2021.         else if (*buf == 'y') {
  2022.             mailbox = TRUE;
  2023.         }
  2024.         else if (*buf == 'q') {
  2025.             goto s_bomb;
  2026.         }
  2027.         else {
  2028.             fputs(hforhelp,stdout) FLUSH;
  2029.             settle_down();
  2030.             goto reask_save;
  2031.         }
  2032.         }
  2033.     }
  2034.     else if (filestat.st_mode & S_IFCHR)
  2035.         mailbox = FALSE;
  2036.     else {
  2037.         int tmpfd;
  2038.         
  2039.         tmpfd = open(s,0);
  2040.         if (tmpfd == -1)
  2041.         mailbox = FALSE;
  2042.         else {
  2043.         read(tmpfd,buf,LBUFLEN);
  2044.         c = buf;
  2045.         if (!isspace(MBOXCHAR))
  2046.             while (isspace(*c))
  2047.             c++;
  2048.         mailbox = (*c == MBOXCHAR);
  2049.         close(tmpfd);
  2050.         }
  2051.     }
  2052.  
  2053.     safecpy(cmd_buf, filexp(mailbox ?
  2054.         getval("MBOXSAVER",MBOXSAVER) :
  2055.         getval("NORMSAVER",NORMSAVER) ), sizeof cmd_buf);
  2056.                 /* format the command */
  2057.     resetty();        /* make terminal behave */
  2058.     if (doshell(use_pref?Nullch:SH,cmd_buf))
  2059.         fputs("Not saved",stdout);
  2060.     else
  2061.         printf("%s to %s %s",
  2062.           there?"Appended":"Saved",
  2063.           mailbox?"mailbox":"file",
  2064.           s);
  2065.     if (interactive)
  2066.         putchar('\n') FLUSH;
  2067.     noecho();        /* make terminal do what we want */
  2068.     crmode();
  2069.     }
  2070. s_bomb:
  2071. #ifdef SERVER
  2072.     if (chdir(spool)) {
  2073. #else not SERVER
  2074.     if (chdir(spool) || chdir(ngdir)) {
  2075. #endif SERVER
  2076.     printf(nocd,ngdir) FLUSH;
  2077.     sig_catcher(0);
  2078.     }
  2079.     return SAVE_DONE;
  2080. }
  2081.  
  2082. int
  2083. cancel_article()
  2084. {
  2085.     char *artid_buf;
  2086.     char *ngs_buf;
  2087.     char *from_buf;
  2088.     char *reply_buf;
  2089.     int myuid = getuid();
  2090.     int r = -1;
  2091.  
  2092.     if (artopen(art) == Nullfp) {
  2093. #ifdef VERBOSE
  2094.     IF(verbose)
  2095.         fputs("\n\
  2096. Cancelling null articles is your idea of fun?  :-)\n\
  2097. ",stdout) FLUSH;
  2098.     ELSE
  2099. #endif
  2100. #ifdef TERSE
  2101.         fputs(nullart,stdout) FLUSH;
  2102. #endif
  2103.     return r;
  2104.     }
  2105.     reply_buf = fetchlines(art,REPLY_LINE);
  2106.     from_buf = fetchlines(art,FROM_LINE);
  2107.     artid_buf = fetchlines(art,ARTID_LINE);
  2108.     ngs_buf = fetchlines(art,NGS_LINE);
  2109.     if (!instr(from_buf,sitename) ||
  2110.     (!instr(from_buf,logname) &&
  2111.      !instr(reply_buf,logname) &&
  2112. #ifdef NEWSADMIN
  2113.      myuid != newsuid &&
  2114. #endif
  2115.      myuid != ROOTID ) )
  2116. #ifdef VERBOSE
  2117.         IF(verbose)
  2118.         fputs("\nYou can't cancel someone else's article\n",stdout)
  2119.           FLUSH;
  2120.         ELSE
  2121. #endif
  2122. #ifdef TERSE
  2123.         fputs("\nNot your article\n",stdout) FLUSH;
  2124. #endif
  2125.     else {
  2126.     tmpfp = fopen(headname,"w");    /* open header file */
  2127.     if (tmpfp == Nullfp) {
  2128.         printf(cantcreate,headname) FLUSH;
  2129.         goto no_cancel;
  2130.     }
  2131.     interp(buf, (sizeof buf), getval("CANCELHEADER",CANCELHEADER));
  2132.     fputs(buf,tmpfp);
  2133.     fclose(tmpfp);
  2134.     fputs("\nCanceling...\n",stdout) FLUSH;
  2135.     r = doshell(sh,filexp(getval("CANCEL",CANCEL)));
  2136.     }
  2137. no_cancel:
  2138.     free(artid_buf);
  2139.     free(ngs_buf);
  2140.     free(from_buf);
  2141.     free(reply_buf);
  2142.     return r;
  2143. }
  2144.  
  2145. void
  2146. reply()
  2147. {
  2148.     bool incl_body = (*buf == 'R');
  2149.     char *maildoer = savestr(filexp(getval("MAILPOSTER",MAILPOSTER)));
  2150.  
  2151.     artopen(art);
  2152.     tmpfp = fopen(headname,"w");    /* open header file */
  2153.     if (tmpfp == Nullfp) {
  2154.     printf(cantcreate,headname) FLUSH;
  2155.     goto no_reply;
  2156.     }
  2157.     interp(buf, (sizeof buf), getval("MAILHEADER",MAILHEADER));
  2158.     fputs(buf,tmpfp);
  2159.     if (!instr(maildoer,"%h"))
  2160. #ifdef VERBOSE
  2161.     IF(verbose)
  2162.         printf("\n%s\n(Above lines saved in file %s)\n",buf,headname)
  2163.           FLUSH;
  2164.     ELSE
  2165. #endif
  2166. #ifdef TERSE
  2167.         printf("\n%s\n(Header in %s)\n",buf,headname) FLUSH;
  2168. #endif
  2169.     if (incl_body && artfp != Nullfp) {
  2170.     interp(buf, (sizeof buf), getval("YOUSAID",YOUSAID));
  2171.     fprintf(tmpfp,"%s\n",buf);
  2172. #ifdef ASYNC_PARSE
  2173.     parse_maybe(art);
  2174. #endif
  2175.     fseek(artfp,(long)htype[PAST_HEADER].ht_minpos,0);
  2176.     while (fgets(buf,LBUFLEN,artfp) != Nullch) {
  2177.         fprintf(tmpfp,"%s%s",indstr,buf);
  2178.     }
  2179.     fprintf(tmpfp,"\n");
  2180.     }
  2181.     fclose(tmpfp);
  2182.     interp(cmd_buf, (sizeof cmd_buf), maildoer);
  2183.     invoke(cmd_buf,origdir);
  2184.     UNLINK(headname);        /* kill the header file */
  2185. no_reply:
  2186.     free(maildoer);
  2187. }
  2188.  
  2189. void
  2190. followup()
  2191. {
  2192.     bool incl_body = (*buf == 'F');
  2193.     char hbuf[4*LBUFLEN];    /* four times the old size */
  2194.  
  2195.     artopen(art);
  2196.     tmpfp = fopen(headname,"w");
  2197.     if (tmpfp == Nullfp) {
  2198.     printf(cantcreate,headname) FLUSH;
  2199.     return;
  2200.     }
  2201.     interp(hbuf, (sizeof hbuf), getval("NEWSHEADER",NEWSHEADER));
  2202.     fprintf(tmpfp,"%s",hbuf);
  2203.     if (incl_body && artfp != Nullfp) {
  2204. #ifdef VERBOSE
  2205.     if (verbose)
  2206.         fputs("\n\
  2207. (Be sure to double-check the attribution against the signature, and\n\
  2208. trim the quoted article down as much as possible.)\n\
  2209. ",stdout) FLUSH;
  2210. #endif
  2211.     interp(buf, (sizeof buf), getval("ATTRIBUTION",ATTRIBUTION));
  2212.     fprintf(tmpfp,"%s\n",buf);
  2213. #ifdef ASYNC_PARSE
  2214.     parse_maybe(art);
  2215. #endif
  2216.     fseek(artfp,(long)htype[PAST_HEADER].ht_minpos,0);
  2217.     while (fgets(buf,LBUFLEN,artfp) != Nullch) {
  2218.         fprintf(tmpfp,"%s%s",indstr,buf);
  2219.     }
  2220.     fprintf(tmpfp,"\n");
  2221.     }
  2222.     fclose(tmpfp);
  2223.     safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),sizeof cmd_buf);
  2224.     invoke(cmd_buf,origdir);
  2225.     UNLINK(headname);
  2226. }
  2227.  
  2228. void
  2229. invoke(cmd,dir)
  2230. char *cmd,*dir;
  2231. {
  2232.     if (chdir(dir)) {
  2233.     printf(nocd,dir) FLUSH;
  2234.     return;
  2235.     }
  2236. #ifdef VERBOSE
  2237.     IF(verbose)
  2238.     printf("\n(leaving cbreak mode; cwd=%s)\nInvoking command: %s\n\n",
  2239.         dir,cmd) FLUSH;
  2240.     ELSE
  2241. #endif
  2242. #ifdef TERSE
  2243.     printf("\n(-cbreak; cwd=%s)\nInvoking: %s\n\n",dir,cmd) FLUSH;
  2244. #endif
  2245.     resetty();            /* make terminal well-behaved */
  2246.     doshell(sh,cmd);        /* do the command */
  2247.     noecho();            /* set no echo */
  2248.     crmode();            /* and cbreak mode */
  2249. #ifdef VERBOSE
  2250.     IF(verbose)
  2251.     fputs("\n(re-entering cbreak mode)\n",stdout) FLUSH;
  2252.     ELSE
  2253. #endif
  2254. #ifdef TERSE
  2255.     fputs("\n(+cbreak)\n",stdout) FLUSH;
  2256. #endif
  2257. #ifdef SERVER
  2258.     if (chdir(spool)) {
  2259. #else not SERVER
  2260.     if (chdir(spool) || chdir(ngdir)) {
  2261. #endif SERVER
  2262.     printf(nocd,ngdir) FLUSH;
  2263.     sig_catcher(0);
  2264.     }
  2265. }
  2266.  
  2267. !STUFFY!FUNK!
  2268. echo Extracting util.c
  2269. cat >util.c <<'!STUFFY!FUNK!'
  2270. /* $Header: util.c,v 4.3.2.6 90/04/23 00:24:42 sob Exp $
  2271.  *
  2272.  * $Log:    util.c,v $
  2273.  * Revision 4.3.2.6  90/04/23  00:24:42  sob
  2274.  * A bit of clean up.
  2275.  * 
  2276.  * Revision 4.3.2.5  90/03/17  21:34:21  sob
  2277.  * Reworked VOIDSIG into SIGRET.
  2278.  * 
  2279.  * Revision 4.3.2.4  89/12/14  23:58:54  sob
  2280.  * Fixed small bug reported by fletcher@cs.utexas.edu in getwd().
  2281.  * 
  2282.  * Revision 4.3.2.3  89/11/08  04:47:11  sob
  2283.  * Added VOIDSIG handling for SunOS 4.X
  2284.  * 
  2285.  * Revision 4.3.2.2  89/11/07  23:19:35  sob
  2286.  * Bug fixes for SIGSTP problems
  2287.  * 
  2288.  * Revision 4.3.2.1  89/11/06  01:03:21  sob
  2289.  * Added RRN support from NNTP 1.5
  2290.  * 
  2291.  * Revision 4.3.1.2  85/05/15  14:44:27  lwall
  2292.  * Last arg of execl changed from 0 to Nullch [(char*)0].
  2293.  * 
  2294.  * Revision 4.3.1.1  85/05/10  11:41:30  lwall
  2295.  * Branch for patches.
  2296.  * 
  2297.  * Revision 4.3  85/05/01  11:51:44  lwall
  2298.  * Baseline for release with 4.3bsd.
  2299.  * 
  2300.  */
  2301.  
  2302. #include "EXTERN.h"
  2303. #include "common.h"
  2304. #include "final.h"
  2305. #include "ndir.h"
  2306. #include "INTERN.h"
  2307. #include "util.h"
  2308.  
  2309. void
  2310. util_init()
  2311. {
  2312.     ;
  2313. }
  2314.     
  2315. /* fork and exec a shell command */
  2316.  
  2317. int
  2318. doshell(shl,s)
  2319. char *s, *shl;
  2320. {
  2321.     int status, pid, w;
  2322.     SIGRET (*signal())();
  2323.     char *shell;
  2324.  
  2325. #ifdef SIGTSTP
  2326.     sigset(SIGTSTP,SIG_DFL);
  2327.     sigset(SIGTTOU,SIG_DFL);
  2328.     sigset(SIGTTIN,SIG_DFL);
  2329. #endif
  2330.     if (shl != Nullch)
  2331.     shell = shl;
  2332.     else if ((shell = getenv("SHELL")) == Nullch || !*shell)
  2333.     shell = PREFSHELL;
  2334.     if ((pid = vfork()) == 0) {
  2335. #ifdef SERVER
  2336.         int i;
  2337.  
  2338.     /* This is necessary to keep bourne shell from puking */
  2339.  
  2340.         for (i = 3; i < 10; ++i)
  2341.                 close(i);
  2342. #endif SERVER
  2343.  
  2344.     if (*s)
  2345.         execl(shell, shell, "-c", s, Nullch);
  2346.     else
  2347.         execl(shell, shell, Nullch, Nullch, Nullch);
  2348.     _exit(127);
  2349.     }
  2350.     signal(SIGINT, SIG_IGN);
  2351.     signal(SIGQUIT, SIG_IGN);
  2352.     waiting = TRUE;
  2353.     while ((w = wait(&status)) != pid && w != -1)
  2354.     ;
  2355.     if (w == -1)
  2356.     status = -1;
  2357.     waiting = FALSE;
  2358.     sigset(SIGINT, int_catcher);    /* always catch interrupts */
  2359.     signal(SIGQUIT, SIG_DFL);
  2360. #ifdef SIGTSTP
  2361.     sigset(SIGTSTP,stop_catcher);
  2362.     sigset(SIGTTOU,stop_catcher);
  2363.     sigset(SIGTTIN,stop_catcher);
  2364. #endif
  2365.     return status;
  2366. }
  2367.  
  2368. static char nomem[] = "rn: out of memory!\n";
  2369.  
  2370. /* paranoid version of malloc */
  2371.  
  2372. char *
  2373. safemalloc(size)
  2374. MEM_SIZE size;
  2375. {
  2376.     char *ptr;
  2377.     char *malloc();
  2378.  
  2379.     ptr = malloc(size?size:1);    /* malloc(0) is NASTY on our system */
  2380.     if (ptr != Nullch)
  2381.     return ptr;
  2382.     else {
  2383.     fputs(nomem,stdout) FLUSH;
  2384.     sig_catcher(0);
  2385.     }
  2386.     /*NOTREACHED*/
  2387. }
  2388.  
  2389. /* paranoid version of realloc */
  2390.  
  2391. char *
  2392. saferealloc(where,size)
  2393. char *where;
  2394. MEM_SIZE size;
  2395. {
  2396.     char *ptr;
  2397.     char *realloc();
  2398.  
  2399.     ptr = realloc(where,size?size:1);    /* realloc(0) is NASTY on our system */
  2400.     if (ptr != Nullch)
  2401.     return ptr;
  2402.     else {
  2403.     fputs(nomem,stdout) FLUSH;
  2404.     sig_catcher(0);
  2405.     }
  2406.     /*NOTREACHED*/
  2407. }
  2408.  
  2409. /* safe version of string copy */
  2410.  
  2411. char *
  2412. safecpy(to,from,len)
  2413. char *to;
  2414. register char *from;
  2415. register int len;
  2416. {
  2417.     register char *dest = to;
  2418.  
  2419.     if (from != Nullch) 
  2420.     for (len--; len && (*dest++ = *from++); len--) ;
  2421.     *dest = '\0';
  2422.     return to;
  2423. }
  2424.  
  2425. /* safe version of string concatenate, with \n deletion and space padding */
  2426.  
  2427. char *
  2428. safecat(to,from,len)
  2429. char *to;
  2430. register char *from;
  2431. register int len;
  2432. {
  2433.     register char *dest = to;
  2434.  
  2435.     len--;                /* leave room for null */
  2436.     if (*dest) {
  2437.     while (len && *dest++) len--;
  2438.     if (len) {
  2439.         len--;
  2440.         *(dest-1) = ' ';
  2441.     }
  2442.     }
  2443.     if (from != Nullch)
  2444.     while (len && (*dest++ = *from++)) len--;
  2445.     if (len)
  2446.     dest--;
  2447.     if (*(dest-1) == '\n')
  2448.     dest--;
  2449.     *dest = '\0';
  2450.     return to;
  2451. }
  2452.  
  2453. /* copy a string up to some (non-backslashed) delimiter, if any */
  2454.  
  2455. char *
  2456. cpytill(to,from,delim)
  2457. register char *to, *from;
  2458. register int delim;
  2459. {
  2460.     for (; *from; from++,to++) {
  2461.     if (*from == '\\' && from[1] == delim)
  2462.         from++;
  2463.     else if (*from == delim)
  2464.         break;
  2465.     *to = *from;
  2466.     }
  2467.     *to = '\0';
  2468.     return from;
  2469. }
  2470.  
  2471. /* return ptr to little string in big string, NULL if not found */
  2472.  
  2473. char *
  2474. instr(big, little)
  2475. char *big, *little;
  2476.  
  2477. {
  2478.     register char *t, *s, *x;
  2479.  
  2480.     for (t = big; *t; t++) {
  2481.     for (x=t,s=little; *s; x++,s++) {
  2482.         if (!*x)
  2483.         return Nullch;
  2484.         if (*s != *x)
  2485.         break;
  2486.     }
  2487.     if (!*s)
  2488.         return t;
  2489.     }
  2490.     return Nullch;
  2491. }
  2492.  
  2493. /* effective access */
  2494.  
  2495. #ifdef SETUIDGID
  2496. int
  2497. eaccess(filename, mod)
  2498. char *filename;
  2499. int mod;
  2500. {
  2501.     int protection, euid;
  2502.     
  2503.     mod &= 7;                /* remove extraneous garbage */
  2504.     if (stat(filename, &filestat) < 0)
  2505.     return -1;
  2506.     euid = geteuid();
  2507.     if (euid == ROOTID)
  2508.     return 0;
  2509.     protection = 7 & (filestat.st_mode >>
  2510.       (filestat.st_uid == euid ? 6 :
  2511.         (filestat.st_gid == getegid() ? 3 : 0)
  2512.       ));
  2513.     if ((mod & protection) == mod)
  2514.     return 0;
  2515.     errno = EACCES;
  2516.     return -1;
  2517. }
  2518. #endif
  2519.  
  2520. /*
  2521.  * Get working directory
  2522.  */
  2523. #ifdef GETCWD
  2524. char *
  2525. getwd(np)
  2526. char *np;
  2527. {
  2528.     char * name;
  2529.     extern char * getcwd();
  2530.     name = getcwd(np,1024);
  2531.     return(name);
  2532. }
  2533. #else
  2534. #ifndef GETWD
  2535. char *
  2536. getwd(np)            /* shorter but slower */
  2537. char *np;
  2538. {
  2539.     FILE *popen();
  2540.     FILE *pipefp = popen("/bin/pwd","r");
  2541.  
  2542.     if (pipefp == Nullfp) {
  2543.     printf("Can't run /bin/pwd\n") FLUSH;
  2544.     finalize(1);
  2545.     }
  2546.     fgets(np,512,pipefp);
  2547.     np[strlen(np)-1] = '\0';    /* wipe out newline */
  2548.     pclose(pipefp);
  2549.     return np;
  2550. }
  2551. #endif
  2552. #endif
  2553. /* just like fgets but will make bigger buffer as necessary */
  2554.  
  2555. char *
  2556. get_a_line(original_buffer,buffer_length,fp)
  2557. char *original_buffer;
  2558. register int buffer_length;
  2559. FILE *fp;
  2560. {
  2561.     register int bufix = 0;
  2562.     register int nextch;
  2563.     register char *some_buffer_or_other = original_buffer;
  2564.  
  2565.     do {
  2566.     if (bufix >= buffer_length) {
  2567.         buffer_length *= 2;
  2568.         if (some_buffer_or_other == original_buffer) {
  2569.                     /* currently static? */
  2570.         some_buffer_or_other = safemalloc((MEM_SIZE)buffer_length+1);
  2571.         strncpy(some_buffer_or_other,original_buffer,buffer_length/2);
  2572.                     /* so we must copy it */
  2573.         }
  2574.         else {            /* just grow in place, if possible */
  2575.         some_buffer_or_other = saferealloc(some_buffer_or_other,
  2576.             (MEM_SIZE)buffer_length+1);
  2577.         }
  2578.     }
  2579.     if ((nextch = getc(fp)) == EOF)
  2580.         return Nullch;
  2581.     some_buffer_or_other[bufix++] = (char) nextch;
  2582.     } while (nextch && nextch != '\n');
  2583.     some_buffer_or_other[bufix] = '\0';
  2584.     len_last_line_got = bufix;
  2585.     return some_buffer_or_other;
  2586. }
  2587.  
  2588. /* copy a string to a safe spot */
  2589.  
  2590. char *
  2591. savestr(str)
  2592. char *str;
  2593. {
  2594.     register char *newaddr = safemalloc((MEM_SIZE)(strlen(str)+1));
  2595.  
  2596.     strcpy(newaddr,str);
  2597.     return newaddr;
  2598. }
  2599.  
  2600. int
  2601. makedir(dirname,nametype)
  2602. register char *dirname;
  2603. int nametype;
  2604. {
  2605. #ifdef MAKEDIR
  2606.     register char *end;
  2607.     register char *s;
  2608.     char tmpbuf[1024];
  2609.     register char *tbptr = tmpbuf+5;
  2610.  
  2611.     for (end = dirname; *end; end++) ;    /* find the end */
  2612.     if (nametype == MD_FILE) {        /* not to create last component? */
  2613.     for (--end; end != dirname && *end != '/'; --end) ;
  2614.     if (*end != '/')
  2615.         return 0;            /* nothing to make */
  2616.     *end = '\0';            /* isolate file name */
  2617.     }
  2618.     strcpy(tmpbuf,"mkdir");
  2619.  
  2620.     s = end;
  2621.     for (;;) {
  2622.     if (stat(dirname,&filestat) >= 0) {
  2623.                     /* does this much exist? */
  2624.         *s = '/';            /* mark this as existing */
  2625.         break;
  2626.     }
  2627.     s = rindex(dirname,'/');    /* shorten name */
  2628.     if (!s)                /* relative path! */
  2629.         break;            /* hope they know what they are doing */
  2630.     *s = '\0';            /* mark as not existing */
  2631.     }
  2632.     
  2633.     for (s=dirname; s <= end; s++) {    /* this is grody but efficient */
  2634.     if (!*s) {            /* something to make? */
  2635.         sprintf(tbptr," %s",dirname);
  2636.         tbptr += strlen(tbptr);    /* make it, sort of */
  2637.         *s = '/';            /* mark it made */
  2638.     }
  2639.     }
  2640.     if (nametype == MD_DIR)        /* don't need final slash unless */
  2641.     *end = '\0';            /*  a filename follows the dir name */
  2642.  
  2643.     return (tbptr==tmpbuf+5 ? 0 : doshell(sh,tmpbuf));
  2644.                     /* exercise our faith */
  2645. #else
  2646.     sprintf(cmd_buf,"%s %s %d", filexp(DIRMAKER), dirname, nametype);
  2647.     return doshell(sh,cmd_buf);
  2648. #endif
  2649. }
  2650.  
  2651. #ifdef SETENV
  2652. static bool firstsetenv = TRUE;
  2653. extern char **environ;
  2654.  
  2655. void
  2656. setenv(nam,val)
  2657. char *nam, *val;
  2658. {
  2659.     register int i=envix(nam);        /* where does it go? */
  2660.  
  2661.     if (!environ[i]) {            /* does not exist yet */
  2662.     if (firstsetenv) {        /* need we copy environment? */
  2663.         int j;
  2664. #ifndef lint
  2665.         char **tmpenv = (char**)    /* point our wand at memory */
  2666.         safemalloc((MEM_SIZE) (i+2) * sizeof(char*));
  2667. #else
  2668.         char **tmpenv = Null(char **);
  2669. #endif lint
  2670.     
  2671.         firstsetenv = FALSE;
  2672.         for (j=0; j<i; j++)        /* copy environment */
  2673.         tmpenv[j] = environ[j];
  2674.         environ = tmpenv;        /* tell exec where it is now */
  2675.     }
  2676. #ifndef lint
  2677.     else
  2678.         environ = (char**) saferealloc((char*) environ,
  2679.         (MEM_SIZE) (i+2) * sizeof(char*));
  2680.                     /* just expand it a bit */
  2681. #endif lint
  2682.     environ[i+1] = Nullch;    /* make sure it's null terminated */
  2683.     }
  2684.     environ[i] = safemalloc((MEM_SIZE) strlen(nam) + strlen(val) + 2);
  2685.                     /* this may or may not be in */
  2686.                     /* the old environ structure */
  2687.     sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
  2688. }
  2689.  
  2690. int
  2691. envix(nam)
  2692. char *nam;
  2693. {
  2694.     register int i, len = strlen(nam);
  2695.  
  2696.     for (i = 0; environ[i]; i++) {
  2697.     if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
  2698.         break;            /* strnEQ must come first to avoid */
  2699.     }                    /* potential SEGV's */
  2700.     return i;
  2701. }
  2702. #endif
  2703.  
  2704. void
  2705. notincl(feature)
  2706. char *feature;
  2707. {
  2708.     printf("\nNo room for feature \"%s\" on this machine.\n",feature) FLUSH;
  2709. }
  2710.  
  2711. char *
  2712. getval(nam,def)
  2713. char *nam,*def;
  2714. {
  2715.     char *val;
  2716.  
  2717.     if ((val = getenv(nam)) == Nullch || !*val)
  2718.     val = def;
  2719.     return val;
  2720. }
  2721.  
  2722. /* grow a static string to at least a certain length */
  2723.  
  2724. void
  2725. growstr(strptr,curlen,newlen)
  2726. char **strptr;
  2727. int *curlen;
  2728. int newlen;
  2729. {
  2730.     if (newlen > *curlen) {        /* need more room? */
  2731.     if (*curlen)
  2732.         *strptr = saferealloc(*strptr,(MEM_SIZE)newlen);
  2733.     else
  2734.         *strptr = safemalloc((MEM_SIZE)newlen);
  2735.     *curlen = newlen;
  2736.     }
  2737. }
  2738.  
  2739. void
  2740. setdef(buffer,dflt)
  2741. char *buffer,*dflt;
  2742. {
  2743. #ifdef STRICTCR
  2744.     if (*buffer == ' ')
  2745. #else
  2746.     if (*buffer == ' ' || *buffer == '\n')
  2747. #endif
  2748.     {
  2749.     if (*dflt == '^' && isupper(dflt[1]))
  2750.         *buffer = Ctl(dflt[1]);
  2751.     else
  2752.         *buffer = *dflt;
  2753.     }
  2754. }
  2755. !STUFFY!FUNK!
  2756. echo Extracting newsetup.1
  2757. cat >newsetup.1 <<'!STUFFY!FUNK!'
  2758. ''' $Header: newsetup.1,v 4.3 85/05/01 11:43:22 lwall Exp $
  2759. ''' 
  2760. ''' $Log:    newsetup.1,v $
  2761. ''' Revision 4.3  85/05/01  11:43:22  lwall
  2762. ''' Baseline for release with 4.3bsd.
  2763. ''' 
  2764. ''' 
  2765. .de Sh
  2766. .br
  2767. .ne 5
  2768. .PP
  2769. \fB\\$1\fR
  2770. .PP
  2771. ..
  2772. .de Sp
  2773. .if t .sp .5v
  2774. .if n .sp
  2775. ..
  2776. '''
  2777. '''     Set up \*(-- to give an unbreakable dash;
  2778. '''     string Tr holds user defined translation string.
  2779. '''     Bell System Logo is used as a dummy character.
  2780. '''
  2781. .ie n \{\
  2782. .tr \(bs-\*(Tr
  2783. .ds -- \(bs-
  2784. .if (\n(.H=4u)&(1m=24u) .ds -- \(bs\h'-12u'\(bs\h'-12u'-\" diablo 10 pitch
  2785. .if (\n(.H=4u)&(1m=20u) .ds -- \(bs\h'-12u'\(bs\h'-8u'-\" diablo 12 pitch
  2786. .ds L" ""
  2787. .ds R" ""
  2788. .ds L' '
  2789. .ds R' '
  2790. 'br\}
  2791. .el\{\
  2792. .ds -- \(em\|
  2793. .tr \*(Tr
  2794. .ds L" ``
  2795. .ds R" ''
  2796. .ds L' `
  2797. .ds R' '
  2798. 'br\}
  2799. .TH NEWSETUP 1 LOCAL
  2800. .SH NAME
  2801. newsetup - a program to set up a .newsrc file
  2802. .SH SYNOPSIS
  2803. .B newsetup
  2804. .SH DESCRIPTION
  2805. The
  2806. .I newsetup
  2807. program creates a new .newsrc file containing all of the currently active
  2808. newsgroups.
  2809. It tries to put them in a reasonable order, i.e. local newsgroups earlier,
  2810. but you'll probably want to change the ordering anyway (if you use
  2811. .IR rn )
  2812. in order to put interesting newsgroups first.
  2813. If you already have a .newsrc, it will be backed up with the name
  2814. \*(L".oldnewsrc\*(R".
  2815. .SH ENVIRONMENT
  2816. .IP DOTDIR 8
  2817. Where to put your .newsrc, if not in your home directory.
  2818. .Sp
  2819. Default: $HOME
  2820. .IP HOME 8
  2821. Your home directory.
  2822. .Sp
  2823. Default: $LOGDIR
  2824. .IP LOGDIR 8
  2825. Your home directory if HOME is undefined.
  2826. .SH FILES
  2827. /usr/lib/news/active or a reasonable facsimile
  2828. .br
  2829. ${DOTDIR-{$HOME-$LOGDIR}}/.newsrc
  2830. .SH SEE ALSO
  2831. rn(1), newsrc(5)
  2832. .SH DIAGNOSTICS
  2833. .SH BUGS
  2834. !STUFFY!FUNK!
  2835. echo ""
  2836. echo "End of kit 6 (of 9)"
  2837. cat /dev/null >kit6isdone
  2838. config=true
  2839. for iskit in 1 2 3 4 5 6 7 8 9 ; do
  2840.     if test -f kit${iskit}isdone; then
  2841.     echo "You have run kit ${iskit}."
  2842.     else
  2843.     echo "You still need to run kit ${iskit}."
  2844.     config=false
  2845.     fi
  2846. done
  2847. case $config in
  2848.     true)
  2849.     echo "You have run all your kits.  Please read README and then type Configure."
  2850.     chmod 755 Configure
  2851.     ;;
  2852. esac
  2853. : I do not append .signature, but someone might mail this.
  2854. exit
  2855.