diff options
Diffstat (limited to 'extra/comp_err.c')
-rw-r--r-- | extra/comp_err.c | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/extra/comp_err.c b/extra/comp_err.c index 2c8d9823201..861ae8020d9 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -37,6 +37,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"; @@ -60,7 +61,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) */ @@ -88,7 +89,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 */ @@ -130,6 +131,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, @@ -206,6 +208,7 @@ static int create_header_files(struct errors *error_head) uint er_last; FILE *er_definef, *sql_statef, *er_namef; struct errors *tmp_error; + uint current_d_code; DBUG_ENTER("create_header_files"); LINT_INIT(er_last); @@ -231,13 +234,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; @@ -393,7 +405,7 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) my_free((uchar*) tmp_error->sql_code1, MYF(0)); if (tmp_error->sql_code2[0]) my_free((uchar*) tmp_error->sql_code2, MYF(0)); - my_free((uchar*) tmp_error->er_name, MYF(0)); + my_free((uchar*) tmp_error->er_name, MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) tmp_error, MYF(0)); } } @@ -406,7 +418,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; @@ -427,11 +440,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= ¤t_error->next_error; + } + } continue; } if (is_prefix(str, "default-language")) @@ -478,7 +512,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))) { @@ -493,12 +528,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); @@ -607,7 +642,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; } } @@ -827,6 +861,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 @@ -839,7 +900,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 */ @@ -969,7 +1032,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; } |