postgresql/contrib/seg/buffer.c

85 lines
1.4 KiB
C
Raw Normal View History

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