forked from psi46/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.h
72 lines (57 loc) · 1.44 KB
/
scanner.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
// scanner.h
#ifndef SCANNER_H
#define SCANNER_H
#include <stdio.h>
#include <string.h>
#include "config.h"
// --- CFile -------------------------------------------------------------
#define FILEBUFFERSIZE 4096
class CFile
{
int pos, count;
char *buffer;
char m_LastChar;
FILE *m_stream;
char loadBuffer();
void init() { m_stream = NULL; m_LastChar = 0; buffer = NULL;
pos = 0; count = 0; }
public:
CFile() { init(); }
~CFile() { close(); }
bool open(const char filename[]);
bool rewind();
char getNextChar()
{
if (pos < count) return m_LastChar = buffer[pos++];
return loadBuffer();
}
char getChar() { return m_LastChar; }
char skipToChar(char ch)
{
while (m_LastChar && m_LastChar != ch) getNextChar();
return m_LastChar;
};
void close();
};
// --- Scanner -----------------------------------------------------------
#define MAXSECTIONLEN 20
#define MAXLINELEN 300
class CScanner
{
CFile m_logf;
char m_Section[MAXSECTIONLEN+1];
char m_Line[MAXLINELEN+1];
public:
bool open(const char filename[]);
bool rewind();
void close();
~CScanner() { close(); }
char* getNextSection();
bool getNextSection(const char name[]);
bool getNextSection(const char name[], const char stop[]);
bool isSection(const char name[]) { return strcmp(m_Section,name) == 0; }
char* getNextLine();
char* getLine() { return m_Line; }
void skipLine();
};
#endif