/*****************************************************************************
* zsh.cpp: create zsh completion rule for vlc
*****************************************************************************
- * Copyright (C) 1998-2005 VideoLAN
+ * Copyright (C) 2005 the VideoLAN team
* $Id$
*
- * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
+ * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
*
* 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
*
* 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 <stdio.h>
#include <iostream>
#include <algorithm>
typedef std::multimap<std::string, std::string> mmap;
+typedef std::multimap<int, std::string> mcmap;
+
typedef std::pair<std::string, std::string> mpair;
+typedef std::pair<int, std::string> mcpair;
#include <vlc/vlc.h>
-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 );}
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;
-
+
if( i_ret < 0 )
{
return i_ret;
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" );
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 );
}
-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;
// 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++ )
if( strcmp( p_module->psz_object_name, "main" ) )
{
- modules_cap.insert( mpair( p_module->psz_capability,
- p_module->psz_object_name ) );
- if( p_module->b_submodule )
- continue;
+ 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:
}
break;
case CONFIG_ITEM_MODULE_CAT:
-// p_control = new ModuleCatConfigControl( p_this, p_item, parent );
- break;
+ {
+ std::pair<mcmap::iterator, mcmap::iterator> 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<mcmap::iterator, mcmap::iterator> 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 )
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
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 );