Remove const char* prompt
This commit is contained in:
parent
a3ffcbd98b
commit
f0e44cdeda
1 changed files with 21 additions and 24 deletions
|
@ -66,38 +66,33 @@ int32_t get_num_physical_cores() {
|
||||||
return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4;
|
return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string process_escapes(const char* input) {
|
void process_escapes(std::string& input) {
|
||||||
std::string output;
|
std::size_t input_len = input.length();
|
||||||
|
std::size_t output_idx = 0;
|
||||||
|
|
||||||
if (input != nullptr) {
|
for (std::size_t input_idx = 0; input_idx < input_len; ++input_idx) {
|
||||||
std::size_t input_len = std::strlen(input);
|
if (input[input_idx] == '\\' && input_idx + 1 < input_len) {
|
||||||
output.reserve(input_len);
|
switch (input[++input_idx]) {
|
||||||
|
case 'n': input[output_idx++] = '\n'; break;
|
||||||
for (std::size_t i = 0; i < input_len; ++i) {
|
case 'r': input[output_idx++] = '\r'; break;
|
||||||
if (input[i] == '\\' && i + 1 < input_len) {
|
case 't': input[output_idx++] = '\t'; break;
|
||||||
switch (input[++i]) {
|
case '\'': input[output_idx++] = '\''; break;
|
||||||
case 'n': output.push_back('\n'); break;
|
case '\"': input[output_idx++] = '\"'; break;
|
||||||
case 'r': output.push_back('\r'); break;
|
case '\\': input[output_idx++] = '\\'; break;
|
||||||
case 't': output.push_back('\t'); break;
|
default: input[output_idx++] = '\\';
|
||||||
case '\'': output.push_back('\''); break;
|
input[output_idx++] = input[input_idx]; break;
|
||||||
case '\"': output.push_back('\"'); break;
|
|
||||||
case '\\': output.push_back('\\'); break;
|
|
||||||
default: output.push_back('\\');
|
|
||||||
output.push_back(input[i]); break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
output.push_back(input[i]);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
input[output_idx++] = input[input_idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
input.resize(output_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
bool invalid_param = false;
|
bool invalid_param = false;
|
||||||
bool escape_prompt = false;
|
bool escape_prompt = false;
|
||||||
const char* prompt = nullptr;
|
|
||||||
std::string arg;
|
std::string arg;
|
||||||
gpt_params default_params;
|
gpt_params default_params;
|
||||||
|
|
||||||
|
@ -121,7 +116,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
invalid_param = true;
|
invalid_param = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prompt = argv[i];
|
params.prompt = argv[i];
|
||||||
} else if (arg == "-e") {
|
} else if (arg == "-e") {
|
||||||
escape_prompt = true;
|
escape_prompt = true;
|
||||||
} else if (arg == "--session") {
|
} else if (arg == "--session") {
|
||||||
|
@ -340,7 +335,9 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
gpt_print_usage(argc, argv, default_params);
|
gpt_print_usage(argc, argv, default_params);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
params.prompt = escape_prompt ? process_escapes(prompt) : prompt;
|
if (escape_prompt) {
|
||||||
|
process_escapes(params.prompt);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue