summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2016-04-06 01:18:38 +0300
committerMonty <monty@mariadb.org>2016-04-06 01:18:38 +0300
commitc0eebb831eb2fe5b18df830c5c7a4c1566028805 (patch)
tree2f05a82739dbfd57b5bcda0472564eb802db32f2 /extra
parentcdd404311792302a27242ba1f210be3addda6405 (diff)
downloadmariadb-git-c0eebb831eb2fe5b18df830c5c7a4c1566028805.tar.gz
Fixed but when generating .sys files
Diffstat (limited to 'extra')
-rw-r--r--extra/comp_err.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/extra/comp_err.c b/extra/comp_err.c
index b4f9db90509..2bab6b60be7 100644
--- a/extra/comp_err.c
+++ b/extra/comp_err.c
@@ -145,7 +145,8 @@ static struct message *find_message(struct errors *err, const char *lang,
static int check_message_format(struct errors *err,
const char* mess);
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 void print_version(void);
static void usage(void);
@@ -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 int create_header_files(struct errors *error_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[])
{
MY_INIT(argv[0]);
{
- uint row_count;
+ uint max_error, error_count;
struct errors *error_head;
struct languages *lang_head;
DBUG_ENTER("main");
@@ -177,32 +179,39 @@ int main(int argc, char *argv[])
charsets_dir= DEFAULT_CHARSET_DIR;
my_umask_dir= 0777;
if (get_options(&argc, &argv))
- DBUG_RETURN(1);
- if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head)))
+ goto err;
+ if (!(max_error= parse_input_file(TXTFILE, &error_head, &lang_head,
+ &error_count)))
{
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
- DBUG_RETURN(1);
+ goto err;
}
if (lang_head == NULL || error_head == NULL)
{
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
- DBUG_RETURN(1);
+ goto err;
}
if (create_header_files(error_head))
{
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");
- DBUG_RETURN(1);
+ goto 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);
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)
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;
uint csnum= 0, length, i, row_nr;
@@ -358,8 +369,8 @@ static int create_sys_files(struct languages *lang_head,
DBUG_RETURN(1);
/* 2 is for 2 bytes to store row position / error message */
- start_pos= (long) (HEADER_LENGTH + (row_count + section_count) * 2);
- fseek(to, start_pos, 0);
+ 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)
{
@@ -383,15 +394,18 @@ static int create_sys_files(struct languages *lang_head,
row_nr++;
}
}
+ DBUG_ASSERT(error_count == row_nr);
/* 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);
- bmove((uchar *) head, (uchar *) file_head, 4);
+ bmove((uchar*) head, (uchar*) file_head, 4);
head[4]= 1;
int4store(head + 6, length);
- int2store(head + 10, row_count);
- int2store(head + 12, section_count);
+ int2store(head + 10, max_error); /* Max error */
+ int2store(head + 12, row_nr);
+ int2store(head + 14, section_count);
head[30]= csnum;
my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
@@ -400,8 +414,8 @@ static int create_sys_files(struct languages *lang_head,
MYF(MY_WME | MY_FNABP)))
goto err;
- file_pos[row_count]= (ftell(to) - start_pos);
- for (i= 0; i < row_count; i++)
+ file_pos[row_nr]= (ftell(to) - start_pos);
+ for (i= 0; i < row_nr; i++)
{
/* Store length of each string */
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)
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;
char *str, buff[1000];
struct errors *current_error= 0, **tail_error= top_error;
struct message current_message;
- uint rcount= 0;
+ uint rcount= 0, skiped_errors= 0;
my_bool er_offset_found= 0;
DBUG_ENTER("parse_input_file");
*top_error= 0;
*top_lang= 0;
+ *error_count= 0;
section_start= er_offset;
section_count= 0;
@@ -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++)
{
+ skiped_errors+= skip != 0;
current_error= generate_empty_message(er_offset + rcount, skip);
*tail_error= current_error;
tail_error= &current_error->next_error;
@@ -603,6 +619,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
int2store(section_header + section_count*2,
er_offset + rcount - section_start);
section_count++;
+ *error_count= rcount - skiped_errors;
*tail_error= 0; /* Mark end of list */
@@ -1119,10 +1136,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
switch (optid) {
case 'V':
print_version();
+ my_end(0);
exit(0);
break;
case '?':
usage();
+ my_end(0);
exit(0);
break;
case '#':