|
|
1.1.1.10 root 1: /*
2: Legal Notice: The source code contained in this file has been derived from
3: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
4: Paul Le Roux and which is covered by the 'License Agreement for Encryption
5: for the Masses'. Modifications and additions to that source code contained
6: in this file are Copyright (c) TrueCrypt Foundation and are covered by the
1.1.1.11! root 7: TrueCrypt License 2.3 the full text of which is contained in the file
1.1.1.10 root 8: License.txt included in TrueCrypt binary and source code distribution
9: packages. */
1.1 root 10:
1.1.1.6 root 11: #include "Tcdefs.h"
1.1 root 12:
13: #include <malloc.h>
14: #include <ctype.h>
1.1.1.6 root 15: #include "Cmdline.h"
1.1 root 16:
1.1.1.6 root 17: #include "Resource.h"
18: #include "Crypto.h"
19: #include "Apidrvr.h"
20: #include "Dlgcode.h"
21: #include "Language.h"
1.1 root 22:
23: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
24: should return nonzero if it processes the message, and zero if it does
25: not. - see DialogProc */
1.1.1.11! root 26: BOOL CALLBACK
1.1 root 27: CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
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.4 root 50: sprintf(tmp2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
1.1 root 51: strcat(tmp,tmp2);
52: }
53:
54: SetWindowText (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), (char*) tmp);
55: return 1;
56: }
57:
58: case WM_COMMAND:
59: EndDialog (hwndDlg, IDOK);
60: return 1;
61: case WM_CLOSE:
62: EndDialog (hwndDlg, 0);
63: return 1;
64: }
65:
66: return 0;
67: }
68:
69: int
70: Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
71: {
72: int i = 0, k = 0, x = 0, nValid = TRUE;
73: int nLen = strlen (lpszCommandLine);
74: int nArrSize = 16;
1.1.1.7 root 75: char szTmp[MAX_PATH * 2];
1.1 root 76:
77: *lpszArgs = malloc (sizeof (char *)* nArrSize);
78:
79: if (*lpszArgs == NULL)
80: return 0;
81:
82: while (i < nLen)
83: {
84: if (lpszCommandLine[i] == ' ')
85: {
86: if (k > 0)
87: {
88: szTmp[k] = 0;
89: (*lpszArgs)[x] = _strdup (szTmp);
90: if ((*lpszArgs)[x] == NULL)
91: {
92: free (*lpszArgs);
93: return 0;
94: }
95: x++;
96: k = 0;
97: if (x == nArrSize)
98: {
99: break;
100: }
101: }
102: i++;
103: continue;
104: }
105: if (lpszCommandLine[i] == '"')
106: {
107: i++;
108: while (i < nLen)
109: {
110: if (lpszCommandLine[i] == '"')
111: break;
112: if (k < sizeof (szTmp))
113: szTmp[k++] = lpszCommandLine[i++];
114: else
115: {
116: free (*lpszArgs);
117: return 0;
118: }
119: }
120:
121: if (lpszCommandLine[i] != '"')
122: {
123: nValid = FALSE;
124: break;
125: }
126: }
127: else
128: {
129: if (k < sizeof (szTmp))
130: szTmp[k++] = lpszCommandLine[i];
131: else
132: {
133: free (*lpszArgs);
134: return 0;
135: }
136: }
137:
138: i++;
139: }
140:
141: if (nValid == FALSE)
142: {
143: free (*lpszArgs);
144: return 0;
145: }
146: else if (k > 0)
147: {
148: szTmp[k] = 0;
149: (*lpszArgs)[x] = _strdup (szTmp);
150: if ((*lpszArgs)[x] == NULL)
151: {
152: free (*lpszArgs);
153: return 0;
154: }
155: x++;
156: k = 0;
157: }
158: if (!x)
159: {
160: free (*lpszArgs);
161: return 0;
162: }
163: return x;
164: }
165:
166: int
167: GetArgSepPosOffset (char *lpszArgument)
168: {
169: if (lpszArgument[0] == '/')
170: return 1;
171: else if (lpszArgument[0] == '-' && lpszArgument[1] == '-')
172: return 2;
173: else if (lpszArgument[0] == '-')
174: return 1;
175: else
176: return 0;
177: }
178:
179: int
180: GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
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;
217: return as->args[i].short_name[1];
218: }
219: }
220: }
221:
222: for (i = 0; i < as->arg_cnt; i++)
223: {
224: size_t k;
225:
226: k = strlen (as->args[i].short_name);
227: if (memcmp (as->args[i].short_name, szTmp, k * sizeof (char)) == 0)
228: {
229: int x;
230: for (x = i + 1; x < as->arg_cnt; x++)
231: {
232: size_t m;
233:
234: m = strlen (as->args[x].short_name);
235: if (memcmp (as->args[x].short_name, szTmp, m * sizeof (char)) == 0)
236: {
237: break;
238: }
239: }
240:
241: if (x == as->arg_cnt)
242: {
243: if (strlen (lpszArgument) != k)
244: *nArgPos = k;
245: else
246: *nArgPos = 0;
247: return as->args[i].short_name[1];
248: }
249: }
250: }
251:
252:
253: return -1;
254: }
255:
256: int
257: GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
258: int nNoCommandLineArgs, char *lpszValue, int nValueSize)
259: {
260: *lpszValue = 0;
261:
262: if (nArgPos)
263: {
264: /* Handles the case of no space between parameter code and
265: value */
1.1.1.5 root 266: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize);
1.1 root 267: lpszValue[nValueSize - 1] = 0;
268: return HAS_ARGUMENT;
269: }
1.1.1.5 root 270: else if (*nArgIdx + 1 < nNoCommandLineArgs)
1.1 root 271: {
272: int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
273: if (x == 0)
274: {
275: /* Handles the case of space between parameter code
276: and value */
1.1.1.5 root 277: strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize);
1.1 root 278: lpszValue[nValueSize - 1] = 0;
279: (*nArgIdx)++;
280: return HAS_ARGUMENT;
281: }
282: }
283:
284: return HAS_NO_ARGUMENT;
285: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.