DEADSOFTWARE

Добавлена проверка базы записи на рекурсивное расширение
[dsw-obn.git] / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
6 #include "../include/oberon.h"
8 static oberon_context_t * ctx;
9 static oberon_module_t * mod;
11 static const char *
12 import_module(const char * name)
13 {
14 assert(name);
16 FILE * fp;
17 char fname[256];
18 snprintf(fname, 256, "%s.obn", name);
19 fp = fopen(fname, "r");
20 if(fp == NULL)
21 {
22 printf("can't open file %s\n", fname);
23 exit(1);
24 return NULL;
25 }
27 char * source;
28 size_t len;
30 fseek(fp, 0, SEEK_END);
31 len = ftell(fp);
32 fseek(fp, 0, SEEK_SET);
34 source = calloc(1, len + 1);
35 fread(source, len, 1, fp);
37 return source;
38 }
40 int
41 main(int argc, char ** argv)
42 {
43 const char * code;
45 if(argc != 2)
46 {
47 printf("use: %s <module>\n", argv[0]);
48 return 1;
49 }
51 code = import_module(argv[1]);
53 ctx = oberon_create_context(import_module);
54 mod = oberon_compile_module(ctx, code);
56 oberon_destroy_context(ctx);
57 return 0;
58 }