1 <refentry id="glib-mkenums" lang="en">
4 <refentrytitle>glib-mkenums</refentrytitle>
5 <manvolnum>1</manvolnum>
6 <refmiscinfo class="manual">User Commands</refmiscinfo>
10 <refname>glib-mkenums</refname>
11 <refpurpose>C language enum description generation utility</refpurpose>
16 <command>glib-mkenums</command>
17 <arg choice="opt" rep="repeat">options</arg>
18 <arg choice="opt" rep="repeat">files</arg>
22 <refsect1><title>Description</title>
23 <para><command>glib-mkenums</command> is a small perl-script utility that parses C
24 code to extract enum definitions and produces enum descriptions based on text
25 templates specified by the user. Most frequently this script is used to
26 produce C code that contains enum values as strings so programs can provide
27 value name strings for introspection.
31 <refsect1><title>Invocation</title>
32 <para><command>glib-mkenums</command> takes a list of valid C code files as
33 input. The options specified control the text that is output, certain
34 substitutions are performed on the text templates for keywords enclosed
38 <refsect2><title>Options</title>
42 <term><option>--fhead</option> <replaceable>text</replaceable></term>
44 Put out <replaceable>text</replaceable> prior to processing input files.
49 <term><option>--fprod</option> <replaceable>text</replaceable></term>
51 Put out <replaceable>text</replaceable> everytime a new input file
57 <term><option>--ftail</option> <replaceable>text</replaceable></term>
59 Put out <replaceable>text</replaceable> after all input files have been
65 <term><option>--eprod</option> <replaceable>text</replaceable></term>
67 Put out <replaceable>text</replaceable> everytime an enum is encountered
73 <term><option>--vhead</option> <replaceable>text</replaceable></term>
75 Put out <replaceable>text</replaceable> before iterating over the set of
81 <term><option>--vprod</option> <replaceable>text</replaceable></term>
83 Put out <replaceable>text</replaceable> for every value of an enum.
88 <term><option>--vtail</option> <replaceable>text</replaceable></term>
90 Put out <replaceable>text</replaceable> after iterating over all values
96 <term><option>--comments</option> <replaceable>text</replaceable></term>
98 Template for auto-generated comments, the default (for C code generations) is
99 <literal>"/* @comment@ */"</literal>.
104 <term><option>--template</option> <replaceable>file</replaceable></term>
106 Read templates from the given file. The templates are enclosed in
107 specially-formatted C comments
109 /*** BEGIN section ***/
110 /*** END section ***/
112 where section may be <literal>file-header</literal>,
113 <literal>file-production</literal>, <literal>file-tail</literal>,
114 <literal>enumeration-production</literal>, <literal>value-header</literal>,
115 <literal>value-production</literal>, <literal>value-tail</literal> or
116 <literal>comment</literal>.
121 <term><option>--help</option></term>
123 Print brief help and exit.
128 <term><option>--version</option></term>
130 Print version and exit.
137 <refsect2><title>Production text substitutions</title>
139 Certain keywords enclosed in @ characters will be substituted in the
140 emitted text. For the substitution examples of the keywords below,
141 the following example enum definition is assumed:
145 PREFIX_THE_XVALUE = 1 << 3,
146 PREFIX_ANOTHER_VALUE = 1 << 4
151 <term>@EnumName@</term>
153 The name of the enum currently being processed, enum names are assumed to be
154 properly namespaced and to use mixed capitalization to separate
155 words (e.g. PrefixTheXEnum).
160 <term>@enum_name@</term>
162 The enum name with words lowercase and word-separated by underscores
163 (e.g. prefix_the_xenum).
168 <term>@ENUMNAME@</term>
170 The enum name with words uppercase and word-separated by underscores
171 (e.g. PREFIX_THE_XENUM).
176 <term>@ENUMSHORT@</term>
178 The enum name with words uppercase and word-separated by underscores,
179 prefix stripped (e.g. THE_XENUM).
184 <term>@VALUENAME@</term>
186 The enum value name currently being processed with words uppercase and
187 word-separated by underscores,
188 this is the assumed literal notation of enum values in the C sources
189 (e.g. PREFIX_THE_XVALUE).
194 <term>@valuenick@</term>
196 A nick name for the enum value currently being processed, this is usually
197 generated by stripping common prefix words of all the enum values of the
198 current enum, the words are lowercase and underscores are substituted by a
199 minus (e.g. the-xvalue).
204 <term>@valuenum@</term>
206 The integer value for the enum value currently being processed. This is
207 calculated by using <command>perl</command> to attempt to evaluate the
208 expression as it appears in the C source code. If evaluation fails then
209 <command>glib-mkenums</command> will exit with an error status, but this
210 only happens if <literal>@valuenum@</literal> appears in your value
211 production template. (Since: 2.26)
218 This is substituted either by "enum" or "flags", depending on whether the
219 enum value definitions contained bit-shift operators or not (e.g. flags).
226 The same as <literal>@type@</literal> with the first letter capitalized (e.g. Flags).
233 The same as <literal>@type@</literal> with all letters uppercased (e.g. FLAGS).
238 <term>@filename@</term>
240 The name of the input file currently being processed (e.g. foo.h).
245 <term>@basename@</term>
247 The base name of the input file currently being processed (e.g. foo.h). (Since: 2.22)
253 <refsect2><title>Trigraph extensions</title>
255 Some C comments are treated specially in the parsed enum definitions,
256 such comments start out with the trigraph sequence <literal>/*<</literal>
257 and end with the trigraph sequence <literal>>*/</literal>.
258 Per enum definition, the options "skip" and "flags" can be specified, to
259 indicate this enum definition to be skipped, or for it to be treated as
260 a flags definition, or to specify the common prefix to be stripped from
261 all values to generate value nicknames, respectively. The "lowercase_name"
262 option can be used to specify the word separation used in the *_get_type()
263 function. For instance, /*< lowercase_name=gnome_vfs_uri_hide_options >*/.
266 Per value definition, the options "skip" and "nick" are supported.
267 The former causes the value to be skipped, and the latter can be used to
268 specify the otherwise auto-generated nickname.
271 typedef enum /*< skip >*/
274 } PrefixThisEnumWillBeSkipped;
275 typedef enum /*< flags,prefix=PREFIX >*/
277 PREFIX_THE_ZEROTH_VALUE, /*< skip >*/
278 PREFIX_THE_FIRST_VALUE,
279 PREFIX_THE_SECOND_VALUE,
280 PREFIX_THE_THIRD_VALUE, /*< nick=the-last-value >*/
281 } PrefixTheFlagsEnum;
286 <refsect1><title>See also</title>
289 <refentrytitle>glib-genmarshal</refentrytitle>
290 <manvolnum>1</manvolnum>