int capitalizeword(UNUSED(char **args)) { int first, n = zmult; int neg = n < 0, ocs = zlecs; if (neg) n = -n; while (n--) { first = 1; while (zlecs != zlell && !ZC_iword(zleline[zlecs])) INCCS(); while (zlecs != zlell && ZC_iword(zleline[zlecs]) && !ZC_ialpha(zleline[zlecs])) INCCS(); while (zlecs != zlell && ZC_iword(zleline[zlecs])) { zleline[zlecs] = (first) ? ZC_toupper(zleline[zlecs]) : ZC_tolower(zleline[zlecs]); first = 0; INCCS(); } } if (neg) zlecs = ocs; return 0; }
int backwardkillword(char **args) { int x = zlecs; int n = zmult; if (n < 0) { int ret; zmult = -n; ret = killword(args); zmult = n; return ret; } while (n--) { while (x) { int pos = x; DECPOS(pos); if (ZC_iword(zleline[pos])) break; x = pos; } while (x) { int pos = x; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; x = pos; } } backkill(zlecs - x, CUT_FRONT|CUT_RAW); return 0; }
int backwarddeleteword(char **args) { int x = zlecs, n = zmult; if (n < 0) { int ret; zmult = -n; ret = deleteword(args); zmult = n; return ret; } while (n--) { while (x) { int pos = x; DECPOS(pos); if (ZC_iword(zleline[pos])) break; x = pos; } while (x) { int pos = x; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; x = pos; } } backdel(zlecs - x, CUT_RAW); return 0; }
int emacsbackwardword(char **args) { int n = zmult; if (n < 0) { int ret; zmult = -n; ret = emacsforwardword(args); zmult = n; return ret; } while (n--) { while (zlecs) { int pos = zlecs; DECPOS(pos); if (ZC_iword(zleline[pos])) break; zlecs = pos; } while (zlecs) { int pos = zlecs; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; zlecs = pos; } } return 0; }
int downcaseword(UNUSED(char **args)) { int n = zmult; int neg = n < 0, ocs = zlecs; if (neg) n = -n; while (n--) { while (zlecs != zlell && !ZC_iword(zleline[zlecs])) INCCS(); while (zlecs != zlell && ZC_iword(zleline[zlecs])) { zleline[zlecs] = ZC_tolower(zleline[zlecs]); INCCS(); } } if (neg) zlecs = ocs; return 0; }
int copyprevword(UNUSED(char **args)) { int len, t0 = zlecs, t1; if (zmult > 0) { int count = zmult; for (;;) { t1 = t0; while (t0) { int prev = t0; DECPOS(prev); if (ZC_iword(zleline[prev])) break; t0 = prev; } while (t0) { int prev = t0; DECPOS(prev); if (!ZC_iword(zleline[prev])) break; t0 = prev; } if (!--count) break; if (t0 == 0) return 1; } } else return 1; len = t1 - t0; spaceinline(len); ZS_memcpy(zleline + zlecs, zleline + t0, len); zlecs += len; return 0; }
int killword(char **args) { int x = zlecs; int n = zmult; if (n < 0) { int ret; zmult = -n; ret = backwardkillword(args); zmult = n; return ret; } while (n--) { while (x != zlell && !ZC_iword(zleline[x])) INCPOS(x); while (x != zlell && ZC_iword(zleline[x])) INCPOS(x); } forekill(x - zlecs, CUT_RAW); return 0; }
int forwardword(char **args) { int n = zmult; if (n < 0) { int ret; zmult = -n; ret = backwardword(args); zmult = n; return ret; } while (n--) { while (zlecs != zlell && ZC_iword(zleline[zlecs])) INCCS(); if (wordflag && !n) return 0; while (zlecs != zlell && !ZC_iword(zleline[zlecs])) INCCS(); } return 0; }
int transposewords(UNUSED(char **args)) { int p1, p2, p3, p4, pt, len, x = zlecs, pos; ZLE_STRING_T temp, pp; int n = zmult; int neg = n < 0, ocs = zlecs; if (neg) n = -n; while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x])) INCPOS(x); if (x == zlell || zleline[x] == ZWC('\n')) { x = zlecs; while (x) { if (ZC_iword(zleline[x])) break; pos = x; DECPOS(pos); if (zleline[pos] == ZWC('\n')) break; x = pos; } if (!x) return 1; pos = x; DECPOS(pos); if (zleline[pos] == ZWC('\n')) return 1; } for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4)) ; for (p3 = p4; p3; ) { pos = p3; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; p3 = pos; } if (!p3) return 1; p1 = p2 = pt = p3; while (n--) { for (p2 = pt; p2; ) { pos = p2; DECPOS(pos); if (ZC_iword(zleline[pos])) break; p2 = pos; } if (!p2) return 1; for (p1 = p2; p1; ) { pos = p1; DECPOS(pos); if (!ZC_iword(zleline[pos])) break; p1 = pos; } pt = p1; } pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE); len = p4 - p3; ZS_memcpy(pp, zleline + p3, len); pp += len; len = p3 - p2; ZS_memcpy(pp, zleline + p2, len); pp += len; ZS_memcpy(pp, zleline + p1, p2 - p1); ZS_memcpy(zleline + p1, temp, p4 - p1); if (neg) zlecs = ocs; else zlecs = p4; return 0; }