Skip to content

Commit c6f3a2e

Browse files
committed
Assume output filename if it is not provided
1 parent 2e62a7c commit c6f3a2e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/opusenc.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,30 @@ int main(int argc, char **argv)
794794
usage();
795795
exit(1);
796796
}
797-
inFile=argv_utf8[optind];
798-
outFile=argv_utf8[optind+1];
799-
797+
inFile = argv_utf8[optind];
798+
/*Assumes filename if output is not provided*/
799+
if (argc_utf8-optind == 1) {
800+
outFile = realloc(NULL, strlen(inFile) * sizeof(char));
801+
strcpy(outFile, inFile);
802+
int foundExt = 0;
803+
for (size_t i = strlen(inFile); i != 0; i--) {
804+
outFile[i] = '\0';
805+
if (inFile[i] == '\\' || inFile[i] == '/') {
806+
break;
807+
}
808+
else if (inFile[i] == '.') {
809+
foundExt = 1;
810+
break;
811+
}
812+
}
813+
if (!foundExt) {
814+
strcpy(outFile, inFile);
815+
}
816+
strcat(outFile, ".opus");
817+
}
818+
else {
819+
outFile = argv_utf8[optind+1];
820+
}
800821
if (cline_size > 0) {
801822
ret = ope_comments_add(inopt.comments, "ENCODER_OPTIONS", ENCODER_string);
802823
if (ret != OPE_OK) {

0 commit comments

Comments
 (0)