PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dict_int.c File Reference
#include "postgres.h"
#include "commands/defrem.h"
#include "tsearch/ts_public.h"
Include dependency graph for dict_int.c:

Go to the source code of this file.

Data Structures

struct  DictInt
 

Functions

 PG_FUNCTION_INFO_V1 (dintdict_init)
 
 PG_FUNCTION_INFO_V1 (dintdict_lexize)
 
Datum dintdict_init (PG_FUNCTION_ARGS)
 
Datum dintdict_lexize (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

Datum dintdict_init ( PG_FUNCTION_ARGS  )

Definition at line 31 of file dict_int.c.

References defGetBoolean(), defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, lfirst, DictInt::maxlen, palloc0(), PG_GETARG_POINTER, PG_RETURN_POINTER, pg_strcasecmp(), and DictInt::rejectlong.

32 {
33  List *dictoptions = (List *) PG_GETARG_POINTER(0);
34  DictInt *d;
35  ListCell *l;
36 
37  d = (DictInt *) palloc0(sizeof(DictInt));
38  d->maxlen = 6;
39  d->rejectlong = false;
40 
41  foreach(l, dictoptions)
42  {
43  DefElem *defel = (DefElem *) lfirst(l);
44 
45  if (pg_strcasecmp(defel->defname, "MAXLEN") == 0)
46  {
47  d->maxlen = atoi(defGetString(defel));
48  }
49  else if (pg_strcasecmp(defel->defname, "REJECTLONG") == 0)
50  {
51  d->rejectlong = defGetBoolean(defel);
52  }
53  else
54  {
55  ereport(ERROR,
56  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
57  errmsg("unrecognized intdict parameter: \"%s\"",
58  defel->defname)));
59  }
60  }
61 
63 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
int maxlen
Definition: dict_int.c:22
bool rejectlong
Definition: dict_int.c:23
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
#define ereport(elevel, rest)
Definition: elog.h:122
void * palloc0(Size size)
Definition: mcxt.c:920
#define lfirst(lc)
Definition: pg_list.h:106
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:675
Definition: pg_list.h:45
Datum dintdict_lexize ( PG_FUNCTION_ARGS  )

Definition at line 66 of file dict_int.c.

References TSLexeme::lexeme, DictInt::maxlen, NULL, palloc0(), pfree(), PG_GETARG_INT32, PG_GETARG_POINTER, PG_RETURN_POINTER, pnstrdup(), and DictInt::rejectlong.

67 {
68  DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
69  char *in = (char *) PG_GETARG_POINTER(1);
70  char *txt = pnstrdup(in, PG_GETARG_INT32(2));
71  TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
72 
73  res[1].lexeme = NULL;
74  if (PG_GETARG_INT32(2) > d->maxlen)
75  {
76  if (d->rejectlong)
77  {
78  /* reject by returning void array */
79  pfree(txt);
80  res[0].lexeme = NULL;
81  }
82  else
83  {
84  /* trim integer */
85  txt[d->maxlen] = '\0';
86  res[0].lexeme = txt;
87  }
88  }
89  else
90  {
91  res[0].lexeme = txt;
92  }
93 
94  PG_RETURN_POINTER(res);
95 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
int maxlen
Definition: dict_int.c:22
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1176
bool rejectlong
Definition: dict_int.c:23
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
void pfree(void *pointer)
Definition: mcxt.c:992
char * lexeme
Definition: ts_public.h:111
void * palloc0(Size size)
Definition: mcxt.c:920
#define NULL
Definition: c.h:226
PG_FUNCTION_INFO_V1 ( dintdict_init  )
PG_FUNCTION_INFO_V1 ( dintdict_lexize  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 18 of file dict_int.c.