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