From 5343e1054d932c879c2999b52aa05091bf814e44 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 11 Feb 2023 14:26:55 +0000 Subject: [PATCH] Straightened out file extensions --- repl/{lib_timer.cx => lib_timer.c__} | 0 repl/{lib_timer.hx => lib_timer.h__} | 0 repl/repl_main.c | 29 ++++++++++++++++++++++++++++ source/toy_common.c | 2 +- source/toy_interpreter.c | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) rename repl/{lib_timer.cx => lib_timer.c__} (100%) rename repl/{lib_timer.hx => lib_timer.h__} (100%) diff --git a/repl/lib_timer.cx b/repl/lib_timer.c__ similarity index 100% rename from repl/lib_timer.cx rename to repl/lib_timer.c__ diff --git a/repl/lib_timer.hx b/repl/lib_timer.h__ similarity index 100% rename from repl/lib_timer.hx rename to repl/lib_timer.h__ diff --git a/repl/repl_main.c b/repl/repl_main.c index a308086..690b666 100644 --- a/repl/repl_main.c +++ b/repl/repl_main.c @@ -132,6 +132,14 @@ int main(int argc, const char* argv[]) { //run source file 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); //lib cleanup @@ -152,6 +160,19 @@ int main(int argc, const char* argv[]) { //compile source file 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; const char* source = Toy_readFile(Toy_commandLine.compilefile, &size); if (!source) { @@ -167,6 +188,14 @@ int main(int argc, const char* argv[]) { //run binary 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); //lib cleanup diff --git a/source/toy_common.c b/source/toy_common.c index 6f6a07e..9b0df00 100644 --- a/source/toy_common.c +++ b/source/toy_common.c @@ -94,7 +94,7 @@ void Toy_initCommandLine(int argc, const char* argv[]) { } void Toy_usageCommandLine(int argc, const char* argv[]) { - printf("Usage: %s [ | -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[]) { diff --git a/source/toy_interpreter.c b/source/toy_interpreter.c index 824ac5f..63adba1 100644 --- a/source/toy_interpreter.c +++ b/source/toy_interpreter.c @@ -1507,7 +1507,7 @@ static bool execImport(Toy_Interpreter* interpreter) { if (!Toy_existsLiteralDictionary(interpreter->hooks, identifier)) { interpreter->errorOutput("Unknown library name in import statement: "); Toy_printLiteralCustom(identifier, interpreter->errorOutput); - interpreter->errorOutput("\"\n"); + interpreter->errorOutput("\n"); Toy_freeLiteral(alias); Toy_freeLiteral(identifier);