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

« back to all changes in this revision

Viewing changes to cmd-line-utils/libedit/vi.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: vi.c,v 1.28 2009/02/06 13:14:37 sketch Exp $   */
 
1
/*      $NetBSD: vi.c,v 1.41 2011/10/04 15:27:04 christos Exp $ */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1992, 1993
35
35
#include "config.h"
36
36
#include <stdlib.h>
37
37
#include <unistd.h>
 
38
#include <limits.h>
38
39
#include <sys/wait.h>
39
40
 
40
41
#if !defined(lint) && !defined(SCCSID)
49
50
 */
50
51
#include "el.h"
51
52
 
52
 
private el_action_t     cv_action(EditLine *, int);
53
 
private el_action_t     cv_paste(EditLine *, int);
 
53
private el_action_t     cv_action(EditLine *, Int);
 
54
private el_action_t     cv_paste(EditLine *, Int);
54
55
 
55
56
/* cv_action():
56
57
 *      Handle vi actions.
57
58
 */
58
59
private el_action_t
59
 
cv_action(EditLine *el, int c)
 
60
cv_action(EditLine *el, Int c)
60
61
{
61
62
 
62
63
        if (el->el_chared.c_vcmd.action != NOP) {
63
64
                /* 'cc', 'dd' and (possibly) friends */
64
 
                if (c != el->el_chared.c_vcmd.action)
 
65
                if (c != (Int)el->el_chared.c_vcmd.action)
65
66
                        return CC_ERROR;
66
67
 
67
68
                if (!(c & YANK))
68
69
                        cv_undo(el);
69
70
                cv_yank(el, el->el_line.buffer,
70
 
                            el->el_line.lastchar - el->el_line.buffer);
 
71
                    (int)(el->el_line.lastchar - el->el_line.buffer));
71
72
                el->el_chared.c_vcmd.action = NOP;
72
73
                el->el_chared.c_vcmd.pos = 0;
73
74
                if (!(c & YANK)) {
77
78
                if (c & INSERT)
78
79
                        el->el_map.current = el->el_map.key;
79
80
 
80
 
                return (CC_REFRESH);
 
81
                return CC_REFRESH;
81
82
        }
82
83
        el->el_chared.c_vcmd.pos = el->el_line.cursor;
83
84
        el->el_chared.c_vcmd.action = c;
84
 
        return (CC_ARGHACK);
 
85
        return CC_ARGHACK;
85
86
}
86
87
 
87
88
/* cv_paste():
88
89
 *      Paste previous deletion before or after the cursor
89
90
 */
90
91
private el_action_t
91
 
cv_paste(EditLine *el, int c)
 
