Skip to content

Commit 39fa0a6

Browse files
committed
added vrs tool supporting UTF characters
1 parent 54fd248 commit 39fa0a6

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

tools/vrs/VrsCommand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ VrsCommand::VrsCommand() {
293293
}
294294
}
295295

296-
bool VrsCommand::parseCommand(const std::string& appName, const char* cmdName) {
297-
cmd = CommandConverter::toEnum(cmdName);
296+
bool VrsCommand::parseCommand(const std::string& appName, const std::string cmdName) {
297+
cmd = CommandConverter::toEnum(cmdName.c_str());
298298
if (cmd != Command::None) {
299299
return XR_VERIFY(getCommandSpec(cmd).cmd == cmd);
300300
}
@@ -310,7 +310,7 @@ bool VrsCommand::parseArgument(
310310
const string& appName,
311311
int& argn,
312312
int argc,
313-
char** argv,
313+
std::vector<std::string> argv,
314314
int& outStatusCode) {
315315
string arg = argv[argn];
316316
if (arg == "-to" || arg == "--to") {

tools/vrs/VrsCommand.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum class Command {
6161
struct VrsCommand {
6262
VrsCommand();
6363

64-
bool parseCommand(const std::string& appName, const char* cmdName);
64+
bool parseCommand(const std::string& appName, const std::string cmdName);
6565

6666
/// Parse a "logical" command line argument, which may have one or more parts.
6767
/// @param appName: Name of the application binary for error messages
@@ -78,8 +78,12 @@ struct VrsCommand {
7878
/// On the other hand, if the argument and possible sub-arguments were valid,
7979
/// outStatusCode is unchanged (presumably, it's still set to EXIT_SUCCESS),
8080
/// and the next argument parameter to parse is at argn + 1.
81-
bool
82-
parseArgument(const std::string& appName, int& argn, int argc, char** argv, int& outStatusCode);
81+
bool parseArgument(
82+
const std::string& appName,
83+
int& argn,
84+
int argc,
85+
std::vector<std::string> argv,
86+
int& outStatusCode);
8387

8488
/// Handle a parameter not recognized by parseArgument and potential additional parsing.
8589
/// Unrecognized arguments are expected to be additional file paths for merge operations.

tools/vrs/vrs.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,39 @@
1818

1919
#include <iostream>
2020

21+
#include <Windows.h>
2122
#include <vrs/os/Utils.h>
2223

24+
namespace {
25+
26+
inline std::vector<std::string> compute_win32_argv() {
27+
std::vector<std::string> result;
28+
int argc = 0;
29+
30+
auto deleter = [](wchar_t** ptr) { LocalFree(ptr); };
31+
// NOLINTBEGIN(*-avoid-c-arrays)
32+
auto wargv = std::unique_ptr<wchar_t*[], decltype(deleter)>(
33+
CommandLineToArgvW(GetCommandLineW(), &argc), deleter);
34+
// NOLINTEND(*-avoid-c-arrays)
35+
36+
if (wargv == nullptr) {
37+
throw std::runtime_error(
38+
"CommandLineToArgvW failed with code " + std::to_string(GetLastError()));
39+
}
40+
41+
result.reserve(static_cast<size_t>(argc));
42+
for (size_t i = 0; i < static_cast<size_t>(argc); ++i) {
43+
result.push_back(vrs::os::osWstringtoUtf8(wargv[i]));
44+
}
45+
46+
return result;
47+
}
48+
} // namespace
49+
2350
using namespace std;
2451

25-
int main(int argc, char** argv) {
52+
int main(int argc, char** argv_old) {
53+
auto argv = compute_win32_argv();
2654
const string& appName = vrs::os::getFilename(argv[0]);
2755
if (argc == 1) {
2856
printHelp(appName);

vrs/os/Utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
namespace vrs {
3535
namespace os {
3636

37+
#if IS_WINDOWS_PLATFORM()
38+
std::wstring osUtf8ToWstring(const std::string& utf8String);
39+
std::string osWstringtoUtf8(const std::wstring& wstring);
40+
#endif // IS_WINDOWS_PLATFORM()
41+
3742
/// FILE helpers
3843
std::FILE* fileOpen(const std::string& path, const char* modes);
3944
int fileClose(std::FILE* file);

vrs/utils/cli/CliParsing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool parseCopyOptions(
3838
const string& arg,
3939
int& argn,
4040
int argc,
41-
char** argv,
41+
std::vector<std::string> argv,
4242
int& outStatusCode,
4343
CopyOptions& copyOptions) {
4444
if (arg == "--no-progress") {
@@ -116,7 +116,7 @@ bool parseTagOverrideOptions(
116116
const string& arg,
117117
int& argn,
118118
int argc,
119-
char** argv,
119+
std::vector<std::string> argv,
120120
int& outStatusCode,
121121
CopyOptions& copyOptions) {
122122
if (arg == "--file-tag") {
@@ -174,7 +174,7 @@ bool parseTimeAndStreamFilters(
174174
const string& arg,
175175
int& argn,
176176
int argc,
177-
char** argv,
177+
std::vector<std::string> argv,
178178
int& outStatusCode,
179179
FilteredFileReader& filteredReader,
180180
RecordFilterParams& outFilters) {
@@ -214,7 +214,7 @@ bool parseTimeAndStreamFilters(
214214
if (argn + 2 < argc) {
215215
try {
216216
filteredReader.filter.minTime = stod(argv[++argn]);
217-
filteredReader.filter.relativeMinTime = isSigned(argv[argn]);
217+
filteredReader.filter.relativeMinTime = isSigned(argv[argn].c_str());
218218
filteredReader.filter.maxTime = stod(argv[++argn]);
219219
filteredReader.filter.aroundTime = true;
220220
} catch (logic_error&) {
@@ -286,7 +286,7 @@ bool parseDecimationOptions(
286286
const string& arg,
287287
int& argn,
288288
int argc,
289-
char** argv,
289+
std::vector<std::string> argv,
290290
int& outStatusCode,
291291
RecordFilterParams& outFilters) {
292292
if (arg == "--decimate") {

vrs/utils/cli/CliParsing.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool parseCopyOptions(
4545
const string& arg,
4646
int& argn,
4747
int argc,
48-
char** argv,
48+
std::vector<std::string> argv,
4949
int& outStatusCode,
5050
CopyOptions& copyOptions);
5151
/// Print copy options help
@@ -72,7 +72,7 @@ bool parseTagOverrideOptions(
7272
const string& arg,
7373
int& argn,
7474
int argc,
75-
char** argv,
75+
std::vector<std::string> argv,
7676
int& outStatusCode,
7777
CopyOptions& copyOptions);
7878
/// Print tag override help
@@ -101,7 +101,7 @@ bool parseTimeAndStreamFilters(
101101
const string& arg,
102102
int& argn,
103103
int argc,
104-
char** argv,
104+
std::vector<std::string> argv,
105105
int& outStatusCode,
106106
FilteredFileReader& filteredReader,
107107
RecordFilterParams& outFilters);
@@ -129,7 +129,7 @@ bool parseDecimationOptions(
129129
const string& arg,
130130
int& argn,
131131
int argc,
132-
char** argv,
132+
std::vector<std::string> argv,
133133
int& outStatusCode,
134134
RecordFilterParams& outFilters);
135135
/// Print decimation options help

0 commit comments

Comments
 (0)