;;; general.mhtml: -*- Meta-HTML -*-  DESCRIPTIVE TEXT.

;;;  Copyright (c) 1996 Brian J. Fox
;;;  Author: Brian J. Fox (bfox@ai.mit.edu) Tue Jun 25 01:01:50 1996.

<defsubst double-digits whitespace=delete>
  <set-var %0=<subst-in-string <pad <get-var %0> 2 align=right> " " 0>>
</defsubst>

<defsubst array-size whitespace=delete>
  <set-var __info[]=<symbol-info "%0">>
  <or <get-var __info[1]> 0>
</defsubst>

<defsubst array-member whitespace=delete>
  <set-var am::i=0 am::size=<array-size "%1"> am::result="">
  <while <and <not <get-var am::result>>
              <lt am::i am::size>>>
    <if <string-eq "%0" "<get-var "%1"[am::i]>">
        <set-var am::result=true>>
    <increment am::i>
  </while>
  <get-var am::result>
</defsubst>

<defsubst array-add-unique whitespace=delete>
  <if <not <array-member "%0" "%1">>
      <array-append "%0" "%1">>
</defsubst>

<defsubst array-append whitespace=delete>
  <set-var aa::size=<array-size "%1">>
  <set-var "%1[aa::size]"="%0">
</defsubst>

<defsubst select-option whitespace=delete>
  <if <array-member "%1" "%0">
      <prog <option selected>%1>
    <prog <if <string-eq "%2" "selected">
              <prog <option selected>%1>
            <prog <option>%1>>>>
</defsubst>

<defsubst file-exists-p whitespace=delete>
  <get-file-properties %0>
</defsubst>

<defsubst comma-separated whitespace=delete>
  <set-var cs::i=0 cs::size=<array-size "%0">>
  <while <lt cs::i cs::size>>
    <concat
     <get-var %0[cs::i]>
     <if <eq cs::i <sub cs::size 2>> ", and "
       <if <lt cs::i <sub cs::size 2>> ", ">>>
    <increment cs::i>
  </while>
</defsubst>

;;; Completely removes the session package
<defsubst session-destroy-package whitespace=delete>
  <session-import %0 %0>
  <set-var sdp::cmd="%unset-session-var <package-vars %0>>">
  <subst-in-var sdp::cmd "^%" "<">
  <get-var sdp::cmd>
</defsubst>


<defun package-merge source dest>
  <alist-to-package <package-to-alist <get-var source>> <get-var dest>>
</defun>

;;; <make-innocuous [package]> turns the contents of PACKAGE into
;;; non-executable text.
<defun make-innocuous package>
  <set-var names[]=<package-vars <get-var package>>>
  <set-var i=0>
  <while <get-var-once names[i]>>
    <subst-in-var <get-var-once names[i]> "&" "&amp;" "<" "&lt;" ">" "&gt;">
    <increment i>
  </while>
</defun>

