Skip to content

Commit c0eebb8

Browse files
committed
Fixed but when generating .sys files
1 parent cdd4043 commit c0eebb8

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

extra/comp_err.c

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ static struct message *find_message(struct errors *err, const char *lang,
145145
static int check_message_format(struct errors *err,
146146
const char* mess);
147147
static uint parse_input_file(const char *file_name, struct errors **top_error,
148-
struct languages **top_language);
148+
struct languages **top_language,
149+
uint *error_count);
149150
static int get_options(int *argc, char ***argv);
150151
static void print_version(void);
151152
static void usage(void);
@@ -162,47 +163,55 @@ static char *find_end_of_word(char *str);
162163
static void clean_up(struct languages *lang_head, struct errors *error_head);
163164
static int create_header_files(struct errors *error_head);
164165
static int create_sys_files(struct languages *lang_head,
165-
struct errors *error_head, uint row_count);
166+
struct errors *error_head, uint max_error,
167+
uint error_count);
166168

167169

168170
int main(int argc, char *argv[])
169171
{
170172
MY_INIT(argv[0]);
171173
{
172-
uint row_count;
174+
uint max_error, error_count;
173175
struct errors *error_head;
174176
struct languages *lang_head;
175177
DBUG_ENTER("main");
176178

177179
charsets_dir= DEFAULT_CHARSET_DIR;
178180
my_umask_dir= 0777;
179181
if (get_options(&argc, &argv))
180-
DBUG_RETURN(1);
181-
if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head)))
182+
goto err;
183+
if (!(max_error= parse_input_file(TXTFILE, &error_head, &lang_head,
184+
&error_count)))
182185
{
183186
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
184-
DBUG_RETURN(1);
187+
goto err;
185188
}
186189
if (lang_head == NULL || error_head == NULL)
187190
{
188191
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
189-
DBUG_RETURN(1);
192+
goto err;
190193
}
191194

192195
if (create_header_files(error_head))
193196
{
194197
fprintf(stderr, "Failed to create header files\n");
195-
DBUG_RETURN(1);
198+
goto err;
196199
}
197-
if (create_sys_files(lang_head, error_head, row_count))
200+
if (create_sys_files(lang_head, error_head, max_error, error_count))
198201
{
199202
fprintf(stderr, "Failed to create sys files\n");
200-
DBUG_RETURN(1);
203+
goto err;
201204
}
202205
clean_up(lang_head, error_head);
203206
DBUG_LEAVE; /* Can't use dbug after my_end() */
204207
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
205208
return 0;
209+
210+
err:
211+
clean_up(lang_head, error_head);
212+
DBUG_LEAVE; /* Can't use dbug after my_end() */
213+
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
214+
exit(1);
206215
}
207216
}
208217

@@ -313,7 +322,9 @@ static int create_header_files(struct errors *error_head)
313322

314323

