Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions | Variables

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)
Datum testprs_start (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (testprs_getlexeme)
Datum testprs_getlexeme (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (testprs_end)
Datum testprs_end (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (testprs_lextype)
Datum testprs_lextype (PG_FUNCTION_ARGS)

Variables

 PG_MODULE_MAGIC

Function Documentation

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

Definition at line 111 of file test_parser.c.

References pfree(), PG_GETARG_POINTER, and PG_RETURN_VOID.

Datum testprs_getlexeme ( PG_FUNCTION_ARGS   ) 

Definition at line 71 of file test_parser.c.

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

{
    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_lextype ( PG_FUNCTION_ARGS   ) 

Definition at line 120 of file test_parser.c.

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

{
    /*
     * 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);
}

Datum testprs_start ( PG_FUNCTION_ARGS   ) 

Variable Documentation

Definition at line 17 of file test_parser.c.