X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fentry.c;h=f259673c5b1cb81be0a636139503ff9b6f510671;hb=df85fc8b8befb1a0cc8b8007d99d82bfac26b249;hp=028fd10d466ecf6862fbf42f692f26e80b762bea;hpb=824bc1c03688269e0a33c0e5e2459f81dc907f0b;p=vlc diff --git a/src/modules/entry.c b/src/modules/entry.c index 028fd10d46..f259673c5b 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -28,12 +28,25 @@ #include #include +#ifdef ENABLE_NLS +# include +#endif + #include "modules/modules.h" #include "config/configuration.h" #include "libvlc.h" -#ifndef ENABLE_NLS -# define dgettext(d, m) ((char *)(m)) + +static const char *mdgettext (const char *domain, const char *msg) +{ + assert (msg); +#ifdef ENABLE_NLS + if (*msg) /* Do not translate ""! */ + return dgettext (domain, msg); +#else + VLC_UNUSED(domain); #endif + return msg; +} static void vlc_module_destruct (gc_object_t *obj) { @@ -110,8 +123,9 @@ module_t *vlc_submodule_create (module_t *module) module->submodule_count++; /* Muahahaha! Heritage! Polymorphism! Ugliness!! */ - memcpy (submodule->pp_shortcuts, module->pp_shortcuts, - sizeof (submodule->pp_shortcuts)); + submodule->pp_shortcuts[0] = module->pp_shortcuts[0]; /* object name */ + for (unsigned i = 1; i < MODULE_SHORTCUT_MAX; i++) + submodule->pp_shortcuts[i] = NULL; submodule->psz_object_name = strdup( module->psz_object_name ); submodule->psz_shortname = module->psz_shortname; @@ -123,15 +137,63 @@ module_t *vlc_submodule_create (module_t *module) return submodule; } +static module_config_t *vlc_config_create (module_t *module, int type) +{ + unsigned confsize = module->confsize; + module_config_t *tab = module->p_config; + + if ((confsize & 0xf) == 0) + { + tab = realloc (tab, (confsize + 17) * sizeof (*tab)); + if (tab == NULL) + return NULL; + + module->p_config = tab; + } + + memset (tab + confsize, 0, sizeof (tab[confsize])); + tab[confsize].i_type = type; + tab[confsize].p_lock = &module->lock; + + if (type & CONFIG_ITEM) + { + module->i_config_items++; + if (type == CONFIG_ITEM_BOOL) + module->i_bool_items++; + } + + module->confsize++; + return tab + confsize; +} + -int vlc_module_set (module_t *module, int propid, ...) +int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) { va_list ap; - int ret = VLC_SUCCESS; + int ret = 0; va_start (ap, propid); switch (propid) { + case VLC_SUBMODULE_CREATE: + { + module_t **pp = va_arg (ap, module_t **); + *pp = vlc_submodule_create (module); + if (*pp == NULL) + ret = -1; + break; + } + + case VLC_CONFIG_CREATE: + { + int type = va_arg (ap, int); + module_config_t **pp = va_arg (ap, module_config_t **); + *pp = vlc_config_create (module, type); + if (*pp == NULL) + ret = -1; + break; + } + case VLC_MODULE_CPU_REQUIREMENT: assert (!module->b_submodule); module->i_cpu |= va_arg (ap, int); @@ -141,11 +203,8 @@ int vlc_module_set (module_t *module, int propid, ...) { unsigned i; for (i = 0; module->pp_shortcuts[i] != NULL; i++); - if (i >= (MODULE_SHORTCUT_MAX - 1)) - { - ret = VLC_ENOMEM; - break; - } + if (i >= (MODULE_SHORTCUT_MAX - 1)) + break; module->pp_shortcuts[i] = va_arg (ap, char *); break; @@ -187,7 +246,7 @@ int vlc_module_set (module_t *module, int propid, ...) const char *domain = va_arg (ap, const char *); if (domain == NULL) domain = PACKAGE; - module->psz_shortname = dgettext (domain, va_arg (ap, char *)); + module->psz_shortname = mdgettext (domain, va_arg (ap, char *)); break; } @@ -196,7 +255,7 @@ int vlc_module_set (module_t *module, int propid, ...) const char *domain = va_arg (ap, const char *); if (domain == NULL) domain = PACKAGE; - module->psz_longname = dgettext (domain, va_arg (ap, char *)); + module->psz_longname = mdgettext (domain, va_arg (ap, char *)); break; } @@ -205,59 +264,10 @@ int vlc_module_set (module_t *module, int propid, ...) const char *domain = va_arg (ap, const char *); if (domain == NULL) domain = PACKAGE; - module->psz_help = dgettext (domain, va_arg (ap, char *)); + module->psz_help = mdgettext (domain, va_arg (ap, char *)); break; } - default: - fprintf (stderr, "LibVLC: unknown module property %d", propid); - fprintf (stderr, "LibVLC: too old to use this module?"); - ret = VLC_EGENERIC; - break; - } - va_end (ap); - return ret; -} - -module_config_t *vlc_config_create (module_t *module, int type) -{ - unsigned confsize = module->confsize; - module_config_t *tab = module->p_config; - - if ((confsize & 0xf) == 0) - { - tab = realloc (tab, (confsize + 17) * sizeof (*tab)); - if (tab == NULL) - return NULL; - - module->p_config = tab; - } - - memset (tab + confsize, 0, sizeof (tab[confsize])); - tab[confsize].i_type = type; - tab[confsize].p_lock = &module->lock; - - if (type & CONFIG_ITEM) - { - module->i_config_items++; - if (type == CONFIG_ITEM_BOOL) - module->i_bool_items++; - } - - module->confsize++; - return tab + confsize; -} - -int vlc_config_set (module_config_t *restrict item, int id, ...) -{ - int ret = -1; - va_list ap; - - assert (item != NULL); - va_start (ap, id); - - switch (id) - { case VLC_CONFIG_NAME: { const char *name = va_arg (ap, const char *); @@ -266,7 +276,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) assert (name != NULL); item->psz_name = strdup (name); item->pf_callback = cb; - ret = 0; break; } @@ -276,14 +285,12 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) { item->orig.i = item->saved.i = item->value.i = va_arg (ap, int); - ret = 0; } else if (IsConfigFloatType (item->i_type)) { item->orig.f = item->saved.f = item->value.f = va_arg (ap, double); - ret = 0; } else if (IsConfigStringType (item->i_type)) @@ -292,7 +299,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) item->value.psz = value ? strdup (value) : NULL; item->orig.psz = value ? strdup (value) : NULL; item->saved.psz = value ? strdup (value) : NULL; - ret = 0; } break; } @@ -305,72 +311,60 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) { item->min.i = va_arg (ap, int); item->max.i = va_arg (ap, int); - ret = 0; } else if (IsConfigFloatType (item->i_type)) { item->min.f = va_arg (ap, double); item->max.f = va_arg (ap, double); - ret = 0; } break; } case VLC_CONFIG_ADVANCED: item->b_advanced = true; - ret = 0; break; case VLC_CONFIG_VOLATILE: item->b_unsaveable = true; - ret = 0; break; case VLC_CONFIG_PERSISTENT: item->b_autosave = true; - ret = 0; break; case VLC_CONFIG_RESTART: item->b_restart = true; - ret = 0; break; case VLC_CONFIG_PRIVATE: item->b_internal = true; - ret = 0; break; case VLC_CONFIG_REMOVED: item->b_removed = true; - ret = 0; break; case VLC_CONFIG_CAPABILITY: { const char *cap = va_arg (ap, const char *); item->psz_type = cap ? strdup (cap) : NULL; - ret = 0; break; } case VLC_CONFIG_SHORTCUT: item->i_short = va_arg (ap, int); - ret = 0; break; case VLC_CONFIG_OLDNAME: { const char *oldname = va_arg (ap, const char *); item->psz_oldname = oldname ? strdup (oldname) : NULL; - ret = 0; break; } case VLC_CONFIG_SAFE: item->b_safe = true; - ret = 0; break; case VLC_CONFIG_DESC: @@ -381,10 +375,9 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) if (domain == NULL) domain = PACKAGE; - item->psz_text = text ? strdup (dgettext (domain, text)) : NULL; + item->psz_text = text ? strdup (mdgettext (domain, text)) : NULL; item->psz_longtext = - longtext ? strdup (dgettext (domain, longtext)) : NULL; - ret = 0; + longtext ? strdup (mdgettext (domain, longtext)) : NULL; break; } @@ -407,21 +400,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) item->pi_list = dst; } else -#if 0 - if (IsConfigFloatType (item->i_type)) - { - const float *src = va_arg (ap, const float *); - float *dst = malloc (sizeof (float) * (len + 1)); - - if (dst != NULL) - { - memcpy (dst, src, sizeof (float) * len); - dst[len] = 0.; - } - item->pf_list = dst; - } - else -#endif if (IsConfigStringType (item->i_type)) { const char *const *src = va_arg (ap, const char *const *); @@ -450,7 +428,7 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) { for (size_t i = 0; i < len; i++) dtext[i] = text[i] ? - strdup( dgettext( domain, text[i] ) ) : + strdup (mdgettext( domain, text[i] )) : NULL; dtext[len] = NULL; } @@ -461,7 +439,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) item->i_list = len; item->pf_update_list = va_arg (ap, vlc_callback_t); - ret = 0; break; } @@ -489,15 +466,20 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) if (domain == NULL) domain = PACKAGE; if (name) - tabtext[item->i_action] = strdup (dgettext (domain, name)); + tabtext[item->i_action] = strdup (mdgettext (domain, name)); else tabtext[item->i_action] = NULL; tabtext[item->i_action + 1] = NULL; item->i_action++; - ret = 0; break; } + + default: + fprintf (stderr, "LibVLC: unknown module property %d\n", propid); + fprintf (stderr, "LibVLC: too old to use this module?\n"); + ret = -1; + break; } va_end (ap);