1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00
elinks/src/main/module.h

102 lines
2.7 KiB
C
Raw Permalink Normal View History

#ifndef EL__MAIN_MODULE_H
#define EL__MAIN_MODULE_H
#include "config/options.h"
#include "main/event.h"
#ifdef __cplusplus
extern "C" {
#endif
/* The module record */
struct module {
/* The name of the module. It needs to be unique in its class (ie. in
* the scope of root modules or submodules of one parent module). */
2022-01-14 15:08:04 -05:00
const char *name;
/* The options that should be registered for this module.
* The table should end with NULL_OPTION_INFO. */
bug 764: Initialize the right member of union option_value INIT_OPTION used to initialize union option_value at compile time by casting the default value to LIST_OF(struct option) *, which is the type of the first member. On sparc64 and other big-endian systems where sizeof(int) < sizeof(struct list_head *), this tended to leave option->value.number as zero, thus messing up OPT_INT and OPT_BOOL at least. OPT_LONG however tended to work right. This would be easy to fix with C99 designated initializers, but doc/hacking.txt says ELinks must be kept C89 compatible. Another solution would be to make register_options() read the value from option->value.tree (the first member), cast it back to the right type, and write it to the appropriate member; but that would still require somewhat dubious conversions between integers, data pointers, and function pointers. So here's a rather more invasive solution. Add struct option_init, which is somewhat similar to struct option but has non-overlapping members for different types of values, to ensure nothing is lost in compile-time conversions. Move unsigned char *path from struct option_info to struct option_init, and replace struct option_info with a union that contains struct option_init and struct option. Now, this union can be initialized with no portability problems, and register_options() then moves the values from struct option_init to their final places in struct option. In my x86 ELinks build with plenty of options configured in, this change bloated the text section by 340 bytes but compressed the data section by 2784 bytes, presumably because union option_info is a pointer smaller than struct option_info was. (cherry picked from elinks-0.12 commit e5f6592ee20780a61f70feeb1f9e17631b9c5835) Conflicts: src/protocol/fsp/fsp.c: All options had been removed in 0.13.GIT. src/protocol/smb/smb2.c: Ditto.
2009-08-15 15:39:07 -04:00
union option_info *options;
/* The event hooks that should be registered for this module.
* The table should end with NULL_EVENT_HOOK_INFO. */
struct event_hook_info *hooks;
/* Any submodules that this module contains. Order matters
* since it is garanteed that initialization will happen in
* the specified order and teardown in the reverse order.
* The table should end with NULL. */
struct module **submodules;
/* User data for the module. Undefined purpose. */
void *data;
/* Lifecycle functions */
/* This function should initialize the module. */
void (*init)(struct module *module);
/* This function should shutdown the module. */
void (*done)(struct module *module);
/* This function return name and version of the module if set. */
const char *(*getname)(struct module *module);
};
#define struct_module(name, options, hooks, submods, data, init, done, getname) \
{ name, options, hooks, submods, data, init, done, getname }
#define foreach_module(module, modules, i) \
for (i = 0, module = modules ? modules[i] : NULL; \
module; \
i++, module = modules[i])
/* The module table has to be NULL terminates */
static inline int
sizeof_modules(struct module **modules)
{
struct module *module;
int i;
foreach_module (module, modules, i) {
; /* m33p */
}
return i - 1;
}
#define foreachback_module(module, modules, i) \
for (i = sizeof_modules(modules); \
i >= 0 && (module = modules[i]); \
i--)
/* Interface for handling single modules */
void register_module_options(struct module *module);
void unregister_module_options(struct module *module);
void init_module(struct module *module);
void done_module(struct module *module);
/* Interface for handling builtin modules */
/* Builtin modules are initialised only when not connecting to a master
* terminal. */
extern struct module *builtin_modules[];
/* Main modules are initialised earlier and are not listed in Help -> About. */
extern struct module *main_modules[];
void register_modules_options(struct module *modules[]);
void unregister_modules_options(struct module *modules[]);
void init_modules(struct module *modules[]);
void done_modules(struct module *modules[]);
#ifdef __cplusplus
}
#endif
#endif