/* Header for errmsg.sys files */
uchar file_head[]= { 254, 254, 2, ERRMSG_VERSION }; /* Store positions to each error message row to store in errmsg.sys header */
uint file_pos[MAX_ROWS+1];
uint section_count,section_start;
uchar section_header[MAX_SECTIONS*2];
constchar *empty_string= ""; /* For empty states */ /* Defaultvaluesforcommandlineoptions.Seegetoptstructurefordefinitions forthese.
*/
/* Storage for languages and charsets (from start of error text file) */
struct languages
{ char *lang_long_name; /* full name of the language */ char *lang_short_name; /* abbreviation of the lang. */ struct languages *next_lang; /* Pointer to next language */
};
/* Name, code and texts (for all lang) for one error message */
struct errors
{ constchar *er_name; /* Name of the error (ER_HASHCK) */
uint d_code; /* Error code number */ constchar *sql_code1; /* sql state */ constchar *sql_code2; /* ODBC state */ struct errors *next_error; /* Pointer to next error */
DYNAMIC_ARRAY msg; /* All language texts for this error */
};
staticint create_sys_files(struct languages *lang_head, struct errors *error_head,
uint max_error,
uint error_count)
{
FILE *to;
uint i, row_nr;
ulong length;
uchar head[HEADER_LENGTH]; char outfile[FN_REFLEN], *outfile_end; long start_pos; struct message *tmp; struct languages *tmp_lang; struct errors *tmp_error;
MY_STAT stat_info;
DBUG_ENTER("create_sys_files");
/* goingoveralllanguagesandassemblingcorrespondingerrormessages
*/ for (tmp_lang= lang_head; tmp_lang; tmp_lang= tmp_lang->next_lang)
{
outfile_end= strxmov(outfile, DATADIRECTORY,
tmp_lang->lang_long_name, NullS); if (!my_stat(outfile, &stat_info,MYF(0)))
{ if (my_mkdir(outfile, 0777,MYF(0)) < 0)
{
fprintf(stderr, "Can't creqate output directory for %s\n",
outfile);
DBUG_RETURN(1);
}
}
strxmov(outfile_end, FN_ROOTDIR, OUTFILE, NullS);
if (!(to= my_fopen(outfile, O_WRONLY | FILE_BINARY, MYF(MY_WME))))
DBUG_RETURN(1);
/* 2 is for 2 bytes to store row position / error message */
start_pos= (long) (HEADER_LENGTH + (error_count + section_count) * 2);
my_fseek(to, start_pos, 0, MYF(0));
row_nr= 0; for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
{ /* dealing with messages */
tmp= find_message(tmp_error, tmp_lang->lang_short_name, FALSE);
if (!tmp)
{
fprintf(stderr, "Did not find message for %s neither in %s nor in default " "language\n", tmp_error->er_name, tmp_lang->lang_short_name); goto err;
} if (tmp->text) /* If not skipped row */
{ if (copy_rows(to, tmp->text, row_nr, start_pos))
{
fprintf(stderr, "Failed to copy rows to %s\n", outfile); goto err;
}
row_nr++;
}
}
DBUG_ASSERT(error_count == row_nr);
if (!(file= my_fopen(file_name, O_RDONLY | O_TEXT | O_SHARE, MYF(MY_WME))))
DBUG_RETURN(0);
while ((str= fgets(buff, sizeof(buff), file)))
{
my_bool skip; if (is_prefix(str, "language"))
{ if (!(*top_lang= parse_charset_string(str)))
{
fprintf(stderr, "Failed to parse the charset string!\n");
DBUG_RETURN(0);
} continue;
}
skip= 0; if (is_prefix(str, "start-error-number") ||
(skip= is_prefix(str, "skip-to-error-number")))
{
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 (skip)
{ if (section_count >= MAX_SECTIONS-1)
{
fprintf(stderr, "Found too many skip-to-error-number entries. " "We only support %d entries\n", MAX_SECTIONS);
DBUG_RETURN(0);
}
int2store(section_header + section_count*2,
er_offset +rcount - section_start);
section_count++;
section_start= tmp_er_offset;
} if (!er_offset_found)
{
er_offset_found= 1;
er_offset= section_start= 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++)
{
skiped_errors+= skip != 0;
current_error= generate_empty_message(er_offset + rcount, skip);
*tail_error= current_error;
tail_error= ¤t_error->next_error;
}
} continue;
} if (is_prefix(str, "default-language"))
{ if (!(default_language= parse_default_language(str)))
{
DBUG_PRINT("info", ("default_slang: %s", default_language));
fprintf(stderr, "Failed to parse the default language line. Aborting\n");
DBUG_RETURN(0);
}
default_language_changed= 1; continue;
}
if (*str == '\t' || *str == ' ')
{ /* New error message in another language for previous error */ if (!current_error)
{
fprintf(stderr, "Error in the input file format\n");
DBUG_RETURN(0);
} if (!parse_message_string(¤t_message, str))
{
fprintf(stderr, "Failed to parse message string for error '%s'",
current_error->er_name);
DBUG_RETURN(0);
} if (find_message(current_error, current_message.lang_short_name, TRUE))
{
fprintf(stderr, "Duplicate message string for error '%s'" " in language '%s'\n",
current_error->er_name, current_message.lang_short_name);
DBUG_RETURN(0);
} if (check_message_format(current_error, current_message.text))
{
fprintf(stderr, "Wrong formatspecifier of error message string" " for error '%s' in language '%s'\n",
current_error->er_name, current_message.lang_short_name);
DBUG_RETURN(0);
} if (insert_dynamic(¤t_error->msg, (uchar *) & current_message))
DBUG_RETURN(0); continue;
} if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) ||
is_prefix(str, ER_PREFIX2))
{ if (!(current_error= parse_error_string(str, rcount)))
{
fprintf(stderr, "Failed to parse the error name string\n");
DBUG_RETURN(0);
}
rcount++; /* Count number of unique errors */
/* add error to the list */
*tail_error= current_error;
tail_error= ¤t_error->next_error; continue;
} if (*str == '#' || *str == '\n') continue; /* skip comment or empty lines */
DBUG_ENTER("parse_error_offset"); /* skipping the "start-error-number" keyword and spaces after it */
str= find_end_of_word(str);
str= skip_delimiters(str);
if (!*str)
DBUG_RETURN(0); /* Unexpected EOL: No error number after the keyword */
/* reading the error offset */ if (!(soffset= get_word(&str)))
DBUG_RETURN(0); /* OOM: Fatal error */
DBUG_PRINT("info", ("default_error_offset: %s", soffset));
/* skipping space(s) and/or tabs after the error offset */
str= skip_delimiters(str);
DBUG_PRINT("info", ("str: %s", str)); if (*str)
{ /* The line does not end with the error offset -> error! */
fprintf(stderr, "The error offset line does not end with an error offset");
DBUG_RETURN(0);
}
DBUG_PRINT("info", ("str: %s", str));
DBUG_ENTER("parse_default_language"); /* skipping the "default-language" keyword */
str= find_end_of_word(str); /* skipping space(s) and/or tabs after the keyword */
str= skip_delimiters(str); if (!*str)
{
fprintf(stderr, "Unexpected EOL: No short language name after the keyword\n");
DBUG_RETURN(0);
}
/* reading the short language tag */ if (!(slang= get_word(&str)))
DBUG_RETURN(0); /* OOM: Fatal error */
DBUG_PRINT("info", ("default_slang: %s", slang));
str= skip_delimiters(str);
DBUG_PRINT("info", ("str: %s", str)); if (*str)
{
fprintf(stderr, "The default language line does not end with short language " "name\n");
DBUG_RETURN(0);
}
DBUG_PRINT("info", ("str: %s", str));
DBUG_RETURN(slang);
}
if (checksum_format_specifier(first->text) !=
checksum_format_specifier(mess))
{ /* Check sum of format specifiers failed, they should be equal */
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
/* if we reached EOL => no more codes, but this can happen */ if (!*str)
{
new_error->sql_code1= empty_string;
new_error->sql_code2= empty_string;
DBUG_PRINT("info", ("str: %s", str));
DBUG_RETURN(new_error);
}
/* if we reached EOL => no more codes, but this can happen */ if (!*str)
{
new_error->sql_code2= empty_string;
DBUG_PRINT("info", ("str: %s", str));
DBUG_RETURN(new_error);
}
/* getting the sql_code 2 */ if (!(new_error->sql_code2= get_word(&str)))
DBUG_RETURN(0); /* OOM: Fatal error */
DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2));
str= skip_delimiters(str); if (*str)
{
fprintf(stderr, "The error line did not end with sql/odbc code!");
DBUG_RETURN(0);
}
staticstruct languages *parse_charset_string(char *str)
{ struct languages *head=0, *new_lang;
DBUG_ENTER("parse_charset_string");
DBUG_PRINT("enter", ("str: %s", str));
/* skip over keyword */
str= find_end_of_word(str); if (!*str)
{ /* unexpected EOL */
DBUG_PRINT("info", ("str: %s", str));
DBUG_RETURN(0);
}
str= skip_delimiters(str); if (!(*str != ';' && *str))
DBUG_RETURN(0);
do
{ /*creating new element of the linked list */
new_lang= (struct languages *) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*new_lang), MYF(MY_WME));
new_lang->next_lang= head;
head= new_lang;
/* get the full language name */
if (!(new_lang->lang_long_name= get_word(&str)))
DBUG_RETURN(0); /* OOM: Fatal error */
staticvoid usage(void)
{
DBUG_ENTER("usage");
print_version();
printf("This software comes with ABSOLUTELY NO WARRANTY. " "This is free software,\n" "and you are welcome to modify and redistribute it under the GPL license.\n" "Usage:\n");
my_print_help(my_long_options);
my_print_variables(my_long_options);
DBUG_VOID_RETURN;
}
staticint get_options(int *argc, char ***argv)
{ int ho_error;
DBUG_ENTER("get_options");
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
DBUG_RETURN(ho_error);
DBUG_RETURN(0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.