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