62 #define SCREEN_WIDTH 80 63 #define SCREEN_ROWS 24 67 #define CTL(x) (char)((x) & 0x1F) 68 #define ISCTL(x) ((x) && (x) < ' ') 69 #define UNCTL(x) (char)((x) + 64) 70 #define META(x) (char)((x) | 0x80) 71 #define ISMETA(x) ((x) & 0x80) 72 #define UNMETA(x) (char)((x) & 0x7F) 91 typedef struct _KEYMAP {
99 typedef struct _HISTORY {
226 #if defined(USE_TERMCAP) 278 else if (rl_meta_chars &&
ISMETA(c)) {
295 #define TTYback() (backspace ? TTYputs((ECHAR *)backspace) : TTYput('\b')) 305 else if (rl_meta_chars &&
ISMETA(*p))
320 for (i=0; i <
Point; i++)
354 #if defined(USE_TERMCAP) 360 #if defined(TIOCGWINSZ) 365 #if defined(TIOCGWINSZ) 367 if (ioctl(0, TIOCGWINSZ, &W) >= 0
368 && W.ws_col > 0 && W.ws_row > 0) {
378 #if defined(USE_TERMCAP) 380 buff2 =
walloc(
char,2048);
396 if (strncmp(term,
"pcansi", 6)==0 || strncmp(term,
"cygwin", 6)==0)
418 #if defined(TIOCGWINSZ) 419 if (ioctl(0, TIOCGWINSZ, &W) >= 0) {
450 sprintf(info1,
"There are %d possibilities. Do you really \n",ac);
453 while (((c =
TTYget()) != EOF) && ((strchr(
"YyNn ",c) ==
NULL)))
455 if (strchr(
"Nn",c) !=
NULL)
463 for (longest = 0, i = 0; i < ac; i++)
464 if ((j = strlen((
char *)av[i])) > longest)
467 if (cols < 1) cols = 1;
470 for (skip = ac / cols + 1, i = 0; i < skip; i++) {
471 for (j = i; j < ac; j += skip) {
472 for (p = (
ECHAR *)av[j], len = strlen((
char *)p), k = len;
476 while (++len < longest + 3)
498 for (i = 0; i <
End; i++)
581 for ( ;
Point <
End && (*p ==
' ' || !isalnum(*p)); p++)
584 for (;
Point <
End && isalnum(*p); p++)
605 if ((count =
Point - OP) < 0)
618 else if (isupper(*p))
648 for (extras = 0, i =
Point, p = &
Line[i]; i <
End; i++, p++) {
655 else if (rl_meta_chars &&
ISMETA(*p)) {
688 for (i=0; i < strlen(
Prompt); i++)
708 len = strlen((
char *)p);
738 for (i=((pos0%
TTYwidth)+pos1)/TTYwidth; i > 0; i--)
741 for (i=0 ; i < (pos0%
TTYwidth); i++)
751 return H.Pos >=
H.Size - 1 ?
NULL :
H.Lines[++
H.Pos];
756 return H.Pos == 0 ?
NULL :
H.Lines[--
H.Pos];
780 if ((p = (*move)()) ==
NULL)
813 if ((c = *pat) ==
'\0')
814 return *text ==
'\0';
815 for ( ; *text; text++)
816 if (*text == c && strncmp(text, pat, len) == 0)
823 static ECHAR *old_search;
830 if (search && *search) {
833 old_search = (
ECHAR *)
STRDUP((
const char *)search);
836 if (old_search ==
NULL || *old_search ==
'\0')
842 if (*search ==
'^') {
844 pat = (
char *)(search + 1);
848 pat = (
char *)search;
852 for (pos =
H.Pos; (*move)() !=
NULL; )
853 if ((*match)((
char *)
H.Lines[
H.Pos], pat, len) == 0)
854 return H.Lines[
H.Pos];
861 static int Searching;
862 CONST char *old_prompt;
930 for (q =
Point, i =
End - (
Point + count) + 1; --i >= 0; q++)
931 Line[q] = tLine[q+count];
937 if ((pos1 > 0) && (pos0+pos1)%
TTYwidth == 0)
944 for (i=((pos0%
TTYwidth)+pos1)/TTYwidth; i > 0; i--)
947 for (i=0 ; i < (pos0%
TTYwidth); i++)
1021 for (; *lpos > 0; (*lpos)--)
1023 for ( ; (*cpos) >= 0 ; (*cpos)--)
1026 if (strncmp(patt,(
char *)
H.Lines[*lpos]+*cpos,strlen(patt)) == 0)
1028 return (
char *)
H.Lines[*lpos];
1032 *cpos = strlen((
char *)
H.Lines[(*lpos)-1]);
1040 CONST char *old_prompt;
1041 char *pat, *hist, *nhist;
1049 nprompt =
walloc(
char,80+160);
1055 cpos = strlen((
char *)
H.Lines[lpos]);
1058 sprintf(nprompt,
"(reverse-i-search)`%s': ",pat);
1063 for (i=strlen((
char *)
H.Lines[lpos]); i>cpos; i--)
bk_char();
1065 if ((c >=
' ') || (c ==
CTL(
'R')))
1069 else if (patend < 79)
1096 }
while ((c >=
' ') || (c ==
CTL(
'R')));
1107 for (i=strlen((
char *)
H.Lines[lpos]); i>cpos; i--) s =
bk_char();
1131 for (i =
Repeat, q = p; --i >= 0; )
1145 if ((c =
TTYget()) == EOF)
1147 #if defined(ANSI_ARROWS) 1149 if (c ==
'[' || c ==
'O')
1152 case EOF:
return CSeof;
1153 case 'A':
return h_prev();
1154 case 'B':
return h_next();
1161 for (
Repeat = c -
'0'; (c =
TTYget()) != EOF && isdigit(c); )
1172 return (*kp->Function)();
1173 if (rl_meta_chars == 0)
1187 if (
ISMETA(c) && rl_meta_chars)
1193 for (kp =
Map; kp->Function; kp++)
1196 s = kp->Function ? (*kp->Function)() :
insert_char((
int)c);
1247 while ((c =
TTYget()) != EOF)
1285 H.Lines[
H.Size++] = p;
1289 H.Lines[i] =
H.Lines[i + 1];
1301 if ((fd = fopen(history_file,
"wb")) ==
NULL)
1303 fprintf(stderr,
"editline: can't access history file \"%s\"\n",
1308 for (i=0; i <
H.Size; i++)
1309 fprintf(fd,
"%s\n",
H.Lines[i]);
1323 if ((fd = fopen(history_file,
"rb")) ==
NULL)
1326 while ((c=getc(fd)) != EOF)
1329 for (i=0; ((c=getc(fd)) !=
'\n') && (c != EOF); i++)
1391 return (
char *)line;
1397 if (p ==
NULL || *p ==
'\0')
1400 #if defined(UNIQUE_HISTORY) 1401 if (
H.Pos && strcmp(p,
H.Lines[
H.Pos - 1]) == 0)
1444 static char SEPS[] =
"#;&|^$=`'{}()<>\n\t ";
1455 new[len - 1] =
'\0';
1467 char *symbol =
NULL;
1479 (strchr(
"()' \t\n\r",
Line[i]) !=
NULL));
1485 for (; i <
End; i++)
1486 if (strchr(
"()' \t\n\r\"",
Line[i]) !=
NULL)
1488 for (j=i-1; j >=0; j--)
1489 if (strchr(
"()' \t\n\r\"",
Line[j]) !=
NULL)
1492 symbol =
walloc(
char,i-j);
1493 strncpy(symbol,(
char *)&
Line[j+1],i-(j+1));
1494 symbol[i-(j+1)] =
'\0';
1499 static char *completion_to_ambiguity(
int index,
char **possibles)
1510 for ( ; extending; e++)
1512 for (i=0; possibles[i] !=
NULL; i++)
1513 if (possibles[i][e] != possibles[0][e])
1525 p =
walloc(
char,(e-index)+1);
1526 strncpy(p,possibles[0]+index,e-index);
1532 static char **el_file_completion_function(
char * text,
int start,
int end)
1541 word =
walloc(
char,(end-start)+1);
1542 strncpy(word,text+start,end-start);
1543 word[end-
start]=
'\0';
1551 matches2 =
walloc(
char *,ac+1);
1552 for (i=0; i < ac; i++)
1553 matches2[i] = matches1[i];
1567 char **possibles=
NULL;
1569 int started_with_quote = 0;
1573 for (start=
Point; start > 0; start--)
1574 if (strchr(
"()' \t\n\r\"",
Line[start-1]) !=
NULL)
1577 strncpy(word,(
char *)(
Line+start),
Point-start);
1579 if ((start > 0) && (
Line[start-1] ==
'"'))
1580 started_with_quote = 1;
1585 if (possibles ==
NULL)
1587 possibles = el_file_completion_function((
char *)
Line,start,
Point);
1590 for (start=
Point; start > 0; start--)
1591 if (strchr(
"()' \t\n\r\"/",
Line[start-1]) !=
NULL)
1595 for (possiblesc=0; possibles[possiblesc] !=
NULL; possiblesc++);
1597 if ((!possibles) || (possiblesc == 0))
1599 else if (possiblesc == 1)
1601 p =
walloc(
char,strlen(possibles[0])-(
Point-start)+2);
1602 sprintf(p,
"%s ",possibles[0]+(
Point-start));
1603 if ((strlen(p) > 1) && (p[strlen(p)-2] ==
'/'))
1604 p[strlen(p)-1] =
'\0';
1605 else if (started_with_quote)
1606 p[strlen(p)-1] =
'"';
1611 else if ((p = completion_to_ambiguity(
Point-start,possibles)) !=
NULL)
1624 for (i=0; possibles && possibles[i] !=
NULL; i++)
1625 wfree(possibles[i]);
1687 #ifdef SYSTEM_IS_WIN32 1783 if ((c =
TTYget()) == EOF)
1824 for (; p >
Line && p[-1] !=
' ' && isalnum(p[-1]); p--)
1854 for (c = line; isspace(*c); c++)
1856 if (*c ==
'\n' || *c ==
'\0')
1859 for (ac = 0, p[ac++] = c; *c && *c !=
'\n'; ) {
1862 if (*c && *c !=
'\n') {
1892 if (
H.Size == 1 || (p =
H.Lines[
H.Size - 2]) ==
NULL)
1936 #ifdef SYSTEM_IS_WIN32 1937 {
CTL(
'Z'), end_of_input },
1972 for (i=0; MetaMap[i].Key != 0; i++)
1974 if (MetaMap[i].Key == c)
1976 MetaMap[i].Function = func;
1984 fprintf(stderr,
"editline: MetaMap table full, requires increase\n");
1988 MetaMap[i].Function = func;
1990 MetaMap[i+1].Function = 0;
1991 MetaMap[i+1].Key = 0;
STATIC void TTYstring(ECHAR *p)
STATIC STATUS fd_kill_word()
STATIC int el_intr_pending
float end(const EST_Item &item)
STATIC void TTYput(ECHAR c)
STATIC STATUS h_risearch()
STATIC ESIZE_T ScreenCount
int rl_list_possib(char *pathname, char ***avp)
#define walloc(TYPE, SIZE)
STATIC STATUS kill_line()
void read_history(const char *history_file)
STATIC STATUS bk_del_char()
STATIC STATUS emacs(unsigned int c)
STATIC int RequireNLforWrap
STATIC void print_columns(int ac, char **av)
EL_USER_COMPLETION_FUNCTION_TYPE * el_user_completion_function
STATIC STATUS do_case(ECHAR type)
STATIC STATUS do_forward(STATUS move)
STATIC STATUS do_insert_hist(ECHAR *p)
STATIC STATUS insert_string(ECHAR *p)
STATIC void hist_add(ECHAR *p)
char * editline_history_file
STATIC STATUS delete_string(int count)
STATIC ECHAR * next_hist()
STATIC void left(STATUS Change)
STATIC STATUS transpose()
STATIC void right(STATUS Change)
STATIC STATUS ring_bell()
STATIC ECHAR * search_hist(ECHAR *search, ECHAR *(*move)())
STATIC void save_yank(int begin, int i)
STATIC STATUS case_down_word()
STATIC STATUS last_argument()
STATIC STATUS c_possible()
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
void write_history(const char *history_file)
STATIC void reposition(int reset)
STATIC ECHAR * prev_hist()
STATIC STATUS bk_kill_word()
void el_bind_key_in_metamap(char c, Keymap_Function func)
STATIC STATUS move_to_char()
FORWARD KEYMAP MetaMap[64]
STATIC STATUS case_up_word()
STATIC STATUS case_cap_word()
STATIC ECHAR * editinput()
STATIC int argify(ECHAR *line, ECHAR ***avp)
STATIC void TTYshow(ECHAR c)
STATIC STATUS redisplay()
STATIC char * rsearch_hist(char *patt, int *lpos, int *cpos)
STATUS(* Keymap_Function)()
void rl_ttyset(int Reset)
STATIC CONST char * Prompt
STATIC ECHAR * find_word()
void add_history(char *p)
void rl_reset_terminal(char *p)
float start(const EST_Item &item)
STATIC ECHAR * move_right
STATIC void TTYputs(ECHAR *p)
STATIC STATUS do_hist(ECHAR *(*move)())
STATIC STATUS accept_line()
STATIC STATUS c_complete()
STATIC int substrcmp(char *text, char *pat, int len)
char ** EL_USER_COMPLETION_FUNCTION_TYPE(char *text, int start, int end)
#define COPYFROMTO(new, p, len)
char * readline(CONST char *prompt)
STATIC ESIZE_T ScreenSize
STATIC STATUS TTYspecial(int c)
STATIC STATUS insert_char(int c)
STATIC int printlen(CONST char *p)
STATIC STATUS copy_region()
char * rl_complete(char *pathname, int *unique)