aboutsummaryrefslogtreecommitdiff
path: root/Converter/src/main.c
blob: 7b647491a9e0caead12a6f34850d5a618c05aec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "../includes/compiler.h"
#include "../includes/test.h"
#include <malloc.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
  if (argc > 1)
  {
    if (strncmp(argv[1], "--test", 7) == 0)
    {
      // run tests
      fputs("Running header test (how does compile_string handle # headers?)\n",
            stderr);
      test_compile_line_header_depth();
    }
    else
    {
      string output =
          (compile_line(argv[1], strnlen(argv[1], 1024), "<stdin>"));
      puts(output);
      free(output);
    }
  }
  else
  {
    int i;
    char *buf;
    while (1)
    {

      printf("> ");
      buf = malloc(sizeof(*buf) * 1024);
      fgets(buf, 1024, stdin);

      for (i = 0; buf[i] != '\n'; ++i) continue;
      buf[i] = '\0'; // terminate

      string output = (compile_line(buf, strlen(buf), "<stdin>"));
      puts(output);
      free(output);
    }
  }
}