92
cv_paste(EditLine *el, Int c)
92
93
{
93
94
        c_kill_t *k = &el->el_chared.c_kill;
94
 
        int len = k->last - k->buf;
 
95
        size_t len = (size_t)(k->last - k->buf);
95
96
 
96
97
        if (k->buf == NULL || len == 0)
97
 
                return (CC_ERROR);
 
98
                return CC_ERROR;
98
99
#ifdef DEBUG_PASTE
99
 
        (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", len, k->buf);
 
100
        (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
100
101
#endif
101
102
 
102
103
        cv_undo(el);
104
105
        if (!c && el->el_line.cursor < el->el_line.lastchar)
105
106
                el->el_line.cursor++;
106
107
 
107
 
        c_insert(el, len);
 
108
        c_insert(el, (int)len);
108
109
        if (el->el_line.cursor + len > el->el_line.lastchar)
109
 
                return (CC_ERROR);
110
 
        (void) memcpy(el->el_line.cursor, k->buf, len +0u);
 
110
                return CC_ERROR;
 
111
        (void) memcpy(el->el_line.cursor, k->buf, len *
 
112
            sizeof(*el->el_line.cursor));
111
113
 
112
 
        return (CC_REFRESH);
 
114
        return CC_REFRESH;
113
115
}
114
116
 
115
117
 
119
121
 */
120
122
protected el_action_t
121
123
/*ARGSUSED*/
122
 
vi_paste_next(EditLine *el, int c __attribute__((__unused__)))
 
124
vi_paste_next(EditLine *el, Int c __attribute__((__unused__)))
123
125
{
124
126
 
125
 
        return (cv_paste(el, 0));
 
127
        return cv_paste(el, 0);
126
128
}
127
129
 
128
130
 
132
134
 */
133
135
protected el_action_t
134
136
/*ARGSUSED*/
135
 
vi_paste_prev(EditLine *el, int c __attribute__((__unused__)))
 
137
vi_paste_prev(EditLine *el, Int c __attribute__((__unused__)))
136
138
{
137
139
 
138
 
        return (cv_paste(el, 1));
 
140
        return cv_paste(el, 1);
139
141
}
140
142
 
141
143
 
145
147
 */
146
148
protected el_action_t
147
149
/*ARGSUSED*/
148
 
vi_prev_big_word(EditLine *el, int c __attribute__((__unused__)))
 
150
vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__)))
149
151
{
150
152
 
151
153
        if (el->el_line.cursor == el->el_line.buffer)
152
 
                return (CC_ERROR);
 
154
                return CC_ERROR;
153
155
 
154
156
        el->el_line.cursor = cv_prev_word(el->el_line.cursor,
155
157
            el->el_line.buffer,
158
160
 
159
161
        if (el->el_chared.c_vcmd.action != NOP) {
160
162
                cv_delfini(el);
161
 
                return (CC_REFRESH);
 
163
                return CC_REFRESH;
162
164
        }
163
 
        return (CC_CURSOR);
 
165
        return CC_CURSOR;
164
166
}
165
167
 
166
168
 
170
172
 */
171
173
protected el_action_t
172
174
/*ARGSUSED*/
173
 
vi_prev_word(EditLine *el, int c __attribute__((__unused__)))
 
175
vi_prev_word(EditLine *el, Int c __attribute__((__unused__)))
174
176
{
175
177
 
176
178
        if (el->el_line.cursor == el->el_line.buffer)
177
 
                return (CC_ERROR);
 
179
                return CC_ERROR;
178
180
 
179
181
        el->el_line.cursor = cv_prev_word(el->el_line.cursor,
180
182
            el->el_line.buffer,
183
185
 
184
186
        if (el->el_chared.c_vcmd.action != NOP) {
185
187
                cv_delfini(el);
186
 
                return (CC_REFRESH);
 
188
                return CC_REFRESH;
187
189
        }
188
 
        return (CC_CURSOR);
 
190
        return CC_CURSOR;
189
191
}
190
192
 
191
193
 
195
197
 */
196
198
protected el_action_t
197
199
/*ARGSUSED*/
198
 
vi_next_big_word(EditLine *el, int c __attribute__((__unused__)))
 
200
vi_next_big_word(EditLine *el, Int c __attribute__((__unused__)))
199
201
{
200
202
 
201
203
        if (el->el_line.cursor >= el->el_line.lastchar - 1)
202
 
                return (CC_ERROR);
 
204
                return CC_ERROR;
203
205
 
204
206
        el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
205
207
            el->el_line.lastchar, el->el_state.argument, cv__isWord);
207
209
        if (el->el_map.type == MAP_VI)
208
210
                if (el->el_chared.c_vcmd.action != NOP) {
209
211
                        cv_delfini(el);
210
 
                        return (CC_REFRESH);
 
212
                        return CC_REFRESH;
211
213
                }
212
 
        return (CC_CURSOR);
 
214
        return CC_CURSOR;
213
215
}
214
216
 
215
217
 
219
221
 */
220
222
protected el_action_t
221
223
/*ARGSUSED*/
222
 
vi_next_word(EditLine *el, int c __attribute__((__unused__)))
 
224
vi_next_word(EditLine *el, Int c __attribute__((__unused__)))
223
225
{
224
226
 
225
227
        if (el->el_line.cursor >= el->el_line.lastchar - 1)
226
 
                return (CC_ERROR);
 
228
                return CC_ERROR;
227
229
 
228
230
        el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
229
231
            el->el_line.lastchar, el->el_state.argument, cv__isword);
231
233
        if (el->el_map.type == MAP_VI)
232
234
                if (el->el_chared.c_vcmd.action != NOP) {
233
235
                        cv_delfini(el);
234
 
                        return (CC_REFRESH);
 
236
                        return CC_REFRESH;
235
237
                }
236
 
        return (CC_CURSOR);
 
238
        return CC_CURSOR;
237
239
}
238
240
 
239
241
 
242
244
 *      [~]
243
245
 */
244
246
protected el_action_t
245
 
vi_change_case(EditLine *el, int c)
 
247
vi_change_case(EditLine *el, Int c)
246
248
{
247
249
        int i;
248
250
 
249
251
        if (el->el_line.cursor >= el->el_line.lastchar)
250
 
                return (CC_ERROR);
 
252
                return CC_ERROR;
251
253
        cv_undo(el);
252
254
        for (i = 0; i < el->el_state.argument; i++) {
253
255
 
254
 
                c = *(unsigned char *)el->el_line.cursor;
255
 
                if (isupper(c))
256
 
                        *el->el_line.cursor = tolower(c);
257
 
                else if (islower(c))
258
 
                        *el->el_line.cursor = toupper(c);
 
256
                c = *el->el_line.cursor;
 
257
                if (Isupper(c))
 
258
                        *el->el_line.cursor = Tolower(c);
 
259
                else if (Islower(c))
 
260
                        *el->el_line.cursor = Toupper(c);
259
261
 
260
262
                if (++el->el_line.cursor >= el->el_line.lastchar) {
261
263
                        el->el_line.cursor--;
274
276
 */
275
277
protected el_action_t
276
278
/*ARGSUSED*/
277
 
vi_change_meta(EditLine *el, int c __attribute__((__unused__)))
 
279
vi_change_meta(EditLine *el, Int c __attribute__((__unused__)))
278
280
{
279
281
 
280
282
        /*
281
283
         * Delete with insert == change: first we delete and then we leave in
282
284
         * insert mode.
283
285
         */
284
 
        return (cv_action(el, DELETE | INSERT));
 
286
        return cv_action(el, DELETE | INSERT);
285
287
}
286
288
 
287
289
 
291
293
 */
292
294
protected el_action_t
293
295
/*ARGSUSED*/
294
 
vi_insert_at_bol(EditLine *el, int c __attribute__((__unused__)))
 
296
vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__)))
295
297
{
296
298
 
297
299
        el->el_line.cursor = el->el_line.buffer;
298
300
        cv_undo(el);
299
301
        el->el_map.current = el->el_map.key;
300
 
        return (CC_CURSOR);
 
302
        return CC_CURSOR;
301
303
}
302
304
 
