summaryrefslogtreecommitdiff
path: root/contrib/cube/buffer.c
blob: bab7ae303c629980518be73bf6647a9f6a02ee37 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
/* This module defines the parse buffer and routines for setting/reading it */

#include "postgres.h"

#include "utils/elog.h"

static char *PARSE_BUFFER;
static char *PARSE_BUFFER_PTR;
static unsigned int PARSE_BUFFER_SIZE;
static unsigned int SCANNER_POS;

void		set_parse_buffer(char *s);
void		reset_parse_buffer(void);
int			read_parse_buffer(void);
char	   *parse_buffer(void);
char	   *parse_buffer_ptr(void);
unsigned int parse_buffer_curr_char(void);
unsigned int parse_buffer_size(void);
unsigned int parse_buffer_pos(void);

extern void cube_flush_scanner_buffer(void);	/* defined in cubescan.l */

void
set_parse_buffer(char *s)
{
	PARSE_BUFFER = s;
	PARSE_BUFFER_SIZE = strlen(s);
	if (PARSE_BUFFER_SIZE == 0)
		elog(ERROR, "cube_in: can't parse an empty string");
	PARSE_BUFFER_PTR = PARSE_BUFFER;
	SCANNER_POS = 0;
}

void
reset_parse_buffer(void)
{
	PARSE_BUFFER_PTR = PARSE_BUFFER;
	SCANNER_POS = 0;
	cube_flush_scanner_buffer();
}

int
read_parse_buffer(void)
{
	int			c;

	/*
	 * c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
	 */
	c = PARSE_BUFFER[SCANNER_POS];
	if (SCANNER_POS < PARSE_BUFFER_SIZE)
		SCANNER_POS++;
	return c;
}

char *
parse_buffer(void)
{
	return PARSE_BUFFER;
}

unsigned int
parse_buffer_curr_char(void)
{
	return PARSE_BUFFER[SCANNER_POS];
}

char *
parse_buffer_ptr(void)
{
	return PARSE_BUFFER_PTR;
}

unsigned int
parse_buffer_pos(void)
{
	return SCANNER_POS;
}

unsigned int
parse_buffer_size(void)
{
	return PARSE_BUFFER_SIZE;
}