1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
5 * $Id: libvlc.c,v 1.53 2002/12/14 19:43:25 gbazin Exp $
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@netcourrier.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
27 * Pretend we are a builtin module
28 *****************************************************************************/
29 #define MODULE_NAME main
30 #define MODULE_PATH main
33 /*****************************************************************************
35 *****************************************************************************/
39 # include <errno.h> /* ENOMEM */
41 #include <stdio.h> /* sprintf() */
42 #include <string.h> /* strerror() */
43 #include <stdlib.h> /* free() */
46 # include <netinet/in.h> /* BSD: struct in_addr */
51 #elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
55 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
56 # include "extras/getopt.h"
63 #include "vlc_cpu.h" /* CPU detection */
64 #include "os_specific.h"
67 #include "netutils.h" /* network_ChannelJoin */
69 #include "stream_control.h"
70 #include "input_ext-intf.h"
72 #include "vlc_playlist.h"
73 #include "interface.h"
75 #include "audio_output.h"
78 #include "video_output.h"
82 /*****************************************************************************
83 * The evil global variable. We handle it with care, don't worry.
84 *****************************************************************************/
85 static libvlc_t libvlc;
86 static vlc_t * p_static_vlc;
88 /*****************************************************************************
90 *****************************************************************************/
91 static void SetLanguage ( char const * );
92 static int GetFilenames ( vlc_t *, int, char *[] );
93 static void Usage ( vlc_t *, char const *psz_module_name );
94 static void ListModules ( vlc_t * );
95 static void Version ( void );
98 static void ShowConsole ( void );
101 /*****************************************************************************
102 * VLC_Version: return the libvlc version.
103 *****************************************************************************
104 * This function returns full version string (numeric version and codename).
105 *****************************************************************************/
106 char const * VLC_Version( void )
108 return VERSION_MESSAGE;
111 /*****************************************************************************
112 * VLC_Error: strerror() equivalent
113 *****************************************************************************
114 * This function returns full version string (numeric version and codename).
115 *****************************************************************************/
116 char const * VLC_Error( int i_err )
118 return vlc_error( i_err );
121 /*****************************************************************************
122 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
123 *****************************************************************************
124 * This function allocates a vlc_t structure and returns a negative value
125 * in case of failure. Also, the thread system is initialized.
126 *****************************************************************************/
127 int VLC_Create( void )
130 vlc_t * p_vlc = NULL;
133 /* vlc_threads_init *must* be the first internal call! No other call is
134 * allowed before the thread system has been initialized. */
135 i_ret = vlc_threads_init( &libvlc );
141 /* Now that the thread system is initialized, we don't have much, but
142 * at least we have var_Create */
143 var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
144 var_Get( &libvlc, "libvlc", &lockval );
145 vlc_mutex_lock( lockval.p_address );
146 if( !libvlc.b_ready )
150 /* Guess what CPU we have */
151 libvlc.i_cpu = CPUCapabilities();
153 /* Find verbosity from VLC_VERBOSE environment variable */
154 psz_env = getenv( "VLC_VERBOSE" );
155 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
158 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
160 libvlc.b_color = VLC_FALSE;
163 /* Initialize message queue */
164 msg_Create( &libvlc );
166 /* Announce who we are */
167 msg_Dbg( &libvlc, COPYRIGHT_MESSAGE );
168 msg_Dbg( &libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
170 /* Initialize the module bank and load the configuration of the
171 * main module. We need to do this at this stage to be able to display
172 * a short help if required by the user. (short help == main module
174 module_InitBank( &libvlc );
175 module_LoadMain( &libvlc );
177 libvlc.b_ready = VLC_TRUE;
179 vlc_mutex_unlock( lockval.p_address );
180 var_Destroy( &libvlc, "libvlc" );
182 /* Allocate a vlc object */
183 p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
189 p_vlc->psz_object_name = "root";
191 /* Initialize mutexes */
192 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
194 /* Store our newly allocated structure in the global list */
195 vlc_object_attach( p_vlc, &libvlc );
197 /* Store data for the non-reentrant API */
198 p_static_vlc = p_vlc;
200 return p_vlc->i_object_id;
203 /*****************************************************************************
204 * VLC_Init: initialize a vlc_t structure.
205 *****************************************************************************
206 * This function initializes a previously allocated vlc_t structure:
208 * - gettext initialization
209 * - message queue, module bank and playlist initialization
210 * - configuration and commandline parsing
211 *****************************************************************************/
212 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
214 char p_capabilities[200];
218 module_t *p_help_module;
219 playlist_t *p_playlist;
221 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
229 * Support for gettext
234 * System specific initialization code
236 system_Init( p_vlc, &i_argc, ppsz_argv );
238 /* Get the executable name (similar to the basename command) */
241 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
244 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
250 p_vlc->psz_object_name = "vlc";
253 /* Hack: insert the help module here */
254 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
255 if( p_help_module == NULL )
257 //module_EndBank( p_vlc );
258 if( i_object ) vlc_object_release( p_vlc );
261 p_help_module->psz_object_name = "help";
262 config_Duplicate( p_help_module, p_help_config );
263 vlc_object_attach( p_help_module, libvlc.p_module_bank );
266 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
268 vlc_object_detach( p_help_module );
269 config_Free( p_help_module );
270 vlc_object_destroy( p_help_module );
271 //module_EndBank( p_vlc );
272 if( i_object ) vlc_object_release( p_vlc );
278 /* Check for short help option */
279 if( config_GetInt( p_vlc, "help" ) )
281 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
282 p_vlc->psz_object_name );
283 Usage( p_vlc, "main" );
284 Usage( p_vlc, "help" );
287 /* Check for version option */
288 else if( config_GetInt( p_vlc, "version" ) )
294 /* Hack: remove the help module here */
295 vlc_object_detach( p_help_module );
300 config_Free( p_help_module );
301 vlc_object_destroy( p_help_module );
302 //module_EndBank( p_vlc );
303 if( i_object ) vlc_object_release( p_vlc );
308 * Load the builtins and plugins into the module_bank.
309 * We have to do it before config_Load*() because this also gets the
310 * list of configuration options exported by each module and loads their
313 module_LoadBuiltins( &libvlc );
314 module_LoadPlugins( &libvlc );
315 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
316 libvlc.p_module_bank->i_children );
318 /* Hack: insert the help module here */
319 vlc_object_attach( p_help_module, libvlc.p_module_bank );
322 /* Check for help on modules */
323 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
325 Usage( p_vlc, p_tmp );
329 /* Check for long help option */
330 else if( config_GetInt( p_vlc, "longhelp" ) )
332 Usage( p_vlc, NULL );
335 /* Check for module list option */
336 else if( config_GetInt( p_vlc, "list" ) )
338 ListModules( p_vlc );
342 /* Hack: remove the help module here */
343 vlc_object_detach( p_help_module );
344 config_Free( p_help_module );
345 vlc_object_destroy( p_help_module );
350 //module_EndBank( p_vlc );
351 if( i_object ) vlc_object_release( p_vlc );
356 * Override default configuration with config file settings
358 p_vlc->psz_homedir = config_GetHomeDir();
359 config_LoadConfigFile( p_vlc, NULL );
362 * Override configuration with command line settings
364 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
368 /* Pause the console because it's destroyed when we exit */
369 fprintf( stderr, "The command line options couldn't be loaded, check "
370 "that they are valid.\nPress the RETURN key to continue..." );
373 //module_EndBank( p_vlc );
374 if( i_object ) vlc_object_release( p_vlc );
379 * System specific configuration
381 system_Configure( p_vlc );
384 * Message queue options
386 if( config_GetInt( p_vlc, "quiet" ) )
388 libvlc.i_verbose = -1;
392 int i_tmp = config_GetInt( p_vlc, "verbose" );
395 libvlc.i_verbose = __MIN( i_tmp, 2 );
398 libvlc.b_color = libvlc.b_color || config_GetInt( p_vlc, "color" );
401 * Output messages that may still be in the queue
405 /* p_vlc inititalization. FIXME ? */
406 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
408 #if defined( __i386__ )
409 if( !config_GetInt( p_vlc, "mmx" ) )
410 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
411 if( !config_GetInt( p_vlc, "3dn" ) )
412 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
413 if( !config_GetInt( p_vlc, "mmxext" ) )
414 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
415 if( !config_GetInt( p_vlc, "sse" ) )
416 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
418 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
419 if( !config_GetInt( p_vlc, "altivec" ) )
420 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
423 #define PRINT_CAPABILITY( capability, string ) \
424 if( libvlc.i_cpu & capability ) \
426 strncat( p_capabilities, string " ", \
427 sizeof(p_capabilities) - strlen(p_capabilities) ); \
428 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
431 p_capabilities[0] = '\0';
432 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
433 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
434 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
435 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
436 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
437 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
438 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
439 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
440 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
441 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
444 * Choose the best memcpy module
446 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy" );
448 if( p_vlc->pf_memcpy == NULL )
450 p_vlc->pf_memcpy = memcpy;
453 if( p_vlc->pf_memset == NULL )
455 p_vlc->pf_memset = memset;
459 * Initialize shared resources and libraries
461 if( config_GetInt( p_vlc, "network-channel" )
462 && network_ChannelCreate( p_vlc ) )
464 /* On error during Channels initialization, switch off channels */
466 "channels initialization failed, deactivating channels" );
467 config_PutInt( p_vlc, "network-channel", VLC_FALSE );
471 * Initialize playlist and get commandline files
473 p_playlist = playlist_Create( p_vlc );
476 msg_Err( p_vlc, "playlist initialization failed" );
477 if( p_vlc->p_memcpy_module != NULL )
479 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
481 //module_EndBank( p_vlc );
482 if( i_object ) vlc_object_release( p_vlc );
487 * Get input filenames given as commandline arguments
489 GetFilenames( p_vlc, i_argc, ppsz_argv );
491 if( i_object ) vlc_object_release( p_vlc );
495 /*****************************************************************************
496 * VLC_AddIntf: add an interface
497 *****************************************************************************
498 * This function opens an interface plugin and runs it. If b_block is set
499 * to 0, VLC_AddIntf will return immediately and let the interface run in a
500 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
501 * user requests to quit.
502 *****************************************************************************/
503 int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
506 intf_thread_t *p_intf;
508 char *psz_oldmodule = NULL;
510 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
519 psz_oldmodule = config_GetPsz( p_vlc, "intf" );
520 config_PutPsz( p_vlc, "intf", psz_module );
523 /* Try to create the interface */
524 p_intf = intf_Create( p_vlc );
528 config_PutPsz( p_vlc, "intf", psz_oldmodule );
531 free( psz_oldmodule );
537 msg_Err( p_vlc, "interface initialization failed" );
538 if( i_object ) vlc_object_release( p_vlc );
542 /* Try to run the interface */
543 p_intf->b_block = b_block;
544 i_err = intf_RunThread( p_intf );
547 vlc_object_detach( p_intf );
548 intf_Destroy( p_intf );
549 if( i_object ) vlc_object_release( p_vlc );
553 if( i_object ) vlc_object_release( p_vlc );
557 /*****************************************************************************
558 * VLC_Destroy: stop playing and destroy everything.
559 *****************************************************************************
560 * This function requests the running threads to finish, waits for their
561 * termination, and destroys their structure.
562 *****************************************************************************/
563 int VLC_Destroy( int i_object )
567 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
575 * Go back into channel 0 which is the network
577 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
579 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
583 * Free allocated memory
585 if( p_vlc->p_memcpy_module )
587 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
588 p_vlc->p_memcpy_module = NULL;
591 if( p_vlc->psz_homedir )
593 free( p_vlc->psz_homedir );
594 p_vlc->psz_homedir = NULL;
598 * XXX: Free module bank !
600 //module_EndBank( p_vlc );
603 * System specific cleaning code
607 /* Destroy mutexes */
608 vlc_mutex_destroy( &p_vlc->config_lock );
610 vlc_object_detach( p_vlc );
612 vlc_object_destroy( p_vlc );
614 /* Stop thread system: last one out please shut the door! */
615 vlc_threads_end( &libvlc );
617 if( i_object ) vlc_object_release( p_vlc );
621 /*****************************************************************************
622 * VLC_Die: ask vlc to die.
623 *****************************************************************************
624 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
625 * task. It is your duty to call vlc_end and VLC_Destroy afterwards.
626 *****************************************************************************/
627 int VLC_Die( int i_object )
631 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
638 p_vlc->b_die = VLC_TRUE;
640 if( i_object ) vlc_object_release( p_vlc );
644 /*****************************************************************************
645 * VLC_AddTarget: adds a target for playing.
646 *****************************************************************************
647 * This function adds psz_target to the current playlist. If a playlist does
648 * not exist, it will create one.
649 *****************************************************************************/
650 int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
653 playlist_t *p_playlist;
656 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
663 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
665 if( p_playlist == NULL )
667 msg_Dbg( p_vlc, "no playlist present, creating one" );
668 p_playlist = playlist_Create( p_vlc );
670 if( p_playlist == NULL )
672 if( i_object ) vlc_object_release( p_vlc );
676 vlc_object_yield( p_playlist );
679 i_err = playlist_Add( p_playlist, psz_target, i_mode, i_pos );
681 vlc_object_release( p_playlist );
683 if( i_object ) vlc_object_release( p_vlc );
687 /*****************************************************************************
688 * VLC_Set: set a vlc variable
689 *****************************************************************************
691 *****************************************************************************/
692 int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
697 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
704 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
705 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
706 if( !strncmp( psz_var, "conf::", 6 ) )
708 module_config_t *p_item;
709 char const *psz_newvar = psz_var + 6;
711 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
715 switch( p_item->i_type )
717 case CONFIG_ITEM_BOOL:
718 config_PutInt( p_vlc, psz_newvar, value.b_bool );
720 case CONFIG_ITEM_INTEGER:
721 config_PutInt( p_vlc, psz_newvar, value.i_int );
723 case CONFIG_ITEM_FLOAT:
724 config_PutFloat( p_vlc, psz_newvar, value.f_float );
727 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
730 if( i_object ) vlc_object_release( p_vlc );
735 i_ret = var_Set( p_vlc, psz_var, value );
737 if( i_object ) vlc_object_release( p_vlc );
741 /*****************************************************************************
742 * VLC_Get: get a vlc variable
743 *****************************************************************************
745 *****************************************************************************/
746 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
751 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
758 i_ret = var_Get( p_vlc, psz_var, p_value );
760 if( i_object ) vlc_object_release( p_vlc );
764 /* FIXME: temporary hacks */
766 /*****************************************************************************
768 *****************************************************************************/
769 int VLC_Play( int i_object )
771 playlist_t * p_playlist;
774 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
776 /* Check that the handle is valid */
782 /* add pseudo sap interface; non blocking */
783 if( config_GetInt( p_vlc, "sap" ) )
785 msg_Dbg( p_vlc, "adding sap interface" );
786 VLC_AddIntf( 0, "sap", VLC_FALSE );
789 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
791 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
795 if( i_object ) vlc_object_release( p_vlc );
799 vlc_mutex_lock( &p_playlist->object_lock );
800 if( p_playlist->i_size )
802 vlc_mutex_unlock( &p_playlist->object_lock );
803 playlist_Play( p_playlist );
807 vlc_mutex_unlock( &p_playlist->object_lock );
810 vlc_object_release( p_playlist );
812 if( i_object ) vlc_object_release( p_vlc );
816 /*****************************************************************************
818 *****************************************************************************/
819 int VLC_Stop( int i_object )
821 intf_thread_t * p_intf;
822 playlist_t * p_playlist;
823 vout_thread_t * p_vout;
824 aout_instance_t * p_aout;
827 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
829 /* Check that the handle is valid */
836 * Ask the interfaces to stop and destroy them
838 msg_Dbg( p_vlc, "removing all interfaces" );
839 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
841 intf_StopThread( p_intf );
842 vlc_object_detach( p_intf );
843 vlc_object_release( p_intf );
844 intf_Destroy( p_intf );
850 msg_Dbg( p_vlc, "removing all playlists" );
851 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
854 vlc_object_detach( p_playlist );
855 vlc_object_release( p_playlist );
856 playlist_Destroy( p_playlist );
862 msg_Dbg( p_vlc, "removing all video outputs" );
863 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
865 vlc_object_detach( p_vout );
866 vlc_object_release( p_vout );
867 vout_Destroy( p_vout );
873 msg_Dbg( p_vlc, "removing all audio outputs" );
874 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
876 vlc_object_detach( (vlc_object_t *)p_aout );
877 vlc_object_release( (vlc_object_t *)p_aout );
878 aout_Delete( p_aout );
881 if( i_object ) vlc_object_release( p_vlc );
885 /*****************************************************************************
886 * VLC_Pause: toggle pause
887 *****************************************************************************/
888 int VLC_Pause( int i_object )
890 input_thread_t *p_input;
893 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
900 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
904 if( i_object ) vlc_object_release( p_vlc );
908 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
909 vlc_object_release( p_input );
911 if( i_object ) vlc_object_release( p_vlc );
915 /*****************************************************************************
916 * VLC_FullScreen: toggle fullscreen mode
917 *****************************************************************************/
918 int VLC_FullScreen( int i_object )
920 vout_thread_t *p_vout;
923 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
930 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
934 if( i_object ) vlc_object_release( p_vlc );
938 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
939 vlc_object_release( p_vout );
941 if( i_object ) vlc_object_release( p_vlc );
945 /* following functions are local */
947 /*****************************************************************************
948 * SetLanguage: set the interface language.
949 *****************************************************************************
950 * We set the LC_MESSAGES locale category for interface messages and buttons,
951 * as well as the LC_CTYPE category for string sorting and possible wide
953 *****************************************************************************/
954 static void SetLanguage ( char const *psz_lang )
956 #if defined( ENABLE_NLS ) \
957 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
959 # if defined( HAVE_INCLUDED_GETTEXT ) && !defined( HAVE_LC_MESSAGES )
962 /* We set LC_ALL manually because it is the only way to set
963 * the language at runtime under eg. Windows. Beware that this
964 * makes the environment unconsistent when libvlc is unloaded and
965 * should probably be moved to a safer place like vlc.c. */
966 static char psz_lcall[20];
967 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
968 psz_lcall[19] = '\0';
973 # if defined( HAVE_LC_MESSAGES )
974 setlocale( LC_MESSAGES, psz_lang );
976 setlocale( LC_CTYPE, psz_lang );
978 /* Specify where to find the locales for current domain */
979 if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
981 fprintf( stderr, "warning: no domain %s in directory %s\n",
982 PACKAGE, LOCALEDIR );
985 /* Set the default domain */
986 textdomain( PACKAGE );
990 /*****************************************************************************
991 * GetFilenames: parse command line options which are not flags
992 *****************************************************************************
993 * Parse command line for input files.
994 *****************************************************************************/
995 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
999 /* We assume that the remaining parameters are filenames */
1000 for( i_opt = i_argc - 1; i_opt > optind; i_opt-- )
1002 /* TODO: write an internal function of this one, to avoid
1003 * unnecessary lookups. */
1004 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1005 PLAYLIST_INSERT, 0 );
1008 /* If there is at least one target, play it */
1009 if( i_argc > optind )
1011 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ optind ],
1012 PLAYLIST_INSERT | PLAYLIST_GO, 0 );
1018 /*****************************************************************************
1019 * Usage: print program usage
1020 *****************************************************************************
1021 * Print a short inline help. Message interface is initialized at this stage.
1022 *****************************************************************************/
1023 static void Usage( vlc_t *p_this, char const *psz_module_name )
1025 #define FORMAT_STRING " --%s%s%s%s%s%s%s %s%s\n"
1026 /* option name -------------' | | | | | |
1027 * <bra --------------------------' | | | | |
1028 * option type or "" ---------------' | | | |
1029 * ket> ------------------------------' | | |
1030 * padding spaces ----------------------' | |
1031 * comment --------------------------------' |
1032 * comment suffix ---------------------------'
1034 * The purpose of having bra and ket is that we might i18n them as well.
1036 #define LINE_START 8
1037 #define PADDING_SPACES 25
1040 module_config_t *p_item;
1041 char psz_spaces[PADDING_SPACES+LINE_START+1];
1042 char psz_format[sizeof(FORMAT_STRING)];
1045 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1046 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1048 strcpy( psz_format, FORMAT_STRING );
1054 /* List all modules */
1055 list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1057 /* Enumerate the config for each module */
1058 for( i_index = 0; i_index < list.i_count; i_index++ )
1060 vlc_bool_t b_help_module;
1062 p_parser = (module_t *)list.p_values[i_index].p_object ;
1064 if( psz_module_name && strcmp( psz_module_name,
1065 p_parser->psz_object_name ) )
1070 /* Ignore modules without config options */
1071 if( !p_parser->i_config_items )
1076 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1078 /* Print module options */
1079 for( p_item = p_parser->p_config;
1080 p_item->i_type != CONFIG_HINT_END;
1083 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1084 char *psz_suf = "", *psz_prefix = NULL;
1087 switch( p_item->i_type )
1089 case CONFIG_HINT_CATEGORY:
1090 case CONFIG_HINT_USAGE:
1091 fprintf( stdout, " %s\n", p_item->psz_text );
1094 case CONFIG_ITEM_STRING:
1095 case CONFIG_ITEM_FILE:
1096 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1097 if( !p_item->ppsz_list )
1099 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1105 psz_type = malloc( 1000 );
1106 memset( psz_type, 0, 1000 );
1107 for( i=0; p_item->ppsz_list[i]; i++ )
1109 strcat( psz_type, p_item->ppsz_list[i] );
1110 strcat( psz_type, "|" );
1112 psz_type[ strlen( psz_type ) - 1 ] = '\0';
1116 case CONFIG_ITEM_INTEGER:
1117 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1119 case CONFIG_ITEM_FLOAT:
1120 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1122 case CONFIG_ITEM_BOOL:
1123 psz_bra = ""; psz_type = ""; psz_ket = "";
1124 if( !b_help_module )
1126 psz_suf = p_item->i_value ? _(" (default enabled)") :
1127 _(" (default disabled)");
1132 /* Add short option if any */
1133 if( p_item->i_short )
1135 psz_format[2] = '-';
1136 psz_format[3] = p_item->i_short;
1137 psz_format[4] = ',';
1141 psz_format[2] = ' ';
1142 psz_format[3] = ' ';
1143 psz_format[4] = ' ';
1148 i = PADDING_SPACES - strlen( p_item->psz_name )
1149 - strlen( psz_bra ) - strlen( psz_type )
1150 - strlen( psz_ket ) - 1;
1151 if( p_item->i_type == CONFIG_ITEM_BOOL
1154 /* If option is of type --foo-bar, we print its counterpart
1155 * as --no-foo-bar, but if it is of type --foobar (without
1156 * dashes in the name) we print it as --nofoobar. Both
1157 * values are of course valid, only the display changes. */
1158 vlc_bool_t b_dash = VLC_FALSE;
1159 psz_prefix = p_item->psz_name;
1160 while( *psz_prefix )
1162 if( *psz_prefix++ == '-' )
1171 psz_prefix = ", --no-";
1172 i -= strlen( p_item->psz_name ) + strlen( ", --no-" );
1176 psz_prefix = ", --no";
1177 i -= strlen( p_item->psz_name ) + strlen( ", --no" );
1184 psz_spaces[i] = '\n';
1188 psz_spaces[i] = '\0';
1191 if( p_item->i_type == CONFIG_ITEM_BOOL &&
1194 fprintf( stdout, psz_format, p_item->psz_name, psz_prefix,
1195 p_item->psz_name, psz_bra, psz_type, psz_ket,
1196 psz_spaces, p_item->psz_text, psz_suf );
1200 fprintf( stdout, psz_format, p_item->psz_name, "", "",
1201 psz_bra, psz_type, psz_ket, psz_spaces,
1202 p_item->psz_text, psz_suf );
1204 psz_spaces[i] = ' ';
1205 if ( p_item->ppsz_list )
1213 /* Release the module list */
1214 vlc_list_release( &list );
1216 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1217 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1222 /*****************************************************************************
1223 * ListModules: list the available modules with their description
1224 *****************************************************************************
1225 * Print a list of all available modules (builtins and plugins) and a short
1226 * description for each one.
1227 *****************************************************************************/
1228 static void ListModules( vlc_t *p_this )
1232 char psz_spaces[22];
1235 memset( psz_spaces, ' ', 22 );
1242 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
1243 p_this->p_vlc->psz_object_name );
1245 fprintf( stdout, _("[module] [description]\n") );
1247 /* List all modules */
1248 list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1250 /* Enumerate each module */
1251 for( i_index = 0; i_index < list.i_count; i_index++ )
1255 p_parser = (module_t *)list.p_values[i_index].p_object ;
1257 /* Nasty hack, but right now I'm too tired to think about a nice
1259 i = 22 - strlen( p_parser->psz_object_name ) - 1;
1263 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
1264 psz_spaces, p_parser->psz_longname );
1266 psz_spaces[i] = ' ';
1269 vlc_list_release( &list );
1271 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1272 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1277 /*****************************************************************************
1278 * Version: print complete program version
1279 *****************************************************************************
1280 * Print complete program version and build number.
1281 *****************************************************************************/
1282 static void Version( void )
1288 fprintf( stdout, VERSION_MESSAGE "\n" );
1290 _("This program comes with NO WARRANTY, to the extent permitted by "
1291 "law.\nYou may redistribute it under the terms of the GNU General "
1292 "Public License;\nsee the file named COPYING for details.\n"
1293 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1295 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1296 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1301 /*****************************************************************************
1302 * ShowConsole: On Win32, create an output console for debug messages
1303 *****************************************************************************
1304 * This function is useful only on Win32.
1305 *****************************************************************************/
1307 static void ShowConsole( void )
1311 freopen( "CONOUT$", "w", stdout );
1312 freopen( "CONOUT$", "w", stderr );
1313 freopen( "CONIN$", "r", stdin );