summaryrefslogtreecommitdiff
path: root/bin/man2html1.awk
blob: a780ab70c9ff1e6f8f607d75d4a5d76a4531fd96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/nawk


# defining macros - eat them 
/^\.de.*/ {
        getline
        while ( $0 !~ "^\.\.$" )
        {
            getline
        }
        getline
    }

# eat [nt]roff comments
$0 ~ /['.][\/\\]"/ || $1 == "'"    { next }

# remove sidebar macros
$1 == ".VS" || $1 == ".VE" || $1 == ".AS"  { next }


# handle first .SH as special case - .SH NAME
/^.SH *NAME */ {
        getline
        while ( $0 ~ /\.[a-zA-Z].*/ )   # eat dot-cmd following title 
        {
            getline
        }
        print "<TITLE>" $0 "</TITLE>"
        print "<H1>" $0 "</H1>\n"
        next

#-e 's/^.SH *NAME */{N;s#.*\n\(.*\)#<H1>\1</H1>#;}' \
    }


# Convert .IP Paragraphs upto next .cmd to hanging indents
#       using <DL></DL> pairs without intervening <LI>

/^\.IP */ {
        if ( inIP > 0 )
        {
            print "</DL>"
        }
        inIP = 1 
	startIP = 1
        print "<DL>"
        match($0, /".*"/ )
        if ( RSTART > 0 )
        {
            arg = substr( $0, RSTART+1, RLENGTH-2)
            
            print "<DT> " arg
        }
        else if ( length( $2 ) > 0 )
        {
            print "<DT> " $2
        }
        next
    }

$0 ~ /^\.[a-zA-Z]*/ && inIP > 0 {
        inIP = 0
        print "</DL>"
    }

# Convert 
# .TP
# Line1
# line 2 - n
# .Any              
#
# to
# <DL>
# <DT> Line1
# <DD> lines 2 - n 
# <DT>

/^\.TP */ {
        if ( inTP > 0 )
        {
            print "</DL>"
        }
        inTP = 1 
        print "<DL>"
        next
    }

inTP == 1 && $1 !~ /\.[a-zA-Z]*/ {
        print "<DT> " $0
        inTP = 2
        next
    }

inTP == 2 && $1 !~ /\.[a-zA-Z]*/{
        print "</I></B>"    # Belt and suspenders
        print "<DD> " $0
        inTP = 3
        next
    }

$0 ~ /^\.[a-zA-Z]*/ && inTP > 0 {
        inTP = 0
        print "</DL>"
    }



$1 == ".AP" {
        $1=""
        print "<DL >"
        print "<DT> " $2 "\t\t" $3 "\t\t("$4")"
        inTP = 2
        next
    }

# make a blank line 
$1 == ".sp" {
        print "<BR>"
        next #        print "<BR>"
    }


$1 == ".ta"  { next }

# just pass everything else on

    {
        if ( startIP > 0 )
        {
            print "<DD> " $0
	    startIP = 0
        }
	else
	{
    	    print $0
	}
    }