This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathistream.h
78 lines (67 loc) · 1.67 KB
/
istream.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ14
*
* Repository:
* https://github.com/Dasio/IFJ
*
* Team:
* Dávid Mikuš (xmikus15)
* Peter Hostačný (xhosta03)
* Tomáš Kello (xkello00)
* Adam Lučanský (xlucan01)
* Michaela Lukášová (xlukas09)
*/
/**
* Module for manipulating with input streams (string or file)
* used for simpler testing with fixed strings instead of files
* laying around.
*/
#include "system.h"
#include "error.h"
#ifndef ISTREAM_H_
#define ISTREAM_H_
typedef enum {
IStream_NONE,
IStream_FILE,
IStream_STRING
} IStreamSource;
typedef struct {
IStreamSource src_type;
FILE *src_file;
char *src_string;
// Pointer used for emulating FILE
char *current_char;
} IStream;
/**
* IStream constructor
* @return Initialized IStream
*/
IStream initIStream();
/**
* IStream destructor, structure may be reused
*/
void destroyIStream(IStream *stream);
/**
* Assigns file to stream, may be called only once per structure
*/
bool assignFile(IStream *stream, char *input_file);
/**
* Assigns regular string (null terminated chars) to IStream
* @param stream Pointer to IStream
* @param array_of_chars Pointer to first char of string
*/
void assignString(IStream *stream, char *array_of_chars);
/**
* Returns next char from stream, EOF if end of stream reached
* @param stream Pointer to IStream
* @return char in type of int due to EOF
*/
int nextChar(IStream *stream);
/**
* fgetc(char, FILE) equivalent; returns char back to stream
* @param stream Pointer to IStream
* @param c Character in int
*/
void returnChar(IStream *stream, int c);
#endif