MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / ingest_args

Function ingest_args

tools/tokenize/tokenize.cpp:81–120  ·  view source on GitHub ↗

Function: ingest_args(...) -> vector Takes argc and argv arguments, and converts them to a vector of UTF-8 encoded strings, as an STL vector . In particular, it handles character encoding shenanigans on Windows. Note: raw_argc and raw_argv are not actually read at all on Windows. On Windows we call GetCommandLineW to get the arguments in wchar_t format, ignoring the regular argc/

Source from the content-addressed store, hash-verified

79// TODO: potential opportunity to roll common stuff into common/console.cpp
80// in relation to Windows wchar_t shenanigans.
81static std::vector<std::string> ingest_args(int raw_argc, char ** raw_argv) {
82 std::vector<std::string> argv;
83
84 // Handle Windows, if given non-ASCII arguments.
85 // We convert wchar_t arguments into UTF-8 char* on this platform.
86 // Lets you invoke 'tokenize' on Windows cmd.exe with non-ASCII characters
87 // without throwing tantrums.
88#if defined(_WIN32)
89 int argc;
90 const LPWSTR cmdline_wargv = GetCommandLineW();
91 LPWSTR * wargv = CommandLineToArgvW(cmdline_wargv, &argc);
92
93 // silence unused arg warnings
94 (void) raw_argc;
95 (void) raw_argv;
96
97 for (int i = 0; i < argc; ++i) {
98 int length_needed = WideCharToMultiByte(CP_UTF8, 0, wargv[i], wcslen(wargv[i]), 0, 0, NULL, NULL);
99 char * output_buf = (char *) calloc(length_needed+1, sizeof(char));
100 GGML_ASSERT(output_buf);
101
102 WideCharToMultiByte(CP_UTF8, 0, wargv[i], wcslen(wargv[i]), output_buf, length_needed, NULL, NULL);
103 output_buf[length_needed] = '\0';
104
105 argv.push_back(output_buf);
106 free(output_buf);
107 }
108
109 LocalFree((HLOCAL) wargv);
110#else
111 int argc = raw_argc;
112 for (int i = 0; i < argc; ++i) {
113 argv.push_back(raw_argv[i]);
114 }
115#endif
116
117 GGML_ASSERT((unsigned int) argc == argv.size());
118
119 return argv;
120}
121
122//
123// Function: write_utf8_cstr_to_stdout(const char *) -> <writes to stdout>

Callers 1

mainFunction · 0.85

Calls 2

push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected