~skinny.moey/drizzle/innodb-replication

« back to all changes in this revision

Viewing changes to drizzled/derror.cc

  • Committer: Monty Taylor
  • Date: 2008-08-02 01:24:51 UTC
  • mfrom: (202.3.14 gettextize)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802012451-nmql6eujc8wc8ogh
Merged in gettextize changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "mysql_priv.h"
25
25
#include <mysys/mysys_err.h>
 
26
#include <drizzled/drizzled_error_messages.h>
26
27
 
27
 
static bool read_texts(const char *file_name,const char ***point,
28
 
                       uint error_messages);
29
28
static void init_myfunc_errs(void);
30
29
 
 
30
 
 
31
 
31
32
/**
32
33
  Read messages from errorfile.
33
34
 
44
45
 
45
46
bool init_errmessage(void)
46
47
{
47
 
  const char **errmsgs, **ptr;
48
 
 
49
 
  /*
50
 
    Get a pointer to the old error messages pointer array.
51
 
    read_texts() tries to free it.
52
 
  */
53
 
  errmsgs= my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
54
 
 
55
 
  /* Read messages from file. */
56
 
  if (read_texts(ERRMSG_FILE, &errmsgs, ER_ERROR_LAST - ER_ERROR_FIRST + 1) &&
57
 
      !errmsgs)
58
 
  {
59
 
    if (!(errmsgs= (const char**) my_malloc((ER_ERROR_LAST-ER_ERROR_FIRST+1)*
60
 
                                            sizeof(char*), MYF(0))))
61
 
      return(true);
62
 
    for (ptr= errmsgs; ptr < errmsgs + ER_ERROR_LAST - ER_ERROR_FIRST; ptr++)
63
 
          *ptr= "";
64
 
  }
65
48
 
66
49
  /* Register messages for use with my_error(). */
67
 
  if (my_error_register(errmsgs, ER_ERROR_FIRST, ER_ERROR_LAST))
 
50
  if (my_error_register(drizzled_error_messages,
 
51
                        ER_ERROR_FIRST, ER_ERROR_LAST))
68
52
  {
69
 
    x_free((uchar*) errmsgs);
70
53
    return(true);
71
54
  }
72
55
 
73
 
  errmesg= errmsgs;                     /* Init global variable */
74
56
  init_myfunc_errs();                   /* Init myfunc messages */
75
57
  return(false);
76
58
}
77
59
 
78
60
 
79
61
/**
80
 
  Read text from packed textfile in language-directory.
81
 
 
82
 
  If we can't read messagefile then it's panic- we can't continue.
83
 
 
84
 
  @TODO
85
 
    Convert the character set to server system character set
86
 
*/
87
 
 
88
 
static bool read_texts(const char *file_name,const char ***point,
89
 
                       uint error_messages)
90
 
{
91
 
  register uint i;
92
 
  uint count,funktpos,textcount;
93
 
  size_t length;
94
 
  File file;
95
 
  char name[FN_REFLEN];
96
 
  uchar *buff;
97
 
  uchar head[32],*pos;
98
 
  const char *errmsg;
99
 
 
100
 
  funktpos=0;
101
 
  if ((file=my_open(fn_format(name,file_name,language,"",4),
102
 
                    O_RDONLY | O_SHARE | O_BINARY,
103
 
                    MYF(0))) < 0)
104
 
    goto err; /* purecov: inspected */
105
 
 
106
 
  funktpos=1;
107
 
  if (my_read(file,(uchar*) head,32,MYF(MY_NABP))) goto err;
108
 
  if (head[0] != (uchar) 254 || head[1] != (uchar) 254 ||
109
 
      head[2] != 2 || head[3] != 1)
110
 
    goto err; /* purecov: inspected */
111
 
  textcount=head[4];
112
 
 
113
 
  if (!head[30])
114
 
  {
115
 
    sql_print_error("Character set information not found in '%s'. \
116
 
Please install the latest version of this file.",name);
117
 
    goto err1;
118
 
  }
119
 
 
120
 
  /* TODO: Convert the character set to server system character set */
121
 
  if (!get_charset(head[30],MYF(MY_WME)))
122
 
  {
123
 
    sql_print_error("Character set #%d is not supported for messagefile '%s'",
124
 
                    (int)head[30],name);
125
 
    goto err1;
126
 
  }
127
 
 
128
 
  length=uint2korr(head+6); count=uint2korr(head+8);
129
 
 
130
 
  if (count < error_messages)
131
 
  {
132
 
    sql_print_error("\
133
 
Error message file '%s' had only %d error messages,\n\
134
 
but it should contain at least %d error messages.\n\
135
 
Check that the above file is the right version for this program!",
136
 
                    name,count,error_messages);
137
 
    VOID(my_close(file,MYF(MY_WME)));
138
 
    return(1);
139
 
  }
140
 
 
141
 
  x_free((uchar*) *point);              /* Free old language */
142
 
  if (!(*point= (const char**)
143
 
        my_malloc((size_t) (length+count*sizeof(char*)),MYF(0))))
144
 
  {
145
 
    funktpos=2;                                 /* purecov: inspected */
146
 
    goto err;                                   /* purecov: inspected */
147
 
  }
148
 
  buff= (uchar*) (*point + count);
149
 
 
150
 
  if (my_read(file, buff, (size_t) count*2,MYF(MY_NABP)))
151
 
    goto err;
152
 
  for (i=0, pos= buff ; i< count ; i++)
153
 
  {
154
 
    (*point)[i]= (char*) buff+uint2korr(pos);
155
 
    pos+=2;
156
 
  }
157
 
  if (my_read(file, buff, length, MYF(MY_NABP)))
158
 
    goto err;
159
 
 
160
 
  for (i=1 ; i < textcount ; i++)
161
 
  {
162
 
    point[i]= *point +uint2korr(head+10+i+i);
163
 
  }
164
 
  VOID(my_close(file,MYF(0)));
165
 
  return(0);
166
 
 
167
 
err:
168
 
  switch (funktpos) {
169
 
  case 2:
170
 
    errmsg= "Not enough memory for messagefile '%s'";
171
 
    break;
172
 
  case 1:
173
 
    errmsg= "Can't read from messagefile '%s'";
174
 
    break;
175
 
  default:
176
 
    errmsg= "Can't find messagefile '%s'";
177
 
    break;
178
 
  }
179
 
  sql_print_error(errmsg, name);
180
 
err1:
181
 
  if (file != FERR)
182
 
    VOID(my_close(file,MYF(MY_WME)));
183
 
  return(1);
184
 
} /* read_texts */
185
 
 
186
 
 
187
 
/**
188
62
  Initiates error-messages used by my_func-library.
189
63
*/
190
64