3 # Copyright (c) 2003-2004, Artem B. Bityuckiy, SoftMine Corporation.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 sub process_section_encodings($);
32 sub process_section_cesdeps($);
35 sub generate_cesbi_h($$);
36 sub generate_encnames_h(@);
37 sub generate_aliasesbi_c($);
38 sub generate_encoding_aliases_c($);
39 sub generate_cesdeps_h($);
40 sub generate_ccsbi_h($);
41 sub generate_cesbi_c($);
42 sub generate_ccsnames_h($);
44 # ==============================================================================
48 # ==============================================================================
50 my $comment_automatic =
52 * This file was automatically generated mkdeps.pl script. Don't edit.
55 my $macro_from_enc = '_ICONV_FROM_ENCODING_';
56 my $macro_to_enc = '_ICONV_TO_ENCODING_';
57 my $macro_from_ucs_ces = 'ICONV_FROM_UCS_CES_';
58 my $macro_to_ucs_ces = 'ICONV_TO_UCS_CES_';
59 my $macro_from_ucs_ccs = 'ICONV_FROM_UCS_CCS_';
60 my $macro_to_ucs_ccs = 'ICONV_TO_UCS_CCS_';
61 my $macro_enc_name = 'ICONV_ENCODING_';
62 my $macro_ccs_name = 'ICONV_CCS_';
64 my $var_from_ucs_handlers = '_iconv_from_ucs_ces_handlers_';
65 my $var_to_ucs_handlers = '_iconv_to_ucs_ces_handlers_';
66 my $var_ccs = '_iconv_ccs_';
67 my $var_aliases = '_iconv_aliases';
68 my $var_ces_names = 'iconv_ces_names_';
70 # ==============================================================================
72 # PARSE COMMAND-LINE OPTIONS.
74 # ==============================================================================
81 my $verbose_opt = 'v';
83 # Default input configuration file name
84 my $default_infile = '../lib/encoding.deps';
85 # Real input configuration file name
87 # Verbose flag (be verbose if not zero)
91 getopts ("${help_opt}${verbose_opt}${infile_opt}:", \%options)
92 or err "getopts() failed: $!.";
94 if ($options{$help_opt})
96 # Output help message and exit.
97 print "Usage: $0 [-$infile_opt depfile] [-$help_opt]\n";
98 print "\t-$infile_opt - input file with configuration ($default_infile ";
99 print "file will be used by default)\n";
100 print "\t-$help_opt - this help message\n";
105 $infile = $options{$infile_opt} ? $options{$infile_opt} : $default_infile;
106 $verbose = $options{$verbose_opt} ? 1 : 0;
108 print "Debug: -$verbose_opt option found.\n" if $verbose;
110 # ==============================================================================
112 # Find and fetch sections from input file
114 # ==============================================================================
117 print "Debug: open \"$infile\" input file.\n" if $verbose;
118 open (INFILE, '<', $infile) or err "Can't open \"$infile\" file for reading.\n"
119 . "System error message: $!.\n";
121 # Configuration file markers
122 my $marker_section = 'SECTION';
123 my $marker_section_end = 'SECTION END';
125 # File sections. Hash values are references to arrays with section contents
128 # Extract sections from file
129 for (my $ln = 1; my $l = <INFILE>; $ln += 1)
131 # Skip comments and empty lines
132 next if $l =~ m/^#.*$/ or $l =~ m/^\s*$/;
134 # Remove last CR symbol
135 $l =~ s/^(.*)\n$/$1/, $l =~ s/^(.*)\r$/$1/;
137 # Generate error if line isn't section begin marker
138 err "(input file line $ln) Unexpected marker: \"$l\". ${marker_section} "
140 if $l !~ m/^$marker_section(\s+(\S*)\s*)?$/;
142 # Generate error if there is no section name
143 err "(input file line $ln) Section name isn't found"
146 # Generate error if this is section end marker
147 err "(input file line $ln) Unexpected \"${marker_section_end}\" marker "
149 if $2 eq $marker_section_end;
153 # Extract section content
154 for (; $l = <INFILE>; $ln += 1)
156 # Skip comments and empty lines
157 next if $l =~ m/^#.*$/ or $l =~ m/^$/;
158 # Remove last CR symbol
159 $l =~ s/^(.*)\n$/$1/, $l =~ s/^(.*)\r$/$1/;
161 last if $l =~ m/^$marker_section_end$/;
163 push @{$sections{$sect_name}}, $l;
166 # Generate error if section wasn't ended
167 err "(input file line $ln) \"No $marker_section_end\" marker found"
168 if $l !~ m/^$marker_section_end$/;
171 close INFILE or err "Error while closing input file.";
173 # =============================================================================
175 # Now sections are fetched. Each section is processed by separate function.
176 # There are only three supported sections now: ENCODINGS, CES_DEPENDENCIES
177 # and ENCODING_CCS_DEPENDENCIES.
179 # =============================================================================
181 my $section_encodings = 'ENCODINGS';
182 my $section_cesdeps = 'CES_DEPENDENCIES';
186 err "$section_encodings not found."
187 if !defined $sections{$section_encodings};
188 err "$section_cesdeps not found."
189 if !defined $sections{$section_cesdeps};
192 print "Debug: process $section_encodings section.\n" if $verbose;
193 process_section_encodings ($sections{$section_encodings});
194 delete $sections{$section_encodings};
196 print "Debug: process $section_cesdeps section.\n" if $verbose;
197 process_section_cesdeps ($sections{$section_cesdeps});
198 delete $sections{$section_cesdeps};
200 print STDERR "Warning: section \"$_\" was ignored!\n"
201 foreach (keys %sections);
206 # =============================================================================
208 # Print error message and exit.
210 # Parameter 1: error message.
212 # =============================================================================
215 print STDERR "Error while running script.\n$_[0]\n";
220 # =============================================================================
222 # Process ENCODINGS section.
224 # Parameter 1 (input): array reference with section content;
226 # =============================================================================
227 sub process_section_encodings($)
232 my $marker_encoding = 'ENCODING';
233 my $marker_ces = 'CES';
234 my $marker_ccs = 'CCS';
235 my $marker_aliases = 'ALIASES';
237 # Keys: CES names. Values: array reference with encodings list.
239 # Keys: encodings. Values: CES converter names.
241 # Keys: CCS tables names. Values: array reference with encodings.
243 # Keys: encodings. Values: aliases list.
246 while (next_entry ($sect, \@entry, \$lineidx))
253 foreach my $l (@entry)
255 if ($l =~ m/^($marker_encoding):\s*(\S*)\s*$/)
257 err "(process_section_encodings()) More than one $marker_encoding "
258 . "records found ($l)"
259 if defined $encoding;
263 elsif ($l =~ m/^($marker_ces):\s*(\S*)\s*$/)
265 err "(process_section_encodings()) More than one $marker_ces "
266 . "records found ($l)"
271 elsif ($l =~ m/^($marker_aliases):\s*(.*)\s*$/)
273 err "(process_section_encodings()) More than one "
274 . "$marker_aliases records found ($l)"
279 elsif ($l =~ m/^($marker_ccs):\s*(.*)\s*$/)
281 err "(process_section_encodings()) More than one "
282 . "$marker_ccs records found ($l)"
289 err "(process_section_encodings()) Can't parse \"$l\"";
293 err "(process_section_encodings()) $encoding is defined twice"
294 if (defined $encces{$encoding});
295 err "(process_section_encodings()) ENCODING: field isn't found"
296 if not defined $encoding;
300 push @{$cesenc{$ces}}, $encoding;
301 $encces{$encoding} = $ces;
306 my @ccs = split / /, $ccs;
307 push @{$ccsenc{$_}}, $encoding foreach (@ccs);
309 $encalias{$encoding} = $aliases;
312 # Generate cesbi.h header file
313 generate_cesbi_h (\%cesenc, \%encces);
315 # Generate encnames.h header file
316 generate_encnames_h (keys %encces);
318 # Generate aliasesbi.c file
319 generate_aliasesbi_c (\%encalias);
321 # Generate encoding.aliases file
322 generate_encoding_aliases (\%encalias);
324 # Generate ccsbi.h header file
325 generate_ccsbi_h (\%ccsenc);
327 # Generate cesbi.c file
328 generate_cesbi_c (\%cesenc);
330 # Generate ccsbi.c file
331 my @ccs = keys %ccsenc;
332 generate_ccsbi_c (\@ccs);
334 # Generate ccsnames.h header file
335 generate_ccsnames_h (\%ccsenc);
339 # ==============================================================================
341 # Process CES_DEPENDENCIES section.
343 # Parameter 1: array reference with section content.
345 # ==============================================================================
346 sub process_section_cesdeps($)
351 my $marker_ces = 'CES';
352 my $marker_used_ces = 'USED_CES';
355 while (next_entry ($sect, \@entry, \$lineidx))
360 foreach my $l (@entry)
362 if ($l =~ m/^($marker_ces):\s*(\S*)\s*$/)
364 err "(process_section_cesdeps()) More than one $marker_ces "
365 . "records found ($l)"
370 elsif ($l =~ m/^($marker_used_ces):\s*(.*)\s*$/)
372 err "(process_section_cesdeps()) More than one $marker_used_ces "
373 . "records found ($l)"
380 err "(process_section_cesdeps()) Can't parse \"$l\"";
384 err "(process_section_esdeps()) $ces dependecties are defined twice"
385 if (defined $cesdeps{$ces});
388 my @used_ces = split / /, $used_ces;
390 $cesdeps{$ces} = \@used_ces;
393 # Generate cesdeps.h header file
394 generate_cesdeps_h (\%cesdeps);
397 # ==============================================================================
399 # Extract next entry.
401 # Parameter 1 (input): array reference with entries;
402 # Parameter 2 (output): array reference with entry content;
403 # Parameter 3 (input/output): scalar reference with line index to process.
405 # Returns 1 is entry was found, 0 if thee is no more entries;
407 # ==============================================================================
413 my $marker_entry = 'ENTRY';
414 my $marker_entry_end = 'ENTRY END';
417 return 0 if not defined ${$entries}[${$idx}];
421 for (; my $l = ${$entries}[${$idx}++];)
423 # Skip comments and empty lines
424 next if $l =~ m/^#.*$/ or $l =~ m/^\s*$/;
426 if ($l =~ m/^$marker_entry$/)
428 err "(next_entry()) $marker_entry marker appears twice"
429 if ($entry_flag == 1);
431 $l = ${$entries}[${$idx}++]
435 # Generate error if line isn't entry begin marker
436 err "(next_entry()) Unexpected marker: \"$l\". ${marker_entry} "
438 if ($entry_flag == 0)
441 last if $l =~ m/^$marker_entry_end$/;
449 # ==============================================================================
451 # Generate cesbi.h file.
453 # Parameter 1 (input): hash reference with keys = CES Converters names and
454 # values = array references with list of supported encodings.
455 # Parameter 2 (input): hash reference with keys = encodings names and
456 # values = CES converter names.
458 # ==============================================================================
459 sub generate_cesbi_h($$)
461 my %cesenc = %{$_[0]};
462 my %encces = %{$_[1]};
463 my @ces = sort keys %cesenc;
465 print "Debug: create \"cesbi.h\" file.\n" if $verbose;
466 open (CESBI_H, '>', "cesbi.h")
467 or err "Can't create \"cesbi.h\" file for writing.\nSystem error message: $!.\n";
469 print CESBI_H "$comment_automatic\n\n";
470 print CESBI_H "#ifndef __CESBI_H__\n";
471 print CESBI_H "#define __CESBI_H__\n\n";
472 print CESBI_H "#include <newlib.h>\n";
473 print CESBI_H "#include <_ansi.h>\n";
474 print CESBI_H "#include \"../lib/encnames.h\"\n";
475 print CESBI_H "#include \"../lib/ucsconv.h\"\n\n";
476 print CESBI_H "/*\n";
477 print CESBI_H " * Enable CES converter if correspondent encoding is requested.\n";
478 print CESBI_H " * Defining ${macro_to_ucs_ces}XXX macro or ${macro_from_ucs_ces}XXX\n";
479 print CESBI_H " * macro is needed to enable \"XXX encoding -> UCS\" or \"UCS -> XXX encoding\"\n";
480 print CESBI_H " * part of UCS-based CES converter.\n";
481 print CESBI_H " */\n";
483 foreach my $ces (@ces)
485 my @encs = sort @{$cesenc{$ces}};
486 foreach my $encoding (@encs)
488 print CESBI_H $encoding eq $encs[0] ? "#if " : " || ";
489 print CESBI_H "defined ($macro_from_enc\U$encoding)";
490 print CESBI_H " \\" if $encoding ne $encs[$#encs];
493 print CESBI_H "# define $macro_to_ucs_ces\U$ces\n";
494 print CESBI_H "#endif\n";
496 foreach my $encoding (@encs)
498 print CESBI_H $encoding eq $encs[0] ? "#if " : " || ";
499 print CESBI_H "defined ($macro_to_enc\U$encoding)";
500 print CESBI_H " \\" if $encoding ne $encs[$#encs];
503 print CESBI_H "# define $macro_from_ucs_ces\U$ces\n";
504 print CESBI_H "#endif\n\n";
507 print CESBI_H "/*\n";
508 print CESBI_H " * Some encodings require another encodings to be enabled.\n";
509 print CESBI_H " * These dependencies are handled in cesdeps.h header file.\n";
510 print CESBI_H " */\n";
511 print CESBI_H "#include \"cesdeps.h\"\n\n";
513 print CESBI_H "/*\n";
514 print CESBI_H " * NLS uses iconv's capabilities and require one of encodings\n";
515 print CESBI_H " * to be enabled for internal wchar_t representation.\n";
516 print CESBI_H " */\n";
517 print CESBI_H "#include \"../lib/iconvnls.h\"\n\n";
519 print CESBI_H "/*\n";
520 print CESBI_H " * Forward declarations of CES converter handlers.\n";
521 print CESBI_H " * These handlers are actually defined in correspondent CES converter files.\n";
522 print CESBI_H " */\n";
524 foreach my $ces (@ces)
526 print CESBI_H "#ifdef $macro_to_ucs_ces\U$ces\n";
527 print CESBI_H "extern _CONST iconv_to_ucs_ces_handlers_t\n";
528 print CESBI_H "$var_to_ucs_handlers$ces;\n";
529 print CESBI_H "#endif\n";
531 print CESBI_H "#ifdef $macro_from_ucs_ces\U$ces\n";
532 print CESBI_H "extern _CONST iconv_from_ucs_ces_handlers_t\n";
533 print CESBI_H "$var_from_ucs_handlers$ces;\n";
534 print CESBI_H "#endif\n\n";
537 print CESBI_H "#endif /* !__CESBI_H__ */\n\n";
538 close CESBI_H or err "Error while closing cesbi.h file.";
541 # ==============================================================================
543 # Generate encnames.h header file.
545 # Parameters: array of supported encodings.
547 # ==============================================================================
548 sub generate_encnames_h(@)
550 print "Debug: create \"../lib/encnames.h\" file.\n" if $verbose;
551 open (ENCNAMES_H, '>', "../lib/encnames.h")
552 or err "Can't create \"../lib/encnames.h\" file for writing.\nSystem error message: $!.\n";
554 print ENCNAMES_H "$comment_automatic\n\n";
555 print ENCNAMES_H "#ifndef __ENCNAMES_H__\n";
556 print ENCNAMES_H "#define __ENCNAMES_H__\n\n";
558 print ENCNAMES_H "/*\n";
559 print ENCNAMES_H " * Encodings name macros.\n";
560 print ENCNAMES_H " */\n";
562 foreach my $enc (sort @_)
564 print ENCNAMES_H "#define $macro_enc_name\U$enc\E \"$enc\"\n";
567 print ENCNAMES_H "\n#endif /* !__ENCNAMES_H__ */\n\n";
568 close ENCNAMES_H or err "Error while closing ../lib/encnames.h file.";
571 # ==============================================================================
573 # Generate aliasesbi.c C source file.
575 # Parameters: hash reference with keys = encodings and values = aliases string.
577 # ==============================================================================
578 sub generate_aliasesbi_c($)
580 print "Debug: create \"../lib/aliasesbi.c\" file.\n" if $verbose;
581 open (ALIASESBI_C, '>', "../lib/aliasesbi.c")
582 or err "Can't create \"../lib/aliasesbi.c\" file for writing.\nSystem error message: $!.\n";
584 print ALIASESBI_C "$comment_automatic\n\n";
585 print ALIASESBI_C "#include <_ansi.h>\n";
586 print ALIASESBI_C "#include \"encnames.h\"\n\n";
587 print ALIASESBI_C "_CONST char *\n";
588 print ALIASESBI_C "$var_aliases =\n";
589 print ALIASESBI_C "{\n";
591 foreach my $enc (sort keys %{$_[0]})
593 print ALIASESBI_C "#if defined ($macro_from_enc\U$enc) \\\n";
594 print ALIASESBI_C " || defined ($macro_to_enc\U$enc)\n";
595 print ALIASESBI_C " $macro_enc_name\U$enc\E";
596 print ALIASESBI_C " \" ${$_[0]}{$enc}\\n\"" if defined ${$_[0]}{$enc};
597 print ALIASESBI_C "\n";
598 print ALIASESBI_C "#endif\n";
600 print ALIASESBI_C " \"\"\n";
601 print ALIASESBI_C "};\n\n";
603 close ALIASESBI_C or err "Error while closing ../lib/aliasesbi.c file.";
606 # ==============================================================================
608 # Generate encoding.aliases file.
610 # Parameter 1: hash reference with keys = encodings and values = aliases string.
612 # ==============================================================================
613 sub generate_encoding_aliases($)
615 print "Debug: create \"../encoding.aliases\" file.\n" if $verbose;
616 open (ALIASES, '>', "../encoding.aliases")
617 or err "Can't create \"../encoding.aliases\" file for writing.\nSystem error message: $!.\n";
619 print ALIASES "#\n# This file was automatically generated. Don't edit.\n#\n\n";
621 foreach my $enc (sort keys %{$_[0]})
623 print ALIASES "$enc";
624 print ALIASES " ${$_[0]}{$enc}" if defined ${$_[0]}{$enc};
630 close ALIASES or err "Error while closing ./encoding.aliases file.";
633 # ==============================================================================
635 # Generate cesdeps.h header file.
637 # Parameter 1: hash reference with keys = CES converters and values = references
638 # to arrays with list of CES converters which are needed by that CES converter
641 # ==============================================================================
642 sub generate_cesdeps_h($)
644 my %cesdeps = %{$_[0]};
646 print "Debug: create \"cesdeps.h\" file.\n" if $verbose;
647 open (CESDEPS_H, '>', "cesdeps.h")
648 or err "Can't create \"cesdeps.h\" file for writing.\nSystem error message: $!.\n";
650 print CESDEPS_H "$comment_automatic\n\n";
651 print CESDEPS_H "#ifndef __CESDEPS_H__\n";
652 print CESDEPS_H "#define __CESDEPS_H__\n\n";
654 print CESDEPS_H "/*\n";
655 print CESDEPS_H " * Some CES converters use another CES converters and the following\n";
656 print CESDEPS_H " * is such dependencies description.\n";
657 print CESDEPS_H " */\n";
659 foreach my $ces (sort keys %cesdeps)
661 my @deps = sort @{$cesdeps{$ces}};
663 print CESDEPS_H "#ifdef $macro_to_ucs_ces\U$ces\n";
665 foreach my $dep (@deps)
667 print CESDEPS_H "# ifndef $macro_to_ucs_ces\U$dep\n";
668 print CESDEPS_H "# define $macro_to_ucs_ces\U$dep\n";
669 print CESDEPS_H "# endif\n";
671 print CESDEPS_H "#endif\n";
673 print CESDEPS_H "#ifdef $macro_from_ucs_ces\U$ces\n";
674 foreach my $dep (@deps)
676 print CESDEPS_H "# ifndef $macro_from_ucs_ces\U$dep\n";
677 print CESDEPS_H "# define $macro_from_ucs_ces\U$dep\n";
678 print CESDEPS_H "# endif\n";
680 print CESDEPS_H "#endif\n";
683 print CESDEPS_H "\n#endif /* !__CESDEPS_H__ */\n\n";
684 close CESDEPS_H or err "Error while closing cesdeps.h file.";
687 # ==============================================================================
689 # Generate ccsbi.h file.
691 # Parameter 1 (input): hash reference with keys = CCS tables names and
692 # values = array references with list of encodings which need this CCS table.
694 # ==============================================================================
695 sub generate_ccsbi_h($)
697 my %ccsenc = %{$_[0]};
698 my @ccs = sort keys %ccsenc;
700 print "Debug: create \"../ccs/ccsbi.h\" file.\n" if $verbose;
701 open (CCSBI_H, '>', "../ccs/ccsbi.h")
702 or err "Can't create \"../ccs/ccsbi.h\" file for writing.\nSystem error message: $!.\n";
704 print CCSBI_H "$comment_automatic\n\n";
705 print CCSBI_H "#ifndef __CCSBI_H__\n";
706 print CCSBI_H "#define __CCSBI_H__\n\n";
707 print CCSBI_H "#include <newlib.h>\n";
708 print CCSBI_H "#include <_ansi.h>\n";
709 print CCSBI_H "#include \"ccs.h\"\n\n";
710 print CCSBI_H "/*\n";
711 print CCSBI_H " * Enable CCS tables if encoding needs them.\n";
712 print CCSBI_H " * Defining ${macro_to_ucs_ccs}XXX macro or ${macro_from_ucs_ccs}XXX\n";
713 print CCSBI_H " * macro is needed to enable \"XXX encoding -> UCS\" or \"UCS -> XXX encoding\"\n";
714 print CCSBI_H " * part of CCS table.\n";
715 print CCSBI_H " * CCS tables aren't linked if Newlib was configuted to use external CCS tables.\n";
716 print CCSBI_H " */\n";
718 print CCSBI_H "#ifndef _ICONV_ENABLE_EXTERNAL_CCS\n\n";
720 foreach my $ccs (@ccs)
722 my @encs = sort @{$ccsenc{$ccs}};
723 foreach my $encoding (@encs)
725 print CCSBI_H $encoding eq $encs[0] ? "#if " : " || ";
726 print CCSBI_H "defined ($macro_from_enc\U$encoding)";
727 print CCSBI_H " \\" if $encoding ne $encs[$#encs];
730 print CCSBI_H "# define $macro_to_ucs_ccs\U$ccs\n";
731 print CCSBI_H "#endif\n";
733 foreach my $encoding (@encs)
735 print CCSBI_H $encoding eq $encs[0] ? "#if " : " || ";
736 print CCSBI_H "defined ($macro_to_enc\U$encoding)";
737 print CCSBI_H " \\" if $encoding ne $encs[$#encs];
740 print CCSBI_H "# define $macro_from_ucs_ccs\U$ccs\n";
741 print CCSBI_H "#endif\n\n";
744 print CCSBI_H "/*\n";
745 print CCSBI_H " * CCS table description structures forward declarations.\n";
746 print CCSBI_H " */\n";
748 foreach my $ccs (@ccs)
750 print CCSBI_H "#if defined ($macro_to_ucs_ccs\U$ccs) \\\n";
751 print CCSBI_H " || defined ($macro_from_ucs_ccs\U$ccs)\n";
752 print CCSBI_H "extern _CONST iconv_ccs_t\n";
753 print CCSBI_H "$var_ccs$ccs;\n";
754 print CCSBI_H "#endif\n";
757 print CCSBI_H "\n#endif /* !_ICONV_ENABLE_EXTERNAL_CCS */\n\n";
758 print CCSBI_H "\n#endif /* __CCSBI_H__ */\n\n";
759 close CCSBI_H or err "Error while closing ../ccs/ccsbi.h file.";
762 # ==============================================================================
764 # Generate cesbi.c file.
766 # Parameter 1 (input): hash reference with keys = CES Converters names and
767 # values = array references with list of supported encodings.
769 # ==============================================================================
770 sub generate_cesbi_c($)
772 my %cesenc = %{$_[0]};
773 my @ces = sort keys %cesenc;
775 print "Debug: create \"cesbi.c\" file.\n" if $verbose;
776 open (CESBI_C, '>', "cesbi.c")
777 or err "Can't create \"cesbi.c\" file for writing.\nSystem error message: $!.\n";
779 print CESBI_C "$comment_automatic\n\n";
780 print CESBI_C "#include <_ansi.h>\n";
781 print CESBI_C "#include <newlib.h>\n";
782 print CESBI_C "#include \"../lib/ucsconv.h\"\n";
783 print CESBI_C "#include \"cesbi.h\"\n\n";
784 print CESBI_C "/*\n";
785 print CESBI_C " * Each CES converter provides the list of supported encodings.\n";
786 print CESBI_C " */\n";
788 foreach my $ces (@ces)
790 print CESBI_C "#if defined ($macro_to_ucs_ces\U$ces) \\\n";
791 print CESBI_C " || defined ($macro_from_ucs_ces\U$ces)\n";
792 print CESBI_C "static _CONST char *\n";
793 print CESBI_C "$var_ces_names${ces}\[] =\n";
795 my @encodings = sort @{$cesenc{$ces}};
796 foreach my $encoding (@encodings)
798 print CESBI_C "# if defined ($macro_from_enc\U$encoding) \\\n";
799 print CESBI_C " || defined ($macro_to_enc\U$encoding)\n";
800 print CESBI_C " $macro_enc_name\U$encoding,\n";
801 print CESBI_C "#endif\n";
803 print CESBI_C " NULL\n";
804 print CESBI_C "};\n";
805 print CESBI_C "#endif\n\n";
808 print CESBI_C "/*\n";
809 print CESBI_C " * The following structure contains the list of \"to UCS\" linked-in CES converters.\n";
810 print CESBI_C " */\n";
811 print CESBI_C "_CONST iconv_to_ucs_ces_t\n";
812 print CESBI_C "_iconv_to_ucs_ces[] =\n";
815 foreach my $ces (@ces)
817 print CESBI_C "#ifdef $macro_to_ucs_ces\U$ces\n";
818 print CESBI_C " {(_CONST char **)$var_ces_names$ces,\n";
819 print CESBI_C " &$var_to_ucs_handlers$ces},\n";
820 print CESBI_C "#endif\n";
822 print CESBI_C " {(_CONST char **)NULL,\n";
823 print CESBI_C " (iconv_to_ucs_ces_handlers_t *)NULL}\n";
824 print CESBI_C "};\n\n";
826 print CESBI_C "/*\n";
827 print CESBI_C " * The following structure contains the list of \"from UCS\" linked-in CES converters.\n";
828 print CESBI_C " */\n";
829 print CESBI_C "_CONST iconv_from_ucs_ces_t\n";
830 print CESBI_C "_iconv_from_ucs_ces[] =\n";
833 foreach my $ces (@ces)
835 print CESBI_C "#ifdef $macro_from_ucs_ces\U$ces\n";
836 print CESBI_C " {(_CONST char **)$var_ces_names$ces,\n";
837 print CESBI_C " &$var_from_ucs_handlers$ces},\n";
838 print CESBI_C "#endif\n";
840 print CESBI_C " {(_CONST char **)NULL,\n";
841 print CESBI_C " (iconv_from_ucs_ces_handlers_t *)NULL}\n";
842 print CESBI_C "};\n";
844 close CESBI_C or err "Error while closing cesbi.c file.";
847 # ==============================================================================
849 # Generate ccsbi.c file.
851 # Parameter 1 (input): array reference with CCS tables names
853 # ==============================================================================
854 sub generate_ccsbi_c($)
858 print "Debug: create \"../ccs/ccsbi.c\" file.\n" if $verbose;
859 open (CESBI_C, '>', "../ccs/ccsbi.c")
860 or err "Can't create \"../ccs/ccsbi.c\" file for writing.\nSystem error message: $!.\n";
862 print CESBI_C "$comment_automatic\n\n";
863 print CESBI_C "#include <_ansi.h>\n";
864 print CESBI_C "#include \"ccsbi.h\"\n\n";
865 print CESBI_C "/*\n";
866 print CESBI_C " * The following array contains the list of built-in CCS tables.\n";
867 print CESBI_C " */\n";
869 print CESBI_C "_CONST iconv_ccs_t *\n";
870 print CESBI_C "_iconv_ccs[] =\n";
873 foreach my $ccs (@ccs)
875 print CESBI_C "#if defined ($macro_to_ucs_ccs\U$ccs) \\\n";
876 print CESBI_C " || defined ($macro_from_ucs_ccs\U$ccs)\n";
877 print CESBI_C " &$var_ccs$ccs,\n";
878 print CESBI_C "#endif\n";
880 print CESBI_C " NULL\n";
881 print CESBI_C "};\n";
883 close CESBI_C or err "Error while closing ../ccs/ccsbi.c file.";
886 # ==============================================================================
888 # Generate ccsnames.h file.
890 # Parameter 1 (input): hash reference with keys = CCS tables names and
891 # values = array references with list of encodings which need this CCS table.
893 # ==============================================================================
894 sub generate_ccsnames_h($)
896 my %ccsenc = %{$_[0]};
897 my @ccs = sort keys %ccsenc;
899 print "Debug: create \"../ccs/ccsnames.h\" file.\n" if $verbose;
900 open (CCSNAMES_H, '>', "../ccs/ccsnames.h")
901 or err "Can't create \"../ccs/ccsnames.h\" file for writing.\nSystem error message: $!.\n";
903 print CCSNAMES_H "$comment_automatic\n\n";
904 print CCSNAMES_H "#ifndef __CCSNAMES_H__\n";
905 print CCSNAMES_H "#define __CCSNAMES_H__\n\n";
906 print CCSNAMES_H "#include \"../lib/encnames.h\"\n\n";
907 print CCSNAMES_H "/*\n";
908 print CCSNAMES_H " * CCS tables names macros.\n";
909 print CCSNAMES_H " */\n";
911 foreach my $ccs (@ccs)
913 my @encs = @{$ccsenc{$ccs}};
915 foreach my $encoding (@encs)
917 print CCSNAMES_H "#define $macro_ccs_name\U$ccs ";
918 if ($encoding eq $ccs)
921 print CCSNAMES_H "$macro_enc_name\U$encoding\n";
925 print CCSNAMES_H "\"$ccs\"\n" if !$flag;
928 print CCSNAMES_H "\n#endif /* !__CCSNAMES_H__ */\n\n";
929 close CCSNAMES_H or err "Error while closing ../ccs/ccsnames.h file.";