00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <map>
00026 #include <string>
00027 #include <utility>
00028 #include <iostream>
00029 #include <algorithm>
00030 typedef std::multimap<std::string, std::string> mmap;
00031 typedef std::multimap<int, std::string> mcmap;
00032
00033 typedef std::pair<std::string, std::string> mpair;
00034 typedef std::pair<int, std::string> mcpair;
00035
00036 #include <vlc/vlc.h>
00037
00038 void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 );
00039 void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 );
00040 void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 );
00041 void PrintOption( char *psz_option, char i_short, char *psz_exlusive,
00042 char *psz_text, char *psz_longtext, char *psz_args );
00043 extern "C"{ vlc_t * vlc_current_object( int i_object );}
00044
00045 int main( int i_argc, char **ppsz_argv )
00046 {
00047 mmap mods;
00048 mcmap mods2;
00049
00050 int i_ret = VLC_Create();
00051 vlc_t *p_vlc;
00052
00053 if( i_ret < 0 )
00054 {
00055 return i_ret;
00056 }
00057
00058
00059 i_ret = VLC_Init( 0, i_argc, ppsz_argv );
00060 if( i_ret < 0 )
00061 {
00062 VLC_Destroy( 0 );
00063 return i_ret;
00064 }
00065 p_vlc = vlc_current_object( i_ret );
00066 printf("#compdef vlc\n\n"
00067
00068 "#This file is autogenerated by zsh.cpp\n"
00069 "typeset -A opt_args\n"
00070 "local context state line ret=1\n"
00071 "local modules\n\n" );
00072
00073 PrintModuleList( p_vlc, mods, mods2 );
00074
00075 printf( "_arguments -S -s \\\n" );
00076 ParseModules( p_vlc, mods, mods2 );
00077 printf( " \"(--module)-p[print help on module]:print help on module:($modules)\"\\\n" );
00078 printf( " \"(-p)--module[print help on module]:print help on module:($modules)\"\\\n" );
00079 printf( " \"(--help)-h[print help]\"\\\n" );
00080 printf( " \"(-h)--help[print help]\"\\\n" );
00081 printf( " \"(--longhelp)-H[print detailed help]\"\\\n" );
00082 printf( " \"(-H)--longhelp[print detailed help]\"\\\n" );
00083 printf( " \"(--list)-l[print a list of available modules]\"\\\n" );
00084 printf( " \"(-l)--list[print a list of available modules]\"\\\n" );
00085 printf( " \"--save-config[save the current command line options in the config file]\"\\\n" );
00086 printf( " \"--reset-config[reset the current config to the default values]\"\\\n" );
00087 printf( " \"--config[use alternate config file]\"\\\n" );
00088 printf( " \"--reset-plugins-cache[resets the current plugins cache]\"\\\n" );
00089 printf( " \"--version[print version information]\"\\\n" );
00090 printf( " \"*:Playlist item:->mrl\" && ret=0\n\n" );
00091
00092 printf( "case $state in\n" );
00093 printf( " mrl)\n" );
00094 printf( " _alternative 'files:file:_files' 'urls:URL:_urls' && ret=0\n" );
00095 printf( " ;;\n" );
00096 printf( "esac\n\n" );
00097
00098 printf( "return ret\n" );
00099
00100 return 0;
00101
00102 VLC_CleanUp( 0 );
00103
00104
00105 VLC_Destroy( 0 );
00106
00107 return i_ret;
00108
00109 }
00110
00111 void ParseModules( vlc_t *p_vlc, mmap &mods, mcmap &mods2 )
00112 {
00113 vlc_list_t *p_list = NULL;;
00114 module_t *p_module;
00115 module_config_t *p_item;
00116 int i_index;
00117
00118
00119 p_list = vlc_list_find( p_vlc, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00120 if( !p_list ) return;
00121 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00122 {
00123 p_module = (module_t *)p_list->p_values[i_index].p_object;
00124
00125
00126
00127 if( p_module->b_submodule )
00128 continue;
00129
00130 else
00131 p_item = p_module->p_config;
00132
00133
00134 if( !p_item ) continue;
00135 do
00136 {
00137 if( p_item->i_type == CONFIG_CATEGORY )
00138 {
00139
00140 }
00141 else if( p_item->i_type == CONFIG_SUBCATEGORY )
00142 {
00143
00144 }
00145 if( p_item->i_type & CONFIG_ITEM )
00146 ParseOption( p_item, mods, mods2 );
00147 }
00148 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00149
00150 }
00151 }
00152
00153 void PrintModuleList( vlc_t *p_vlc, mmap &mods, mcmap &mods2 )
00154 {
00155 vlc_list_t *p_list = NULL;;
00156 module_t *p_module;
00157 int i_index;
00158
00159
00160 p_list = vlc_list_find( p_vlc, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00161 if( !p_list ) return;
00162
00163 printf( "modules=\"" );
00164 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00165 {
00166 p_module = (module_t *)p_list->p_values[i_index].p_object;
00167
00168
00169
00170
00171 if( strcmp( p_module->psz_object_name, "main" ) )
00172 {
00173 mods.insert( mpair( p_module->psz_capability,
00174 p_module->psz_object_name ) );
00175 module_config_t *p_config = p_module->p_config;
00176 if( p_config ) do
00177 {
00178
00179 if( p_config->i_type == CONFIG_SUBCATEGORY )
00180 {
00181 mods2.insert( mcpair( p_config->i_value,
00182 p_module->psz_object_name ) );
00183 }
00184 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
00185 if( p_module->b_submodule )
00186 continue;
00187 printf( "%s ", p_module->psz_object_name );
00188 }
00189
00190 }
00191 printf( "\"\n\n" );
00192 return;
00193 }
00194
00195 void ParseOption( module_config_t *p_item, mmap &mods, mcmap &mods2 )
00196 {
00197 char *psz_arguments = "";
00198 char *psz_exclusive;
00199 char *psz_option;
00200
00201 if( p_item->psz_current )
00202 return;
00203
00204 switch( p_item->i_type )
00205 {
00206 case CONFIG_ITEM_MODULE:
00207 {
00208 std::pair<mmap::iterator, mmap::iterator> range = mods.equal_range( p_item->psz_type );
00209 std::string list = (*range.first).second;
00210 ++range.first;
00211 while( range.first != range.second )
00212 {
00213 list = list.append( " " );
00214 printf("%s",range.first->second.c_str());
00215 list = list.append( range.first->second );
00216 ++range.first;
00217 }
00218 asprintf( &psz_arguments, "(%s)", list.c_str() );
00219 }
00220 break;
00221 case CONFIG_ITEM_MODULE_CAT:
00222 {
00223 std::pair<mcmap::iterator, mcmap::iterator> range =
00224 mods2.equal_range( p_item->i_min );
00225 std::string list = (*range.first).second;
00226 ++range.first;
00227 while( range.first != range.second )
00228 {
00229 list = list.append( " " );
00230 list = list.append( range.first->second );
00231 ++range.first;
00232 }
00233 asprintf( &psz_arguments, "(%s)", list.c_str() );
00234 }
00235 break;
00236 case CONFIG_ITEM_MODULE_LIST_CAT:
00237 {
00238 std::pair<mcmap::iterator, mcmap::iterator> range =
00239 mods2.equal_range( p_item->i_min );
00240 std::string list = "_values -s , ";
00241 list = list.append( p_item->psz_name );
00242 while( range.first != range.second )
00243 {
00244 list = list.append( " '*" );
00245 list = list.append( range.first->second );
00246 list = list.append( "'" );
00247 ++range.first;
00248 }
00249 asprintf( &psz_arguments, "%s", list.c_str() );
00250 }
00251 break;
00252
00253 case CONFIG_ITEM_STRING:
00254 if( p_item->i_list )
00255 {
00256 int i = p_item->i_list -1;
00257 char *psz_list;
00258 if( p_item->ppsz_list_text )
00259 asprintf( &psz_list, "%s\\:%s", p_item->ppsz_list[i],
00260 p_item->ppsz_list_text[i] );
00261 else
00262 psz_list = strdup(p_item->ppsz_list[i]);
00263 char *psz_list2;
00264 while( i>1 )
00265 {
00266 if( p_item->ppsz_list_text )
00267 asprintf( &psz_list2, "%s\\:%s %s", p_item->ppsz_list[i-1],
00268 p_item->ppsz_list_text[i-1], psz_list );
00269 else
00270 asprintf( &psz_list2, "%s %s", p_item->ppsz_list[i-1],
00271 psz_list );
00272
00273 free( psz_list );
00274 psz_list = psz_list2;
00275 i--;
00276 }
00277 if( p_item->ppsz_list_text )
00278 asprintf( &psz_arguments, "((%s))", psz_list );
00279 else
00280 asprintf( &psz_arguments, "(%s)", psz_list );
00281
00282 free( psz_list );
00283 }
00284 break;
00285
00286 case CONFIG_ITEM_FILE:
00287 psz_arguments = "_files";
00288 break;
00289 case CONFIG_ITEM_DIRECTORY:
00290 psz_arguments = "_files -/";
00291 break;
00292
00293 case CONFIG_ITEM_INTEGER:
00294 if( p_item->i_list )
00295 {
00296 int i = p_item->i_list -1;
00297 char *psz_list;
00298 if( p_item->ppsz_list_text )
00299 asprintf( &psz_list, "%d\\:%s", p_item->pi_list[i],
00300 p_item->ppsz_list_text[i] );
00301 else
00302 psz_list = strdup(p_item->ppsz_list[i]);
00303 char *psz_list2;
00304 while( i>1 )
00305 {
00306 if( p_item->ppsz_list_text )
00307 asprintf( &psz_list2, "%d\\:%s %s", p_item->pi_list[i-1],
00308 p_item->ppsz_list_text[i-1], psz_list );
00309 else
00310 asprintf( &psz_list2, "%s %s", p_item->ppsz_list[i-1],
00311 psz_list );
00312
00313 free( psz_list );
00314 psz_list = psz_list2;
00315 i--;
00316 }
00317 if( p_item->ppsz_list_text )
00318 asprintf( &psz_arguments, "((%s))", psz_list );
00319 else
00320 asprintf( &psz_arguments, "(%s)", psz_list );
00321
00322 free( psz_list );
00323 }
00324 else if( p_item->i_min != 0 || p_item->i_max != 0 )
00325 {
00326
00327 }
00328 else
00329 {
00330
00331 }
00332 break;
00333
00334 case CONFIG_ITEM_KEY:
00335
00336 break;
00337
00338 case CONFIG_ITEM_FLOAT:
00339
00340 break;
00341
00342 case CONFIG_ITEM_BOOL:
00343
00344 psz_arguments = NULL;
00345 asprintf( &psz_exclusive, "--no%s --no-%s", p_item->psz_name,
00346 p_item->psz_name );
00347 PrintOption( p_item->psz_name, p_item->i_short, psz_exclusive,
00348 p_item->psz_text, p_item->psz_longtext, psz_arguments );
00349 free( psz_exclusive );
00350 asprintf( &psz_exclusive, "--no%s --%s", p_item->psz_name,
00351 p_item->psz_name );
00352 asprintf( &psz_option, "no-%s", p_item->psz_name );
00353 PrintOption( psz_option, p_item->i_short, psz_exclusive,
00354 p_item->psz_text, p_item->psz_longtext, psz_arguments );
00355 free( psz_exclusive );
00356 free( psz_option );
00357 asprintf( &psz_exclusive, "--no-%s --%s", p_item->psz_name,
00358 p_item->psz_name );
00359 asprintf( &psz_option, "no%s", p_item->psz_name );
00360 PrintOption( psz_option, p_item->i_short, psz_exclusive,
00361 p_item->psz_text, p_item->psz_longtext, psz_arguments );
00362 free( psz_exclusive );
00363 free( psz_option );
00364 return;
00365
00366 case CONFIG_SECTION:
00367
00368 break;
00369
00370 default:
00371 break;
00372 }
00373 PrintOption( p_item->psz_name, p_item->i_short, NULL,
00374 p_item->psz_text, p_item->psz_longtext, psz_arguments );
00375
00376 }
00377
00378 void PrintOption( char *psz_option, char i_short, char *psz_exclusive,
00379 char *psz_text, char *psz_longtext, char *psz_args )
00380 {
00381 char *foo;
00382 if( !psz_longtext ||
00383 strchr( psz_longtext, '\n' ) ||
00384 strchr( psz_longtext, '(' ) ) psz_longtext = psz_text;
00385 if( psz_text )
00386 while( (foo = strchr( psz_text, '"' ))) *foo='\'';
00387 if( i_short )
00388 {
00389 if( !psz_exclusive ) psz_exclusive = "";
00390 else asprintf( &psz_exclusive, " %s", psz_exclusive );
00391 printf( " \"(-%c%s)--%s%s[%s]", i_short, psz_exclusive,
00392 psz_option, psz_args?"=":"", psz_text );
00393 if( psz_args )
00394 printf( ":%s:%s\"\\\n", psz_longtext, psz_args );
00395 else
00396 printf( "\"\\\n" );
00397 printf( " \"(--%s%s)-%c[%s]", psz_option, psz_exclusive,
00398 i_short, psz_text );
00399 if( psz_args )
00400 printf( ":%s:%s\"\\\n", psz_longtext, psz_args );
00401 else
00402 printf( "\"\\\n" );
00403
00404 }
00405 else
00406 {
00407 if( psz_exclusive )
00408 printf( " \"(%s)--%s%s[%s]", psz_exclusive, psz_option,
00409 psz_args?"=":"", psz_text );
00410 else
00411 printf( " \"--%s[%s]", psz_option, psz_text );
00412
00413 if( psz_args )
00414 printf( ":%s:%s\"\\\n", psz_longtext, psz_args );
00415 else
00416 printf( "\"\\\n" );
00417
00418 }
00419 }
00420