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;
272
struct stat stat_info;
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 (stat(outfile, &stat_info))
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
639
static ha_checksum checksum_format_specifier(const char* msg)
641
ha_checksum chksum= 0;
642
const uchar* p= (uchar *)msg;
643
const uchar* start= 0;
644
int num_format_specifiers= 0;
650
start= p+1; /* Entering format specifier */
651
num_format_specifiers++;
661
chksum= my_checksum(chksum, start, p-start);
662
start= 0; /* Not in format specifier anymore */
675
/* Still inside a format specifier after end of string */
677
fprintf(stderr, "Still inside formatspecifier after end of string"
679
DBUG_ASSERT(start==0);
682
/* Add number of format specifiers to checksum as extra safeguard */
683
chksum+= num_format_specifiers;
690
Check message format specifiers against error message for
694
check_message_format()
695
err Error to check message for
696
mess Message to check
699
Returns 0 if no previous error message or message format is ok
701
static int check_message_format(struct errors *err,
704
struct message *first;
705
DBUG_ENTER("check_message_format");
707
/* Get first message(if any) */
708
if ((err->msg).elements == 0)
709
DBUG_RETURN(0); /* No previous message to compare against */
711
first= dynamic_element(&err->msg, 0, struct message*);
712
DBUG_ASSERT(first != NULL);
714
if (checksum_format_specifier(first->text) !=
715
checksum_format_specifier(mess))
717
/* Check sum of format specifiers failed, they should be equal */
725
Skips spaces and or tabs till the beginning of the next word
726
Returns pointer to the beginning of the first character of the word
729
static char *skip_delimiters(char *str)
731
DBUG_ENTER("skip_delimiters");
733
*str == ' ' || *str == ',' || *str == '\t' || *str == '\r' ||
734
*str == '\n' || *str == '='; str++)
741
Skips all characters till meets with space, or tab, or EOL
744
static char *find_end_of_word(char *str)
746
DBUG_ENTER("find_end_of_word");
748
*str != ' ' && *str != '\t' && *str != '\n' && *str != '\r' && *str &&
749
*str != ',' && *str != ';' && *str != '='; str++)
755
/* Read the word starting from *str */
757
static char *get_word(char **str)
760
DBUG_ENTER("get_word");
762
*str= find_end_of_word(start);
763
DBUG_RETURN(my_strndup(start, (uint) (*str - start),
764
MYF(MY_WME | MY_FAE)));
769
Parsing the string with short_lang - message text. Code - to
770
remember to which error does the text belong
773
static struct message *parse_message_string(struct message *new_message,
778
DBUG_ENTER("parse_message_string");
779
DBUG_PRINT("enter", ("str: %s", str));
781
/*skip space(s) and/or tabs in the beginning */
782
while (*str == ' ' || *str == '\t' || *str == '\n')
787
/* It was not a message line, but an empty line. */
788
DBUG_PRINT("info", ("str: %s", str));
792
/* reading the short lang */
794
while (*str != ' ' && *str != '\t' && *str)
796
if (!(new_message->lang_short_name=
797
my_strndup(start, (uint) (str - start),
798
MYF(MY_WME | MY_FAE))))
799
DBUG_RETURN(0); /* Fatal error */
800
DBUG_PRINT("info", ("msg_slang: %s", new_message->lang_short_name));
802
/*skip space(s) and/or tabs after the lang */
803
while (*str == ' ' || *str == '\t' || *str == '\n')
808
fprintf(stderr, "Unexpected EOL");
809
DBUG_PRINT("info", ("str: %s", str));
813
/* reading the text */
815
str= parse_text_line(start);
817
if (!(new_message->text= my_strndup(start, (uint) (str - start),
818
MYF(MY_WME | MY_FAE))))
819
DBUG_RETURN(0); /* Fatal error */
820
DBUG_PRINT("info", ("msg_text: %s", new_message->text));
822
DBUG_RETURN(new_message);
827
Parsing the string with error name and codes; returns the pointer to
831
static struct errors *parse_error_string(char *str, int er_count)
833
struct errors *new_error;
835
DBUG_ENTER("parse_error_string");
836
DBUG_PRINT("enter", ("str: %s", str));
838
/* create a new element */
839
new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
841
if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
842
DBUG_RETURN(0); /* OOM: Fatal error */
844
/* getting the error name */
846
str= skip_delimiters(str);
848
if (!(new_error->er_name= get_word(&str)))
849
DBUG_RETURN(0); /* OOM: Fatal error */
850
DBUG_PRINT("info", ("er_name: %s", new_error->er_name));
852
str= skip_delimiters(str);
854
/* getting the code1 */
856
new_error->d_code= er_offset + er_count;
857
DBUG_PRINT("info", ("d_code: %d", new_error->d_code));
859
str= skip_delimiters(str);
861
/* if we reached EOL => no more codes, but this can happen */
864
new_error->sql_code1= empty_string;
865
new_error->sql_code2= empty_string;
866
DBUG_PRINT("info", ("str: %s", str));
867
DBUG_RETURN(new_error);
870
/* getting the sql_code 1 */
872
if (!(new_error->sql_code1= get_word(&str)))
873
DBUG_RETURN(0); /* OOM: Fatal error */
874
DBUG_PRINT("info", ("sql_code1: %s", new_error->sql_code1));
876
str= skip_delimiters(str);
878
/* if we reached EOL => no more codes, but this can happen */
881
new_error->sql_code2= empty_string;
882
DBUG_PRINT("info", ("str: %s", str));
883
DBUG_RETURN(new_error);
886
/* getting the sql_code 2 */
887
if (!(new_error->sql_code2= get_word(&str)))
888
DBUG_RETURN(0); /* OOM: Fatal error */
889
DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2));
891
str= skip_delimiters(str);
894
fprintf(stderr, "The error line did not end with sql/odbc code!");
898
DBUG_RETURN(new_error);
903
Parsing the string with full lang name/short lang name/charset;
904
returns pointer to the language structure
907
static struct languages *parse_charset_string(char *str)
909
struct languages *head=0, *new_lang;
910
DBUG_ENTER("parse_charset_string");
911
DBUG_PRINT("enter", ("str: %s", str));
913
/* skip over keyword */
914
str= find_end_of_word(str);
918
DBUG_PRINT("info", ("str: %s", str));
922
str= skip_delimiters(str);
923
if (!(*str != ';' && *str))
928
/*creating new element of the linked list */
929
new_lang= (struct languages *) my_malloc(sizeof(*new_lang), MYF(MY_WME));
930
new_lang->next_lang= head;
933
/* get the full language name */
935
if (!(new_lang->lang_long_name= get_word(&str)))
936
DBUG_RETURN(0); /* OOM: Fatal error */
938
DBUG_PRINT("info", ("long_name: %s", new_lang->lang_long_name));
940
/* getting the short name for language */
941
str= skip_delimiters(str);
943
DBUG_RETURN(0); /* Error: No space or tab */
945
if (!(new_lang->lang_short_name= get_word(&str)))
946
DBUG_RETURN(0); /* OOM: Fatal error */
947
DBUG_PRINT("info", ("short_name: %s", new_lang->lang_short_name));
949
/* getting the charset name */
950
str= skip_delimiters(str);
951
if (!(new_lang->charset= get_word(&str)))
952
DBUG_RETURN(0); /* Fatal error */
953
DBUG_PRINT("info", ("charset: %s", new_lang->charset));
955
/* skipping space, tab or "," */
956
str= skip_delimiters(str);
958
while (*str != ';' && *str);
960
DBUG_PRINT("info", ("long name: %s", new_lang->lang_long_name));
967
static void print_version(void)
969
DBUG_ENTER("print_version");
970
printf("%s (Compile errormessage) Ver %s\n", my_progname, "2.0");
976
get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
977
char *argument __attribute__ ((unused)))
979
DBUG_ENTER("get_one_option");
990
DBUG_PUSH(argument ? argument : default_dbug_option);
997
static void usage(void)
1001
printf("This software comes with ABSOLUTELY NO WARRANTY. "
1002
"This is free software,\n"
1003
"and you are welcome to modify and redistribute it under the GPL license.\n"
1005
my_print_help(my_long_options);
1006
my_print_variables(my_long_options);
1011
static int get_options(int *argc, char ***argv)
1014
DBUG_ENTER("get_options");
1016
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1017
DBUG_RETURN(ho_error);
1023
Read rows and remember them until row that start with char Converts
1024
row as a C-compiler would convert a textstring
1027
static char *parse_text_line(char *pos)
1031
DBUG_ENTER("parse_text_line");
1040
VOID(strmov(pos - 1, pos));
1044
VOID(strmov(pos, pos + 1));
1047
if (*pos >= '0' && *pos < '8')
1050
for (i= 0; i < 3 && (*pos >= '0' && *pos < '8'); i++)
1051
nr= nr * 8 + (*(pos++) - '0');
1054
VOID(strmov(pos, pos + i));
1057
VOID(strmov(pos - 1, pos)); /* Remove '\' */
1063
while (pos > row + 1 && *pos != '"')
1070
/* Copy rows from memory to file and remember position */
1072
static int copy_rows(FILE *to, char *row, int row_nr, long start_pos)
1074
DBUG_ENTER("copy_rows");
1076
file_pos[row_nr]= (int) (ftell(to) - start_pos);
1077
if (fputs(row, to) == EOF || fputc('\0', to) == EOF)
1079
fprintf(stderr, "Can't write to outputfile\n");