303
305
 
307
309
 */
308
310
protected el_action_t
309
311
/*ARGSUSED*/
310
 
vi_replace_char(EditLine *el, int c __attribute__((__unused__)))
 
312
vi_replace_char(EditLine *el, Int c __attribute__((__unused__)))
311
313
{
312
314
 
313
315
        if (el->el_line.cursor >= el->el_line.lastchar)
316
318
        el->el_map.current = el->el_map.key;
317
319
        el->el_state.inputmode = MODE_REPLACE_1;
318
320
        cv_undo(el);
319
 
        return (CC_ARGHACK);
 
321
        return CC_ARGHACK;
320
322
}
321
323
 
322
324
 
326
328
 */
327
329
protected el_action_t
328
330
/*ARGSUSED*/
329
 
vi_replace_mode(EditLine *el, int c __attribute__((__unused__)))
 
331
vi_replace_mode(EditLine *el, Int c __attribute__((__unused__)))
330
332
{
331
333
 
332
334
        el->el_map.current = el->el_map.key;
333
335
        el->el_state.inputmode = MODE_REPLACE;
334
336
        cv_undo(el);
335
 
        return (CC_NORM);
 
337
        return CC_NORM;
336
338
}
337
339
 
338
340
 
342
344
 */
343
345
protected el_action_t
344
346
/*ARGSUSED*/
345
 
vi_substitute_char(EditLine *el, int c __attribute__((__unused__)))
 
347
vi_substitute_char(EditLine *el, Int c __attribute__((__unused__)))
346
348
{
347
349
 
348
350
        c_delafter(el, el->el_state.argument);
349
351
        el->el_map.current = el->el_map.key;
350
 
        return (CC_REFRESH);
 
352
        return CC_REFRESH;
351
353
}
352
354
 
353
355
 
357
359
 */
358
360
protected el_action_t
359
361
/*ARGSUSED*/
360
 
vi_substitute_line(EditLine *el, int c __attribute__((__unused__)))
 
362
vi_substitute_line(EditLine *el, Int c __attribute__((__unused__)))
361
363
{
362
364
 
363
365
        cv_undo(el);
364
366
        cv_yank(el, el->el_line.buffer,
365
 
                    el->el_line.lastchar - el->el_line.buffer);
 
367
            (int)(el->el_line.lastchar - el->el_line.buffer));
366
368
        (void) em_kill_line(el, 0);
367
369
        el->el_map.current = el->el_map.key;
368
 
        return (CC_REFRESH);
 
370
        return CC_REFRESH;
369
371
}
370
372
 
371
373
 
375
377
 */
376
378
protected el_action_t
377
379
/*ARGSUSED*/
378
 
vi_change_to_eol(EditLine *el, int c __attribute__((__unused__)))
 
380
vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__)))
379
381
{
380
382
 
381
383
        cv_undo(el);
382
384
        cv_yank(el, el->el_line.cursor,
383
 
                    el->el_line.lastchar - el->el_line.cursor);
 
385
            (int)(el->el_line.lastchar - el->el_line.cursor));
384
386
        (void) ed_kill_line(el, 0);
385
387
        el->el_map.current = el->el_map.key;
386
 
        return (CC_REFRESH);
 
388
        return CC_REFRESH;
387
389
}
388
390
 
389
391
 
393
395
 */
394
396
protected el_action_t
395
397
/*ARGSUSED*/
396
 
vi_insert(EditLine *el, int c __attribute__((__unused__)))
 
398
vi_insert(EditLine *el, Int c __attribute__((__unused__)))
397
399
{
398
400
 
399
401
        el->el_map.current = el->el_map.key;
400
402
        cv_undo(el);
401
 
        return (CC_NORM);
 
403
        return CC_NORM;
402
404
}
403
405
 
404
406
 
408
410
 */
409
411
protected el_action_t
410
412
/*ARGSUSED*/
411
 
vi_add(EditLine *el, int c __attribute__((__unused__)))
 
413
vi_add(EditLine *el, Int c __attribute__((__unused__)))
412
414
{
413
415
        int ret;
414
416
 
423
425
 
424
426
        cv_undo(el);
425
427
 
426
 
        return (ret);
 
428
        return (el_action_t)ret;
427
429
}
428
430
 
