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