Imported bzip2 modified to build a decompression only dll for use by the ramdisk...
[reactos.git] / rosapps / cmd / msgbox.c
1 /*
2 * MSGBOX.C - msgbox internal command.
3 *
4 * clone from 4nt msgbox command
5 *
6 * 25 Aug 1999
7 * started - Paolo Pantaleo <paolopan@freemail.it>
8 */
9
10 #include "config.h"
11
12 #ifdef INCLUDE_CMD_MSGBOX
13 #include <windows.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include <tchar.h>
17 #include "cmd.h"
18 //#include <assert.h>
19
20 //#include <malloc.h>
21
22
23 #define U_TYPE_INIT 0
24
25 //undefine it to allow to omit arguments
26 //that will be replaced by default ones
27 #define _SYNTAX_CHECK
28
29
30 INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
31 {
32 //used to parse command line
33 LPTSTR tmp;
34
35 //used to find window title (used as messagebox title)
36 //and to find window handle to pass to MessageBox
37 HWND hWnd;
38 TCHAR buff[128];
39
40 //these are MessabeBox() parameters
41 LPTSTR title, prompt="";
42 UINT uType=U_TYPE_INIT;
43
44 //set default title to window title
45 GetConsoleTitle(buff,128);
46 title = buff;
47
48 if (_tcsncmp (param, _T("/?"), 2) == 0)
49 {
50 ConOutPuts(_T(
51 "display a message box and return user responce\n"
52 "\n"
53 "MSGBOX type [\"title\"] prompt\n"
54 "\n"
55 "type button displayed\n"
56 " possible values are: OK, OKCANCEL,\n"
57 " YESNO, YESNOCANCEL\n"
58 "title title of message box\n"
59 "prompt text displayed by the message box\n"
60 "\n"
61 "\n"
62 "ERRORLEVEL is set according the button pressed:\n"
63 "\n"
64 "YES : 10 | NO : 11\n"
65 "OK : 10 | CANCEL : 12\n"));
66 return 0;
67 }
68
69 //yes here things are quite massed up :)
70
71 //skip spaces
72 while(_istspace(*param))
73 param++;
74
75 //search for type of messagebox (ok, okcancel, ...)
76 if (_tcsnicmp(param, _T("ok "),3 ) == 0)
77 {
78 uType |= MB_ICONEXCLAMATION | MB_OK;
79 param+=3;
80 }
81 else if (_tcsnicmp(param, _T("okcancel "),9 ) == 0)
82 {
83 uType |= MB_ICONQUESTION | MB_OKCANCEL;
84 param+=9;
85 }
86 else if (_tcsnicmp(param, _T("yesno "),6 ) == 0)
87 {
88 uType |= MB_ICONQUESTION | MB_YESNO;
89 param+=6;
90 }
91 else if (_tcsnicmp(param, _T("yesnocancel "), 12 ) == 0)
92 {
93 uType |= MB_ICONQUESTION | MB_YESNOCANCEL;
94 param+=12;
95 }
96 else{
97 #ifdef _SYNTAX_CHECK
98 error_req_param_missing ();
99 return 1;
100 #else
101 uType |= MB_ICONEXCLAMATION | MB_OK;
102 #endif
103 }
104
105
106 //skip spaces
107 while(_istspace(*param))
108 param++;
109
110 #ifdef _SYNTAX_CHECK
111 //if reached end of string
112 //it is an error becuase we do not yet have prompt
113 if ( *param == 0)
114 {
115 error_req_param_missing ();
116 return 1;
117 }
118 #endif
119
120 //search for "title"
121 tmp = param;
122
123 if(*param == '"')
124 {
125 tmp = _tcschr(param+1,'"');
126 if (tmp)
127 {
128 *tmp = 0;
129 title = param+1;
130 tmp++;
131 param = tmp;
132 }
133 }
134
135 //skip spaces
136 while(_istspace(*param))
137 param++;
138 #ifdef _SYNTAX_CHECK
139 //get prompt
140 if ( *param == 0)
141 {
142 error_req_param_missing ();
143 return 1;
144 }
145 #endif
146
147 prompt = param;
148
149 hWnd=GetConsoleWindow ();
150 // DebugPrintf("FindWindow hWnd = %d\n",hWnd);
151 ConErrPrintf("FindWindow hWnd = %d\n",hWnd);
152
153 switch (
154 MessageBox(hWnd,prompt,title,uType)
155 )
156 {
157 case IDYES:
158 case IDOK:
159 nErrorLevel = 10;
160 break;
161
162 case IDNO:
163 nErrorLevel = 11;
164 break;
165
166 case IDCANCEL:
167 nErrorLevel = 12;
168 break;
169 }
170
171 return 0;
172 }
173
174 #endif /* INCLUDE_CMD_MSGBOX */