Implement bash completion for gsettings
[platform/upstream/glib.git] / gio / makegioalias.pl
1 #!/usr/bin/perl -w
2
3 exit 0;
4
5 my $do_def = 0;
6
7 if (($#ARGV >= 0) && ($ARGV[0] eq "-def")) {
8     shift;
9     $do_def = 1;
10 }
11
12 print <<EOF;
13 /* Generated by makegioalias.pl */
14
15 #ifndef DISABLE_VISIBILITY
16
17 #include "glib.h"
18
19 #ifdef G_HAVE_GNUC_VISIBILITY
20
21 EOF
22
23 if ($do_def) {
24     print <<EOF
25 #undef IN_FILE
26 #define IN_FILE defined
27
28 #undef IN_HEADER
29 #define IN_HEADER(x) 1
30
31 EOF
32
33 else { 
34     print <<EOF
35 #define IN_FILE(x) 1
36 #define IN_HEADER defined
37
38 EOF
39 }
40
41 my $in_comment = 0;
42 my $in_skipped_section = 0;
43
44 while (<>) {
45
46   # ignore empty lines
47   next if /^\s*$/;
48
49   # skip comments
50   if ($_ =~ /^\s*\/\*/)
51   {
52       $in_comment = 1;
53   }
54   
55   if ($in_comment)
56   {
57       if ($_ =~  /\*\/\s$/)
58       {
59           $in_comment = 0;
60       }
61       
62       next;
63   }
64
65   # handle ifdefs
66   if ($_ =~ /^\#endif/)
67   {
68       if (!$in_skipped_section)
69       {
70           print $_;
71       }
72
73       $in_skipped_section = 0;
74
75       next;
76   }
77
78   if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
79   {
80       $in_skipped_section = 1;
81   }
82
83   if ($in_skipped_section)
84   {
85       next;
86   }
87
88   if ($_ =~ /^\#ifn?def\s+G/)
89   {
90       print $_;
91       
92       next;
93   }
94  
95   if ($_ =~ /^\#if.*(IN_FILE|IN_HEADER)/)
96   {
97       print $_;
98       
99       next;
100   }
101
102   chop;
103   my $str = $_;
104   my @words;
105   my $attributes = "";
106
107   @words = split(/ /, $str);
108   $str = shift(@words);
109   chomp($str);
110   my $alias = "IA__".$str;
111   
112   # Drop any Win32 specific .def file syntax,  but keep attributes
113   foreach $word (@words) {
114       $attributes = "$attributes $word" unless $word eq "PRIVATE";
115   }
116   
117   if (!$do_def) {
118     print <<EOF
119 extern __typeof ($str) $alias __attribute((visibility("hidden")))$attributes;
120 \#define $str $alias
121
122 EOF
123   }
124   else {
125     print <<EOF
126 \#undef $str 
127 extern __typeof ($str) $str __attribute((alias("$alias"), visibility("default")));
128
129 EOF
130   }
131 }
132
133 print <<EOF;
134
135 #endif /* G_HAVE_GNUC_VISIBILITY */
136 #endif /* DISABLE_VISIBILITY */
137 EOF
138
139