PostgreSQL Source Code git master
ts_locale.c File Reference
#include "postgres.h"
#include "common/string.h"
#include "storage/fd.h"
#include "tsearch/ts_locale.h"
Include dependency graph for ts_locale.c:

Go to the source code of this file.

Macros

#define WC_BUF_LEN   3
 

Functions

static void tsearch_readline_callback (void *arg)
 
int t_isalpha (const char *ptr)
 
int t_isalnum (const char *ptr)
 
bool tsearch_readline_begin (tsearch_readline_state *stp, const char *filename)
 
char * tsearch_readline (tsearch_readline_state *stp)
 
void tsearch_readline_end (tsearch_readline_state *stp)
 

Macro Definition Documentation

◆ WC_BUF_LEN

#define WC_BUF_LEN   3

Definition at line 32 of file ts_locale.c.

Function Documentation

◆ t_isalnum()

int t_isalnum ( const char *  ptr)

Definition at line 50 of file ts_locale.c.

51{
52 int clen = pg_mblen(ptr);
53 wchar_t character[WC_BUF_LEN];
54 pg_locale_t mylocale = 0; /* TODO */
55
56 if (clen == 1 || database_ctype_is_c)
57 return isalnum(TOUCHAR(ptr));
58
59 char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
60
61 return iswalnum((wint_t) character[0]);
62}
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023
bool database_ctype_is_c
Definition: pg_locale.c:145
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
#define WC_BUF_LEN
Definition: ts_locale.c:32
#define TOUCHAR(x)
Definition: ts_locale.h:35

References char2wchar(), database_ctype_is_c, pg_mblen(), TOUCHAR, and WC_BUF_LEN.

Referenced by parse_or_operator().

◆ t_isalpha()

int t_isalpha ( const char *  ptr)

Definition at line 35 of file ts_locale.c.

36{
37 int clen = pg_mblen(ptr);
38 wchar_t character[WC_BUF_LEN];
39 pg_locale_t mylocale = 0; /* TODO */
40
41 if (clen == 1 || database_ctype_is_c)
42 return isalpha(TOUCHAR(ptr));
43
44 char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
45
46 return iswalpha((wint_t) character[0]);
47}

References char2wchar(), database_ctype_is_c, pg_mblen(), TOUCHAR, and WC_BUF_LEN.

Referenced by parse_affentry(), RS_compile(), and RS_isRegis().

◆ tsearch_readline()

char * tsearch_readline ( tsearch_readline_state stp)

Definition at line 112 of file ts_locale.c.

113{
114 char *recoded;
115
116 /* Advance line number to use in error reports */
117 stp->lineno++;
118
119 /* Clear curline, it's no longer relevant */
120 if (stp->curline)
121 {
122 if (stp->curline != stp->buf.data)
123 pfree(stp->curline);
124 stp->curline = NULL;
125 }
126
127 /* Collect next line, if there is one */
128 if (!pg_get_line_buf(stp->fp, &stp->buf))
129 return NULL;
130
131 /* Validate the input as UTF-8, then convert to DB encoding if needed */
132 recoded = pg_any_to_server(stp->buf.data, stp->buf.len, PG_UTF8);
133
134 /* Save the correctly-encoded string for possible error reports */
135 stp->curline = recoded; /* might be equal to buf.data */
136
137 /*
138 * We always return a freshly pstrdup'd string. This is clearly necessary
139 * if pg_any_to_server() returned buf.data, and we need a second copy even
140 * if encoding conversion did occur. The caller is entitled to pfree the
141 * returned string at any time, which would leave curline pointing to
142 * recycled storage, causing problems if an error occurs after that point.
143 * (It's preferable to return the result of pstrdup instead of the output
144 * of pg_any_to_server, because the conversion result tends to be
145 * over-allocated. Since callers might save the result string directly
146 * into a long-lived dictionary structure, we don't want it to be a larger
147 * palloc chunk than necessary. We'll reclaim the conversion result on
148 * the next call.)
149 */
150 return pstrdup(recoded);
151}
char * pg_any_to_server(const char *s, int len, int encoding)
Definition: mbutils.c:676
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void pfree(void *pointer)
Definition: mcxt.c:1521
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition: pg_get_line.c:95
@ PG_UTF8
Definition: pg_wchar.h:232
StringInfoData buf
Definition: ts_locale.h:29

