;;; view-section.mhtml: -*- Meta-HTML -*-  DESCRIPTIVE TEXT.

;;;  Copyright (c) 1996 Brian J. Fox
;;;  Author: Brian J. Fox (bfox@ai.mit.edu) Mon Jul  1 10:53:32 1996.
<set-var title =
  <prog
    Section Intro:
    <capitalize <subst-in-string <or <get-var key> <get-var section>>
				 "-" " ">>>>
<require ./mandefs.mhtml>

<when <get-var-once posted::section>>
  <set-var posted::key=<get-var-once posted::section>>
  <set-var key=<get-var-once posted::section>>
</when>

<when <get-var-once posted::key>>
  <set-var posted::key =
    <upcase <subst-in-string <get-var-once key>
			     "^[ \t]+" "" "[ \t]+$" "" " +" "-">>>
  <set-var key=<get-var-once posted::key>>
</when>

<section::get-sections>

<set-var p="" n="" .="" i=0>
<while <and <gt i -1> <get-var-once sections[i]>>>
  <if <string-eq <get-var-once sections[i]> <get-var-once key>>
      <prog
	<if <gt i 0>
	    <set-var p=<sub i 1>>>
	<set-var .=<get-var i>>
	<if <get-var-once sections[<add i 1>]>
	    <set-var n=<add i 1>>>
	<set-var i=-1>>
    <increment i>>
</while>

<when <get-var p>>
  <with-local-package>
    <set-var
      key=<get-var default::sections[default::p]>
      default::prev-page = view-section.mhtml?<cgi-encode key>
      default::prev-title =
      <capitalize <subst-in-string <get-var key> "-" " ">>>
  </with-local-package>
</when>

<when <get-var n>>
  <with-local-package>
    <set-var
      key=<get-var default::sections[default::n]>
      default::next-page = view-section.mhtml?<cgi-encode key>
      default::next-title =
      <capitalize <subst-in-string <get-var key> "-" " ">>>
  </with-local-package>
</when>

<include header.mhtml>
<set-var mhtml::cacheable=true>
<set-var posted::expanded-view=true>

<when <get-var-once posted::key>>
  <package-delete section>
  <with-open-database db <metahtml::section-db> mode=read>
    <set-var x =
      <database-load-record db <upcase <get-var-once key>> prefix=section>>
  </with-open-database>

  <when <not <get-var x>>>
    <ptext>
      There isn't a documentation pointer for the section <get-var-once key>
      in the database <metahtml::section-db>.

      Perhaps now would be a good time to
      <concat <a href="<get-var mhtml::url-to-dir>/
	create-section.mhtml?<cgi-encode key>">>
      <b>enter the pointer</b>.</a>
    </ptext>
    <p>
  </when>
</when>

<if <not <get-var-once posted::key>>
    <redirect <get-var mhtml::url-to-dir>/section-index.mhtml>>