429
431
 
433
435
 */
434
436
protected el_action_t
435
437
/*ARGSUSED*/
436
 
vi_add_at_eol(EditLine *el, int c __attribute__((__unused__)))
 
438
vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__)))
437
439
{
438
440
 
439
441
        el->el_map.current = el->el_map.key;
440
442
        el->el_line.cursor = el->el_line.lastchar;
441
443
        cv_undo(el);
442
 
        return (CC_CURSOR);
 
444
        return CC_CURSOR;
443
445
}
444
446
 
445
447
 
449
451
 */
450
452
protected el_action_t
451
453
/*ARGSUSED*/
452
 
vi_delete_meta(EditLine *el, int c __attribute__((__unused__)))
 
454
vi_delete_meta(EditLine *el, Int c __attribute__((__unused__)))
453
455
{
454
456
 
455
 
        return (cv_action(el, DELETE));
 
457
        return cv_action(el, DELETE);
456
458
}
457
459
 
458
460
 
462
464
 */
463
465
protected el_action_t
464
466
/*ARGSUSED*/
465
 
vi_end_big_word(EditLine *el, int c __attribute__((__unused__)))
 
467
vi_end_big_word(EditLine *el, Int c __attribute__((__unused__)))
466
468
{
467
469
 
468
470
        if (el->el_line.cursor == el->el_line.lastchar)
469
 
                return (CC_ERROR);
 
471
                return CC_ERROR;
470
472
 
471
473
        el->el_line.cursor = cv__endword(el->el_line.cursor,
472
474
            el->el_line.lastchar, el->el_state.argument, cv__isWord);
474
476
        if (el->el_chared.c_vcmd.action != NOP) {
475
477
                el->el_line.cursor++;
476
478
                cv_delfini(el);
477
 
                return (CC_REFRESH);
 
479
                return CC_REFRESH;
478
480
        }
479
 
        return (CC_CURSOR);
 
481
        return CC_CURSOR;
480
482
}
481
483
 
482
484
 
486
488
 */
487
489
protected el_action_t
488
490
/*ARGSUSED*/
489
 
vi_end_word(EditLine *el, int c __attribute__((__unused__)))
 
491
vi_end_word(EditLine *el, Int c __attribute__((__unused__)))
490
492
{
491
493
 
492
494
        if (el->el_line.cursor == el->el_line.lastchar)
493
 
                return (CC_ERROR);
 
495
                return CC_ERROR;
494
496
 
495
497
        el->el_line.cursor = cv__endword(el->el_line.cursor,
496
498
            el->el_line.lastchar, el->el_state.argument, cv__isword);
498
500
        if (el->el_chared.c_vcmd.action != NOP) {
499
501
                el->el_line.cursor++;
500
502
                cv_delfini(el);
501
 
                return (CC_REFRESH);
 
503
                return CC_REFRESH;
502
504
        }
503
 
        return (CC_CURSOR);
 
505
        return CC_CURSOR;
504
506
}
505
507
 
506
508
 
510
512
 */
511
513
protected el_action_t
512
514
/*ARGSUSED*/
513
 
vi_undo(EditLine *el, int c __attribute__((__unused__)))
 
515
vi_undo(EditLine *el, Int c __attribute__((__unused__)))
514
516
{
515
517
        c_undo_t un = el->el_chared.c_undo;
516
518
 
520
522
        /* switch line buffer and undo buffer */
521
523
        el->el_chared.c_undo.buf = el->el_line.buffer;
522
524
        el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
523
 
        el->el_chared.c_undo.cursor = el->el_line.cursor - el->el_line.buffer;
 
525
        el->el_chared.c_undo.cursor =
 
526
            (int)(el->el_line.cursor - el->el_line.buffer);
524
527
        el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
525
528
        el->el_line.buffer = un.buf;
526
529
        el->el_line.cursor = un.buf + un.cursor;
527
530
        el->el_line.lastchar = un.buf + un.len;
528
531
 
529
 
        return (CC_REFRESH);
 
532
        return CC_REFRESH;
530
533
}
531
534
 
532
535
 
536
539
 */
537
540
protected el_action_t
538
541
/*ARGSUSED*/
539
 
vi_command_mode(EditLine *el, int c __attribute__((__unused__)))
 
542
vi_command_mode(EditLine *el, Int c __attribute__((__unused__)))
540
543
{
541
544
 
542
545
        /* [Esc] cancels pending action */
551
554
        if (el->el_line.cursor > el->el_line.buffer)
552
555
                el->el_line.cursor--;
553
556
#endif
554
 
        return (CC_CURSOR);
 
557
        return CC_CURSOR;
555
558
}
556
559
 
557
560
 
560
563
 *      [0]
561
564
 */
562
565
protected el_action_t
563
 
vi_zero(EditLine *el, int c)
 
