~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Init cclasses array from ctypes */
2
3
#include <my_global.h>
4
#include <m_ctype.h>
5
#include <m_string.h>
53.2.27 by Monty Taylor
Fixed some old-school style things in regex.
6
#include "my_regex.h"
1 by brian
clean slate
7
#include "cclass.h"
8
9
static my_bool regex_inited=0;
10
11
void my_regex_init(CHARSET_INFO *cs)
12
{
13
  char buff[CCLASS_LAST][256];
14
  int  count[CCLASS_LAST];
15
  uint i;
16
17
  if (!regex_inited)
18
  {
19
    regex_inited=1;
20
    bzero((uchar*) &count,sizeof(count));
21
22
    for (i=1 ; i<= 255; i++)
23
    {
24
      if (my_isalnum(cs,i))
25
	buff[CCLASS_ALNUM][count[CCLASS_ALNUM]++]=(char) i;
26
      if (my_isalpha(cs,i))
27
	buff[CCLASS_ALPHA][count[CCLASS_ALPHA]++]=(char) i;
28
      if (my_iscntrl(cs,i))
29
	buff[CCLASS_CNTRL][count[CCLASS_CNTRL]++]=(char) i;
30
      if (my_isdigit(cs,i))
31
	buff[CCLASS_DIGIT][count[CCLASS_DIGIT]++]=(char) i;
32
      if (my_isgraph(cs,i))
33
	buff[CCLASS_GRAPH][count[CCLASS_GRAPH]++]=(char) i;
34
      if (my_islower(cs,i))
35
	buff[CCLASS_LOWER][count[CCLASS_LOWER]++]=(char) i;
36
      if (my_isprint(cs,i))
37
	buff[CCLASS_PRINT][count[CCLASS_PRINT]++]=(char) i;
38
      if (my_ispunct(cs,i))
39
	buff[CCLASS_PUNCT][count[CCLASS_PUNCT]++]=(char) i;
40
      if (my_isspace(cs,i))
41
	buff[CCLASS_SPACE][count[CCLASS_SPACE]++]=(char) i;
42
      if (my_isupper(cs,i))
43
	buff[CCLASS_UPPER][count[CCLASS_UPPER]++]=(char) i;
44
      if (my_isxdigit(cs,i))
45
	buff[CCLASS_XDIGIT][count[CCLASS_XDIGIT]++]=(char) i;
46
    }
47
    buff[CCLASS_BLANK][0]=' ';
48
    buff[CCLASS_BLANK][1]='\t';
49
    count[CCLASS_BLANK]=2;
50
    for (i=0; i < CCLASS_LAST ; i++)
51
    {
52
      char *tmp=(char*) malloc(count[i]+1);
53
      if (!tmp)
54
      {
55
	/*
56
	  This is very unlikely to happen as this function is called once
57
	  at program startup
58
	*/
59
	fprintf(stderr,
60
		"Fatal error: Can't allocate memory in regex_init\n");
61
	exit(1);
62
      }
63
      memcpy(tmp,buff[i],count[i]*sizeof(char));
64
      tmp[count[i]]=0;
65
      cclasses[i].chars=tmp;
66
    }
67
  }
68
  return;
69
}
70
71
void my_regex_end()
72
{
73
  if (regex_inited)
74
  {
75
    int i;
76
    for (i=0; i < CCLASS_LAST ; i++)
77
      free((char*) cclasses[i].chars);
78
    regex_inited=0;
79
  }
80
}
81
82