Mercurial > repo
comparison delvs-master/bf.c @ 3122:276f475af97b
<L8D> tar xf master.tar.gz
author | HackBot |
---|---|
date | Sun, 16 Jun 2013 06:17:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3121:38bec9e9e910 | 3122:276f475af97b |
---|---|
1 #include <stdio.h> | |
2 #include <string.h> | |
3 #include <stdbool.h> | |
4 #include <stdlib.h> | |
5 #include "bf.h" | |
6 | |
7 bool fileExists(const char *filename) { | |
8 FILE *file; | |
9 if ((file = fopen(filename, "r")) == NULL) { | |
10 return false; | |
11 } else { | |
12 fclose(file); | |
13 return true; | |
14 } | |
15 } | |
16 | |
17 int main(int argc, char *argv[]) { | |
18 if(argc > 1) { | |
19 if(fileExists(argv[1])) { | |
20 FILE *fp; | |
21 long size; | |
22 | |
23 fp = fopen(argv[1], "r"); | |
24 | |
25 fseek(fp, 0, SEEK_END); | |
26 size = ftell(fp); | |
27 rewind(fp); | |
28 | |
29 char *temp = (char*) malloc (100); | |
30 | |
31 char *file = (char*) malloc (size); | |
32 | |
33 file[0] = '\0'; | |
34 | |
35 while (fgets(temp, 100, fp) != NULL) strcat(file, temp); | |
36 | |
37 free(temp); | |
38 fclose(fp); | |
39 | |
40 struct Data g; | |
41 | |
42 g.code = file; | |
43 g.pointer = &g.vars[15000]; | |
44 | |
45 lexer(&g); | |
46 } | |
47 else { | |
48 printf("File not found!\n"); | |
49 } | |
50 } | |
51 | |
52 return 0; | |
53 } |