566
vi_zero(EditLine *el, Int c)
564
567
{
565
568
 
566
569
        if (el->el_state.doingarg)
569
572
        el->el_line.cursor = el->el_line.buffer;
570
573
        if (el->el_chared.c_vcmd.action != NOP) {
571
574
                cv_delfini(el);
572
 
                return (CC_REFRESH);
 
575
                return CC_REFRESH;
573
576
        }
574
 
        return (CC_CURSOR);
 
577
        return CC_CURSOR;
575
578
}
576
579
 
577
580
 
581
584
 */
582
585
protected el_action_t
583
586
/*ARGSUSED*/
584
 
vi_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
 
587
vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
585
588
{
586
589
 
587
590
        if (el->el_line.cursor <= el->el_line.buffer)
588
 
                return (CC_ERROR);
 
591
                return CC_ERROR;
589
592
 
590
593
        c_delbefore1(el);
591
594
        el->el_line.cursor--;
592
 
        return (CC_REFRESH);
 
595
        return CC_REFRESH;
593
596
}
594
597
 
595
598
 
599
602
 */
600
603
protected el_action_t
601
604
/*ARGSUSED*/
602
 
vi_list_or_eof(EditLine *el, int c)
 
605
vi_list_or_eof(EditLine *el, Int c)
603
606
{
604
607
 
605
608
        if (el->el_line.cursor == el->el_line.lastchar) {
606
609
                if (el->el_line.cursor == el->el_line.buffer) {
607
 
                        term_writec(el, c);     /* then do a EOF */
608
 
                        return (CC_EOF);
 
610
                        terminal_writec(el, c); /* then do a EOF */
 
611
                        return CC_EOF;
609
612
                } else {
610
613
                        /*
611
614
                         * Here we could list completions, but it is an
612
615
                         * error right now
613
616
                         */
614
 
                        term_beep(el);
615
 
                        return (CC_ERROR);
 
617
                        terminal_beep(el);
 
618
                        return CC_ERROR;
616
619
                }
617
620
        } else {
618
621
#ifdef notyet
619
622
                re_goto_bottom(el);
620
623
                *el->el_line.lastchar = '\0';   /* just in case */
621
 
                return (CC_LIST_CHOICES);
 
624
                return CC_LIST_CHOICES;
622
625
#else
623
626
                /*
624
627
                 * Just complain for now.
625
628
                 */
626
 
                term_beep(el);
627
 
                return (CC_ERROR);
 
629
                terminal_beep(el);
 
630
                return CC_ERROR;
628
631
#endif
629
632
        }
630
633
}
636
639
 */
637
640
protected el_action_t
638
641
/*ARGSUSED*/
639
 
vi_kill_line_prev(EditLine *el, int c __attribute__((__unused__)))
 
642
vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__)))
640
643
{
641
 
        char *kp, *cp;
 
644
        Char *kp, *cp;
642
645
 
643
646
        cp = el->el_line.buffer;
644
647
        kp = el->el_chared.c_kill.buf;
645
648
        while (cp < el->el_line.cursor)
646
649
                *kp++ = *cp++;  /* copy it */
647
650
        el->el_chared.c_kill.last = kp;
648
 
        c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
 
651
        c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
649
652
        el->el_line.cursor = el->el_line.buffer;        /* zap! */
650
 
        return (CC_REFRESH);
 
653
        return CC_REFRESH;
651
654
}
652
655
 
653
656
 
657
660
 */
658
661
protected el_action_t
659
662
/*ARGSUSED*/
660
 
vi_search_prev(EditLine *el, int c __attribute__((__unused__)))
 
663
vi_search_prev(EditLine *el, Int c __attribute__((__unused__)))
661
664
{
662
665
 
663
 
        return (cv_search(el, ED_SEARCH_PREV_HISTORY));
 
666
        return cv_search(el, ED_SEARCH_PREV_HISTORY);
664
667
}
665
668
 
666
669
 
670
673
 */
671
674
protected el_action_t
672
675
/*ARGSUSED*/
673
 
vi_search_next(EditLine *el, int c __attribute__((__unused__)))
 
676
vi_search_next(EditLine *el, Int c __attribute__((__unused__)))
674
677
{
675
678
 
676
 
        return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
 
679
        return cv_search(el, ED_SEARCH_NEXT_HISTORY);
677
680
}
678
681
 
679
682
 
683
686
 */
684
687
protected el_action_t
685
688
/*ARGSUSED*/
686
 
vi_repeat_search_next(EditLine *el, int c __attribute__((__unused__)))
 
689
vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__)))
687
690
{
688
691
 
689
692
        if (el->el_search.patlen == 0)
690
 
                return (CC_ERROR);
 
693
                return CC_ERROR;
691
694
        else
692
 
                return (cv_repeat_srch(el, el->el_search.patdir));
 
695
                return cv_repeat_srch(el, el->el_search.patdir);
693
696
}
694
697
 
695
698
 
699
702
 */
700
703
/*ARGSUSED*/
701
704
protected el_action_t
702
 
