Handle the %f case in wsprintf.
[wine.git] / dlls / msvcrt / data.c
blob71d30d037cb157e20a830c86fa12e24fd6ee859e
1 /*
2 * msvcrt.dll dll data items
4 * Copyright 2000 Jon Griffiths
5 */
6 #include <math.h>
7 #include "msvcrt.h"
9 #include "msvcrt/stdlib.h"
10 #include "msvcrt/string.h"
13 DEFAULT_DEBUG_CHANNEL(msvcrt);
15 unsigned int MSVCRT___argc;
16 unsigned int MSVCRT_basemajor;/* FIXME: */
17 unsigned int MSVCRT_baseminor;/* FIXME: */
18 unsigned int MSVCRT_baseversion; /* FIXME: */
19 unsigned int MSVCRT__commode;
20 unsigned int MSVCRT__fmode;
21 unsigned int MSVCRT_osmajor;/* FIXME: */
22 unsigned int MSVCRT_osminor;/* FIXME: */
23 unsigned int MSVCRT_osmode;/* FIXME: */
24 unsigned int MSVCRT__osver;
25 unsigned int MSVCRT_osversion; /* FIXME: */
26 unsigned int MSVCRT__winmajor;
27 unsigned int MSVCRT__winminor;
28 unsigned int MSVCRT__winver;
29 unsigned int MSVCRT__sys_nerr; /* FIXME: not accessible from Winelib apps */
30 char** MSVCRT__sys_errlist; /* FIXME: not accessible from Winelib apps */
31 unsigned int MSVCRT___setlc_active;
32 unsigned int MSVCRT___unguarded_readlc_active;
33 double MSVCRT__HUGE;
34 char **MSVCRT___argv;
35 WCHAR **MSVCRT___wargv;
36 char *MSVCRT__acmdln;
37 WCHAR *MSVCRT__wcmdln;
38 char **MSVCRT__environ;
39 WCHAR **MSVCRT__wenviron;
40 char **MSVCRT___initenv;
41 WCHAR **MSVCRT___winitenv;
42 int MSVCRT_timezone;
43 int MSVCRT_app_type;
45 typedef void (*_INITTERMFUN)(void);
47 /***********************************************************************
48 * __p___argc (MSVCRT.@)
50 int* __p___argc(void) { return &MSVCRT___argc; }
52 /***********************************************************************
53 * __p__commode (MSVCRT.@)
55 unsigned int* __p__commode(void) { return &MSVCRT__commode; }
57 /***********************************************************************
58 * __p__fmode (MSVCRT.@)
60 unsigned int* __p__fmode(void) { return &MSVCRT__fmode; }
62 /***********************************************************************
63 * __p__osver (MSVCRT.@)
65 unsigned int* __p__osver(void) { return &MSVCRT__osver; }
67 /***********************************************************************
68 * __p__winmajor (MSVCRT.@)
70 unsigned int* __p__winmajor(void) { return &MSVCRT__winmajor; }
72 /***********************************************************************
73 * __p__winminor (MSVCRT.@)
75 unsigned int* __p__winminor(void) { return &MSVCRT__winminor; }
77 /***********************************************************************
78 * __p__winver (MSVCRT.@)
80 unsigned int* __p__winver(void) { return &MSVCRT__winver; }
82 /*********************************************************************
83 * __p__acmdln (MSVCRT.@)
85 char** __p__acmdln(void) { return &MSVCRT__acmdln; }
87 /*********************************************************************
88 * __p__wcmdln (MSVCRT.@)
90 WCHAR** __p__wcmdln(void) { return &MSVCRT__wcmdln; }
92 /*********************************************************************
93 * __p___argv (MSVCRT.@)
95 char*** __p___argv(void) { return &MSVCRT___argv; }
97 /*********************************************************************
98 * __p___wargv (MSVCRT.@)
100 WCHAR*** __p___wargv(void) { return &MSVCRT___wargv; }
102 /*********************************************************************
103 * __p__environ (MSVCRT.@)
105 char*** __p__environ(void) { return &MSVCRT__environ; }
107 /*********************************************************************
108 * __p__wenviron (MSVCRT.@)
110 WCHAR*** __p__wenviron(void) { return &MSVCRT__wenviron; }
112 /*********************************************************************
113 * __p___initenv (MSVCRT.@)
115 char*** __p___initenv(void) { return &MSVCRT___initenv; }
117 /*********************************************************************
118 * __p___winitenv (MSVCRT.@)
120 WCHAR*** __p___winitenv(void) { return &MSVCRT___winitenv; }
122 /*********************************************************************
123 * __p__timezone (MSVCRT.@)
125 int* __p__timezone(void) { return &MSVCRT_timezone; }
127 /* INTERNAL: Create a wide string from an ascii string */
128 static WCHAR *wstrdupa(const char *str)
130 const size_t len = strlen(str) + 1 ;
131 WCHAR *wstr = MSVCRT_malloc(len* sizeof (WCHAR));
132 if (!wstr)
133 return NULL;
134 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len*sizeof(char),wstr,len* sizeof (WCHAR));
135 return wstr;
138 /* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
139 * we initialise data values during DLL loading. The when called by a native
140 * program we simply return the data we've already initialised. This also means
141 * you can call multiple times without leaking
143 void msvcrt_init_args(void)
145 char *cmdline, **xargv = NULL;
146 WCHAR *wcmdline, **wxargv = NULL;
147 int xargc,end,last_arg,afterlastspace;
148 DWORD version;
150 MSVCRT__acmdln = _strdup( GetCommandLineA() );
151 MSVCRT__wcmdln = wcmdline = wstrdupa(MSVCRT__acmdln);
153 /* Make a copy of MSVCRT__acmdln to be able modify it.
154 We will free it at the end of processing. */
155 cmdline = _strdup(MSVCRT__acmdln);
157 TRACE("got '%s', wide = '%s'\n", cmdline, debugstr_w(wcmdline));
159 version = GetVersion();
160 MSVCRT__osver = version >> 16;
161 MSVCRT__winminor = version & 0xFF;
162 MSVCRT__winmajor = (version>>8) & 0xFF;
163 MSVCRT_baseversion = version >> 16;
164 MSVCRT__winver = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
165 MSVCRT_baseminor = (version >> 16) & 0xFF;
166 MSVCRT_basemajor = (version >> 24) & 0xFF;
167 MSVCRT_osversion = version & 0xFFFF;
168 MSVCRT_osminor = version & 0xFF;
169 MSVCRT_osmajor = (version>>8) & 0xFF;
170 MSVCRT__sys_nerr = 43;
171 MSVCRT__HUGE = HUGE_VAL;
172 MSVCRT___setlc_active = 0;
173 MSVCRT___unguarded_readlc_active = 0;
174 MSVCRT_timezone = 0;
176 /* FIXME: set app type for Winelib apps */
178 end = last_arg = xargc = afterlastspace = 0;
179 while (1)
181 if ((cmdline[end]==' ') || (cmdline[end]=='\0'))
183 if (cmdline[end]=='\0')
184 last_arg=1;
185 else
186 cmdline[end]='\0';
187 /* alloc xargc + NULL entry */
188 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
189 sizeof(char*)*(xargc+1));
190 wxargv=(WCHAR**)HeapReAlloc( GetProcessHeap(), 0, wxargv,
191 sizeof(WCHAR*)*(xargc+1));
193 if (strlen(cmdline+afterlastspace))
195 xargv[xargc] = _strdup(cmdline+afterlastspace);
196 wxargv[xargc] = wstrdupa(xargv[xargc]);
197 xargc++;
198 if (!last_arg) /* need to seek to the next arg ? */
200 end++;
201 while (cmdline[end]==' ')
202 end++;
204 afterlastspace=end;
206 else
208 xargv[xargc] = NULL;
209 wxargv[xargc] = NULL; /* the last entry is NULL */
210 break;
213 else
214 end++;
216 MSVCRT___argc = xargc;
217 MSVCRT___argv = xargv;
218 MSVCRT___wargv = wxargv;
220 /* Free a no more needed copy of the command line */
221 MSVCRT_free( cmdline );
223 TRACE("found %d arguments\n",MSVCRT___argc);
224 /* FIXME: This is plain wrong, we must convert from a '\0' separated
225 * memory block to an array of pointers to string format.
227 MSVCRT__environ = GetEnvironmentStringsA();
228 MSVCRT___initenv = MSVCRT__environ;
229 /* FIXME: This is plain wrong, we must convert from a '\0' separated
230 * memory block to an array of pointers to string format.
232 MSVCRT__wenviron = GetEnvironmentStringsW();
233 MSVCRT___winitenv = MSVCRT__wenviron;
237 /* INTERNAL: free memory used by args */
238 void msvcrt_free_args(void)
240 /* FIXME */
243 /*********************************************************************
244 * __getmainargs (MSVCRT.@)
246 void __getmainargs(int *argc, char** *argv, char** *envp,
247 int expand_wildcards, int *new_mode)
249 TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
250 *argc = MSVCRT___argc;
251 *argv = MSVCRT___argv;
252 *envp = MSVCRT__environ;
253 MSVCRT__set_new_mode( *new_mode );
256 /*********************************************************************
257 * __wgetmainargs (MSVCRT.@)
259 void __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
260 int expand_wildcards, int *new_mode)
262 TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
263 *argc = MSVCRT___argc;
264 *wargv = MSVCRT___wargv;
265 *wenvp = MSVCRT__wenviron;
266 MSVCRT__set_new_mode( *new_mode );
269 /*********************************************************************
270 * _initterm (MSVCRT.@)
272 unsigned int _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
274 _INITTERMFUN* current = start;
276 TRACE("(%p,%p)\n",start,end);
277 while (current<end)
279 if (*current)
281 TRACE("Call init function %p\n",*current);
282 (**current)();
283 TRACE("returned\n");
285 current++;
287 return 0;
290 /*********************************************************************
291 * __set_app_type (MSVCRT.@)
293 void MSVCRT___set_app_type(int app_type)
295 TRACE("(%d) %s application\n", app_type, app_type == 2 ? "Gui" : "Console");
296 MSVCRT_app_type = app_type;