|
|
1.1.1.10 root 1: /*
1.1.1.12 root 2: Legal Notice: Some portions of the source code contained in this file were
3: derived from the source code of Encryption for the Masses 2.02a, which is
4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
5: Agreement for Encryption for the Masses'. Modifications and additions to
6: the original source code (contained in this file) and all other portions of
1.1.1.16! root 7: this file are Copyright (c) 2003-2009 TrueCrypt Foundation and are governed
! 8: by the TrueCrypt License 2.8 the full text of which is contained in the
1.1.1.12 root 9: file License.txt included in TrueCrypt binary and source code distribution
1.1.1.10 root 10: packages. */
1.1 root 11:
1.1.1.6 root 12: #include "Tcdefs.h"
1.1 root 13:
14: #include <malloc.h>
15: #include <ctype.h>
1.1.1.6 root 16: #include "Cmdline.h"
1.1 root 17:
1.1.1.6 root 18: #include "Resource.h"
19: #include "Crypto.h"
20: #include "Apidrvr.h"
21: #include "Dlgcode.h"
22: #include "Language.h"
1.1 root 23:
24: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
25: should return nonzero if it processes the message, and zero if it does
26: not. - see DialogProc */
1.1.1.14 root 27: BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1 root 28: {
29: if (lParam); /* remove warning */
30: if (wParam); /* remove warning */
31:
32: switch (msg)
33: {
34: case WM_INITDIALOG:
35: {
36: char * tmp = err_malloc(8192);
1.1.1.7 root 37: char tmp2[MAX_PATH * 2];
1.1 root 38: argumentspec *as;
39: int i;
40:
1.1.1.6 root 41: LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
1.1 root 42:
43: as = (argumentspec*) lParam;
44:
45: *tmp = 0;
46:
1.1.1.4 root 47: strcpy (tmp, "Command line options:\n\n");
1.1 root 48: for (i = 0; i < as->arg_cnt; i ++)
49: {
1.1.1.14 root 50: if (!as->args[i].Internal)
51: {
52: sprintf(tmp2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
53: strcat(tmp,tmp2);
54: }
1.1 root 55: }
56:
57: SetWindowText (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), (char*) tmp);
58: return 1;
59: }
60:
61: case WM_COMMAND:
62: EndDialog (hwndDlg, IDOK);
63: return 1;
64: case WM_CLOSE:
65: EndDialog (hwndDlg, 0);
66: return 1;
67: }
68:
69: return 0;
70: }
71:
1.1.1.14 root 72: int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
1.1 root 73: {
1.1.1.16! root 74: int argumentCount;
! 75: int i;
1.1 root 76:
1.1.1.16! root 77: LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
! 78: if (!arguments)
! 79: {
! 80: handleWin32Error (NULL);
! 81: return 0;
! 82: }
1.1 root 83:
1.1.1.16! root 84: --argumentCount;
! 85: if (argumentCount < 1)
! 86: {
! 87: LocalFree (arguments);
1.1 root 88: return 0;
1.1.1.16! root 89: }
! 90:
! 91: *lpszArgs = malloc (sizeof (char *) * argumentCount);
! 92: if (!*lpszArgs)
! 93: AbortProcess ("OUTOFMEMORY");
1.1 root 94:
1.1.1.16! root 95: for (i = 0; i < argumentCount; ++i)
1.1 root 96: {
1.1.1.16! root 97: size_t argLen = wcslen (arguments[i + 1]);
1.1 root 98:
1.1.1.16! root 99: char *arg = malloc (argLen + 1);
! 100: if (!arg)
! 101: AbortProcess ("OUTOFMEMORY");
! 102:
! 103: if (argLen > 0)
1.1 root 104: {
1.1.1.16! root 105: int len = WideCharToMultiByte (CP_ACP, 0, arguments[i + 1], -1, arg, argLen + 1, NULL, NULL);
! 106: if (len == 0)
1.1 root 107: {
1.1.1.16! root 108: handleWin32Error (NULL);
! 109: AbortProcessSilent();
1.1 root 110: }
111: }
1.1.1.16! root 112: else
! 113: arg[0] = 0;
1.1 root 114:
1.1.1.16! root 115: (*lpszArgs)[i] = arg;
1.1 root 116: }
117:
1.1.1.16! root 118: LocalFree (arguments);
! 119: return argumentCount;
1.1 root 120: }
121:
1.1.1.14 root 122: int GetArgSepPosOffset (char *lpszArgument)
1.1 root 123: {
124: if (lpszArgument[0] == '/')
125: return 1;
126: else if (lpszArgument[0] == '-' && lpszArgument[1] == '-')
127: return 2;
128: else if (lpszArgument[0] == '-')
129: return 1;
130: else
131: return 0;
132: }
133:
1.1.1.14 root 134: int GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
1.1 root 135: {
1.1.1.7 root 136: char szTmp[MAX_PATH * 2];
1.1 root 137: int i;
138:
139: i = strlen (lpszArgument);
140: szTmp[i] = 0;
141: while (--i >= 0)
142: {
143: szTmp[i] = (char) tolower (lpszArgument[i]);
144: }
145:
146: for (i = 0; i < as->arg_cnt; i++)
147: {
148: size_t k;
149:
150: k = strlen (as->args[i].long_name);
151: if (memcmp (as->args[i].long_name, szTmp, k * sizeof (char)) == 0)
152: {
153: int x;
154: for (x = i + 1; x < as->arg_cnt; x++)
155: {
156: size_t m;
157:
158: m = strlen (as->args[x].long_name);
159: if (memcmp (as->args[x].long_name, szTmp, m * sizeof (char)) == 0)
160: {
161: break;
162: }
163: }
164:
165: if (x == as->arg_cnt)
166: {
167: if (strlen (lpszArgument) != k)
168: *nArgPos = k;
169: else
170: *nArgPos = 0;
1.1.1.14 root 171: return as->args[i].Id;
1.1 root 172: }
173: }
174: }
175:
176: for (i = 0; i < as->arg_cnt; i++)
177: {
178: size_t k;
179:
1.1.1.14 root 180: if (as->args[i].short_name[0] == 0)
181: continue;
182:
1.1 root 183: k = strlen (as->args[i].short_name);
184: if (memcmp (as->args[i].short_name, szTmp, k * sizeof (char)) == 0)
185: {
186: int x;
187: for (x = i + 1; x < as->arg_cnt; x++)
188: {
189: size_t m;
190:
1.1.1.14 root 191: if (as->args[x].short_name[0] == 0)
192: continue;
193:
1.1 root 194: m = strlen (as->args[x].short_name);
195: if (memcmp (as->args[x].short_name, szTmp, m * sizeof (char)) == 0)
196: {
197: break;
198: }
199: }
200:
201: if (x == as->arg_cnt)
202: {
203: if (strlen (lpszArgument) != k)
204: *nArgPos = k;
205: else
206: *nArgPos = 0;
1.1.1.14 root 207: return as->args[i].Id;
1.1 root 208: }
209: }
210: }
211:
212:
213: return -1;
214: }
215:
1.1.1.14 root 216: int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
1.1 root 217: int nNoCommandLineArgs, char *lpszValue, int nValueSize)
218: {
219: *lpszValue = 0;
220:
221: if (nArgPos)
222: {
223: /* Handles the case of no space between parameter code and
224: value */
1.1.1.5 root 225: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize);
1.1 root 226: lpszValue[nValueSize - 1] = 0;
227: return HAS_ARGUMENT;
228: }
1.1.1.5 root 229: else if (*nArgIdx + 1 < nNoCommandLineArgs)
1.1 root 230: {
231: int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
232: if (x == 0)
233: {
234: /* Handles the case of space between parameter code
235: and value */
1.1.1.5 root 236: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize);
1.1 root 237: lpszValue[nValueSize - 1] = 0;
238: (*nArgIdx)++;
239: return HAS_ARGUMENT;
240: }
241: }
242:
243: return HAS_NO_ARGUMENT;
244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.