1 /*****************************************************************************
2 * winvlc.c: the Windows VLC player
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
6 * Authors: Vincent Seguin <seguin@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Lots of other people, see the libvlc AUTHORS file
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
38 static void find_end_quote( char **s, char **ppsz_parser, int i_quote )
47 (*ppsz_parser)++; (*s)++;
50 else if( **s == '"' || **s == '\'' )
52 /* Preceeded by a number of '\' which we erase. */
53 *ppsz_parser -= i_bcount / 2;
56 /* '\\' followed by a '"' or '\'' */
59 (*ppsz_parser)++; (*s)++;
71 /* Different quoting */
74 (*ppsz_parser)++; (*s)++;
75 find_end_quote( s, ppsz_parser, i_quote );
77 (*ppsz_parser)++; (*s)++;
84 /* A regular character */
86 (*ppsz_parser)++; (*s)++;
92 /*************************************************************************
93 * vlc_parse_cmdline: Command line parsing into elements.
95 * The command line is composed of space/tab separated arguments.
96 * Quotes can be used as argument delimiters and a backslash can be used to
98 *************************************************************************/
99 static char **vlc_parse_cmdline( const char *psz_cmdline, int *i_args )
102 char *s, *psz_parser, *psz_arg, *psz_orig;
103 int i_bcount = 0, argc = 0;
105 psz_orig = strdup( psz_cmdline );
106 psz_arg = psz_parser = s = psz_orig;
110 if( *s == '\t' || *s == ' ' )
112 /* We have a complete argument */
114 argv = realloc( argv, (argc + 1) * sizeof (char *) );
115 argv[argc] = psz_arg;
117 /* Skip trailing spaces/tabs */
118 do{ s++; } while( *s == '\t' || *s == ' ' );
121 psz_arg = psz_parser = s;
124 else if( *s == '\\' )
126 *psz_parser++ = *s++;
129 else if( *s == '"' || *s == '\'' )
131 if( ( i_bcount & 1 ) == 0 )
133 /* Preceeded by an even number of '\', this is half that
134 * number of '\', plus a quote which we erase. */
136 psz_parser -= i_bcount / 2;
138 find_end_quote( &s, &psz_parser, i_quote );
143 /* Preceeded by an odd number of '\', this is half that
144 * number of '\' followed by a '"' */
145 psz_parser = psz_parser - i_bcount/2 - 1;
153 /* A regular character */
154 *psz_parser++ = *s++;
159 /* Take care of the last arg */
163 argv = realloc( argv, (argc + 1) * sizeof (char *) );
164 argv[argc] = psz_arg;
173 # define wWinMain WinMain
176 /*****************************************************************************
177 * wWinMain: parse command line, start interface and spawn threads.
178 *****************************************************************************/
179 int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
180 LPWSTR lpCmdLine, int nCmdShow )
182 char **argv, psz_cmdline[wcslen(lpCmdLine) * 4];
185 (void)hInstance; (void)hPrevInstance; (void)nCmdShow;
186 /* This clutters OSX GUI error logs */
187 fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
189 WideCharToMultiByte( CP_UTF8, 0, lpCmdLine, -1,
190 psz_cmdline, MAX_PATH, NULL, NULL );
191 argv = vlc_parse_cmdline( psz_cmdline, &argc );
193 libvlc_exception_t ex;
194 libvlc_exception_init (&ex);
196 /* Initialize libvlc */
197 libvlc_instance_t *vlc = libvlc_new (argc, (const char **)argv, &ex);
200 libvlc_run_interface (vlc, NULL, &ex);
201 libvlc_release (vlc);
204 ret = libvlc_exception_raised (&ex);
205 libvlc_exception_clear (&ex);