mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added -n option to diable print newline
This commit is contained in:
@@ -29,6 +29,7 @@ void Toy_initCommandLine(int argc, const char* argv[]) {
|
|||||||
Toy_commandLine.outfile = "out.tb";
|
Toy_commandLine.outfile = "out.tb";
|
||||||
Toy_commandLine.source = NULL;
|
Toy_commandLine.source = NULL;
|
||||||
Toy_commandLine.initialfile = NULL;
|
Toy_commandLine.initialfile = NULL;
|
||||||
|
Toy_commandLine.enablePrintNewline = true;
|
||||||
Toy_commandLine.verbose = false;
|
Toy_commandLine.verbose = false;
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) { //start at 1 to skip the program name
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(argv[i], "-n")) {
|
||||||
|
Toy_commandLine.enablePrintNewline = false;
|
||||||
|
Toy_commandLine.error = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//option without a flag + ending in .tb = binary input
|
//option without a flag + ending in .tb = binary input
|
||||||
if (i < argc) {
|
if (i < argc) {
|
||||||
if (strncmp(&(argv[i][strlen(argv[i]) - 3]), ".tb", 3) == 0) {
|
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("-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("-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("-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[]) {
|
void Toy_copyrightCommandLine(int argc, const char* argv[]) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ typedef struct {
|
|||||||
char* outfile; //defaults to out.tb
|
char* outfile; //defaults to out.tb
|
||||||
char* source;
|
char* source;
|
||||||
char* initialfile;
|
char* initialfile;
|
||||||
|
bool enablePrintNewline;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
} Toy_CommandLine;
|
} Toy_CommandLine;
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void printWrapper(const char* output) {
|
static void printWrapper(const char* output) {
|
||||||
printf("%s", output);
|
if (Toy_commandLine.enablePrintNewline) {
|
||||||
// printf("\n"); //default new line
|
printf("%s\n", output);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%s", output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assertWrapper(const char* output) {
|
static void assertWrapper(const char* output) {
|
||||||
|
|||||||
Reference in New Issue
Block a user