summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 56253a64c7c5c7ec9959285be63be8fe93d4b109 (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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include "include/fileops.h"
#include "include/parser.h"

int main(int argc, char **argv)
{
  if (argc != 2)
    exit(1);
  char *filename = argv[1];
  
  uint8_t *buf = readdb(filename);
  if (buf == NULL)
    exit(0);
  struct byte *bytes = parse(buf);
  free(buf);

  for (int i = 0; i < blen; ++i) {
    switch (bytes[i].type) {
      case BEGIN:
        printf("BEGIN\n");
        break;
      case END:
        printf("END\n");
        break;
      case PAIR:
        printf("PAIR: %s\n", bytes[i].value);
        free(bytes[i].value);
        break;
      case ERROR:
        fprintf(stderr, "%s\n", bytes[i].value);
        exit(1);
    }
  }

  free(bytes);
  exit(0);
}