Straightened out file extensions

This commit is contained in:
2023-02-11 14:26:55 +00:00
parent 3930ec0477
commit 5343e1054d
5 changed files with 31 additions and 2 deletions

View File

@@ -132,6 +132,14 @@ int main(int argc, const char* argv[]) {
//run source file //run source file
if (Toy_commandLine.sourcefile) { if (Toy_commandLine.sourcefile) {
//only works on toy files
const char* s = strrchr(Toy_commandLine.sourcefile, '.');
if (!s || strcmp(s, ".toy")) {
fprintf(stderr, TOY_CC_ERROR "Bad file extension passed to %s (expected '.toy', found '%s')" TOY_CC_RESET, argv[0], s);
return -1;
}
//run the source file
Toy_runSourceFile(Toy_commandLine.sourcefile); Toy_runSourceFile(Toy_commandLine.sourcefile);
//lib cleanup //lib cleanup
@@ -152,6 +160,19 @@ int main(int argc, const char* argv[]) {
//compile source file //compile source file
if (Toy_commandLine.compilefile && Toy_commandLine.outfile) { if (Toy_commandLine.compilefile && Toy_commandLine.outfile) {
//only works on toy and tb files
const char* c = strrchr(Toy_commandLine.compilefile, '.');
if (!c || strcmp(c, ".toy")) {
fprintf(stderr, TOY_CC_ERROR "Bad file extension passed to %s (expected '.toy', found '%s')" TOY_CC_RESET, argv[0], c);
return -1;
}
const char* o = strrchr(Toy_commandLine.outfile, '.');
if (!o || strcmp(o, ".tb")) {
fprintf(stderr, TOY_CC_ERROR "Bad file extension passed to %s (expected '.tb', found '%s')" TOY_CC_RESET, argv[0], o);
return -1;
}
//compile and save
size_t size = 0; size_t size = 0;
const char* source = Toy_readFile(Toy_commandLine.compilefile, &size); const char* source = Toy_readFile(Toy_commandLine.compilefile, &size);
if (!source) { if (!source) {
@@ -167,6 +188,14 @@ int main(int argc, const char* argv[]) {
//run binary //run binary
if (Toy_commandLine.binaryfile) { if (Toy_commandLine.binaryfile) {
//only works on tb files
const char* c = strrchr(Toy_commandLine.binaryfile, '.');
if (!c || strcmp(c, ".tb")) {
fprintf(stderr, TOY_CC_ERROR "Bad file extension passed to %s (expected '.tb', found '%s')" TOY_CC_RESET, argv[0], c); //this one is never seen
return -1;
}
//run the binary file
Toy_runBinaryFile(Toy_commandLine.binaryfile); Toy_runBinaryFile(Toy_commandLine.binaryfile);
//lib cleanup //lib cleanup

View File

@@ -94,7 +94,7 @@ void Toy_initCommandLine(int argc, const char* argv[]) {
} }
void Toy_usageCommandLine(int argc, const char* argv[]) { void Toy_usageCommandLine(int argc, const char* argv[]) {
printf("Usage: %s [<file.tb> | -h | -v | [-d][-f file | -i source | -c file [-o outfile]]]\n\n", argv[0]); printf("Usage: %s [ file.tb | -h | -v | [ -d ][ -f file.toy | -i source | -c file.toy [ -o outfile.tb ]]]\n\n", argv[0]);
} }
void Toy_helpCommandLine(int argc, const char* argv[]) { void Toy_helpCommandLine(int argc, const char* argv[]) {

View File

@@ -1507,7 +1507,7 @@ static bool execImport(Toy_Interpreter* interpreter) {
if (!Toy_existsLiteralDictionary(interpreter->hooks, identifier)) { if (!Toy_existsLiteralDictionary(interpreter->hooks, identifier)) {
interpreter->errorOutput("Unknown library name in import statement: "); interpreter->errorOutput("Unknown library name in import statement: ");
Toy_printLiteralCustom(identifier, interpreter->errorOutput); Toy_printLiteralCustom(identifier, interpreter->errorOutput);
interpreter->errorOutput("\"\n"); interpreter->errorOutput("\n");
Toy_freeLiteral(alias); Toy_freeLiteral(alias);
Toy_freeLiteral(identifier); Toy_freeLiteral(identifier);