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