Commit c0eebb83 authored by Monty's avatar Monty

Fixed but when generating .sys files

parent cdd40431
...@@ -145,7 +145,8 @@ static struct message *find_message(struct errors *err, const char *lang, ...@@ -145,7 +145,8 @@ static struct message *find_message(struct errors *err, const char *lang,
static int check_message_format(struct errors *err, static int check_message_format(struct errors *err,
const char* mess); const char* mess);
static uint parse_input_file(const char *file_name, struct errors **top_error, static uint parse_input_file(const char *file_name, struct errors **top_error,
struct languages **top_language); struct languages **top_language,
uint *error_count);
static int get_options(int *argc, char ***argv); static int get_options(int *argc, char ***argv);
static void print_version(void); static void print_version(void);
static void usage(void); static void usage(void);
...@@ -162,14 +163,15 @@ static char *find_end_of_word(char *str); ...@@ -162,14 +163,15 @@ static char *find_end_of_word(char *str);
static void clean_up(struct languages *lang_head, struct errors *error_head); static void clean_up(struct languages *lang_head, struct errors *error_head);
static int create_header_files(struct errors *error_head); static int create_header_files(struct errors *error_head);
static int create_sys_files(struct languages *lang_head, static int create_sys_files(struct languages *lang_head,
struct errors *error_head, uint row_count); struct errors *error_head, uint max_error,
uint error_count);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
MY_INIT(argv[0]); MY_INIT(argv[0]);
{ {
uint row_count; uint max_error, error_count;
struct errors *error_head; struct errors *error_head;
struct languages *lang_head; struct languages *lang_head;
DBUG_ENTER("main"); DBUG_ENTER("main");
...@@ -177,32 +179,39 @@ int main(int argc, char *argv[]) ...@@ -177,32 +179,39 @@ int main(int argc, char *argv[])
charsets_dir= DEFAULT_CHARSET_DIR; charsets_dir= DEFAULT_CHARSET_DIR;
my_umask_dir= 0777; my_umask_dir= 0777;
if (get_options(&argc, &argv)) if (get_options(&argc, &argv))
DBUG_RETURN(1); goto err;
if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head))) if (!(max_error= parse_input_file(TXTFILE, &error_head, &lang_head,
&error_count)))
{ {
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
DBUG_RETURN(1); goto err;
} }
if (lang_head == NULL || error_head == NULL) if (lang_head == NULL || error_head == NULL)
{ {
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
DBUG_RETURN(1); goto err;
} }
if (create_header_files(error_head)) if (create_header_files(error_head))
{ {
fprintf(stderr, "Failed to create header files\n"); fprintf(stderr, "Failed to create header files\n");
DBUG_RETURN(1); goto err;
} }
if (create_sys_files(lang_head, error_head, row_count)) if (create_sys_files(lang_head, error_head, max_error, error_count))
{ {
fprintf(stderr, "Failed to create sys files\n"); fprintf(stderr, "Failed to create sys files\n");
DBUG_RETURN(1); goto err;
} }
clean_up(lang_head, error_head); clean_up(lang_head, error_head);
DBUG_LEAVE; /* Can't use dbug after my_end() */ DBUG_LEAVE; /* Can't use dbug after my_end() */
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
return 0; return 0;
err:
clean_up(lang_head, error_head);
DBUG_LEAVE; /* Can't use dbug after my_end() */
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
exit(1);
} }
} }
...@@ -313,7 +322,9 @@ static int create_header_files(struct errors *error_head) ...@@ -313,7 +322,9 @@ static int create_header_files(struct errors *error_head)
static int create_sys_files(struct languages *lang_head, static int create_sys_files(struct languages *lang_head,
struct errors *error_head, uint row_count) struct errors *error_head,
uint max_error,
uint error_count)
{ {
FILE *to; FILE *to;
uint csnum= 0, length, i, row_nr; uint csnum= 0, length, i, row_nr;
...@@ -358,8 +369,8 @@ static int create_sys_files(struct languages *lang_head, ...@@ -358,8 +369,8 @@ static int create_sys_files(struct languages *lang_head,
DBUG_RETURN(1); DBUG_RETURN(1);
/* 2 is for 2 bytes to store row position / error message */ /* 2 is for 2 bytes to store row position / error message */
start_pos= (long) (HEADER_LENGTH + (row_count + section_count) * 2); start_pos= (long) (HEADER_LENGTH + (error_count + section_count) * 2);
fseek(to, start_pos, 0); my_fseek(to, start_pos, 0, MYF(0));
row_nr= 0; row_nr= 0;
for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error) for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
{ {
...@@ -383,15 +394,18 @@ static int create_sys_files(struct languages *lang_head, ...@@ -383,15 +394,18 @@ static int create_sys_files(struct languages *lang_head,
row_nr++; row_nr++;
} }
} }
DBUG_ASSERT(error_count == row_nr);
/* continue with header of the errmsg.sys file */ /* continue with header of the errmsg.sys file */
length= ftell(to) - HEADER_LENGTH - (row_count + section_count) * 2; length= (my_ftell(to, MYF(0)) - HEADER_LENGTH -
(error_count + section_count) * 2);
bzero((uchar*) head, HEADER_LENGTH); bzero((uchar*) head, HEADER_LENGTH);
bmove((uchar *) head, (uchar *) file_head, 4); bmove((uchar*) head, (uchar*) file_head, 4);
head[4]= 1; head[4]= 1;
int4store(head + 6, length); int4store(head + 6, length);
int2store(head + 10, row_count); int2store(head + 10, max_error); /* Max error */
int2store(head + 12, section_count); int2store(head + 12, row_nr);
int2store(head + 14, section_count);
head[30]= csnum; head[30]= csnum;
my_fseek(to, 0l, MY_SEEK_SET, MYF(0)); my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
...@@ -400,8 +414,8 @@ static int create_sys_files(struct languages *lang_head, ...@@ -400,8 +414,8 @@ static int create_sys_files(struct languages *lang_head,
MYF(MY_WME | MY_FNABP))) MYF(MY_WME | MY_FNABP)))
goto err; goto err;
file_pos[row_count]= (ftell(to) - start_pos); file_pos[row_nr]= (ftell(to) - start_pos);
for (i= 0; i < row_count; i++) for (i= 0; i < row_nr; i++)
{ {
/* Store length of each string */ /* Store length of each string */
int2store(head, file_pos[i+1] - file_pos[i]); int2store(head, file_pos[i+1] - file_pos[i]);
...@@ -459,18 +473,19 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) ...@@ -459,18 +473,19 @@ static void clean_up(struct languages *lang_head, struct errors *error_head)
static uint parse_input_file(const char *file_name, struct errors **top_error, static uint parse_input_file(const char *file_name, struct errors **top_error,
struct languages **top_lang) struct languages **top_lang, uint *error_count)
{ {
FILE *file; FILE *file;
char *str, buff[1000]; char *str, buff[1000];
struct errors *current_error= 0, **tail_error= top_error; struct errors *current_error= 0, **tail_error= top_error;
struct message current_message; struct message current_message;
uint rcount= 0; uint rcount= 0, skiped_errors= 0;
my_bool er_offset_found= 0; my_bool er_offset_found= 0;
DBUG_ENTER("parse_input_file"); DBUG_ENTER("parse_input_file");
*top_error= 0; *top_error= 0;
*top_lang= 0; *top_lang= 0;
*error_count= 0;
section_start= er_offset; section_start= er_offset;
section_count= 0; section_count= 0;
...@@ -528,6 +543,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error, ...@@ -528,6 +543,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
} }
for ( ; er_offset + rcount < tmp_er_offset ; rcount++) for ( ; er_offset + rcount < tmp_er_offset ; rcount++)
{ {
skiped_errors+= skip != 0;
current_error= generate_empty_message(er_offset + rcount, skip); current_error= generate_empty_message(er_offset + rcount, skip);
*tail_error= current_error; *tail_error= current_error;
tail_error= &current_error->next_error; tail_error= &current_error->next_error;
...@@ -603,6 +619,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error, ...@@ -603,6 +619,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
int2store(section_header + section_count*2, int2store(section_header + section_count*2,
er_offset + rcount - section_start); er_offset + rcount - section_start);
section_count++; section_count++;
*error_count= rcount - skiped_errors;
*tail_error= 0; /* Mark end of list */ *tail_error= 0; /* Mark end of list */
...@@ -1119,10 +1136,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)), ...@@ -1119,10 +1136,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
switch (optid) { switch (optid) {
case 'V': case 'V':
print_version(); print_version();
my_end(0);
exit(0); exit(0);
break; break;
case '?': case '?':
usage(); usage();
my_end(0);
exit(0); exit(0);
break; break;
case '#': case '#':
......
...@@ -176,6 +176,7 @@ static bool check_error_mesg(const char *file_name, const char **errmsg) ...@@ -176,6 +176,7 @@ static bool check_error_mesg(const char *file_name, const char **errmsg)
struct st_msg_file struct st_msg_file
{ {
uint sections; uint sections;
uint max_error;
uint errors; uint errors;
size_t text_length; size_t text_length;
}; };
...@@ -224,10 +225,11 @@ static File open_error_msg_file(const char *file_name, const char *language, ...@@ -224,10 +225,11 @@ static File open_error_msg_file(const char *file_name, const char *language,
goto err; /* purecov: inspected */ goto err; /* purecov: inspected */
ret->text_length= uint4korr(head+6); ret->text_length= uint4korr(head+6);
ret->errors= uint2korr(head+10); ret->max_error= uint2korr(head+10);
ret->sections= uint2korr(head+12); ret->errors= uint2korr(head+12);
ret->sections= uint2korr(head+14);
if (ret->errors < error_messages || ret->sections != MAX_ERROR_RANGES) if (ret->max_error < error_messages || ret->sections != MAX_ERROR_RANGES)
{ {
sql_print_error("\ sql_print_error("\
Error message file '%s' had only %d error messages, but it should contain at least %d error messages.\nCheck that the above file is the right version for this program!", Error message file '%s' had only %d error messages, but it should contain at least %d error messages.\nCheck that the above file is the right version for this program!",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment