summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code/tokenizer/parser.c
blob: 69ec4586c39ca076644b61fd7c35adcc5ce4066b (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
#include <stdio.h>
#include <stdlib.h>

#include "../global/util.h"

char *ReadFile(char *fileName); // reads the file into a single var
char *Parse(char *fileName); // general parser function

char *ReadFile(char *filename){
	FILE *f = fopen(filename, "r");
	if (f == NULL)
		Die();	

	fseek(f, 0, SEEK_END);
	size_t len = ftell(f);
	rewind(f);
	
	char *out = malloc(len+1);

	char c;
	for (int i = 0; i < len; i++){
		c = fgetc(f);	
		if (c == '\n' || c == '\t')
			out[i] = ' ';
		else
			out[i] = c;
	}
	out[len+1] = '\0';

	fclose(f);
	return out;
}

char *Parser(char *fileName){
	return ReadFile(fileName);
}