Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/html/mm2twiki.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1996-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# #
19
########################################################################
20
: mm2twiki - convert mm/man subset to twiki markups
21
22
# it keeps going and going ...
23
#
24
# \h'0*\w"URL"'HOT-TEXT\h'0' link goto with alternate url
25
# \h'0*1'HOT-TEXT\h'0' link goto
26
#
27
# .xx link="URL\tHOT-TEXT" link goto with url request
28
# .xx link="HOT-TEXT" link goto request
29
# .xx ref="URL\tMIME-TYPE" head link hint
30
31
command=mm2twiki
32
version='mm2twiki (AT&T Research) 2010-05-28' # NOTE: repeated in USAGE
33
LC_NUMERIC=C
34
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
35
0123) ARGV0="-a $command"
36
USAGE=$'
37
[-?
38
@(#)$Id: mm2twiki (at&t research) 2010-05-28 $
39
]
40
'$USAGE_LICENSE$'
41
[+NAME?mm2twiki - convert mm/man subset to twiki markups]
42
[+DESCRIPTION?\bmm2twiki\b is a \bsed\b(1)/\bksh\b(1) script (yes!) that
43
converts input \bmm\b(1) or \bman\b(1) documents to a \btwiki\b markups
44
document on the standard output. If \afile\a is omitted then the
45
standard input is read. \adir\a operands and directory components
46
of \afile\a operands are added to the included file search list.
47
The default \btwiki\b markup style is [\aop\a]]\adata\a[/\aop\a]].]
48
49
[ file ... ]
50
51
[+SEE ALSO?\bmm2html\b(1)]
52
'
53
;;
54
*) ARGV0=""
55
USAGE=' [ file ... ]'
56
;;
57
esac
58
59
set -o noglob
60
61
integer count row n s ndirs=0 nfiles=0
62
integer fd=0 head=2 line=0 lists=0 nest=0 peek=0 pp=0 so=0 soff=4
63
integer labels=0 reference=1 ce=0 nf=0 augment=0 tbl_ns=0 tbl_no=1 tbl_fd=1
64
typeset -Z2 page=01
65
typeset -u upper
66
typeset -x -l OP
67
typeset -x -A ds map nr outline
68
typeset cond dirs files fg frame label list prev text title type
69
typeset license html meta nl mm index authors vg references
70
typeset mm_AF mm_AF_cur mm_AF_old mm_AU tt
71
72
nl=$'\n'
73
74
html=(
75
H1=(
76
align=center
77
)
78
home=(
79
href=
80
)
81
index=(
82
left=
83
top=
84
)
85
logo=(
86
src=
87
)
88
width=96%
89
)
90
91
code=0
92
figure=1
93
file=
94
font=
95
frame=
96
framebody=
97
framelink=
98
framerefs=
99
hp=
100
ifs=${IFS-'
101
'}
102
inch=" "
103
indent=
104
indent_prev=
105
macros=
106
pd="$nl"
107
pm=
108
primary=".BL|.LI|.IX"
109
top=
110
vg_ps=20
111
112
usage()
113
{
114
OPTIND=0
115
getopts $ARGV0 "$USAGE" OPT '-?'
116
exit 2
117
}
118
119
while getopts $ARGV0 "$USAGE" OPT
120
do case $OPT in
121
*) usage ;;
122
esac
123
done
124
shift OPTIND-1
125
case $# in
126
1) file=$1
127
if [[ ! -f $file ]]
128
then print -u2 $command: $file: cannot read
129
exit 1
130
fi
131
x="-m $file"
132
;;
133
*) x=
134
;;
135
esac
136
137
ds[Cr]='&#169;'
138
ds[Dt]=$(date -f "%B %d, %Y" $x)
139
ds[Rf]="[$reference]"
140
ds[Rg]='&#174;'
141
ds[CM]='&#169;'
142
ds[RM]='&#174;'
143
size_small=9
144
size_normal=12
145
size_big=18
146
ds[SM]="[size=$size_small][b]SM[/b][/size]"
147
ds[TM]="[size=$size_small][b]TM[/b][/size]"
148
tt=code
149
dd=
150
151
map[.Cs]=.EX
152
map[.Ce]=.EE
153
map[.Sh]=.SH
154
map[.Ss]=.SS
155
map[.Tp]=.TP
156
157
H=H$(( head + 1 ))
158
159
function warning
160
{
161
print -u2 "$command: warning: ${file:+"$file: "}line $line:" "$@"
162
}
163
164
function getfiles
165
{
166
sed \
167
-e 's%\\".*%%' \
168
-e 's%\\(>=%>=%g' \
169
-e 's%\\(<=%<=%g' \
170
-e 's%\\'\''%'\''%g' \
171
-e 's%\\`%`%g' \
172
-e 's%\\+%+%g' \
173
-e 's%\\0% %g' \
174
-e 's%\\|% %g' \
175
-e 's%\\\^% %g' \
176
-e 's%\\ % %g' \
177
-e 's%\\(+-%\&#177;%g' \
178
-e 's%\\(-%=%g' \
179
-e 's%\\(ap%~%g' \
180
-e 's%\\(bu%\&#183;%g' \
181
-e 's%\\(bv%|%g' \
182
-e 's%\\(co%\&#169;%g' \
183
-e 's%\\(dg%\&#167;%g' \
184
-e 's%\\(fm%'\''%g' \
185
-e 's%\\(rg%\&#174;%g' \
186
-e 's%\\(sq%\&#164;%g' \
187
-e 's%\\(\*\([*`'\'']\)%\1%g' \
188
-e 's%\\\*\([*`'\'']\)%\1%g' \
189
-e 's%\\d\([^\\]*\)\\u%\1%g' \
190
-e 's%\\u\([^\\]*\)\\d%\1%g' \
191
-e 's%\\v\(.\)-\([^\\]*\)\1\(.*\)\\v\1+*\2\1%\3%g' \
192
-e 's%\\v\(.\)+*\([^\\]*\)\1\(.*\)\\v\1-\2\1%\3%g' \
193
-e 's%\\h'\''0\*\\w"\([abcdefghijklmnopqrstuvwxyz]*:[^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
194
-e 's%\\h'\''0\*\\w"\(/[^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
195
-e 's%\\h'\''0\*\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
196
-e 's%\\h'\''0\*1'\''\([^:/'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
197
-e 's%\\h'\''0\*1'\''\([abcdefghijklmnopqrstuvwxyz]*:[^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
198
-e 's%\\h'\''0\*1'\''\(/[^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
199
-e 's%\\h'\''0\*1'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
200
-e 's%\\h'\''0/\\w"\([^"]*\)"'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\2]]%g' \
201
-e 's%\\h'\''0/1'\''\([^'\'']*\)\\h'\''0'\''%[[\1][\1]]%g' \
202
-e 's%\\s+\(.\)\([^\\]*\)\\s-\1%[size='$size_big']\2[/size]%g' \
203
-e 's%\\s+\(.\)\([^\\]*\)\\s0%[size='$size_big']\2[/size]%g' \
204
-e 's%\\s-\(.\)\([^\\]*\)\\s+\1%[size='$size_small']\2[/size]%g' \
205
-e 's%\\s-\(.\)\([^\\]*\)\\s0%[size='$size_small']\2[/size]%g' \
206
-e 's%\\f(\(..\)\([^\\]*\)%<\1>\2</\1>%g' \
207
-e 's%\\f[PR]%\\fZ%g' \
208
-e 's%\\f\(.\)\([^\\]*\)%<\1>\2</\1>%g' \
209
-e 's%&lt;\([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789][-._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]*@[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.]*\)&gt;%[size='$size_small']\&lt;[url=mailto:\1]\1[/url]\&gt;[/size]%g' \
210
-e 's%\[[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]*[0123456789][0123456789][abcdefghijklmnopqrstuvwxyz]*]%*&*%g' \
211
-e 's%</*Z>%%g' \
212
-e 's%<[146789]>%%g' \
213
-e 's%</[146789]>%%g' \
214
-e 's%<2>%_%g' \
215
-e 's%</2>%_ %g' \
216
-e 's%<3>%*%g' \
217
-e 's%</3>%* %g' \
218
-e 's%<5>%=%g' \
219
-e 's%</5>%= %g' \
220
-e 's%<B>%*%g' \
221
-e 's%</B>%* %g' \
222
-e 's%<I>%_%g' \
223
-e 's%</I>%_ %g' \
224
-e 's%<L>%=%g' \
225
-e 's%</L>%= %g' \
226
-e 's%<X>%=%g' \
227
-e 's%</X>%= %g' \
228
-e 's%<CW>%=%g' \
229
-e 's%</CW>%= %g' \
230
-e 's%<i>\([^<]*\)</i>(\([0123456789]\))%[[../man\2/\1.html][\1]]\2%g' \
231
-e 's%<b>\([^<]*\)</b>(\([0123456789]\))%[[../man\2/\1.html][\1]]\2%g' \
232
-e 's%\\s+\(.\)\(.*\)\\s-\1%[size='$size_big']\2[/size]%g' \
233
-e 's%\\s-\(.\)\(.*\)\\s+\1%[size='$size_small']\2[/size]%g' \
234
-e 's%\\e%\&#0092;%g' \
235
-e '/^'\''[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]\>/s%.%.%' \
236
-e '/^\..*".*\\/s%\\[^\*][^(]%\\&%g' \
237
"$@"
238
}
239
240
fill=
241
spaced=1
242
243
function space
244
{
245
flush
246
if (( !spaced ))
247
then spaced=1
248
print
249
fi
250
}
251
252
function flush
253
{
254
if [[ $fill ]]
255
then print -r -- "${fill#?}" | fmt -w80
256
fill=
257
spaced=0
258
fi
259
}
260
261
function puttext
262
{
263
if ((nf))
264
then print -r -- "$*"
265
spaced=0
266
elif [[ $1 ]]
267
then fill="$fill $*"
268
else flush
269
space
270
fi
271
}
272
273
function putop
274
{
275
flush
276
if (( $# ))
277
then print -r -- "$*"
278
spaced=0
279
fi
280
}
281
282
function putopn
283
{
284
flush
285
if (( $# ))
286
then print -r -n -- "$*"
287
spaced=1
288
fi
289
}
290
291
function putopt
292
{
293
if [[ $1 ]]
294
then fill="$fill$*"
295
fi
296
}
297
298
function getline
299
{
300
integer i n
301
typeset data a c d q v x d
302
if (( peek ))
303
then (( peek = 0 ))
304
trap 'set -- "${text[@]}"' 0
305
return
306
fi
307
while :
308
do data=
309
while :
310
do IFS= read -r -u$fd a || {
311
if (( so > 0 ))
312
then eval exec $fd'>&-'
313
if (( ( fd = --so + soff ) == soff ))
314
then (( fd = 0 ))
315
fi
316
file=${so_file[so]}
317
line=${so_line[so]}
318
continue
319
fi
320
return 1
321
}
322
(( line++ ))
323
case $a in
324
*\\) x=${a%%+(\\)}
325
a=${a#"$x"}
326
if (( ! ( ${#a} & 1 ) ))
327
then data=$data$x$a
328
break
329
fi
330
data=$data$x${a%?}
331
;;
332
*\\\}) data=$data${a%??}
333
break
334
;;
335
*) data=$data$a
336
break
337
;;
338
esac
339
done
340
case $data in
341
*\\[n\*]*)
342
a= i=0
343
while :
344
do c=${data:i++:1}
345
case $c in
346
"") break
347
;;
348
\\) x=${data:i:1}
349
case $x in
350
[n\*]) (( i++ ))
351
c=${data:i++:1}
352
case $c in
353
\() c=${data:i:2}
354
(( i += 2 ))
355
;;
356
\[) c=${data:i}
357
c=${c%%]*}
358
(( i += ${#c} + 1 ))
359
x='*'
360
;;
361
esac
362
case $x in
363
n) a=$a${nr[$c]} ;;
364
*) a=$a${ds[$c]} ;;
365
esac
366
continue
367
;;
368
\\) a=$a$c
369
while :
370
do c=${data:i++:1}
371
case $c in
372
\\) ;;
373
*) break ;;
374
esac
375
a=$a$c
376
done
377
;;
378
esac
379
;;
380
esac
381
a=$a$c
382
done
383
data=$a
384
;;
385
esac
386
case $data in
387
.?*) case $data in
388
*[\"]*)
389
unset v
390
a= i=0 n=0 q=
391
while :
392
do c=${data:i++:1}
393
case $c in
394
"") break ;;
395
esac
396
case $c in
397
$q) q=
398
case $c in
399
\>) ;;
400
*) continue
401
;;
402
esac
403
;;
404
[\"\<]) case $q in
405
"") case $c in
406
\<) q=\>
407
;;
408
*) q=$c
409
continue
410
;;
411
esac
412
;;
413
esac
414
;;
415
\ |\ )
416
case $q in
417
"") case $a in
418
?*) v[n++]=$a
419
a=
420
;;
421
esac
422
continue
423
;;
424
esac
425
;;
426
esac
427
a=$a$c
428
done
429
case $a in
430
?*) v[n++]=$a ;;
431
esac
432
set -A text -- "${v[@]}"
433
;;
434
*) set -A text -- $data
435
;;
436
esac
437
case ${text[0]} in
438
.el|.ie|.if)
439
set -- "${text[@]}"
440
shift
441
x=$1
442
shift
443
case ${text[0]} in
444
.e*) if (( nest <= 0 ))
445
then warning "unmatched ${text[0]}"
446
n=0
447
else n=$(( ! ${cond[nest--]} ))
448
fi
449
;;
450
.i*) case $x in
451
!*) x=${x#?}
452
n=1
453
;;
454
*) n=0
455
;;
456
esac
457
case $x in
458
t|\'@(*)\'\1\'|+([\-+0123456789])=\1)
459
(( n = ! n ))
460
;;
461
+([\-+0123456789])=+([\-+0123456789]))
462
;;
463
[0123456789]*[0123456789])
464
(( n = $x ))
465
;;
466
esac
467
case ${text[0]} in
468
.ie) cond[++nest]=$n ;;
469
esac
470
;;
471
esac
472
if (( ! n ))
473
then case $@ in
474
\\\{*) while read -r -u$fd data
475
do (( line++ ))
476
case $data in
477
*\\\}) break ;;
478
esac
479
done
480
;;
481
esac
482
continue
483
fi
484
set -A text -- "$@"
485
case ${text[0]} in
486
\\\{*) text[0]=${text[0]#??} ;;
487
esac
488
;;
489
.so) x=${text[1]}
490
for d in "${dirs[@]}"
491
do if [[ -f "$d$x" ]]
492
then (( fd = so + soff ))
493
tmp=/tmp/m2h$$
494
getfiles "$d$x" > $tmp
495
eval exec $fd'< $tmp'
496
rm $tmp
497
so_file[so]=$file
498
file=$d$x
499
so_line[so]=$line
500
(( line = 0 ))
501
(( so++ ))
502
continue 2
503
fi
504
done
505
warning "$x: $op cannot read"
506
continue
507
;;
508
.xx) data=
509
set -- "${text[@]}"
510
shift
511
while :
512
do case $# in
513
0) break ;;
514
esac
515
nam=${1%%=*}
516
case $nam in
517
no?*) nam=${nam#no} val=0 ;;
518
*) val=${1#*=} ;;
519
esac
520
shift
521
case $nam in
522
label|link*|ref)
523
case $val in
524
*' '*)
525
url=${val%%' '*}
526
txt=${val#*' '}
527
;;
528
*'\\t'*)
529
url=${val%%'\\t'*}
530
txt=${val#*'\\t'}
531
;;
532
*) url=$val
533
txt=$val
534
;;
535
esac
536
case $url in
537
*[:/.]*) pfx= ;;
538
*) pfx='#' ;;
539
esac
540
case $url in
541
*'${html.'*'}'*)
542
eval url=\"$url\"
543
;;
544
esac
545
case $nam in
546
label) if (( labels >= 0 ))
547
then nam=name
548
label[labels++]=$txt
549
puttext "[[$url][$txt]]"
550
fi
551
;;
552
link*) tar=
553
case $nam in
554
link) case $frame$top$vg in
555
?*) case $url in
556
*([abcdefghijklmnopqrstuvwxyz]):*|/*)
557
tar=" target=_top"
558
;;
559
esac
560
;;
561
esac
562
;;
563
esac
564
nam=href
565
data="${data}[[$pfx$url][$txt]]"
566
;;
567
esac
568
;;
569
esac
570
done
571
case $data in
572
'') continue ;;
573
esac
574
set -A text -- "$data"
575
break
576
;;
577
esac
578
case ${text[0]} in
579
@($primary))
580
: primary macros take precedence
581
;;
582
.[BILMRUX]?([BILMRUX])|.F|.FR|.MW|.RF)
583
case $macros:${text[0]} in
584
mm:.RF) break ;;
585
esac
586
typeset font1 font2 op
587
set -- "${text[@]}"
588
op=$1
589
shift
590
case $op in
591
.[BIL]R)case $#:$2 in
592
2':('[0123456789]')'*([,.?!:;]))
593
x=${2#'('*')'}
594
y=${2%$x}
595
n=$y
596
case $op in
597
.B*) font1=b ;;
598
.L*) font1=$tt ;;
599
*) font1=i ;;
600
esac
601
case $macros in
602
man) set -A text -- "[[../man$n/$1.html][$1]]$y$x" ;;
603
*) set -A text -- "[[${html.man:=../man}/man$n/$1.html][$1]]$y$x" ;;
604
esac
605
break
606
;;
607
esac
608
;;
609
.F) op=.L ;;
610
.FR) op=.LR ;;
611
.MW) op=.L ;;
612
.RF) op=.RL ;;
613
esac
614
case $#:$macros:$op in
615
0:*) ;;
616
*:man:.?)
617
set -- "$*"
618
;;
619
esac
620
case $# in
621
0) getline
622
set -- "$*"
623
;;
624
esac
625
set -- "$indent""$@"
626
case $font in
627
"") data=
628
;;
629
?*) data="$font"
630
font=
631
;;
632
esac
633
font1=${op#.}
634
case $font1 in
635
?) font2=R
636
;;
637
*) font2=${font1#?}
638
font1=${font1%?}
639
;;
640
esac
641
case $font1 in
642
B) font1=* ;;
643
I) font1=_ ;;
644
[LMX]) font1== ;;
645
R) font1= ;;
646
esac
647
case $font2 in
648
B) font2=* ;;
649
I) font2=_ ;;
650
[LMX]) font2== ;;
651
R) font2= ;;
652
esac
653
font=$font2
654
while :
655
do case $# in
656
0) break ;;
657
esac
658
case $font in
659
$font2) font=$font1 ;;
660
*) font=$font2 ;;
661
esac
662
case $1 in
663
"") ;;
664
*"[size"*)
665
case $font in
666
"") data="$data$1" ;;
667
*) data="$data$font$1$font " ;;
668
esac
669
;;
670
*) case "$1 $2" in
671
*"[size"*)
672
case $font in
673
"") data="$data$1 $2" ;;
674
*) data="$data$font$1 $2$font " ;;
675
esac
676
shift
677
;;
678
*) case $font in
679
"") data="$data$1" ;;
680
*) data="$data$font$1$font " ;;
681
esac
682
;;
683
esac
684
;;
685
esac
686
shift
687
done
688
font=
689
set -A text -- $data
690
;;
691
.PD) case $1 in
692
0) pd= ;;
693
*) pd=$nl ;;
694
esac
695
continue
696
;;
697
.PF|.PH)continue
698
;;
699
.SB) set -- "${text[@]}"
700
shift
701
case $# in
702
0) getline ;;
703
esac
704
set -A text -- "[size=$size_small]*""$@""*[/size]"
705
;;
706
.SG) continue
707
;;
708
.SM) set -- "${text[@]}"
709
shift
710
case $# in
711
0) getline ;;
712
esac
713
set -A text -- "[size=$size_small]""$@""[/size]"
714
;;
715
*) x=${map[${text[0]}]}
716
case $x in
717
?*) text[0]=$x ;;
718
esac
719
;;
720
esac
721
;;
722
*) set -A text -- "$data"
723
;;
724
esac
725
break
726
done
727
trap 'set -- "${text[@]}"' 0
728
}
729
730
function heading
731
{
732
typeset op=$1 i o options beg
733
integer count
734
735
shift
736
case $op in
737
.H) case $# in
738
0) count=1 ;;
739
*) count=$1; shift ;;
740
esac
741
options=
742
;;
743
.H*|.AS)count=1
744
;;
745
*) count=2
746
;;
747
esac
748
case $* in
749
"") putop
750
;;
751
*) space
752
beg=---+
753
while (( count-- ))
754
do beg=$beg+
755
done
756
putop "$beg$*"
757
space
758
;;
759
esac
760
}
761
762
function tbl_attributes
763
{
764
typeset d f i u x
765
typeset -F0 w
766
case $1 in
767
[aAcC]*)a="$a align=center" ;;
768
[lL]*) a="$a align=left" ;;
769
[nN]*) a="$a align=right char=." ;;
770
[rR]*) a="$a align=right" ;;
771
esac
772
case $i in
773
*[wW]\(+([0-9.])*\)*)
774
x=${i##*[wW]\(}
775
x=${x%%\)*}
776
u=${x##+([0-9.])}
777
x=${x%$u}
778
case $u in
779
c) (( w=x*75/2.54 )) ;;
780
i) (( w=x*75 )) ;;
781
m) (( w=x*75*12/72 )) ;;
782
n) (( w=x*75*12/72/2 )) ;;
783
p) (( w=x*75/72 )) ;;
784
P) (( w=x*75/6 )) ;;
785
*) (( w=x*75*12/72/2 )) ;;
786
esac
787
a="$a width=$w"
788
;;
789
esac
790
case $i in
791
*[bB]*) b="$b*" e="*$e"
792
;;
793
esac
794
case X$i in
795
*[!0-9.][iI]*)
796
b="$b_" e="_$e"
797
;;
798
esac
799
}
800
801
dirs[++ndirs]=""
802
for i
803
do if [[ -d $i ]]
804
then dirs[++ndirs]=$i/
805
else files[++nfiles]=$i
806
if [[ $i == */* ]]
807
then dirs[++ndirs]=${i%/*}/
808
fi
809
fi
810
done
811
document="${files[@]}"
812
813
getfiles "${files[@]}" |
814
while :
815
do getline || {
816
[[ $title != '' ]] && break
817
set -- .TL
818
}
819
case $1 in
820
.) : comment
821
;;
822
.*) op=$1
823
shift
824
case $op in
825
.AC) : ignore $op
826
;;
827
.AE) : ignore $op
828
;;
829
.AF) case $mm_AF_cur in
830
"") mm_AF_cur="[i]$*" ;;
831
*) mm_AF_cur="${mm_AF_cur}${nl}$*" ;;
832
esac
833
;;
834
.AL|.[IR]S|.VL)
835
case $macros:$op in
836
mm:.RS)
837
Rf="\\u[$reference]\\d"
838
references="$references$nl[list][$reference][/list]"
839
while getline
840
do case $1 in
841
.RF) break ;;
842
esac
843
references="$references$nl$*"
844
done
845
(( reference++ ))
846
continue
847
;;
848
esac
849
type[++lists]=.AL
850
list[lists]=DL
851
case $op in
852
.AL) case $1 in
853
'') type[++lists]=.al
854
list[lists]=OL
855
;;
856
[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ])
857
type[++lists]=.al
858
list[lists]=OL
859
;;
860
esac
861
putop '[list]'
862
;;
863
.[IR]S) putop '[list]'
864
;;
865
.VL) case $1 in
866
?*) type[++lists]=.al
867
list[lists]=DL
868
;;
869
esac
870
putop '[list]'
871
;;
872
esac
873
;;
874
.AS|.H|.HU|.SH|.SS|.ce|.CE)
875
if ((nf))
876
then nf=0
877
putop "}"
878
fi
879
if ((ce))
880
then ce=0
881
fi
882
case $hp in
883
?*) indent=${indent#$hp}
884
hp=
885
;;
886
esac
887
if (( lists > pp ))
888
then case ${type[@]:0:lists} in
889
*.[Aa][Ll]*|*.[IiTt][Pp]*)
890
while :
891
do case ${type[lists]} in
892
.[Aa][Ll]|.[IiTt][Pp])
893
case ${type[lists]} in
894
.AL|.IP|.TP)break ;;
895
esac
896
;;
897
*) break
898
;;
899
esac
900
done
901
;;
902
esac
903
fi
904
(( pp = lists ))
905
end=
906
case ${mm.title} in
907
?*) beg="$beg[size=$size_big][color=blue]"
908
end="[/color][/size]$end"
909
space
910
putop "$beg ${mm.title} $end"
911
space
912
mm.title=
913
case ${mm.author} in
914
?*) IFS=:
915
set -- ${mm.author#:} : "$@"
916
IFS=$ifs
917
while :
918
do case $# in
919
0) break ;;
920
esac
921
x=$1
922
shift
923
case $x in
924
:) break ;;
925
esac
926
putop "$x"
927
done
928
;;
929
esac
930
case $mm_AU in
931
?*) putop "${mm_AU#?}"
932
case $mm_AF_cur in
933
?*) mm_AF="${mm_AF_cur}[/i]"
934
;;
935
esac
936
case $mm_AF in
937
?*) putop "$mm_AF" ;;
938
esac
939
;;
940
esac
941
;;
942
esac
943
case $op in
944
.AS) heading $op Abstract
945
;;
946
.ce) case $# in
947
0) count=1 ;;
948
*) count=$1 ;;
949
esac
950
while (( count-- > 0 )) && read -r data
951
do putop "$data"
952
done
953
;;
954
.CE) ;;
955
.S[HS]) macros=man
956
while (( lists > 0 ))
957
do case ${type[lists--]} in
958
.S[HS]) break ;;
959
esac
960
done
961
type[++lists]=$op
962
list[lists]=DL
963
case $op in
964
.SS) type[++lists]=.XX
965
list[lists]=DL
966
;;
967
esac
968
case $op in
969
.SH) heading .H 2 "$@" ;;
970
*) heading .H 3 "$@" ;;
971
esac
972
type[++lists]=.XX
973
list[lists]=DL
974
;;
975
*) heading $op "$@"
976
;;
977
esac
978
;;
979
.AT) : ignore $op
980
;;
981
.AU) case $mm_AF_cur in
982
?*) case $mm_AF in
983
?*) case $mm_AU in
984
?*) mm_AU="${mm_AU}${mm_AF}" ;;
985
esac
986
;;
987
esac
988
mm_AF="${mm_AF_cur}[/i]"
989
mm_AF_cur=""
990
;;
991
esac
992
mm_AU="${mm_AU}$nl$1"
993
;;
994
.BL) i=
995
for ((n = 1; n <= lists; n++))
996
do i=$i${list[n]}
997
done
998
case $i in
999
*UL*UL*)i=disc ;;
1000
*UL*) i=circle ;;
1001
*) i=square ;;
1002
esac
1003
type[++lists]=.AL
1004
list[lists]=UL
1005
putop "[list]"
1006
;;
1007
.BP) unset parm
1008
while [[ $1 == *=* ]]
1009
do eval parm="( ${1%%=*}='${1#*=}' )"
1010
shift
1011
done
1012
unset oparm
1013
oparm=$parm
1014
i=$1
1015
if [[ $i == *.@(gif|png) ]]
1016
then for i
1017
do f=
1018
for d in "${dirs[@]}"
1019
do if [[ -f "$d$i" ]]
1020
then f=$d$i
1021
break
1022
fi
1023
done
1024
if [[ ! $f ]]
1025
then print -u2 "$command: warning: $i: data file not found"
1026
fi
1027
if [[ ! ${oparm.alt} ]]
1028
then u=${i##*/}
1029
u=${i%.*}
1030
parm=( alt=$u )
1031
fi
1032
if [[ ! ${oparm.title} ]]
1033
then u=${i##*/}
1034
u=${i%.*}
1035
if [[ ${parm.category} ]]
1036
then u="${parm.category} $u"
1037
elif [[ ${oparm.category} ]]
1038
then u="${oparm.category} $u"
1039
fi
1040
parm=( title=$u )
1041
fi
1042
putop "[img=\"$i\"]"
1043
done
1044
else i=${i%.*}.gif
1045
case $frame in
1046
?*) [[ -f $frame-$i ]] && i=$frame-$i ;;
1047
esac
1048
f=
1049
for d in "${dirs[@]}"
1050
do if [[ -f "$d$1" ]]
1051
then f=$d$1
1052
break
1053
fi
1054
done
1055
if [[ ! $f ]]
1056
then print -u2 "$command: $1: data file not found"
1057
elif [[ $f -nt $i ]]
1058
then ps2gif $f $i
1059
fi
1060
putop "[img=\"$i\"]"
1061
fi
1062
;;
1063
.CT) : ignore $op
1064
;;
1065
.DE|.fi)
1066
if ((nf))
1067
then nf=0
1068
putop "</verbatim>"
1069
fi
1070
;;
1071
.DF|.DS|.nf)
1072
if ((!nf))
1073
then nf=1
1074
putop "<verbatim>"
1075
fi
1076
;;
1077
.DT) case $macros in
1078
man) ;;
1079
*) putop "${ds[Dt]}" ;;
1080
esac
1081
;;
1082
.EE)if ((nf))
1083
then nf=0
1084
putop "</verbatim>"
1085
fi
1086
if [[ $fg ]]
1087
then putop "[color=blue]$fg[/color]"
1088
fi
1089
indent=${indent#$inch}
1090
;;
1091
.EX)if ((!nf))
1092
then nf=1
1093
putop "<verbatim>"
1094
fi
1095
indent=$inch$indent
1096
case $# in
1097
2) fg="Figure $1: $2" ;;
1098
*) fg= ;;
1099
esac
1100
;;
1101
.FE) putop " ] "
1102
;;
1103
.FG) putop "[color=blue]Figure $figure: $*[/color]"
1104
(( figure++ ))
1105
;;
1106
.FS) putop " [ "
1107
;;
1108
.HP|.LP|.P|.PP)
1109
case $hp in
1110
?*) indent=${indent#$hp}
1111
hp=
1112
;;
1113
esac
1114
if (( lists > pp ))
1115
then case ${type[@]:0:lists} in
1116
*.[Aa][Ll]*|*.[IiTt][Pp]*)
1117
while :
1118
do case ${type[lists]} in
1119
.[Aa][Ll]|.[IiTt][Pp])
1120
case ${type[lists]} in
1121
.AL|.IP|.TP)break ;;
1122
esac
1123
;;
1124
*) break
1125
;;
1126
esac
1127
done
1128
;;
1129
esac
1130
fi
1131
(( pp = lists ))
1132
space
1133
;;
1134
.HY) : ignore $op
1135
;;
1136
.IP|.LI|.TF|.TP)
1137
case $macros:$op in
1138
mm:.TP) continue ;;
1139
esac
1140
case $op in
1141
.IP|.LP|.TF|.TP)OP=$op
1142
case ${type[lists]} in
1143
$op|$OP);;
1144
*) type[++lists]=$op
1145
list[lists]=DL
1146
putop
1147
;;
1148
esac
1149
case $op in
1150
.IP|.LP|.TF)
1151
set -- "=$*="
1152
;;
1153
.TP) getline
1154
;;
1155
esac
1156
;;
1157
esac
1158
if [[ ${list[lists]} ]]
1159
then if [[ ${list[lists]} == DL ]] && (( ! $# ))
1160
then getline
1161
fi
1162
case $* in
1163
'['*']'[[:alpnum:]]*) putopn "[*]$* " ;;
1164
'['*) putopn "[*]$*: " ;;
1165
'') putopn "[*] " ;;
1166
[[:alpnum:]]*) putopn "[*][b]$*[/b] " ;;
1167
*) putopn "[*][b]$*[/b]: " ;;
1168
esac
1169
else warning "$op: no current list"
1170
fi
1171
;;
1172
.IX) : ignore $op
1173
;;
1174
.LE|.[IR]E)
1175
if [[ $op == ".LE" ]]
1176
then putop '[/list]'
1177
fi
1178
case ${type[@]} in
1179
*.[Aa][Ll]*)
1180
space
1181
while (( lists > 0 ))
1182
do case ${type[lists--]} in
1183
.AL) break ;;
1184
esac
1185
done
1186
;;
1187
*) warning "$op: no current list type"
1188
;;
1189
esac
1190
case $op:$pd in
1191
.[IR]E:?*) putop ;;
1192
esac
1193
;;
1194
.LX) : ignore $op
1195
;;
1196
.MT) macros=mm
1197
;;
1198
.ND|.Dt)ds[Dt]=$*
1199
;;
1200
.NL) type[++lists]=.AL
1201
list[lists]=OL
1202
putop '[list]'
1203
;;
1204
.OK) mm.keywords="$*"
1205
;;
1206
.OP) : .OP opt arg arg-append arg-prepend
1207
x="$4[b]&#45;$1[/b][i]$2[/i]"
1208
case $3 in
1209
'[]') x="[ $x ]" ;;
1210
?*) x="$x$3" ;;
1211
esac
1212
putop "$x"
1213
;;
1214
.PM) case ${html.company} in
1215
'') pm= ;;
1216
*) pm="${html.company//\&/&amp\;} " ;;
1217
esac
1218
case $1 in
1219
'') pm= ;;
1220
C|NDA) pm="${pm}CONFIDENTIAL" ;;
1221
RG) pm="${pm}PROPRIETARY (REGISTERED)" ;;
1222
RS) pm="${pm}PROPRIETARY (RESTRICTED)" ;;
1223
*) pm="${pm}PROPRIETARY" ;;
1224
esac
1225
case $pm in
1226
?*) pm="[color=blue]${pm}[/color]"
1227
esac
1228
;;
1229
.PU) : ignore $op
1230
;;
1231
.SA) : ignore $op
1232
;;
1233
.SU) : ignore $op
1234
;;
1235
.TH|.TL): .TL junk junk
1236
: .TH item section foot_center foot_left head_center
1237
title=1
1238
case $macros:$op in
1239
:.TH) macros=man ;;
1240
:.TL) macros=mm ;;
1241
esac
1242
case $op in
1243
.TH) case $3 in
1244
?*) dc[++dcs]=$3 ;;
1245
esac
1246
case $4 in
1247
?*) dl[++dls]=$4 ;;
1248
esac
1249
case $5 in
1250
'') sec=$(set --'???'MAN=$2 2>&1)
1251
sec=$ver$msc$cmp$sec
1252
;;
1253
*) sec=$5
1254
;;
1255
esac
1256
mm.title="$sec -- $1($2)"
1257
;;
1258
.TL) getline || break
1259
case ${html.title} in
1260
'') mm.title=$* ;;
1261
esac
1262
;;
1263
esac
1264
;;
1265
.TM) : ignore $op
1266
;;
1267
.TX) : ignore $op
1268
;;
1269
.UC) : ignore $op
1270
;;
1271
.VE) : ignore $op
1272
;;
1273
.VS) : ignore $op
1274
;;
1275
.al) : ignore $op
1276
;;
1277
.bd) : ignore $op
1278
;;
1279
.br) putop
1280
;;
1281
.de|.am.ig)
1282
end=..
1283
case $#:$op in
1284
0:*) ;;
1285
*:.ig) end=$1 ;;
1286
esac
1287
: ignore $op to $end
1288
while getline
1289
do case $1 in
1290
$end) break ;;
1291
esac
1292
done
1293
;;
1294
.ds) op=$1
1295
shift
1296
ds[$op]=$*
1297
;;
1298
.f[tBILPR])
1299
case $op in
1300
.f[BILPR])
1301
set -- ${op#.f}
1302
;;
1303
esac
1304
case $1 in
1305
5|TT) font=$tt
1306
;;
1307
B) font=b$dd
1308
;;
1309
I) font=i$dd
1310
;;
1311
*) case $font in
1312
?*) puttext "$font"
1313
font=
1314
;;
1315
esac
1316
;;
1317
esac
1318
if [[ $font ]]
1319
then puttext "$font"
1320
fi
1321
;;
1322
.fp) : ignore $op
1323
;;
1324
.hc) : ignore $op
1325
;;
1326
.hw) : ignore $op
1327
;;
1328
.hy) : ignore $op
1329
;;
1330
.in) indent_prev=$indent
1331
case $1 in
1332
"") i=$indent_prev; indent_prev=$indent; indent=$i ;;
1333
-*) indent=${indent#$inch} ;;
1334
+*) indent=$inch$indent ;;
1335
*) indent=$inch ;;
1336
esac
1337
;;
1338
.lf) : ignore $op
1339
;;
1340
.ll) : ignore $op
1341
;;
1342
.ne) : ignore $op
1343
;;
1344
.nh) : ignore $op
1345
;;
1346
.nr) op=$1
1347
shift
1348
nr[$op]=$*
1349
;;
1350
.ns) : ignore $op
1351
;;
1352
.ps) case $1 in
1353
-*) putop "[size=$size_small]"
1354
;;
1355
+*) putop "[size=$size_big]"
1356
;;
1357
esac
1358
;;
1359
.sh) case $HTMLPATH in
1360
'') ;;
1361
*) (( fd = so + soff ))
1362
file=/tmp/m2h$$
1363
path=$PATH
1364
eval PATH=$HTMLPATH "$*" > $file
1365
PATH=$path
1366
eval exec $fd'< $file'
1367
rm $file
1368
so_file[so]=$file
1369
file=$1
1370
so_line[so]=$line
1371
(( line = 0 ))
1372
(( so++ ))
1373
;;
1374
esac
1375
;;
1376
.sn) for d in "${dirs[@]}"
1377
do if [[ -f "$d$1" ]]
1378
then cat "$d$1"
1379
continue 2
1380
fi
1381
done
1382
warning "$1: $op cannot read"
1383
;;
1384
.sp|.SP)space
1385
;;
1386
.ta) : ignore $op
1387
;;
1388
.ti) : ignore $op
1389
;;
1390
.ul) : ignore $op
1391
;;
1392
*) warning "$op: unknown op"
1393
;;
1394
esac
1395
;;
1396
""|[\ \ ]*)
1397
case $macros in
1398
man) leading=1
1399
prefix="<verbatim>"
1400
blank=
1401
while :
1402
do case $1 in
1403
*([\ \ ]))
1404
case $leading in
1405
1) leading= ;;
1406
*) blank=$'\n' ;;
1407
esac
1408
;;
1409
[\ \ ]*)
1410
puttext "$prefix$blank$inch$indent$*"
1411
blank=
1412
leading=
1413
prefix=
1414
;;
1415
*) (( peek = 1 ))
1416
break
1417
;;
1418
esac
1419
getline || break
1420
done
1421
case $prefix in
1422
"") putop "</verbatim>"
1423
;;
1424
esac
1425
;;
1426
*) puttext "$indent$*"
1427
;;
1428
esac
1429
;;
1430
*) puttext "$indent$*"
1431
;;
1432
esac
1433
done
1434
flush
1435
case $references in
1436
?*) heading .H 1 References
1437
puttext "$references"
1438
flush
1439
;;
1440
esac
1441
exit $code
1442
1443