ed.chared.c (167466) | ed.chared.c (195609) |
---|---|
1/* $Header: /p/tcsh/cvsroot/tcsh/ed.chared.c,v 3.93 2006/08/23 15:03:13 christos Exp $ */ | 1/* $Header: /p/tcsh/cvsroot/tcsh/ed.chared.c,v 3.95 2009/06/25 21:15:37 christos Exp $ */ |
2/* 3 * ed.chared.c: Character editing functions. 4 */ 5/*- 6 * Copyright (c) 1980, 1991 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without --- 57 unchanged lines hidden (view full) --- 67 68 The only difference between the two echo lines is in the first character 69 after the echo command. The result is either one or three arguments. 70 71 */ 72 73#include "sh.h" 74 | 2/* 3 * ed.chared.c: Character editing functions. 4 */ 5/*- 6 * Copyright (c) 1980, 1991 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without --- 57 unchanged lines hidden (view full) --- 67 68 The only difference between the two echo lines is in the first character 69 after the echo command. The result is either one or three arguments. 70 71 */ 72 73#include "sh.h" 74 |
75RCSID("$tcsh: ed.chared.c,v 3.93 2006/08/23 15:03:13 christos Exp $") | 75RCSID("$tcsh: ed.chared.c,v 3.95 2009/06/25 21:15:37 christos Exp $") |
76 77#include "ed.h" 78#include "tw.h" 79#include "ed.defns.h" 80 81/* #define SDEBUG */ 82 83#define TCSHOP_NOP 0x00 --- 31 unchanged lines hidden (view full) --- 115void c_insert (int); 116void c_delafter (int); 117void c_delbefore (int); 118static int c_to_class (Char); 119static Char *c_prev_word (Char *, Char *, int); 120static Char *c_next_word (Char *, Char *, int); 121static Char *c_number (Char *, int *, int); 122static Char *c_expand (Char *); | 76 77#include "ed.h" 78#include "tw.h" 79#include "ed.defns.h" 80 81/* #define SDEBUG */ 82 83#define TCSHOP_NOP 0x00 --- 31 unchanged lines hidden (view full) --- 115void c_insert (int); 116void c_delafter (int); 117void c_delbefore (int); 118static int c_to_class (Char); 119static Char *c_prev_word (Char *, Char *, int); 120static Char *c_next_word (Char *, Char *, int); 121static Char *c_number (Char *, int *, int); 122static Char *c_expand (Char *); |
123static void c_excl (Char *); 124static void c_substitute (void); | 123static int c_excl (Char *); 124static int c_substitute (void); |
125static void c_delfini (void); 126static int c_hmatch (Char *); 127static void c_hsetpat (void); 128#ifdef COMMENT 129static void c_get_word (Char **, Char **); 130#endif 131static Char *c_preword (Char *, Char *, int, Char *); 132static Char *c_nexword (Char *, Char *, int); --- 544 unchanged lines hidden (view full) --- 677 return(op + 1); 678} 679 680/* 681 * c_excl: An excl has been found at point p -- back up and find some white 682 * space (or the beginning of the buffer) and properly expand all the excl's 683 * from there up to the current cursor position. We also avoid (trying to) 684 * expanding '>!' | 125static void c_delfini (void); 126static int c_hmatch (Char *); 127static void c_hsetpat (void); 128#ifdef COMMENT 129static void c_get_word (Char **, Char **); 130#endif 131static Char *c_preword (Char *, Char *, int, Char *); 132static Char *c_nexword (Char *, Char *, int); --- 544 unchanged lines hidden (view full) --- 677 return(op + 1); 678} 679 680/* 681 * c_excl: An excl has been found at point p -- back up and find some white 682 * space (or the beginning of the buffer) and properly expand all the excl's 683 * from there up to the current cursor position. We also avoid (trying to) 684 * expanding '>!' |
685 * Returns number of expansions attempted (doesn't matter whether they succeeded 686 * or not). |
|
685 */ 686 | 687 */ 688 |
687static void | 689static int |
688c_excl(Char *p) 689{ 690 int i; 691 Char *q; | 690c_excl(Char *p) 691{ 692 int i; 693 Char *q; |
694 int nr_exp; |
|
692 693 /* 694 * if />[SPC TAB]*![SPC TAB]/, back up p to just after the >. otherwise, 695 * back p up to just before the current word. 696 */ 697 if ((p[1] == ' ' || p[1] == '\t') && 698 (p[-1] == ' ' || p[-1] == '\t' || p[-1] == '>')) { 699 for (q = p - 1; q > InputBuf && (*q == ' ' || *q == '\t'); --q) 700 continue; 701 if (*q == '>') 702 ++p; 703 } 704 else { 705 while (*p != ' ' && *p != '\t' && p > InputBuf) 706 --p; 707 } 708 709 /* 710 * Forever: Look for history char. (Stop looking when we find the cursor.) | 695 696 /* 697 * if />[SPC TAB]*![SPC TAB]/, back up p to just after the >. otherwise, 698 * back p up to just before the current word. 699 */ 700 if ((p[1] == ' ' || p[1] == '\t') && 701 (p[-1] == ' ' || p[-1] == '\t' || p[-1] == '>')) { 702 for (q = p - 1; q > InputBuf && (*q == ' ' || *q == '\t'); --q) 703 continue; 704 if (*q == '>') 705 ++p; 706 } 707 else { 708 while (*p != ' ' && *p != '\t' && p > InputBuf) 709 --p; 710 } 711 712 /* 713 * Forever: Look for history char. (Stop looking when we find the cursor.) |
711 * Count backslashes. Of odd, skip history char. Return if all done. 712 * Expand if even number of backslashes. | 714 * Count backslashes. If odd, skip history char. Expand if even number of 715 * backslashes. |
713 */ | 716 */ |
717 nr_exp = 0; |
|
714 for (;;) { 715 while (*p != HIST && p < Cursor) 716 ++p; 717 for (i = 1; (p - i) >= InputBuf && p[-i] == '\\'; i++) 718 continue; 719 if (i % 2 == 0) 720 ++p; | 718 for (;;) { 719 while (*p != HIST && p < Cursor) 720 ++p; 721 for (i = 1; (p - i) >= InputBuf && p[-i] == '\\'; i++) 722 continue; 723 if (i % 2 == 0) 724 ++p; |
721 if (p >= Cursor) 722 return; 723 if (i % 2 == 1) | 725 if (p >= Cursor) /* all done */ 726 return nr_exp; 727 if (i % 2 == 1) { |
724 p = c_expand(p); | 728 p = c_expand(p); |
729 ++nr_exp; 730 } |
|
725 } | 731 } |
732 733 return nr_exp; |
|
726} 727 728 | 734} 735 736 |
729static void | 737static int |
730c_substitute(void) 731{ 732 Char *p; | 738c_substitute(void) 739{ 740 Char *p; |
741 int nr_exp; |
|
733 734 /* 735 * Start p out one character before the cursor. Move it backwards looking 736 * for white space, the beginning of the line, or a history character. 737 */ 738 for (p = Cursor - 1; 739 p > InputBuf && *p != ' ' && *p != '\t' && *p != HIST; --p) 740 continue; 741 742 /* 743 * If we found a history character, go expand it. 744 */ 745 if (*p == HIST) | 742 743 /* 744 * Start p out one character before the cursor. Move it backwards looking 745 * for white space, the beginning of the line, or a history character. 746 */ 747 for (p = Cursor - 1; 748 p > InputBuf && *p != ' ' && *p != '\t' && *p != HIST; --p) 749 continue; 750 751 /* 752 * If we found a history character, go expand it. 753 */ 754 if (*p == HIST) |
746 c_excl(p); | 755 nr_exp = c_excl(p); 756 else 757 nr_exp = 0; |
747 Refresh(); | 758 Refresh(); |
759 760 return nr_exp; |
|
748} 749 750static void 751c_delfini(void) /* Finish up delete action */ 752{ 753 int Size; 754 755 if (ActionFlag & TCSHOP_INSERT) --- 2680 unchanged lines hidden (view full) --- 3436CCRETVAL 3437e_tty_stopo(Char c) 3438{ 3439 USE(c); 3440 /* do no editing */ 3441 return(CC_NORM); 3442} 3443 | 761} 762 763static void 764c_delfini(void) /* Finish up delete action */ 765{ 766 int Size; 767 768 if (ActionFlag & TCSHOP_INSERT) --- 2680 unchanged lines hidden (view full) --- 3449CCRETVAL 3450e_tty_stopo(Char c) 3451{ 3452 USE(c); 3453 /* do no editing */ 3454 return(CC_NORM); 3455} 3456 |
3457/* returns the number of (attempted) expansions */ 3458int 3459ExpandHistory(void) 3460{ 3461 *LastChar = '\0'; /* just in case */ 3462 return c_substitute(); 3463} 3464 |
|
3444/*ARGSUSED*/ 3445CCRETVAL 3446e_expand_history(Char c) 3447{ 3448 USE(c); | 3465/*ARGSUSED*/ 3466CCRETVAL 3467e_expand_history(Char c) 3468{ 3469 USE(c); |
3449 *LastChar = '\0'; /* just in case */ 3450 c_substitute(); | 3470 (void)ExpandHistory(); |
3451 return(CC_NORM); 3452} 3453 3454/*ARGSUSED*/ 3455CCRETVAL 3456e_magic_space(Char c) 3457{ 3458 USE(c); 3459 *LastChar = '\0'; /* just in case */ | 3471 return(CC_NORM); 3472} 3473 3474/*ARGSUSED*/ 3475CCRETVAL 3476e_magic_space(Char c) 3477{ 3478 USE(c); 3479 *LastChar = '\0'; /* just in case */ |
3460 c_substitute(); | 3480 (void)c_substitute(); |
3461 return(e_insert(' ')); 3462} 3463 3464/*ARGSUSED*/ 3465CCRETVAL 3466e_inc_fwd(Char c) 3467{ 3468 CCRETVAL ret; --- 74 unchanged lines hidden (view full) --- 3543 PastBottom(); 3544#ifdef TIOCSTAT 3545 /* 3546 * Here we pass &c to the ioctl because some os's (NetBSD) expect it 3547 * there even if they don't use it. (lukem@netbsd.org) 3548 */ 3549 if (ioctl(SHIN, TIOCSTAT, (ioctl_t) &c) < 0) 3550#endif | 3481 return(e_insert(' ')); 3482} 3483 3484/*ARGSUSED*/ 3485CCRETVAL 3486e_inc_fwd(Char c) 3487{ 3488 CCRETVAL ret; --- 74 unchanged lines hidden (view full) --- 3563 PastBottom(); 3564#ifdef TIOCSTAT 3565 /* 3566 * Here we pass &c to the ioctl because some os's (NetBSD) expect it 3567 * there even if they don't use it. (lukem@netbsd.org) 3568 */ 3569 if (ioctl(SHIN, TIOCSTAT, (ioctl_t) &c) < 0) 3570#endif |
3551 xprintf(CGETS(5, 1, "Load average unavailable\n")); | 3571 xprintf("%s", CGETS(5, 1, "Load average unavailable\n")); |
3552 return(CC_REFRESH); 3553} 3554 3555/*ARGSUSED*/ 3556CCRETVAL 3557v_chgmeta(Char c) 3558{ 3559 USE(c); --- 311 unchanged lines hidden --- | 3572 return(CC_REFRESH); 3573} 3574 3575/*ARGSUSED*/ 3576CCRETVAL 3577v_chgmeta(Char c) 3578{ 3579 USE(c); --- 311 unchanged lines hidden --- |