Incorporate rosapps. 0.3.15 was branched somewhat incorrectly so rosapps is not synce...
[reactos.git] / modules / rosapps / applications / sysutils / wmain.c
1 /*
2 * Entry point for programs that use wmain()
3 */
4 #include <stdio.h>
5 #include <stdarg.h>
6
7 #include <windef.h>
8 #include <winbase.h>
9
10 int wmain(int argc,wchar_t *argv[]);
11
12 wchar_t *
13 a2w( char * a, wchar_t * w )
14 {
15 wchar_t * ww = w;
16 while (*a) *w++ = (wchar_t) *a++;
17 *w = 0;
18 return ww;
19 }
20
21 wchar_t *
22 fgetws(wchar_t *buf, int bufsize, FILE *file)
23 {
24 char * abuf = GlobalAlloc(bufsize,0);
25 if (!buf)return NULL;
26 fgets(abuf,bufsize,file);
27 a2w(abuf,buf);
28 GlobalFree(abuf);
29 return buf;
30 }
31
32 int main(int argc, char *argv[])
33 {
34 wchar_t ** wargv;
35 int i;
36 int ec;
37
38 wargv = (wchar_t **) GlobalAlloc(
39 sizeof(void*) * argc,
40 0
41 );
42 for(i=0;i<argc;++i)
43 {
44 wargv[i] = (wchar_t*) GlobalAlloc(
45 sizeof(wchar_t) * (1+lstrlenA(argv[i])),
46 0
47 );
48 a2w(argv[i],wargv[i]);
49 }
50 wargv[i] = NULL;
51 ec = wmain(argc,wargv);
52 for (i=0;wargv[i];++i) GlobalFree(wargv[i]);
53 return ec;
54 }