vi_repeat_search_prev(EditLine *el, int c __attribute__((__unused__)))
 
705
vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__)))
703
706
{
704
707
 
705
708
        if (el->el_search.patlen == 0)
706
 
                return (CC_ERROR);
 
709
                return CC_ERROR;
707
710
        else
708
711
                return (cv_repeat_srch(el,
709
712
                    el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
717
720
 */
718
721
protected el_action_t
719
722
/*ARGSUSED*/
720
 
vi_next_char(EditLine *el, int c __attribute__((__unused__)))
 
723
vi_next_char(EditLine *el, Int c __attribute__((__unused__)))
721
724
{
722
725
        return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
723
726
}
729
732
 */
730
733
protected el_action_t
731
734
/*ARGSUSED*/
732
 
vi_prev_char(EditLine *el, int c __attribute__((__unused__)))
 
735
vi_prev_char(EditLine *el, Int c __attribute__((__unused__)))
733
736
{
734
737
        return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
735
738
}
741
744
 */
742
745
protected el_action_t
743
746
/*ARGSUSED*/
744
 
vi_to_next_char(EditLine *el, int c __attribute__((__unused__)))
 
747
vi_to_next_char(EditLine *el, Int c __attribute__((__unused__)))
745
748
{
746
749
        return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
747
750
}
753
756
 */
754
757
protected el_action_t
755
758
/*ARGSUSED*/
756
 
vi_to_prev_char(EditLine *el, int c __attribute__((__unused__)))
 
759
vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__)))
757
760
{
758
761
        return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
759
762
}
765
768
 */
766
769
protected el_action_t
767
770
/*ARGSUSED*/
768
 
vi_repeat_next_char(EditLine *el, int c __attribute__((__unused__)))
 
771
vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__)))
769
772
{
770
773
 
771
774
        return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
779
782
 */
780
783
protected el_action_t
781
784
/*ARGSUSED*/
782
 
vi_repeat_prev_char(EditLine *el, int c __attribute__((__unused__)))
 
785
vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__)))
783
786
{
784
787
        el_action_t r;
785
788
        int dir = el->el_search.chadir;
797
800
 */
798
801
protected el_action_t
799
802
/*ARGSUSED*/
800
 
vi_match(EditLine *el, int c __attribute__((__unused__)))
 
803
vi_match(EditLine *el, Int c __attribute__((__unused__)))
801
804
{
802
 
        const char match_chars[] = "()[]{}";
803
 
        char *cp;
804
 
        int delta, i, count;
805
 
        char o_ch, c_ch;
 
805
        const Char match_chars[] = STR("()[]{}");
 
806
        Char *cp;
 
807
        size_t delta, i, count;
 
808
        Char o_ch, c_ch;
806
809
 
807
810
        *el->el_line.lastchar = '\0';           /* just in case */
808
811
 
809
 
        i = strcspn(el->el_line.cursor, match_chars);
 
812
        i = Strcspn(el->el_line.cursor, match_chars);
810
813
        o_ch = el->el_line.cursor[i];
811
814
        if (o_ch == 0)
812
815
                return CC_ERROR;
813
 
        delta = strchr(match_chars, o_ch) - match_chars;
 
816
        delta = (size_t)(Strchr(match_chars, o_ch) - match_chars);
814
817
        c_ch = match_chars[delta ^ 1];
815
818
        count = 1;
816
819
        delta = 1 - (delta & 1) * 2;
833
836
                if (delta > 0)
834
837
                        el->el_line.cursor++;
835
838
                cv_delfini(el);
836
 
                return (CC_REFRESH);
 
839
                return CC_REFRESH;
837
840
        }
838
 
        return (CC_CURSOR);
 
841
        return CC_CURSOR;
839
842
}
840
843
 
841
844
/* vi_undo_line():
844
847
 */
845
848
protected el_action_t
846
849
/*ARGSUSED*/
847
 
vi_undo_line(EditLine *el, int c __attribute__((__unused__)))
 
