Command line arguments via CMDLINE_ARGS list var
This commit is contained in:
30
src/main.c
30
src/main.c
@@ -1,6 +1,7 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
#include "types.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
char* getFileContents(const char* filename) {
|
char* getFileContents(const char* filename) {
|
||||||
@@ -40,19 +41,6 @@ char* getFileContents(const char* filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
/*
|
|
||||||
if (argc < 2) {
|
|
||||||
printf("Usage: ground [file]\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
char* file = getFileContents(argv[1]);
|
|
||||||
GroundProgram program = parseFile(file);
|
|
||||||
free(file);
|
|
||||||
char* compiled = compileGroundProgram(&program);
|
|
||||||
printf("%s\n", compiled);
|
|
||||||
interpretGroundProgram(&program, NULL);
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Usage: %s <file> [-c] [--compile] [-h] [--help]\n", argv[0]);
|
printf("Usage: %s <file> [-c] [--compile] [-h] [--help]\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -60,7 +48,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
bool compile = false;
|
bool compile = false;
|
||||||
char* fileName = NULL;
|
char* fileName = NULL;
|
||||||
|
List groundArgs = createList();
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (strcmp("--compile", argv[i]) == 0 || strcmp("-c", argv[i]) == 0) {
|
if (strcmp("--compile", argv[i]) == 0 || strcmp("-c", argv[i]) == 0) {
|
||||||
compile = true;
|
compile = true;
|
||||||
@@ -73,7 +61,11 @@ int main(int argc, char** argv) {
|
|||||||
printf(" -h or --help: Shows this help message\n");
|
printf(" -h or --help: Shows this help message\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
if (fileName == NULL) {
|
||||||
fileName = argv[i];
|
fileName = argv[i];
|
||||||
|
} else {
|
||||||
|
appendToList(&groundArgs, createStringGroundValue(argv[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +83,14 @@ int main(int argc, char** argv) {
|
|||||||
char* compiled = compileGroundProgram(&program);
|
char* compiled = compileGroundProgram(&program);
|
||||||
printf("%s\n", compiled);
|
printf("%s\n", compiled);
|
||||||
} else {
|
} else {
|
||||||
interpretGroundProgram(&program, NULL);
|
GroundVariable* variables = NULL;
|
||||||
|
GroundLabel* labels = NULL;
|
||||||
|
|
||||||
|
GroundScope scope;
|
||||||
|
scope.variables = &variables;
|
||||||
|
scope.labels = &labels;
|
||||||
|
scope.isMainScope = true;
|
||||||
|
addVariable(scope.variables, "CMDLINE_ARGS", createListGroundValue(groundArgs));
|
||||||
|
interpretGroundProgram(&program, &scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user