diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-11-29 23:55:00 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-11-29 23:55:00 -0300 |
commit | 22dfd116a127a2fc916a4fdac282ee69d4905a25 (patch) | |
tree | f72fa75958a5c9bbecda92bee316258c5680c410 /contrib/test_parser/test_parser.c | |
parent | 5b12987b2e80fcf3af1f6fd23954da5c453e9e64 (diff) | |
download | postgresql-22dfd116a127a2fc916a4fdac282ee69d4905a25.tar.gz postgresql-22dfd116a127a2fc916a4fdac282ee69d4905a25.zip |
Move test modules from contrib to src/test/modules
This is advance preparation for introducing even more test modules; the
easy solution is to add them to contrib, but that's bloated enough that
it seems a good time to think of something different.
Moved modules are dummy_seclabel, test_shm_mq, test_parser and
worker_spi.
(test_decoding was also a candidate, but there was too much opposition
to moving that one. We can always reconsider later.)
Diffstat (limited to 'contrib/test_parser/test_parser.c')
-rw-r--r-- | contrib/test_parser/test_parser.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/contrib/test_parser/test_parser.c b/contrib/test_parser/test_parser.c deleted file mode 100644 index cbf77966ae5..00000000000 --- a/contrib/test_parser/test_parser.c +++ /dev/null @@ -1,128 +0,0 @@ -/*------------------------------------------------------------------------- - * - * test_parser.c - * Simple example of a text search parser - * - * Copyright (c) 2007-2014, PostgreSQL Global Development Group - * - * IDENTIFICATION - * contrib/test_parser/test_parser.c - * - *------------------------------------------------------------------------- - */ -#include "postgres.h" - -#include "fmgr.h" - -PG_MODULE_MAGIC; - -/* - * types - */ - -/* self-defined type */ -typedef struct -{ - char *buffer; /* text to parse */ - int len; /* length of the text in buffer */ - int pos; /* position of the parser */ -} ParserState; - -/* copy-paste from wparser.h of tsearch2 */ -typedef struct -{ - int lexid; - char *alias; - char *descr; -} 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) -{ - ParserState *pst = (ParserState *) palloc0(sizeof(ParserState)); - - pst->buffer = (char *) PG_GETARG_POINTER(0); - pst->len = PG_GETARG_INT32(1); - pst->pos = 0; - - PG_RETURN_POINTER(pst); -} - -Datum -testprs_getlexeme(PG_FUNCTION_ARGS) -{ - ParserState *pst = (ParserState *) PG_GETARG_POINTER(0); - char **t = (char **) PG_GETARG_POINTER(1); - int *tlen = (int *) PG_GETARG_POINTER(2); - int startpos = pst->pos; - int type; - - *t = pst->buffer + pst->pos; - - if (pst->pos < pst->len && - (pst->buffer)[pst->pos] == ' ') - { - /* blank type */ - type = 12; - /* go to the next non-space character */ - while (pst->pos < pst->len && - (pst->buffer)[pst->pos] == ' ') - (pst->pos)++; - } - else - { - /* word type */ - type = 3; - /* go to the next space character */ - while (pst->pos < pst->len && - (pst->buffer)[pst->pos] != ' ') - (pst->pos)++; - } - - *tlen = pst->pos - startpos; - - /* we are finished if (*tlen == 0) */ - if (*tlen == 0) - type = 0; - - PG_RETURN_INT32(type); -} - -Datum -testprs_end(PG_FUNCTION_ARGS) -{ - ParserState *pst = (ParserState *) PG_GETARG_POINTER(0); - - pfree(pst); - PG_RETURN_VOID(); -} - -Datum -testprs_lextype(PG_FUNCTION_ARGS) -{ - /* - * Remarks: - we have to return the blanks for headline reason - we use - * the same lexids like Teodor in the default word parser; in this way we - * can reuse the headline function of the default word parser. - */ - LexDescr *descr = (LexDescr *) palloc(sizeof(LexDescr) * (2 + 1)); - - /* there are only two types in this parser */ - descr[0].lexid = 3; - descr[0].alias = pstrdup("word"); - descr[0].descr = pstrdup("Word"); - descr[1].lexid = 12; - descr[1].alias = pstrdup("blank"); - descr[1].descr = pstrdup("Space symbols"); - descr[2].lexid = 0; - - PG_RETURN_POINTER(descr); -} |