Skip to content

Commit 671b4bd

Browse files
ulatekhggerganov
andauthored
main : allow a response-file as the sole parameter (ggml-org#2019)
* The "main" example now allows a response-file as the sole parameter. A response-file is a text file with command-line parameters, one per line. Prefix the name of the response-file with "@" to identify it as such. It's used under MS Windows to work around command-line length limits. It may be useful under other platforms to simplify character-escaping. * minor : style --------- Co-authored-by: Georgi Gerganov <[email protected]>
1 parent c8eeb93 commit 671b4bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/main/main.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,35 @@ void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
867867
int main(int argc, char ** argv) {
868868
whisper_params params;
869869

870+
// If the only argument starts with "@", read arguments line-by-line
871+
// from the given file.
872+
std::vector<std::string> vec_args;
873+
if (argc == 2 && argv != nullptr && argv[1] != nullptr && argv[1][0] == '@') {
874+
// Save the name of the executable.
875+
vec_args.push_back(argv[0]);
876+
877+
// Open the response file.
878+
char const * rspfile = argv[1] + sizeof(char);
879+
std::ifstream fin(rspfile);
880+
if (fin.is_open() == false) {
881+
fprintf(stderr, "error: response file '%s' not found\n", rspfile);
882+
return 1;
883+
}
884+
885+
// Read the entire response file.
886+
std::string line;
887+
while (std::getline(fin, line)) {
888+
vec_args.push_back(line);
889+
}
890+
891+
// Use the contents of the response file as the command-line arguments.
892+
argc = static_cast<int>(vec_args.size());
893+
argv = static_cast<char **>(alloca(argc * sizeof (char *)));
894+
for (int i = 0; i < argc; ++i) {
895+
argv[i] = const_cast<char *>(vec_args[i].c_str());
896+
}
897+
}
898+
870899
if (whisper_params_parse(argc, argv, params) == false) {
871900
whisper_print_usage(argc, argv, params);
872901
return 1;

0 commit comments

Comments
 (0)