1
/* Copyright (C) 2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Written by Anjuta Widenius
21
Creates one include file and multiple language-error message files from one
22
multi-language text file.
25
#include <my_global.h>
29
#include <my_getopt.h>
34
#define HEADER_LENGTH 32 /* Length of header in errmsg.sys */
35
#define DEFAULT_CHARSET_DIR "../sql/share/charsets"
36
#define ER_PREFIX "ER_"
37
#define WARN_PREFIX "WARN_"
38
static char *OUTFILE= (char*) "errmsg.sys";
39
static char *HEADERFILE= (char*) "mysqld_error.h";
40
static char *NAMEFILE= (char*) "mysqld_ername.h";
41
static char *STATEFILE= (char*) "sql_state.h";
42
static char *TXTFILE= (char*) "../sql/share/errmsg.txt";
43
static char *DATADIRECTORY= (char*) "../sql/share/";
45
static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace";
48
/* Header for errmsg.sys files */
49
uchar file_head[]= { 254, 254, 2, 1 };
50
/* Store positions to each error message row to store in errmsg.sys header */
51
uint file_pos[MAX_ROWS];
53
const char *empty_string= ""; /* For empty states */
55
Default values for command line options. See getopt structure for definitions
59
const char *default_language= "eng";
63
/* Storage of one error message row (for one language) */
67
char *lang_short_name;
72
/* Storage for languages and charsets (from start of error text file) */
76
char *lang_long_name; /* full name of the language */
77
char *lang_short_name; /* abbreviation of the lang. */
78
char *charset; /* Character set name */
79
struct languages *next_lang; /* Pointer to next language */
83
/* Name, code and texts (for all lang) for one error message */
87
const char *er_name; /* Name of the error (ER_HASHCK) */
88
int d_code; /* Error code number */
89
const char *sql_code1; /* sql state */
90
const char *sql_code2; /* ODBC state */
91
struct errors *next_error; /* Pointer to next error */
92
DYNAMIC_ARRAY msg; /* All language texts for this error */
96
static struct my_option my_long_options[]=
99
{"debug", '#', "This is a non-debug version. Catch this and exit",
100
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
102
{"debug", '#', "Output debug log", (uchar**) & default_dbug_option,
103
(uchar**) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
105
{"debug-info", 'T', "Print some debug info at exit.", (uchar**) & info_flag,
106
(uchar**) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
107
{"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG,
108
NO_ARG, 0, 0, 0, 0, 0, 0},
109
{"version", 'V', "Prints version", 0, 0, 0, GET_NO_ARG,
110
NO_ARG, 0, 0, 0, 0, 0, 0},
111
{"charset", 'C', "Charset dir", (uchar**) & charsets_dir,
112
(uchar**) & charsets_dir,
113
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
114
{"in_file", 'F', "Input file", (uchar**) & TXTFILE, (uchar**) & TXTFILE,
115
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
116
{"out_dir", 'D', "Output base directory", (uchar**) & DATADIRECTORY,
117
(uchar**) & DATADIRECTORY,
118
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
119
{"out_file", 'O', "Output filename (errmsg.sys)", (uchar**) & OUTFILE,
120
(uchar**) & OUTFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
121
{"header_file", 'H', "mysqld_error.h file ", (uchar**) & HEADERFILE,
122
(uchar**) & HEADERFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
123
{"name_file", 'N', "mysqld_ername.h file ", (uchar**) & NAMEFILE,
124
(uchar**) & NAMEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
125
{"state_file", 'S', "sql_state.h file", (uchar**) & STATEFILE,
126
(uchar**) & STATEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
127
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
131
static struct languages *parse_charset_string(char *str);
132
static struct errors *parse_error_string(char *ptr, int er_count);
133
static struct message *parse_message_string(struct message *new_message,
135
static struct message *find_message(struct errors *err, const char *lang,
137
static int check_message_format(struct errors *err,
139
static int parse_input_file(const char *file_name, struct errors **top_error,
140
struct languages **top_language);
141
static int get_options(int *argc, char ***argv);
142
static void print_version(void);
143
static void usage(void);
144
static my_bool get_one_option(int optid, const struct my_option *opt,
146
static char *parse_text_line(char *pos);
147
static int copy_rows(FILE * to, char *row, int row_nr, long start_pos);
148
static char *parse_default_language(char *str);
149
static uint parse_error_offset(char *str);
151
static char *skip_delimiters(char *str);
152
static char *get_word(char **str);
153
static char *find_end_of_word(char *str);
154
static void clean_up(struct languages *lang_head, struct errors *error_head);
155
static int create_header_files(struct errors *error_head);
156
static int create_sys_files(struct languages *lang_head,
157
struct errors *error_head, uint row_count);
160
int main(int argc, char *argv[])
165
struct errors *error_head;
166
struct languages *lang_head;
169
charsets_dir= DEFAULT_CHARSET_DIR;
171
if (get_options(&argc, &argv))
173
if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head)))
175
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
178
if (lang_head == NULL || error_head == NULL)
180
fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
184
if (create_header_files(error_head))
186
fprintf(stderr, "Failed to create header files\n");
189
if (create_sys_files(lang_head, error_head, row_count))
191
fprintf(stderr, "Failed to create sys files\n");
194
clean_up(lang_head, error_head);
195
DBUG_LEAVE; /* Can't use dbug after my_end() */
196
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
202
static int create_header_files(struct errors *error_head)
205
FILE *er_definef, *sql_statef, *er_namef;
206
struct errors *tmp_error;
207
DBUG_ENTER("create_header_files");
209
if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
213
if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
215
my_fclose(er_definef, MYF(0));
218
if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
220
my_fclose(er_definef, MYF(0));
221
my_fclose(sql_statef, MYF(0));
225
fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
226
fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
227
fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");
229
fprintf(er_definef, "#define ER_ERROR_FIRST %d\n", error_head->d_code);
231
for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
234
generating mysqld_error.h
235
fprintf() will automatically add \r on windows
237
fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
239
er_last= tmp_error->d_code;
241
/* generating sql_state.h file */
242
if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
244
"{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
245
tmp_error->sql_code1, tmp_error->sql_code2);
246
/*generating er_name file */
247
fprintf(er_namef, "{ \"%s\", %d },\n", tmp_error->er_name,
251
/* finishing off with mysqld_error.h */
252
fprintf(er_definef, "#define ER_ERROR_LAST %d\n", er_last);
253
my_fclose(er_definef, MYF(0));
254
my_fclose(sql_statef, MYF(0));
255
my_fclose(er_namef, MYF(0));
260
static int create_sys_files(struct languages *lang_head,
261
struct errors *error_head, uint row_count)
264
uint csnum= 0, length, i, row_nr;
266
char outfile[FN_REFLEN], *outfile_end;
269
struct languages *tmp_lang;
270
struct errors *tmp_error;
273
DBUG_ENTER("create_sys_files");
276
going over all languages and assembling corresponding error messages
278
for (tmp_lang= lang_head; tmp_lang; tmp_lang= tmp_lang->next_lang)
281
/* setting charset name */
282
if (!(csnum= get_charset_number(tmp_lang->charset, MY_CS_PRIMARY)))
284
fprintf(stderr, "Unknown charset '%s' in '%s'\n", tmp_lang->charset,
289
outfile_end= strxmov(outfile, DATADIRECTORY,
290
tmp_lang->lang_long_name, NullS);
291
if (!my_stat(outfile, &stat_info,MYF(0)))
293
if (my_mkdir(outfile, 0777,MYF(0)) < 0)
295
fprintf(stderr, "Can't create output directory for %s\n",
301
strxmov(outfile_end, FN_ROOTDIR, OUTFILE, NullS);
303
if (!(to= my_fopen(outfile, O_WRONLY | FILE_BINARY, MYF(MY_WME))))
306
/* 2 is for 2 bytes to store row position / error message */
307
start_pos= (long) (HEADER_LENGTH + row_count * 2);
308
fseek(to, start_pos, 0);
310
for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
312
/* dealing with messages */
313
tmp= find_message(tmp_error, tmp_lang->lang_short_name, FALSE);
318
"Did not find message for %s neither in %s nor in default "
319
"language\n", tmp_error->er_name, tmp_lang->lang_short_name);
322
if (copy_rows(to, tmp->text, row_nr, start_pos))
324
fprintf(stderr, "Failed to copy rows to %s\n", outfile);
330
/* continue with header of the errmsg.sys file */
331
length= ftell(to) - HEADER_LENGTH - row_count * 2;
332
bzero((uchar*) head, HEADER_LENGTH);
333
bmove((uchar *) head, (uchar *) file_head, 4);
335
int2store(head + 6, length);
336
int2store(head + 8, row_count);
339
my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
340
if (my_fwrite(to, (uchar*) head, HEADER_LENGTH, MYF(MY_WME | MY_FNABP)))
343
for (i= 0; i < row_count; i++)
345
int2store(head, file_pos[i]);
346
if (my_fwrite(to, (uchar*) head, 2, MYF(MY_WME | MY_FNABP)))
349
my_fclose(to, MYF(0));
354
my_fclose(to, MYF(0));
359
static void clean_up(struct languages *lang_head, struct errors *error_head)
361
struct languages *tmp_lang, *next_language;
362
struct errors *tmp_error, *next_error;
365
my_free((uchar*) default_language, MYF(0));
367
for (tmp_lang= lang_head; tmp_lang; tmp_lang= next_language)
369
next_language= tmp_lang->next_lang;
370
my_free(tmp_lang->lang_short_name, MYF(0));
371
my_free(tmp_lang->lang_long_name, MYF(0));
372
my_free(tmp_lang->charset, MYF(0));
373
my_free((uchar*) tmp_lang, MYF(0));
376
for (tmp_error= error_head; tmp_error; tmp_error= next_error)
378
next_error= tmp_error->next_error;
379
count= (tmp_error->msg).elements;
380
for (i= 0; i < count; i++)
383
tmp= dynamic_element(&tmp_error->msg, i, struct message*);
384
my_free((uchar*) tmp->lang_short_name, MYF(0));
385
my_free((uchar*) tmp->text, MYF(0));
388
delete_dynamic(&tmp_error->msg);
389
if (tmp_error->sql_code1[0])
390
my_free((uchar*) tmp_error->sql_code1, MYF(0));
391
if (tmp_error->sql_code2[0])
392
my_free((uchar*) tmp_error->sql_code2, MYF(0));
393
my_free((uchar*) tmp_error->er_name, MYF(0));
394
my_free((uchar*) tmp_error, MYF(0));
399
static int parse_input_file(const char *file_name, struct errors **top_error,
400
struct languages **top_lang)
403
char *str, buff[1000];
404
struct errors *current_error= 0, **tail_error= top_error;
405
struct message current_message;
407
DBUG_ENTER("parse_input_file");
411
if (!(file= my_fopen(file_name, O_RDONLY | O_SHARE, MYF(MY_WME))))
414
while ((str= fgets(buff, sizeof(buff), file)))
416
if (is_prefix(str, "language"))
418
if (!(*top_lang= parse_charset_string(str)))
420
fprintf(stderr, "Failed to parse the charset string!\n");
425
if (is_prefix(str, "start-error-number"))
427
if (!(er_offset= parse_error_offset(str)))
429
fprintf(stderr, "Failed to parse the error offset string!\n");
434
if (is_prefix(str, "default-language"))
436
if (!(default_language= parse_default_language(str)))
438
DBUG_PRINT("info", ("default_slang: %s", default_language));
440
"Failed to parse the default language line. Aborting\n");
446
if (*str == '\t' || *str == ' ')
448
/* New error message in another language for previous error */
451
fprintf(stderr, "Error in the input file format\n");
454
if (!parse_message_string(¤t_message, str))
456
fprintf(stderr, "Failed to parse message string for error '%s'",
457
current_error->er_name);
460
if (find_message(current_error, current_message.lang_short_name, TRUE))
462
fprintf(stderr, "Duplicate message string for error '%s'"
463
" in language '%s'\n",
464
current_error->er_name, current_message.lang_short_name);
467
if (check_message_format(current_error, current_message.text))
469
fprintf(stderr, "Wrong formatspecifier of error message string"
470
" for error '%s' in language '%s'\n",
471
current_error->er_name, current_message.lang_short_name);
474
if (insert_dynamic(¤t_error->msg, (uchar *) & current_message))
478
if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
480
if (!(current_error= parse_error_string(str, rcount)))
482
fprintf(stderr, "Failed to parse the error name string\n");
485
rcount++; /* Count number of unique errors */
487
/* add error to the list */
488
*tail_error= current_error;
489
tail_error= ¤t_error->next_error;
492
if (*str == '#' || *str == '\n')
493
continue; /* skip comment or empty lines */
495
fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str);
498
*tail_error= 0; /* Mark end of list */
500
my_fclose(file, MYF(0));
505
static uint parse_error_offset(char *str)
511
DBUG_ENTER("parse_error_offset");
512
/* skipping the "start-error-number" keyword and spaces after it */
513
str= find_end_of_word(str);
514
str= skip_delimiters(str);
517
DBUG_RETURN(0); /* Unexpected EOL: No error number after the keyword */
519
/* reading the error offset */
520
if (!(soffset= get_word(&str)))
521
DBUG_RETURN(0); /* OOM: Fatal error */
522
DBUG_PRINT("info", ("default_error_offset: %s", soffset));
524
/* skipping space(s) and/or tabs after the error offset */
525
str= skip_delimiters(str);
526
DBUG_PRINT("info", ("str: %s", str));
529
/* The line does not end with the error offset -> error! */
530
fprintf(stderr, "The error offset line does not end with an error offset");
533
DBUG_PRINT("info", ("str: %s", str));
536
ioffset= (uint) my_strtoll10(soffset, &end, &error);
537
my_free((uchar*) soffset, MYF(0));
538
DBUG_RETURN(ioffset);
542
/* Parsing of the default language line. e.g. "default-language eng" */
544
static char *parse_default_language(char *str)
548
DBUG_ENTER("parse_default_language");
549
/* skipping the "default-language" keyword */
550
str= find_end_of_word(str);
551
/* skipping space(s) and/or tabs after the keyword */
552
str= skip_delimiters(str);
556
"Unexpected EOL: No short language name after the keyword\n");
560
/* reading the short language tag */
561
if (!(slang= get_word(&str)))
562
DBUG_RETURN(0); /* OOM: Fatal error */
563
DBUG_PRINT("info", ("default_slang: %s", slang));
565
str= skip_delimiters(str);
566
DBUG_PRINT("info", ("str: %s", str));
570
"The default language line does not end with short language "
574
DBUG_PRINT("info", ("str: %s", str));
580
Find the message in a particular language
584
err Error to find message for
585
lang Language of message to find
586
no_default Don't return default (English) if does not exit
589
Returns the message structure if one is found, or NULL if not.
591
static struct message *find_message(struct errors *err, const char *lang,
594
struct message *tmp, *return_val= 0;
596
DBUG_ENTER("find_message");
598
count= (err->msg).elements;
599
for (i= 0; i < count; i++)
601
tmp= dynamic_element(&err->msg, i, struct message*);
603
if (!strcmp(tmp->lang_short_name, lang))
605
if (!strcmp(tmp->lang_short_name, default_language))
607
DBUG_ASSERT(tmp->text[0] != 0);
611
DBUG_RETURN(no_default ? NULL : return_val);
617
Check message format specifiers against error message for
621
checksum_format_specifier()
622
msg String for which to generate checksum
623
for the format specifiers
626
Returns the checksum for all the characters of the
630
"text '%-64.s' text part 2 %d'"
632
characters will be xored to form checksum
635
Does not support format specifiers with positional args
636
like "%2$s" but that is not yet supported by my_vsnprintf
640
static ha_checksum checksum_format_specifier(const char* msg)
642
ha_checksum chksum= 0;
644
const char* start= 0;
645
int num_format_specifiers= 0;
651
start= p+1; /* Entering format specifier */
652
num_format_specifiers++;
662
chksum= my_checksum(chksum, start, p-start);
663
start= 0; /* Not in format specifier anymore */
676
/* Still inside a format specifier after end of string */
678
fprintf(stderr, "Still inside formatspecifier after end of string"
680
DBUG_ASSERT(start==0);
683
/* Add number of format specifiers to checksum as extra safeguard */
684
chksum+= num_format_specifiers;
691
Check message format specifiers against error message for
695
check_message_format()
696
err Error to check message for
697
mess Message to check
700
Returns 0 if no previous error message or message format is ok
702
static int check_message_format(struct errors *err,
705
struct message *first;
706
DBUG_ENTER("check_message_format");
708
/* Get first message(if any) */
709
if ((err->msg).elements == 0)
710
DBUG_RETURN(0); /* No previous message to compare against */
712
first= dynamic_element(&err->msg, 0, struct message*);
713
DBUG_ASSERT(first != NULL);
715
if (checksum_format_specifier(first->text) !=
716
checksum_format_specifier(mess))
718
/* Check sum of format specifiers failed, they should be equal */
726
Skips spaces and or tabs till the beginning of the next word
727
Returns pointer to the beginning of the first character of the word
730
static char *skip_delimiters(char *str)
732
DBUG_ENTER("skip_delimiters");
734
*str == ' ' || *str == ',' || *str == '\t' || *str == '\r' ||
735
*str == '\n' || *str == '='; str++)
742
Skips all characters till meets with space, or tab, or EOL
745
static char *find_end_of_word(char *str)
747
DBUG_ENTER("find_end_of_word");
749
*str != ' ' && *str != '\t' && *str != '\n' && *str != '\r' && *str &&
750
*str != ',' && *str != ';' && *str != '='; str++)
756
/* Read the word starting from *str */
758
static char *get_word(char **str)
761
DBUG_ENTER("get_word");
763
*str= find_end_of_word(start);
764
DBUG_RETURN(my_strndup(start, (uint) (*str - start),
765
MYF(MY_WME | MY_FAE)));
770
Parsing the string with short_lang - message text. Code - to
771
remember to which error does the text belong
774
static struct message *parse_message_string(struct message *new_message,
779
DBUG_ENTER("parse_message_string");
780
DBUG_PRINT("enter", ("str: %s", str));
782
/*skip space(s) and/or tabs in the beginning */
783
while (*str == ' ' || *str == '\t' || *str == '\n')
788
/* It was not a message line, but an empty line. */
789
DBUG_PRINT("info", ("str: %s", str));
793
/* reading the short lang */
795
while (*str != ' ' && *str != '\t' && *str)
797
if (!(new_message->lang_short_name=
798
my_strndup(start, (uint) (str - start),
799
MYF(MY_WME | MY_FAE))))
800
DBUG_RETURN(0); /* Fatal error */
801
DBUG_PRINT("info", ("msg_slang: %s", new_message->lang_short_name));
803
/*skip space(s) and/or tabs after the lang */
804
while (*str == ' ' || *str == '\t' || *str == '\n')
809
fprintf(stderr, "Unexpected EOL");
810
DBUG_PRINT("info", ("str: %s", str));
814
/* reading the text */
816
str= parse_text_line(start);
818
if (!(new_message->text= my_strndup(start, (uint) (str - start),
819
MYF(MY_WME | MY_FAE))))
820
DBUG_RETURN(0); /* Fatal error */
821
DBUG_PRINT("info", ("msg_text: %s", new_message->text));
823
DBUG_RETURN(new_message);
828
Parsing the string with error name and codes; returns the pointer to
832
static struct errors *parse_error_string(char *str, int er_count)
834
struct errors *new_error;
836
DBUG_ENTER("parse_error_string");
837
DBUG_PRINT("enter", ("str: %s", str));
839
/* create a new element */
840
new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
842
if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
843
DBUG_RETURN(0); /* OOM: Fatal error */
845
/* getting the error name */
847
str= skip_delimiters(str);
849
if (!(new_error->er_name= get_word(&str)))
850
DBUG_RETURN(0); /* OOM: Fatal error */
851
DBUG_PRINT("info", ("er_name: %s", new_error->er_name));
853
str= skip_delimiters(str);
855
/* getting the code1 */
857
new_error->d_code= er_offset + er_count;
858
DBUG_PRINT("info", ("d_code: %d", new_error->d_code));
860
str= skip_delimiters(str);
862
/* if we reached EOL => no more codes, but this can happen */
865
new_error->sql_code1= empty_string;
866
new_error->sql_code2= empty_string;
867
DBUG_PRINT("info", ("str: %s", str));
868
DBUG_RETURN(new_error);
871
/* getting the sql_code 1 */
873
if (!(new_error->sql_code1= get_word(&str)))
874
DBUG_RETURN(0); /* OOM: Fatal error */
875
DBUG_PRINT("info", ("sql_code1: %s", new_error->sql_code1));
877
str= skip_delimiters(str);
879
/* if we reached EOL => no more codes, but this can happen */
882
new_error->sql_code2= empty_string;
883
DBUG_PRINT("info", ("str: %s", str));
884
DBUG_RETURN(new_error);
887
/* getting the sql_code 2 */
888
if (!(new_error->sql_code2= get_word(&str)))
889
DBUG_RETURN(0); /* OOM: Fatal error */
890
DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2));
892
str= skip_delimiters(str);
895
fprintf(stderr, "The error line did not end with sql/odbc code!");
899
DBUG_RETURN(new_error);
904
Parsing the string with full lang name/short lang name/charset;
905
returns pointer to the language structure
908
static struct languages *parse_charset_string(char *str)
910
struct languages *head=0, *new_lang;
911
DBUG_ENTER("parse_charset_string");
912
DBUG_PRINT("enter", ("str: %s", str));
914
/* skip over keyword */
915
str= find_end_of_word(str);
919
DBUG_PRINT("info", ("str: %s", str));
923
str= skip_delimiters(str);
924
if (!(*str != ';' && *str))
929
/*creating new element of the linked list */
930
new_lang= (struct languages *) my_malloc(sizeof(*new_lang), MYF(MY_WME));
931
new_lang->next_lang= head;
934
/* get the full language name */
936
if (!(new_lang->lang_long_name= get_word(&str)))
937
DBUG_RETURN(0); /* OOM: Fatal error */
939
DBUG_PRINT("info", ("long_name: %s", new_lang->lang_long_name));
941
/* getting the short name for language */
942
str= skip_delimiters(str);
944
DBUG_RETURN(0); /* Error: No space or tab */
946
if (!(new_lang->lang_short_name= get_word(&str)))
947
DBUG_RETURN(0); /* OOM: Fatal error */
948
DBUG_PRINT("info", ("short_name: %s", new_lang->lang_short_name));
950
/* getting the charset name */
951
str= skip_delimiters(str);
952
if (!(new_lang->charset= get_word(&str)))
953
DBUG_RETURN(0); /* Fatal error */
954
DBUG_PRINT("info", ("charset: %s", new_lang->charset));
956
/* skipping space, tab or "," */
957
str= skip_delimiters(str);
959
while (*str != ';' && *str);
961
DBUG_PRINT("info", ("long name: %s", new_lang->lang_long_name));
968
static void print_version(void)
970
DBUG_ENTER("print_version");
971
printf("%s (Compile errormessage) Ver %s\n", my_progname, "2.0");
977
get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
978
char *argument __attribute__ ((unused)))
980
DBUG_ENTER("get_one_option");
991
DBUG_PUSH(argument ? argument : default_dbug_option);
998
static void usage(void)
1000
DBUG_ENTER("usage");
1002
printf("This software comes with ABSOLUTELY NO WARRANTY. "
1003
"This is free software,\n"
1004
"and you are welcome to modify and redistribute it under the GPL license.\n"
1006
my_print_help(my_long_options);
1007
my_print_variables(my_long_options);
1012
static int get_options(int *argc, char ***argv)
1015
DBUG_ENTER("get_options");
1017
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1018
DBUG_RETURN(ho_error);
1024
Read rows and remember them until row that start with char Converts
1025
row as a C-compiler would convert a textstring
1028
static char *parse_text_line(char *pos)
1032
DBUG_ENTER("parse_text_line");
1041
VOID(strmov(pos - 1, pos));
1045
VOID(strmov(pos, pos + 1));
1048
if (*pos >= '0' && *pos < '8')
1051
for (i= 0; i < 3 && (*pos >= '0' && *pos < '8'); i++)
1052
nr= nr * 8 + (*(pos++) - '0');
1055
VOID(strmov(pos, pos + i));
1058
VOID(strmov(pos - 1, pos)); /* Remove '\' */
1064
while (pos > row + 1 && *pos != '"')
1071
/* Copy rows from memory to file and remember position */
1073
static int copy_rows(FILE *to, char *row, int row_nr, long start_pos)
1075
DBUG_ENTER("copy_rows");
1077
file_pos[row_nr]= (int) (ftell(to) - start_pos);
1078
if (fputs(row, to) == EOF || fputc('\0', to) == EOF)
1080
fprintf(stderr, "Can't write to outputfile\n");