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

Revision 14482, 2.9 KB checked in by ghudson, 25 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.
RevLine 
[14481]1
2BEGIN {
3  type_name = "";       # GtkEnumType
4  type_macro = "";      # GTK_TYPE_ENUM_TYPE
5  type_ident = "";      # _gtk_enum_type
6  type_flags = 0;
7  type_counter = 0;
8  delete value_names;   # GTK_ENUM_VALUE
9  delete value_nicks;   # enum-value
10  VI = 0;
11  gen_arrays = 0;
12  gen_defs = 0;
13  comment_file = "";
14 
15  for (i = 1; i < ARGC; i++)
16    {
17      if (ARGV[i] == "arrays")
18        gen_arrays = 1;
19      else if (ARGV[i] == "defs")
20        gen_defs = 1;
21      ARGV[i] = "";
22    }
23 
24  if (gen_arrays)
25    printf ("/* generated by makeenums.awk */\n\n");
26  else if (gen_defs)
27    printf (";; generated by makeenums.awk  ; -*- scheme -*-\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_name = set_type_1;
38  type_macro = "GTK_TYPE";
39  type_ident = "";
40  for (i = 0; i < length (type_name); i++)
41    {
42      ch = substr (type_name, i + 1, 1);
43      Ch = toupper (ch);
44      if (Ch == ch)
45        {
46          type_macro = type_macro "_" Ch;
47          type_ident = type_ident "_" tolower (ch);
48        }
49      else
50        {
51          type_macro = type_macro Ch;
52          type_ident = type_ident ch;
53        }
54    }
55}
56
57function set_value (set_value_1, set_value_2)
58{
59  value_names[VI] = set_value_1;
60  value_nicks[VI] = tolower (set_value_2);
61  while (match (value_nicks[VI], "_"))
62    sub ("_", "-", value_nicks[VI]);
63}
64
65function generate_arrays ()
66{
67  if (gen_arrays)
68    {
69      printf ("static GtkEnumValue %s_values[] = {\n", type_ident);
70      for (i = 0; i < VI; i++)
71        {
72          printf ("  { %s, \"%s\", \"%s\" },\n",
73                  value_names[i], value_names[i], value_nicks[i]);
74        }
75      printf ("  { 0, NULL, NULL }\n");
76      printf ("};\n");
77    }
78}
79
80function generate_defs ()
81{
82  if (gen_defs)
83    {
84      if (comment_file != "")
85        {
86          printf ("\n; enumerations from \"%s\"\n", comment_file);
87          comment_file = "";
88        }
89     
90      printf ("\n(define-%s %s",
91              type_flags ? "flags" : "enum",
92              type_name);
93      for (i = 0; i < VI; i++)
94        {
95          printf ("\n  (%s %s)",
96                  value_nicks[i], value_names[i]);
97        }
98      printf (")\n");
99    }
100}
101
102function basename (basename_1)
103{
104  sub ("\"", "", basename_1);
105  while (match (basename_1, "/"))
106    sub (".*/", "", basename_1);
107  sub ("\"", "", basename_1);
108  return basename_1;
109}
110
111# parse keywords
112
113/G_ENUM_E/ {
114  if ($3 != "+" || $5 != "+")
115    printf ("huh? G_ENUM_E keyword without arg?\n") > "/dev/stderr";
116  else
117    set_type($4);
118  type_flags = 0;
119
120  generate_defs();
121  generate_arrays();
122  VI = 0;
123}
124
125/G_ENUM_F/ {
126  if ($3 != "+" || $5 != "+")
127    printf ("huh? G_ENUM_F keyword without arg?\n") > "/dev/stderr";
128  else
129    set_type($4);
130  type_flags = 1;
131
132  generate_defs();
133  generate_arrays();
134  VI = 0;
135}
136
137/G_ENUM_V/ {
138  if ($2 != "+" || $4 != "+" || $6 != "+")
139    printf ("huh? G_ENUM_V keyword without arg?\n") > "/dev/stderr";
140  else
141    set_value($3, $5);
142  VI += 1;
143}
144
145# feature per file comments
146/# / {
147  comment_file = basename($3);
148}
149
150END {
151  printf("\n");
152}
Note: See TracBrowser for help on using the repository browser.