diff --git a/source/toy_common.c b/source/toy_common.c index 5275fdc..cfa49f7 100644 --- a/source/toy_common.c +++ b/source/toy_common.c @@ -29,6 +29,7 @@ void Toy_initCommandLine(int argc, const char* argv[]) { Toy_commandLine.outfile = "out.tb"; Toy_commandLine.source = NULL; Toy_commandLine.initialfile = NULL; + Toy_commandLine.enablePrintNewline = true; Toy_commandLine.verbose = false; for (int i = 1; i < argc; i++) { //start at 1 to skip the program name @@ -87,6 +88,12 @@ void Toy_initCommandLine(int argc, const char* argv[]) { continue; } + if (!strcmp(argv[i], "-n")) { + Toy_commandLine.enablePrintNewline = false; + Toy_commandLine.error = false; + continue; + } + //option without a flag + ending in .tb = binary input if (i < argc) { if (strncmp(&(argv[i][strlen(argv[i]) - 3]), ".tb", 3) == 0) { @@ -117,6 +124,7 @@ void Toy_helpCommandLine(int argc, const char* argv[]) { printf("-c\t| --compile filename\tParse and compile the specified source file into an output file.\n\n"); printf("-o\t| --output outfile\tName of the output file built with --compile (default: out.tb).\n\n"); printf("-t\t| --initial filename\tStart the repl as normal, after first running the given file.\n\n"); + printf("-n\t|\t\t\tDisable the newline character at the end of the print statement.\n\n"); } void Toy_copyrightCommandLine(int argc, const char* argv[]) { diff --git a/source/toy_common.h b/source/toy_common.h index e6538c8..5e6d915 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -39,6 +39,7 @@ typedef struct { char* outfile; //defaults to out.tb char* source; char* initialfile; + bool enablePrintNewline; bool verbose; } Toy_CommandLine; diff --git a/source/toy_interpreter.c b/source/toy_interpreter.c index 721a9fb..ae13bb7 100644 --- a/source/toy_interpreter.c +++ b/source/toy_interpreter.c @@ -12,8 +12,12 @@ #include static void printWrapper(const char* output) { - printf("%s", output); - // printf("\n"); //default new line + if (Toy_commandLine.enablePrintNewline) { + printf("%s\n", output); + } + else { + printf("%s", output); + } } static void assertWrapper(const char* output) {