1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
5 * $Id: libvlc.c,v 1.55 2002/12/27 00:17:48 massiot 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 * System specific initialization code
231 system_Init( p_vlc, &i_argc, ppsz_argv );
233 /* Get the executable name (similar to the basename command) */
236 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
239 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
245 p_vlc->psz_object_name = "vlc";
249 * Support for gettext
252 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
254 /* Hack: insert the help module here */
255 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
256 if( p_help_module == NULL )
258 //module_EndBank( p_vlc );
259 if( i_object ) vlc_object_release( p_vlc );
262 p_help_module->psz_object_name = "help";
263 config_Duplicate( p_help_module, p_help_config );
264 vlc_object_attach( p_help_module, libvlc.p_module_bank );
267 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
269 vlc_object_detach( p_help_module );
270 config_Free( p_help_module );
271 vlc_object_destroy( p_help_module );
272 //module_EndBank( p_vlc );
273 if( i_object ) vlc_object_release( p_vlc );
279 /* Check for short help option */
280 if( config_GetInt( p_vlc, "help" ) )
282 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
283 p_vlc->psz_object_name );
284 Usage( p_vlc, "main" );
285 Usage( p_vlc, "help" );
288 /* Check for version option */
289 else if( config_GetInt( p_vlc, "version" ) )
295 /* Hack: remove the help module here */
296 vlc_object_detach( p_help_module );
301 config_Free( p_help_module );
302 vlc_object_destroy( p_help_module );
303 //module_EndBank( p_vlc );
304 if( i_object ) vlc_object_release( p_vlc );
309 * Load the builtins and plugins into the module_bank.
310 * We have to do it before config_Load*() because this also gets the
311 * list of configuration options exported by each module and loads their
314 module_LoadBuiltins( &libvlc );
315 module_LoadPlugins( &libvlc );
316 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
317 libvlc.p_module_bank->i_children );
319 /* Hack: insert the help module here */
320 vlc_object_attach( p_help_module, libvlc.p_module_bank );
323 /* Check for help on modules */
324 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
326 Usage( p_vlc, p_tmp );
330 /* Check for long help option */
331 else if( config_GetInt( p_vlc, "longhelp" ) )
333 Usage( p_vlc, NULL );
336 /* Check for module list option */
337 else if( config_GetInt( p_vlc, "list" ) )
339 ListModules( p_vlc );
343 /* Hack: remove the help module here */
344 vlc_object_detach( p_help_module );
345 config_Free( p_help_module );
346 vlc_object_destroy( p_help_module );
351 //module_EndBank( p_vlc );
352 if( i_object ) vlc_object_release( p_vlc );
357 * Override default configuration with config file settings
359 p_vlc->psz_homedir = config_GetHomeDir();
360 config_LoadConfigFile( p_vlc, NULL );
363 * Override configuration with command line settings
365 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
369 /* Pause the console because it's destroyed when we exit */
370 fprintf( stderr, "The command line options couldn't be loaded, check "
371 "that they are valid.\nPress the RETURN key to continue..." );
374 //module_EndBank( p_vlc );
375 if( i_object ) vlc_object_release( p_vlc );
380 * System specific configuration
382 system_Configure( p_vlc );
385 * Message queue options
387 if( config_GetInt( p_vlc, "quiet" ) )
389 libvlc.i_verbose = -1;
393 int i_tmp = config_GetInt( p_vlc, "verbose" );
396 libvlc.i_verbose = __MIN( i_tmp, 2 );
399 libvlc.b_color = libvlc.b_color || config_GetInt( p_vlc, "color" );
402 * Output messages that may still be in the queue
406 /* p_vlc inititalization. FIXME ? */
407 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
409 #if defined( __i386__ )
410 if( !config_GetInt( p_vlc, "mmx" ) )
411 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
412 if( !config_GetInt( p_vlc, "3dn" ) )
413 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
414 if( !config_GetInt( p_vlc, "mmxext" ) )
415 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
416 if( !config_GetInt( p_vlc, "sse" ) )
417 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
419 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
420 if( !config_GetInt( p_vlc, "altivec" ) )
421 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
424 #define PRINT_CAPABILITY( capability, string ) \
425 if( libvlc.i_cpu & capability ) \
427 strncat( p_capabilities, string " ", \
428 sizeof(p_capabilities) - strlen(p_capabilities) ); \
429 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
432 p_capabilities[0] = '\0';
433 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
434 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
435 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
436 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
437 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
438 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
439 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
440 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
441 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
442 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
445 * Choose the best memcpy module
447 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy" );
449 if( p_vlc->pf_memcpy == NULL )
451 p_vlc->pf_memcpy = memcpy;
454 if( p_vlc->pf_memset == NULL )
456 p_vlc->pf_memset = memset;
460 * Initialize shared resources and libraries
462 if( config_GetInt( p_vlc, "network-channel" )
463 && network_ChannelCreate( p_vlc ) )
465 /* On error during Channels initialization, switch off channels */
467 "channels initialization failed, deactivating channels" );
468 config_PutInt( p_vlc, "network-channel", VLC_FALSE );
472 * Initialize playlist and get commandline files
474 p_playlist = playlist_Create( p_vlc );
477 msg_Err( p_vlc, "playlist initialization failed" );
478 if( p_vlc->p_memcpy_module != NULL )
480 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
482 //module_EndBank( p_vlc );
483 if( i_object ) vlc_object_release( p_vlc );
488 * Get input filenames given as commandline arguments
490 GetFilenames( p_vlc, i_argc, ppsz_argv );
492 if( i_object ) vlc_object_release( p_vlc );
496 /*****************************************************************************
497 * VLC_AddIntf: add an interface
498 *****************************************************************************
499 * This function opens an interface plugin and runs it. If b_block is set
500 * to 0, VLC_AddIntf will return immediately and let the interface run in a
501 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
502 * user requests to quit.
503 *****************************************************************************/
504 int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
507 intf_thread_t *p_intf;
509 char *psz_oldmodule = NULL;
511 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
520 psz_oldmodule = config_GetPsz( p_vlc, "intf" );
521 config_PutPsz( p_vlc, "intf", psz_module );
524 /* Try to create the interface */
525 p_intf = intf_Create( p_vlc );
529 config_PutPsz( p_vlc, "intf", psz_oldmodule );
532 free( psz_oldmodule );
538 msg_Err( p_vlc, "interface initialization failed" );
539 if( i_object ) vlc_object_release( p_vlc );
543 /* Try to run the interface */
544 p_intf->b_block = b_block;
545 i_err = intf_RunThread( p_intf );
548 vlc_object_detach( p_intf );
549 intf_Destroy( p_intf );
550 if( i_object ) vlc_object_release( p_vlc );
554 if( i_object ) vlc_object_release( p_vlc );
558 /*****************************************************************************
559 * VLC_Destroy: stop playing and destroy everything.
560 *****************************************************************************
561 * This function requests the running threads to finish, waits for their
562 * termination, and destroys their structure.
563 *****************************************************************************/
564 int VLC_Destroy( int i_object )
568 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
576 * Go back into channel 0 which is the network
578 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
580 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
584 * Free allocated memory
586 if( p_vlc->p_memcpy_module )
588 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
589 p_vlc->p_memcpy_module = NULL;
592 if( p_vlc->psz_homedir )
594 free( p_vlc->psz_homedir );
595 p_vlc->psz_homedir = NULL;
599 * XXX: Free module bank !
601 //module_EndBank( p_vlc );
604 * System specific cleaning code
608 /* Destroy mutexes */
609 vlc_mutex_destroy( &p_vlc->config_lock );
611 vlc_object_detach( p_vlc );
613 vlc_object_destroy( p_vlc );
615 /* Stop thread system: last one out please shut the door! */
616 vlc_threads_end( &libvlc );
618 if( i_object ) vlc_object_release( p_vlc );
622 /*****************************************************************************
623 * VLC_Die: ask vlc to die.
624 *****************************************************************************
625 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
626 * task. It is your duty to call vlc_end and VLC_Destroy afterwards.
627 *****************************************************************************/
628 int VLC_Die( int i_object )
632 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
639 p_vlc->b_die = VLC_TRUE;
641 if( i_object ) vlc_object_release( p_vlc );
645 /*****************************************************************************
646 * VLC_AddTarget: adds a target for playing.
647 *****************************************************************************
648 * This function adds psz_target to the current playlist. If a playlist does
649 * not exist, it will create one.
650 *****************************************************************************/
651 int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
654 playlist_t *p_playlist;
657 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
664 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
666 if( p_playlist == NULL )
668 msg_Dbg( p_vlc, "no playlist present, creating one" );
669 p_playlist = playlist_Create( p_vlc );
671 if( p_playlist == NULL )
673 if( i_object ) vlc_object_release( p_vlc );
677 vlc_object_yield( p_playlist );
680 i_err = playlist_Add( p_playlist, psz_target, i_mode, i_pos );
682 vlc_object_release( p_playlist );
684 if( i_object ) vlc_object_release( p_vlc );
688 /*****************************************************************************
689 * VLC_Set: set a vlc variable
690 *****************************************************************************
692 *****************************************************************************/
693 int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
698 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
705 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
706 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
707 if( !strncmp( psz_var, "conf::", 6 ) )
709 module_config_t *p_item;
710 char const *psz_newvar = psz_var + 6;
712 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
716 switch( p_item->i_type )
718 case CONFIG_ITEM_BOOL:
719 config_PutInt( p_vlc, psz_newvar, value.b_bool );
721 case CONFIG_ITEM_INTEGER:
722 config_PutInt( p_vlc, psz_newvar, value.i_int );
724 case CONFIG_ITEM_FLOAT:
725 config_PutFloat( p_vlc, psz_newvar, value.f_float );
728 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
731 if( i_object ) vlc_object_release( p_vlc );
736 i_ret = var_Set( p_vlc, psz_var, value );
738 if( i_object ) vlc_object_release( p_vlc );
742 /*****************************************************************************
743 * VLC_Get: get a vlc variable
744 *****************************************************************************
746 *****************************************************************************/
747 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
752 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
759 i_ret = var_Get( p_vlc, psz_var, p_value );
761 if( i_object ) vlc_object_release( p_vlc );
765 /* FIXME: temporary hacks */
767 /*****************************************************************************
769 *****************************************************************************/
770 int VLC_Play( int i_object )
772 playlist_t * p_playlist;
775 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
777 /* Check that the handle is valid */
783 /* add pseudo sap interface; non blocking */
784 if( config_GetInt( p_vlc, "sap" ) )
786 msg_Dbg( p_vlc, "adding sap interface" );
787 VLC_AddIntf( 0, "sap", VLC_FALSE );
790 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
792 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
796 if( i_object ) vlc_object_release( p_vlc );
800 vlc_mutex_lock( &p_playlist->object_lock );
801 if( p_playlist->i_size )
803 vlc_mutex_unlock( &p_playlist->object_lock );
804 playlist_Play( p_playlist );
808 vlc_mutex_unlock( &p_playlist->object_lock );
811 vlc_object_release( p_playlist );
813 if( i_object ) vlc_object_release( p_vlc );
817 /*****************************************************************************
819 *****************************************************************************/
820 int VLC_Stop( int i_object )
822 intf_thread_t * p_intf;
823 playlist_t * p_playlist;
824 vout_thread_t * p_vout;
825 aout_instance_t * p_aout;
828 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
830 /* Check that the handle is valid */
837 * Ask the interfaces to stop and destroy them
839 msg_Dbg( p_vlc, "removing all interfaces" );
840 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
842 intf_StopThread( p_intf );
843 vlc_object_detach( p_intf );
844 vlc_object_release( p_intf );
845 intf_Destroy( p_intf );
851 msg_Dbg( p_vlc, "removing all playlists" );
852 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
855 vlc_object_detach( p_playlist );
856 vlc_object_release( p_playlist );
857 playlist_Destroy( p_playlist );
863 msg_Dbg( p_vlc, "removing all video outputs" );
864 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
866 vlc_object_detach( p_vout );
867 vlc_object_release( p_vout );
868 vout_Destroy( p_vout );
874 msg_Dbg( p_vlc, "removing all audio outputs" );
875 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
877 vlc_object_detach( (vlc_object_t *)p_aout );
878 vlc_object_release( (vlc_object_t *)p_aout );
879 aout_Delete( p_aout );
882 if( i_object ) vlc_object_release( p_vlc );
886 /*****************************************************************************
887 * VLC_Pause: toggle pause
888 *****************************************************************************/
889 int VLC_Pause( int i_object )
891 input_thread_t *p_input;
894 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
901 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
905 if( i_object ) vlc_object_release( p_vlc );
909 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
910 vlc_object_release( p_input );
912 if( i_object ) vlc_object_release( p_vlc );
916 /*****************************************************************************
917 * VLC_FullScreen: toggle fullscreen mode
918 *****************************************************************************/
919 int VLC_FullScreen( int i_object )
921 vout_thread_t *p_vout;
924 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
931 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
935 if( i_object ) vlc_object_release( p_vlc );
939 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
940 vlc_object_release( p_vout );
942 if( i_object ) vlc_object_release( p_vlc );
946 /* following functions are local */
948 /*****************************************************************************
949 * SetLanguage: set the interface language.
950 *****************************************************************************
951 * We set the LC_MESSAGES locale category for interface messages and buttons,
952 * as well as the LC_CTYPE category for string sorting and possible wide
954 *****************************************************************************/
955 static void SetLanguage ( char const *psz_lang )
957 #if defined( ENABLE_NLS ) \
958 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
962 char * psz_vlcpath = system_GetProgramPath();
966 # if defined( HAVE_INCLUDED_GETTEXT ) && !defined( HAVE_LC_MESSAGES )
969 /* We set LC_ALL manually because it is the only way to set
970 * the language at runtime under eg. Windows. Beware that this
971 * makes the environment unconsistent when libvlc is unloaded and
972 * should probably be moved to a safer place like vlc.c. */
973 static char psz_lcall[20];
974 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
975 psz_lcall[19] = '\0';
980 # if defined( HAVE_LC_MESSAGES )
981 setlocale( LC_MESSAGES, psz_lang );
983 setlocale( LC_CTYPE, psz_lang );
985 /* Specify where to find the locales for current domain */
987 psz_path = LOCALEDIR;
989 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", psz_vlcpath,
993 if( !bindtextdomain( PACKAGE, psz_path ) )
995 fprintf( stderr, "warning: no domain %s in directory %s\n",
999 /* Set the default domain */
1000 textdomain( PACKAGE );
1004 /*****************************************************************************
1005 * GetFilenames: parse command line options which are not flags
1006 *****************************************************************************
1007 * Parse command line for input files.
1008 *****************************************************************************/
1009 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1013 /* We assume that the remaining parameters are filenames */
1014 for( i_opt = i_argc - 1; i_opt > optind; i_opt-- )
1016 /* TODO: write an internal function of this one, to avoid
1017 * unnecessary lookups. */
1018 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1019 PLAYLIST_INSERT, 0 );
1022 /* If there is at least one target, play it */
1023 if( i_argc > optind )
1025 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ optind ],
1026 PLAYLIST_INSERT | PLAYLIST_GO, 0 );
1032 /*****************************************************************************
1033 * Usage: print program usage
1034 *****************************************************************************
1035 * Print a short inline help. Message interface is initialized at this stage.
1036 *****************************************************************************/
1037 static void Usage( vlc_t *p_this, char const *psz_module_name )
1039 #define FORMAT_STRING " --%s%s%s%s%s%s%s %s%s\n"
1040 /* option name -------------' | | | | | |
1041 * <bra --------------------------' | | | | |
1042 * option type or "" ---------------' | | | |
1043 * ket> ------------------------------' | | |
1044 * padding spaces ----------------------' | |
1045 * comment --------------------------------' |
1046 * comment suffix ---------------------------'
1048 * The purpose of having bra and ket is that we might i18n them as well.
1050 #define LINE_START 8
1051 #define PADDING_SPACES 25
1054 module_config_t *p_item;
1055 char psz_spaces[PADDING_SPACES+LINE_START+1];
1056 char psz_format[sizeof(FORMAT_STRING)];
1059 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1060 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1062 strcpy( psz_format, FORMAT_STRING );
1068 /* List all modules */
1069 list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1071 /* Enumerate the config for each module */
1072 for( i_index = 0; i_index < list.i_count; i_index++ )
1074 vlc_bool_t b_help_module;
1076 p_parser = (module_t *)list.p_values[i_index].p_object ;
1078 if( psz_module_name && strcmp( psz_module_name,
1079 p_parser->psz_object_name ) )
1084 /* Ignore modules without config options */
1085 if( !p_parser->i_config_items )
1090 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1092 /* Print module options */
1093 for( p_item = p_parser->p_config;
1094 p_item->i_type != CONFIG_HINT_END;
1097 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1098 char *psz_suf = "", *psz_prefix = NULL;
1101 switch( p_item->i_type )
1103 case CONFIG_HINT_CATEGORY:
1104 case CONFIG_HINT_USAGE:
1105 fprintf( stdout, " %s\n", p_item->psz_text );
1108 case CONFIG_ITEM_STRING:
1109 case CONFIG_ITEM_FILE:
1110 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1111 if( !p_item->ppsz_list )
1113 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1119 psz_type = malloc( 1000 );
1120 memset( psz_type, 0, 1000 );
1121 for( i=0; p_item->ppsz_list[i]; i++ )
1123 strcat( psz_type, p_item->ppsz_list[i] );
1124 strcat( psz_type, "|" );
1126 psz_type[ strlen( psz_type ) - 1 ] = '\0';
1130 case CONFIG_ITEM_INTEGER:
1131 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1133 case CONFIG_ITEM_FLOAT:
1134 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1136 case CONFIG_ITEM_BOOL:
1137 psz_bra = ""; psz_type = ""; psz_ket = "";
1138 if( !b_help_module )
1140 psz_suf = p_item->i_value ? _(" (default enabled)") :
1141 _(" (default disabled)");
1146 /* Add short option if any */
1147 if( p_item->i_short )
1149 psz_format[2] = '-';
1150 psz_format[3] = p_item->i_short;
1151 psz_format[4] = ',';
1155 psz_format[2] = ' ';
1156 psz_format[3] = ' ';
1157 psz_format[4] = ' ';
1162 i = PADDING_SPACES - strlen( p_item->psz_name )
1163 - strlen( psz_bra ) - strlen( psz_type )
1164 - strlen( psz_ket ) - 1;
1165 if( p_item->i_type == CONFIG_ITEM_BOOL
1168 /* If option is of type --foo-bar, we print its counterpart
1169 * as --no-foo-bar, but if it is of type --foobar (without
1170 * dashes in the name) we print it as --nofoobar. Both
1171 * values are of course valid, only the display changes. */
1172 vlc_bool_t b_dash = VLC_FALSE;
1173 psz_prefix = p_item->psz_name;
1174 while( *psz_prefix )
1176 if( *psz_prefix++ == '-' )
1185 psz_prefix = ", --no-";
1186 i -= strlen( p_item->psz_name ) + strlen( ", --no-" );
1190 psz_prefix = ", --no";
1191 i -= strlen( p_item->psz_name ) + strlen( ", --no" );
1198 psz_spaces[i] = '\n';
1202 psz_spaces[i] = '\0';
1205 if( p_item->i_type == CONFIG_ITEM_BOOL &&
1208 fprintf( stdout, psz_format, p_item->psz_name, psz_prefix,
1209 p_item->psz_name, psz_bra, psz_type, psz_ket,
1210 psz_spaces, p_item->psz_text, psz_suf );
1214 fprintf( stdout, psz_format, p_item->psz_name, "", "",
1215 psz_bra, psz_type, psz_ket, psz_spaces,
1216 p_item->psz_text, psz_suf );
1218 psz_spaces[i] = ' ';
1219 if ( p_item->ppsz_list )
1227 /* Release the module list */
1228 vlc_list_release( &list );
1230 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1231 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1236 /*****************************************************************************
1237 * ListModules: list the available modules with their description
1238 *****************************************************************************
1239 * Print a list of all available modules (builtins and plugins) and a short
1240 * description for each one.
1241 *****************************************************************************/
1242 static void ListModules( vlc_t *p_this )
1246 char psz_spaces[22];
1249 memset( psz_spaces, ' ', 22 );
1256 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
1257 p_this->p_vlc->psz_object_name );
1259 fprintf( stdout, _("[module] [description]\n") );
1261 /* List all modules */
1262 list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1264 /* Enumerate each module */
1265 for( i_index = 0; i_index < list.i_count; i_index++ )
1269 p_parser = (module_t *)list.p_values[i_index].p_object ;
1271 /* Nasty hack, but right now I'm too tired to think about a nice
1273 i = 22 - strlen( p_parser->psz_object_name ) - 1;
1277 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
1278 psz_spaces, p_parser->psz_longname );
1280 psz_spaces[i] = ' ';
1283 vlc_list_release( &list );
1285 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1286 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1291 /*****************************************************************************
1292 * Version: print complete program version
1293 *****************************************************************************
1294 * Print complete program version and build number.
1295 *****************************************************************************/
1296 static void Version( void )
1302 fprintf( stdout, VERSION_MESSAGE "\n" );
1304 _("This program comes with NO WARRANTY, to the extent permitted by "
1305 "law.\nYou may redistribute it under the terms of the GNU General "
1306 "Public License;\nsee the file named COPYING for details.\n"
1307 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1309 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1310 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1315 /*****************************************************************************
1316 * ShowConsole: On Win32, create an output console for debug messages
1317 *****************************************************************************
1318 * This function is useful only on Win32.
1319 *****************************************************************************/
1321 static void ShowConsole( void )
1325 freopen( "CONOUT$", "w", stdout );
1326 freopen( "CONOUT$", "w", stderr );
1327 freopen( "CONIN$", "r", stdin );