1: #!/usr/bin/perl
2: # by david bird - to format stuff in this directory
3:
4: sub trim {
5: my $line = shift;
6: $line =~ s/^\s+//g;
7: $line =~ s/\s+$//g;
8: $line;
9: }
10:
11: sub man2wiki {
12: $r = 0;
13: $in_tp=0;
14: $in_tp_s=0;
15: $in_ex=0;
16: $nl=0;
17: $in_rs=0;
18:
19: $out='';
20:
21: while (<STDIN>) {
22: next if (/^\.\\\"/);
23: chop;
24:
25: $line = $_;
26:
27: $line = trim($line);
28:
29: if ($line =~ /^\.TH (.*)$/) {
30: $nl=0;
31: @a = split / /, $line;
32: $out .= "= [[CoovaChilli]] - ".trim($a[1])."(".trim($a[2]).") =\n";
33: } elsif ($line =~ /^\.SH (.*)$/) {
34: $nl=0;
35: $l = $1;
36: $l =~ s/"//g; #"
37: $out .= "\n== ".trim($l)." ==\n\n";
38: $in_ex = ($l eq 'EXAMPLES');
39: $in_tp_s=0;
40: } elsif ($line =~ /^\.B (.*)$/) {
41: $nl=0;
42: $l = $1;
43: $l =~ s/"//g; #"
44: if ($in_tp) {
45: $out .= "; '''".trim($l)."''' ";
46: } else {
47: $out .= "'''".trim($l)."''' ";
48: }
49: } elsif ($line =~ /^\.TP/) {
50: $nl=0;
51: $in_tp=1;
52: $in_tp_s=1;
53: } elsif ($line =~ /^\.BI (.*)$/) {
54: $nl=0;
55: $l = $1;
56: $l =~ s/"//g; #"
57: @a = split / /, $l, 2;
58: if ($in_tp) {
59: $out .= "; '''".trim($a[0])."''' ";
60: $out .= "''".trim($a[1])."'' " if ($a[1]);
61: } else {
62: $out .= "'''".trim($a[0])."''' ";
63: $out .= "''".trim($a[1])."'' ";
64: }
65: } elsif ($line =~ /^\.I (.*)$/) {
66: $nl=0;
67: $out .= " " if $in_ex;
68: $out .= "''".trim($1)."'' ";
69: $out .= "BACKSLASH" if $in_ex && $line =~ /\\$/;
70: $out .= "\n " if $in_ex;
71: $out .= "\n" if $in_tp_s && $nl;
72: } elsif ($line =~ /^\.LP/) {
73: } elsif ($line =~ /^\.RS/) {
74: # $out .= "\n<dl><dd>\n";
75: # $out .= "\n: ";
76: $out .= "\n<div style='margin-left:60px;'>\n";
77: $in_rs = 1;
78: } elsif ($line =~ /^\.RE/) {
79: # $out .= "\n</dd></dl>\n";
80: if ($in_rs) {
81: $out .= "\n</div>\n";
82: $in_rs = 0;
83: }
84: } elsif ($line =~ /^\.BR (.*)$/) {
85: $nl=0;
86: $link = trim($1);
87: if ($link =~ /chilli/) {
88: $out .= "[[CoovaChilli/$link|$link]] ";
89: } else {
90: $link =~ s/\s//g;
91: $out .= "'''$link'''";
92: }
93: } else {
94: if ($line =~ /^$/) {
95: if ($nl < 1) {
96: $out .= "\n\n";
97: }
98: $nl++;
99: $in_tp=0;
100: } else {
101: $nl=0;
102: if ($in_tp) {
103: $out .= ": ";
104: $in_tp=0;
105: }
106: $out .= "$line ";
107: $out .= "BACKSLASH\n " if ($in_ex && $line =~ /\\$/);
108: }
109: }
110: }
111:
112: $out =~ s/\n\n\n/\n\n/gs;
113: $out =~ s/\n\n\n/\n\n/gs;
114: $out =~ s/<[^\@>]+\@[^>]+>//sg;
115: $out =~ s/ , /, /gs;
116: $out =~ s/ \. /. /gs;
117: $out =~ s/\\//gs;
118: $out =~ s/BACKSLASH/\\/gs;
119:
120: print "<div style='float:right;'>__TOC__</div>\n";
121: print trim($out);
122: print "\n";
123: }
124:
125: sub attributes2wiki {
126: $r = 0;
127: while (<STDIN>) {
128: chop;
129: if (/^[a-zA-Z]/) {
130: @cols = split(/\s*:\s*/,$_,9);
131: print "|-";
132: print "style='background-color: #ddd;' " if ($r % 2);
133: print "\n";
134: $i = 0;
135: foreach (@cols) {
136: $l = 0;
137: print "| ";
138: print "style='font-weight:bold;border-right: solid 1px grey;' " if ($i < 1 && ++$l);
139: print "style='border-right: solid 1px grey;' " if ($i > 0 && $i < 8 && ++$l);
140: print "align='center' " if ($i > 1 && $i < 8 && ++$l);
141: print "align='right' " if ($i == 1 && ++$l);
142: print "nowrap='nowrap' " if ($i < 2 && ++$l);
143: print "| " if $l;
144: print $_;
145: print "\n";
146: $i++;
147: }
148: $r++;
149: }
150: }
151: }
152:
153: sub attributes2man {
154: $r = 0;
155:
156: $attributes='';
157: while (<STDIN>) {
158: chop;
159: if (/^[a-zA-Z]/) {
160: @cols = split(/\s*:\s*/,$_,9);
161: $attributes .= "\n";
162: $attributes .= ".TP\n";
163: $attributes .= ".B $cols[0] ($cols[1])\n";
164: $attributes .= $cols[8];
165: $attributes .= "\n";
166: $r++;
167: }
168: }
169:
170: $file = `cat chilli-radius.5.in`;
171: $file =~ s/\@ATTRIBUTES\@/$attributes/;
172:
173: print $file
174: }
175:
176: man2wiki() if ($ARGV[0] eq 'man2wiki');
177: attributes2wiki() if ($ARGV[0] eq 'attributes2wiki');
178: attributes2man() if ($ARGV[0] eq 'chilli-radius');
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>