420db7510e366a6f4821cd96f3f2cbd73951f3a3
[platform/upstream/libsolv.git] / doc / filters / xcode.pl
1 #!/usr/bin/perl
2
3 die("I only understand docbook\n") unless @ARGV && $ARGV[0] eq 'docbook';
4
5 #my $ii = '//';
6 #my $io = '//';
7
8 #my $si = '**';
9 #my $so = '**';
10
11 my $ii = '<emphasis>';
12 my $io = '</emphasis>';
13
14 my $si = '<emphasis role="strong">';
15 my $so = '</emphasis>';
16
17 while(<STDIN>) {
18   chomp;
19   my $in = '';
20   my $out = '';
21   s/^\s+//;
22   s/\s+$//;
23   if (/^(.*)(\s*\/\*.*?\*\/\s*?)$/) {
24     $out = $2;
25     $_ = $1;
26   }
27   if (/^(my\s+)(.*?)$/) {
28     $in = $1;
29     $_ = $2;
30   }
31   if (/(?<!\&gt);$/) {
32     $out = ";$out";
33     chop $_;
34   }
35   if (!/^[a-zA-Z0-9_]+$/) {
36     $_ = " $_";
37     $_ = "$_ ";
38     s/(?<=[^a-zA-Z_\&:\.\'\";])(?!solv\W|Solv\W|Pool\W)([\$\@[a-zA-Z_][a-zA-Z0-9_]*)(?=[^a-zA-Z0-9_\(;\[])(?!::)(?! [^=])/<-S><I>$1<-I><S>/g;
39     # small fixup for perl bare words
40     s/{<-S><I>([a-zA-Z_][a-zA-Z0-9]*)<-I><S>}/{$1}/g;
41     # small fixup for callbackfunctions
42     s/\\(&amp;[a-zA-Z_]+)/\\<-S><I>$1<-I><S>/;
43     # small fixup for stringification
44     s/\$<-S><I>/<-S><I>\$/g;
45     # iterators
46     s/^ //;
47     s/ $//;
48     s/^(for (?:my )?)(\S+) /$1<-S><I>$2<-I><S> /;
49   }
50   $_ = "<S>$_<-S>";
51   s/<S>(\s*)<-S>/$1/g;
52   s/<-S>(\s*)<S>/$1/g;
53   s/<I>(\s*)<-I>/$1/g;
54   s/<-I>(\s*)<I>/$1/g;
55   s/<S>(\s+)/$1<S>/g;
56   s/(\s+)<-S>/<-S>$1/g;
57   s/<I>(\s+)/$1<I>/g;
58   s/(\s+)<-I>/<-I>$1/g;
59   s/<S>/$si/g;
60   s/<-S>/$so/g;
61   s/<I>/$ii/g;
62   s/<-I>/$io/g;
63   print "$in$_$out\n";
64 }