########################################################################
# #
# 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=mm2twiki
USAGE=$'
[-?
@(#)$Id: mm2twiki (at&t research) 2010-05-28 $
]
[+DESCRIPTION?\bmm2twiki\b is a \bsed\b(1)/\bksh\b(1) script (yes!) that
converts input \bmm\b(1) or \bman\b(1) documents to a \btwiki\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 \btwiki\b markup style is [\aop\a]]\adata\a[/\aop\a]].]
[ 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
}
*) usage ;;
esac
done
shift OPTIND-1
case $# in
if [[ ! -f $file ]]
exit 1
fi
x="-m $file"
;;
*) x=
;;
esac
size_normal=12
size_big=18
dd=
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'\''%[[\1][\2]]%g' \
-e 's%\\h'\''0\*\\w"\(/[^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
-e 's%\\h'\''0\*\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
-e 's%\\h'\''0\*1'\''\([^:/'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
-e 's%\\h'\''0\*1'\''\([abcdefghijklmnopqrstuvwxyz]*:[^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
-e 's%\\h'\''0\*1'\''\(/[^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
-e 's%\\h'\''0\*1'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
-e 's%\\h'\''0/\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
-e 's%\\h'\''0/1'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\1]]%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]*]%*&*%g' \
-e 's%</*Z>%%g' \
-e 's%<[146789]>%%g' \
-e 's%</[146789]>%%g' \
-e 's%<2>%_%g' \
-e 's%</2>%_ %g' \
-e 's%<3>%*%g' \
-e 's%</3>%* %g' \
-e 's%<5>%=%g' \
-e 's%</5>%= %g' \
-e 's%<B>%*%g' \
-e 's%</B>%* %g' \
-e 's%<I>%_%g' \
-e 's%</I>%_ %g' \
-e 's%<L>%=%g' \
-e 's%</L>%= %g' \
-e 's%<X>%=%g' \
-e 's%</X>%= %g' \
-e 's%<CW>%=%g' \
-e 's%</CW>%= %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 ]]
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
;;
tar=" target=_top"
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
done
'') continue ;;
esac
break
;;
esac
;;
esac
set -- "${text[@]}"
op=$1
shift
2':('[0123456789]')'*([,.?!:;]))
x=${2#'('*')'}
y=${2%$x}
n=$y
.B*) font1=b ;;
*) font1=i ;;
esac
esac
break
;;
esac
;;
.F) op=.L ;;
esac
0:*) ;;
*:man:.?)
set -- "$*"
;;
esac
case $# in
0) getline
set -- "$*"
;;
esac
set -- "$indent""$@"
;;
font=
;;
esac
?) font2=R
;;
;;
esac
B) font1=* ;;
I) font1=_ ;;
R) font1= ;;
esac
B) font2=* ;;
I) font2=_ ;;
R) font2= ;;
esac
while :
do case $# in
0) break ;;
esac
esac
case $1 in
"") ;;
*"[size"*)
esac
;;
*"[size"*)
esac
shift
;;
esac
;;
esac
;;
esac
shift
done
font=
;;
0) pd= ;;
esac
continue
;;
;;
.SB) set -- "${text[@]}"
shift
case $# in
0) getline ;;
esac
set -A text -- "[size=$size_small]*""$@""*[/size]"
;;
.SG) continue
;;
.SM) set -- "${text[@]}"
shift
case $# in
0) getline ;;
esac
set -A text -- "[size=$size_small]""$@""[/size]"
;;
case $x in
?*) text[0]=$x ;;
esac
;;
esac
;;
;;
esac
break
done
trap 'set -- "${text[@]}"' 0
}
function heading
{
integer count
shift
.H) case $# in
0) count=1 ;;
*) count=$1; shift ;;
esac
;;
;;
*) count=2
;;
esac
case $* in
;;
*) space
beg=---+
done
;;
esac
}
function tbl_attributes
{
typeset d f i u x
typeset -F0 w
case $1 in
esac
case $i in
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
;;
esac
case X$i in
*[!0-9.][iI]*)
;;
esac
}
dirs[++ndirs]=""
for i
do if [[ -d $i ]]
then dirs[++ndirs]=$i/
if [[ $i == */* ]]
then dirs[++ndirs]=${i%/*}/
fi
fi
done
document="${files[@]}"
while :
do getline || {
set -- .TL
}
case $1 in
.) : comment
;;
.*) op=$1
shift
;;
;;
.AF) case $mm_AF_cur in
esac
;;
Rf="\\u[$reference]\\d"
references="$references$nl[list][$reference][/list]"
while getline
do case $1 in
.RF) break ;;
esac
done
continue
;;
esac
;;
[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ])
;;
esac
putop '[list]'
;;
;;
;;
esac
putop '[list]'
;;
esac
;;
then nf=0
putop "}"
fi
then ce=0
fi
hp=
;;
esac
while :
esac
;;
*) break
;;
esac
done
;;
esac
fi
end=
end="[/color][/size]$end"
?*) IFS=:
set -- ${mm.author#:} : "$@"
while :
do case $# in
0) break ;;
esac
x=$1
shift
case $x in
:) break ;;
esac
putop "$x"
done
;;
esac
?*) putop "${mm_AU#?}"
case $mm_AF_cur in
?*) mm_AF="${mm_AF_cur}[/i]"
;;
esac
esac
;;
esac
;;
esac
;;
0) count=1 ;;
*) count=$1 ;;
esac
done
;;
.CE) ;;
.S[HS]) break ;;
esac
done
;;
esac
esac
;;
;;
esac
;;
;;
.AU) case $mm_AF_cur in
esac
;;
esac
mm_AF="${mm_AF_cur}[/i]"
mm_AF_cur=""
;;
esac
;;
.BL) i=
do i=$i${list[n]}
done
case $i in
*) i=square ;;
esac
putop "[list]"
;;
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
putop "</verbatim>"
fi
;;
then nf=1
putop "<verbatim>"
fi
;;
man) ;;
esac
;;
then nf=0
putop "</verbatim>"
fi
if [[ $fg ]]
fi
;;
then nf=1
putop "<verbatim>"
fi
case $# in
2) fg="Figure $1: $2" ;;
*) fg= ;;
esac
;;
;;
;;
;;
hp=
;;
esac
while :
esac
;;
*) break
;;
esac
done
;;
esac
fi
;;
;;
esac
;;
esac
set -- "=$*="
;;
;;
esac
;;
esac
then getline
fi
case $* in
esac
fi
;;
;;
then putop '[/list]'
fi
case ${type[@]} in
.AL) break ;;
esac
done
;;
;;
esac
esac
;;
;;
;;
;;
putop '[list]'
;;
.OK) mm.keywords="$*"
;;
x="$4[b]-$1[/b][i]$2[/i]"
case $3 in
'[]') x="[ $x ]" ;;
?*) x="$x$3" ;;
esac
putop "$x"
;;
.PM) case ${html.company} in
esac
case $1 in
esac
?*) pm="[color=blue]${pm}[/color]"
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
;;
;;
;;
font=
;;
esac
;;
esac
if [[ $font ]]
fi
;;
;;
;;
;;
;;
case $1 in
esac
;;
;;
;;
;;
;;
shift
;;
;;
-*) putop "[size=$size_small]"
;;
;;
esac
;;
'') ;;
eval exec $fd'< $file'
file=$1
;;
esac
;;
do if [[ -f "$d$1" ]]
then cat "$d$1"
continue 2
fi
done
;;
;;
;;
;;
;;
;;
esac
;;
""|[\ \ ]*)
prefix="<verbatim>"
while :
do case $1 in
*([\ \ ]))
1) leading= ;;
esac
;;
[\ \ ]*)
;;
break
;;
esac
getline || break
done
;;
esac
;;
;;
esac
;;
;;
esac
done
case $references in
?*) heading .H 1 References
;;
esac
exit $code