Changeset 32205 in vbox for trunk/src/VBox
- Timestamp:
- Sep 2, 2010 2:10:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp
r32201 r32205 66 66 67 67 /** Enumerate the different parts of the usage we might want to print out */ 68 enum g_eUsage68 enum VBoxControlUsage 69 69 { 70 70 #ifdef RT_OS_WINDOWS … … 85 85 }; 86 86 87 static void usage( g_eUsage eWhich = USAGE_ALL)87 static void usage(enum VBoxControlUsage eWhich = USAGE_ALL) 88 88 { 89 89 RTPrintf("Usage:\n\n"); … … 131 131 * Displays an error message. 132 132 * 133 * @param pszFormat The message text. 133 * @returns RTEXITCODE_FAILURE. 134 * @param pszFormat The message text. No newline. 134 135 * @param ... Format arguments. 135 136 */ 136 static void VBoxControlError(const char *pszFormat, ...) 137 { 138 // RTStrmPrintf(g_pStdErr, "%s: error: ", g_pszProgName); 139 137 static RTEXITCODE VBoxControlError(const char *pszFormat, ...) 138 { 140 139 va_list va; 141 140 va_start(va, pszFormat); 142 RT StrmPrintfV(g_pStdErr,pszFormat, va);141 RTMsgErrorV(pszFormat, va); 143 142 va_end(va); 143 return RTEXITCODE_FAILURE; 144 } 145 146 147 /** 148 * Displays an syntax error message. 149 * 150 * @returns RTEXITCODE_FAILURE. 151 * @param pszFormat The message text. No newline. 152 * @param ... Format arguments. 153 */ 154 static RTEXITCODE VBoxControlSyntaxError(const char *pszFormat, ...) 155 { 156 va_list va; 157 va_start(va, pszFormat); 158 RTMsgErrorV(pszFormat, va); 159 va_end(va); 160 return RTEXITCODE_FAILURE; 144 161 } 145 162 … … 805 822 || (bpp != 32))) 806 823 { 807 VBoxControlError(" Error:invalid mode specified!\n");824 VBoxControlError("invalid mode specified!\n"); 808 825 return RTEXITCODE_FAILURE; 809 826 } … … 1349 1366 * @returns 0 on success, 1 on failure 1350 1367 * @note see the command line API description for parameters 1368 * (r=bird: yeah, right. The API description contains nil about params) 1351 1369 */ 1352 1370 static RTEXITCODE handleSharedFolder(int argc, char *argv[]) … … 1364 1382 } 1365 1383 #endif 1384 1385 static RTEXITCODE handleVersion(int argc, char *argv[]) 1386 { 1387 if (argc) 1388 return VBoxControlSyntaxError("getversion does not take any arguments"); 1389 RTPrintf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision()); 1390 return RTEXITCODE_SUCCESS; 1391 } 1392 1393 static RTEXITCODE handleHelp(int argc, char *argv[]) 1394 { 1395 /* ignore arguments for now. */ 1396 usage(); 1397 return RTEXITCODE_SUCCESS; 1398 } 1366 1399 1367 1400 /** command handler type */ … … 1390 1423 { "sharedfolder", handleSharedFolder }, 1391 1424 #endif 1392 { NULL, NULL } /* unnecessary terminator entry */ 1425 { "getversion", handleVersion }, 1426 { "version", handleVersion }, 1427 { "help", handleHelp } 1393 1428 }; 1394 1429 … … 1424 1459 || !strcmp(argv[iArg], "--version") 1425 1460 || !strcmp(argv[iArg], "-version") 1426 || !strcmp(argv[iArg], "getversion")1427 1461 ) 1428 1462 { … … 1501 1535 if (argc > iArg) 1502 1536 { 1503 /** Is next parameter a known command? */ 1504 bool found = false; 1505 /** And if so, what is its position in the table? */ 1506 unsigned index = 0; 1507 while ( index < RT_ELEMENTS(g_aCommandHandlers) 1508 && !found 1509 && (g_aCommandHandlers[index].pszCommand != NULL)) 1510 { 1511 if (!strcmp(argv[iArg], g_aCommandHandlers[index].pszCommand)) 1512 found = true; 1513 else 1514 ++index; 1515 } 1516 if (found) 1517 rcExit = g_aCommandHandlers[index].pfnHandler(argc - iArg - 1, argv + iArg + 1); 1518 else 1537 /* 1538 * Try locate the command and execute it, complain if not found. 1539 */ 1540 unsigned i; 1541 for (i = 0; i < RT_ELEMENTS(g_aCommandHandlers); i++) 1542 if (!strcmp(argv[iArg], g_aCommandHandlers[i].pszCommand)) 1543 { 1544 rcExit = g_aCommandHandlers[i].pfnHandler(argc - iArg - 1, argv + iArg + 1); 1545 break; 1546 } 1547 if (i >= RT_ELEMENTS(g_aCommandHandlers)) 1519 1548 { 1520 1549 rcExit = RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.