enable_encoding.pm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*-perl-*-
  2. #+##############################################################################
  3. #
  4. # enable_encoding.pm: mimics --enable-encoding
  5. # This is now directly handled in the main program. It is, however different
  6. # from the main program implementation snce this init file is much more
  7. # intrusive (for example it wouldn't work with info, but it would work
  8. # better for a simple output format when entities are not used).
  9. #
  10. # Copyright (C) 2008 Free Software Foundation, Inc.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 3 of the License,
  15. # or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. # Originally written by Patrice Dumas.
  26. #
  27. #-##############################################################################
  28. use strict;
  29. my $enable_encoding_default_init_out = $init_out;
  30. $init_out = \&enable_encoding_init_out;
  31. # badly interact with --enable-encoding support in info.pm
  32. set_from_init_file('ENABLE_ENCODING', 0);
  33. sub enable_encoding_init_out()
  34. {
  35. &$enable_encoding_default_init_out();
  36. # like utf8.pm
  37. if (get_conf('ENCODING_NAME') eq 'utf-8')
  38. {
  39. $normal_text = \&t2h_utf8_normal_text unless (get_conf('ENABLE_ENCODING_USE_ENTITY'));
  40. foreach my $key (keys(%unicode_accents), 'dotless')
  41. {
  42. $style_map{$key}->{'function'} = \&t2h_utf8_accent;
  43. $style_map_texi{$key}->{'function'} = \&t2h_utf8_accent;
  44. $style_map_pre{$key}->{'function'} = \&t2h_utf8_accent;
  45. }
  46. foreach my $key (%things_map)
  47. {
  48. if (exists($unicode_map{$key}) and ($unicode_map{$key} ne ''))
  49. {
  50. $things_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($things_map{$key}));
  51. $texi_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($texi_map{$key}));
  52. $sorting_things_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($sorting_things_map{$key}));
  53. $pre_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($pre_map{$key}));
  54. }
  55. }
  56. }
  57. elsif (exists($makeinfo_encoding_to_map{get_conf('ENCODING_NAME')}))
  58. {
  59. my $enc_map = $makeinfo_encoding_to_map{get_conf('ENCODING_NAME')};
  60. foreach my $key (keys(%unicode_accents), 'dotless')
  61. {
  62. $t2h_enable_encoding_default_accent{'normal'}->{$key} = $style_map{$key}->{'function'};
  63. $t2h_enable_encoding_default_accent{'texi'}->{$key} = $style_map_texi{$key}->{'function'};
  64. $t2h_enable_encoding_default_accent{'pre'}->{$key} = $style_map_pre{$key}->{'function'};
  65. $style_map{$key}->{'function'} = \&t2h_enable_encoding_normal_accent;
  66. $style_map_texi{$key}->{'function'} = \&t2h_enable_encoding_texi_accent;
  67. $style_map_pre{$key}->{'function'} = \&t2h_enable_encoding_pre_accent;
  68. }
  69. foreach my $key (%things_map)
  70. {
  71. if (exists($unicode_map{$key}) and ($unicode_map{$key} ne '') and
  72. exists($makeinfo_unicode_to_eight_bit{$enc_map}->{$unicode_map{$key}}))
  73. { # we let perl handle the conversion
  74. $things_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($things_map{$key}));
  75. $texi_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($texi_map{$key}));
  76. $sorting_things_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($sorting_things_map{$key}));
  77. $pre_map{$key} = chr(hex($unicode_map{$key})) unless (t2h_encoding_is_entity($pre_map{$key}));
  78. }
  79. }
  80. }
  81. }
  82. 1;