Command line arguments via CMDLINE_ARGS list var

This commit is contained in:
2026-01-31 09:08:38 +11:00
parent ca861f7e4b
commit e3702f46f3

View File

@@ -1,6 +1,7 @@
#include "parser.h"
#include "interpreter.h"
#include "compiler.h"
#include "types.h"
#include <stdio.h>
char* getFileContents(const char* filename) {
@@ -40,19 +41,6 @@ char* getFileContents(const char* filename) {
}
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) {
printf("Usage: %s <file> [-c] [--compile] [-h] [--help]\n", argv[0]);
exit(1);
@@ -60,7 +48,7 @@ int main(int argc, char** argv) {
bool compile = false;
char* fileName = NULL;
List groundArgs = createList();
for (int i = 1; i < argc; i++) {
if (strcmp("--compile", argv[i]) == 0 || strcmp("-c", argv[i]) == 0) {
compile = true;
@@ -73,7 +61,11 @@ int main(int argc, char** argv) {
printf(" -h or --help: Shows this help message\n");
exit(0);
} else {
fileName = argv[i];
if (fileName == NULL) {
fileName = argv[i];
} else {
appendToList(&groundArgs, createStringGroundValue(argv[i]));
}
}
}
@@ -91,6 +83,14 @@ int main(int argc, char** argv) {
char* compiled = compileGroundProgram(&program);
printf("%s\n", compiled);
} 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);
}
}