Fix description
[vlc.git] / src / winvlc.c
blob18c1b13b1234e3989db029fc72b63df17ed5ba22
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 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #define UNICODE
32 #include <vlc/vlc.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <windows.h>
38 static int parse_cmdline (char *line, char ***argvp)
40 char **argv = malloc (sizeof (char *));
41 int argc = 0;
43 while (*line != '\0')
45 char quote = 0;
47 /* Skips white spaces */
48 while (strchr ("\t ", *line))
49 line++;
50 if (!*line)
51 break;
53 /* Starts a new parameter */
54 argv = realloc (argv, (argc + 2) * sizeof (char *));
55 if (*line == '"')
57 quote = '"';
58 line++;
60 argv[argc++] = line;
62 more:
63 while (*line && !strchr ("\t ", *line))
64 line++;
66 if (line > argv[argc - 1] && line[-1] == quote)
67 /* End of quoted parameter */
68 line[-1] = 0;
69 else
70 if (*line && quote)
72 /* Space within a quote */
73 line++;
74 goto more;
76 else
77 /* End of unquoted parameter */
78 if (*line)
79 *line++ = 0;
81 argv[argc] = NULL;
82 *argvp = argv;
83 return argc;
86 #ifdef UNDER_CE
87 # define wWinMain WinMain
88 #endif
90 /*****************************************************************************
91 * wWinMain: parse command line, start interface and spawn threads.
92 *****************************************************************************/
93 int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
94 LPWSTR lpCmdLine, int nCmdShow )
96 char **argv, psz_cmdline[wcslen(lpCmdLine) * 4 + 1];
97 int argc, ret;
99 (void)hInstance; (void)hPrevInstance; (void)nCmdShow;
101 WideCharToMultiByte( CP_UTF8, 0, lpCmdLine, -1,
102 psz_cmdline, sizeof (psz_cmdline), NULL, NULL );
104 argc = parse_cmdline (psz_cmdline, &argv);
106 libvlc_exception_t ex, dummy;
107 libvlc_exception_init (&ex);
108 libvlc_exception_init (&dummy);
110 /* Initialize libvlc */
111 libvlc_instance_t *vlc = libvlc_new (argc, (const char **)argv, &ex);
112 if (vlc != NULL)
114 libvlc_add_intf (vlc, NULL, &ex);
115 libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
116 libvlc_wait (vlc);
117 libvlc_release (vlc);
119 free (argv);
121 ret = libvlc_exception_raised (&ex);
122 libvlc_exception_clear (&ex);
123 libvlc_exception_clear (&dummy);
124 return ret;
127 #ifndef IF_MINGW_SUPPORTED_UNICODE
128 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
129 LPSTR args, int nCmdShow)
131 /* This makes little sense, but at least it links properly */
132 wchar_t lpCmdLine[(strlen (args) + 1) * 3];
133 MultiByteToWideChar (CP_ACP, 0, args, -1, lpCmdLine, sizeof (lpCmdLine));
134 return wWinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow);
136 #endif