2 * Copyright (C) 2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 let eps = ref api.api_entry_points in
31 let name = en.en_name in
33 (* Add an entry point wrap_<name>_enum_to_string. *)
34 let fname = sprintf "%s_enum_to_string" name in
36 let b = Buffer.create 512 in
37 bprintf b " switch (v) {\n";
40 bprintf b " case WRAP_%s_%s: return \"%s\";\n"
41 (String.uppercase name) (String.uppercase id) id;
43 bprintf b " default:\n";
44 bprintf b " set_error (\"unknown enum case %%d\", v);\n";
45 bprintf b " return NULL;\n";
56 ep_ftype = RStaticString, ["v", TEnum name, None], [];
57 ep_code = Some c_code;
61 eps := StringMap.add fname ep !eps;
63 (* Add an entry point wrap_<name>_string_to_enum. *)
64 let fname = sprintf "%s_string_to_enum" name in
66 let b = Buffer.create 512 in
69 bprintf b " if (STREQ (v, \"%s\"))\n" id;
70 bprintf b " return WRAP_%s_%s;\n"
71 (String.uppercase name) (String.uppercase id);
73 bprintf b " set_error (\"unknown enum case %%s\", v);\n";
74 bprintf b " return -1;\n";
84 ep_ftype = Return (TEnum name), ["v", TString, None], [];
85 ep_code = Some c_code;
89 eps := StringMap.add fname ep !eps
92 { api with api_entry_points = !eps }