Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic CLI #35

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ deps_macos:
brew install clang-format

run: default
$(BUILD_DIR)/$(TARGET)
@$(BUILD_DIR)/$(TARGET) $(program);

test: compile_rust $(TEST_TARGET)
$(BUILD_DIR)/$(TEST_TARGET)
Expand Down
10 changes: 10 additions & 0 deletions src/cairo_run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "cairo_run.h"
#include "parser.h"
#include <stdlib.h>

ResultCairoRun cairo_run(char *program_file_name) {
Program *program = parse_json_filename(program_file_name);
free(program);
ResultCairoRun ok = {.is_error = false, .error_message = ""};
return ok;
}
7 changes: 7 additions & 0 deletions src/cairo_run.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdbool.h>
typedef struct ResultCairoRun {
bool is_error;
char *error_message;
} ResultCairoRun;

ResultCairoRun cairo_run(char *program_file_name);
19 changes: 13 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "decoder.h"
#include "utils.h"
#include <limits.h>
#include "cairo_run.h"
#include <stdio.h>

int main(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
printf("Hello World!\n");

int main(int argc, char **argv) {
if (argc != 2) {
printf("Error: expected the name of a program json file\n");
return -1;
}
char * program_file_name = argv[1];
printf("Running program: %s\n", program_file_name);
ResultCairoRun result = cairo_run(program_file_name);
if (result.is_error) {
printf("Error: %s\n", result.error_message);
}
printf("Run succesful\n");
return 0;
}