]> Pileus Git - ~andy/gtk/blob - gtk/maketypes.awk
new functions gtk_selection_data_copy and gtk_selection_data_free.
[~andy/gtk] / gtk / maketypes.awk
1
2 BEGIN {
3   type_name = "";       # GtkEnumType
4   type_macro = "";      # GTK_TYPE_ENUM_TYPE
5   type_ident = "";      # _gtk_enum_type
6   type_counter = 0;
7   gen_macros = 0;
8   gen_entries = 0;
9   gen_vars = 0;
10   
11   for (i = 2; i < ARGC; i++)
12     {
13       if (ARGV[i] == "macros")
14         gen_macros = 1;
15       else if (ARGV[i] == "entries")
16         gen_entries = 1;
17       else if (ARGV[i] == "variables")
18         gen_vars = 1;
19       ARGV[i] = "";
20     }
21   
22   if (gen_macros)
23     printf ("/* type macros, generated by maketypes.awk */\n\n");
24   else if (gen_entries)
25     printf ("/* type entries, generated by maketypes.awk */\n\n");
26   else if (gen_vars)
27     printf ("/* type variables, generated by maketypes.awk */\n\n");
28   else
29     {
30       printf ("hm? what do you want me to do?\n") > "/dev/stderr";
31       exit 1;
32     }
33 }
34
35 function set_type (set_type_1)
36 {
37   type_counter += 1;
38   type_name = set_type_1;
39   type_macro = "GTK_TYPE";
40   type_ident = "";
41   for (i = 0; i < length (type_name); i++)
42     {
43       ch = substr (type_name, i + 1, 1);
44       Ch = toupper (ch);
45       if (Ch == ch)
46         {
47           type_macro = type_macro "_" Ch;
48           type_ident = type_ident "_" tolower (ch);
49         }
50       else
51         {
52           type_macro = type_macro Ch;
53           type_ident = type_ident ch;
54         }
55     }
56   sub ("^GTK_TYPE_GTK_", "GTK_TYPE_", type_macro);
57 }
58
59 function generate (generate_1)
60 {
61   if (gen_macros)
62     {
63       printf ("extern GtkType %s;\n", type_macro);
64     }
65   if (gen_entries)
66     {
67       printf ("  { \"%s\", &%s,\n", type_name, type_macro);
68       if (generate_1 == "BOXED")
69         printf ("    GTK_TYPE_%s, NULL },\n", generate_1);
70       else
71         printf ("    GTK_TYPE_%s, %s_values },\n", generate_1, type_ident);
72     }
73   if (gen_vars)
74     {
75       printf ("GtkType %s = 0;\n", type_macro);
76     }
77 }
78
79 # skip scheme comments
80 ";" {
81   sub (";.*", "");
82 }
83
84 # parse keywords
85
86 /\(define-enum/ {
87   if ($2 == "")
88     printf ("huh? define-enum keyword without arg?\n") > "/dev/stderr";
89   else
90     {
91       set_type($2);
92       generate("ENUM");
93     }
94 }
95
96 /\(define-flags/ {
97   if ($2 == "")
98     printf ("huh? define-flags keyword without arg?\n") > "/dev/stderr";
99   else
100     {
101       set_type($2);
102       generate("FLAGS");
103     }
104 }
105
106 /\(define-boxed/ {
107   if ($2 == "")
108     printf ("huh? define-boxed keyword without arg?\n") > "/dev/stderr";
109   else
110     {
111       set_type($2);
112       generate("BOXED");
113     }
114 }
115
116 END {
117   if (gen_macros)
118     printf("\n#define\tGTK_TYPE_NUM_BUILTINS\t(%u)\n", type_counter);
119 }