|
|
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
1.1.1.17 root 6: the original source code (contained in this file) and all other portions
7: of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
1.1.1.18 root 8: and are governed by the TrueCrypt License 3.0 the full text of which is
1.1.1.17 root 9: contained in the file License.txt included in TrueCrypt binary and source
10: code distribution 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;
1.1.1.19! root 126:
! 127: return 0;
1.1 root 128: }
129:
1.1.1.14 root 130: int GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
1.1 root 131: {
1.1.1.7 root 132: char szTmp[MAX_PATH * 2];
1.1 root 133: int i;
134:
135: i = strlen (lpszArgument);
136: szTmp[i] = 0;
137: while (--i >= 0)
138: {
139: szTmp[i] = (char) tolower (lpszArgument[i]);
140: }
141:
142: for (i = 0; i < as->arg_cnt; i++)
143: {
144: size_t k;
145:
146: k = strlen (as->args[i].long_name);
147: if (memcmp (as->args[i].long_name, szTmp, k * sizeof (char)) == 0)
148: {
149: int x;
150: for (x = i + 1; x < as->arg_cnt; x++)
151: {
152: size_t m;
153:
154: m = strlen (as->args[x].long_name);
155: if (memcmp (as->args[x].long_name, szTmp, m * sizeof (char)) == 0)
156: {
157: break;
158: }
159: }
160:
161: if (x == as->arg_cnt)
162: {
163: if (strlen (lpszArgument) != k)
164: *nArgPos = k;
165: else
166: *nArgPos = 0;
1.1.1.14 root 167: return as->args[i].Id;
1.1 root 168: }
169: }
170: }
171:
172: for (i = 0; i < as->arg_cnt; i++)
173: {
174: size_t k;
175:
1.1.1.14 root 176: if (as->args[i].short_name[0] == 0)
177: continue;
178:
1.1 root 179: k = strlen (as->args[i].short_name);
180: if (memcmp (as->args[i].short_name, szTmp, k * sizeof (char)) == 0)
181: {
182: int x;
183: for (x = i + 1; x < as->arg_cnt; x++)
184: {
185: size_t m;
186:
1.1.1.14 root 187: if (as->args[x].short_name[0] == 0)
188: continue;
189:
1.1 root 190: m = strlen (as->args[x].short_name);
191: if (memcmp (as->args[x].short_name, szTmp, m * sizeof (char)) == 0)
192: {
193: break;
194: }
195: }
196:
197: if (x == as->arg_cnt)
198: {
199: if (strlen (lpszArgument) != k)
200: *nArgPos = k;
201: else
202: *nArgPos = 0;
1.1.1.14 root 203: return as->args[i].Id;
1.1 root 204: }
205: }
206: }
207:
208:
209: return -1;
210: }
211:
1.1.1.14 root 212: int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
1.1 root 213: int nNoCommandLineArgs, char *lpszValue, int nValueSize)
214: {
215: *lpszValue = 0;
216:
217: if (nArgPos)
218: {
219: /* Handles the case of no space between parameter code and
220: value */
1.1.1.5 root 221: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize);
1.1 root 222: lpszValue[nValueSize - 1] = 0;
223: return HAS_ARGUMENT;
224: }
1.1.1.5 root 225: else if (*nArgIdx + 1 < nNoCommandLineArgs)
1.1 root 226: {
227: int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
228: if (x == 0)
229: {
230: /* Handles the case of space between parameter code
231: and value */
1.1.1.5 root 232: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize);
1.1 root 233: lpszValue[nValueSize - 1] = 0;
234: (*nArgIdx)++;
235: return HAS_ARGUMENT;
236: }
237: }
238:
239: return HAS_NO_ARGUMENT;
240: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.