summaryrefslogtreecommitdiff
path: root/src/parsers/manparser.cxx
blob: 25858dad8dc58765b39e14918e51fc9edbc0a49b (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
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
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <ctype.h>

#include "../hunspell/csutil.hxx"
#include "manparser.hxx"


#ifndef W32
using namespace std;
#endif

ManParser::ManParser() {
}

ManParser::ManParser(const char * wordchars)
{
	init(wordchars);
}

ManParser::ManParser(unsigned short * wordchars, int len)
{
	init(wordchars, len);
}

ManParser::~ManParser() 
{
}

char * ManParser::next_token()
{
	for (;;) {
		switch (state)
		{
		case 1: // command arguments
			if (line[actual][head] == ' ') state = 2;
			break;
		case 0: // dot in begin of line
			if (line[actual][0] == '.') {
				state =  1;
				break;
			} else { 
				state = 2;
			}
			// no break
		case 2: // non word chars
			if (is_wordchar(line[actual] + head)) {
				state = 3;
				token = head;
			} else if ((line[actual][head] == '\\') && 
				   (line[actual][head + 1] == 'f') &&
				   (line[actual][head + 2] != '\0')) {
				head += 2;
			}
			break;
		case 3: // wordchar
			if (! is_wordchar(line[actual] + head)) {
				state = 2;
				char * t = alloc_token(token, &head);
				if (t) return t;
			}
			break;
		}
                if (next_char(line[actual], &head)) {
			state = 0;
			return NULL;
		}
	}
}