~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-02-14 23:59:22 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120214235922-cux5uek1e5l0hje9
Tags: 5.5.20-0ubuntu1
* New upstream release.
* d/mysql-server-5.5.mysql.upstart: Fix stop on to make sure mysql is
  fully stopped before shutdown commences. (LP: #688541) Also simplify
  start on as it is redundant.
* d/control: Depend on upstart version which has apparmor profile load
  script to prevent failure on upgrade from lucid to precise.
  (LP: #907465)
* d/apparmor-profile: need to allow /run since that is the true path
  of /var/run files. (LP: #917542)
* d/control: mysql-server-5.5 has files in it that used to be owned
  by libmysqlclient-dev, so it must break/replace it. (LP: #912487)
* d/rules, d/control: 5.5.20 Fixes segfault on tests with gcc 4.6,
  change compiler back to system default.
* d/rules: Turn off embedded libedit/readline.(Closes: #659566)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $ */
 
1
/*      $NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $      */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1992, 1993
57
57
#include <stdlib.h>
58
58
 
59
59
private const struct {
60
 
        const char *name;
61
 
        int (*func)(EditLine *, int, const char **);
 
60
        const Char *name;
 
61
        int (*func)(EditLine *, int, const Char **);
62
62
} cmds[] = {
63
 
        { "bind",       map_bind        },
64
 
        { "echotc",     term_echotc     },
65
 
        { "edit",       el_editmode     },
66
 
        { "history",    hist_command    },
67
 
        { "telltc",     term_telltc     },
68
 
        { "settc",      term_settc      },
69
 
        { "setty",      tty_stty        },
70
 
        { NULL,         NULL            }
 
63
        { STR("bind"),          map_bind        },
 
64
        { STR("echotc"),        terminal_echotc },
 
65
        { STR("edit"),          el_editmode     },
 
66
        { STR("history"),       hist_command    },
 
67
        { STR("telltc"),        terminal_telltc },
 
68
        { STR("settc"),         terminal_settc  },
 
69
        { STR("setty"),         tty_stty        },
 
70
        { NULL,                 NULL            }
71
71
};
72
72
 
73
73
 
75
75
 *      Parse a line and dispatch it
76
76
 */
77
77
protected int
78
 
parse_line(EditLine *el, const char *line)
 
78
parse_line(EditLine *el, const Char *line)
79
79
{
80
 
        const char **argv;
 
80
        const Char **argv;
81
81
        int argc;
82
 
        Tokenizer *tok;
 
82
        TYPE(Tokenizer) *tok;
83
83
 
84
 
        tok = tok_init(NULL);
85
 
        tok_str(tok, line, &argc, &argv);
86
 
        argc = el_parse(el, argc, argv);
87
 
        tok_end(tok);
88
 
        return (argc);
 
84
        tok = FUN(tok,init)(NULL);
 
85
        FUN(tok,str)(tok, line, &argc, &argv);
 
86
        argc = FUN(el,parse)(el, argc, argv);
 
87
        FUN(tok,end)(tok);
 
88
        return argc;
89
89
}
90
90
 
91
91
 
93
93
 *      Command dispatcher
94
94
 */
95
95
public int
96
 
el_parse(EditLine *el, int argc, const char *argv[])
 
96
FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
97
97
{
98
 
        const char *ptr;
 
98
        const Char *ptr;
99
99
        int i;
100
100
 
101
101
        if (argc < 1)
102
 
                return (-1);
103
 
        ptr = strchr(argv[0], ':');
 
102
                return -1;
 
103
        ptr = Strchr(argv[0], ':');
104
104
        if (ptr != NULL) {
105
 
                char *tprog;
 
105
                Char *tprog;
106
106
                size_t l;
107
107
 
108
108
                if (ptr == argv[0])
109
 
                        return (0);
110
 
                l = ptr - argv[0] - 1;
111
 
                tprog = (char *) el_malloc(l + 1);
 
109
                        return 0;
 
110
                l = (size_t)(ptr - argv[0] - 1);
 
111
                tprog = el_malloc((l + 1) * sizeof(*tprog));
112
112
                if (tprog == NULL)
113
 
                        return (0);
114
 
                (void) strncpy(tprog, argv[0], l);
 
113
                        return 0;
 
114
                (void) Strncpy(tprog, argv[0], l);
115
115
                tprog[l] = '\0';
116
116
                ptr++;
117
 
                l = el_match(el->el_prog, tprog);
 
117
                l = (size_t)el_match(el->el_prog, tprog);
118
118
                el_free(tprog);
119
119
                if (!l)
120
 
                        return (0);
 
120
                        return 0;
121
121
        } else
122
122
                ptr = argv[0];
123
123
 
124
124
        for (i = 0; cmds[i].name != NULL; i++)
125
 
                if (strcmp(cmds[i].name, ptr) == 0) {
 
125
                if (Strcmp(cmds[i].name, ptr) == 0) {
126
126
                        i = (*cmds[i].func) (el, argc, argv);
127
 
                        return (-i);
 
127
                        return -i;
128
128
                }
129
 
        return (-1);
 
129
        return -1;
130
130
}
131
131
 
132
132
 
133
133
/* parse__escape():
134
 
 *      Parse a string of the form ^<char> \<odigit> \<char> and return
 
134
 *      Parse a string of the form ^<char> \<odigit> \<char> \U+xxxx and return
135
135
 *      the appropriate character or -1 if the escape is not valid
136
136
 */
137
137
protected int
138
 
parse__escape(const char **ptr)
 
138
parse__escape(const Char **ptr)
139
139
{
140
 
        const char *p;
141
 
        int c;
 
140
        const Char *p;
 
141
        Int c;
142
142
 
143
143
        p = *ptr;
144
144
 
145
145
        if (p[1] == 0)
146
 
                return (-1);
 
146
                return -1;
147
147
 
148
148
        if (*p == '\\') {
149
149
                p++;
172
172
                case 'e':
173
173
                        c = '\033';     /* Escape */
174
174
                        break;
 
175
                case 'U':               /* Unicode \U+xxxx or \U+xxxxx format */
 
176
                {
 
177
                        int i;
 
178
                        const Char hex[] = STR("0123456789ABCDEF");
 
179
                        const Char *h;
 
180
                        ++p;
 
181
                        if (*p++ != '+')
 
182
                                return -1;
 
183
                        c = 0;
 
184
                        for (i = 0; i < 5; ++i) {
 
185
                                h = Strchr(hex, *p++);
 
186
                                if (!h && i < 4)
 
187
                                        return -1;
 
188
                                else if (h)
 
189
                                        c = (c << 4) | ((int)(h - hex));
 
190
                                else
 
191
                                        --p;
 
192
                        }
 
193
                        if (c > 0x10FFFF) /* outside valid character range */
 
194
                                return -1;
 
195
                        break;
 
196
                }
175
197
                case '0':
176
198
                case '1':
177
199
                case '2':
191
213
                                }
192
214
                                c = (c << 3) | (ch - '0');
193
215
                        }
194
 
                        if ((c & 0xffffff00) != 0)
195
 
                                return (-1);
 
216
                        if ((c & (wint_t)0xffffff00) != (wint_t)0)
 
217
                                return -1;
196
218
                        --p;
197
219
                        break;
198
220
                }
206
228
        } else
207
229
                c = *p;
208
230
        *ptr = ++p;
209
 
        return (c);
 
231
        return c;
210
232
}
211
233
 
212
234
/* parse__string():
213
235
 *      Parse the escapes from in and put the raw string out
214
236
 */
215
 
protected char *
216
 
parse__string(char *out, const char *in)
 
237
protected Char *
 
238
parse__string(Char *out, const Char *in)
217
239
{
218
 
        char *rv = out;
 
240
        Char *rv = out;
219
241
        int n;
220
242
 
221
243
        for (;;)
222
244
                switch (*in) {
223
245
                case '\0':
224
246
                        *out = '\0';
225
 
                        return (rv);
 
247
                        return rv;
226
248
 
227
249
                case '\\':
228
250
                case '^':
229
251
                        if ((n = parse__escape(&in)) == -1)
230
 
                                return (NULL);
 
252
                                return NULL;
231
253
                        *out++ = n;
232
254
                        break;
233
255
 
251
273
 *      or -1 if one is not found
252
274
 */
253
275
protected int
254
 
parse_cmd(EditLine *el, const char *cmd)
 
276
parse_cmd(EditLine *el, const Char *cmd)
255
277
{
256
278
        el_bindings_t *b;
257
279
 
258
280
        for (b = el->el_map.help; b->name != NULL; b++)
259
 
                if (strcmp(b->name, cmd) == 0)
260
 
                        return (b->func);
261
 
        return (-1);
 
281
                if (Strcmp(b->name, cmd) == 0)
 
282
                        return b->func;
 
283
        return -1;
262
284
}