~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to regex/reginit.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

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