1 <refentry id="glib-mkenums" lang="en">
5 <productname>GObject</productname>
8 <contrib>Developer</contrib>
9 <firstname>Owen</firstname>
10 <surname>Taylor</surname>
16 <refentrytitle>glib-mkenums</refentrytitle>
17 <manvolnum>1</manvolnum>
18 <refmiscinfo class="manual">User Commands</refmiscinfo>
22 <refname>glib-mkenums</refname>
23 <refpurpose>C language enum description generation utility</refpurpose>
28 <command>glib-mkenums</command>
29 <arg choice="opt" rep="repeat">OPTION</arg>
30 <arg choice="opt" rep="repeat">FILE</arg>
34 <refsect1><title>Description</title>
35 <para><command>glib-mkenums</command> is a small perl-script utility that
36 parses C code to extract enum definitions and produces enum descriptions based
37 on text templates specified by the user. Most frequently this script is used to
38 produce C code that contains enum values as strings so programs can provide
39 value name strings for introspection.
42 <para><command>glib-mkenums</command> takes a list of valid C code files as
43 input. The options specified control the text that is output, certain
44 substitutions are performed on the text templates for keywords enclosed
48 <refsect2><title>Production text substitutions</title>
50 Certain keywords enclosed in @ characters will be substituted in the
51 emitted text. For the substitution examples of the keywords below,
52 the following example enum definition is assumed:
53 <informalexample><programlisting>
56 PREFIX_THE_XVALUE = 1 << 3,
57 PREFIX_ANOTHER_VALUE = 1 << 4
59 </programlisting></informalexample>
62 <term>@EnumName@</term>
64 The name of the enum currently being processed, enum names are assumed to be
65 properly namespaced and to use mixed capitalization to separate
66 words (e.g. PrefixTheXEnum).
71 <term>@enum_name@</term>
73 The enum name with words lowercase and word-separated by underscores
74 (e.g. prefix_the_xenum).
79 <term>@ENUMNAME@</term>
81 The enum name with words uppercase and word-separated by underscores
82 (e.g. PREFIX_THE_XENUM).
87 <term>@ENUMSHORT@</term>
89 The enum name with words uppercase and word-separated by underscores,
90 prefix stripped (e.g. THE_XENUM).
95 <term>@ENUMPREFIX@</term>
97 The prefix of the enum name (e.g. PREFIX).
102 <term>@VALUENAME@</term>
104 The enum value name currently being processed with words uppercase and
105 word-separated by underscores,
106 this is the assumed literal notation of enum values in the C sources
107 (e.g. PREFIX_THE_XVALUE).
112 <term>@valuenick@</term>
114 A nick name for the enum value currently being processed, this is usually
115 generated by stripping common prefix words of all the enum values of the
116 current enum, the words are lowercase and underscores are substituted by a
117 minus (e.g. the-xvalue).
122 <term>@valuenum@</term>
124 The integer value for the enum value currently being processed. This is
125 calculated by using <command>perl</command> to attempt to evaluate the
126 expression as it appears in the C source code. If evaluation fails then
127 <command>glib-mkenums</command> will exit with an error status, but this
128 only happens if <literal>@valuenum@</literal> appears in your value
129 production template. (Since: 2.26)
136 This is substituted either by "enum" or "flags", depending on whether the
137 enum value definitions contained bit-shift operators or not (e.g. flags).
144 The same as <literal>@type@</literal> with the first letter capitalized (e.g. Flags).
151 The same as <literal>@type@</literal> with all letters uppercased (e.g. FLAGS).
156 <term>@filename@</term>
158 The name of the input file currently being processed (e.g. foo.h).
163 <term>@basename@</term>
165 The base name of the input file currently being processed (e.g. foo.h). (Since: 2.22)
171 <refsect2><title>Trigraph extensions</title>
173 Some C comments are treated specially in the parsed enum definitions,
174 such comments start out with the trigraph sequence <literal>/*<</literal>
175 and end with the trigraph sequence <literal>>*/</literal>.
176 Per enum definition, the options "skip" and "flags" can be specified, to
177 indicate this enum definition to be skipped, or for it to be treated as
178 a flags definition, or to specify the common prefix to be stripped from
179 all values to generate value nicknames, respectively. The "underscore_name"
180 option can be used to specify the word separation used in the *_get_type()
181 function. For instance, /*< underscore_name=gnome_vfs_uri_hide_options >*/.
184 Per value definition, the options "skip" and "nick" are supported.
185 The former causes the value to be skipped, and the latter can be used to
186 specify the otherwise auto-generated nickname.
188 <informalexample><programlisting>
189 typedef enum /*< skip >*/
192 } PrefixThisEnumWillBeSkipped;
193 typedef enum /*< flags,prefix=PREFIX >*/
195 PREFIX_THE_ZEROTH_VALUE, /*< skip >*/
196 PREFIX_THE_FIRST_VALUE,
197 PREFIX_THE_SECOND_VALUE,
198 PREFIX_THE_THIRD_VALUE, /*< nick=the-last-value >*/
199 } PrefixTheFlagsEnum;
200 </programlisting></informalexample>
205 <refsect1><title>Options</title>
209 <term><option>--fhead</option> <replaceable>TEXT</replaceable></term>
211 Put out <replaceable>TEXT</replaceable> prior to processing input files.
216 <term><option>--fprod</option> <replaceable>TEXT</replaceable></term>
218 Put out <replaceable>TEXT</replaceable> everytime a new input file
224 <term><option>--ftail</option> <replaceable>TEXT</replaceable></term>
226 Put out <replaceable>TEXT</replaceable> after all input files have been
232 <term><option>--eprod</option> <replaceable>TEXT</replaceable></term>
234 Put out <replaceable>TEXT</replaceable> everytime an enum is encountered
240 <term><option>--vhead</option> <replaceable>TEXT</replaceable></term>
242 Put out <replaceable>TEXT</replaceable> before iterating over the set of
248 <term><option>--vprod</option> <replaceable>TEXT</replaceable></term>
250 Put out <replaceable>TEXT</replaceable> for every value of an enum.
255 <term><option>--vtail</option> <replaceable>TEXT</replaceable></term>
257 Put out <replaceable>TEXT</replaceable> after iterating over all values
263 <term><option>--comments</option> <replaceable>TEXT</replaceable></term>
265 Template for auto-generated comments, the default (for C code generations) is
266 <literal>"/* @comment@ */"</literal>.
271 <term><option>--template</option> <replaceable>FILE</replaceable></term>
273 Read templates from the given file. The templates are enclosed in
274 specially-formatted C comments
275 <informalexample><programlisting>
276 /*** BEGIN section ***/
277 /*** END section ***/
278 </programlisting></informalexample>
279 where section may be <literal>file-header</literal>,
280 <literal>file-production</literal>, <literal>file-tail</literal>,
281 <literal>enumeration-production</literal>, <literal>value-header</literal>,
282 <literal>value-production</literal>, <literal>value-tail</literal> or
283 <literal>comment</literal>.
288 <term><option>--identifier-prefix</option> <replaceable>PREFIX</replaceable></term>
290 Indicates what portion of the enum name should be intepreted as the
291 prefix (eg, the "<literal>Gtk</literal>" in
292 "<literal>GtkDirectionType</literal>"). Normally this will be figured
293 out automatically, but you may need to override the default if your
294 namespace is capitalized oddly.
299 <term><option>--symbol-prefix</option> <replaceable>PREFIX</replaceable></term>
301 Indicates what prefix should be used to correspond to the identifier
302 prefix in related C function names (eg, the "<literal>gtk</literal>"
303 in "<literal>gtk_direction_type_get_type</literal>". Equivalently,
304 this is the lowercase version of the prefix component of the enum
305 value names (eg, the "<literal>GTK</literal>" in
306 "<literal>GTK_DIR_UP</literal>". The default value is the identifier
307 prefix, converted to lowercase.
312 <term><option>--help</option></term>
314 Print brief help and exit.
319 <term><option>--version</option></term>
321 Print version and exit.
326 <term><option>--output=FILE</option></term>
328 Write output to FILE instead of stdout.
335 <refsect1><title>See also</title>
338 <refentrytitle>glib-genmarshal</refentrytitle>
339 <manvolnum>1</manvolnum>