Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit da1b98d

Browse files
authored
Update run.cpp
Update to support non-space separated args
1 parent 02dd5db commit da1b98d

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

runner/run.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -803,41 +803,49 @@ int main(int argc, char *argv[]) {
803803
} else {
804804
error_usage();
805805
}
806-
for (int i = 2; i < argc; i += 2) {
806+
for (int i = 2; i < argc; i += 1) {
807807
// do some basic validation
808-
if (i + 1 >= argc) {
809-
error_usage();
810-
} // must have arg after flag
808+
char *parm = argv[i+1];
809+
811810
if (argv[i][0] != '-') {
812811
error_usage();
813812
} // must start with dash
814-
if (strlen(argv[i]) != 2) {
813+
814+
// uniarg means the arg comes right after the letter in accordance with posix
815+
int uniarg = strlen(argv[i]) != 2;
816+
if (uniarg) {
817+
parm=&argv[i][2];
818+
} else if (i + 1 >= argc) {
815819
error_usage();
816-
} // must be -x (one dash, one letter)
820+
} // must have arg after option if flag is not contiguous to option
821+
817822
// read in the args
818823
if (argv[i][1] == 't') {
819-
temperature = atof(argv[i + 1]);
824+
temperature = atof(parm);
820825
} else if (argv[i][1] == 'p') {
821-
topp = atof(argv[i + 1]);
826+
topp = atof(parm);
822827
} else if (argv[i][1] == 's') {
823-
rng_seed = atoi(argv[i + 1]);
828+
rng_seed = atoi(parm);
824829
} else if (argv[i][1] == 'n') {
825-
steps = atoi(argv[i + 1]);
830+
steps = atoi(parm);
826831
} else if (argv[i][1] == 'v') {
827832
vocab_size = atoi(argv[i + 1]);
828833
} else if (argv[i][1] == 'i') {
829-
prompt = argv[i + 1];
834+
prompt = parm;
830835
} else if (argv[i][1] == 'z') {
831-
tokenizer_path = argv[i + 1];
836+
tokenizer_path = parm;
832837
} else if (argv[i][1] == 'm') {
833-
mode = argv[i + 1];
838+
mode = parm;
834839
} else if (argv[i][1] == 'y') {
835-
system_prompt = argv[i + 1];
840+
system_prompt = parm;
836841
} else if (argv[i][1] == 'l') {
837-
llama_ver = atoi(argv[i + 1]);
842+
llama_ver = atoi(parm);
838843
} else {
839844
error_usage();
840845
}
846+
847+
// account for parameter
848+
i += (uniarg)?0:1;
841849
}
842850

843851
if (model_path == NULL) {

0 commit comments

Comments
 (0)