main soggy/cotton / src / main.c
 1#include "cotton.h"
 2#include "interpreter.h"
 3#include <stdio.h>
 4
 5int main
 6(int argc, char **argv)
 7{
 8    if (argc < 2) {
 9        
10        fprintf(stderr, "cotton: cotton couldn't find any .cot files to run :P\n");        
11		return 1;
12    }
13
14    FILE *f = fopen(argv[1], "r");
15
16    if (!f) {
17        
18        fprintf(stderr, "cotton: couldn't open \"%s\", is this even a file.,.? :<\n", argv[1]); 
19        return 1;
20    }
21
22    Cotton c;
23    cotton_init(&c);
24
25    char line[256];
26    while (fgets(line, sizeof(line), f)) {
27        
28        cotton_compile(&c, line);
29    }
30
31    fclose(f);
32    
33    c.mem[c.mem_len++] = OP_KILL;
34
35    cotton_run(&c);
36
37    return 0;
38}