aboutsummaryrefslogtreecommitdiff
path: root/contrib/tsearch2/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tsearch2/common.c')
-rw-r--r--contrib/tsearch2/common.c101
1 files changed, 60 insertions, 41 deletions
diff --git a/contrib/tsearch2/common.c b/contrib/tsearch2/common.c
index 917dced87fa..30062180076 100644
--- a/contrib/tsearch2/common.c
+++ b/contrib/tsearch2/common.c
@@ -4,80 +4,99 @@
#include "ts_cfg.h"
#include "dict.h"
-text*
-char2text(char* in) {
+text *
+char2text(char *in)
+{
return charl2text(in, strlen(in));
}
-text* charl2text(char* in, int len) {
- text *out=(text*)palloc(len+VARHDRSZ);
+text *
+charl2text(char *in, int len)
+{
+ text *out = (text *) palloc(len + VARHDRSZ);
+
memcpy(VARDATA(out), in, len);
- VARATT_SIZEP(out) = len+VARHDRSZ;
+ VARATT_SIZEP(out) = len + VARHDRSZ;
return out;
}
-char
-*text2char(text* in) {
- char *out=palloc( VARSIZE(in) );
- memcpy(out, VARDATA(in), VARSIZE(in)-VARHDRSZ);
- out[ VARSIZE(in)-VARHDRSZ ] ='\0';
+char
+ *
+text2char(text *in)
+{
+ char *out = palloc(VARSIZE(in));
+
+ memcpy(out, VARDATA(in), VARSIZE(in) - VARHDRSZ);
+ out[VARSIZE(in) - VARHDRSZ] = '\0';
return out;
}
-char
-*pnstrdup(char* in, int len) {
- char *out=palloc( len+1 );
+char
+ *
+pnstrdup(char *in, int len)
+{
+ char *out = palloc(len + 1);
+
memcpy(out, in, len);
- out[len]='\0';
+ out[len] = '\0';
return out;
}
-text
-*ptextdup(text* in) {
- text *out=(text*)palloc( VARSIZE(in) );
- memcpy(out,in,VARSIZE(in));
+text
+ *
+ptextdup(text *in)
+{
+ text *out = (text *) palloc(VARSIZE(in));
+
+ memcpy(out, in, VARSIZE(in));
return out;
}
-text
-*mtextdup(text* in) {
- text *out=(text*)malloc( VARSIZE(in) );
- if ( !out )
+text
+ *
+mtextdup(text *in)
+{
+ text *out = (text *) malloc(VARSIZE(in));
+
+ if (!out)
ts_error(ERROR, "No memory");
- memcpy(out,in,VARSIZE(in));
+ memcpy(out, in, VARSIZE(in));
return out;
}
-void
-ts_error(int state, const char *format, ...) {
- va_list args;
- int tlen = 128, len=0;
- char *buf;
-
+void
+ts_error(int state, const char *format,...)
+{
+ va_list args;
+ int tlen = 128,
+ len = 0;
+ char *buf;
+
reset_cfg();
reset_dict();
reset_prs();
va_start(args, format);
buf = palloc(tlen);
- len = vsnprintf(buf, tlen-1, format, args);
- if ( len >= tlen ) {
- tlen=len+1;
- buf = repalloc( buf, tlen );
- vsnprintf(buf, tlen-1, format, args);
+ len = vsnprintf(buf, tlen - 1, format, args);
+ if (len >= tlen)
+ {
+ tlen = len + 1;
+ buf = repalloc(buf, tlen);
+ vsnprintf(buf, tlen - 1, format, args);
}
va_end(args);
-
+
/* ?? internal error ?? */
elog(state, "%s", buf);
pfree(buf);
}
-int
-text_cmp(text *a, text *b) {
- if ( VARSIZE(a) == VARSIZE(b) )
- return strncmp( VARDATA(a), VARDATA(b), VARSIZE(a)-VARHDRSZ );
- return (int)VARSIZE(a) - (int)VARSIZE(b);
+int
+text_cmp(text *a, text *b)
+{
+ if (VARSIZE(a) == VARSIZE(b))
+ return strncmp(VARDATA(a), VARDATA(b), VARSIZE(a) - VARHDRSZ);
+ return (int) VARSIZE(a) - (int) VARSIZE(b);
}
-