mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Pgindent run for 8.0.
This commit is contained in:
@ -2,105 +2,132 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#include "regis.h"
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
RS_isRegis(const char *str) {
|
||||
unsigned char *ptr=(unsigned char *)str;
|
||||
RS_isRegis(const char *str)
|
||||
{
|
||||
unsigned char *ptr = (unsigned char *) str;
|
||||
|
||||
while(ptr && *ptr)
|
||||
if ( isalpha(*ptr) || *ptr=='[' || *ptr==']' || *ptr=='^')
|
||||
while (ptr && *ptr)
|
||||
if (isalpha(*ptr) || *ptr == '[' || *ptr == ']' || *ptr == '^')
|
||||
ptr++;
|
||||
else
|
||||
return 0;
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define RS_IN_ONEOF 1
|
||||
#define RS_IN_ONEOF 1
|
||||
#define RS_IN_ONEOF_IN 2
|
||||
#define RS_IN_NONEOF 3
|
||||
#define RS_IN_WAIT 4
|
||||
|
||||
static RegisNode*
|
||||
newRegisNode(RegisNode *prev, int len) {
|
||||
RegisNode *ptr;
|
||||
ptr = (RegisNode*)malloc(RNHDRSZ+len+1);
|
||||
static RegisNode *
|
||||
newRegisNode(RegisNode * prev, int len)
|
||||
{
|
||||
RegisNode *ptr;
|
||||
|
||||
ptr = (RegisNode *) malloc(RNHDRSZ + len + 1);
|
||||
if (!ptr)
|
||||
ts_error(ERROR, "No memory");
|
||||
memset(ptr,0,RNHDRSZ+len+1);
|
||||
ts_error(ERROR, "No memory");
|
||||
memset(ptr, 0, RNHDRSZ + len + 1);
|
||||
if (prev)
|
||||
prev->next=ptr;
|
||||
prev->next = ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int
|
||||
RS_compile(Regis *r, int issuffix, const char *str) {
|
||||
int i,len = strlen(str);
|
||||
int state = RS_IN_WAIT;
|
||||
RegisNode *ptr=NULL;
|
||||
RS_compile(Regis * r, int issuffix, const char *str)
|
||||
{
|
||||
int i,
|
||||
len = strlen(str);
|
||||
int state = RS_IN_WAIT;
|
||||
RegisNode *ptr = NULL;
|
||||
|
||||
memset(r,0,sizeof(Regis));
|
||||
memset(r, 0, sizeof(Regis));
|
||||
r->issuffix = (issuffix) ? 1 : 0;
|
||||
|
||||
for(i=0;i<len;i++) {
|
||||
unsigned char c = *( ( (unsigned char*)str ) + i );
|
||||
if ( state == RS_IN_WAIT ) {
|
||||
if ( isalpha(c) ) {
|
||||
if ( ptr )
|
||||
ptr = newRegisNode(ptr,len);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *(((unsigned char *) str) + i);
|
||||
|
||||
if (state == RS_IN_WAIT)
|
||||
{
|
||||
if (isalpha(c))
|
||||
{
|
||||
if (ptr)
|
||||
ptr = newRegisNode(ptr, len);
|
||||
else
|
||||
ptr = r->node = newRegisNode(NULL,len);
|
||||
ptr->data[ 0 ] = c;
|
||||
ptr = r->node = newRegisNode(NULL, len);
|
||||
ptr->data[0] = c;
|
||||
ptr->type = RSF_ONEOF;
|
||||
ptr->len=1;
|
||||
} else if ( c=='[' ) {
|
||||
if ( ptr )
|
||||
ptr = newRegisNode(ptr,len);
|
||||
ptr->len = 1;
|
||||
}
|
||||
else if (c == '[')
|
||||
{
|
||||
if (ptr)
|
||||
ptr = newRegisNode(ptr, len);
|
||||
else
|
||||
ptr = r->node = newRegisNode(NULL,len);
|
||||
ptr = r->node = newRegisNode(NULL, len);
|
||||
ptr->type = RSF_ONEOF;
|
||||
state=RS_IN_ONEOF;
|
||||
} else
|
||||
ts_error(ERROR,"Error in regis: %s at pos %d\n", str, i+1);
|
||||
} else if ( state == RS_IN_ONEOF ) {
|
||||
if ( c=='^' ) {
|
||||
state = RS_IN_ONEOF;
|
||||
}
|
||||
else
|
||||
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
|
||||
}
|
||||
else if (state == RS_IN_ONEOF)
|
||||
{
|
||||
if (c == '^')
|
||||
{
|
||||
ptr->type = RSF_NONEOF;
|
||||
state=RS_IN_NONEOF;
|
||||
} else if ( isalpha(c) ) {
|
||||
ptr->data[ 0 ] = c;
|
||||
ptr->len=1;
|
||||
state=RS_IN_ONEOF_IN;
|
||||
} else
|
||||
ts_error(ERROR,"Error in regis: %s at pos %d\n", str, i+1);
|
||||
} else if ( state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF ) {
|
||||
if ( isalpha(c) ) {
|
||||
ptr->data[ ptr->len ] = c;
|
||||
state = RS_IN_NONEOF;
|
||||
}
|
||||
else if (isalpha(c))
|
||||
{
|
||||
ptr->data[0] = c;
|
||||
ptr->len = 1;
|
||||
state = RS_IN_ONEOF_IN;
|
||||
}
|
||||
else
|
||||
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
|
||||
}
|
||||
else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
|
||||
{
|
||||
if (isalpha(c))
|
||||
{
|
||||
ptr->data[ptr->len] = c;
|
||||
ptr->len++;
|
||||
} else if ( c==']' ) {
|
||||
state=RS_IN_WAIT;
|
||||
} else
|
||||
ts_error(ERROR,"Error in regis: %s at pos %d\n", str, i+1);
|
||||
} else
|
||||
ts_error(ERROR,"Internal error in RS_compile: %d\n", state);
|
||||
}
|
||||
else if (c == ']')
|
||||
state = RS_IN_WAIT;
|
||||
else
|
||||
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
|
||||
}
|
||||
else
|
||||
ts_error(ERROR, "Internal error in RS_compile: %d\n", state);
|
||||
}
|
||||
|
||||
ptr = r->node;
|
||||
while(ptr) {
|
||||
while (ptr)
|
||||
{
|
||||
r->nchar++;
|
||||
ptr=ptr->next;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RS_free(Regis *r) {
|
||||
RegisNode *ptr=r->node,*tmp;
|
||||
void
|
||||
RS_free(Regis * r)
|
||||
{
|
||||
RegisNode *ptr = r->node,
|
||||
*tmp;
|
||||
|
||||
while(ptr) {
|
||||
tmp=ptr->next;
|
||||
while (ptr)
|
||||
{
|
||||
tmp = ptr->next;
|
||||
free(ptr);
|
||||
ptr = tmp;
|
||||
}
|
||||
@ -108,42 +135,49 @@ RS_free(Regis *r) {
|
||||
r->node = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
RS_execute(Regis *r, const char *str, int len) {
|
||||
RegisNode *ptr=r->node;
|
||||
int
|
||||
RS_execute(Regis * r, const char *str, int len)
|
||||
{
|
||||
RegisNode *ptr = r->node;
|
||||
unsigned char *c;
|
||||
|
||||
if (len<0)
|
||||
len=strlen(str);
|
||||
if (len < 0)
|
||||
len = strlen(str);
|
||||
|
||||
if (len<r->nchar)
|
||||
if (len < r->nchar)
|
||||
return 0;
|
||||
|
||||
if ( r->issuffix )
|
||||
c = ((unsigned char*)str) + len - r->nchar;
|
||||
if (r->issuffix)
|
||||
c = ((unsigned char *) str) + len - r->nchar;
|
||||
else
|
||||
c = (unsigned char*)str;
|
||||
c = (unsigned char *) str;
|
||||
|
||||
while(ptr) {
|
||||
switch(ptr->type) {
|
||||
while (ptr)
|
||||
{
|
||||
switch (ptr->type)
|
||||
{
|
||||
case RSF_ONEOF:
|
||||
if ( ptr->len==0 ) {
|
||||
if ( *c != *(ptr->data) )
|
||||
if (ptr->len == 0)
|
||||
{
|
||||
if (*c != *(ptr->data))
|
||||
return 0;
|
||||
} else if ( strchr((char*)ptr->data, *c) == NULL )
|
||||
}
|
||||
else if (strchr((char *) ptr->data, *c) == NULL)
|
||||
return 0;
|
||||
break;
|
||||
case RSF_NONEOF:
|
||||
if ( ptr->len==0 ) {
|
||||
if ( *c == *(ptr->data) )
|
||||
if (ptr->len == 0)
|
||||
{
|
||||
if (*c == *(ptr->data))
|
||||
return 0;
|
||||
} else if ( strchr((char*)ptr->data, *c) != NULL )
|
||||
}
|
||||
else if (strchr((char *) ptr->data, *c) != NULL)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
ts_error(ERROR,"RS_execute: Unknown type node: %d\n", ptr->type);
|
||||
ts_error(ERROR, "RS_execute: Unknown type node: %d\n", ptr->type);
|
||||
}
|
||||
ptr=ptr->next;
|
||||
ptr = ptr->next;
|
||||
c++;
|
||||
}
|
||||
|
||||
|
@ -1,34 +1,38 @@
|
||||
#ifndef __REGIS_H__
|
||||
#define __REGIS_H__
|
||||
|
||||
#include "postgres.h"
|
||||
#include "postgres.h"
|
||||
|
||||
typedef struct RegisNode {
|
||||
uint32
|
||||
type:2,
|
||||
len:16,
|
||||
unused:14;
|
||||
typedef struct RegisNode
|
||||
{
|
||||
uint32
|
||||
type:2,
|
||||
len:16,
|
||||
unused:14;
|
||||
struct RegisNode *next;
|
||||
unsigned char data[1];
|
||||
} RegisNode;
|
||||
unsigned char data[1];
|
||||
} RegisNode;
|
||||
|
||||
#define RNHDRSZ (sizeof(uint32)+sizeof(void*))
|
||||
#define RNHDRSZ (sizeof(uint32)+sizeof(void*))
|
||||
|
||||
#define RSF_ONEOF 1
|
||||
#define RSF_NONEOF 2
|
||||
#define RSF_ONEOF 1
|
||||
#define RSF_NONEOF 2
|
||||
|
||||
typedef struct Regis {
|
||||
RegisNode *node;
|
||||
uint32
|
||||
issuffix:1,
|
||||
nchar:16,
|
||||
unused:15;
|
||||
} Regis;
|
||||
typedef struct Regis
|
||||
{
|
||||
RegisNode *node;
|
||||
uint32
|
||||
issuffix:1,
|
||||
nchar:16,
|
||||
unused:15;
|
||||
} Regis;
|
||||
|
||||
int RS_isRegis(const char *str);
|
||||
int RS_isRegis(const char *str);
|
||||
|
||||
int RS_compile(Regis * r, int issuffix, const char *str);
|
||||
void RS_free(Regis * r);
|
||||
|
||||
int RS_compile(Regis *r, int issuffix, const char *str);
|
||||
void RS_free(Regis *r);
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
int RS_execute(Regis *r, const char *str, int len);
|
||||
int RS_execute(Regis * r, const char *str, int len);
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,19 +10,21 @@
|
||||
struct SPNode;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32
|
||||
val:8,
|
||||
isword:1,
|
||||
compoundallow:1,
|
||||
affix:22;
|
||||
struct SPNode *node;
|
||||
} SPNodeData;
|
||||
typedef struct
|
||||
{
|
||||
uint32
|
||||
val:8,
|
||||
isword:1,
|
||||
compoundallow:1,
|
||||
affix:22;
|
||||
struct SPNode *node;
|
||||
} SPNodeData;
|
||||
|
||||
typedef struct SPNode {
|
||||
uint32 length;
|
||||
SPNodeData data[1];
|
||||
} SPNode;
|
||||
typedef struct SPNode
|
||||
{
|
||||
uint32 length;
|
||||
SPNodeData data[1];
|
||||
} SPNode;
|
||||
|
||||
#define SPNHRDSZ (sizeof(uint32))
|
||||
|
||||
@ -30,81 +32,87 @@ typedef struct SPNode {
|
||||
typedef struct spell_struct
|
||||
{
|
||||
char *word;
|
||||
union {
|
||||
union
|
||||
{
|
||||
char flag[16];
|
||||
struct {
|
||||
int affix;
|
||||
int len;
|
||||
} d;
|
||||
} p;
|
||||
struct
|
||||
{
|
||||
int affix;
|
||||
int len;
|
||||
} d;
|
||||
} p;
|
||||
} SPELL;
|
||||
|
||||
typedef struct aff_struct
|
||||
{
|
||||
uint32
|
||||
flag:8,
|
||||
type:2,
|
||||
compile:1,
|
||||
flagflags:3,
|
||||
issimple:1,
|
||||
isregis:1,
|
||||
unused:1,
|
||||
replen:16;
|
||||
char mask[32];
|
||||
char find[16];
|
||||
char repl[16];
|
||||
union {
|
||||
regex_t regex;
|
||||
Regis regis;
|
||||
} reg;
|
||||
uint32
|
||||
flag:8,
|
||||
type:2,
|
||||
compile:1,
|
||||
flagflags:3,
|
||||
issimple:1,
|
||||
isregis:1,
|
||||
unused:1,
|
||||
replen:16;
|
||||
char mask[32];
|
||||
char find[16];
|
||||
char repl[16];
|
||||
union
|
||||
{
|
||||
regex_t regex;
|
||||
Regis regis;
|
||||
} reg;
|
||||
} AFFIX;
|
||||
|
||||
#define FF_CROSSPRODUCT 0x01
|
||||
#define FF_COMPOUNDWORD 0x02
|
||||
#define FF_COMPOUNDONLYAFX 0x04
|
||||
#define FF_SUFFIX 2
|
||||
#define FF_PREFIX 1
|
||||
#define FF_CROSSPRODUCT 0x01
|
||||
#define FF_COMPOUNDWORD 0x02
|
||||
#define FF_COMPOUNDONLYAFX 0x04
|
||||
#define FF_SUFFIX 2
|
||||
#define FF_PREFIX 1
|
||||
|
||||
struct AffixNode;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint32
|
||||
val:8,
|
||||
naff:24;
|
||||
AFFIX **aff;
|
||||
val:8,
|
||||
naff:24;
|
||||
AFFIX **aff;
|
||||
struct AffixNode *node;
|
||||
} AffixNodeData;
|
||||
} AffixNodeData;
|
||||
|
||||
typedef struct AffixNode {
|
||||
uint32 isvoid:1,
|
||||
length:31;
|
||||
AffixNodeData data[1];
|
||||
} AffixNode;
|
||||
typedef struct AffixNode
|
||||
{
|
||||
uint32 isvoid:1,
|
||||
length:31;
|
||||
AffixNodeData data[1];
|
||||
} AffixNode;
|
||||
|
||||
#define ANHRDSZ (sizeof(uint32))
|
||||
#define ANHRDSZ (sizeof(uint32))
|
||||
|
||||
typedef struct {
|
||||
char *affix;
|
||||
int len;
|
||||
} CMPDAffix;
|
||||
typedef struct
|
||||
{
|
||||
char *affix;
|
||||
int len;
|
||||
} CMPDAffix;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int maffixes;
|
||||
int naffixes;
|
||||
AFFIX *Affix;
|
||||
char compoundcontrol;
|
||||
char compoundcontrol;
|
||||
|
||||
int nspell;
|
||||
int mspell;
|
||||
SPELL *Spell;
|
||||
|
||||
AffixNode *Suffix;
|
||||
AffixNode *Prefix;
|
||||
AffixNode *Suffix;
|
||||
AffixNode *Prefix;
|
||||
|
||||
SPNode *Dictionary;
|
||||
char **AffixData;
|
||||
CMPDAffix *CompoundAffix;
|
||||
SPNode *Dictionary;
|
||||
char **AffixData;
|
||||
CMPDAffix *CompoundAffix;
|
||||
|
||||
} IspellDict;
|
||||
|
||||
|
Reference in New Issue
Block a user