54b4080058f553d0403ae202e060b555f8acbb47
[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     # fixup for perl bare words
40     s/{<-S><I>([a-zA-Z_][a-zA-Z0-9]*)<-I><S>}/{$1}/g;
41     # fixup for callbackfunctions
42     s/\\(&amp;[a-zA-Z_]+)/\\<-S><I>$1<-I><S>/;
43     # fixup for stringification
44     s/\$<-S><I>/<-S><I>\$/g;
45     # fixup for %d
46     s/%<-S><I>d<-I><S>\"/%d\"/;
47     s/%<-S><I>d<-I><S>\\<-S><I>n<-I><S>/%d\\n/;
48     # iterators
49     s/^ //;
50     s/ $//;
51     s/^(for (?:my )?)(\S+) /$1<-S><I>$2<-I><S> /;
52   }
53   $_ = "<S>$_<-S>";
54   s/<S>(\s*)<-S>/$1/g;
55   s/<-S>(\s*)<S>/$1/g;
56   s/<I>(\s*)<-I>/$1/g;
57   s/<-I>(\s*)<I>/$1/g;
58   s/<S>(\s+)/$1<S>/g;
59   s/(\s+)<-S>/<-S>$1/g;
60   s/<I>(\s+)/$1<I>/g;
61   s/(\s+)<-I>/<-I>$1/g;
62   s/<S>/$si/g;
63   s/<-S>/$so/g;
64   s/<I>/$ii/g;
65   s/<-I>/$io/g;
66   print "$in$_$out\n";
67 }