2000-12-12 04:40:33 +08:00
|
|
|
/* This module defines the parse buffer and routines for setting/reading it */
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
static char *PARSE_BUFFER;
|
|
|
|
static char *PARSE_BUFFER_PTR;
|
|
|
|
static unsigned int PARSE_BUFFER_SIZE;
|
2000-12-12 04:40:33 +08:00
|
|
|
static unsigned int SCANNER_POS;
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
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);
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
extern void seg_flush_scanner_buffer(void); /* defined in segscan.l */
|
2000-12-12 04:40:33 +08:00
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
void
|
|
|
|
set_parse_buffer(char *s)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
PARSE_BUFFER = s;
|
|
|
|
PARSE_BUFFER_SIZE = strlen(s);
|
|
|
|
if (PARSE_BUFFER_SIZE == 0)
|
2003-07-25 01:52:50 +08:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
|
|
|
|
errmsg("can't parse an empty string")));
|
2001-03-22 12:01:46 +08:00
|
|
|
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
|
|
|
SCANNER_POS = 0;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
void
|
|
|
|
reset_parse_buffer(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
|
|
|
SCANNER_POS = 0;
|
|
|
|
seg_flush_scanner_buffer();
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
int
|
|
|
|
read_parse_buffer(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
int c;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
|
|
|
|
*/
|
|
|
|
c = PARSE_BUFFER[SCANNER_POS];
|
|
|
|
if (SCANNER_POS < PARSE_BUFFER_SIZE)
|
|
|
|
SCANNER_POS++;
|
|
|
|
return c;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
char *
|
|
|
|
parse_buffer(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
return PARSE_BUFFER;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
unsigned int
|
|
|
|
parse_buffer_curr_char(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
return PARSE_BUFFER[SCANNER_POS];
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
char *
|
|
|
|
parse_buffer_ptr(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
return PARSE_BUFFER_PTR;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
unsigned int
|
|
|
|
parse_buffer_pos(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
return SCANNER_POS;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
unsigned int
|
|
|
|
parse_buffer_size(void)
|
2000-12-12 04:40:33 +08:00
|
|
|
{
|
2001-03-22 12:01:46 +08:00
|
|
|
return PARSE_BUFFER_SIZE;
|
2000-12-12 04:40:33 +08:00
|
|
|
}
|