~ubuntu-branches/ubuntu/precise/texinfo/precise

« back to all changes in this revision

Viewing changes to makeinfo/lang.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2009-03-09 15:50:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090309155003-3k9a07mt2jqnuudg
Tags: 4.13a.dfsg.1-1
* new upstream releases (Closes: #500301)
  - fix (wrongly) added leading spaces in direntries (Closes: #457741)
  -  work with ~ in th epath (Closes: #495577)
  - disable the patch fix-direntry and fix-texi2dvi-bashism, 
    included upstream
* update the list of files to be installed (new translations, pdftexi2dvi)
* mange version in the watch file to remove the .dfsg.N part
* use quilt.make (first step in direction of source format 3.0, but that
  is broken)
* add README.Debian to info package (Closes: #513187)
* add README.source, bump standards version to 3.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* lang.c -- language-dependent support.
2
 
   $Id: lang.c,v 1.32 2007/08/16 17:42:20 karl Exp $
 
2
   $Id: lang.c,v 1.34 2007/12/03 01:38:43 karl Exp $
3
3
 
4
4
   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5
5
   Free Software Foundation, Inc.
486
486
  { ISO_8859_15, "iso-8859-15", (iso_map_type *) iso8859_15_map },
487
487
  { KOI8_R,      "koi8-r",      (iso_map_type *) koi8_map },
488
488
  { KOI8_U,      "koi8-u",      (iso_map_type *) koi8_map },
489
 
  { UTF_8,       "utf-8",       asis_map },  /* fixxme: much more needed */
 
489
  { UTF_8,       "utf-8",       asis_map },  /* specific code for this below */
490
490
  { last_encoding_code, NULL, NULL }
491
491
};
492
492
 
493
493
 
494
 
/* To update this list, download the current language table from
 
494
/* List of HTML entities.  */
 
495
static struct { const char *html; unsigned int unicode; } unicode_map[] = {
 
496
/* Extracted from http://www.w3.org/TR/html401/sgml/entities.html through
 
497
   sed -n -e 's|<!ENTITY \([^ ][^ ]*\) *CDATA "[&]#\([0-9][0-9]*\);".*|  { "\1", \2 },|p'
 
498
   | LC_ALL=C sort -k2  */
 
499
  { "AElig",     198 },
 
500
  { "Aacute",    193 },
 
501
  { "Acirc",     194 },
 
502
  { "Agrave",    192 },
 
503
  { "Alpha",     913 },
 
504
  { "Aring",     197 },
 
505
  { "Atilde",    195 },
 
506
  { "Auml",      196 },
 
507
  { "Beta",      914 },
 
508
  { "Ccedil",    199 },
 
509
  { "Chi",       935 },
 
510
  { "Dagger",   8225 },
 
511
  { "Delta",     916 },
 
512
  { "ETH",       208 },
 
513
  { "Eacute",    201 },
 
514
  { "Ecirc",     202 },
 
515
  { "Egrave",    200 },
 
516
  { "Epsilon",   917 },
 
517
  { "Eta",       919 },
 
518
  { "Euml",      203 },
 
519
  { "Gamma",     915 },
 
520
  { "Iacute",    205 },
 
521
  { "Icirc",     206 },
 
522
  { "Igrave",    204 },
 
523
  { "Iota",      921 },
 
524
  { "Iuml",      207 },
 
525
  { "Kappa",     922 },
 
526
  { "Lambda",    923 },
 
527
  { "Mu",        924 },
 
528
  { "Ntilde",    209 },
 
529
  { "Nu",        925 },
 
530
  { "OElig",     338 },
 
531
  { "Oacute",    211 },
 
532
  { "Ocirc",     212 },
 
533
  { "Ograve",    210 },
 
534
  { "Omega",     937 },
 
535
  { "Omicron",   927 },
 
536
  { "Oslash",    216 },
 
537
  { "Otilde",    213 },
 
538
  { "Ouml",      214 },
 
539
  { "Phi",       934 },
 
540
  { "Pi",        928 },
 
541
  { "Prime",    8243 },
 
542
  { "Psi",       936 },
 
543
  { "Rho",       929 },
 
544
  { "Scaron",    352 },
 
545
  { "Sigma",     931 },
 
546
  { "THORN",     222 },
 
547
  { "Tau",       932 },
 
548
  { "Theta",     920 },
 
549
  { "Uacute",    218 },
 
550
  { "Ucirc",     219 },
 
551
  { "Ugrave",    217 },
 
552
  { "Upsilon",   933 },
 
553
  { "Uuml",      220 },
 
554
  { "Xi",        926 },
 
555
  { "Yacute",    221 },
 
556
  { "Yuml",      376 },
 
557
  { "Zeta",      918 },
 
558
  { "aacute",    225 },
 
559
  { "acirc",     226 },
 
560
  { "acute",     180 },
 
561
  { "aelig",     230 },
 
562
  { "agrave",    224 },
 
563
  { "alefsym",  8501 },
 
564
  { "alpha",     945 },
 
565
  { "amp",        38 },
 
566
  { "and",      8743 },
 
567
  { "ang",      8736 },
 
568
  { "aring",     229 },
 
569
  { "asymp",    8776 },
 
570
  { "atilde",    227 },
 
571
  { "auml",      228 },
 
572
  { "bdquo",    8222 },
 
573
  { "beta",      946 },
 
574
  { "brvbar",    166 },
 
575
  { "bull",     8226 },
 
576
  { "cap",      8745 },
 
577
  { "ccedil",    231 },
 
578
  { "cedil",     184 },
 
579
  { "cent",      162 },
 
580
  { "chi",       967 },
 
581
  { "circ",      710 },
 
582
  { "clubs",    9827 },
 
583
  { "cong",     8773 },
 
584
  { "copy",      169 },
 
585
  { "crarr",    8629 },
 
586
  { "cup",      8746 },
 
587
  { "curren",    164 },
 
588
  { "dArr",     8659 },
 
589
  { "dagger",   8224 },
 
590
  { "darr",     8595 },
 
591
  { "deg",       176 },
 
592
  { "delta",     948 },
 
593
  { "diams",    9830 },
 
594
  { "divide",    247 },
 
595
  { "eacute",    233 },
 
596
  { "ecirc",     234 },
 
597
  { "egrave",    232 },
 
598
  { "empty",    8709 },
 
599
  { "emsp",     8195 },
 
600
  { "ensp",     8194 },
 
601
  { "epsilon",   949 },
 
602
  { "equiv",    8801 },
 
603
  { "eta",       951 },
 
604
  { "eth",       240 },
 
605
  { "euml",      235 },
 
606
  { "euro",     8364 },
 
607
  { "exist",    8707 },
 
608
  { "fnof",      402 },
 
609
  { "forall",   8704 },
 
610
  { "frac12",    189 },
 
611
  { "frac14",    188 },
 
612
  { "frac34",    190 },
 
613
  { "frasl",    8260 },
 
614
  { "gamma",     947 },
 
615
  { "ge",       8805 },
 
616
  { "gt",         62 },
 
617
  { "hArr",     8660 },
 
618
  { "harr",     8596 },
 
619
  { "hearts",   9829 },
 
620
  { "hellip",   8230 },
 
621
  { "iacute",    237 },
 
622
  { "icirc",     238 },
 
623
  { "iexcl",     161 },
 
624
  { "igrave",    236 },
 
625
  { "image",    8465 },
 
626
  { "infin",    8734 },
 
627
  { "int",      8747 },
 
628
  { "iota",      953 },
 
629
  { "iquest",    191 },
 
630
  { "isin",     8712 },
 
631
  { "iuml",      239 },
 
632
  { "kappa",     954 },
 
633
  { "lArr",     8656 },
 
634
  { "lambda",    955 },
 
635
  { "lang",     9001 },
 
636
  { "laquo",     171 },
 
637
  { "larr",     8592 },
 
638
  { "lceil",    8968 },
 
639
  { "ldquo",    8220 },
 
640
  { "le",       8804 },
 
641
  { "lfloor",   8970 },
 
642
  { "lowast",   8727 },
 
643
  { "loz",      9674 },
 
644
  { "lrm",      8206 },
 
645
  { "lsaquo",   8249 },
 
646
  { "lsquo",    8216 },
 
647
  { "lt",         60 },
 
648
  { "macr",      175 },
 
649
  { "mdash",    8212 },
 
650
  { "micro",     181 },
 
651
  { "middot",    183 },
 
652
  { "minus",    8722 },
 
653
  { "mu",        956 },
 
654
  { "nabla",    8711 },
 
655
  { "nbsp",      160 },
 
656
  { "ndash",    8211 },
 
657
  { "ne",       8800 },
 
658
  { "ni",       8715 },
 
659
  { "not",       172 },
 
660
  { "notin",    8713 },
 
661
  { "nsub",     8836 },
 
662
  { "ntilde",    241 },
 
663
  { "nu",        957 },
 
664
  { "oacute",    243 },
 
665
  { "ocirc",     244 },
 
666
  { "oelig",     339 },
 
667
  { "ograve",    242 },
 
668
  { "oline",    8254 },
 
669
  { "omega",     969 },
 
670
  { "omicron",   959 },
 
671
  { "oplus",    8853 },
 
672
  { "or",       8744 },
 
673
  { "ordf",      170 },
 
674
  { "ordm",      186 },
 
675
  { "oslash",    248 },
 
676
  { "otilde",    245 },
 
677
  { "otimes",   8855 },
 
678
  { "ouml",      246 },
 
679
  { "para",      182 },
 
680
  { "part",     8706 },
 
681
  { "permil",   8240 },
 
682
  { "perp",     8869 },
 
683
  { "phi",       966 },
 
684
  { "pi",        960 },
 
685
  { "piv",       982 },
 
686
  { "plusmn",    177 },
 
687
  { "pound",     163 },
 
688
  { "prime",    8242 },
 
689
  { "prod",     8719 },
 
690
  { "prop",     8733 },
 
691
  { "psi",       968 },
 
692
  { "quot",       34 },
 
693
  { "rArr",     8658 },
 
694
  { "radic",    8730 },
 
695
  { "rang",     9002 },
 
696
  { "raquo",     187 },
 
697
  { "rarr",     8594 },
 
698
  { "rceil",    8969 },
 
699
  { "rdquo",    8221 },
 
700
  { "real",     8476 },
 
701
  { "reg",       174 },
 
702
  { "rfloor",   8971 },
 
703
  { "rho",       961 },
 
704
  { "rlm",      8207 },
 
705
  { "rsaquo",   8250 },
 
706
  { "rsquo",    8217 },
 
707
  { "sbquo",    8218 },
 
708
  { "scaron",    353 },
 
709
  { "sdot",     8901 },
 
710
  { "sect",      167 },
 
711
  { "shy",       173 },
 
712
  { "sigma",     963 },
 
713
  { "sigmaf",    962 },
 
714
  { "sim",      8764 },
 
715
  { "spades",   9824 },
 
716
  { "sub",      8834 },
 
717
  { "sube",     8838 },
 
718
  { "sum",      8721 },
 
719
  { "sup",      8835 },
 
720
  { "sup1",      185 },
 
721
  { "sup2",      178 },
 
722
  { "sup3",      179 },
 
723
  { "supe",     8839 },
 
724
  { "szlig",     223 },
 
725
  { "tau",       964 },
 
726
  { "there4",   8756 },
 
727
  { "theta",     952 },
 
728
  { "thetasym",  977 },
 
729
  { "thinsp",   8201 },
 
730
  { "thorn",     254 },
 
731
  { "tilde",     732 },
 
732
  { "times",     215 },
 
733
  { "trade",    8482 },
 
734
  { "uArr",     8657 },
 
735
  { "uacute",    250 },
 
736
  { "uarr",     8593 },
 
737
  { "ucirc",     251 },
 
738
  { "ugrave",    249 },
 
739
  { "uml",       168 },
 
740
  { "upsih",     978 },
 
741
  { "upsilon",   965 },
 
742
  { "uuml",      252 },
 
743
  { "weierp",   8472 },
 
744
  { "xi",        958 },
 
745
  { "yacute",    253 },
 
746
  { "yen",       165 },
 
747
  { "yuml",      255 },
 
748
  { "zeta",      950 },
 
749
  { "zwj",      8205 },
 
750
  { "zwnj",     8204 }
 
751
};
 
752
 
 
753
 
 
754
 
 
755
/* To update this list of language codes, download the current data from
495
756
   http://www.loc.gov/standards/iso639-2; specifically,
496
757
   http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits-8559-1.txt.
497
758
   Run cut -d\| -f 3,4 <ISO-639-2_values_8bits-8559-1.txt | sort -u >/tmp/639.2
950
1211
  /* If we didn't find one to copy, warn and duplicate.  */
951
1212
  if (c == principal_len)
952
1213
    {
953
 
      if (strcasecmp (ll_code, "en") == 0)
 
1214
      if (mbscasecmp (ll_code, "en") == 0)
954
1215
        cc_code = xstrdup ("en_US");
955
1216
      else
956
1217
        {
1051
1312
static int
1052
1313
cm_search_iso_map (char *html)
1053
1314
{
1054
 
  int i;
1055
 
  iso_map_type *iso = encoding_table[document_encoding_code].isotab;
1056
 
 
1057
 
  /* If no conversion table for this encoding, quit.  */
1058
 
  if (!iso)
1059
 
    return -1;
1060
 
 
1061
 
  for (i = 0; iso[i].html; i++)
1062
 
    {
1063
 
      if (strcmp (html, iso[i].html) == 0)
1064
 
        return i;
1065
 
    }
1066
 
 
1067
 
  return -1;
 
1315
  if (document_encoding_code == UTF_8)
 
1316
    {
 
1317
      /* Binary search in unicode_map.  */
 
1318
      size_t low = 0;
 
1319
      size_t high = sizeof (unicode_map) / sizeof (unicode_map[0]);
 
1320
 
 
1321
      /* At each loop iteration, low < high; for indices < low the values are
 
1322
         smaller than HTML; for indices >= high the values are greater than HTML.
 
1323
         So, if HTML occurs in the list, it is at  low <= position < high.  */
 
1324
      do
 
1325
        {
 
1326
          size_t mid = low + (high - low) / 2; /* low <= mid < high */
 
1327
          int cmp = strcmp (unicode_map[mid].html, html);
 
1328
 
 
1329
          if (cmp < 0)
 
1330
            low = mid + 1;
 
1331
          else if (cmp > 0)
 
1332
            high = mid;
 
1333
          else /* cmp == 0 */
 
1334
            return unicode_map[mid].unicode;
 
1335
        }
 
1336
      while (low < high);
 
1337
 
 
1338
      return -1;
 
1339
    }
 
1340
  else
 
1341
    {
 
1342
      int i;
 
1343
      iso_map_type *iso = encoding_table[document_encoding_code].isotab;
 
1344
 
 
1345
      /* If no conversion table for this encoding, quit.  */
 
1346
      if (!iso)
 
1347
        return -1;
 
1348
 
 
1349
      for (i = 0; iso[i].html; i++)
 
1350
        {
 
1351
          if (strcmp (html, iso[i].html) == 0)
 
1352
            return i;
 
1353
        }
 
1354
 
 
1355
      return -1;
 
1356
    }
1068
1357
}
1069
1358
 
1070
1359
 
1097
1386
      /* See if we have this encoding.  */
1098
1387
      for (enc = no_encoding+1; enc != last_encoding_code; enc++)
1099
1388
        {
1100
 
          if (strcasecmp (enc_arg, encoding_table[enc].encname) == 0)
 
1389
          if (mbscasecmp (enc_arg, encoding_table[enc].encname) == 0)
1101
1390
            {
1102
1391
              document_encoding_code = enc;
1103
1392
              break;
1146
1435
}
1147
1436
 
1148
1437
 
 
1438
/* Add RC per the current encoding.  */
 
1439
 
 
1440
static void
 
1441
add_encoded_char_from_code (int rc)
 
1442
{
 
1443
  if (document_encoding_code == UTF_8)
 
1444
    {
 
1445
      if (rc < 0x80)
 
1446
        add_char (rc);
 
1447
      else if (rc < 0x800)
 
1448
        {
 
1449
          add_char (0xc0 | (rc >> 6));
 
1450
          add_char (0x80 | (rc & 0x3f));
 
1451
        }
 
1452
      else if (rc < 0x10000)
 
1453
        {
 
1454
          add_char (0xe0 | (rc >> 12));
 
1455
          add_char (0x80 | ((rc >> 6) & 0x3f));
 
1456
          add_char (0x80 | (rc & 0x3f));
 
1457
        }
 
1458
      else
 
1459
        {
 
1460
          add_char (0xf0 | (rc >> 18));
 
1461
          add_char (0x80 | ((rc >> 12) & 0x3f));
 
1462
          add_char (0x80 | ((rc >> 6) & 0x3f));
 
1463
          add_char (0x80 | (rc & 0x3f));
 
1464
        }
 
1465
    }
 
1466
  else
 
1467
    add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
 
1468
}
 
1469
 
 
1470
 
1149
1471
/* If html or xml output, add &HTML_STR; to the output.  If not html and
1150
1472
   the user requested encoded output, add the real 8-bit character
1151
1473
   corresponding to HTML_STR from the translation tables.  Otherwise,
1164
1486
      int rc = cm_search_iso_map (html_str);
1165
1487
      if (rc >= 0)
1166
1488
        /* We found it, add the real character.  */
1167
 
        add_char (encoding_table[document_encoding_code].isotab[rc].bytecode);
 
1489
        add_encoded_char_from_code (rc);
1168
1490
      else
1169
1491
        { /* We didn't find it, that seems bad.  */
1170
1492
          warning (_("invalid encoded character `%s'"), html_str);
1268
1590
 
1269
1591
          rc = cm_search_iso_map (buffer);
1270
1592
          if (rc >= 0)
1271
 
            /* A little bit tricky ;-)
1272
 
               Here we replace the character which has
1273
 
               been inserted in read_command with
1274
 
               the value we have found in converting table
1275
 
               Does there exist a better way to do this?  kama. */
1276
 
            output_paragraph[end - 1]
1277
 
              = encoding_table[document_encoding_code].isotab[rc].bytecode;
 
1593
            {
 
1594
              /* Here we replace the character which has
 
1595
                 been inserted in read_command with
 
1596
                 the value we have found in the conversion table.  */
 
1597
              output_paragraph_offset--;
 
1598
              add_encoded_char_from_code (rc);
 
1599
            }
1278
1600
          else
1279
1601
            { /* If we didn't find a translation for this character,
1280
1602
                 put the single instead. E.g., &Xuml; does not exist so X&uml;