References tsearch_readline_state::buf, tsearch_readline_state::curline, StringInfoData::data, tsearch_readline_state::fp, StringInfoData::len, tsearch_readline_state::lineno, pfree(), pg_any_to_server(), pg_get_line_buf(), PG_UTF8, and pstrdup().

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().

◆ tsearch_readline_begin()

bool tsearch_readline_begin ( tsearch_readline_state stp,
const char *  filename 
)

Definition at line 89 of file ts_locale.c.

91{
92 if ((stp->fp = AllocateFile(filename, "r")) == NULL)
93 return false;
94 stp->filename = filename;
95 stp->lineno = 0;
96 initStringInfo(&stp->buf);
97 stp->curline = NULL;
98 /* Setup error traceback support for ereport() */
100 stp->cb.arg = stp;
102 error_context_stack = &stp->cb;
103 return true;
104}
ErrorContextCallback * error_context_stack
Definition: elog.c:94
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2605
static char * filename
Definition: pg_dumpall.c:119
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
struct ErrorContextCallback * previous
Definition: elog.h:296
void(* callback)(void *arg)
Definition: elog.h:297
ErrorContextCallback cb
Definition: ts_locale.h:32
const char * filename
Definition: ts_locale.h:27
static void tsearch_readline_callback(void *arg)
Definition: ts_locale.c:180

References AllocateFile(), ErrorContextCallback::arg, tsearch_readline_state::buf, ErrorContextCallback::callback, tsearch_readline_state::cb, tsearch_readline_state::curline, error_context_stack, filename, tsearch_readline_state::filename, tsearch_readline_state::fp, initStringInfo(), tsearch_readline_state::lineno, ErrorContextCallback::previous, and tsearch_readline_callback().

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().

◆ tsearch_readline_callback()

static void tsearch_readline_callback ( void *  arg)
static

Definition at line 180 of file ts_locale.c.

181{
183
184 /*
185 * We can't include the text of the config line for errors that occur
186 * during tsearch_readline() itself. The major cause of such errors is
187 * encoding violations, and we daren't try to print error messages
188 * containing badly-encoded data.
189 */
190 if (stp->curline)
191 errcontext("line %d of configuration file \"%s\": \"%s\"",
192 stp->lineno,
193 stp->filename,
194 stp->curline);
195 else
196 errcontext("line %d of configuration file \"%s\"",
197 stp->lineno,
198 stp->filename);
199}
#define errcontext
Definition: elog.h:196
void * arg

References arg, tsearch_readline_state::curline, errcontext, tsearch_readline_state::filename, and tsearch_readline_state::lineno.

Referenced by tsearch_readline_begin().

◆ tsearch_readline_end()

void tsearch_readline_end ( tsearch_readline_state stp)

Definition at line 157 of file ts_locale.c.

158{
159 /* Suppress use of curline in any error reported below */
160 if (stp->curline)
161 {
162 if (stp->curline != stp->buf.data)
163 pfree(stp->curline);
164 stp->curline = NULL;
165 }
166
167 /* Release other resources */
168 pfree(stp->buf.data);
169 FreeFile(stp->fp);
170
171 /* Pop the error context stack */
173}
int FreeFile(FILE *file)
Definition: fd.c:2803

References tsearch_readline_state::buf, tsearch_readline_state::cb, tsearch_readline_state::curline, StringInfoData::data, error_context_stack, tsearch_readline_state::fp, FreeFile(), pfree(), and ErrorContextCallback::previous.

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().