~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to cmd-line-utils/libedit/key.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $        */
 
1
/*      $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $        */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1992, 1993
32
32
 * SUCH DAMAGE.
33
33
 */
34
34
 
35
 
#include <config.h>
 
35
#include "config.h"
 
36
#if !defined(lint) && !defined(SCCSID)
 
37
#if 0
 
38
static char sccsid[] = "@(#)key.c       8.1 (Berkeley) 6/4/93";
 
39
#else
 
40
#endif
 
41
#endif /* not lint && not SCCSID */
36
42
 
37
43
/*
38
44
 * key.c: This module contains the procedures for maintaining
39
45
 *        the extended-key map.
40
46
 *
41
47
 *      An extended-key (key) is a sequence of keystrokes introduced
42
 
 *      with an sequence introducer and consisting of an arbitrary
 
48
 *      with a sequence introducer and consisting of an arbitrary
43
49
 *      number of characters.  This module maintains a map (the el->el_key.map)
44
50
 *      to convert these extended-key sequences into input strs
45
51
 *      (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
78
84
private int              node__try(EditLine *, key_node_t *, const char *,
79
85
    key_value_t *, int);
80
86
private key_node_t      *node__get(int);
 
87
private void             node__free(key_node_t *);
81
88
private void             node__put(EditLine *, key_node_t *);
82
89
private int              node__delete(EditLine *, key_node_t **, const char *);
83
90
private int              node_lookup(EditLine *, const char *, key_node_t *,
84
91
    int);
85
92
private int              node_enum(EditLine *, key_node_t *, int);
86
 
private int              key__decode_char(char *, int, int);
87
93
 
88
94
#define KEY_BUFSIZ      EL_BUFSIZ
89
95
 
103
109
        return (0);
104
110
}
105
111
 
106
 
 
107
112
/* key_end():
108
113
 *      Free the key maps
109
114
 */
113
118
 
114
119
        el_free((ptr_t) el->el_key.buf);
115
120
        el->el_key.buf = NULL;
116
 
        /* XXX: provide a function to clear the keys */
117
 
        el->el_key.map = NULL;
 
121
        node__free(el->el_key.map);
118
122
}
119
123
 
120
124
 
443
447
 
444
448
 
445
449
/* node__get():
446
 
 *      Returns pointer to an key_node_t for ch.
 
450
 *      Returns pointer to a key_node_t for ch.
447
451
 */
448
452
private key_node_t *
449
453
node__get(int ch)
461
465
        return (ptr);
462
466
}
463
467
 
464
 
 
 
468
private void
 
469
node__free(key_node_t *k)
 
470
{
 
471
        if (k == NULL)
 
472
                return;
 
473
        node__free(k->sibling);
 
474
        node__free(k->next);
 
475
        el_free((ptr_t) k);
 
476
}
465
477
 
466
478
/* node_lookup():
467
479
 *      look for the str starting at node ptr.
483
495
                /* If match put this char into el->el_key.buf.  Recurse */
484
496
                if (ptr->ch == *str) {
485
497
                        /* match found */
486
 
                        ncnt = key__decode_char(el->el_key.buf, cnt,
 
498
                        ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
487
499
                            (unsigned char) ptr->ch);
488
500
                        if (ptr->next != NULL)
489
501
                                /* not yet at leaf */
537
549
                return (-1);
538
550
        }
539
551
        /* put this char at end of str */
540
 
        ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch);
 
552
        ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
 
553
            (unsigned char)ptr->ch);
