]> git.sesse.net Git - vlc/blob - bin/winvlc.c
Remove un-needed libs
[vlc] / bin / winvlc.c
1 /*****************************************************************************
2  * winvlc.c: the Windows VLC player
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
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
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #define UNICODE
32 #include <vlc/vlc.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <windows.h>
37
38 #ifndef UNDER_CE
39 static char *FromWide (const wchar_t *wide)
40 {
41     size_t len;
42     len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
43
44     char *out = (char *)malloc (len);
45     if (out)
46         WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
47     return out;
48 }
49 #else
50 static int parse_cmdline (char *line, char ***argvp)
51 {
52     char **argv = malloc (sizeof (char *));
53     int argc = 0;
54
55     while (*line != '\0')
56     {
57         char quote = 0;
58
59         /* Skips white spaces */
60         while (strchr ("\t ", *line))
61             line++;
62         if (!*line)
63             break;
64
65         /* Starts a new parameter */
66         argv = realloc (argv, (argc + 2) * sizeof (char *));
67         if (*line == '"')
68         {
69             quote = '"';
70             line++;
71         }
72         argv[argc++] = line;
73
74     more:
75             while (*line && !strchr ("\t ", *line))
76             line++;
77
78     if (line > argv[argc - 1] && line[-1] == quote)
79         /* End of quoted parameter */
80         line[-1] = 0;
81     else
82         if (*line && quote)
83     {
84         /* Space within a quote */
85         line++;
86         goto more;
87     }
88     else
89         /* End of unquoted parameter */
90         if (*line)
91             *line++ = 0;
92     }
93     argv[argc] = NULL;
94     *argvp = argv;
95     return argc;
96 }
97 #endif
98
99 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
100 #ifndef UNDER_CE
101                     LPSTR lpCmdLine,
102 #else
103                     LPWSTR lpCmdLine,
104 #endif
105                     int nCmdShow )
106 {
107     int argc, ret;
108 #ifndef UNDER_CE
109     wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
110     if (wargv == NULL)
111         return 1;
112
113     char *argv[argc + 1];
114     for (int i = 0; i < argc; i++)
115         argv[i] = FromWide (wargv[i]);
116     argv[argc] = NULL;
117     LocalFree (wargv);
118 #else
119     char **argv, psz_cmdline[wcslen(lpCmdLine) * 4];
120
121     WideCharToMultiByte( CP_UTF8, 0, lpCmdLine, -1,
122                          psz_cmdline, sizeof (psz_cmdline), NULL, NULL );
123
124     argc = parse_cmdline (psz_cmdline, &argv);
125 #endif
126
127     libvlc_exception_t ex, dummy;
128     libvlc_exception_init (&ex);
129     libvlc_exception_init (&dummy);
130
131     /* Initialize libvlc */
132     libvlc_instance_t *vlc;
133     vlc = libvlc_new (argc - 1, (const char **)argv + 1, &ex);
134     if (vlc != NULL)
135     {
136         libvlc_add_intf (vlc, NULL, &ex);
137         libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
138         libvlc_wait (vlc);
139         libvlc_release (vlc);
140     }
141
142     ret = libvlc_exception_raised (&ex);
143     libvlc_exception_clear (&ex);
144     libvlc_exception_clear (&dummy);
145
146     for (int i = 0; i < argc; i++)
147         free (argv[i]);
148
149     (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
150     return ret;
151 }