Changeset 54580 in vbox for trunk/src/VBox
- Timestamp:
- Mar 2, 2015 2:52:24 PM (10 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxControl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp
r54520 r54580 22 22 #include <iprt/cpp/autores.h> 23 23 #include <iprt/buildconfig.h> 24 #include <iprt/getopt.h> 24 25 #include <iprt/initterm.h> 25 26 #include <iprt/mem.h> … … 91 92 WRITE_CORE_DUMP, 92 93 #endif 94 WRITE_LOG, 93 95 TAKE_SNAPSHOT, 94 96 SAVE_STATE, … … 100 102 }; 101 103 102 static voidusage(enum VBoxControlUsage eWhich = USAGE_ALL)104 static RTEXITCODE usage(enum VBoxControlUsage eWhich = USAGE_ALL) 103 105 { 104 106 RTPrintf("Usage:\n\n"); … … 148 150 doUsage("", g_pszProgName, "writecoredump"); 149 151 #endif 152 if (eWhich == WRITE_LOG || eWhich == USAGE_ALL) 153 doUsage("", g_pszProgName, "writelog [--] <msg>"); 150 154 if (eWhich == TAKE_SNAPSHOT || eWhich == USAGE_ALL) 151 155 doUsage("", g_pszProgName, "takesnapshot"); … … 160 164 if (eWhich == VERSION || eWhich == USAGE_ALL) 161 165 doUsage("", g_pszProgName, "version"); 166 167 return RTEXITCODE_SUCCESS; 162 168 } 163 169 164 170 /** @} */ 171 172 173 /** 174 * Implementation of the '--version' option. 175 * 176 * @returns RTEXITCODE_SUCCESS 177 */ 178 static RTEXITCODE printVersion(void) 179 { 180 RTPrintf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision()); 181 return RTEXITCODE_SUCCESS; 182 } 183 165 184 166 185 /** … … 173 192 static RTEXITCODE VBoxControlError(const char *pszFormat, ...) 174 193 { 194 /** @todo prefix with current command. */ 175 195 va_list va; 176 196 va_start(va, pszFormat); … … 182 202 183 203 /** 204 * Displays a getopt error. 205 * 206 * @returns RTEXITCODE_FAILURE. 207 * @param ch The RTGetOpt return value. 208 * @param pValueUnion The RTGetOpt return data. 209 */ 210 static RTEXITCODE VBoxCtrlGetOptError(int ch, PCRTGETOPTUNION pValueUnion) 211 { 212 /** @todo prefix with current command. */ 213 return RTGetOptPrintError(ch, pValueUnion); 214 } 215 216 217 /** 184 218 * Displays an syntax error message. 185 219 * … … 190 224 static RTEXITCODE VBoxControlSyntaxError(const char *pszFormat, ...) 191 225 { 226 /** @todo prefix with current command. */ 192 227 va_list va; 193 228 va_start(va, pszFormat); … … 1724 1759 1725 1760 /** 1761 * @callback_method_impl{FNVBOXCTRLCMDHANDLER, Command: writelog} 1762 */ 1763 static RTEXITCODE handleWriteLog(int argc, char *argv[]) 1764 { 1765 static const RTGETOPTDEF s_aOptions[] = 1766 { 1767 { "--dummy", 'D', RTGETOPT_REQ_NOTHING } 1768 }; 1769 1770 RTGETOPTSTATE GetOptState; 1771 int rc = RTGetOptInit(&GetOptState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1772 0 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1773 if (RT_SUCCESS(rc)) 1774 { 1775 RTGETOPTUNION ValueUnion; 1776 int ch; 1777 while ((ch == RTGetOpt(&GetOptState, &ValueUnion)) != 0) 1778 { 1779 switch (ch) 1780 { 1781 case VINF_GETOPT_NOT_OPTION: 1782 rc = VbglR3WriteLog(ValueUnion.psz, strlen(ValueUnion.psz)); 1783 if (RT_FAILURE(rc)) 1784 return VBoxControlError("VbglR3WriteLog: %Rrc", rc); 1785 break; 1786 1787 case 'h': return usage(WRITE_LOG); 1788 case 'V': return printVersion(); 1789 default: 1790 return VBoxCtrlGetOptError(ch, &ValueUnion); 1791 } 1792 } 1793 } 1794 else 1795 return VBoxControlError("RTGetOptInit: %Rrc", rc); 1796 return RTEXITCODE_SUCCESS; 1797 } 1798 1799 1800 /** 1726 1801 * @callback_method_impl{FNVBOXCTRLCMDHANDLER, Command: takesnapshot} 1727 1802 */ … … 1766 1841 if (argc) 1767 1842 return VBoxControlSyntaxError("getversion does not take any arguments"); 1768 RTPrintf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision()); 1769 return RTEXITCODE_SUCCESS; 1843 return printVersion(); 1770 1844 } 1771 1845 … … 1813 1887 { "dpc", handleDpc }, 1814 1888 #endif 1889 { "writelog", handleWriteLog }, 1815 1890 { "takesnapshot", handleTakeSnapshot }, 1816 1891 { "savestate", handleSaveState }, … … 1858 1933 { 1859 1934 /* Print version number, and do nothing else. */ 1860 RTPrintf("%sr%u\n", VBOX_VERSION_STRING, RTBldCfgRevision());1935 printVersion(); 1861 1936 fOnlyInfo = true; 1862 1937 fShowLogo = false; -
trunk/src/VBox/Additions/common/VBoxControl/testcase/tstVBoxControl.cpp
r44324 r54580 200 200 201 201 #endif 202 203 VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cch) 204 { 205 NOREF(pch); NOREF(cch); 206 return VINF_SUCCESS; 207 } 208
Note:
See TracChangeset
for help on using the changeset viewer.