wscript: Implemented Host_put_Interactive.
[wine] / programs / wscript / host.c
1 /*
2  * Copyright 2010 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22 #define CONST_VTABLE
23
24 #include <windef.h>
25 #include <winbase.h>
26 #include <ole2.h>
27
28 #include "wscript.h"
29
30 #include <wine/debug.h>
31 #include <wine/unicode.h>
32
33 #define BUILDVERSION 16535
34
35 static const WCHAR wshNameW[] = {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
36 static const WCHAR wshVersionW[] = {'5','.','8'};
37 VARIANT_BOOL wshInteractive = VARIANT_TRUE;
38
39 WINE_DEFAULT_DEBUG_CHANNEL(wscript);
40
41 static HRESULT WINAPI Host_QueryInterface(IHost *iface, REFIID riid, void **ppv)
42 {
43     WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
44
45     if(IsEqualGUID(&IID_IUnknown, riid)
46        || IsEqualGUID(&IID_IDispatch, riid)
47        || IsEqualGUID(&IID_IHost, riid)) {
48         *ppv = iface;
49         return S_OK;
50     }
51
52     *ppv = NULL;
53     return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI Host_AddRef(IHost *iface)
57 {
58     return 2;
59 }
60
61 static ULONG WINAPI Host_Release(IHost *iface)
62 {
63     return 1;
64 }
65
66 static HRESULT WINAPI Host_GetTypeInfoCount(IHost *iface, UINT *pctinfo)
67 {
68     WINE_TRACE("(%p)\n", pctinfo);
69     *pctinfo = 1;
70     return S_OK;
71 }
72
73 static HRESULT WINAPI Host_GetTypeInfo(IHost *iface, UINT iTInfo, LCID lcid,
74         ITypeInfo **ppTInfo)
75 {
76     WINE_TRACE("(%x %x %p\n", iTInfo, lcid, ppTInfo);
77
78     ITypeInfo_AddRef(host_ti);
79     *ppTInfo = host_ti;
80     return S_OK;
81 }
82
83 static HRESULT WINAPI Host_GetIDsOfNames(IHost *iface, REFIID riid, LPOLESTR *rgszNames,
84         UINT cNames, LCID lcid, DISPID *rgDispId)
85 {
86     WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid), rgszNames,
87         cNames, lcid, rgDispId);
88
89     return ITypeInfo_GetIDsOfNames(host_ti, rgszNames, cNames, rgDispId);
90 }
91
92 static HRESULT WINAPI Host_Invoke(IHost *iface, DISPID dispIdMember, REFIID riid,
93         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
94         EXCEPINFO *pExcepInfo, UINT *puArgErr)
95 {
96     WINE_TRACE("(%d %p %p)\n", dispIdMember, pDispParams, pVarResult);
97
98     return ITypeInfo_Invoke(host_ti, iface, dispIdMember, wFlags, pDispParams,
99             pVarResult, pExcepInfo, puArgErr);
100 }
101
102 static HRESULT WINAPI Host_get_Name(IHost *iface, BSTR *out_Name)
103 {
104     WINE_TRACE("(%p)\n", out_Name);
105
106     if(!(*out_Name = SysAllocString(wshNameW)))
107         return E_OUTOFMEMORY;
108     return S_OK;
109 }
110
111 static HRESULT WINAPI Host_get_Application(IHost *iface, IDispatch **out_Dispatch)
112 {
113     WINE_FIXME("(%p)\n", out_Dispatch);
114     return E_NOTIMPL;
115 }
116
117 static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
118 {
119     WCHAR fullPath[MAX_PATH];
120
121     WINE_TRACE("(%p)\n", out_Path);
122
123     if(GetModuleFileNameW(NULL, fullPath, sizeof(fullPath)/sizeof(WCHAR)) == 0)
124         return E_FAIL;
125     if(!(*out_Path = SysAllocString(fullPath)))
126         return E_OUTOFMEMORY;
127     return S_OK;
128 }
129
130 static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path)
131 {
132     WCHAR path[MAX_PATH];
133     int howMany;
134     WCHAR *pos;
135
136     WINE_TRACE("(%p)\n", out_Path);
137
138     if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0)
139         return E_FAIL;
140     pos = strrchrW(path, '\\');
141     howMany = pos - path;
142     if(!(*out_Path = SysAllocStringLen(path, howMany)))
143         return E_OUTOFMEMORY;
144     return S_OK;
145 }
146
147 static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive)
148 {
149     WINE_TRACE("(%p)\n", out_Interactive);
150
151     *out_Interactive = wshInteractive;
152     return S_OK;
153 }
154
155 static HRESULT WINAPI Host_put_Interactive(IHost *iface, VARIANT_BOOL v)
156 {
157     WINE_TRACE("(%x)\n", v);
158
159     wshInteractive = v;
160     return S_OK;
161 }
162
163 static HRESULT WINAPI Host_Quit(IHost *iface, int ExitCode)
164 {
165     WINE_FIXME("(%d)\n", ExitCode);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI Host_get_ScriptName(IHost *iface, BSTR *out_ScriptName)
170 {
171     WCHAR *scriptName;
172
173     WINE_TRACE("(%p)\n", out_ScriptName);
174
175     scriptName = strrchrW(scriptFullName, '\\');
176     ++scriptName;
177     if(!(*out_ScriptName = SysAllocString(scriptName)))
178         return E_OUTOFMEMORY;
179     return S_OK;
180 }
181
182 static HRESULT WINAPI Host_get_ScriptFullName(IHost *iface, BSTR *out_ScriptFullName)
183 {
184     WINE_TRACE("(%p)\n", out_ScriptFullName);
185
186     if(!(*out_ScriptFullName = SysAllocString(scriptFullName)))
187         return E_OUTOFMEMORY;
188     return S_OK;
189 }
190
191 static HRESULT WINAPI Host_get_Arguments(IHost *iface, IArguments2 **out_Arguments)
192 {
193     WINE_TRACE("(%p)\n", out_Arguments);
194
195     *out_Arguments = &arguments_obj;
196     return S_OK;
197 }
198
199 static HRESULT WINAPI Host_get_Version(IHost *iface, BSTR *out_Version)
200 {
201     WINE_TRACE("(%p)\n", out_Version);
202
203     if(!(*out_Version = SysAllocString(wshVersionW)))
204         return E_OUTOFMEMORY;
205     return S_OK;
206 }
207
208 static HRESULT WINAPI Host_get_BuildVersion(IHost *iface, int *out_Build)
209 {
210     WINE_TRACE("(%p)\n", out_Build);
211
212     *out_Build = BUILDVERSION;
213     return S_OK;
214 }
215
216 static HRESULT WINAPI Host_get_Timeout(IHost *iface, LONG *out_Timeout)
217 {
218     WINE_FIXME("(%p)\n", out_Timeout);
219     return E_NOTIMPL;
220 }
221
222 static HRESULT WINAPI Host_put_Timeout(IHost *iface, LONG v)
223 {
224     WINE_FIXME("(%d)\n", v);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI Host_CreateObject(IHost *iface, BSTR ProgID, BSTR Prefix,
229         IDispatch **out_Dispatch)
230 {
231     WINE_FIXME("(%s %s %p)\n", wine_dbgstr_w(ProgID), wine_dbgstr_w(Prefix), out_Dispatch);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI Host_Echo(IHost *iface, SAFEARRAY *args)
236 {
237     WINE_FIXME("(%p)\n", args);
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI Host_GetObject(IHost *iface, BSTR Pathname, BSTR ProgID,
242         BSTR Prefix, IDispatch **out_Dispatch)
243 {
244     WINE_FIXME("(%s %s %s %p)\n", wine_dbgstr_w(Pathname), wine_dbgstr_w(ProgID),
245         wine_dbgstr_w(Prefix), out_Dispatch);
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI Host_DisconnectObject(IHost *iface, IDispatch *Object)
250 {
251     WINE_FIXME("(%p)\n", Object);
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI Host_Sleep(IHost *iface, LONG Time)
256 {
257     WINE_FIXME("(%d)\n", Time);
258     return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI Host_ConnectObject(IHost *iface, IDispatch *Object, BSTR Prefix)
262 {
263     WINE_FIXME("(%p %s)\n", Object, wine_dbgstr_w(Prefix));
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI Host_get_StdIn(IHost *iface, ITextStream **ppts)
268 {
269     WINE_FIXME("(%p)\n", ppts);
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI Host_get_StdOut(IHost *iface, ITextStream **ppts)
274 {
275     WINE_FIXME("(%p)\n", ppts);
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI Host_get_StdErr(IHost *iface, ITextStream **ppts)
280 {
281     WINE_FIXME("(%p)\n", ppts);
282     return E_NOTIMPL;
283 }
284
285 static const IHostVtbl HostVtbl = {
286     Host_QueryInterface,
287     Host_AddRef,
288     Host_Release,
289     Host_GetTypeInfoCount,
290     Host_GetTypeInfo,
291     Host_GetIDsOfNames,
292     Host_Invoke,
293     Host_get_Name,
294     Host_get_Application,
295     Host_get_FullName,
296     Host_get_Path,
297     Host_get_Interactive,
298     Host_put_Interactive,
299     Host_Quit,
300     Host_get_ScriptName,
301     Host_get_ScriptFullName,
302     Host_get_Arguments,
303     Host_get_Version,
304     Host_get_BuildVersion,
305     Host_get_Timeout,
306     Host_put_Timeout,
307     Host_CreateObject,
308     Host_Echo,
309     Host_GetObject,
310     Host_DisconnectObject,
311     Host_Sleep,
312     Host_ConnectObject,
313     Host_get_StdIn,
314     Host_get_StdOut,
315     Host_get_StdErr
316 };
317
318 IHost host_obj = { &HostVtbl };