int Line::ins_char(int pos, PLine src, Buffer* pBuf) { if(!src->size()) return 0; return ins_char(pos, src->str, src->size(), pBuf); }
void Line::indent(PLine src, int offset) { if(!src || offset <= 0) return; char* in = src->str; int pos = 0; if(!iIndUseTab) { ins_char(0, ' ', offset); return; } while(pos < offset) { if(!__issp(*in)) break; int delta = (*in == '\t') ? iTabWidth:1; if((pos + delta) > offset) break; pos += delta; in++; } if(pos) /* found something to insert */ ins_char(0, src->str, in - src->str); if((offset - pos) >= iTabWidth) { int ntabs = (offset - pos)/iTabWidth; ins_char(pos, '\t', ntabs); pos += iTabWidth * ntabs; } if((offset - pos) > 0) ins_char(pos, ' ', (offset - pos)); }
int Line::ins_char(int pos, int chr, int num, Buffer* pBuf) { if(num <= 0 || pos < 0) return 0; char* c = new char[num]; memset(c, chr, num); return ins_char(pos, c, num, pBuf); }
static BYTE *fs_back(BYTE *pstr, BYTE *pend) { if (!pend) pend = pstr + strlen(pstr); /* back off to last */ /* slash */ while ( (*pend != ':') && (*pend != '\\') && (pend != pstr) ) pend--; /* if a : then insert */ /* a backslash */ if (*pend == ':') { pend++; ins_char(pend, 0, '\\', LEN_ZPATH-3); } return(pend); }
char * inputLineHistSearch(char *prompt, char *def_str, int flag, Hist *hist, int (*incrfunc) (int ch, Str str, Lineprop *prop)) { int opos, x, y, lpos, rpos, epos; unsigned char c; char *p; #ifdef USE_M17N Str tmp; #endif is_passwd = FALSE; move_word = TRUE; CurrentHist = hist; if (hist != NULL) { use_hist = TRUE; strCurrentBuf = NULL; } else { use_hist = FALSE; } if (flag & IN_URL) { cm_mode = CPL_ALWAYS | CPL_URL; } else if (flag & IN_FILENAME) { cm_mode = CPL_ALWAYS; } else if (flag & IN_PASSWORD) { cm_mode = CPL_NEVER; is_passwd = TRUE; move_word = FALSE; } else if (flag & IN_COMMAND) cm_mode = CPL_ON; else cm_mode = CPL_OFF; opos = get_strwidth(prompt); epos = CLEN - opos; if (epos < 0) epos = 0; lpos = epos / 3; rpos = epos * 2 / 3; offset = 0; if (def_str) { strBuf = Strnew_charp(def_str); CLen = CPos = setStrType(strBuf, strProp); } else { strBuf = Strnew(); CLen = CPos = 0; } #ifdef SUPPORT_WIN9X_CONSOLE_MBCS enable_win9x_console_input(); #endif i_cont = TRUE; i_broken = FALSE; i_quote = FALSE; cm_next = FALSE; cm_disp_next = -1; need_redraw = FALSE; #ifdef USE_M17N wc_char_conv_init(wc_guess_8bit_charset(DisplayCharset), InnerCharset); #endif do { x = calcPosition(strBuf->ptr, strProp, CLen, CPos, 0, CP_FORCE); if (x - rpos > offset) { y = calcPosition(strBuf->ptr, strProp, CLen, CLen, 0, CP_AUTO); if (y - epos > x - rpos) offset = x - rpos; else if (y - epos > 0) offset = y - epos; } else if (x - lpos < offset) { if (x - lpos > 0) offset = x - lpos; else offset = 0; } move(LASTLINE, 0); addstr(prompt); if (is_passwd) addPasswd(strBuf->ptr, strProp, CLen, offset, COLS - opos); else addStr(strBuf->ptr, strProp, CLen, offset, COLS - opos); clrtoeolx(); move(LASTLINE, opos + x - offset); refresh(); next_char: c = getch(); #ifdef __EMX__ if (c == 0) { if (!(c = getcntrl())) goto next_char; } #endif cm_clear = TRUE; cm_disp_clear = TRUE; if (!i_quote && (((cm_mode & CPL_ALWAYS) && (c == CTRL_I || c == ' ')) || ((cm_mode & CPL_ON) && (c == CTRL_I)))) { if (emacs_like_lineedit && cm_next) { _dcompl(); need_redraw = TRUE; } else { _compl(); cm_disp_next = -1; } } else if (!i_quote && CLen == CPos && (cm_mode & CPL_ALWAYS || cm_mode & CPL_ON) && c == CTRL_D) { if (!emacs_like_lineedit) { _dcompl(); need_redraw = TRUE; } } else if (!i_quote && c == DEL_CODE) { _bs(); cm_next = FALSE; cm_disp_next = -1; } else if (!i_quote && c < 0x20) { /* Control code */ if (incrfunc == NULL || (c = incrfunc((int)c, strBuf, strProp)) < 0x20) (*InputKeymap[(int)c]) (c); if (incrfunc && c != (unsigned char)-1 && c != CTRL_J) incrfunc(-1, strBuf, strProp); if (cm_clear) cm_next = FALSE; if (cm_disp_clear) cm_disp_next = -1; } #ifdef USE_M17N else { tmp = wc_char_conv(c); if (tmp == NULL) { i_quote = TRUE; goto next_char; } i_quote = FALSE; cm_next = FALSE; cm_disp_next = -1; if (CLen + tmp->length > STR_LEN || !tmp->length) goto next_char; ins_char(tmp); if (incrfunc) incrfunc(-1, strBuf, strProp); } #else else { i_quote = FALSE; cm_next = FALSE; cm_disp_next = -1; if (CLen >= STR_LEN) goto next_char; insC(); strBuf->ptr[CPos] = c; if (!is_passwd && get_mctype(&c) == PC_CTRL) strProp[CPos] = PC_CTRL; else strProp[CPos] = PC_ASCII; CPos++; if (incrfunc) incrfunc(-1, strBuf, strProp); } #endif if (CLen && (flag & IN_CHAR)) break; } while (i_cont);