# Build a section of the Reference Manual in =doc=/?man
#  Usage: man_section [<env_opt>]
#           <env_opt> ::= -d | -p | -s | -t | -l

   declare search_rule = "^int,^var,=bin=/&"
   declare ev dd

   case [arg 1]
      when s1
      when s2
      when s3
      when s4
      when s5
      when s6
      out
         error "Usage: "[arg 0]" (s1|s2|s3|s4|s5|s6) [-d|-p|-s|-t|-l]"
   esac

   case [arg 2]
      when ""
         set ev = =fmac=/evp
         set dd = fman
      when -p
         set ev = =fmac=/evp
         set dd = fman
      when -d
         set ev = =fmac=/evd
         set dd = dman
      when -s
         set ev = =fmac=/evs
         set dd = sman
      when -t
         set ev = =fmac=/evt
         set dd = tman
      when -l
         set ev = =fmac=/evl2
         set dd = lman
      out
         error "Usage: "[arg 0]" (s1|s2|s3|s4|s5|s6) [-d|-p|-s|-t|-l]"
   esac

# section header:
   fmt [ev] =doc=/man/[arg 1]_macros =doc=/man/[arg 1]_header _
      >=doc=/[dd]/[arg 1]_header

# each section manual entry:
   files .d$ =doc=/man/[arg 1] _
      | change ?* _
       "fmt "[ev]" =doc=/man/"[arg 1]"_macros =doc=/man/"[arg 1]"/& _
           >=doc=/[dd]/"[arg 1]"/&" _
      | sh

   chat -pa/r -s =doc=/[dd]/[arg 1]
