summaryrefslogtreecommitdiff
path: root/extra/comp_err.c
diff options
context:
space:
mode:
Diffstat (limited to 'extra/comp_err.c')
-rw-r--r--extra/comp_err.c86
1 files changed, 74 insertions, 12 deletions
diff --git a/extra/comp_err.c b/extra/comp_err.c
index c3d8f8ac01b..f1159232087 100644
--- a/extra/comp_err.c
+++ b/extra/comp_err.c
@@ -34,6 +34,7 @@
#define HEADER_LENGTH 32 /* Length of header in errmsg.sys */
#define DEFAULT_CHARSET_DIR "../sql/share/charsets"
#define ER_PREFIX "ER_"
+#define ER_PREFIX2 "MARIA_ER_"
#define WARN_PREFIX "WARN_"
static char *OUTFILE= (char*) "errmsg.sys";
static char *HEADERFILE= (char*) "mysqld_error.h";
@@ -57,7 +58,7 @@ const char *empty_string= ""; /* For empty states */
*/
const char *default_language= "eng";
-int er_offset= 1000;
+uint er_offset= 1000;
my_bool info_flag= 0;
/* Storage of one error message row (for one language) */
@@ -85,7 +86,7 @@ struct languages
struct errors
{
const char *er_name; /* Name of the error (ER_HASHCK) */
- int d_code; /* Error code number */
+ uint d_code; /* Error code number */
const char *sql_code1; /* sql state */
const char *sql_code2; /* ODBC state */
struct errors *next_error; /* Pointer to next error */
@@ -127,6 +128,7 @@ static struct my_option my_long_options[]=
};
+static struct errors *generate_empty_message(uint dcode);
static struct languages *parse_charset_string(char *str);
static struct errors *parse_error_string(char *ptr, int er_count);
static struct message *parse_message_string(struct message *new_message,
@@ -225,7 +227,7 @@ static int create_header_files(struct errors *error_head)
struct errors *tmp_error;
struct message *er_msg;
const char *er_text;
-
+ uint current_d_code;
DBUG_ENTER("create_header_files");
if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
@@ -250,13 +252,22 @@ static int create_header_files(struct errors *error_head)
fprintf(er_definef, "#define ER_ERROR_FIRST %d\n", error_head->d_code);
+ current_d_code= error_head->d_code -1;
for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
{
/*
generating mysqld_error.h
fprintf() will automatically add \r on windows
*/
- fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
+
+ if (!tmp_error->er_name)
+ continue; /* Placeholder for gap */
+
+ if (tmp_error->d_code > current_d_code + 1)
+ fprintf(er_definef, "\n/* New section */\n\n");
+ current_d_code= tmp_error->d_code;
+
+ fprintf(er_definef, "#define %s %u\n", tmp_error->er_name,
tmp_error->d_code);
er_last= tmp_error->d_code;
@@ -428,7 +439,8 @@ static int parse_input_file(const char *file_name, struct errors **top_error,
char *str, buff[1000];
struct errors *current_error= 0, **tail_error= top_error;
struct message current_message;
- int rcount= 0;
+ uint rcount= 0;
+ my_bool er_offset_found= 0;
DBUG_ENTER("parse_input_file");
*top_error= 0;
@@ -449,11 +461,32 @@ static int parse_input_file(const char *file_name, struct errors **top_error,
}
if (is_prefix(str, "start-error-number"))
{
- if (!(er_offset= parse_error_offset(str)))
+ uint tmp_er_offset;
+ if (!(tmp_er_offset= parse_error_offset(str)))
{
fprintf(stderr, "Failed to parse the error offset string!\n");
DBUG_RETURN(0);
}
+ if (!er_offset_found)
+ {
+ er_offset_found= 1;
+ er_offset= tmp_er_offset;
+ }
+ else
+ {
+ /* Create empty error messages between er_offset and tmp_err_offset */
+ if (tmp_er_offset < er_offset + rcount)
+ {
+ fprintf(stderr, "new start-error-number %u is smaller than current error message: %u\n", tmp_er_offset, er_offset + rcount);
+ DBUG_RETURN(0);
+ }
+ for ( ; er_offset + rcount < tmp_er_offset ; rcount++)
+ {
+ current_error= generate_empty_message(er_offset + rcount);
+ *tail_error= current_error;
+ tail_error= &current_error->next_error;
+ }
+ }
continue;
}
if (is_prefix(str, "default-language"))
@@ -500,7 +533,8 @@ static int parse_input_file(const char *file_name, struct errors **top_error,
DBUG_RETURN(0);
continue;
}
- if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
+ if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) ||
+ is_prefix(str, ER_PREFIX2))
{
if (!(current_error= parse_error_string(str, rcount)))
{
@@ -515,12 +549,12 @@ static int parse_input_file(const char *file_name, struct errors **top_error,
continue;
}
if (*str == '#' || *str == '\n')
- continue; /* skip comment or empty lines */
+ continue; /* skip comment or empty lines */
fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
DBUG_RETURN(0);
}
- *tail_error= 0; /* Mark end of list */
+ *tail_error= 0; /* Mark end of list */
my_fclose(file, MYF(0));
DBUG_RETURN(rcount);
@@ -629,7 +663,6 @@ static struct message *find_message(struct errors *err, const char *lang,
DBUG_RETURN(tmp);
if (!strcmp(tmp->lang_short_name, default_language))
{
- DBUG_ASSERT(tmp->text[0] != 0);
return_val= tmp;
}
}
@@ -849,6 +882,33 @@ static struct message *parse_message_string(struct message *new_message,
}
+static struct errors *generate_empty_message(uint d_code)
+{
+ struct errors *new_error;
+ struct message message;
+
+ /* create a new element */
+ if (!(new_error= (struct errors *) my_malloc(sizeof(*new_error),
+ MYF(MY_WME))))
+ return(0);
+ if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 1))
+ return(0); /* OOM: Fatal error */
+
+ new_error->er_name= NULL;
+ new_error->d_code= d_code;
+ new_error->sql_code1= empty_string;
+ new_error->sql_code2= empty_string;
+
+ if (!(message.lang_short_name= my_strdup(default_language, MYF(MY_WME))) ||
+ !(message.text= my_strdup("", MYF(MY_WME))))
+ return(0);
+
+ /* Can't fail as msg is preallocated */
+ (void) insert_dynamic(&new_error->msg, (uchar*) &message);
+ return(new_error);
+}
+
+
/*
Parsing the string with error name and codes; returns the pointer to
the errors struct
@@ -861,7 +921,9 @@ static struct errors *parse_error_string(char *str, int er_count)
DBUG_PRINT("enter", ("str: %s", str));
/* create a new element */
- new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
+ if (!(new_error= (struct errors *) my_malloc(sizeof(*new_error),
+ MYF(MY_WME))))
+ DBUG_RETURN(0);
if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
DBUG_RETURN(0); /* OOM: Fatal error */
@@ -991,7 +1053,7 @@ static struct languages *parse_charset_string(char *str)
static void print_version(void)
{
DBUG_ENTER("print_version");
- printf("%s (Compile errormessage) Ver %s\n", my_progname, "2.0");
+ printf("%s (Compile errormessage) Ver %s\n", my_progname, "3.0");
DBUG_VOID_RETURN;
}