315324
static int create_sys_files(struct languages *lang_head,
316-
struct errors *error_head, uint row_count)
325+
struct errors *error_head,
326+
uint max_error,
327+
uint error_count)
317328
{
318329
FILE *to;
319330
uint csnum= 0, length, i, row_nr;
@@ -358,8 +369,8 @@ static int create_sys_files(struct languages *lang_head,
358369
DBUG_RETURN(1);
359370

360371
/* 2 is for 2 bytes to store row position / error message */
361-
start_pos= (long) (HEADER_LENGTH + (row_count + section_count) * 2);
362-
fseek(to, start_pos, 0);
372+
start_pos= (long) (HEADER_LENGTH + (error_count + section_count) * 2);
373+
my_fseek(to, start_pos, 0, MYF(0));
363374
row_nr= 0;
364375
for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
365376
{
@@ -383,15 +394,18 @@ static int create_sys_files(struct languages *lang_head,
383394
row_nr++;
384395
}
385396
}
397+
DBUG_ASSERT(error_count == row_nr);
386398

387399
/* continue with header of the errmsg.sys file */
388-
length= ftell(to) - HEADER_LENGTH - (row_count + section_count) * 2;
400+
length= (my_ftell(to, MYF(0)) - HEADER_LENGTH -
401+
(error_count + section_count) * 2);
389402
bzero((uchar*) head, HEADER_LENGTH);
390-
bmove((uchar *) head, (uchar *) file_head, 4);
403+
bmove((uchar*) head, (uchar*) file_head, 4);
391404
head[4]= 1;
392405
int4store(head + 6, length);
393-
int2store(head + 10, row_count);
394-
int2store(head + 12, section_count);
406+
int2store(head + 10, max_error); /* Max error */
407+
int2store(head + 12, row_nr);
408+
int2store(head + 14, section_count);
395409
head[30]= csnum;
396410

397411
my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
@@ -400,8 +414,8 @@ static int create_sys_files(struct languages *lang_head,
400414
MYF(MY_WME | MY_FNABP)))
401415
goto err;
402416

403-
file_pos[row_count]= (ftell(to) - start_pos);
404-
for (i= 0; i < row_count; i++)
417+
file_pos[row_nr]= (ftell(to) - start_pos);
418+
for (i= 0; i < row_nr; i++)
405419
{
406420
/* Store length of each string */
407421
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)
459473

460474

461475
static uint parse_input_file(const char *file_name, struct errors **top_error,
462-
struct languages **top_lang)
476+
struct languages **top_lang, uint *error_count)
463477
{
464478
FILE *file;
465479
char *str, buff[1000];
466480
struct errors *current_error= 0, **tail_error= top_error;
467481
struct message current_message;
468-
uint rcount= 0;
482+
uint rcount= 0, skiped_errors= 0;
469483
my_bool er_offset_found= 0;
470484
DBUG_ENTER("parse_input_file");
471485

472486
*top_error= 0;
473487
*top_lang= 0;
488+
*error_count= 0;
474489
section_start= er_offset;
475490
section_count= 0;
476491

@@ -528,6 +543,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
528543
}
529544
for ( ; er_offset + rcount < tmp_er_offset ; rcount++)
530545
{
546+
skiped_errors+= skip != 0;
531547
current_error= generate_empty_message(er_offset + rcount, skip);
532548
*tail_error= current_error;
533549
tail_error= &current_error->next_error;
@@ -603,6 +619,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
603619
int2store(section_header + section_count*2,
604620
er_offset + rcount - section_start);
605621
section_count++;
622+
*error_count= rcount - skiped_errors;
606623

607624
*tail_error= 0; /* Mark end of list */
608625

@@ -1119,10 +1136,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
11191136
switch (optid) {
11201137
case 'V':
11211138
print_version();
1139+
my_end(0);
11221140
exit(0);
11231141
break;
11241142
case '?':
11251143
usage();
1144+
my_end(0);
11261145
exit(0);
11271146
break;
11281147
case '#':

sql/derror.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static bool check_error_mesg(const char *file_name, const char **errmsg)
176176
struct st_msg_file
177177
{
178178
uint sections;
179+
uint max_error;
179180
uint errors;
180181
size_t text_length;
181182
};
@@ -224,10 +225,11 @@ static File open_error_msg_file(const char *file_name, const char *language,
224225
goto err; /* purecov: inspected */
225226

226227
ret->text_length= uint4korr(head+6);
227-
ret->errors= uint2korr(head+10);
228-
ret->sections= uint2korr(head+12);
228+
ret->max_error= uint2korr(head+10);
229+
ret->errors= uint2korr(head+12);
230+
ret->sections= uint2korr(head+14);
229231

230-
if (ret->errors < error_messages || ret->sections != MAX_ERROR_RANGES)
232+
if (ret->max_error < error_messages || ret->sections != MAX_ERROR_RANGES)
231233
{
232234
sql_print_error("\
233235
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!",

0 commit comments

Comments
 (0)