]> git.sesse.net Git - vlc/blob - src/interface/main.c
e5edc8ed1fb4c0d81607972ab4f982733f3ada26
[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-2001 VideoLAN
7  * $Id: main.c,v 1.127 2001/11/28 15:08:06 massiot Exp $
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *          Samuel Hocevar <sam@zoy.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
33 #include <stdio.h>                                              /* sprintf() */
34 #include <setjmp.h>                                       /* longjmp, setjmp */
35
36 #ifdef HAVE_GETOPT_LONG
37 #   ifdef HAVE_GETOPT_H
38 #       include <getopt.h>                                       /* getopt() */
39 #   endif
40 #else
41 #   include "GNUgetopt/getopt.h"
42 #endif
43
44 #ifdef SYS_DARWIN
45 #   include <mach/mach.h>                               /* Altivec detection */
46 #   include <mach/mach_error.h>       /* some day the header files||compiler *
47                                                        will define it for us */
48 #   include <mach/bootstrap.h>
49 #endif
50
51 #ifndef WIN32
52 #   include <netinet/in.h>                            /* BSD: struct in_addr */
53 #endif
54
55 #ifdef HAVE_UNISTD_H
56 #   include <unistd.h>
57 #elif defined( _MSC_VER ) && defined( _WIN32 )
58 #   include <io.h>
59 #endif
60
61 #include <errno.h>                                                 /* ENOMEM */
62 #include <stdlib.h>                                  /* getenv(), strtol(),  */
63 #include <string.h>                                            /* strerror() */
64 #include <fcntl.h>                                       /* open(), O_WRONLY */
65 #include <sys/stat.h>                                             /* S_IREAD */
66
67 #include "config.h"
68 #include "common.h"
69 #include "debug.h"
70 #include "intf_msg.h"
71 #include "threads.h"
72 #include "mtime.h"
73 #include "tests.h"                                              /* TestCPU() */
74 #include "modules.h"
75
76 #include "stream_control.h"
77 #include "input_ext-intf.h"
78
79 #include "intf_playlist.h"
80 #include "interface.h"
81
82 #include "audio_output.h"
83
84 #include "video.h"
85 #include "video_output.h"
86
87 #ifdef SYS_BEOS
88 #   include "beos_specific.h"
89 #endif
90
91 #ifdef SYS_DARWIN
92 #   include "darwin_specific.h"
93 #endif
94
95 #ifdef WIN32
96 #   include "win32_specific.h"
97 #endif
98
99 #include "netutils.h"                                 /* network_ChannelJoin */
100
101 #include "main.h"
102
103 /*****************************************************************************
104  * Command line options constants. If something is changed here, be sure that
105  * GetConfiguration and Usage are also changed.
106  *****************************************************************************/
107
108 /* Long options return values - note that values corresponding to short options
109  * chars, and in general any regular char, should be avoided */
110 #define OPT_NOAUDIO             150
111 #define OPT_STEREO              151
112 #define OPT_MONO                152
113 #define OPT_SPDIF               153
114 #define OPT_VOLUME              154
115
116 #define OPT_NOVIDEO             160
117 #define OPT_DISPLAY             161
118 #define OPT_WIDTH               162
119 #define OPT_HEIGHT              163
120 #define OPT_COLOR               164
121 #define OPT_FULLSCREEN          165
122 #define OPT_OVERLAY             166
123 #define OPT_XVADAPTOR           167
124 #define OPT_SMP                 168
125
126 #define OPT_CHANNELS            170
127 #define OPT_SERVER              171
128 #define OPT_PORT                172
129 #define OPT_BROADCAST           173
130 #define OPT_CHANNELSERVER       174
131
132 #define OPT_INPUT               180
133 #define OPT_MOTION              181
134 #define OPT_IDCT                182
135 #define OPT_YUV                 183
136 #define OPT_DOWNMIX             184
137 #define OPT_IMDCT               185
138 #define OPT_DVDCSS_METHOD       186
139 #define OPT_DVDCSS_VERBOSE      187
140
141 #define OPT_SYNCHRO             190
142 #define OPT_WARNING             191
143 #define OPT_VERSION             192
144 #define OPT_STDOUT              193
145 #define OPT_STATS               194
146
147 /* Usage fashion */
148 #define USAGE                     0
149 #define SHORT_HELP                1
150 #define LONG_HELP                 2
151
152 /* Needed for x86 CPU capabilities detection */
153 #define cpuid( a )                 \
154     asm volatile ( "cpuid"         \
155                  : "=a" ( i_eax ), \
156                    "=b" ( i_ebx ), \
157                    "=c" ( i_ecx ), \
158                    "=d" ( i_edx )  \
159                  : "a"  ( a )      \
160                  : "cc" );
161
162 /* Long options */
163 static const struct option longopts[] =
164 {
165     /*  name,               has_arg,    flag,   val */
166
167     /* General/common options */
168     {   "help",             0,          0,      'h' },
169     {   "longhelp",         0,          0,      'H' },
170     {   "version",          0,          0,      OPT_VERSION },
171
172     /* Interface options */
173     {   "intf",             1,          0,      'I' },
174     {   "warning",          1,          0,      OPT_WARNING },
175     {   "stdout",           1,          0,      OPT_STDOUT },
176     {   "stats",            0,          0,      OPT_STATS },
177
178     /* Audio options */
179     {   "noaudio",          0,          0,      OPT_NOAUDIO },
180     {   "aout",             1,          0,      'A' },
181     {   "stereo",           0,          0,      OPT_STEREO },
182     {   "mono",             0,          0,      OPT_MONO },
183     {   "spdif",            0,          0,      OPT_SPDIF },
184     {   "downmix",          1,          0,      OPT_DOWNMIX },
185     {   "imdct",            1,          0,      OPT_IMDCT },
186     {   "volume",           1,          0,      OPT_VOLUME },
187
188     /* Video options */
189     {   "novideo",          0,          0,      OPT_NOVIDEO },
190     {   "vout",             1,          0,      'V' },
191     {   "display",          1,          0,      OPT_DISPLAY },
192     {   "width",            1,          0,      OPT_WIDTH },
193     {   "height",           1,          0,      OPT_HEIGHT },
194     {   "grayscale",        0,          0,      'g' },
195     {   "color",            0,          0,      OPT_COLOR },
196     {   "motion",           1,          0,      OPT_MOTION },
197     {   "idct",             1,          0,      OPT_IDCT },
198     {   "yuv",              1,          0,      OPT_YUV },
199     {   "fullscreen",       0,          0,      OPT_FULLSCREEN },
200     {   "overlay",          0,          0,      OPT_OVERLAY },
201     {   "xvadaptor",        1,          0,      OPT_XVADAPTOR },
202     {   "smp",              1,          0,      OPT_SMP },
203
204     /* DVD options */
205     {   "dvdtitle",         1,          0,      't' },
206     {   "dvdchapter",       1,          0,      'T' },
207     {   "dvdangle",         1,          0,      'u' },
208     {   "dvdaudio",         1,          0,      'a' },
209     {   "dvdchannel",       1,          0,      'c' },
210     {   "dvdsubtitle",      1,          0,      's' },
211     {   "dvdcss-method",    1,          0,      OPT_DVDCSS_METHOD },
212     {   "dvdcss-verbose",   1,          0,      OPT_DVDCSS_VERBOSE },
213     
214     /* Input options */
215     {   "input",            1,          0,      OPT_INPUT },
216     {   "channels",         0,          0,      OPT_CHANNELS },
217     {   "channelserver",    1,          0,      OPT_CHANNELSERVER },
218
219     /* Synchro options */
220     {   "synchro",          1,          0,      OPT_SYNCHRO },
221     {   0,                  0,          0,      0 }
222 };
223
224 /* Short options */
225 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
226
227 /*****************************************************************************
228  * Global variable program_data - these are the only ones, see main.h and
229  * modules.h
230  *****************************************************************************/
231 main_t        *p_main;
232 module_bank_t *p_module_bank;
233 aout_bank_t   *p_aout_bank;
234 vout_bank_t   *p_vout_bank;
235
236 /*****************************************************************************
237  * Local prototypes
238  *****************************************************************************/
239 static int  GetConfiguration        ( int *pi_argc, char *ppsz_argv[],
240                                       char *ppsz_env[] );
241 static int  GetFilenames            ( int i_argc, char *ppsz_argv[] );
242 static void Usage                   ( int i_fashion );
243 static void Version                 ( void );
244
245 static void InitSignalHandler       ( void );
246 static void SimpleSignalHandler     ( int i_signal );
247 static void FatalSignalHandler      ( int i_signal );
248 static void InstructionSignalHandler( int i_signal );
249 static int  CPUCapabilities         ( void );
250
251 static int  RedirectSTDOUT          ( void );
252 static void ShowConsole             ( void );
253
254 static jmp_buf env;
255 static int  i_illegal;
256
257 /*****************************************************************************
258  * main: parse command line, start interface and spawn threads
259  *****************************************************************************
260  * Steps during program execution are:
261  *      -configuration parsing and messages interface initialization
262  *      -opening of audio output device and some global modules
263  *      -execution of interface, which exit on error or on user request
264  *      -closing of audio output device and some global modules
265  * On error, the spawned threads are canceled, and the open devices closed.
266  *****************************************************************************/
267 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
268 {
269     main_t        main_data;                /* root of all data - see main.h */
270     module_bank_t module_bank;
271     aout_bank_t   aout_bank;
272     vout_bank_t   vout_bank;
273
274     p_main        = &main_data;               /* set up the global variables */
275     p_module_bank = &module_bank;
276     p_aout_bank   = &aout_bank;
277     p_vout_bank   = &vout_bank;
278
279     /*
280      * Initialize threads system
281      */
282     vlc_threads_init( );
283
284     /*
285      * Test if our code is likely to run on this CPU 
286      */
287     p_main->i_cpu_capabilities = CPUCapabilities();
288     
289     /*
290      * System specific initialization code
291      */
292 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
293     system_Init( &i_argc, ppsz_argv, ppsz_env );
294
295 #elif defined( SYS_LINUX )
296 #   ifdef DEBUG
297     /* Activate malloc checking routines to detect heap corruptions. */
298     main_PutIntVariable( "MALLOC_CHECK_", 2 );
299 #   endif
300 #endif
301
302     /*
303      * Initialize messages interface
304      */
305     p_main->p_msg = intf_MsgCreate();
306     if( !p_main->p_msg )                         /* start messages interface */
307     {
308         fprintf( stderr, "error: can't initialize messages interface (%s)\n",
309                  strerror(errno) );
310         return( errno );
311     }
312
313     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );
314
315     /*
316      * Read configuration
317      */
318     if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
319     {
320         intf_MsgDestroy();
321         return( errno );
322     }
323
324     /*
325      * Redirect the standard output if required by the user, and on Win32 we
326      * also open a console to display the debug messages.
327      */
328     RedirectSTDOUT();
329
330     if( p_main->b_stats )
331     {
332         char          p_capabilities[200];
333         p_capabilities[0] = '\0';
334
335 #define PRINT_CAPABILITY( capability, string )                              \
336         if( p_main->i_cpu_capabilities & capability )                       \
337         {                                                                   \
338             strncat( p_capabilities, string " ",                            \
339                      sizeof(p_capabilities) - strlen(p_capabilities) );     \
340             p_capabilities[sizeof(p_capabilities) - 1] = '\0';              \
341         }
342
343         PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
344         PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
345         PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
346         PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
347         PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
348         PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
349         PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
350         PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "Altivec" );
351         intf_StatMsg("info: CPU has capabilities %s", p_capabilities );
352     }
353
354     /*
355      * Initialize playlist and get commandline files
356      */
357     p_main->p_playlist = intf_PlaylistCreate();
358     if( !p_main->p_playlist )
359     {
360         intf_ErrMsg( "playlist error: playlist initialization failed" );
361         intf_MsgDestroy();
362         return( errno );
363     }
364     intf_PlaylistInit( p_main->p_playlist );
365
366     /*
367      * Get input filenames given as commandline arguments
368      */
369     GetFilenames( i_argc, ppsz_argv );
370
371     /*
372      * Initialize module, aout and vout banks
373      */
374     module_InitBank();
375     aout_InitBank();
376     vout_InitBank();
377
378     /*
379      * Initialize shared resources and libraries
380      */
381     if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
382                              INPUT_NETWORK_CHANNEL_DEFAULT ) &&
383         network_ChannelCreate() )
384     {
385         /* On error during Channels initialization, switch off channels */
386         intf_Msg( "Channels initialization failed : "
387                   "Channel management is deactivated" );
388         main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 0 );
389     }
390
391     /*
392      * Try to run the interface
393      */
394     p_main->p_intf = intf_Create();
395     if( p_main->p_intf == NULL )
396     {
397         intf_ErrMsg( "intf error: interface initialization failed" );
398     }
399     else
400     {
401         /*
402          * Set signal handling policy for all threads
403          */
404         InitSignalHandler();
405
406         /*
407          * This is the main loop
408          */
409         p_main->p_intf->pf_run( p_main->p_intf );
410
411         /*
412          * Finished, destroy the interface
413          */
414         intf_Destroy( p_main->p_intf );
415
416         /*
417          * Go back into channel 0 which is the network
418          */
419         if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
420                                  INPUT_NETWORK_CHANNEL_DEFAULT ) )
421         {
422             network_ChannelJoin( COMMON_CHANNEL );
423         }
424     }
425
426     /*
427      * Free module, aout and vout banks
428      */
429     vout_EndBank();
430     aout_EndBank();
431     module_EndBank();
432
433     /*
434      * Free playlist
435      */
436     intf_PlaylistDestroy( p_main->p_playlist );
437
438     /*
439      * System specific cleaning code
440      */
441 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
442     system_End();
443 #endif
444
445
446     /*
447      * Terminate messages interface and program
448      */
449     intf_Msg( "intf: program terminated" );
450     intf_MsgDestroy();
451
452     /*
453      * Stop threads system
454      */
455     vlc_threads_end( );
456
457     return 0;
458 }
459
460 /*****************************************************************************
461  * main_GetIntVariable: get the int value of an environment variable
462  *****************************************************************************
463  * This function is used to read some default parameters in modules.
464  *****************************************************************************/
465 int main_GetIntVariable( char *psz_name, int i_default )
466 {
467     char *      psz_env;                                /* environment value */
468     char *      psz_end;                             /* end of parsing index */
469     long int    i_value;                                            /* value */
470
471     psz_env = getenv( psz_name );
472     if( psz_env )
473     {
474         i_value = strtol( psz_env, &psz_end, 0 );
475         if( (*psz_env != '\0') && (*psz_end == '\0') )
476         {
477             return( i_value );
478         }
479     }
480     return( i_default );
481 }
482
483 /*****************************************************************************
484  * main_GetPszVariable: get the string value of an environment variable
485  *****************************************************************************
486  * This function is used to read some default parameters in modules.
487  *****************************************************************************/
488 char * main_GetPszVariable( char *psz_name, char *psz_default )
489 {
490     char *psz_env;
491
492     psz_env = getenv( psz_name );
493     if( psz_env )
494     {
495         return( psz_env );
496     }
497     return( psz_default );
498 }
499
500 /*****************************************************************************
501  * main_PutPszVariable: set the string value of an environment variable
502  *****************************************************************************
503  * This function is used to set some default parameters in modules. The use of
504  * this function will cause some memory leak: since some systems use the pointer
505  * passed to putenv to store the environment string, it can't be freed.
506  *****************************************************************************/
507 void main_PutPszVariable( char *psz_name, char *psz_value )
508 {
509     char *psz_env;
510
511     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
512     if( psz_env == NULL )
513     {
514         intf_ErrMsg( "intf error: cannot create psz_env (%s)",
515                      strerror(ENOMEM) );
516     }
517     else
518     {
519         sprintf( psz_env, "%s=%s", psz_name, psz_value );
520         if( putenv( psz_env ) )
521         {
522             intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
523         }
524     }
525 }
526
527 /*****************************************************************************
528  * main_PutIntVariable: set the integer value of an environment variable
529  *****************************************************************************
530  * This function is used to set some default parameters in modules. The use of
531  * this function will cause some memory leak: since some systems use the pointer
532  * passed to putenv to store the environment string, it can't be freed.
533  *****************************************************************************/
534 void main_PutIntVariable( char *psz_name, int i_value )
535 {
536     char psz_value[ 256 ];                               /* buffer for value */
537
538     sprintf( psz_value, "%d", i_value );
539     main_PutPszVariable( psz_name, psz_value );
540 }
541
542 /* following functions are local */
543
544 /*****************************************************************************
545  * GetConfiguration: parse command line
546  *****************************************************************************
547  * Parse command line and configuration file for configuration. If the inline
548  * help is requested, the function Usage() is called and the function returns
549  * -1 (causing main() to exit). The messages interface is initialized at this
550  * stage, but most structures are not allocated, so only environment should
551  * be used.
552  *****************************************************************************/
553 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
554 {
555     int   i_cmd;
556     char *p_tmp;
557
558     /* Set default configuration and copy arguments */
559     p_main->i_argc    = *pi_argc;
560     p_main->ppsz_argv = ppsz_argv;
561     p_main->ppsz_env  = ppsz_env;
562
563     p_main->b_audio     = 1;
564     p_main->b_video     = 1;
565
566     p_main->i_warning_level = 0;
567     p_main->b_stats = 0;
568
569     p_main->p_channel = NULL;
570
571     /* Get the executable name (similar to the basename command) */
572     p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
573     while( *p_tmp )
574     {
575         if( *p_tmp == '/' )
576         {
577             p_main->psz_arg0 = ++p_tmp;
578         }
579         else
580         {
581             ++p_tmp;
582         }
583     }
584
585 #ifdef SYS_DARWIN
586     /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
587      * is the PSN - process serial number (a unique PID-ish thingie)
588      * still ok for real Darwin & when run from command line */
589     if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
590                                         /* for example -psn_0_9306113 */
591     {
592         /* GDMF!... I can't do this or else the MacOSX window server will
593          * not pick up the PSN and not register the app and we crash...
594          * hence the following kludge otherwise we'll get confused w/ argv[1]
595          * being an input file name */
596 #if 0
597         ppsz_argv[ 1 ] = NULL;
598 #endif
599         *pi_argc = *pi_argc - 1;
600         pi_argc--;
601         return( 0 );
602     }
603 #endif
604
605     /* Parse command line options */
606     opterr = 0;
607     while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
608                                    psz_shortopts, longopts, 0 ) ) != EOF )
609     {
610         switch( i_cmd )
611         {
612         /* General/common options */
613         case 'h':                                              /* -h, --help */
614             ShowConsole();
615             RedirectSTDOUT();
616             Usage( SHORT_HELP );
617 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
618             if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
619                                                  INTF_STDOUT_DEFAULT ) ) == 0 )
620             {
621                 /* No stdout redirection has been asked for */
622                 intf_MsgImm( "\nPress the RETURN key to continue..." );
623                 getchar();
624             }
625 #endif
626             return( -1 );
627             break;
628         case 'H':                                          /* -H, --longhelp */
629             ShowConsole();
630             RedirectSTDOUT();
631             Usage( LONG_HELP );
632 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
633             if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
634                                                  INTF_STDOUT_DEFAULT ) ) == 0 )
635             {
636                 /* No stdout redirection has been asked for */
637                 intf_MsgImm( "\nPress the RETURN key to continue..." );
638                 getchar();
639             }
640 #endif
641             return( -1 );
642             break;
643         case OPT_VERSION:                                       /* --version */
644             ShowConsole();
645             RedirectSTDOUT();
646             Version();
647 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
648             if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
649                                                  INTF_STDOUT_DEFAULT ) ) == 0 )
650             {
651                 /* No stdout redirection has been asked for */
652                 intf_MsgImm( "\nPress the RETURN key to continue..." );
653                 getchar();
654             }
655 #endif
656             return( -1 );
657             break;
658         case 'v':                                           /* -v, --verbose */
659             p_main->i_warning_level++;
660             break;
661
662         /* Interface warning messages level */
663         case 'I':                                              /* -I, --intf */
664             main_PutPszVariable( INTF_METHOD_VAR, optarg );
665             break;
666         case OPT_WARNING:                                       /* --warning */
667             intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
668             p_main->i_warning_level = atoi(optarg);
669             break;
670
671         case OPT_STDOUT:                                         /* --stdout */
672             main_PutPszVariable( INTF_STDOUT_VAR, optarg );
673             break;
674
675         case OPT_STATS:
676             p_main->b_stats = 1;
677             break;
678
679         /* Audio options */
680         case OPT_NOAUDIO:                                       /* --noaudio */
681             p_main->b_audio = 0;
682             break;
683         case 'A':                                              /* -A, --aout */
684             main_PutPszVariable( AOUT_METHOD_VAR, optarg );
685             break;
686         case OPT_STEREO:                                         /* --stereo */
687             main_PutIntVariable( AOUT_STEREO_VAR, 1 );
688             break;
689         case OPT_MONO:                                             /* --mono */
690             main_PutIntVariable( AOUT_STEREO_VAR, 0 );
691             break;
692         case OPT_SPDIF:                                           /* --spdif */
693             main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
694             break;
695         case OPT_DOWNMIX:                                       /* --downmix */
696             main_PutPszVariable( DOWNMIX_METHOD_VAR, optarg );
697             break;
698         case OPT_IMDCT:                                           /* --imdct */
699             main_PutPszVariable( IMDCT_METHOD_VAR, optarg );
700             break;
701         case OPT_VOLUME:                                         /* --volume */
702             main_PutIntVariable( AOUT_VOLUME_VAR, atoi(optarg) );
703             break;
704
705         /* Video options */
706         case OPT_NOVIDEO:                                       /* --novideo */
707             p_main->b_video = 0;
708             break;
709         case 'V':                                              /* -V, --vout */
710             main_PutPszVariable( VOUT_METHOD_VAR, optarg );
711             break;
712         case OPT_DISPLAY:                                       /* --display */
713             main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
714             break;
715         case OPT_WIDTH:                                           /* --width */
716             main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
717             break;
718         case OPT_HEIGHT:                                         /* --height */
719             main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
720             break;
721         case 'g':                                         /* -g, --grayscale */
722             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
723             break;
724         case OPT_COLOR:                                           /* --color */
725             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
726             break;
727         case OPT_FULLSCREEN:                                 /* --fullscreen */
728             main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
729             break;
730         case OPT_OVERLAY:                                       /* --overlay */
731             main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
732             break;
733         case OPT_XVADAPTOR:                                   /* --xvadaptor */
734             main_PutIntVariable( VOUT_XVADAPTOR_VAR, atoi(optarg) );
735             break;
736         case OPT_MOTION:                                         /* --motion */
737             main_PutPszVariable( MOTION_METHOD_VAR, optarg );
738             break;
739         case OPT_IDCT:                                             /* --idct */
740             main_PutPszVariable( IDCT_METHOD_VAR, optarg );
741             break;
742         case OPT_YUV:                                               /* --yuv */
743             main_PutPszVariable( YUV_METHOD_VAR, optarg );
744             break;
745         case OPT_SMP:                                               /* --smp */
746             main_PutIntVariable( VDEC_SMP_VAR, atoi(optarg) );
747             break;
748
749         /* DVD options */
750         case 't':                                              /* --dvdtitle */
751             main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
752             break;
753         case 'T':                                            /* --dvdchapter */
754             main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
755             break;
756         case 'u':                                              /* --dvdangle */
757             main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
758             break;
759         case 'a':                                              /* --dvdaudio */
760             if ( ! strcmp(optarg, "ac3") )
761                 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
762             else if ( ! strcmp(optarg, "lpcm") )
763                 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
764             else if ( ! strcmp(optarg, "mpeg") )
765                 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
766             else
767                 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
768             break;
769         case 'c':                                            /* --dvdchannel */
770             main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
771             break;
772         case 's':                                           /* --dvdsubtitle */
773             main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
774             break;
775         case OPT_DVDCSS_METHOD:                           /* --dvdcss-method */
776             main_PutPszVariable( "DVDCSS_METHOD", optarg );
777             break;
778         case OPT_DVDCSS_VERBOSE:                         /* --dvdcss-verbose */
779             main_PutPszVariable( "DVDCSS_VERBOSE", optarg );
780             break;
781
782         /* Input options */
783         case OPT_INPUT:                                           /* --input */
784             main_PutPszVariable( INPUT_METHOD_VAR, optarg );
785             break;
786         case OPT_CHANNELS:                                     /* --channels */
787             main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 1 );
788             break;
789         case OPT_CHANNELSERVER:                           /* --channelserver */
790             main_PutPszVariable( INPUT_CHANNEL_SERVER_VAR, optarg );
791             break;
792
793         /* Synchro options */
794         case OPT_SYNCHRO:                                      
795             main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
796             break;
797             
798         /* Internal error: unknown option */
799         case '?':
800         default:
801             ShowConsole();
802             RedirectSTDOUT();
803             intf_ErrMsg( "intf error: unknown option `%s'",
804                          ppsz_argv[optind] );
805             Usage( USAGE );
806 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
807             if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
808                                                  INTF_STDOUT_DEFAULT ) ) == 0 )
809             {
810                 /* No stdout redirection has been asked for */
811                 intf_MsgImm( "\nPress the RETURN key to continue..." );
812                 getchar();
813             }
814 #endif
815             return( EINVAL );
816             break;
817         }
818     }
819
820     if( p_main->i_warning_level < 0 )
821     {
822         p_main->i_warning_level = 0;
823     }
824
825     return( 0 );
826 }
827
828 /*****************************************************************************
829  * GetFilenames: parse command line options which are not flags
830  *****************************************************************************
831  * Parse command line for input files.
832  *****************************************************************************/
833 static int GetFilenames( int i_argc, char *ppsz_argv[] )
834 {
835     int i_opt;
836
837     /* We assume that the remaining parameters are filenames */
838     for( i_opt = optind; i_opt < i_argc; i_opt++ )
839     {
840         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
841                           ppsz_argv[ i_opt ] );
842     }
843
844     return( 0 );
845 }
846
847 /*****************************************************************************
848  * Usage: print program usage
849  *****************************************************************************
850  * Print a short inline help. Message interface is initialized at this stage.
851  *****************************************************************************/
852 static void Usage( int i_fashion )
853 {
854     /* Usage */
855     intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
856                  p_main->psz_arg0 );
857
858     if( i_fashion == USAGE )
859     {
860         intf_MsgImm( "Try `%s --help' for more information.",
861                      p_main->psz_arg0 );
862         return;
863     }
864
865     /* Options */
866     intf_MsgImm( "\nOptions:"
867           "\n  -I, --intf <module>            \tinterface method"
868           "\n  -v, --verbose                  \tverbose mode (cumulative)"
869           "\n      --stdout <filename>        \tredirect console stdout"
870           "\n"
871           "\n      --noaudio                  \tdisable audio"
872           "\n  -A, --aout <module>            \taudio output method"
873           "\n      --stereo, --mono           \tstereo/mono audio"
874           "\n      --spdif                    \tAC3 pass-through mode"
875           "\n      --downmix <module>         \tAC3 downmix method"
876           "\n      --imdct <module>           \tAC3 IMDCT method"
877           "\n      --volume [0..1024]         \tVLC output volume"
878           "\n"
879           "\n      --novideo                  \tdisable video"
880           "\n  -V, --vout <module>            \tvideo output method"
881           "\n      --display <display>        \tdisplay string"
882           "\n      --width <w>, --height <h>  \tdisplay dimensions"
883           "\n  -g, --grayscale                \tgrayscale output"
884           "\n      --fullscreen               \tfullscreen output"
885           "\n      --overlay                  \taccelerated display"
886           "\n      --xvadaptor <adaptor>      \tXVideo adaptor"
887           "\n      --color                    \tcolor output"
888           "\n      --motion <module>          \tmotion compensation method"
889           "\n      --idct <module>            \tIDCT method"
890           "\n      --yuv <module>             \tYUV method"
891           "\n      --synchro <type>           \tforce synchro algorithm"
892           "\n      --smp <number of threads>  \tuse several processors"
893           "\n"
894           "\n  -t, --dvdtitle <num>           \tchoose DVD title"
895           "\n  -T, --dvdchapter <num>         \tchoose DVD chapter"
896           "\n  -u, --dvdangle <num>           \tchoose DVD angle"
897           "\n  -a, --dvdaudio <type>          \tchoose DVD audio type"
898           "\n  -c, --dvdchannel <channel>     \tchoose DVD audio channel"
899           "\n  -s, --dvdsubtitle <channel>    \tchoose DVD subtitle channel"
900           "\n      --dvdcss-method <method>   \tselect dvdcss decryption method"
901           "\n      --dvdcss-verbose <level>   \tselect dvdcss verbose level"
902           "\n"
903           "\n      --input                    \tinput method"
904           "\n      --channels                 \tenable channels"
905           "\n      --channelserver <host>     \tchannel server address"
906           "\n"
907           "\n  -h, --help                     \tprint help and exit"
908           "\n  -H, --longhelp                 \tprint long help and exit"
909           "\n      --version                  \toutput version information and exit" );
910
911     if( i_fashion == SHORT_HELP )
912         return;
913
914     /* Interface parameters */
915     intf_MsgImm( "\nInterface parameters:"
916         "\n  " INTF_METHOD_VAR "=<method name>        \tinterface method"
917         "\n  " INTF_INIT_SCRIPT_VAR "=<filename>              \tinitialization script"
918         "\n  " INTF_CHANNELS_VAR "=<filename>         \tchannels list"
919         "\n  " INTF_STDOUT_VAR "=<filename>           \tredirect console stdout" );
920
921     /* Audio parameters */
922     intf_MsgImm( "\nAudio parameters:"
923         "\n  " AOUT_METHOD_VAR "=<method name>        \taudio method"
924         "\n  " AOUT_DSP_VAR "=<filename>              \tdsp device path"
925         "\n  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output"
926         "\n  " AOUT_SPDIF_VAR "={1|0}                 \tAC3 pass-through mode"
927         "\n  " DOWNMIX_METHOD_VAR "=<method name>     \tAC3 downmix method"
928         "\n  " IMDCT_METHOD_VAR "=<method name>       \tAC3 IMDCT method"
929         "\n  " AOUT_VOLUME_VAR "=[0..1024]            \tVLC output volume"
930         "\n  " AOUT_RATE_VAR "=<rate>             \toutput rate" );
931
932     /* Video parameters */
933     intf_MsgImm( "\nVideo parameters:"
934         "\n  " VOUT_METHOD_VAR "=<method name>        \tdisplay method"
935         "\n  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used"
936         "\n  " VOUT_WIDTH_VAR "=<width>               \tdisplay width"
937         "\n  " VOUT_HEIGHT_VAR "=<height>             \tdislay height"
938         "\n  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path"
939         "\n  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output"
940         "\n  " VOUT_FULLSCREEN_VAR "={1|0}            \tfullscreen"
941         "\n  " VOUT_OVERLAY_VAR "={1|0}               \toverlay"
942         "\n  " VOUT_XVADAPTOR_VAR "=<adaptor>         \tXVideo adaptor"
943         "\n  " MOTION_METHOD_VAR "=<method name>      \tmotion compensation method"
944         "\n  " IDCT_METHOD_VAR "=<method name>        \tIDCT method"
945         "\n  " YUV_METHOD_VAR "=<method name>         \tYUV method"
946         "\n  " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB}   \tsynchro algorithm"
947         "\n  " VDEC_SMP_VAR "=<number of threads>     \tuse several processors" );
948
949     /* DVD parameters */
950     intf_MsgImm( "\nDVD parameters:"
951         "\n  " INPUT_DVD_DEVICE_VAR "=<device>        \tDVD device"
952         "\n  " INPUT_TITLE_VAR "=<title>              \ttitle number"
953         "\n  " INPUT_CHAPTER_VAR "=<chapter>          \tchapter number"
954         "\n  " INPUT_ANGLE_VAR "=<angle>              \tangle number"
955         "\n  " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off}  \taudio type"
956         "\n  " INPUT_CHANNEL_VAR "=[0-15]             \taudio channel"
957         "\n  " INPUT_SUBTITLE_VAR "=[0-31]            \tsubtitle channel" );
958
959     /* Input parameters */
960     intf_MsgImm( "\nInput parameters:"
961         "\n  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface"
962         "\n  " INPUT_CHANNEL_SERVER_VAR "=<hostname>  \tchannel server"
963         "\n  " INPUT_CHANNEL_PORT_VAR "=<port>        \tchannel server port" );
964
965 }
966
967 /*****************************************************************************
968  * Version: print complete program version
969  *****************************************************************************
970  * Print complete program version and build number.
971  *****************************************************************************/
972 static void Version( void )
973 {
974     intf_MsgImm( VERSION_MESSAGE
975         "This program comes with NO WARRANTY, to the extent permitted by law.\n"
976         "You may redistribute it under the terms of the GNU General Public License;\n"
977         "see the file named COPYING for details.\n"
978         "Written by the VideoLAN team at Ecole Centrale, Paris." );
979 }
980
981 /*****************************************************************************
982  * InitSignalHandler: system signal handler initialization
983  *****************************************************************************
984  * Set the signal handlers. SIGTERM is not intercepted, because we need at
985  * at least a method to kill the program when all other methods failed, and
986  * when we don't want to use SIGKILL.
987  *****************************************************************************/
988 static void InitSignalHandler( void )
989 {
990     /* Termination signals */
991 #ifndef WIN32
992     signal( SIGINT,  FatalSignalHandler );
993     signal( SIGHUP,  FatalSignalHandler );
994     signal( SIGQUIT, FatalSignalHandler );
995
996     /* Other signals */
997     signal( SIGALRM, SimpleSignalHandler );
998     signal( SIGPIPE, SimpleSignalHandler );
999 #endif
1000 }
1001
1002
1003 /*****************************************************************************
1004  * SimpleSignalHandler: system signal handler
1005  *****************************************************************************
1006  * This function is called when a non fatal signal is received by the program.
1007  *****************************************************************************/
1008 static void SimpleSignalHandler( int i_signal )
1009 {
1010     /* Acknowledge the signal received */
1011     intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
1012 }
1013
1014
1015 /*****************************************************************************
1016  * FatalSignalHandler: system signal handler
1017  *****************************************************************************
1018  * This function is called when a fatal signal is received by the program.
1019  * It tries to end the program in a clean way.
1020  *****************************************************************************/
1021 static void FatalSignalHandler( int i_signal )
1022 {
1023     /* Once a signal has been trapped, the termination sequence will be
1024      * armed and following signals will be ignored to avoid sending messages
1025      * to an interface having been destroyed */
1026 #ifndef WIN32
1027     signal( SIGINT,  SIG_IGN );
1028     signal( SIGHUP,  SIG_IGN );
1029     signal( SIGQUIT, SIG_IGN );
1030 #endif
1031
1032     /* Acknowledge the signal received */
1033     intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
1034
1035     /* Try to terminate everything - this is done by requesting the end of the
1036      * interface thread */
1037     p_main->p_intf->b_die = 1;
1038 }
1039
1040 /*****************************************************************************
1041  * InstructionSignalHandler: system signal handler
1042  *****************************************************************************
1043  * This function is called when a illegal instruction signal is received by
1044  * the program.
1045  * We use this function to test OS and CPU_Capabilities
1046  *****************************************************************************/
1047 static void InstructionSignalHandler( int i_signal )
1048 {
1049     /* Once a signal has been trapped, the termination sequence will be
1050      * armed and following signals will be ignored to avoid sending messages
1051      * to an interface having been destroyed */
1052
1053     /* Acknowledge the signal received */
1054     i_illegal = 1;
1055     
1056 #ifdef HAVE_SIGRELSE
1057     sigrelse( i_signal );
1058 #endif
1059     longjmp( env, 1 );
1060 }
1061
1062 /*****************************************************************************
1063  * CPUCapabilities: list the processors MMX support and other capabilities
1064  *****************************************************************************
1065  * This function is called to list extensions the CPU may have.
1066  *****************************************************************************/
1067 static int CPUCapabilities( void )
1068 {
1069     volatile int i_capabilities = CPU_CAPABILITY_NONE;
1070
1071 #if defined( SYS_BEOS )
1072     i_capabilities |= CPU_CAPABILITY_486
1073                       | CPU_CAPABILITY_586
1074                       | CPU_CAPABILITY_MMX;
1075
1076     return( i_capabilities );
1077
1078 #elif defined( SYS_DARWIN )
1079     struct host_basic_info hi;
1080     kern_return_t          ret;
1081     host_name_port_t       host;
1082
1083     int i_size;
1084     char *psz_name, *psz_subname;
1085
1086     /* Should 'never' fail? */
1087     host = mach_host_self();
1088
1089     i_size = sizeof( hi ) / sizeof( int );
1090     ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
1091
1092     if( ret != KERN_SUCCESS )
1093     {
1094         fprintf( stderr, "error: couldn't get CPU information\n" );
1095         return( i_capabilities );
1096     }
1097
1098     slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
1099     /* FIXME: need better way to detect newer proccessors.
1100      * could do strncmp(a,b,5), but that's real ugly */
1101     if( !strcmp(psz_name, "ppc7400") || !strcmp(psz_name, "ppc7450") )
1102     {
1103         i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1104     }
1105
1106     return( i_capabilities );
1107
1108 #elif defined( __i386__ )
1109     volatile unsigned int  i_eax, i_ebx, i_ecx, i_edx;
1110     volatile boolean_t     b_amd;
1111
1112     signal( SIGILL, InstructionSignalHandler );
1113     
1114     /* test for a 486 CPU */
1115     asm volatile ( "pushfl\n\t"
1116                    "popl %%eax\n\t"
1117                    "movl %%eax, %%ebx\n\t"
1118                    "xorl $0x200000, %%eax\n\t"
1119                    "pushl %%eax\n\t"
1120                    "popfl\n\t"
1121                    "pushfl\n\t"
1122                    "popl %%eax"
1123                  : "=a" ( i_eax ),
1124                    "=b" ( i_ebx )
1125                  :
1126                  : "cc" );
1127
1128     if( i_eax == i_ebx )
1129     {
1130         signal( SIGILL, NULL );     
1131         return( i_capabilities );
1132     }
1133
1134     i_capabilities |= CPU_CAPABILITY_486;
1135
1136     /* the CPU supports the CPUID instruction - get its level */
1137     cpuid( 0x00000000 );
1138
1139     if( !i_eax )
1140     {
1141         signal( SIGILL, NULL );     
1142         return( i_capabilities );
1143     }
1144
1145     /* FIXME: this isn't correct, since some 486s have cpuid */
1146     i_capabilities |= CPU_CAPABILITY_586;
1147
1148     /* borrowed from mpeg2dec */
1149     b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1150                     && ( i_edx == 0x69746e65 );
1151
1152     /* test for the MMX flag */
1153     cpuid( 0x00000001 );
1154
1155     if( ! (i_edx & 0x00800000) )
1156     {
1157         signal( SIGILL, NULL );     
1158         return( i_capabilities );
1159     }
1160
1161     i_capabilities |= CPU_CAPABILITY_MMX;
1162
1163     if( i_edx & 0x02000000 )
1164     {
1165         i_capabilities |= CPU_CAPABILITY_MMXEXT;
1166
1167 #ifdef HAVE_SSE
1168         /* We test if OS support the SSE instructions */
1169         i_illegal = 0;
1170         if( setjmp( env ) == 0 )
1171         {
1172             /* Test a SSE instruction */
1173             __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
1174         }
1175
1176         if( i_illegal == 0 )
1177         {
1178             i_capabilities |= CPU_CAPABILITY_SSE;
1179         }
1180         else
1181         {
1182             fprintf( stderr, "warning: your OS doesn't have support for "
1183                              "SSE instructions, "
1184                              "some optimizations\nwill be disabled\n" );
1185 #ifdef SYS_LINUX
1186             fprintf( stderr, "(you will need Linux kernel 2.4.x or later)\n" );
1187 #endif
1188         }
1189 #endif
1190     }
1191     
1192     /* test for additional capabilities */
1193     cpuid( 0x80000000 );
1194
1195     if( i_eax < 0x80000001 )
1196     {
1197         signal( SIGILL, NULL );     
1198         return( i_capabilities );
1199     }
1200
1201     /* list these additional capabilities */
1202     cpuid( 0x80000001 );
1203
1204 #ifdef HAVE_3DNOW
1205     if( i_edx & 0x80000000 )
1206     {
1207         i_illegal = 0;
1208         if( setjmp( env ) == 0 )
1209         {
1210             /* Test a 3D Now! instruction */
1211             __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
1212         }
1213
1214         if( i_illegal == 0 ) 
1215         {
1216             i_capabilities |= CPU_CAPABILITY_3DNOW;
1217         }
1218     }
1219 #endif
1220
1221     if( b_amd && ( i_edx & 0x00400000 ) )
1222     {
1223         i_capabilities |= CPU_CAPABILITY_MMXEXT;
1224     }
1225
1226     signal( SIGILL, NULL );     
1227     return( i_capabilities );
1228
1229 #elif defined( __powerpc__ )
1230
1231     /* Test for Altivec */
1232     signal( SIGILL, InstructionSignalHandler );
1233
1234 #ifdef HAVE_ALTIVEC
1235     i_illegal = 0;
1236     if( setjmp( env ) == 0 )
1237     {
1238         asm volatile ("mtspr 256,%0" : : "r" (-1));
1239     }
1240
1241     if( i_illegal == 0 )
1242     {
1243         i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1244     }
1245 #endif
1246
1247     signal( SIGILL, NULL );     
1248     return( i_capabilities );
1249
1250 #else
1251     /* default behaviour */
1252     return( i_capabilities );
1253
1254 #endif
1255 }
1256
1257 /*****************************************************************************
1258  * RedirectSTDOUT: redirect stdout and stderr to a file
1259  *****************************************************************************
1260  * This function will redirect stdout and stderr to a file if the user has
1261  * specified so.
1262  *****************************************************************************/
1263 static int RedirectSTDOUT( void )
1264 {
1265     int  i_stdout_filedesc;
1266     char *psz_stdout_filename;
1267
1268     psz_stdout_filename = main_GetPszVariable( INTF_STDOUT_VAR,
1269                                                INTF_STDOUT_DEFAULT );
1270     if( strcmp( "", psz_stdout_filename ) != 0 )
1271     {
1272         ShowConsole();
1273         i_stdout_filedesc = open( psz_stdout_filename,
1274                                   O_CREAT | O_TRUNC | O_RDWR,
1275                                   S_IREAD | S_IWRITE );
1276
1277         if( dup2( i_stdout_filedesc, fileno(stdout) ) == -1 )
1278         {
1279             intf_ErrMsg( "warning: unable to redirect stdout" );
1280         }
1281
1282         if( dup2( i_stdout_filedesc, fileno(stderr) ) == -1 )
1283         {
1284             intf_ErrMsg( "warning: unable to redirect stderr" );
1285         }
1286
1287         close( i_stdout_filedesc );
1288     }
1289     else
1290     {
1291         /* No stdout redirection has been asked so open a console */
1292         if( p_main->i_warning_level )
1293         {
1294             ShowConsole();
1295         }
1296
1297     }
1298
1299     return 0;
1300 }
1301
1302 /*****************************************************************************
1303  * ShowConsole: On Win32, create an output console for debug messages
1304  *****************************************************************************
1305  * This function is usefull only on Win32.
1306  *****************************************************************************/
1307 static void ShowConsole( void )
1308 {
1309 #ifdef WIN32 /*  */
1310     AllocConsole();
1311     freopen( "CONOUT$", "w", stdout );
1312     freopen( "CONOUT$", "w", stderr );
1313     freopen( "CONIN$", "r", stdin );
1314 #endif
1315     return;
1316 }
1317