~ubuntu-branches/ubuntu/natty/ncurses/natty

« back to all changes in this revision

Viewing changes to progs/infocmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-17 09:00:42 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517090042-86fgxrr6j5jzagot
Tags: 5.6-0ubuntu1
* New upstream version.
  - Remove patches applied upstream: ncurses.upstream, signed-chars.
  - Update patches: debian-backspace.
* Build-depend on g++-multilib instead of lib{32,64}c*-dev-*.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
 
2
 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
3
3
 *                                                                          *
4
4
 * Permission is hereby granted, free of charge, to any person obtaining a  *
5
5
 * copy of this software and associated documentation files (the            *
41
41
 
42
42
#include <dump_entry.h>
43
43
 
44
 
MODULE_ID("$Id: infocmp.c,v 1.79 2005/09/25 00:39:43 tom Exp $")
 
44
MODULE_ID("$Id: infocmp.c,v 1.85 2006/08/19 21:20:37 tom Exp $")
45
45
 
46
46
#define L_CURL "{"
47
47
#define R_CURL "}"
555
555
    return result;
556
556
}
557
557
 
 
558
static bool
 
559
same_param(const char *table, const char *param, unsigned length)
 
560
{
 
561
    bool result = FALSE;
 
562
    if (strncmp(table, param, length) == 0) {
 
563
        result = !isdigit(UChar(param[length]));
 
564
    }
 
565
    return result;
 
566
}
 
567
 
 
568
static char *
 
569
lookup_params(const assoc * table, char *dst, char *src)
 
570
{
 
571
    const char *ep = strtok(src, ";");
 
572
    const assoc *ap;
 
573
 
 
574
    do {
 
575
        bool found = FALSE;
 
576
 
 
577
        for (ap = table; ap->from; ap++) {
 
578
            size_t tlen = strlen(ap->from);
 
579
 
 
580
            if (same_param(ap->from, ep, tlen)) {
 
581
                (void) strcat(dst, ap->to);
 
582
                found = TRUE;
 
583
                break;
 
584
            }
 
585
        }
 
586
 
 
587
        if (!found)
 
588
            (void) strcat(dst, ep);
 
589
        (void) strcat(dst, ";");
 
590
    } while
 
591
        ((ep = strtok((char *) 0, ";")));
 
592
 
 
593
    dst[strlen(dst) - 1] = '\0';
 
594
 
 
595
    return dst;
 
596
}
 
597
 
