|
|
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
7: this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
1.1.1.14! root 8: by the TrueCrypt License 2.6 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: {
74: int i = 0, k = 0, x = 0, nValid = TRUE;
75: int nLen = strlen (lpszCommandLine);
1.1.1.14! root 76: int nArrSize = 1024;
1.1.1.7 root 77: char szTmp[MAX_PATH * 2];
1.1 root 78:
79: *lpszArgs = malloc (sizeof (char *)* nArrSize);
80:
81: if (*lpszArgs == NULL)
82: return 0;
83:
84: while (i < nLen)
85: {
86: if (lpszCommandLine[i] == ' ')
87: {
88: if (k > 0)
89: {
90: szTmp[k] = 0;
91: (*lpszArgs)[x] = _strdup (szTmp);
92: if ((*lpszArgs)[x] == NULL)
93: {
94: free (*lpszArgs);
95: return 0;
96: }
97: x++;
98: k = 0;
99: if (x == nArrSize)
100: {
101: break;
102: }
103: }
104: i++;
105: continue;
106: }
107: if (lpszCommandLine[i] == '"')
108: {
109: i++;
110: while (i < nLen)
111: {
112: if (lpszCommandLine[i] == '"')
113: break;
114: if (k < sizeof (szTmp))
115: szTmp[k++] = lpszCommandLine[i++];
116: else
117: {
118: free (*lpszArgs);
119: return 0;
120: }
121: }
122:
123: if (lpszCommandLine[i] != '"')
124: {
125: nValid = FALSE;
126: break;
127: }
128: }
129: else
130: {
131: if (k < sizeof (szTmp))
132: szTmp[k++] = lpszCommandLine[i];
133: else
134: {
135: free (*lpszArgs);
136: return 0;
137: }
138: }
139:
140: i++;
141: }
142:
143: if (nValid == FALSE)
144: {
145: free (*lpszArgs);
146: return 0;
147: }
148: else if (k > 0)
149: {
150: szTmp[k] = 0;
151: (*lpszArgs)[x] = _strdup (szTmp);
152: if ((*lpszArgs)[x] == NULL)
153: {
154: free (*lpszArgs);
155: return 0;
156: }
157: x++;
158: k = 0;
159: }
160: if (!x)
161: {
162: free (*lpszArgs);
163: return 0;
164: }
165: return x;
166: }
167:
1.1.1.14! root 168: int GetArgSepPosOffset (char *lpszArgument)
1.1 root 169: {
170: if (lpszArgument[0] == '/')
171: return 1;
172: else if (lpszArgument[0] == '-' && lpszArgument[1] == '-')
173: return 2;
174: else if (lpszArgument[0] == '-')
175: return 1;
176: else
177: return 0;
178: }
179:
1.1.1.14! root 180: int GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
1.1 root 181: {
1.1.1.7 root 182: char szTmp[MAX_PATH * 2];
1.1 root 183: int i;
184:
185: i = strlen (lpszArgument);
186: szTmp[i] = 0;
187: while (--i >= 0)
188: {
189: szTmp[i] = (char) tolower (lpszArgument[i]);
190: }
191:
192: for (i = 0; i < as->arg_cnt; i++)
193: {
194: size_t k;
195:
196: k = strlen (as->args[i].long_name);
197: if (memcmp (as->args[i].long_name, szTmp, k * sizeof (char)) == 0)
198: {
199: int x;
200: for (x = i + 1; x < as->arg_cnt; x++)
201: {
202: size_t m;
203:
204: m = strlen (as->args[x].long_name);
205: if (memcmp (as->args[x].long_name, szTmp, m * sizeof (char)) == 0)
206: {
207: break;
208: }
209: }
210:
211: if (x == as->arg_cnt)
212: {
213: if (strlen (lpszArgument) != k)
214: *nArgPos = k;
215: else
216: *nArgPos = 0;
1.1.1.14! root 217: return as->args[i].Id;
1.1 root 218: }
219: }
220: }
221:
222: for (i = 0; i < as->arg_cnt; i++)
223: {
224: size_t k;
225:
1.1.1.14! root 226: if (as->args[i].short_name[0] == 0)
! 227: continue;
! 228:
1.1 root 229: k = strlen (as->args[i].short_name);
230: if (memcmp (as->args[i].short_name, szTmp, k * sizeof (char)) == 0)
231: {
232: int x;
233: for (x = i + 1; x < as->arg_cnt; x++)
234: {
235: size_t m;
236:
1.1.1.14! root 237: if (as->args[x].short_name[0] == 0)
! 238: continue;
! 239:
1.1 root 240: m = strlen (as->args[x].short_name);
241: if (memcmp (as->args[x].short_name, szTmp, m * sizeof (char)) == 0)
242: {
243: break;
244: }
245: }
246:
247: if (x == as->arg_cnt)
248: {
249: if (strlen (lpszArgument) != k)
250: *nArgPos = k;
251: else
252: *nArgPos = 0;
1.1.1.14! root 253: return as->args[i].Id;
1.1 root 254: }
255: }
256: }
257:
258:
259: return -1;
260: }
261:
1.1.1.14! root 262: int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
1.1 root 263: int nNoCommandLineArgs, char *lpszValue, int nValueSize)
264: {
265: *lpszValue = 0;
266:
267: if (nArgPos)
268: {
269: /* Handles the case of no space between parameter code and
270: value */
1.1.1.5 root 271: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize);
1.1 root 272: lpszValue[nValueSize - 1] = 0;
273: return HAS_ARGUMENT;
274: }
1.1.1.5 root 275: else if (*nArgIdx + 1 < nNoCommandLineArgs)
1.1 root 276: {
277: int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
278: if (x == 0)
279: {
280: /* Handles the case of space between parameter code
281: and value */
1.1.1.5 root 282: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize);
1.1 root 283: lpszValue[nValueSize - 1] = 0;
284: (*nArgIdx)++;
285: return HAS_ARGUMENT;
286: }
287: }
288:
289: return HAS_NO_ARGUMENT;
290: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.