linters, some ast headers

This commit is contained in:
2024-12-18 22:34:22 +02:00
parent c2915d2eaa
commit 7361b6058d
8 changed files with 184 additions and 48 deletions

14
zig1.c
View File

@@ -6,11 +6,16 @@
// - code = 0: program successfully terminated.
// - code = 1: panicked, panic message in msg. Caller should free msg.
// - code = 2: interpreter error, error in msg. Caller should free msg.
int zig1_run(char* program, char** msg) { return 0; }
int zig1_run(const char* program, char** msg)
{
(void)program;
(void)msg;
return 0;
}
// API: run and:
// code = 3: abnormal error, expect something in stderr.
int zig1_run_file(char* fname, char** msg)
int zig1_run_file(const char* fname, char** msg)
{
FILE* f = fopen(fname, "r");
if (f == NULL) {
@@ -18,12 +23,13 @@ int zig1_run_file(char* fname, char** msg)
return 3;
}
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
if (fsize == -1) {
long fsizel = ftell(f);
if (fsizel == -1) {
perror("ftell");
fclose(f);
return 3;
}
unsigned long fsize = (unsigned long)fsizel;
fseek(f, 0, SEEK_SET);
char* program = malloc(fsize + 1);