<when <get-var x>>
  ;;; Get the functions which belong to this section.
  <with-open-database db <metahtml::function-db> mode=read>
    <database-query db <and
			<string-eq <upcase <get-var-once posted::key>>
				   <upcase <get-var-once section>>>
			<not <string-eq <get-var-once funtype> variable>>>
      keys=keys>
  </with-open-database>

  ;;; Get the variables which belong to this section.
  <with-open-database db <metahtml::function-db> mode=read>
    <database-query db <and
			<string-eq <get-var-once funtype> variable>
			<string-eq <upcase <get-var-once posted::key>>
				   <upcase <get-var-once section>>>>
      keys=variables>
  </with-open-database>

  <b>Synopsis:</b><br>
  <ul>
    <set-var expr="<%ptext><get-var-once section::short-desc></ptext>">
    <subst-in-var expr "^<%" "<" "\r\n" "\n" "\r" "\n">
    <get-var expr>
  </ul>

  <p>

  <when <get-var-once default::keys>>
    <sort keys>
    <b>Commands:</b><br>
    <ul>
      <set-var i=0 max=0>
      <while <get-var keys[i]>>
	<set-var keys[i] = <downcase <get-var keys[i]>>>
	<set-var x=<match <get-var keys[i]> ".*" action=length>>
	<if <gt x max> <set-var max=<get-var x>>>
	<increment i>
      </while>
      <set-var w=<if <gt max 15> 3 4>>
      <vertical-table default::keys <get-var w>
		      <if <get-var posted::expanded-view> # man-page.mhtml>>
    </ul>
    <p>
  </when>

  <when <get-var-once default::variables>>
    <sort variables>
    <b>Variables:</b><br>
    <ul>
      <set-var i=0>
      <while <get-var variables[i]>>
	<set-var variables[i] = <downcase <get-var variables[i]>>>
	<increment i>
      </while>
      <vertical-table default::variables 4 man-page.mhtml>
    </ul>
    <p>
  </when>

  <when <get-var-once section::long-desc>>
    <b>More Information:</b><br>
    <ul>
      <set-var expr="<%ptext><get-var-once section::long-desc></ptext>">
      <subst-in-var expr "^<%" "<" "\r\n" "\n" "\r" "\n">
      <get-var expr>
    </ul>
  </when>

  <when <and <get-var-once posted::expanded-view>
	     <get-var-once default::keys>>>

    <h3>Function Documentation</h3>
    <p>
    <with-open-database db <metahtml::function-db> mode=read>
      <set-var findex=0>
      <while <get-var keys[findex]>>
	<a name="<get-var-once keys[findex]>">
	  <package-delete function>
	  <set-var x = <database-load-record db
			 <upcase <get-var-once keys[findex]>>
			 prefix=function>>
	  <p>
	  <table width=100%>
	    <tr valign=top>
	      <td align=left width=85%>
		<code>
		<when <string-eq <get-var function::funtype> complex>>
		  <concat
		   &lt;
		   <b><get-var function::name></b>
		   <set-var i=0>
		   <while <get-var function::req-args[i]>>
		   &nbsp;<i><upcase <get-var function::req-args[i]>></i>
		   <increment i>
		   </while>
		   <set-var i=0>
		   <while <get-var function::opt-args[i]>>
		   <if <string-eq <get-var function::opt-args[i]> "...">
		       <prog &nbsp;<i>...</i>>
		     <prog &nbsp;[<i><upcase <get-var function::opt-args[i]>></i>]>>
		   <increment i>
		   </while>
		   <set-var i=0>
		   <while <get-var function::key-args[i]>>
		   <if <string-eq <get-var function::key-args[i]> "...">
		       <prog &nbsp;<i>...</i>>
		     <prog &nbsp;[<i><upcase <get-var function::key-args[i]>></i>]>>
		   <increment i>
		   </while>
		   &gt;
		   <br>
		   &nbsp;&nbsp;<i>body</i>
		   <br>
		   &lt;/
		   <b><get-var function::name></b>
		   &gt;>
		</when>

		<when <string-eq <get-var function::funtype> simple>>
		  <concat
		   &lt;
		   <b><get-var function::name></b>
		   <set-var i=0>
		   <while <get-var function::req-args[i]>>
		   &nbsp;<i><upcase <get-var function::req-args[i]>></i>
		   <increment i>
		   </while>
		   <set-var i=0>
		   <while <get-var function::opt-args[i]>>
		   <if <string-eq <get-var function::opt-args[i]> "...">
		       <prog &nbsp;<i>...</i>>
		     <prog &nbsp;[<i><upcase <get-var function::opt-args[i]>></i>]>>
		   <increment i>
		   </while>
		   <set-var i=0>
		   <while <get-var function::key-args[i]>>
		   <if <string-eq <get-var function::key-args[i]> "...">
		       <prog &nbsp;<i>...</i>>
		     <prog &nbsp;[<i><upcase <get-var function::key-args[i]>></i>]>>
		   <increment i>
		   </while>
		   &gt;>
		</when>

		</code>
	      </td>
	      <td align=right>
		<b><i><capitalize <get-var function::funtype>></i></b>
	      </td>
	    </tr>
	  </table>
	  <p>
	  <set-var expr="<%ptext><get-var function::short-desc></ptext>">
	  <subst-in-var expr "^<%" "<" "\r\n" "\n" "\r" "\n">
	  <ul> <get-var expr> </ul>
	  <p>
	  <increment findex>
	</a>
      </while>
    </with-open-database>
  </when>
</when>

<p>
<when <not <string-eq <get-var env::server_name> "www.metahtml.com">>>
  <a href="<get-var mhtml::url-to-dir>/create-section.mhtml?<cgi-encode key>">
    Edit Section
  </a>
  <br>
</when>
<a href="<get-var mhtml::url-to-dir>/function-index.mhtml">
  Function Index
</a>
<br>
<a href="<get-var mhtml::url-to-dir>/variable-index.mhtml">
  Variable Index
</a>
<include footer.mhtml>
