X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=extras%2Fzsh.cpp;h=f54696a6ffac204876e6f13dcaaa7bc0114df921;hb=115261e50283aadb28173295c70b7ac91905db44;hp=8fc531ca187d6f5c78cda4d586dffab69fd1c2b5;hpb=ea235d4a6b6af5a8f6fb36bc0a785b10dbaf6cf7;p=vlc diff --git a/extras/zsh.cpp b/extras/zsh.cpp index 8fc531ca18..f54696a6ff 100644 --- a/extras/zsh.cpp +++ b/extras/zsh.cpp @@ -1,7 +1,7 @@ /***************************************************************************** * zsh.cpp: create zsh completion rule for vlc ***************************************************************************** - * Copyright (C) 1998-2005 VideoLAN + * Copyright (C) 2005 VideoLAN * $Id$ * * Authors: Sigmund Augdal @@ -28,13 +28,16 @@ #include #include typedef std::multimap mmap; +typedef std::multimap mcmap; + typedef std::pair mpair; +typedef std::pair mcpair; #include -void ParseModules( vlc_t *p_vlc, mmap &mods ); -mmap PrintModuleList( vlc_t *p_vlc ); -void ParseOption( module_config_t *p_item, mmap &mods ); +void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ); +void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ); +void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ); void PrintOption( char *psz_option, char i_short, char *psz_exlusive, char *psz_text, char *psz_longtext, char *psz_args ); extern "C"{ vlc_t * vlc_current_object( int i_object );} @@ -42,6 +45,7 @@ extern "C"{ vlc_t * vlc_current_object( int i_object );} int main( int i_argc, char **ppsz_argv ) { mmap mods; + mcmap mods2; /* Create a libvlc structure */ int i_ret = VLC_Create(); vlc_t *p_vlc; @@ -61,14 +65,15 @@ int main( int i_argc, char **ppsz_argv ) p_vlc = vlc_current_object( i_ret ); printf("#compdef vlc\n\n" + "#This file is autogenerated by zsh.cpp\n" "typeset -A opt_args\n" - "local context state line\n" + "local context state line ret=1\n" "local modules\n\n" ); - mods = PrintModuleList( p_vlc ); + PrintModuleList( p_vlc, mods, mods2 ); printf( "_arguments -S -s \\\n" ); - ParseModules( p_vlc, mods ); + ParseModules( p_vlc, mods, mods2 ); printf( " \"(--module)-p[print help on module]:print help on module:($modules)\"\\\n" ); printf( " \"(-p)--module[print help on module]:print help on module:($modules)\"\\\n" ); printf( " \"(--help)-h[print help]\"\\\n" ); @@ -82,11 +87,16 @@ int main( int i_argc, char **ppsz_argv ) printf( " \"--config[use alternate config file]\"\\\n" ); printf( " \"--reset-plugins-cache[resets the current plugins cache]\"\\\n" ); printf( " \"--version[print version information]\"\\\n" ); - printf( " \"*:Playlist item:_files\"\\\n" ); - printf( " && return 0\n\n" ); + printf( " \"*:Playlist item:->mrl\" && ret=0\n\n" ); - printf( "return 1\n" ); + printf( "case $state in\n" ); + printf( " mrl)\n" ); + printf( " _alternative 'files:file:_files' 'urls:URL:_urls' && ret=0\n" ); + printf( " ;;\n" ); + printf( "esac\n\n" ); + printf( "return ret\n" ); + return 0; /* Finish the threads */ VLC_CleanUp( 0 ); @@ -98,7 +108,7 @@ int main( int i_argc, char **ppsz_argv ) } -void ParseModules( vlc_t *p_vlc, mmap &mods ) +void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) { vlc_list_t *p_list = NULL;; module_t *p_module; @@ -133,23 +143,22 @@ void ParseModules( vlc_t *p_vlc, mmap &mods ) // printf( " #Subcategory %d\n", p_item->i_value ); } if( p_item->i_type & CONFIG_ITEM ) - ParseOption( p_item, mods ); + ParseOption( p_item, mods, mods2 ); } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); } } -mmap PrintModuleList( vlc_t *p_vlc ) +void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) { vlc_list_t *p_list = NULL;; module_t *p_module; int i_index; - mmap modules_cap; /* List the plugins */ p_list = vlc_list_find( p_vlc, VLC_OBJECT_MODULE, FIND_ANYWHERE ); - if( !p_list ) return mmap(); + if( !p_list ) return; printf( "modules=\"" ); for( i_index = 0; i_index < p_list->i_count; i_index++ ) @@ -158,26 +167,40 @@ mmap PrintModuleList( vlc_t *p_vlc ) /* Exclude empty plugins (submodules don't have config options, they * are stored in the parent module) */ - if( p_module->b_submodule ) - continue; if( strcmp( p_module->psz_object_name, "main" ) ) { - modules_cap.insert( mpair( p_module->psz_capability, - p_module->psz_object_name ) ); + mods.insert( mpair( p_module->psz_capability, + p_module->psz_object_name ) ); + module_config_t *p_config = p_module->p_config; + if( p_config ) do + { + /* Hack: required subcategory is stored in i_min */ + if( p_config->i_type == CONFIG_SUBCATEGORY ) + { + mods2.insert( mcpair( p_config->i_value, + p_module->psz_object_name ) ); + } + } while( p_config->i_type != CONFIG_HINT_END && p_config++ ); + if( p_module->b_submodule ) + continue; printf( "%s ", p_module->psz_object_name ); } } printf( "\"\n\n" ); - return modules_cap; + return; } -void ParseOption( module_config_t *p_item, mmap &mods ) +void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) { char *psz_arguments = ""; char *psz_exclusive; char *psz_option; + //Skip deprecated options + if( p_item->psz_current ) + return; + switch( p_item->i_type ) { case CONFIG_ITEM_MODULE: @@ -188,6 +211,7 @@ void ParseOption( module_config_t *p_item, mmap &mods ) while( range.first != range.second ) { list = list.append( " " ); + printf("%s",range.first->second.c_str()); list = list.append( range.first->second ); ++range.first; } @@ -195,11 +219,36 @@ void ParseOption( module_config_t *p_item, mmap &mods ) } break; case CONFIG_ITEM_MODULE_CAT: -// p_control = new ModuleCatConfigControl( p_this, p_item, parent ); - break; + { + std::pair range = + mods2.equal_range( p_item->i_min ); + std::string list = (*range.first).second; + ++range.first; + while( range.first != range.second ) + { + list = list.append( " " ); + list = list.append( range.first->second ); + ++range.first; + } + asprintf( &psz_arguments, "(%s)", list.c_str() ); + } + break; case CONFIG_ITEM_MODULE_LIST_CAT: -// p_control = new ModuleListCatConfigControl( p_this, p_item, parent ); - break; + { + std::pair range = + mods2.equal_range( p_item->i_min ); + std::string list = "_values -s , "; + list = list.append( p_item->psz_name ); + while( range.first != range.second ) + { + list = list.append( " '*" ); + list = list.append( range.first->second ); + list = list.append( "'" ); + ++range.first; + } + asprintf( &psz_arguments, "%s", list.c_str() ); + } + break; case CONFIG_ITEM_STRING: if( p_item->i_list ) @@ -333,13 +382,14 @@ void PrintOption( char *psz_option, char i_short, char *psz_exclusive, if( !psz_longtext || strchr( psz_longtext, '\n' ) || strchr( psz_longtext, '(' ) ) psz_longtext = psz_text; - while( (foo = strchr( psz_text, '"' ))) *foo='\''; + if( psz_text ) + while( (foo = strchr( psz_text, '"' ))) *foo='\''; if( i_short ) { if( !psz_exclusive ) psz_exclusive = ""; else asprintf( &psz_exclusive, " %s", psz_exclusive ); - printf( " \"(-%c%s)--%s[%s]", i_short, psz_exclusive, - psz_option, psz_text ); + printf( " \"(-%c%s)--%s%s[%s]", i_short, psz_exclusive, + psz_option, psz_args?"=":"", psz_text ); if( psz_args ) printf( ":%s:%s\"\\\n", psz_longtext, psz_args ); else @@ -355,8 +405,8 @@ void PrintOption( char *psz_option, char i_short, char *psz_exclusive, else { if( psz_exclusive ) - printf( " \"(%s)--%s[%s]", psz_exclusive, psz_option, - psz_text ); + printf( " \"(%s)--%s%s[%s]", psz_exclusive, psz_option, + psz_args?"=":"", psz_text ); else printf( " \"--%s[%s]", psz_option, psz_text );