source: trunk/third/gtk/gtk/maketypes.awk @ 14482

Revision 14482, 2.4 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14481, which included commits to RCS files with non-trunk default branches.
Line 
1
2BEGIN {
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
35function set_type (set_type_1)
36{
37  type_counter += 1;
38  type_name = set_type_1;
39  type_macro = "GTK_TYPE_";
40 
41  tmp = type_name;
42# OK, the following is ridiculous, and sed s///g would be far easier
43  gsub ("[A-Z]", "@&", tmp);
44  gsub ("[^A-Z]@", "&_", tmp);
45  gsub ("@", "", tmp);
46  gsub ("[A-Z][A-Z][A-Z][0-9a-z]", "@&", tmp);
47  gsub ("@..", "&_", tmp);
48  gsub ("@", "", tmp);
49  type_macro = type_macro toupper (tmp);
50  type_ident = "_" tolower (tmp);
51
52  sub ("^GTK_TYPE_GTK_", "GTK_TYPE_", type_macro);
53}
54
55function generate (generate_1)
56{
57  if (gen_macros)
58    {
59      printf ("extern GtkType %s;\n", type_macro);
60    }
61  if (gen_entries)
62    {
63      printf ("  { \"%s\", &%s,\n", type_name, type_macro);
64      if (generate_1 == "BOXED")
65        printf ("    GTK_TYPE_%s, NULL },\n", generate_1);
66      else
67        printf ("    GTK_TYPE_%s, %s_values },\n", generate_1, type_ident);
68    }
69  if (gen_vars)
70    {
71      printf ("GtkType %s = 0;\n", type_macro);
72    }
73}
74
75# skip scheme comments
76";" {
77  sub (";.*", "");
78}
79
80# parse keywords
81
82/\(define-enum/ {
83  if ($2 == "")
84    printf ("huh? define-enum keyword without arg?\n") > "/dev/stderr";
85  else
86    {
87      set_type($2);
88      generate("ENUM");
89    }
90}
91
92/\(define-flags/ {
93  if ($2 == "")
94    printf ("huh? define-flags keyword without arg?\n") > "/dev/stderr";
95  else
96    {
97      set_type($2);
98      generate("FLAGS");
99    }
100}
101
102/\(define-boxed/ {
103  if ($2 == "")
104    printf ("huh? define-boxed keyword without arg?\n") > "/dev/stderr";
105  else
106    {
107      set_type($2);
108      generate("BOXED");
109    }
110}
111
112END {
113  if (gen_macros)
114    printf("\n#define\tGTK_TYPE_NUM_BUILTINS\t(%u)\n", type_counter);
115}
Note: See TracBrowser for help on using the repository browser.