1
0
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:
Bruce Momjian
2004-08-29 05:07:03 +00:00
parent 90cb9c3051
commit b6b71b85bc
527 changed files with 20550 additions and 18283 deletions

View File

@ -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++;
}