850
vi_undo_line(EditLine *el, Int c __attribute__((__unused__)))
848
851
{
849
852
 
850
853
        cv_undo(el);
858
861
 */
859
862
protected el_action_t
860
863
/*ARGSUSED*/
861
 
vi_to_column(EditLine *el, int c __attribute__((__unused__)))
 
864
vi_to_column(EditLine *el, Int c __attribute__((__unused__)))
862
865
{
863
866
 
864
867
        el->el_line.cursor = el->el_line.buffer;
872
875
 */
873
876
protected el_action_t
874
877
/*ARGSUSED*/
875
 
vi_yank_end(EditLine *el, int c __attribute__((__unused__)))
 
878
vi_yank_end(EditLine *el, Int c __attribute__((__unused__)))
876
879
{
877
880
 
878
881
        cv_yank(el, el->el_line.cursor,
879
 
                el->el_line.lastchar - el->el_line.cursor);
 
882
            (int)(el->el_line.lastchar - el->el_line.cursor));
880
883
        return CC_REFRESH;
881
884
}
882
885
 
886
889
 */
887
890
protected el_action_t
888
891
/*ARGSUSED*/
889
 
vi_yank(EditLine *el, int c __attribute__((__unused__)))
 
892
vi_yank(EditLine *el, Int c __attribute__((__unused__)))
890
893
{
891
894
 
892
895
        return cv_action(el, YANK);
898
901
 */
899
902
protected el_action_t
900
903
/*ARGSUSED*/
901
 
vi_comment_out(EditLine *el, int c __attribute__((__unused__)))
 
904
vi_comment_out(EditLine *el, Int c __attribute__((__unused__)))
902
905
{
903
906
 
904
907
        el->el_line.cursor = el->el_line.buffer;
915
918
 * this is against historical precedent...
916
919
 */
917
920
#if defined(__weak_reference) && !defined(__FreeBSD__)
918
 
extern char *get_alias_text(const char *) __weak_reference(get_alias_text);
 
921
__weakref_visible char *my_get_alias_text(const char *)
 
922
    __weak_reference(get_alias_text);
919
923
#endif
920
924
protected el_action_t
921
925
/*ARGSUSED*/
922
926
vi_alias(EditLine *el __attribute__((__unused__)),
923
 
         int c __attribute__((__unused__)))
 
927
         Int c __attribute__((__unused__)))
924
928
{
925
929
#if defined(__weak_reference) && !defined(__FreeBSD__)
926
930
        char alias_name[3];
927
931
        char *alias_text;
928
932
 
929
 
        if (get_alias_text == 0) {
 
933
        if (my_get_alias_text == 0) {
930
934
                return CC_ERROR;
931
935
        }
932
936
 
935
939
        if (el_getc(el, &alias_name[1]) != 1)
936
940
                return CC_ERROR;
937
941
 
938
 
        alias_text = get_alias_text(alias_name);
 
942
        alias_text = my_get_alias_text(alias_name);
939
943
        if (alias_text != NULL)
940
 
                el_push(el, alias_text);
 
944
                FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch));
941
945
        return CC_NORM;
942
946
#else
943
947
        return CC_ERROR;
950
954
 */
951
955
protected el_action_t
952
956
/*ARGSUSED*/
953
 
vi_to_history_line(EditLine *el, int c __attribute__((__unused__)))
 
957
vi_to_history_line(EditLine *el, Int c __attribute__((__unused__)))
954
958
{
955
959
        int sv_event_no = el->el_history.eventno;
956
960
        el_action_t rval;
957
961
 
958
962
 
959
963
        if (el->el_history.eventno == 0) {
960
 
                 (void) strncpy(el->el_history.buf, el->el_line.buffer,
 
964
                 (void) Strncpy(el->el_history.buf, el->el_line.buffer,
961
965
                     EL_BUFSIZ);
962
966
                 el->el_history.last = el->el_history.buf +
963
967
                         (el->el_line.lastchar - el->el_line.buffer);
995
999
 */
996
1000
protected el_action_t
997
1001
/*ARGSUSED*/
998
 
vi_histedit(EditLine *el, int c __attribute__((__unused__)))
 
1002
vi_histedit(EditLine *el, Int c __attribute__((__unused__)))
999
1003
{
1000
1004
        int fd;
1001
1005
        pid_t pid;
1002
 
        int st;
 
1006
        ssize_t st;
 
1007
        int status;
1003
1008
        char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
1004
1009
        char *cp;
 
1010
        size_t len;
 
1011
        Char *line;
 
1012
        mbstate_t state;
1005
1013
 
 
1014
        memset(&state, 0, sizeof(mbstate_t));
1006
1015
        if (el->el_state.doingarg) {
1007
1016
                if (vi_to_history_line(el, 0) == CC_ERROR)
1008
1017
                        return CC_ERROR;
1011
1020
        fd = mkstemp(tempfile);
1012
1021
        if (fd < 0)
1013
1022
                return CC_ERROR;
1014
 
        cp = el->el_line.buffer;
1015
 
        if (write(fd, cp, el->el_line.lastchar - cp +0u) == -1)
 
1023
        len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
 
1024
#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
 
1025
        cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
 
1026
        if (cp == NULL) {
 
1027
                unlink(tempfile);
 
1028
                close(fd);
 
1029
                return CC_ERROR;
 
1030
        }
 
1031
        line = el_malloc(len * sizeof(*line));
 
1032
        if (line == NULL) {
 
1033
                el_free(cp);
 
1034
                return CC_ERROR;
 
1035
        }
 
1036
        Strncpy(line, el->el_line.buffer, len);
 
1037
        line[len] = '\0';
 
1038
        wcsrtombs(cp, (const wchar_t **) &line, TMP_BUFSIZ - 1, &state);
 
1039
        cp[TMP_BUFSIZ - 1] = '\0';
 
1040
        len = strlen(cp);
 
1041
        if (write(fd, cp, len) == -1)
1016
1042
          goto error;
1017
 
        if (write(fd, "\n", 1) == -1)
 
1043
        if (write(fd, "\n", (size_t)1) == -1)
1018
1044
          goto error;
1019
1045
        pid = fork();
1020
1046
        switch (pid) {
1021
1047
        case -1:
1022
1048
                close(fd);
1023
1049
                unlink(tempfile);
 
1050
                el_free(cp);
 
1051
                el_free(line);
1024
1052
                return CC_ERROR;
1025
1053
        case 0:
1026
1054
                close(fd);
1028
1056
                exit(0);
1029
1057
                /*NOTREACHED*/
1030
1058
        default:
1031
 
                while (waitpid(pid, &st, 0) != pid)
 
1059
                while (waitpid(pid, &status, 0) != pid)
1032
1060
                        continue;
1033
 
                lseek(fd, 0ll, SEEK_SET);
1034
 
                st = read(fd, cp, el->el_line.limit - cp +0u);
1035
 
                if (st > 0 && cp[st - 1] == '\n')
1036
 
                        st--;
1037
 
                el->el_line.cursor = cp;
1038
 
                el->el_line.lastchar = cp + st;
 
1061
                lseek(fd, (off_t)0, SEEK_SET);
 
1062
                st = read(fd, cp, TMP_BUFSIZ);
 
1063
                if (st > 0) {
 
1064
                        len = (size_t)(el->el_line.lastchar -
 
1065
                            el->el_line.buffer);
 
1066
                        memset(&state, 0, sizeof(mbstate_t));
 
1067
                        len = mbsrtowcs(el->el_line.buffer,
 
1068
                                        (const char**) &cp, len, &state);
 
1069
                        if (len > 0 && el->el_line.buffer[len -1] == '\n')
 
1070
                                --len;
 
1071
                }
 
1072
                else
 
1073
                        len = 0;
 
1074
                el->el_line.cursor = el->el_line.buffer;
 
1075
                el->el_line.lastchar = el->el_line.buffer + len;
 
1076
                el_free(cp);
 
1077
                el_free(line);
1039
1078
                break;
1040
1079
        }
1041
1080
 
1059
1098
 */
1060
1099
protected el_action_t
1061
1100
/*ARGSUSED*/
1062
 
vi_history_word(EditLine *el, int c __attribute__((__unused__)))
 
1101
vi_history_word(EditLine *el, Int c __attribute__((__unused__)))
1063
1102
{
1064
 
        const char *wp = HIST_FIRST(el);
1065
 
        const char *wep, *wsp;
 
1103
        const Char *wp = HIST_FIRST(el);
 
1104
        const Char *wep, *wsp;
1066
1105
        int len;
1067
 
        char *cp;
1068
 
        const char *lim;
 
1106
        Char *cp;
 
1107
        const Char *lim;
1069
1108
 
1070
1109
        if (wp == NULL)
1071
1110
                return CC_ERROR;
1072
1111
 
1073
1112
        wep = wsp = 0;
1074
1113
        do {
1075
 
                while (isspace((unsigned char)*wp))
 
1114
                while (Isspace(*wp))
1076
1115
                        wp++;
1077
1116
                if (*wp == 0)
1078
1117
                        break;
1079
1118
                wsp = wp;
1080
 
                while (*wp && !isspace((unsigned char)*wp))
 
1119
                while (*wp && !Isspace(*wp))
1081
1120
                        wp++;
1082
1121
                wep = wp;
1083
 
        } while ((!el->el_state.doingarg || --el->el_state.argument > 0) && *wp != 0);
 
1122
        } while ((!el->el_state.doingarg || --el->el_state.argument > 0)
 
1123
            && *wp != 0);
1084
1124
 
1085
1125
        if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0))
1086
1126
                return CC_ERROR;
1087
1127
 
1088
1128
        cv_undo(el);
1089
 
        len = wep - wsp;
 
1129
        len = (int)(wep - wsp);
1090
1130
        if (el->el_line.cursor < el->el_line.lastchar)
1091
1131
                el->el_line.cursor++;
1092
1132
        c_insert(el, len + 1);
1108
1148
 */
1109
1149
protected el_action_t
1110
1150
/*ARGSUSED*/
1111
 
vi_redo(EditLine *el, int c __attribute__((__unused__)))
 
1151
vi_redo(EditLine *el, Int c __attribute__((__unused__)))
1112
1152
{
1113
1153
        c_redo_t *r = &el->el_chared.c_redo;
1114
1154
 
1124
1164
                        /* sanity */
1125
1165
                        r->pos = r->lim - 1;
1126
1166
                r->pos[0] = 0;
1127
 
                el_push(el, r->buf);
 
1167
                FUN(el,push)(el, r->buf);
1128
1168
        }
1129
1169
 
1130
1170
        el->el_state.thiscmd = r->cmd;
1131
1171
        el->el_state.thisch = r->ch;
1132
 
        return  (*el->el_map.func[r->cmd])(el, r->ch);
 
1172
        return (*el->el_map.func[r->cmd])(el, r->ch);
1133
1173
}