/+junk/codegen

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/codegen
1 by Gustav Hartvigsson
Beep Boop, nothin yet.
1
#include <stdio.h>
2
3
#include "defs.h"
4
#include "utils.h"
5
#include "configuration.h"
6
7
#define FLAG_IMPLEMENTATION
8
#include "flag.h"
9
10
void
11
print_help ();
12
13
void
14
parse_args (int argc,str_t* argv);
15
16
int main(int argc, char **argv) {
17
    parse_args (argc, argv);
18
19
    return 0;
20
}
21
22
void
23
print_help () {
24
  fprintf (stdout, PROJECT_NAME " " PROJECT_VERSION "\n");
25
  fprintf (stdout, "OPTIONS:\n");
26
  flag_print_options (stdout);
27
}
28
void
29
parse_args (int argc, str_t* argv) {
30
  bool *_help = flag_bool ("help", false, "Print the this help message.");
31
  str_t* _in_path = flag_str ("i", "", "The path to the input file");
32
  str_t* _out_path = flag_str ("o", "a.out", "The path to the output file");
33
34
  if (!flag_parse(argc, argv)) {
35
    print_help ();
36
    flag_print_error(stderr);
37
    exit(1);
38
  }
39
40
  if (*_help) {
41
    print_help ();
42
  }
43
44
  if (!(strlen(*_in_path))) {
45
    fprintf (stdout, "Missing input file.\n\n");
46
    print_help ();
47
    exit (1);
48
  }
49
50
  // check if file exists.
51
  FILE * f;
52
  f = fopen (*_in_path, "r");
53
  if (f) {
54
    fclose (f);
55
  } else {
56
    err_print ("File %s can not be found or is unreadable.\n", *_in_path);
57
  }
58
  
59
  f = fopen (*_out_path, "w");
60
  if (f) {
61
    fclose (f);
62
  } else {
63
    err_print ("Could not write to file %s."
64
               " Do you have accesse to the file?\n",
65
               *_out_path);
66
  }
67
68
  Configuration * cfg = configuration_get_default ();
69
70
  cfg->in_file_path = *_in_path;
71
  cfg->out_file_path = *_out_path;
72
}