int viputafter(UNUSED(char **args)) { Cutbuffer buf = &cutbuf; int n = zmult; startvichange(-1); if (n < 0) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; if (!buf->buf) return 1; if(buf->flags & CUTBUFFER_LINE) { zlecs = findeol(); spaceinline(buf->len + 1); zleline[zlecs++] = ZWC('\n'); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); vifirstnonblank(zlenoargs); } else { if (zlecs != findeol()) INCCS(); while (n--) { spaceinline(buf->len); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); zlecs += buf->len; } if (zlecs) DECCS(); } return 0; }
int downline(void) { int n = zmult; if (n < 0) { zmult = -zmult; n = upline(); zmult = -zmult; return n; } if ((lastcmd & ZLE_LINEMOVE) != ZLE_LINEMOVE) lastcol = cs - findbol(); while (n) { int x = findeol(); if (x == ll) break; cs = x + 1; n--; } if (!n) { int x = findeol(); if ((cs += lastcol) >= x) { cs = x; if (cs > findbol() && bindtab == altbindtab) cs--; } } return n; }
void viputafter(void) { Cutbuffer buf = &cutbuf; startvichange(-1); if (zmult < 0) return; if (gotvibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); return; } vilinerange = !!(buf->flags & CUTBUFFER_LINE); if (vilinerange) { cs = findeol(); spaceinline(buf->len + 1); line[cs++] = '\n'; memcpy((char *)line + cs, buf->buf, buf->len); vifirstnonblank(); } else { if (cs != findeol()) cs++; while (zmult--) { spaceinline(buf->len); memcpy((char *)line + cs, buf->buf, buf->len); cs += buf->len; } if (cs) cs--; } }
int poundinsert(UNUSED(char **args)) { zlecs = 0; vifirstnonblank(zlenoargs); if (zleline[zlecs] != '#') { spaceinline(1); zleline[zlecs] = '#'; zlecs = findeol(); while(zlecs != zlell) { zlecs++; vifirstnonblank(zlenoargs); spaceinline(1); zleline[zlecs] = '#'; zlecs = findeol(); } } else { foredel(1, 0); zlecs = findeol(); while(zlecs != zlell) { zlecs++; vifirstnonblank(zlenoargs); if(zleline[zlecs] == '#') foredel(1, 0); zlecs = findeol(); } } done = 1; return 0; }
int videletechar(char **args) { int n = zmult; startvichange(-1); /* handle negative argument */ if (n < 0) { int ret; zmult = -n; ret = vibackwarddeletechar(args); zmult = n; return ret; } /* it is an error to be on the end of line */ if (zlecs == zlell || zleline[zlecs] == '\n') return 1; /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ /* HERE: we should do the test properly with INCPOS(). */ if (n > findeol() - zlecs) { n = findeol() - zlecs; /* do the deletion */ forekill(n, CUT_RAW); } else { forekill(n, 0); } return 0; }
void vikilleol(void) { int n = findeol() - cs; startvichange(-1); if (!n) { /* error -- line already empty */ feep(); return; } /* delete to end of line */ forekill(findeol() - cs, 0); }
int vikilleol(UNUSED(char **args)) { int n = findeol() - zlecs; startvichange(-1); if (!n) { /* error -- line already empty */ return 1; } /* delete to end of line */ forekill(findeol() - zlecs, CUT_RAW); return 0; }
int viunindent(UNUSED(char **args)) { int oldcs = zlecs, c2; /* get the range */ startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = 0; return 1; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; return 1; } oldcs = zlecs; /* remove a tab from the beginning of each line within range */ while (zlecs < c2) { if (zleline[zlecs] == '\t') foredel(1, 0); zlecs = findeol() + 1; } /* go back to the first line of the range */ zlecs = oldcs; vifirstnonblank(zlenoargs); return 0; }
void viaddnext(void) { if (cs != findeol()) cs++; startvitext(1); }
int viaddeol(UNUSED(char **args)) { zlecs = findeol(); startvitext(1); return 0; }
static void parse_char(PCONF_CTX *ctx) { switch(ctx->state) { case STATE_FINDWORDSTART: ctx->state = findwordstart(ctx); break; case STATE_FINDEOL: ctx->state = findeol(ctx); break; case STATE_QUOTECOLLECT: ctx->state = quotecollect(ctx); break; case STATE_QC_LITERAL: ctx->state = qc_literal(ctx); break; case STATE_COLLECT: ctx->state = collect(ctx); break; case STATE_COLLECTLITERAL: ctx->state = collectliteral(ctx); break; } /* switch */ }
static int dovilinerange(void) { int pos = zlecs, n = zmult; /* A number of lines is taken as the range. The current line * * is included. If the repeat count is positive the lines go * * downward, otherwise upward. The repeat count gives the * * number of lines. */ vilinerange = 1; if (!n) return 1; if (n > 0) { while(n-- && zlecs <= zlell) zlecs = findeol() + 1; if (n != -1) { zlecs = pos; return 1; } DECCS(); } else { while(n++ && zlecs >= 0) zlecs = findbol() - 1; if (n != 1) { zlecs = pos; return 1; } INCCS(); } virangeflag = 2; return 0; }
int vijoin(UNUSED(char **args)) { int x, pos; startvichange(-1); if ((x = findeol()) == zlell) return 1; zlecs = x + 1; pos = zlecs; for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs)) ; x = 1 + (zlecs - pos); backdel(x, CUT_RAW); if (zlecs) { int pos = zlecs; DECPOS(pos); if (ZC_iblank(zleline[pos])) { zlecs = pos; return 0; } } spaceinline(1); zleline[zlecs] = ZWC(' '); return 0; }
int viyank(UNUSED(char **args)) { int c2, ret = 1; startvichange(1); if ((c2 = getvirange(0)) != -1) { cut(zlecs, c2 - zlecs, CUT_YANK); ret = 0; } vichgflag = 0; /* cursor now at the start of the range yanked. For line mode * restore the column position */ if (vilinerange && lastcol != -1) { int x = findeol(); if ((zlecs += lastcol) >= x) { zlecs = x; if (zlecs > findbol() && invicmdmode()) DECCS(); } #ifdef MULTIBYTE_SUPPORT else CCRIGHT(); #endif lastcol = -1; } return ret; }
int vichangeeol(UNUSED(char **args)) { forekill(findeol() - zlecs, CUT_RAW); startvitext(1); return 0; }
void vireplacechars(void) { int ch; startvichange(1); /* get key */ if((ch = vigetkey()) == -1) { vichgflag = 0; feep(); return; } /* check argument range */ if (zmult < 0 || zmult + cs > findeol()) { vichgflag = 0; feep(); return; } /* do change */ if (ch == '\r' || ch == '\n') { /* <return> handled specially */ cs += zmult - 1; backkill(zmult - 1, 0); line[cs++] = '\n'; } else { while (zmult--) line[cs++] = ch; cs--; } vichgflag = 0; }
void viunindent(void) { int oldcs = cs, c2; /* get the range */ startvichange(1); if ((c2 = getvirange(0)) == -1) { vichgflag = vilinerange = 0; return; } vichgflag = 0; /* must be a line range */ if (!vilinerange) { feep(); cs = oldcs; return; } vilinerange = 0; oldcs = cs; /* remove a tab from the beginning of each line within range */ while (cs < c2) { if (line[cs] == '\t') foredel(1); cs = findeol() + 1; } /* go back to the first line of the range */ cs = oldcs; vifirstnonblank(); }
/* position: 0 is before, 1 after, 2 split the line */ static void pastebuf(Cutbuffer buf, int mult, int position) { int cc; if (buf->flags & CUTBUFFER_LINE) { if (position == 2) { if (!zlecs) position = 0; else if (zlecs == zlell) position = 1; } if (position == 2) { yankb = zlecs; spaceinline(buf->len + 2); zleline[zlecs++] = ZWC('\n'); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); zlecs += buf->len; zleline[zlecs] = ZWC('\n'); yanke = zlecs + 1; } else if (position != 0) { yankb = zlecs = findeol(); spaceinline(buf->len + 1); zleline[zlecs++] = ZWC('\n'); yanke = zlecs + buf->len; ZS_memcpy(zleline + zlecs, buf->buf, buf->len); } else { yankb = zlecs = findbol(); spaceinline(buf->len + 1); ZS_memcpy(zleline + zlecs, buf->buf, buf->len); yanke = zlecs + buf->len + 1; zleline[zlecs + buf->len] = ZWC('\n'); } vifirstnonblank(zlenoargs); } else { if (position == 1 && zlecs != findeol()) INCCS(); yankb = zlecs; cc = buf->len; while (mult--) { spaceinline(cc); ZS_memcpy(zleline + zlecs, buf->buf, cc); zlecs += cc; } yanke = zlecs; if (zlecs && invicmdmode()) DECCS(); } }
void viopenlinebelow(void) { cs = findeol(); spaceinline(1); line[cs++] = '\n'; startvitext(1); }
int viaddnext(UNUSED(char **args)) { if (zlecs != findeol()) INCCS(); startvitext(1); return 0; }
void regionlines(int *start, int *end) { int origcs = zlecs; UNMETACHECK(); if (zlecs < mark) { *start = findbol(); zlecs = (mark > zlell) ? zlell : mark; *end = findeol(); } else { *end = findeol(); zlecs = mark; *start = findbol(); } zlecs = origcs; }
void endofbufferorhistory(void) { if (findeol() != ll) cs = ll; else endofhistory(); }
int viopenlinebelow(UNUSED(char **args)) { zlecs = findeol(); spaceinline(1); zleline[zlecs++] = '\n'; startvitext(1); clearlist = 1; return 0; }
int vijoin(UNUSED(char **args)) { int x, pos; int n = zmult; int visual = region_active; startvichange(-1); if (n < 1) return 1; if (visual && zlecs > mark) { exchangepointandmark(zlenoargs); x = findeol(); if (x >= mark) { exchangepointandmark(zlenoargs); return 1; } } else if ((x = findeol()) == zlell || (visual && x >= mark)) return 1; while (n) { zlecs = x + 1; pos = zlecs; for (; zlecs != zlell && ZC_iblank(zleline[zlecs]); INCPOS(zlecs)) ; x = 1 + (zlecs - pos); backdel(x, CUT_RAW); if (zlecs) { int pos = zlecs; DECPOS(pos); if (ZC_iblank(zleline[pos])) { zlecs = pos; return 0; } } spaceinline(1); zleline[zlecs] = ZWC(' '); if ((!visual && --n < 2) || (x = findeol()) == zlell || (visual && x >= mark)) return 0; } return 0; }
int visubstitute(UNUSED(char **args)) { int n = zmult; startvichange(1); if (n < 0) return 1; /* it is an error to be on the end of line */ if (zlecs == zlell || zleline[zlecs] == '\n') return 1; /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ if (n > findeol() - zlecs) n = findeol() - zlecs; /* do the substitution */ forekill(n, CUT_RAW); startvitext(1); return 0; }
int viyankeol(UNUSED(char **args)) { int x = findeol(); startvichange(-1); if (x == zlecs) return 1; cut(zlecs, x - zlecs, 0); return 0; }
void visubstitute(void) { startvichange(1); if (zmult < 0) { feep(); return; } /* it is an error to be on the end of line */ if (cs == ll || line[cs] == '\n') { feep(); return; } /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ if (zmult > findeol() - cs) zmult = findeol() - cs; /* do the substitution */ forekill(zmult, 0); startvitext(1); }
void viyankeol(void) { int x = findeol(); startvichange(-1); if (x == cs) { feep(); return; } cut(cs, x - cs, 0); }
void videletechar(void) { startvichange(-1); /* handle negative argument */ if (zmult < 0) { zmult = -zmult; vibackwarddeletechar(); return; } /* it is an error to be on the end of line */ if (cs == ll || line[cs] == '\n') { feep(); return; } /* Put argument into the acceptable range -- it is not an error to * * specify a greater count than the number of available characters. */ if (zmult > findeol() - cs) zmult = findeol() - cs; /* do the deletion */ forekill(zmult, 0); }
int vichangeeol(UNUSED(char **args)) { int a, b; if (region_active) { regionlines(&a, &b); zlecs = a; region_active = 0; cut(zlecs, b - zlecs, CUT_RAW); shiftchars(zlecs, b - zlecs); } else forekill(findeol() - zlecs, CUT_RAW); startvitext(1); return 0; }