Mercurial > dwindows
comparison winmain.c @ 3:67a643a734d9
Import
author | ktk@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 03 Jul 2001 07:50:39 +0000 |
parents | |
children | bf42d08d72d7 |
comparison
equal
deleted
inserted
replaced
2:36c5f0ce3fbe | 3:67a643a734d9 |
---|---|
1 /* Dynamic Windows stub file to allow Win32 applications | |
2 * to use the main() entry point instead of WinMain(). | |
3 */ | |
4 | |
5 #include <windows.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <stdio.h> | |
9 #include <process.h> | |
10 | |
11 void Win32_Set_Instance(HINSTANCE hInstance); | |
12 | |
13 char **_convertargs(int *count, char *start, HINSTANCE DWInstance) | |
14 { | |
15 char *tmp, *argstart, **argv; | |
16 int loc = 0, inquotes = 0; | |
17 | |
18 (*count) = 1; | |
19 | |
20 tmp = start; | |
21 | |
22 /* Count the number of entries */ | |
23 if(*start) | |
24 { | |
25 (*count)++; | |
26 | |
27 while(*tmp) | |
28 { | |
29 if(*tmp == '"' && inquotes) | |
30 inquotes = 0; | |
31 else if(*tmp == '"' && !inquotes) | |
32 inquotes = 1; | |
33 else if(*tmp == ' ' && !inquotes) | |
34 { | |
35 /* Push past any white space */ | |
36 while(*(tmp+1) == ' ') | |
37 tmp++; | |
38 /* If we aren't at the end of the command | |
39 * line increment the count. | |
40 */ | |
41 if(*(tmp+1)) | |
42 (*count)++; | |
43 } | |
44 tmp++; | |
45 } | |
46 } | |
47 | |
48 argv = (char **)malloc(sizeof(char *) * ((*count)+1)); | |
49 argv[0] = malloc(260); | |
50 GetModuleFileName(DWInstance, argv[0], 260); | |
51 | |
52 argstart = tmp = start; | |
53 | |
54 if(*start) | |
55 { | |
56 loc = 1; | |
57 | |
58 while(*tmp) | |
59 { | |
60 if(*tmp == '"' && inquotes) | |
61 { | |
62 *tmp = 0; | |
63 inquotes = 0; | |
64 } | |
65 else if(*tmp == '"' && !inquotes) | |
66 { | |
67 argstart = tmp+1; | |
68 inquotes = 1; | |
69 } | |
70 else if(*tmp == ' ' && !inquotes) | |
71 { | |
72 *tmp = 0; | |
73 argv[loc] = strdup(argstart); | |
74 | |
75 /* Push past any white space */ | |
76 while(*(tmp+1) == ' ') | |
77 tmp++; | |
78 | |
79 /* Move the start pointer */ | |
80 argstart = tmp+1; | |
81 | |
82 /* If we aren't at the end of the command | |
83 * line increment the count. | |
84 */ | |
85 if(*(tmp+1)) | |
86 loc++; | |
87 } | |
88 tmp++; | |
89 } | |
90 if(*argstart) | |
91 argv[loc] = strdup(argstart); | |
92 } | |
93 argv[loc+1] = NULL; | |
94 return argv; | |
95 } | |
96 | |
97 /* Ok this is a really big hack but what the hell ;) */ | |
98 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |
99 { | |
100 char **argv; | |
101 int argc; | |
102 | |
103 Win32_Set_Instance(hInstance); | |
104 | |
105 argv = _convertargs(&argc, lpCmdLine, hInstance); | |
106 | |
107 return main(argc, argv); | |
108 } |