add enable_cache example to xombrero.conf
[xombrero.git] / txt2tooltip.pl
blobd2af2c0dc78fc8d2ec4d3cb43614c97919bf8729
1 #!/bin/perl
3 # Copyright (c) 2012 Todd T. Fries <todd@fries.net>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 # read in 'ascii2txt.pl' formatted man pages, spit out #defines for tooltips
19 use strict;
20 use warnings;
22 our $verbose = 0;
24 my $line;
25 my @lines;
26 my @states = ("prekewords", "keywords", "postkeywords");
27 my $state = 0;
29 my $tipname;
30 my @tipinfo;
31 my $tiplines;
32 while(<STDIN>) {
33 chomp($line = $_);
34 if ($state == 0) {
35 if ($line =~ /following keywords:$/) {
36 $state++;
38 next;
40 if ($state == 1) {
41 if ($line =~ /^$/) {
42 next;
44 if ($line =~ /^[A-Z]/) {
45 showtip($tipname,@tipinfo);
46 $state++;
47 next;
49 if ($line =~ /^ {11,11}([a-z_]+)[ ]*(.*)$/) {
50 showtip($tipname,@tipinfo);
51 $tiplines = 1;
52 $tipname = $1;
53 @tipinfo = ($2);
54 next;
56 if ($line =~ /^ {39,39}(.*)$/) {
57 push @tipinfo, $1;
62 sub showtip {
63 my ($tip,@info) = @_;
65 my $text;
66 my $count = 1;
68 if (!defined($tip) || length($tip) < 1) {
69 return;
72 my $fmt;
73 for my $line (@info) {
74 $line =~ s/&/&amp;/g;
75 $line =~ s/</&lt;/g;
76 $line =~ s/>/&gt;/g;
77 $line =~ s/"/&quot;/g;
78 $line =~ s/^ {6,6}/\\t/g;
79 $line =~ s/\\t {6,6}/\\t\\t/g;
80 $line =~ s/\\t {6,6}/\\t\\t/g;
81 if ($count > $#info) {
82 $fmt = " \"%s\"\n";
83 } else {
84 $fmt = " \"%s\\n\" \\\n";
86 $text .= sprintf $fmt,$line;
87 $count++;
90 $tip = uc($tip);
91 printf "#define TT_%s%s",$tip,$text;
93 exit(0);