/*{{{ quoted_insert */ int quoted_insert() { SLwchar_Type ch; int ins_byte = 1; CHECK_READ_ONLY if (*Error_Buffer || SLKeyBoard_Quit) return(0); if (Repeat_Factor != NULL) { ch = *Repeat_Factor; ins_byte = 0; Repeat_Factor = NULL; } else { SLang_Key_TimeOut_Flag = 1; ch = jed_getkey(); SLang_Key_TimeOut_Flag = 0; } if (SLang_get_error () == SL_USER_BREAK) SLang_set_error (0); if ((ch == '\n') && (CBuf == MiniBuffer)) { (void) _jed_ins_byte ('\n'); /* msg_error("Not allowed!"); */ return (1); } SLKeyBoard_Quit = 0; if (ins_byte == 0) { if (-1 == jed_insert_wchar_n_times(ch, 1)) return -1; } else { unsigned char byte = (unsigned char) ch; if (-1 == jed_insert_nbytes (&byte, 1)) return -1; } if ((CBuf->syntax_table != NULL) && (CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX) && !input_pending(&Number_Zero)) blink_match (); /* (ch); */ return(1); }
/*{{{ ins_char_cmd */ int ins_char_cmd (void) { unsigned char ch; int wrap = Buffer_Local.wrap_column; int do_blink; int did_abbrev = 0; SLang_Name_Type *wrapok_hook; CHECK_READ_ONLY #if 0 ; #endif #if JED_HAS_LINE_ATTRIBUTES if (check_line_attr_no_modify (CLine)) return 0; #endif ch = SLang_Last_Key_Char; if (ch == '\n') { newline(); return(1); } #if JED_HAS_ABBREVS if (CBuf->flags & ABBREV_MODE) { if (-1 == (did_abbrev = jed_expand_abbrev (ch))) return -1; } #endif if ((CBuf->flags & OVERWRITE_MODE) && !eolp()) { /* FIXME: jed_del_wchar should be called for the last byte of a * UTF-8 sequence */ if ((did_abbrev == 0) && (-1 == jed_del_wchar ())) return -1; } /* It is ok to use Point as an estimator of the current column. This * avoids the more expensive call to calculate_column. */ if (CBuf->buffer_hooks != NULL) wrapok_hook = CBuf->buffer_hooks->wrapok_hook; else wrapok_hook = NULL; if (((ch == ' ') || (Point >= wrap)) && ((CBuf->modes & WRAP_MODE) || (wrapok_hook != NULL)) && (calculate_column() > wrap) && ((wrapok_hook == NULL) || (1 == execute_is_ok_hook (wrapok_hook)))) { unsigned int this_line_num = LineNum; if ((did_abbrev == 0) && (-1 == jed_insert_byte (ch))) return -1; if (1 != wrap_line(0)) /* do not format--- just wrap */ return -1; /* line isn't wrapable */ /* There is a bug involving wrapping a very long line containing * no whitespace and then we try to insert a character. This work * arounds the bug. */ if ((this_line_num == LineNum) && (ch == ' ')) /* && (calculate_column () > wrap)) */ { if (0 == jed_right (1)) newline (); } if ((CBuf->buffer_hooks != NULL) && (CBuf->buffer_hooks->wrap_hook != NULL)) SLexecute_function(CBuf->buffer_hooks->wrap_hook); else if (Indented_Text_Mode) indent_line (); return(1); } do_blink = ((((CBuf->syntax_table != NULL) && ((CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX))) || ((ch == ')') || (ch == '}') || (ch == ']'))) && !input_pending(&Number_Zero)); if (did_abbrev == 0) (void) jed_insert_byte (ch); if (do_blink) blink_match (); return 1; }
char *SLrline_read_line (SLrline_Type *rli, SLFUTURE_CONST char *prompt, unsigned int *lenp) { unsigned char *p, *pmax; SLang_Key_Type *key; int last_input_char; unsigned int dummy_len_buf; if (lenp == NULL) lenp = &dummy_len_buf; *lenp = 0; if (rli == NULL) return NULL; if (rli->state == RLI_LINE_IN_PROGRESS) { *lenp = 0; return NULL; } if (prompt == NULL) prompt = ""; if ((rli->prompt == NULL) || strcmp (rli->prompt, prompt)) { if (NULL == (prompt = SLmake_string (prompt))) return NULL; SLfree ((char *)rli->prompt); rli->prompt = prompt; } SLang_Rline_Quit = 0; p = rli->old_upd; pmax = p + rli->edit_width; while (p < pmax) *p++ = ' '; if (rli->state != RLI_LINE_SET) { rli->len = 0; rli->point = 0; *rli->buf = 0; } rli->state = RLI_LINE_IN_PROGRESS; rli->curs_pos = rli->start_column = 0; rli->new_upd_len = rli->old_upd_len = 0; rli->last_fun = NULL; if (rli->update_hook == NULL) putc ('\r', stdout); rli->is_modified = 0; rli->last = NULL; RLupdate (rli); last_input_char = 0; while (1) { SLrline_Type *save_rli = Active_Rline_Info; key = SLang_do_key (RL_Keymap, (int (*)(void)) rli->getkey); if ((key == NULL) || (key->f.f == NULL)) { rl_beep (); continue; } if ((*key->str != 2) || (key->str[1] != rli->eof_char)) last_input_char = 0; else { if ((rli->len == 0) && (last_input_char != rli->eof_char)) { rli->buf[rli->len] = 0; rli->state = RLI_LINE_READ; *lenp = 0; return NULL; /* EOF */ } last_input_char = rli->eof_char; } Active_Rline_Info = rli; if (key->type == SLKEY_F_INTRINSIC) { int (*func)(SLrline_Type *); func = (int (*)(SLrline_Type *)) key->f.f; (void) (*func)(rli); RLupdate (rli); if ((rli->flags & SL_RLINE_BLINK_MATCH) && (rli->input_pending != NULL)) blink_match (rli); } else if (key->type == SLKEY_F_SLANG) { (void) SLexecute_function (key->f.slang_fun); RLupdate (rli); } Active_Rline_Info = save_rli; if ((SLang_Rline_Quit) || _pSLang_Error) { if (_pSLang_Error) { rli->len = 0; } rli->buf[rli->len] = 0; rli->state = RLI_LINE_READ; *lenp = rli->len; free_history_item (rli->saved_line); rli->saved_line = NULL; if (_pSLang_Error) return NULL; return SLmake_nstring ((char *)rli->buf, rli->len); } if (key != NULL) rli->last_fun = key->f.f; } }