541
554
        if (ptr->next == NULL) {
542
555
                /* print this key and function */
543
556
                el->el_key.buf[ncnt + 1] = '"';
568
581
                switch (ntype) {
569
582
                case XK_STR:
570
583
                case XK_EXE:
571
 
                        (void) fprintf(el->el_outfile, fmt, key,
572
 
                            key__decode_str(val->str, unparsbuf,
573
 
                                ntype == XK_STR ? "\"\"" : "[]"));
 
584
                        (void) key__decode_str(val->str, unparsbuf,
 
585
                            sizeof(unparsbuf), 
 
586
                            ntype == XK_STR ? "\"\"" : "[]");
 
587
                        (void) fprintf(el->el_outfile, fmt, key, unparsbuf);
574
588
                        break;
575
589
                case XK_CMD:
576
590
                        for (fp = el->el_map.help; fp->name; fp++)
595
609
}
596
610
 
597
611
 
 
612
#define ADDC(c) \
 
613
        if (b < eb) \
 
614
                *b++ = c; \
 
615
        else \
 
616
                b++
598
617
/* key__decode_char():
599
618
 *      Put a printable form of char in buf.
600
619
 */
601
 
private int
602
 
key__decode_char(char *buf, int cnt, int ch)
 
620
protected int
 
621
key__decode_char(char *buf, int cnt, int off, int ch)
603
622
{
 
623
        char *sb = buf + off;
 
624
        char *eb = buf + cnt;
 
625
        char *b = sb;
604
626
        if (ch == 0) {
605
 
                buf[cnt++] = '^';
606
 
                buf[cnt] = '@';
607
 
                return (cnt);
 
627
                ADDC('^');
 
628
                ADDC('@');
 
629
                return b - sb;
608
630
        }
609
631
        if (iscntrl(ch)) {
610
 
                buf[cnt++] = '^';
 
632
                ADDC('^');
611
633
                if (ch == '\177')
612
 
                        buf[cnt] = '?';
 
634
                        ADDC('?');
613
635
                else
614
 
                        buf[cnt] = ch | 0100;
 
636
                        ADDC(ch | 0100);
615
637
        } else if (ch == '^') {
616
 
                buf[cnt++] = '\\';
617
 
                buf[cnt] = '^';
 
638
                ADDC('\\');
 
639
                ADDC('^');
618
640
        } else if (ch == '\\') {
619
 
                buf[cnt++] = '\\';
620
 
                buf[cnt] = '\\';
 
641
                ADDC('\\');
 
642
                ADDC('\\');
621
643
        } else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) {
622
 
                buf[cnt] = ch;
 
644
                ADDC(ch);
623
645
        } else {
624
 
                buf[cnt++] = '\\';
625
 
                buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0';
626
 
                buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0';
627
 
                buf[cnt] = (ch & 7) + '0';
 
646
                ADDC('\\');
 
647
                ADDC((((unsigned int) ch >> 6) & 7) + '0');
 
648
                ADDC((((unsigned int) ch >> 3) & 7) + '0');
 
649
                ADDC((ch & 7) + '0');
628
650
        }
629
 
        return (cnt);
 
651
        return b - sb;
630
652
}
631
653
 
632
654
 
633
655
/* key__decode_str():
634
656
 *      Make a printable version of the ey
635
657
 */
636
 
protected char *
637
 
key__decode_str(const char *str, char *buf, const char *sep)
 
658
protected int
 
659
key__decode_str(const char *str, char *buf, int len, const char *sep)
638
660
{
639
 
        char *b;
 
661
        char *b = buf, *eb = b + len;
640
662
        const char *p;
641
663
 
642
664
        b = buf;
643
 
        if (sep[0] != '\0')
644
 
                *b++ = sep[0];
645
 
        if (*str == 0) {
646
 
                *b++ = '^';
647
 
                *b++ = '@';
648
 
                if (sep[0] != '\0' && sep[1] != '\0')
649
 
                        *b++ = sep[1];
650
 
                *b++ = 0;
651
 
                return (buf);
 
665
        if (sep[0] != '\0') {
 
666
                ADDC(sep[0]);
 
667
        }
 
668
        if (*str == '\0') {
 
669
                ADDC('^');
 
670
                ADDC('@');
 
671
                if (sep[0] != '\0' && sep[1] != '\0') {
 
672
                        ADDC(sep[1]);
 
673
                }
 
674
                goto done;
652
675
        }
653
676
        for (p = str; *p != 0; p++) {
654
677
                if (iscntrl((unsigned char) *p)) {
655
 
                        *b++ = '^';
656
 
                        if (*p == '\177')
657
 
                                *b++ = '?';
658
 
                        else
659
 
                                *b++ = *p | 0100;
 
678
                        ADDC('^');
 
679
                        if (*p == '\177') {
 
680
                                ADDC('?');
 
681
                        } else {
 
682
                                ADDC(*p | 0100);
 
683
                        }
660
684
                } else if (*p == '^' || *p == '\\') {
661
 
                        *b++ = '\\';
662
 
                        *b++ = *p;
 
685
                        ADDC('\\');
 
686
                        ADDC(*p);
663
687
                } else if (*p == ' ' || (el_isprint((unsigned char) *p) &&
664
688
                        !isspace((unsigned char) *p))) {
665
 
                        *b++ = *p;
 
689
                        ADDC(*p);
666
690
                } else {
667
 
                        *b++ = '\\';
668
 
                        *b++ = (((unsigned int) *p >> 6) & 7) + '0';
669
 
                        *b++ = (((unsigned int) *p >> 3) & 7) + '0';
670
 
                        *b++ = (*p & 7) + '0';
 
691
                        ADDC('\\');
 
692
                        ADDC((((unsigned int) *p >> 6) & 7) + '0');
 
693
                        ADDC((((unsigned int) *p >> 3) & 7) + '0');
 
694
                        ADDC((*p & 7) + '0');
671
695
                }
672
696
        }
673
 
        if (sep[0] != '\0' && sep[1] != '\0')
674
 
                *b++ = sep[1];
675
 
        *b++ = 0;
676
 
        return (buf);           /* should check for overflow */
 
697
        if (sep[0] != '\0' && sep[1] != '\0') {
 
698
                ADDC(sep[1]);
 
699
        }
 
700
done:
 
701
        ADDC('\0');
 
702
        if (b - buf >= len)
 
703
            buf[len - 1] = '\0';
 
704
        return b - buf;
677
705
}