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