@@ -145,7 +145,8 @@ static struct message *find_message(struct errors *err, const char *lang,
145
145
static int check_message_format (struct errors * err ,
146
146
const char * mess );
147
147
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 );
149
150
static int get_options (int * argc , char * * * argv );
150
151
static void print_version (void );
151
152
static void usage (void );
@@ -162,47 +163,55 @@ static char *find_end_of_word(char *str);
162
163
static void clean_up (struct languages * lang_head , struct errors * error_head );
163
164
static int create_header_files (struct errors * error_head );
164
165
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 );
166
168
167
169
168
170
int main (int argc , char * argv [])
169
171
{
170
172
MY_INIT (argv [0 ]);
171
173
{
172
- uint row_count ;
174
+ uint max_error , error_count ;
173
175
struct errors * error_head ;
174
176
struct languages * lang_head ;
175
177
DBUG_ENTER ("main" );
176
178
177
179
charsets_dir = DEFAULT_CHARSET_DIR ;
178
180
my_umask_dir = 0777 ;
179
181
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 )))
182
185
{
183
186
fprintf (stderr , "Failed to parse input file %s\n" , TXTFILE );
184
- DBUG_RETURN ( 1 ) ;
187
+ goto err ;
185
188
}
186
189
if (lang_head == NULL || error_head == NULL )
187
190
{
188
191
fprintf (stderr , "Failed to parse input file %s\n" , TXTFILE );
189
- DBUG_RETURN ( 1 ) ;
192
+ goto err ;
190
193
}
191
194
192
195
if (create_header_files (error_head ))
193
196
{
194
197
fprintf (stderr , "Failed to create header files\n" );
195
- DBUG_RETURN ( 1 ) ;
198
+ goto err ;
196
199
}
197
- if (create_sys_files (lang_head , error_head , row_count ))
200
+ if (create_sys_files (lang_head , error_head , max_error , error_count ))
198
201
{
199
202
fprintf (stderr , "Failed to create sys files\n" );
200
- DBUG_RETURN ( 1 ) ;
203
+ goto err ;
201
204
}
202
205
clean_up (lang_head , error_head );
203
206
DBUG_LEAVE ; /* Can't use dbug after my_end() */
204
207
my_end (info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0 );
205
208
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 );
206
215
}
207
216
}
208
217
@@ -313,7 +322,9 @@ static int create_header_files(struct errors *error_head)
313
322
314
323
315
324
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 )
317
328
{
318
329
FILE * to ;
319
330
uint csnum = 0 , length , i , row_nr ;
@@ -358,8 +369,8 @@ static int create_sys_files(struct languages *lang_head,
358
369
DBUG_RETURN (1 );
359
370
360
371
/* 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 ) );
363
374
row_nr = 0 ;
364
375
for (tmp_error = error_head ; tmp_error ; tmp_error = tmp_error -> next_error )
365
376
{
@@ -383,15 +394,18 @@ static int create_sys_files(struct languages *lang_head,
383
394
row_nr ++ ;
384
395
}
385
396
}
397
+ DBUG_ASSERT (error_count == row_nr );
386
398
387
399
/* 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 );
389
402
bzero ((uchar * ) head , HEADER_LENGTH );
390
- bmove ((uchar * ) head , (uchar * ) file_head , 4 );
403
+ bmove ((uchar * ) head , (uchar * ) file_head , 4 );
391
404
head [4 ]= 1 ;
392
405
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 );
395
409
head [30 ]= csnum ;
396
410
397
411
my_fseek (to , 0l , MY_SEEK_SET , MYF (0 ));
@@ -400,8 +414,8 @@ static int create_sys_files(struct languages *lang_head,
400
414
MYF (MY_WME | MY_FNABP )))
401
415
goto err ;
402
416
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 ++ )
405
419
{
406
420
/* Store length of each string */
407
421
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
473
460
474
461
475
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 )
463
477
{
464
478
FILE * file ;
465
479
char * str , buff [1000 ];
466
480
struct errors * current_error = 0 , * * tail_error = top_error ;
467
481
struct message current_message ;
468
- uint rcount = 0 ;
482
+ uint rcount = 0 , skiped_errors = 0 ;
469
483
my_bool er_offset_found = 0 ;
470
484
DBUG_ENTER ("parse_input_file" );
471
485
472
486
* top_error = 0 ;
473
487
* top_lang = 0 ;
488
+ * error_count = 0 ;
474
489
section_start = er_offset ;
475
490
section_count = 0 ;
476
491
@@ -528,6 +543,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
528
543
}
529
544
for ( ; er_offset + rcount < tmp_er_offset ; rcount ++ )
530
545
{
546
+ skiped_errors += skip != 0 ;
531
547
current_error = generate_empty_message (er_offset + rcount , skip );
532
548
* tail_error = current_error ;
533
549
tail_error = & current_error -> next_error ;
@@ -603,6 +619,7 @@ static uint parse_input_file(const char *file_name, struct errors **top_error,
603
619
int2store (section_header + section_count * 2 ,
604
620
er_offset + rcount - section_start );
605
621
section_count ++ ;
622
+ * error_count = rcount - skiped_errors ;
606
623
607
624
* tail_error = 0 ; /* Mark end of list */
608
625
@@ -1119,10 +1136,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
1119
1136
switch (optid ) {
1120
1137
case 'V' :
1121
1138
print_version ();
1139
+ my_end (0 );
1122
1140
exit (0 );
1123
1141
break ;
1124
1142
case '?' :
1125
1143
usage ();
1144
+ my_end (0 );
1126
1145
exit (0 );
1127
1146
break ;
1128
1147
case '#' :
0 commit comments