Adding upstream version 4.02+dfsg.
[syslinux-debian/hramrach.git] / com32 / lua / src / dmi.c
blobd0305333302796486b6e983c819ba14b3007c618
1 #include <stdlib.h>
2 #include <string.h>
4 #define ldmilib_c /* Define the library */
6 /* Include the Lua API header files */
7 #include "lua.h"
8 #include "lauxlib.h"
9 #include "lualib.h"
10 #include "dmi/dmi.h"
12 static int dmi_gettable(lua_State *L)
14 s_dmi dmi;
16 lua_newtable(L);
18 if ( ! dmi_iterate(&dmi) ) {
19 printf("No DMI Structure found\n");
20 return -1;
23 parse_dmitable(&dmi);
25 /* bios */
26 lua_pushstring(L, "bios.vendor");
27 lua_pushstring(L, dmi.bios.vendor);
28 lua_settable(L,-3);
30 lua_pushstring(L, "bios.version");
31 lua_pushstring(L, dmi.bios.version);
32 lua_settable(L,-3);
34 lua_pushstring(L, "bios.release_date");
35 lua_pushstring(L, dmi.bios.release_date);
36 lua_settable(L,-3);
38 lua_pushstring(L, "bios.bios_revision");
39 lua_pushstring(L, dmi.bios.bios_revision);
40 lua_settable(L,-3);
42 lua_pushstring(L, "bios.firmware_revision");
43 lua_pushstring(L, dmi.bios.firmware_revision);
44 lua_settable(L,-3);
46 lua_pushstring(L, "bios.address");
47 lua_pushnumber(L, dmi.bios.address);
48 lua_settable(L,-3);
50 lua_pushstring(L, "bios.runtime_size");
51 lua_pushnumber(L, dmi.bios.runtime_size);
52 lua_settable(L,-3);
54 lua_pushstring(L, "bios.runtime_size_unit");
55 lua_pushstring(L, dmi.bios.runtime_size_unit);
56 lua_settable(L,-3);
58 lua_pushstring(L, "bios.rom_size");
59 lua_pushnumber(L, dmi.bios.rom_size);
60 lua_settable(L,-3);
62 lua_pushstring(L, "bios.rom_size_unit");
63 lua_pushstring(L, dmi.bios.rom_size_unit);
64 lua_settable(L,-3);
66 /* system */
67 lua_pushstring(L, "system.manufacturer");
68 lua_pushstring(L, dmi.system.manufacturer);
69 lua_settable(L,-3);
71 lua_pushstring(L, "system.product_name");
72 lua_pushstring(L, dmi.system.product_name);
73 lua_settable(L,-3);
75 lua_pushstring(L, "system.version");
76 lua_pushstring(L, dmi.system.version);
77 lua_settable(L,-3);
79 lua_pushstring(L, "system.serial");
80 lua_pushstring(L, dmi.system.serial);
81 lua_settable(L,-3);
83 lua_pushstring(L, "system.uuid");
84 lua_pushstring(L, dmi.system.uuid);
85 lua_settable(L,-3);
87 lua_pushstring(L, "system.wakeup_type");
88 lua_pushstring(L, dmi.system.wakeup_type);
89 lua_settable(L,-3);
91 lua_pushstring(L, "system.sku_number");
92 lua_pushstring(L, dmi.system.sku_number);
93 lua_settable(L,-3);
95 lua_pushstring(L, "system.family");
96 lua_pushstring(L, dmi.system.family);
97 lua_settable(L,-3);
99 /* base_board */
100 lua_pushstring(L, "base_board.manufacturer");
101 lua_pushstring(L, dmi.base_board.manufacturer);
102 lua_settable(L,-3);
104 lua_pushstring(L, "base_board.product_name");
105 lua_pushstring(L, dmi.base_board.product_name);
106 lua_settable(L,-3);
108 lua_pushstring(L, "base_board.version");
109 lua_pushstring(L, dmi.base_board.version);
110 lua_settable(L,-3);
112 lua_pushstring(L, "base_board.serial");
113 lua_pushstring(L, dmi.base_board.serial);
114 lua_settable(L,-3);
116 lua_pushstring(L, "base_board.asset_tag");
117 lua_pushstring(L, dmi.base_board.asset_tag);
118 lua_settable(L,-3);
120 lua_pushstring(L, "base_board.location");
121 lua_pushstring(L, dmi.base_board.location);
122 lua_settable(L,-3);
124 lua_pushstring(L, "base_board.type");
125 lua_pushstring(L, dmi.base_board.type);
126 lua_settable(L,-3);
128 /* chassis */
129 lua_pushstring(L, "chassis.manufacturer");
130 lua_pushstring(L, dmi.chassis.manufacturer);
131 lua_settable(L,-3);
133 lua_pushstring(L, "chassis.type");
134 lua_pushstring(L, dmi.chassis.type);
135 lua_settable(L,-3);
137 lua_pushstring(L, "chassis.lock");
138 lua_pushstring(L, dmi.chassis.lock);
139 lua_settable(L,-3);
141 lua_pushstring(L, "chassis.version");
142 lua_pushstring(L, dmi.chassis.version);
143 lua_settable(L,-3);
145 lua_pushstring(L, "chassis.serial");
146 lua_pushstring(L, dmi.chassis.serial);
147 lua_settable(L,-3);
149 lua_pushstring(L, "chassis.asset_tag");
150 lua_pushstring(L, dmi.chassis.asset_tag);
151 lua_settable(L,-3);
153 lua_pushstring(L, "chassis.boot_up_state");
154 lua_pushstring(L, dmi.chassis.boot_up_state);
155 lua_settable(L,-3);
157 lua_pushstring(L, "chassis.power_supply_state");
158 lua_pushstring(L, dmi.chassis.power_supply_state);
159 lua_settable(L,-3);
161 lua_pushstring(L, "chassis.thermal_state");
162 lua_pushstring(L, dmi.chassis.thermal_state);
163 lua_settable(L,-3);
165 lua_pushstring(L, "chassis.security_status");
166 lua_pushstring(L, dmi.chassis.security_status);
167 lua_settable(L,-3);
169 lua_pushstring(L, "chassis.oem_information");
170 lua_pushstring(L, dmi.chassis.oem_information);
171 lua_settable(L,-3);
173 lua_pushstring(L, "chassis.height");
174 lua_pushnumber(L, dmi.chassis.height);
175 lua_settable(L,-3);
177 lua_pushstring(L, "chassis.nb_power_cords");
178 lua_pushnumber(L, dmi.chassis.nb_power_cords);
179 lua_settable(L,-3);
181 /* processor */
182 lua_pushstring(L, "processor.socket_designation");
183 lua_pushstring(L, dmi.processor.socket_designation);
184 lua_settable(L,-3);
186 lua_pushstring(L, "processor.type");
187 lua_pushstring(L, dmi.processor.type);
188 lua_settable(L,-3);
190 lua_pushstring(L, "processor.family");
191 lua_pushstring(L, dmi.processor.family);
192 lua_settable(L,-3);
194 lua_pushstring(L, "processor.manufacturer");
195 lua_pushstring(L, dmi.processor.manufacturer);
196 lua_settable(L,-3);
198 lua_pushstring(L, "processor.version");
199 lua_pushstring(L, dmi.processor.version);
200 lua_settable(L,-3);
202 lua_pushstring(L, "processor.external_clock");
203 lua_pushnumber(L, dmi.processor.external_clock);
204 lua_settable(L,-3);
206 lua_pushstring(L, "processor.max_speed");
207 lua_pushnumber(L, dmi.processor.max_speed);
208 lua_settable(L,-3);
210 lua_pushstring(L, "processor.current_speed");
211 lua_pushnumber(L, dmi.processor.current_speed);
212 lua_settable(L,-3);
214 lua_pushstring(L, "processor.signature.type");
215 lua_pushnumber(L, dmi.processor.signature.type);
216 lua_settable(L,-3);
218 lua_pushstring(L, "processor.signature.family");
219 lua_pushnumber(L, dmi.processor.signature.family);
220 lua_settable(L,-3);
222 lua_pushstring(L, "processor.signature.model");
223 lua_pushnumber(L, dmi.processor.signature.model);
224 lua_settable(L,-3);
226 lua_pushstring(L, "processor.signature.stepping");
227 lua_pushnumber(L, dmi.processor.signature.stepping);
228 lua_settable(L,-3);
230 lua_pushstring(L, "processor.signature.minor_stepping");
231 lua_pushnumber(L, dmi.processor.signature.minor_stepping);
232 lua_settable(L,-3);
234 lua_pushstring(L, "processor.voltage_mv");
235 lua_pushnumber(L, dmi.processor.voltage_mv);
236 lua_settable(L,-3);
238 lua_pushstring(L, "processor.status");
239 lua_pushstring(L, dmi.processor.status);
240 lua_settable(L,-3);
242 lua_pushstring(L, "processor.upgrade");
243 lua_pushstring(L, dmi.processor.upgrade);
244 lua_settable(L,-3);
246 lua_pushstring(L, "processor.cache1");
247 lua_pushstring(L, dmi.processor.cache1);
248 lua_settable(L,-3);
250 lua_pushstring(L, "processor.cache2");
251 lua_pushstring(L, dmi.processor.cache2);
252 lua_settable(L,-3);
254 lua_pushstring(L, "processor.cache3");
255 lua_pushstring(L, dmi.processor.cache3);
256 lua_settable(L,-3);
258 lua_pushstring(L, "processor.serial");
259 lua_pushstring(L, dmi.processor.serial);
260 lua_settable(L,-3);
262 lua_pushstring(L, "processor.part_number");
263 lua_pushstring(L, dmi.processor.part_number);
264 lua_settable(L,-3);
266 lua_pushstring(L, "processor.id");
267 lua_pushstring(L, dmi.processor.id);
268 lua_settable(L,-3);
270 /* set global variable: lua_setglobal(L, "dmitable"); */
272 /* return number of return values on stack */
273 return 1;
277 static int dmi_supported(lua_State *L)
279 s_dmi dmi;
281 if ( dmi_iterate(&dmi) ) {
282 lua_pushboolean(L, 1);
283 } else {
284 lua_pushboolean(L, 0);
286 return 1;
290 static const luaL_Reg dmilib[] = {
291 {"gettable", dmi_gettable},
292 {"supported", dmi_supported},
293 {NULL, NULL}
297 LUALIB_API int luaopen_dmi (lua_State *L) {
298 luaL_openlib(L, LUA_DMILIBNAME, dmilib, 0);
299 return 1;