Commit f15b7d6b authored by Rafaël Carré's avatar Rafaël Carré

zsh completion: refactor

parent 85336e05
...@@ -29,26 +29,19 @@ ...@@ -29,26 +29,19 @@
#include <map> #include <map>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <utility>
#include <iostream> #include <vlc/vlc.h>
#include <algorithm> #include <vlc_common.h>
#include <vlc_modules.h>
#include "../src/modules/modules.h" /* evil hack */
typedef std::pair<std::string, std::string> mpair; typedef std::pair<std::string, std::string> mpair;
typedef std::multimap<std::string, std::string> mumap; typedef std::multimap<std::string, std::string> mumap;
mumap mods; mumap capabilities;
typedef std::pair<int, std::string> mcpair; typedef std::pair<int, std::string> mcpair;
typedef std::multimap<int, std::string> mcmap; typedef std::multimap<int, std::string> mcmap;
mcmap mods2; mcmap categories;
#include <vlc_common.h>
#include <vlc/vlc.h>
#include <vlc_modules.h>
/* evil hack */
#undef __PLUGIN__
#include <../src/modules/modules.h>
static void ReplaceChars(char *str) static void ReplaceChars(char *str)
{ {
...@@ -114,27 +107,23 @@ static void ParseOption(const module_config_t *item) ...@@ -114,27 +107,23 @@ static void ParseOption(const module_config_t *item)
switch(item->i_type) switch(item->i_type)
{ {
case CONFIG_ITEM_MODULE: case CONFIG_ITEM_MODULE:
range_mod = mods.equal_range(item->psz_type); range_mod = capabilities.equal_range(item->psz_type);
list = (*range_mod.first).second; args = "(" + (*range_mod.first).second;
if (range_mod.first != range_mod.second) { while (range_mod.first++ != range_mod.second)
while (range_mod.first++ != range_mod.second) args += " " + range_mod.first->second;
list += " " + range_mod.first->second; args += ")";
args = std::string("(") + list + ")";
}
break; break;
case CONFIG_ITEM_MODULE_CAT: case CONFIG_ITEM_MODULE_CAT:
range = mods2.equal_range(item->min.i); range = categories.equal_range(item->min.i);
list = (*range.first).second; args = "(" + (*range.first).second;
if (range.first != range.second) { while (range.first++ != range.second)
while (range.first++ != range.second) args += " " + range.first->second;
list += " " + range.first->second; args += ")";
args = std::string("(") + list + ")";
}
break; break;
case CONFIG_ITEM_MODULE_LIST_CAT: case CONFIG_ITEM_MODULE_LIST_CAT:
range = mods2.equal_range(item->min.i); range = categories.equal_range(item->min.i);
args = std::string("_values -s , ") + item->psz_name; args = std::string("_values -s , ") + item->psz_name;
while (range.first != range.second) while (range.first != range.second)
args += " '*" + range.first++->second + "'"; args += " '*" + range.first++->second + "'";
...@@ -200,60 +189,33 @@ static void ParseOption(const module_config_t *item) ...@@ -200,60 +189,33 @@ static void ParseOption(const module_config_t *item)
PrintOption(item, item->psz_name, "", args); PrintOption(item, item->psz_name, "", args);
} }
static void PrintModuleList() static void PrintModule(const module_t *mod)
{ {
printf("vlc_modules=\""); const char *name = mod->pp_shortcuts[0];
if (!strcmp(name, "main"))
size_t modules = 0;
module_t **list = module_list_get(&modules);
if (!list || modules == 0)
return; return;
for (module_t **pmod = list; pmod < &list[modules]; pmod++) { if (mod->psz_capability)
/* Exclude empty plugins (submodules don't have config options, they capabilities.insert(mpair(mod->psz_capability, name));
* are stored in the parent module) */
module_t *mod = *pmod;
if (!strcmp(mod->pp_shortcuts[0], "main"))
continue;
const char *capability = mod->psz_capability ? mod->psz_capability : "";
mods.insert(mpair(capability, mod->pp_shortcuts[0]));
module_config_t *max = &mod->p_config[mod->i_config_items]; module_config_t *max = &mod->p_config[mod->i_config_items];
for (module_config_t *cfg = mod->p_config; cfg && cfg < max; cfg++) for (module_config_t *cfg = mod->p_config; cfg && cfg < max; cfg++)
if (cfg->i_type == CONFIG_SUBCATEGORY) if (cfg->i_type == CONFIG_SUBCATEGORY)
mods2.insert(mcpair(cfg->value.i, mod->pp_shortcuts[0])); categories.insert(mcpair(cfg->value.i, name));
if (!mod->parent) if (!mod->parent)
printf("%s ", mod->pp_shortcuts[0]); printf("%s ", name);
}
puts("\"\n");
module_list_free(list);
} }
static void ParseModules() static void ParseModule(const module_t *mod)
{ {
size_t modules = 0; if (mod->parent)
module_t **list = module_list_get(&modules);
if (!list || modules == 0)
return; return;
for (module_t **pmod = list; pmod < &list[modules]; pmod++) { module_config_t *max = mod->p_config + mod->confsize;
/* Exclude empty plugins (submodules don't have config options, they for (module_config_t *cfg = mod->p_config; cfg && cfg < max; cfg++)
* are stored in the parent module) */ if (CONFIG_ITEM(cfg->i_type))
module_t *mod = *pmod; ParseOption(cfg);
if (mod->parent)
continue;
module_config_t *max = mod->p_config + mod->confsize;
for (module_config_t *cfg = mod->p_config; cfg && cfg < max; cfg++)
if (CONFIG_ITEM(cfg->i_type))
ParseOption(cfg);
}
module_list_free(list);
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)
...@@ -262,16 +224,29 @@ int main(int argc, const char **argv) ...@@ -262,16 +224,29 @@ int main(int argc, const char **argv)
if (!libvlc) if (!libvlc)
return 1; return 1;
size_t modules = 0;
module_t **mod_list;
mod_list = module_list_get(&modules);
if (!mod_list || modules == 0)
return 2;
module_t **max = &mod_list[modules];
puts("#compdef vlc cvlc rvlc svlc mvlc qvlc nvlc\n" puts("#compdef vlc cvlc rvlc svlc mvlc qvlc nvlc\n"
"#This file is autogenerated by zsh.cpp" "#This file is autogenerated by zsh.cpp"
"typeset -A opt_args" "typeset -A opt_args"
"local context state line ret=1" "local context state line ret=1"
"local modules\n"); "local modules\n");
PrintModuleList(); printf("vlc_modules=\"");
for (module_t **mod = mod_list; mod < max; mod++)
PrintModule(*mod);
puts("\"\n");
puts("_arguments -S -s \\"); puts("_arguments -S -s \\");
ParseModules(); for (module_t **mod = mod_list; mod < max; mod++)
ParseModule(*mod);
puts(" \"(--module)-p[print help on module]:print help on module:($vlc_modules)\"\\"); puts(" \"(--module)-p[print help on module]:print help on module:($vlc_modules)\"\\");
puts(" \"(-p)--module[print help on module]:print help on module:($vlc_modules)\"\\"); puts(" \"(-p)--module[print help on module]:print help on module:($vlc_modules)\"\\");
puts(" \"(--help)-h[print help]\"\\"); puts(" \"(--help)-h[print help]\"\\");
...@@ -294,7 +269,7 @@ int main(int argc, const char **argv) ...@@ -294,7 +269,7 @@ int main(int argc, const char **argv)
puts("return ret"); puts("return ret");
module_list_free(mod_list);
libvlc_release(libvlc); libvlc_release(libvlc);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment