########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1996-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# #
########################################################################
# it keeps going and going ...
#
# \h'0*\w"URL"'HOT-TEXT\h'0' link goto with alternate url
# \h'0*1'HOT-TEXT\h'0' link goto
#
# .xx link="URL\tHOT-TEXT" link goto with url request
# .xx link="HOT-TEXT" link goto request
# .xx ref="URL\tMIME-TYPE" head link hint
command=mm2bb
USAGE=$'
[-?
@(#)$Id: mm2bb (AT&T Research) 2010-05-28 $
]
[+DESCRIPTION?\bmm2bb\b is a \bsed\b(1)/\bksh\b(1) script (yes!) that
converts input \bmm\b(1) or \bman\b(1) documents to a \bbb\b markups
document on the standard output. If \afile\a is omitted then the
standard input is read. \adir\a operands and directory components
of \afile\a operands are added to the included file search list.
The default \bbb\b markup style is [\aop\a]]\adata\a[/\aop\a]].]
[t:texish?\b\\foo\b{\adata\a} \bbb\b markup style]
[ file ... ]
[+SEE ALSO?\bmm2html\b(1)]
'
;;
*) ARGV0=""
USAGE=' [ file ... ]'
;;
esac
set -o noglob
typeset -u upper
typeset -x -l OP
nl=$'\n'
html=(
H1=(
)
home=(
href=
)
index=(
left=
top=
)
logo=(
src=
)
width=96%
)
code=0
figure=1
file=
font=
hp=
'}
inch=" "
pm=
primary=".BL|.LI|.IX"
top=
vg_ps=20
{
OPTIND=0
exit 2
}
t) tex=1 ;;
*) usage ;;
esac
done
shift OPTIND-1
case $# in
if [[ ! -f $file ]]
exit 1
fi
x="-m $file"
;;
*) x=
;;
esac
then
tt='font{courier new\,courier,'
dd='{'
else
size_normal=12
size_big=18
dd=
fi
function warning
{
}
function getfiles
{
sed \
-e 's%\\".*%%' \
-e 's%\\(>=%>=%g' \
-e 's%\\(<=%<=%g' \
-e 's%\\'\''%'\''%g' \
-e 's%\\`%`%g' \
-e 's%\\+%+%g' \
-e 's%\\0% %g' \
-e 's%\\|% %g' \
-e 's%\\\^% %g' \
-e 's%\\ % %g' \
-e 's%\\(+-%\±%g' \
-e 's%\\(-%=%g' \
-e 's%\\(ap%~%g' \
-e 's%\\(bu%\·%g' \
-e 's%\\(bv%|%g' \
-e 's%\\(co%\©%g' \
-e 's%\\(dg%\§%g' \
-e 's%\\(fm%'\''%g' \
-e 's%\\(rg%\®%g' \
-e 's%\\(sq%\¤%g' \
-e 's%\\(\*\([*`'\'']\)%\1%g' \
-e 's%\\\*\([*`'\'']\)%\1%g' \
-e 's%\\d\([^\\]*\)\\u%\1%g' \
-e 's%\\u\([^\\]*\)\\d%\1%g' \
-e 's%\\v\(.\)-\([^\\]*\)\1\(.*\)\\v\1+*\2\1%\3%g' \
-e 's%\\v\(.\)+*\([^\\]*\)\1\(.*\)\\v\1-\2\1%\3%g' \
-e 's%\\h'\''0\*\\w"\([abcdefghijklmnopqrstuvwxyz]*:[^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\2[/url]%g' \
-e 's%\\h'\''0\*\\w"\(/[^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\2[/url]%g' \
-e 's%\\h'\''0\*\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\2[/url]%g' \
-e 's%\\h'\''0\*1'\''\([^:/'\'']*\)\\h'\''0'\''%[url=\1]\1[/url]%g' \
-e 's%\\h'\''0\*1'\''\([abcdefghijklmnopqrstuvwxyz]*:[^'\'']*\)\\h'\''0'\''%[url=\1]\1[/url]%g' \
-e 's%\\h'\''0\*1'\''\(/[^'\'']*\)\\h'\''0'\''%[url=\1]\1[/url]%g' \
-e 's%\\h'\''0\*1'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\1[/url]%g' \
-e 's%\\h'\''0/\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\2[/url]%g' \
-e 's%\\h'\''0/1'\''\([^'\'']*\)\\h'\''0'\''%[url=\1]\1[/url]%g' \
-e 's%\\f(\(..\)\([^\\]*\)%<\1>\2</\1>%g' \
-e 's%\\f[PR]%\\fZ%g' \
-e 's%\\f\(.\)\([^\\]*\)%<\1>\2</\1>%g' \
-e 's%<\([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789][-._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]*@[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.]*\)>%[size='$size_small']\<[url=mailto:\1]\1[/url]\>[/size]%g' \
-e 's%\[[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]*[0123456789][0123456789][abcdefghijklmnopqrstuvwxyz]*]%[b]&[/b]%g' \
-e 's%</*Z>%%g' \
-e 's%<[146789]>%%g' \
-e 's%</[146789]>%%g' \
-e 's%<2>%[i]%g' \
-e 's%</2>%[/i]%g' \
-e 's%<3>%[b]%g' \
-e 's%</3>%[/b]%g' \
-e 's%<5>%[code]%g' \
-e 's%</5>%[/code]%g' \
-e 's%<B>%[b]%g' \
-e 's%</B>%[/b]%g' \
-e 's%<I>%[i]%g' \
-e 's%</I>%[/i]%g' \
-e 's%<L>%[code]%g' \
-e 's%</L>%[/code]%g' \
-e 's%<X>%[code]%g' \
-e 's%</X>%[/code]%g' \
-e 's%<CW>%[code]%g' \
-e 's%</CW>%[/code]%g' \
-e 's%\\e%\\%g' \
-e '/^'\''[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]\>/s%.%.%' \
-e '/^\..*".*\\/s%\\[^\*][^(]%\\&%g' \
"$@"
}
fill=
spaced=1
function space
{
then spaced=1
print
fi
}
function flush
{
if [[ $fill ]]
then print -r -- "${fill#?}"
fill=
spaced=0
fi
}
function puttext
{
then print -r -- "$*"
spaced=0
elif [[ $1 ]]
else flush
fi
}
function putop
{
if (( $# ))
then print -r -- "$*"
spaced=0
fi
}
function putopn
{
if (( $# ))
then print -r -n -- "$*"
spaced=1
fi
}
function putopt
{
if [[ $1 ]]
fi
}
function getline
{
integer i n
typeset data a c d q v x d
trap 'set -- "${text[@]}"' 0
return
fi
while :
do data=
while :
then eval exec $fd'>&-'
fi
continue
fi
return 1
}
case $a in
*\\) x=${a%%+(\\)}
a=${a#"$x"}
if (( ! ( ${#a} & 1 ) ))
break
fi
;;
break
;;
break
;;
esac
done
*\\[n\*]*)
a= i=0
while :
do c=${data:i++:1}
case $c in
"") break
;;
\\) x=${data:i:1}
case $x in
[n\*]) (( i++ ))
c=${data:i++:1}
case $c in
\() c=${data:i:2}
(( i += 2 ))
;;
\[) c=${data:i}
c=${c%%]*}
(( i += ${#c} + 1 ))
x='*'
;;
esac
case $x in
n) a=$a${nr[$c]} ;;
*) a=$a${ds[$c]} ;;
esac
continue
;;
\\) a=$a$c
while :
do c=${data:i++:1}
case $c in
\\) ;;
*) break ;;
esac
a=$a$c
done
;;
esac
;;
esac
a=$a$c
done
data=$a
;;
esac
*[\"]*)
unset v
a= i=0 n=0 q=
while :
do c=${data:i++:1}
case $c in
"") break ;;
esac
case $c in
$q) q=
case $c in
\>) ;;
*) continue
;;
esac
;;
[\"\<]) case $q in
\<) q=\>
;;
*) q=$c
continue
;;
esac
;;
esac
;;
\ |\ )
case $q in
?*) v[n++]=$a
a=
;;
esac
continue
;;
esac
;;
esac
a=$a$c
done
case $a in
?*) v[n++]=$a ;;
esac
set -A text -- "${v[@]}"
;;
;;
esac
set -- "${text[@]}"
shift
x=$1
shift
then warning "unmatched ${text[0]}"
n=0
fi
;;
.i*) case $x in
!*) x=${x#?}
n=1
;;
*) n=0
;;
esac
case $x in
t|\'@(*)\'\1\'|+([\-+0123456789])=\1)
(( n = ! n ))
;;
+([\-+0123456789])=+([\-+0123456789]))
;;
[0123456789]*[0123456789])
(( n = $x ))
;;
esac
esac
;;
esac
if (( ! n ))
then case $@ in
*\\\}) break ;;
esac
done
;;
esac
continue
fi
set -A text -- "$@"
esac
;;
for d in "${dirs[@]}"
do if [[ -f "$d$x" ]]
eval exec $fd'< $tmp'
file=$d$x
continue 2
fi
done
continue
;;
set -- "${text[@]}"
shift
while :
do case $# in
0) break ;;
esac
nam=${1%%=*}
*) val=${1#*=} ;;
esac
shift
*' '*)
;;
*'\\t'*)
;;
;;
esac
*[:/.]*) pfx= ;;
esac
*'${html.'*'}'*)
;;
esac
fi
fi
;;
tar=" target=_top"
;;
esac
;;
esac
;;
esac
fi
;;
esac
;;
esac
done
'') continue ;;
esac
break
;;
esac
;;
esac
set -- "${text[@]}"
op=$1
shift
2':('[0123456789]')'*([,.?!:;]))
x=${2#'('*')'}
y=${2%$x}
n=$y
then
.L*) font1='\'$tt ;;
*) font1='\i{' ;;
esac
case $macros in
man) set -A text -- "\\newurl{../man$n/$1.html,$font1$1}}$y$x" ;;
esac
else
case $op in
.B*) font1=b ;;
.L*) font1=$tt ;;
*) font1=i ;;
esac
case $macros in
man) set -A text -- "[url=../man$n/$1.html][$font1]$1[/$font1][/url]$y$x" ;;
esac
fi
break
;;
esac
;;
.F) op=.L ;;
.FR) op=.LR ;;
.MW) op=.L ;;
.RF) op=.RL ;;
esac
case $#:$macros:$op in
0:*) ;;
*:man:.?)
set -- "$*"
;;
esac
case $# in
0) getline
set -- "$*"
;;
esac
set -- "$indent""$@"
case $font in
"") data=
;;
?*) if (( tex ))
then data="}"
else data="[/$font]"
fi
font=
;;
esac
font1=${op#.}
case $font1 in
?) font2=R
;;
*) font2=${font1#?}
font1=${font1%?}
;;
esac
case $font1 in
B) font1=b$dd ;;
I) font1=i$dd ;;
[LMX]) font1=$tt ;;
R) font1= ;;
esac
case $font2 in
B) font2=b$dd ;;
I) font2=i$dd ;;
[LMX]) font2=$tt ;;
R) font2= ;;
esac
font=$font2
while :
do case $# in
0) break ;;
esac
case $font in
$font2) font=$font1 ;;
*) font=$font2 ;;
esac
if (( tex ))
then
case $1 in
"") ;;
*'\-'[1-9]*|*'\'[1-9]*)
esac
;;
*'\\-'[1-9]*|*'\'[1-9]*)
case $font in
"") data="$data$1 $2" ;;
*) data="$data\\$font$1 $2}" ;;
esac
shift
;;
*) case $font in
"") data="$data$1" ;;
*) data="$data\\$font$1}" ;;
esac
;;
esac
;;
esac
else
case $1 in
"") ;;
*"[size"*)
case $font in
"") data="$data$1" ;;
*) data="$data[$font]$1[/$font]" ;;
esac
;;
*) case "$1 $2" in
*"[size"*)
case $font in
"") data="$data$1 $2" ;;
*) data="$data[$font]$1 $2[/$font]" ;;
esac
shift
;;
*) case $font in
"") data="$data$1" ;;
*) data="$data[$font]$1[/$font]" ;;
esac
;;
esac
;;
esac
fi
shift
done
font=
set -A text -- $data
;;
.PD) case $1 in
0) pd= ;;
*) pd=$nl ;;
esac
continue
;;
.PF|.PH)continue
;;
.SB) set -- "${text[@]}"
shift
case $# in
0) getline ;;
esac
if (( tex ))
then set -A text -- "\\-1{\\b{""$@""}}"
else set -A text -- "[size=$size_small][b]""$@""[/b][/size]"
fi
;;
.SG) continue
;;
.SM) set -- "${text[@]}"
shift
case $# in
0) getline ;;
esac
if (( tex ))
then set -A text -- "\\-1{""$@""}"
else set -A text -- "[size=$size_small]""$@""[/size]"
fi
;;
*) x=${map[${text[0]}]}
case $x in
?*) text[0]=$x ;;
esac
;;
esac
;;
*) set -A text -- "$data"
;;
esac
break
done
trap 'set -- "${text[@]}"' 0
}
function heading
{
typeset op=$1 i o options beg end
integer count
shift
case $op in
.H) case $# in
0) count=1 ;;
*) count=$1; shift ;;
esac
options=
;;
.H*|.AS)count=1
;;
*) count=2
;;
esac
case $* in
"") putop
;;
*) if (( count == 1 ))
then if (( tex ))
then beg="$beg\\red{\\1{"
end="}}$end"
else beg="$beg[color=red][size=$size_big]"
end="[/size][/color]$end"
fi
fi
space
putop "$beg $* $end"
space
;;
esac
}
function tbl_attributes
{
typeset d f i u x
typeset -F0 w
case $1 in
[aAcC]*)a="$a align=center" ;;
[lL]*) a="$a align=left" ;;
[nN]*) a="$a align=right char=." ;;
[rR]*) a="$a align=right" ;;
esac
case $i in
*[wW]\(+([0-9.])*\)*)
x=${i##*[wW]\(}
x=${x%%\)*}
u=${x##+([0-9.])}
x=${x%$u}
case $u in
c) (( w=x*75/2.54 )) ;;
i) (( w=x*75 )) ;;
m) (( w=x*75*12/72 )) ;;
n) (( w=x*75*12/72/2 )) ;;
p) (( w=x*75/72 )) ;;
P) (( w=x*75/6 )) ;;
*) (( w=x*75*12/72/2 )) ;;
esac
a="$a width=$w"
;;
esac
case $i in
*[bB]*) if (( tex ))
then b="$b\\b{" e="}$e"
else b="$b[b]" e="[/b]$e"
fi
;;
esac
case X$i in
*[!0-9.][iI]*)
if (( tex ))
then b="$b\\i{" e="}$e"
else b="$b[i]" e="[/i]$e"
fi
;;
esac
}
dirs[++ndirs]=""
for i
do if [[ -d $i ]]
then dirs[++ndirs]=$i/
else files[++nfiles]=$i
if [[ $i == */* ]]
then dirs[++ndirs]=${i%/*}/
fi
fi
done
document="${files[@]}"
getfiles "${files[@]}" |
while :
do getline || {
[[ $title != '' ]] && break
set -- .TL
}
case $1 in
.) : comment
;;
.*) op=$1
shift
case $op in
.AC) : ignore $op
;;
.AE) : ignore $op
;;
.AF) case $mm_AF_cur in
"") mm_AF_cur="[i]$*" ;;
*) mm_AF_cur="${mm_AF_cur}${nl}$*" ;;
esac
;;
.AL|.[IR]S|.VL)
case $macros:$op in
mm:.RS) if (( tex ))
then Rf="\\+{[$reference]}"
references="$references$nl\\list{[$reference]}"
else Rf="\\u[$reference]\\d"
references="$references$nl[list][$reference][/list]"
fi
while getline
do case $1 in
.RF) break ;;
esac
references="$references$nl$*"
done
(( reference++ ))
continue
;;
esac
type[++lists]=.AL
list[lists]=DL
case $op in
.AL) case $1 in
'') type[++lists]=.al
list[lists]=OL
;;
[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ])
type[++lists]=.al
list[lists]=OL
;;
esac
if (( tex ))
fi
;;
.[IR]S) if (( tex ))
fi
;;
.VL) case $1 in
?*) type[++lists]=.al
list[lists]=DL
;;
esac
if (( tex ))
fi
;;
esac
;;
.AS|.H|.HU|.SH|.SS|.ce|.CE)
if ((nf))
then nf=0
putop "}"
fi
if ((ce))
then ce=0
fi
case $hp in
?*) indent=${indent#$hp}
hp=
;;
esac
if (( lists > pp ))
then case ${type[@]:0:lists} in
*.[Aa][Ll]*|*.[IiTt][Pp]*)
while :
do case ${type[lists]} in
.[Aa][Ll]|.[IiTt][Pp])
case ${type[lists]} in
.AL|.IP|.TP)break ;;
esac
;;
*) break
;;
esac
done
;;
esac
fi
(( pp = lists ))
end=
case ${mm.title} in
?*) if (( tex ))
then beg="$beg\\1{\\blue{"
end="}}$end"
else beg="$beg[size=$size_big][color=blue]"
end="[/color][/size]$end"
fi
space
putop "$beg ${mm.title} $end"
space
case ${mm.author} in
?*) IFS=:
set -- ${mm.author#:} : "$@"
IFS=$ifs
while :
do case $# in
0) break ;;
esac
x=$1
shift
case $x in
:) break ;;
esac
putop "$x"
done
;;
esac
case $mm_AU in
?*) putop "${mm_AU#?}"
case $mm_AF_cur in
?*) if (( tex ))
then mm_AF="${mm_AF_cur}[/i]"
else mm_AF="${mm_AF_cur}[/i]"
fi
;;
esac
case $mm_AF in
?*) putop "$mm_AF" ;;
esac
;;
esac
;;
esac
case $op in
.AS) heading $op Abstract
;;
.ce) case $# in
0) count=1 ;;
*) count=$1 ;;
esac
while (( count-- > 0 )) && read -r data
do putop "$data"
done
;;
.CE) ;;
.S[HS]) macros=man
while (( lists > 0 ))
do case ${type[lists--]} in
.S[HS]) break ;;
esac
done
type[++lists]=$op
list[lists]=DL
case $op in
.SS) type[++lists]=.XX
list[lists]=DL
;;
esac
case $op in
.SH) heading .H 2 "$@" ;;
*) heading .H 3 "$@" ;;
esac
type[++lists]=.XX
list[lists]=DL
;;
*) heading $op "$@"
;;
esac
;;
.AT) : ignore $op
;;
.AU) case $mm_AF_cur in
?*) case $mm_AF in
?*) case $mm_AU in
?*) mm_AU="${mm_AU}${mm_AF}" ;;
esac
;;
esac
if (( tex ))
then mm_AF="${mm_AF_cur}}"
else mm_AF="${mm_AF_cur}[/i]"
fi
mm_AF_cur=""
;;
esac
mm_AU="${mm_AU}$nl$1"
;;
.BL) i=
for ((n = 1; n <= lists; n++))
do i=$i${list[n]}
done
case $i in
*UL*UL*)i=disc ;;
*UL*) i=circle ;;
*) i=square ;;
esac
type[++lists]=.AL
list[lists]=UL
if (( tex ))
else putop "[list]"
fi
;;
.BP) unset parm
while [[ $1 == *=* ]]
do eval parm="( ${1%%=*}='${1#*=}' )"
shift
done
unset oparm
i=$1
then for i
do f=
for d in "${dirs[@]}"
do if [[ -f "$d$i" ]]
then f=$d$i
break
fi
done
if [[ ! $f ]]
fi
if [[ ! ${oparm.alt} ]]
then u=${i##*/}
u=${i%.*}
fi
if [[ ! ${oparm.title} ]]
then u=${i##*/}
u=${i%.*}
if [[ ${parm.category} ]]
then u="${parm.category} $u"
elif [[ ${oparm.category} ]]
then u="${oparm.category} $u"
fi
fi
putop "[img=\"$i\"]"
done
else i=${i%.*}.gif
esac
f=
for d in "${dirs[@]}"
do if [[ -f "$d$1" ]]
then f=$d$1
break
fi
done
if [[ ! $f ]]
elif [[ $f -nt $i ]]
then ps2gif $f $i
fi
putop "[img=\"$i\"]"
fi
;;
;;
.DE|.fi)
then nf=0
then putop "}</PRE>"
else putop "[/code]"
fi
fi
;;
then nf=1
else putop "[code]"
fi
fi
;;
man) ;;
esac
;;
then nf=0
then putop "}</PRE>"
else putop "[/code]"
fi
fi
if [[ $fg ]]
fi
fi
;;
then nf=1
else putop "[code]"
fi
fi
case $# in
2) fg="Figure $1: $2" ;;
*) fg= ;;
esac
;;
;;
fi
;;
;;
hp=
;;
esac
while :
esac
;;
*) break
;;
esac
done
;;
esac
fi
;;
;;
esac
;;
esac
then set -- "<PRE>\\$tt$*}</PRE>"
else set -- "[code]$*[/code]"
fi
;;
;;
esac
;;
esac
then getline
fi
then case $* in
esac
else case $* in
esac
fi
fi
;;
;;
then putopt '}'
else putop '[/list]'
fi
fi
case ${type[@]} in
then flush
else space
fi
.AL) break ;;
esac
done
;;
;;
esac
esac
fi
;;
;;
;;
;;
then putopn '\olist{'
else putop '[list]'
fi
;;
.OK) mm.keywords="$*"
;;
then x="$4\\b{-$1}\\i{$2}"
else x="$4[b]-$1[/b][i]$2[/i]"
fi
case $3 in
'[]') x="[ $x ]" ;;
?*) x="$x$3" ;;
esac
putop "$x"
;;
.PM) case ${html.company} in
esac
case $1 in
esac
then pm="\\blue{${pm}}"
else pm="[color=blue]${pm}[/color]"
fi
esac
;;
;;
;;
;;
title=1
esac
esac
case $4 in
esac
case $5 in
;;
*) sec=$5
;;
esac
;;
case ${html.title} in
esac
;;
esac
;;
;;
;;
;;
;;
;;
;;
;;
;;
end=..
0:*) ;;
*:.ig) end=$1 ;;
esac
while getline
do case $1 in
$end) break ;;
esac
done
;;
shift
;;
.f[tBILPR])
.f[BILPR])
set -- ${op#.f}
;;
esac
case $1 in
;;
;;
;;
then puttext "}"
fi
font=
;;
esac
;;
esac
if [[ $font ]]
fi
fi
;;
;;
;;
;;
;;
case $1 in
esac
;;
;;
;;
;;
;;
shift
;;
;;
then putop "\\-{"
else putop "[size=$size_small]"
fi
;;
then putop "\\+{"
fi
esac
;;
'') ;;
eval exec $fd'< $file'
file=$1
;;
esac
;;
do if [[ -f "$d$1" ]]
then expand "$d$1"
continue 2
fi
done
;;
;;
;;
;;
;;
;;
esac
;;
""|[\ \ ]*)
else prefix="[code]"
fi
while :
do case $1 in
*([\ \ ]))
1) leading= ;;
esac
;;
[\ \ ]*)
;;
break
;;
esac
getline || break
done
then putop "}</PRE>"
else putop "[/code]"
fi
;;
esac
;;
;;
esac
;;
;;
esac
done
case $references in
?*) heading .H 1 References
;;
esac
exit $code