]> git.sesse.net Git - vlc/blob - src/interface/main.c
* Added -a, -c and -s options. (-a doesn't work but I will let the people
[vlc] / src / interface / main.c
1 /*****************************************************************************
2  * main.c: main vlc source
3  * Includes the main() function for vlc. Parses command line, start interface
4  * and spawn threads.
5  *****************************************************************************
6  * Copyright (C) 1998, 1999, 2000 VideoLAN
7  *
8  * Authors:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
31 #include <stdio.h>                                              /* sprintf() */
32
33 #ifdef HAVE_GETOPT_H
34 #include <getopt.h>                                              /* getopt() */
35 #endif
36
37 #include <errno.h>                                                 /* ENOMEM */
38 #include <stdlib.h>                                  /* getenv(), strtol(),  */
39 #include <string.h>                                            /* strerror() */
40
41 #include "config.h"
42 #include "debug.h"
43 #include "common.h"
44 #include "threads.h"
45 #include "mtime.h"
46 #include "tests.h"                                              /* TestMMX() */
47 #include "plugins.h"
48 #include "playlist.h"
49 #include "stream_control.h"
50 #include "input_ext-intf.h"
51
52 #include "intf_msg.h"
53 #include "interface.h"
54
55 #include "audio_output.h"
56
57 #ifdef SYS_BEOS
58 #include "beos_specific.h"
59 #endif
60
61 #include "main.h"
62
63 /*****************************************************************************
64  * Command line options constants. If something is changed here, be sure that
65  * GetConfiguration and Usage are also changed.
66  *****************************************************************************/
67
68 /* Long options return values - note that values corresponding to short options
69  * chars, and in general any regular char, should be avoided */
70 #define OPT_NOAUDIO             150
71 #define OPT_AOUT                151
72 #define OPT_STEREO              152
73 #define OPT_MONO                153
74
75 #define OPT_NOVIDEO             160
76 #define OPT_VOUT                161
77 #define OPT_DISPLAY             162
78 #define OPT_WIDTH               163
79 #define OPT_HEIGHT              164
80 #define OPT_COLOR               165
81 #define OPT_YUV                 166
82
83 #define OPT_VLANS               170
84 #define OPT_SERVER              171
85 #define OPT_PORT                172
86 #define OPT_BROADCAST           173
87
88 #define OPT_SYNCHRO             180
89
90 #define OPT_WARNING             190
91
92 /* Usage fashion */
93 #define USAGE                     0
94 #define SHORT_HELP                1
95 #define LONG_HELP                 2
96
97 /* Long options */
98 #ifdef HAVE_GETOPT_H
99 static const struct option longopts[] =
100 {
101     /*  name,               has_arg,    flag,   val */
102
103     /* General/common options */
104     {   "help",             0,          0,      'h' },
105     {   "longhelp",         0,          0,      'H' },
106     {   "version",          0,          0,      'v' },
107
108     /* Audio options */
109     {   "noaudio",          0,          0,      OPT_NOAUDIO },
110     {   "aout",             1,          0,      OPT_AOUT },
111     {   "stereo",           0,          0,      OPT_STEREO },
112     {   "mono",             0,          0,      OPT_MONO },
113
114     /* Video options */
115     {   "novideo",          0,          0,      OPT_NOVIDEO },
116     {   "vout",             1,          0,      OPT_VOUT },
117     {   "display",          1,          0,      OPT_DISPLAY },
118     {   "width",            1,          0,      OPT_WIDTH },
119     {   "height",           1,          0,      OPT_HEIGHT },
120     {   "grayscale",        0,          0,      'g' },
121     {   "color",            0,          0,      OPT_COLOR },
122     {   "yuv",              1,          0,      OPT_YUV },
123
124     /* DVD options */
125     {   "dvdaudio",         1,          0,      'a' },
126     {   "dvdchannel",       1,          0,      'c' },
127     {   "dvdsubtitle",      1,          0,      's' },
128     
129     /* Input options */
130     {   "vlans",            0,          0,      OPT_VLANS },
131     {   "server",           1,          0,      OPT_SERVER },
132     {   "port",             1,          0,      OPT_PORT },
133     {   "broadcast",        0,          0,      OPT_BROADCAST },
134
135     /* Synchro options */
136     {   "synchro",          1,          0,      OPT_SYNCHRO },
137
138     /* Interface messages */
139     {   "warning",          1,          0,      OPT_WARNING },
140     {   0,                  0,          0,      0 }
141 };
142
143 /* Short options */
144 static const char *psz_shortopts = "hHvga:s:c:";
145 #endif
146
147
148 /*****************************************************************************
149  * Global variable program_data - this is the one and only, see main.h
150  *****************************************************************************/
151 main_t *p_main;
152
153 /*****************************************************************************
154  * Local prototypes
155  *****************************************************************************/
156 static void SetDefaultConfiguration ( void );
157 static int  GetConfiguration        ( int i_argc, char *ppsz_argv[],
158                                       char *ppsz_env[] );
159 static void Usage                   ( int i_fashion );
160 static void Version                 ( void );
161
162 static void InitSignalHandler       ( void );
163 static void SimpleSignalHandler     ( int i_signal );
164 static void FatalSignalHandler      ( int i_signal );
165 #ifdef HAVE_MMX
166        int  TestMMX                 ( void );
167 #endif
168
169 /*****************************************************************************
170  * main: parse command line, start interface and spawn threads
171  *****************************************************************************
172  * Steps during program execution are:
173  *      -configuration parsing and messages interface initialization
174  *      -opening of audio output device and some global modules
175  *      -execution of interface, which exit on error or on user request
176  *      -closing of audio output device and some global modules
177  * On error, the spawned threads are canceled, and the open devices closed.
178  *****************************************************************************/
179 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
180 {
181     main_t  main_data;                      /* root of all data - see main.h */
182
183     p_main = &main_data;                       /* set up the global variable */
184
185     /*
186      * System specific initialization code
187      */
188 #ifdef SYS_BEOS
189     beos_Create();
190 #endif
191
192     /*
193      * Test if our code is likely to run on this CPU 
194      */
195 #ifdef HAVE_MMX
196     if( !TestMMX() )
197     {
198         fprintf( stderr, "Sorry, this program needs an MMX processor. "
199                          "Please run the non-MMX version.\n" );
200         return( 1 );
201     }
202 #endif
203
204     /*
205      * Initialize messages interface
206      */
207     p_main->p_msg = intf_MsgCreate();
208     if( !p_main->p_msg )                         /* start messages interface */
209     {
210         fprintf( stderr, "error: can't initialize messages interface (%s)\n",
211                 strerror(errno) );
212         return( errno );
213     }
214
215     /*
216      * Set signal handling policy up for all the threads that will be created
217      */
218     InitSignalHandler();                 /* prepare signals for interception */
219
220     /*
221      * Read configuration
222      */
223     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
224     {
225         intf_MsgDestroy();
226         return( errno );
227     }
228
229     /*
230      * Initialize playlist and get commandline files
231      */
232     p_main->p_playlist = playlist_Create( );
233     if( !p_main->p_playlist )
234     {
235         intf_Msg( "Playlist initialization failed\n" );
236         intf_MsgDestroy();
237         return( errno );
238     }
239     playlist_Init( p_main->p_playlist, optind );
240
241     /*
242      * Initialize plugin bank
243      */
244     p_main->p_bank = bank_Create( );
245     if( !p_main->p_bank )
246     {
247         intf_Msg( "Plugin bank initialization failed\n" );
248         playlist_Destroy( p_main->p_playlist );
249         intf_MsgDestroy();
250         return( errno );
251     }
252     bank_Init( p_main->p_bank );
253
254     /*
255      * Initialize shared resources and libraries
256      */
257     /* FIXME: no VLANs */
258 #if 0
259     if( p_main->b_vlans && input_VlanCreate() )
260     {
261         /* On error during vlans initialization, switch off vlans */
262         intf_Msg( "Virtual LANs initialization failed : "
263                   "vlans management is deactivated\n" );
264         p_main->b_vlans = 0;
265     }
266 #endif
267
268     /*
269      * Open audio device and start aout thread
270      */
271     if( p_main->b_audio )
272     {
273         p_main->p_aout = aout_CreateThread( NULL );
274         if( p_main->p_aout == NULL )
275         {
276             /* On error during audio initialization, switch off audio */
277             intf_Msg( "Audio initialization failed : audio is deactivated\n" );
278             p_main->b_audio = 0;
279         }
280     }
281
282     /*
283      * Run interface
284      */
285     p_main->p_intf = intf_Create();
286     if( p_main->p_intf != NULL )
287     {
288         /*
289          * This is the main loop
290          */
291         intf_Run( p_main->p_intf );
292
293         intf_Destroy( p_main->p_intf );
294     }
295
296     /*
297      * Close audio device
298      */
299     if( p_main->b_audio )
300     {
301         aout_DestroyThread( p_main->p_aout, NULL );
302     }
303
304     /*
305      * Free shared resources and libraries
306      */
307     /* FIXME */
308 #if 0
309     if( p_main->b_vlans )
310     {
311         input_VlanDestroy();
312     }
313 #endif
314
315     /*
316      * Free plugin bank
317      */
318     bank_Destroy( p_main->p_bank );
319
320     /*
321      * Free playlist
322      */
323     playlist_Destroy( p_main->p_playlist );
324
325 #ifdef SYS_BEOS
326     /*
327      * System specific cleaning code
328      */
329     beos_Destroy();
330 #endif
331
332     /*
333      * Terminate messages interface and program
334      */
335     intf_Msg( "Program terminated.\n" );
336     intf_MsgDestroy();
337
338     return( 0 );
339 }
340
341 /*****************************************************************************
342  * main_GetIntVariable: get the int value of an environment variable
343  *****************************************************************************
344  * This function is used to read some default parameters in modules.
345  *****************************************************************************/
346 int main_GetIntVariable( char *psz_name, int i_default )
347 {
348     char *      psz_env;                                /* environment value */
349     char *      psz_end;                             /* end of parsing index */
350     long int    i_value;                                            /* value */
351
352     psz_env = getenv( psz_name );
353     if( psz_env )
354     {
355         i_value = strtol( psz_env, &psz_end, 0 );
356         if( (*psz_env != '\0') && (*psz_end == '\0') )
357         {
358             return( i_value );
359         }
360     }
361     return( i_default );
362 }
363
364 /*****************************************************************************
365  * main_GetPszVariable: get the string value of an environment variable
366  *****************************************************************************
367  * This function is used to read some default parameters in modules.
368  *****************************************************************************/
369 char * main_GetPszVariable( char *psz_name, char *psz_default )
370 {
371     char *psz_env;
372
373     psz_env = getenv( psz_name );
374     if( psz_env )
375     {
376         return( psz_env );
377     }
378     return( psz_default );
379 }
380
381 /*****************************************************************************
382  * main_PutPszVariable: set the string value of an environment variable
383  *****************************************************************************
384  * This function is used to set some default parameters in modules. The use of
385  * this function will cause some memory leak: since some systems use the pointer
386  * passed to putenv to store the environment string, it can't be freed.
387  *****************************************************************************/
388 void main_PutPszVariable( char *psz_name, char *psz_value )
389 {
390     char *psz_env;
391
392     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
393     if( psz_env == NULL )
394     {
395         intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
396     }
397     else
398     {
399         sprintf( psz_env, "%s=%s", psz_name, psz_value );
400         if( putenv( psz_env ) )
401         {
402             intf_ErrMsg( "error: %s\n", strerror(errno) );
403         }
404     }
405 }
406
407 /*****************************************************************************
408  * main_PutIntVariable: set the integer value of an environment variable
409  *****************************************************************************
410  * This function is used to set some default parameters in modules. The use of
411  * this function will cause some memory leak: since some systems use the pointer
412  * passed to putenv to store the environment string, it can't be freed.
413  *****************************************************************************/
414 void main_PutIntVariable( char *psz_name, int i_value )
415 {
416     char psz_value[ 256 ];                               /* buffer for value */
417
418     sprintf( psz_value, "%d", i_value );
419     main_PutPszVariable( psz_name, psz_value );
420 }
421
422 /* following functions are local */
423
424 /*****************************************************************************
425  * SetDefaultConfiguration: set default options
426  *****************************************************************************
427  * This function is called by GetConfiguration before command line is parsed.
428  * It sets all the default values required later by the program. At this stage,
429  * most structure are not yet allocated, so initialization must be done using
430  * environment.
431  *****************************************************************************/
432 static void SetDefaultConfiguration( void )
433 {
434     /*
435      * All features are activated by default except vlans
436      */
437     p_main->b_audio  = 1;
438     p_main->b_video  = 1;
439     p_main->b_vlans  = 0;
440
441     /* This is |_|lt1m4t3 |<l|_|d63 */
442     main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, -1 );
443 }
444
445 /*****************************************************************************
446  * GetConfiguration: parse command line
447  *****************************************************************************
448  * Parse command line and configuration file for configuration. If the inline
449  * help is requested, the function Usage() is called and the function returns
450  * -1 (causing main() to exit). The messages interface is initialized at this
451  * stage, but most structures are not allocated, so only environment should
452  * be used.
453  *****************************************************************************/
454 static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
455 {
456     int c, i_opt;
457     char * p_pointer;
458
459     /* Set default configuration and copy arguments */
460     p_main->i_argc    = i_argc;
461     p_main->ppsz_argv = ppsz_argv;
462     p_main->ppsz_env  = ppsz_env;
463     SetDefaultConfiguration();
464
465     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );
466
467     /* Get the executable name (similar to the basename command) */
468     p_main->psz_arg0 = p_pointer = ppsz_argv[ 0 ];
469     while( *p_pointer )
470     {
471         if( *p_pointer == '/' )
472         {
473             p_main->psz_arg0 = ++p_pointer;
474         }
475         else
476         {
477             ++p_pointer;
478         }
479     }
480
481     /* Parse command line options */
482 #ifdef HAVE_GETOPT_H
483     opterr = 0;
484     while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
485     {
486         switch( c )
487         {
488         /* General/common options */
489         case 'h':                                              /* -h, --help */
490             Usage( SHORT_HELP );
491             return( -1 );
492             break;
493         case 'H':                                          /* -H, --longhelp */
494             Usage( LONG_HELP );
495             return( -1 );
496             break;
497         case 'v':                                           /* -v, --version */
498             Version();
499             return( -1 );
500             break;
501
502         /* Audio options */
503         case OPT_NOAUDIO:                                       /* --noaudio */
504             p_main->b_audio = 0;
505             break;
506         case OPT_AOUT:                                             /* --aout */
507             main_PutPszVariable( AOUT_METHOD_VAR, optarg );
508             break;
509         case OPT_STEREO:                                         /* --stereo */
510             main_PutIntVariable( AOUT_STEREO_VAR, 1 );
511             break;
512         case OPT_MONO:                                             /* --mono */
513             main_PutIntVariable( AOUT_STEREO_VAR, 0 );
514             break;
515
516         /* Video options */
517         case OPT_NOVIDEO:                                       /* --novideo */
518             p_main->b_video = 0;
519             break;
520         case OPT_VOUT:                                             /* --vout */
521             main_PutPszVariable( VOUT_METHOD_VAR, optarg );
522             break;
523         case OPT_DISPLAY:                                       /* --display */
524             main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
525             break;
526         case OPT_WIDTH:                                           /* --width */
527             main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
528             break;
529         case OPT_HEIGHT:                                         /* --height */
530             main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
531             break;
532
533         case 'g':                                         /* -g, --grayscale */
534             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
535             break;
536         case OPT_COLOR:                                           /* --color */
537             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
538             break;
539         case OPT_YUV:                                               /* --yuv */
540             main_PutPszVariable( YUV_METHOD_VAR, optarg );
541             break;
542
543         /* DVD options */
544         case 'a':
545             if ( ! strcmp(optarg, "ac3") )
546                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
547             else if ( ! strcmp(optarg, "lpcm") )
548                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
549             else if ( ! strcmp(optarg, "off") )
550                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
551             else
552                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
553             break;
554         case 'c':
555             main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
556             break;
557         case 's':
558             main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
559             break;
560
561         /* Input options */
562         case OPT_VLANS:                                           /* --vlans */
563             p_main->b_vlans = 1;
564             break;
565         case OPT_SERVER:                                         /* --server */
566             main_PutPszVariable( INPUT_SERVER_VAR, optarg );
567             break;
568         case OPT_PORT:                                             /* --port */
569             main_PutPszVariable( INPUT_PORT_VAR, optarg );
570             break;
571         case OPT_BROADCAST:                                   /* --broadcast */
572             main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
573             break;
574
575         /* Synchro options */
576         case OPT_SYNCHRO:                                      
577             main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
578             break;
579
580         /* Interface warning messages level */
581         case OPT_WARNING:                                       /* --warning */
582             main_PutIntVariable( INTF_WARNING_VAR, atoi(optarg) );
583             break;
584             
585         /* Internal error: unknown option */
586         case '?':
587         default:
588             intf_ErrMsg( "intf error: unknown option `%s'\n", ppsz_argv[optind - 1] );
589             Usage( USAGE );
590             return( EINVAL );
591             break;
592         }
593     }
594 #endif
595
596     /* Parse command line parameters - no check is made for these options */
597     for( i_opt = optind; i_opt < i_argc; i_opt++ )
598     {
599         putenv( ppsz_argv[ i_opt ] );
600     }
601     return( 0 );
602 }
603
604 /*****************************************************************************
605  * Usage: print program usage
606  *****************************************************************************
607  * Print a short inline help. Message interface is initialized at this stage.
608  *****************************************************************************/
609 static void Usage( int i_fashion )
610 {
611     /* Usage */
612     intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
613               p_main->psz_arg0 );
614
615     if( i_fashion == USAGE )
616     {
617         intf_Msg( "Try `%s --help' for more information.\n",
618                   p_main->psz_arg0 );
619         return;
620     }
621
622     /* Options */
623     intf_Msg( "\n"
624               "Options:\n"
625               "      --noaudio                  \tdisable audio\n"
626               "      --aout <plugin>            \taudio output method\n"
627               "      --stereo, --mono           \tstereo/mono audio\n"
628               "\n"
629               "      --novideo                  \tdisable video\n"
630               "      --vout <plugin>            \tvideo output method\n"
631               "      --display <display>        \tdisplay string\n"
632               "      --width <w>, --height <h>  \tdisplay dimensions\n"
633               "  -g, --grayscale                \tgrayscale output\n"
634               "      --color                    \tcolor output\n"
635               "\n"
636               "  -a, --dvdaudio <type>          \tchoose DVD audio type\n"
637               "  -c, --dvdchannel <channel>     \tchoose DVD audio channel\n"
638               "  -s, --dvdsubtitle <channel>    \tchoose DVD subtitle channel\n"
639               "\n"
640               "      --vlans                    \tenable vlans\n"
641               "      --server <host>            \tvideo server address\n"
642               "      --port <port>              \tvideo server port\n"
643               "      --broadcast                \tlisten to a broadcast\n"
644               "\n"
645               "      --synchro <type>           \tforce synchro algorithm\n"
646               "\n"
647               "      --warning <level>          \tdisplay warning messages\n"
648               "\n"
649               "  -h, --help                     \tprint help and exit\n"
650               "  -H, --longhelp                 \tprint long help and exit\n"
651               "  -v, --version                  \toutput version information and exit\n" );
652
653     if( i_fashion == SHORT_HELP )
654         return;
655
656     /* Interface parameters */
657     intf_Msg( "\n"
658               "Interface parameters:\n"
659               "  " INTF_INIT_SCRIPT_VAR "=<filename>               \tinitialization script\n"
660               "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n"
661               "  " INTF_WARNING_VAR "=<level>                \twarning level\n" );
662
663     /* Audio parameters */
664     intf_Msg( "\n"
665               "Audio parameters:\n"
666               "  " AOUT_METHOD_VAR "=<method name>        \taudio method\n"
667               "  " AOUT_DSP_VAR "=<filename>              \tdsp device path\n"
668               "  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output\n"
669               "  " AOUT_RATE_VAR "=<rate>             \toutput rate\n" );
670
671     /* Video parameters */
672     intf_Msg( "\n"
673               "Video parameters:\n"
674               "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method\n"
675               "  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used\n"
676               "  " VOUT_WIDTH_VAR "=<width>               \tdisplay width\n"
677               "  " VOUT_HEIGHT_VAR "=<height>             \tdislay height\n"
678               "  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path\n"
679               "  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output\n" );
680
681     /* DVD parameters */
682     intf_Msg( "\n"
683               "DVD parameters:\n"
684               "  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type\n"
685               "  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel\n"
686               "  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel\n" );
687
688     /* Input parameters */
689     intf_Msg( "\n"
690               "Input parameters:\n"
691               "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n"
692               "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n"
693               "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"
694               "  " INPUT_BROADCAST_VAR "={1|0}            \tbroadcast mode\n"
695               "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n"
696               "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n" );
697
698     /* Synchro parameters */
699     intf_Msg( "\n"
700               "Synchro parameters:\n"
701               "  " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB}   \tsynchro algorithm\n");
702 }
703
704 /*****************************************************************************
705  * Version: print complete program version
706  *****************************************************************************
707  * Print complete program version and build number.
708  *****************************************************************************/
709 static void Version( void )
710 {
711     intf_Msg( VERSION_MESSAGE
712               "This program comes with NO WARRANTY, to the extent permitted by law.\n"
713               "You may redistribute it under the terms of the GNU General Public License;\n"
714               "see the file named COPYING for details.\n"
715               "Written by the VideoLAN team at Ecole Centrale, Paris.\n" );
716
717 }
718
719 /*****************************************************************************
720  * InitSignalHandler: system signal handler initialization
721  *****************************************************************************
722  * Set the signal handlers. SIGTERM is not intercepted, because we need at
723  * at least a method to kill the program when all other methods failed, and
724  * when we don't want to use SIGKILL.
725  *****************************************************************************/
726 static void InitSignalHandler( void )
727 {
728     /* Termination signals */
729     signal( SIGHUP,  FatalSignalHandler );
730     signal( SIGINT,  FatalSignalHandler );
731     signal( SIGQUIT, FatalSignalHandler );
732
733     /* Other signals */
734     signal( SIGALRM, SimpleSignalHandler );
735     signal( SIGPIPE, SimpleSignalHandler );
736 }
737
738
739 /*****************************************************************************
740  * SimpleSignalHandler: system signal handler
741  *****************************************************************************
742  * This function is called when a non fatal signal is received by the program.
743  *****************************************************************************/
744 static void SimpleSignalHandler( int i_signal )
745 {
746     /* Acknowledge the signal received */
747     intf_WarnMsg(0, "intf: ignoring signal %d\n", i_signal );
748 }
749
750
751 /*****************************************************************************
752  * FatalSignalHandler: system signal handler
753  *****************************************************************************
754  * This function is called when a fatal signal is received by the program.
755  * It tries to end the program in a clean way.
756  *****************************************************************************/
757 static void FatalSignalHandler( int i_signal )
758 {
759     /* Once a signal has been trapped, the termination sequence will be armed and
760      * following signals will be ignored to avoid sending messages to an interface
761      * having been destroyed */
762     signal( SIGHUP,  SIG_IGN );
763     signal( SIGINT,  SIG_IGN );
764     signal( SIGQUIT, SIG_IGN );
765
766     /* Acknowledge the signal received */
767     intf_ErrMsgImm("intf: signal %d received, exiting\n", i_signal );
768
769     /* Try to terminate everything - this is done by requesting the end of the
770      * interface thread */
771     p_main->p_intf->b_die = 1;
772 }
773