PostgreSQL Source Code git master
test_parser.c File Reference
#include "postgres.h"
#include "fmgr.h"
Include dependency graph for test_parser.c:

Go to the source code of this file.

Data Structures

struct  ParserState
 
struct  LexDescr
 

Functions

 PG_FUNCTION_INFO_V1 (testprs_start)
 
 PG_FUNCTION_INFO_V1 (testprs_getlexeme)
 
 PG_FUNCTION_INFO_V1 (testprs_end)
 
 PG_FUNCTION_INFO_V1 (testprs_lextype)
 
Datum testprs_start (PG_FUNCTION_ARGS)
 
Datum testprs_getlexeme (PG_FUNCTION_ARGS)
 
Datum testprs_end (PG_FUNCTION_ARGS)
 
Datum testprs_lextype (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ PG_FUNCTION_INFO_V1() [1/4]

PG_FUNCTION_INFO_V1 ( testprs_end  )

◆ PG_FUNCTION_INFO_V1() [2/4]

PG_FUNCTION_INFO_V1 ( testprs_getlexeme  )

◆ PG_FUNCTION_INFO_V1() [3/4]

PG_FUNCTION_INFO_V1 ( testprs_lextype  )

◆ PG_FUNCTION_INFO_V1() [4/4]

PG_FUNCTION_INFO_V1 ( testprs_start  )

◆ testprs_end()

Datum testprs_end ( PG_FUNCTION_ARGS  )

Definition at line 99 of file test_parser.c.

100{
102
103 pfree(pst);
105}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
void pfree(void *pointer)
Definition: mcxt.c:1521

References pfree(), PG_GETARG_POINTER, and PG_RETURN_VOID.

◆ testprs_getlexeme()

Datum testprs_getlexeme ( PG_FUNCTION_ARGS  )

Definition at line 59 of file test_parser.c.

60{
62 char **t = (char **) PG_GETARG_POINTER(1);
63 int *tlen = (int *) PG_GETARG_POINTER(2);
64 int startpos = pst->pos;
65 int type;
66
67 *t = pst->buffer + pst->pos;
68
69 if (pst->pos < pst->len &&
70 (pst->buffer)[pst->pos] == ' ')
71 {
72 /* blank type */
73 type = 12;
74 /* go to the next non-space character */
75 while (pst->pos < pst->len &&
76 (pst->buffer)[pst->pos] == ' ')
77 (pst->pos)++;
78 }
79 else
80 {
81 /* word type */
82 type = 3;
83 /* go to the next space character */
84 while (pst->pos < pst->len &&
85 (pst->buffer)[pst->pos] != ' ')
86 (pst->pos)++;
87 }
88
89 *tlen = pst->pos - startpos;
90
91 /* we are finished if (*tlen == 0) */
92 if (*tlen == 0)
93 type = 0;
94
96}
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
static XLogRecPtr startpos
char * buffer
Definition: test_parser.c:26
const char * type

References ParserState::buffer, ParserState::len, PG_GETARG_POINTER, PG_RETURN_INT32, ParserState::pos, startpos, and type.

◆ testprs_lextype()

Datum testprs_lextype ( PG_FUNCTION_ARGS  )

Definition at line 108 of file test_parser.c.

109{
110 /*
111 * Remarks: - we have to return the blanks for headline reason - we use
112 * the same lexids like Teodor in the default word parser; in this way we
113 * can reuse the headline function of the default word parser.
114 */
115 LexDescr *descr = (LexDescr *) palloc(sizeof(LexDescr) * (2 + 1));
116
117 /* there are only two types in this parser */
118 descr[0].lexid = 3;
119 descr[0].alias = pstrdup("word");
120 descr[0].descr = pstrdup("Word");
121 descr[1].lexid = 12;
122 descr[1].alias = pstrdup("blank");
123 descr[1].descr = pstrdup("Space symbols");
124 descr[2].lexid = 0;
125
126 PG_RETURN_POINTER(descr);
127}
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void * palloc(Size size)
Definition: mcxt.c:1317
char * alias
Definition: ts_public.h:28
int lexid
Definition: ts_public.h:27
char * descr
Definition: ts_public.h:29

References LexDescr::alias, LexDescr::descr, LexDescr::lexid, palloc(), PG_RETURN_POINTER, and pstrdup().

◆ testprs_start()

Datum testprs_start ( PG_FUNCTION_ARGS  )

Definition at line 47 of file test_parser.c.

48{
49 ParserState *pst = (ParserState *) palloc0(sizeof(ParserState));
50
51 pst->buffer = (char *) PG_GETARG_POINTER(0);
52 pst->len = PG_GETARG_INT32(1);
53 pst->pos = 0;
54
56}
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void * palloc0(Size size)
Definition: mcxt.c:1347

References ParserState::buffer, ParserState::len, palloc0(), PG_GETARG_INT32, PG_GETARG_POINTER, PG_RETURN_POINTER, and ParserState::pos.

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 17 of file test_parser.c.