X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=extras%2Fzsh.cpp;h=109eb11eff15f6e7e46c889dcfb110fc44aed4dd;hb=408b9c7a7a8333dc2ea6fe48b743b8183c55551c;hp=b0fb9aa5555d5350f3c5ef8a34b315bd01d34e9a;hpb=aa811adbd30a6e82092728b6f08832b32a398fea;p=vlc diff --git a/extras/zsh.cpp b/extras/zsh.cpp index b0fb9aa555..109eb11eff 100644 --- a/extras/zsh.cpp +++ b/extras/zsh.cpp @@ -1,10 +1,10 @@ /***************************************************************************** * zsh.cpp: create zsh completion rule for vlc ***************************************************************************** - * Copyright (C) 1998-2005 VideoLAN + * Copyright (C) 2005 the VideoLAN team * $Id$ * - * Authors: Sigmund Augdal + * Authors: Sigmund Augdal Helberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include @@ -35,12 +35,11 @@ typedef std::pair mcpair; #include -void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ); -void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ); +void ParseModules( libvlc_int_t *p_libvlc, mmap &mods, mcmap &mods2 ); +void PrintModuleList( libvlc_int_t *p_libvlc, 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 );} int main( int i_argc, char **ppsz_argv ) { @@ -48,21 +47,21 @@ int main( int i_argc, char **ppsz_argv ) mcmap mods2; /* Create a libvlc structure */ int i_ret = VLC_Create(); - vlc_t *p_vlc; - + libvlc_int_t *p_libvlc; + if( i_ret < 0 ) { return i_ret; } - /* Initialize libvlc */ + /* Initialize libvlc */ i_ret = VLC_Init( 0, i_argc, ppsz_argv ); if( i_ret < 0 ) { VLC_Destroy( 0 ); return i_ret; } - p_vlc = vlc_current_object( i_ret ); + p_libvlc = (libvlc_int_t*)vlc_object_get( (vlc_object_t*)NULL, i_ret ); printf("#compdef vlc\n\n" "#This file is autogenerated by zsh.cpp\n" @@ -70,10 +69,10 @@ int main( int i_argc, char **ppsz_argv ) "local context state line ret=1\n" "local modules\n\n" ); - PrintModuleList( p_vlc, mods, mods2 ); + PrintModuleList( p_libvlc, mods, mods2 ); printf( "_arguments -S -s \\\n" ); - ParseModules( p_vlc, mods, mods2 ); + ParseModules( p_libvlc, 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" ); @@ -108,15 +107,16 @@ int main( int i_argc, char **ppsz_argv ) } -void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) +void ParseModules( libvlc_int_t *p_libvlc, mmap &mods, mcmap &mods2 ) { vlc_list_t *p_list = NULL;; module_t *p_module; module_config_t *p_item; int i_index; + int i_items; /* List the plugins */ - p_list = vlc_list_find( p_vlc, VLC_OBJECT_MODULE, FIND_ANYWHERE ); + p_list = vlc_list_find( p_libvlc, VLC_OBJECT_MODULE, FIND_ANYWHERE ); if( !p_list ) return; for( i_index = 0; i_index < p_list->i_count; i_index++ ) { @@ -132,6 +132,7 @@ void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) // printf( " #%s\n", p_module->psz_longname ); if( !p_item ) continue; + i_items = 0; do { if( p_item->i_type == CONFIG_CATEGORY ) @@ -145,19 +146,20 @@ void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) if( p_item->i_type & CONFIG_ITEM ) ParseOption( p_item, mods, mods2 ); } - while( p_item->i_type != CONFIG_HINT_END && p_item++ ); + while( i_items++ < p_module->i_config_items && p_item++ ); } } -void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) +void PrintModuleList( libvlc_int_t *p_libvlc, mmap &mods, mcmap &mods2 ) { vlc_list_t *p_list = NULL;; module_t *p_module; int i_index; + int i_items; /* List the plugins */ - p_list = vlc_list_find( p_vlc, VLC_OBJECT_MODULE, FIND_ANYWHERE ); + p_list = vlc_list_find( p_libvlc, VLC_OBJECT_MODULE, FIND_ANYWHERE ); if( !p_list ) return; printf( "modules=\"" ); @@ -173,15 +175,16 @@ void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 ) mods.insert( mpair( p_module->psz_capability, p_module->psz_object_name ) ); module_config_t *p_config = p_module->p_config; + i_items = 0; 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, + mods2.insert( mcpair( p_config->value.i, p_module->psz_object_name ) ); } - } while( p_config->i_type != CONFIG_HINT_END && p_config++ ); + } while( i_items++ < p_module->i_config_items && p_config++ ); if( p_module->b_submodule ) continue; printf( "%s ", p_module->psz_object_name ); @@ -197,6 +200,16 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) char *psz_arguments = ""; char *psz_exclusive; char *psz_option; + char *psz_name; + char *psz_text; + char *psz_longtext; + +#define DUP( x ) strdup( x ? x : "" ) + + //Skip deprecated options + if( p_item->psz_current ) + return; + switch( p_item->i_type ) { case CONFIG_ITEM_MODULE: @@ -216,7 +229,7 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) case CONFIG_ITEM_MODULE_CAT: { std::pair range = - mods2.equal_range( p_item->i_min ); + mods2.equal_range( p_item->min.i ); std::string list = (*range.first).second; ++range.first; while( range.first != range.second ) @@ -231,7 +244,7 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) case CONFIG_ITEM_MODULE_LIST_CAT: { std::pair range = - mods2.equal_range( p_item->i_min ); + mods2.equal_range( p_item->min.i ); std::string list = "_values -s , "; list = list.append( p_item->psz_name ); while( range.first != range.second ) @@ -316,7 +329,7 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) free( psz_list ); } - else if( p_item->i_min != 0 || p_item->i_max != 0 ) + else if( p_item->min.i != 0 || p_item->max.i != 0 ) { // p_control = new RangedIntConfigControl( p_this, p_item, parent ); } @@ -339,21 +352,35 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) psz_arguments = NULL; asprintf( &psz_exclusive, "--no%s --no-%s", p_item->psz_name, p_item->psz_name ); - PrintOption( p_item->psz_name, p_item->i_short, psz_exclusive, - p_item->psz_text, p_item->psz_longtext, psz_arguments ); + psz_name = DUP( p_item->psz_name ); + psz_text = DUP( p_item->psz_text ); + psz_longtext = DUP( p_item->psz_longtext ); + PrintOption( psz_name, p_item->i_short, psz_exclusive, + psz_text, psz_longtext, psz_arguments ); + free( psz_name ); + free( psz_text ); + free( psz_longtext ); free( psz_exclusive ); asprintf( &psz_exclusive, "--no%s --%s", p_item->psz_name, p_item->psz_name ); asprintf( &psz_option, "no-%s", p_item->psz_name ); + psz_text = DUP( p_item->psz_text ); + psz_longtext = DUP( p_item->psz_longtext ); PrintOption( psz_option, p_item->i_short, psz_exclusive, - p_item->psz_text, p_item->psz_longtext, psz_arguments ); + psz_text, psz_longtext, psz_arguments ); + free( psz_text ); + free( psz_longtext ); free( psz_exclusive ); free( psz_option ); asprintf( &psz_exclusive, "--no-%s --%s", p_item->psz_name, p_item->psz_name ); asprintf( &psz_option, "no%s", p_item->psz_name ); + psz_text = DUP( p_item->psz_text ); + psz_longtext = DUP( p_item->psz_longtext ); PrintOption( psz_option, p_item->i_short, psz_exclusive, - p_item->psz_text, p_item->psz_longtext, psz_arguments ); + psz_text, psz_longtext, psz_arguments ); + free( psz_text ); + free( psz_longtext ); free( psz_exclusive ); free( psz_option ); return; @@ -365,9 +392,14 @@ void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 ) default: break; } - PrintOption( p_item->psz_name, p_item->i_short, NULL, - p_item->psz_text, p_item->psz_longtext, psz_arguments ); - + psz_name = DUP( p_item->psz_name ); + psz_text = DUP( p_item->psz_text ); + psz_longtext = DUP( p_item->psz_longtext ); + PrintOption( psz_name, p_item->i_short, NULL, + psz_text, psz_longtext, psz_arguments ); + free( psz_name ); + free( psz_text ); + free( psz_longtext ); } void PrintOption( char *psz_option, char i_short, char *psz_exclusive, @@ -377,7 +409,8 @@ 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 = "";