558
598
static void
559
599
analyze_string(const char *name, const char *cap, TERMTYPE *tp)
560
600
{
561
601
    char buf[MAX_TERMINFO_LENGTH];
562
602
    char buf2[MAX_TERMINFO_LENGTH];
563
 
    const char *sp, *ep;
 
603
    const char *sp;
564
604
    const assoc *ap;
565
605
    int tp_lines = tp->Numbers[2];
566
606
 
573
613
        int i;
574
614
        int csi;
575
615
        size_t len = 0;
 
616
        size_t next;
576
617
        const char *expansion = 0;
 
618
        char buf3[MAX_TERMINFO_LENGTH];
577
619
 
578
620
        /* first, check other capabilities in this entry */
579
621
        for (i = 0; i < STRCOUNT; i++) {
617
659
                size_t adj = csi ? 2 : 0;
618
660
 
619
661
                len = strlen(ap->from);
 
662
                if (csi && skip_csi(ap->from) != csi)
 
663
                    continue;
620
664
                if (len > adj
621
665
                    && strncmp(ap->from + adj, sp + csi, len - adj) == 0) {
622
666
                    expansion = ap->to;
631
675
        if (!expansion
632
676
            && (csi = skip_csi(sp)) != 0
633
677
            && (len = strspn(sp + csi, "0123456789;"))
634
 
            && ((sp[csi + len] == 'h') || (sp[csi + len] == 'l'))) {
635
 
            char buf3[MAX_TERMINFO_LENGTH];
 
678
            && (next = csi + len)
 
679
            && ((sp[next] == 'h') || (sp[next] == 'l'))) {
636
680
 
637
 
            (void) strcpy(buf2, (sp[csi + len] == 'h') ? "ECMA+" : "ECMA-");
 
681
            (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-");
638
682
            (void) strncpy(buf3, sp + csi, len);
 
683
            buf3[len] = '\0';
639
684
            len += csi + 1;
640
 
            buf3[len] = '\0';
641
 
 
642
 
            ep = strtok(buf3, ";");
643
 
            do {
644
 
                bool found = FALSE;
645
 
 
646
 
                for (ap = std_modes; ap->from; ap++) {
647
 
                    size_t tlen = strlen(ap->from);
648
 
 
649
 
                    if (strncmp(ap->from, ep, tlen) == 0) {
650
 
                        (void) strcat(buf2, ap->to);
651
 
                        found = TRUE;
652
 
                        break;
653
 
                    }
654
 
                }
655
 
 
656
 
                if (!found)
657
 
                    (void) strcat(buf2, ep);
658
 
                (void) strcat(buf2, ";");
659
 
            } while
660
 
                ((ep = strtok((char *) 0, ";")));
661
 
            buf2[strlen(buf2) - 1] = '\0';
662
 
            expansion = buf2;
 
685
 
 
686
            expansion = lookup_params(std_modes, buf2, buf3);
663
687
        }
664
688
 
665
689
        /* now check for private-mode sequences */
667
691
            && (csi = skip_csi(sp)) != 0
668
692
            && sp[csi] == '?'
669
693
            && (len = strspn(sp + csi + 1, "0123456789;"))
670
 
            && ((sp[csi + 1 + len] == 'h') || (sp[csi + 1 + len] == 'l'))) {
671
 
            char buf3[MAX_TERMINFO_LENGTH];
 
694
            && (next = csi + 1 + len)
 
695
            && ((sp[next] == 'h') || (sp[next] == 'l'))) {
672
696
 
673
 
            (void) strcpy(buf2, (sp[csi + 1 + len] == 'h') ? "DEC+" : "DEC-");
 
697
            (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-");
674
698
            (void) strncpy(buf3, sp + csi + 1, len);
 
699
            buf3[len] = '\0';
675
700
            len += csi + 2;
676
 
            buf3[len] = '\0';
677
 
 
678
 
            ep = strtok(buf3, ";");
679
 
            do {
680
 
                bool found = FALSE;
681
 
 
682
 
                for (ap = private_modes; ap->from; ap++) {
683
 
                    size_t tlen = strlen(ap->from);
684
 
 
685
 
                    if (strncmp(ap->from, ep, tlen) == 0) {
686
 
                        (void) strcat(buf2, ap->to);
687
 
                        found = TRUE;
688
 
                        break;
689
 
                    }
690
 
                }
691
 
 
692
 
                if (!found)
693
 
                    (void) strcat(buf2, ep);
694
 
                (void) strcat(buf2, ";");
695
 
            } while
696
 
                ((ep = strtok((char *) 0, ";")));
697
 
            buf2[strlen(buf2) - 1] = '\0';
698
 
            expansion = buf2;
 
701
 
 
702
            expansion = lookup_params(private_modes, buf2, buf3);
699
703
        }
700
704
 
701
705
        /* now check for ECMA highlight sequences */
702
706
        if (!expansion
703
707
            && (csi = skip_csi(sp)) != 0
704
708
            && (len = strspn(sp + csi, "0123456789;")) != 0
705
 
            && sp[csi + len] == 'm') {
706
 
            char buf3[MAX_TERMINFO_LENGTH];
 
709
            && (next = csi + len)
 
710
            && sp[next] == 'm') {
707
711
 
708
712
            (void) strcpy(buf2, "SGR:");
709
713
            (void) strncpy(buf3, sp + csi, len);
 
714
            buf3[len] = '\0';
710
715
            len += csi + 1;
711
 
            buf3[len] = '\0';
712
 
 
713
 
            ep = strtok(buf3, ";");
714
 
            do {
715
 
                bool found = FALSE;
716
 
 
717
 
                for (ap = ecma_highlights; ap->from; ap++) {
718
 
                    size_t tlen = strlen(ap->from);
719
 
 
720
 
                    if (strncmp(ap->from, ep, tlen) == 0) {
721
 
                        (void) strcat(buf2, ap->to);
722
 
                        found = TRUE;
723
 
                        break;
724
 
                    }
725
 
                }
726
 
 
727
 
                if (!found)
728
 
                    (void) strcat(buf2, ep);
729
 
                (void) strcat(buf2, ";");
730
 
            } while
731
 
                ((ep = strtok((char *) 0, ";")));
732
 
 
733
 
            buf2[strlen(buf2) - 1] = '\0';
734
 
            expansion = buf2;
 
716
 
 
717
            expansion = lookup_params(ecma_highlights, buf2, buf3);
735
718
        }
736
719
 
737
720
        if (!expansion
1289
1272
 
1290
1273
    while ((c = getopt(argc,
1291
1274
                       argv,
1292
 
                       "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != EOF)
 
1275
                       "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != EOF) {
1293
1276
        switch (c) {
1294
1277
        case '1':
1295
1278
            mwidth = 0;
1405
1388
            else {
1406
1389
                (void) fprintf(stderr,
1407
1390
                               "infocmp: unknown sort mode\n");
1408
 
                return EXIT_FAILURE;
 
1391
                ExitProgram(EXIT_FAILURE);
1409
1392
            }
1410
1393
            break;
1411
1394
 
1450
1433
        default:
1451
1434
            usage();
1452
1435
        }
 
1436
    }
1453
1437
 
1454
1438
    /* by default, sort by terminfo name */
1455
1439
    if (sortmode == S_DEFAULT)
1477
1461
            if (termcount >= MAXTERMS) {
1478
1462
                (void) fprintf(stderr,
1479
1463
                               "infocmp: too many terminal type arguments\n");
1480
 
                return EXIT_FAILURE;
 
1464
                ExitProgram(EXIT_FAILURE);
1481
1465
            } else {
1482
1466
                const char *directory = termcount ? restdir : firstdir;
1483
1467
                int status;
1485
1469
                tname[termcount] = argv[optind];
1486
1470
 
1487
1471
                if (directory) {
 
1472
#if USE_DATABASE
1488
1473
                    (void) sprintf(tfile[termcount], "%s/%c/%s",
1489
1474
                                   directory,
1490
1475
                                   *argv[optind], argv[optind]);
1495
1480
 
1496
1481
                    status = _nc_read_file_entry(tfile[termcount],
1497
1482
                                                 &entries[termcount].tterm);
 
1483
#else
 
1484
                    (void) fprintf(stderr, "terminfo files not supported\n");
 
1485
                    ExitProgram(EXIT_FAILURE);
 
1486
#endif
1498
1487
                } else {
1499
1488
                    if (itrace)
1500
1489
                        (void) fprintf(stderr,
1501
 
                                       "infocmp: reading entry %s from system directories %s\n",
1502
 
                                       argv[optind], tname[termcount]);
 
1490
                                       "infocmp: reading entry %s from database\n",
 
1491
                                       tname[termcount]);
1503
1492
 
1504
1493
                    status = _nc_read_entry(tname[termcount],
1505
1494
                                            tfile[termcount],
1511
1500
                    (void) fprintf(stderr,
1512
1501
                                   "infocmp: couldn't open terminfo file %s.\n",
1513
1502
                                   tfile[termcount]);
1514
 
                    return EXIT_FAILURE;
 
1503
                    ExitProgram(EXIT_FAILURE);
1515
1504
                }
1516
1505
                repair_acsc(&entries[termcount].tterm);
1517
1506
                termcount++;
1529
1518
                dump_termtype(&entries[0].tterm);
1530
1519
            if (initdump & 2)
1531
1520
                dump_initializers(&entries[0].tterm);
1532
 
            ExitProgram(EXIT_SUCCESS);
1533
1521
        }
1534
1522
 
1535
1523
        /* analyze the init strings */
1536
 
        if (init_analyze) {
 
1524
        else if (init_analyze) {
1537
1525
#undef CUR
1538
1526
#define CUR     entries[0].tterm.
1539
1527
            analyze_string("is1", init_1string, &entries[0].tterm);
1545
1533
            analyze_string("smcup", enter_ca_mode, &entries[0].tterm);
1546
1534
            analyze_string("rmcup", exit_ca_mode, &entries[0].tterm);
1547
1535
#undef CUR
1548
 
            ExitProgram(EXIT_SUCCESS);
1549
 
        }
1550
 
 
1551
 
        /*
1552
 
         * Here's where the real work gets done
1553
 
         */
1554
 
        switch (compare) {
1555
 
        case C_DEFAULT:
1556
 
            if (itrace)
1557
 
                (void) fprintf(stderr,
1558
 
                               "infocmp: about to dump %s\n",
1559
 
                               tname[0]);
1560
 
            (void) printf("#\tReconstructed via infocmp from file: %s\n",
1561
 
                          tfile[0]);
1562
 
            len = dump_entry(&entries[0].tterm,
1563
 
                             suppress_untranslatable,
1564
 
                             limited,
1565
 
                             0,
1566
 
                             numbers,
1567
 
                             NULL);
1568
 
            putchar('\n');
1569
 
            if (itrace)
1570
 
                (void) fprintf(stderr, "infocmp: length %d\n", len);
1571
 
            break;
1572
 
 
1573
 
        case C_DIFFERENCE:
1574
 
            if (itrace)
1575
 
                (void) fprintf(stderr, "infocmp: dumping differences\n");
1576
 
            (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1577
 
            compare_entry(compare_predicate, &entries->tterm, quiet);
1578
 
            break;
1579
 
 
1580
 
        case C_COMMON:
1581
 
            if (itrace)
1582
 
                (void) fprintf(stderr,
1583
 
                               "infocmp: dumping common capabilities\n");
1584
 
            (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1585
 
            compare_entry(compare_predicate, &entries->tterm, quiet);
1586
 
            break;
1587
 
 
1588
 
        case C_NAND:
1589
 
            if (itrace)
1590
 
                (void) fprintf(stderr,
1591
 
                               "infocmp: dumping differences\n");
1592
 
            (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1593
 
            compare_entry(compare_predicate, &entries->tterm, quiet);
1594
 
            break;
1595
 
 
1596
 
        case C_USEALL:
1597
 
            if (itrace)
1598
 
                (void) fprintf(stderr, "infocmp: dumping use entry\n");
1599
 
            len = dump_entry(&entries[0].tterm,
1600
 
                             suppress_untranslatable,
1601
 
                             limited,
1602
 
                             0,
1603
 
                             numbers,
1604
 
                             use_predicate);
1605
 
            for (i = 1; i < termcount; i++)
1606
 
                len += dump_uses(tname[i], !(outform == F_TERMCAP
1607
 
                                             || outform == F_TCONVERR));
1608
 
            putchar('\n');
1609
 
            if (itrace)
1610
 
                (void) fprintf(stderr, "infocmp: length %d\n", len);
1611
 
            break;
 
1536
        } else {
 
1537
 
 
1538
            /*
 
1539
             * Here's where the real work gets done
 
1540
             */
 
1541
            switch (compare) {
 
1542
            case C_DEFAULT:
 
1543
                if (itrace)
 
1544
                    (void) fprintf(stderr,
 
1545
                                   "infocmp: about to dump %s\n",
 
1546
                                   tname[0]);
 
1547
                (void) printf("#\tReconstructed via infocmp from file: %s\n",
 
1548
                              tfile[0]);
 
1549
                dump_entry(&entries[0].tterm,
 
1550
                           suppress_untranslatable,
 
1551
                           limited,
 
1552
                           numbers,
 
1553
                           NULL);
 
1554
                len = show_entry();
 
1555
                if (itrace)
 
1556
                    (void) fprintf(stderr, "infocmp: length %d\n", len);
 
1557
                break;
 
1558
 
 
1559
            case C_DIFFERENCE:
 
1560
                if (itrace)
 
1561
                    (void) fprintf(stderr, "infocmp: dumping differences\n");
 
1562
                (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
 
1563
                compare_entry(compare_predicate, &entries->tterm, quiet);
 
1564
                break;
 
1565
 
 
1566
            case C_COMMON:
 
1567
                if (itrace)
 
1568
                    (void) fprintf(stderr,
 
1569
                                   "infocmp: dumping common capabilities\n");
 
1570
                (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
 
1571
                compare_entry(compare_predicate, &entries->tterm, quiet);
 
1572
                break;
 
1573
 
 
1574
            case C_NAND:
 
1575
                if (itrace)
 
1576
                    (void) fprintf(stderr,
 
1577
                                   "infocmp: dumping differences\n");
 
1578
                (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
 
1579
                compare_entry(compare_predicate, &entries->tterm, quiet);
 
1580
                break;
 
1581
 
 
1582
            case C_USEALL:
 
1583
                if (itrace)
 
1584
                    (void) fprintf(stderr, "infocmp: dumping use entry\n");
 
1585
                dump_entry(&entries[0].tterm,
 
1586
                           suppress_untranslatable,
 
1587
                           limited,
 
1588
                           numbers,
 
1589
                           use_predicate);
 
1590
                for (i = 1; i < termcount; i++)
 
1591
                    dump_uses(tname[i], !(outform == F_TERMCAP
 
1592
                                          || outform == F_TCONVERR));
 
1593
                len = show_entry();
 
1594
                if (itrace)
 
1595
                    (void) fprintf(stderr, "infocmp: length %d\n", len);
 
1596
                break;
 
1597
            }
1612
1598
        }
1613
1599
    } else if (compare == C_USEALL)
1614
1600
        (void) fprintf(stderr, "Sorry, -u doesn't work with -F\n");
1620
1606
    else
1621
1607
        file_comparison(argc - optind, argv + optind);
1622
1608
 
 
1609
    free(tfile);
1623
1610
    ExitProgram(EXIT_SUCCESS);
1624
1611
}
1625
1612