/* * Move the cursor forward by the specified number of words. All of the motion * is done by "forwchar". Error if you try and move beyond the buffer's end. */ int forwword(int f, int n) { if (n < 0) return (backword(f, -n)); while (n--) { #if NFWORD while (inword() != FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); } #endif while (inword() == FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); } #if NFWORD == 0 while (inword() != FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); } #endif } return(TRUE); }
/* * Kill forward by "n" words. Remember the location of dot. Move forward by * the right number of words. Put dot back where it was and issue the kill * command for the right number of characters. Bound to "M-D" */ int delfword(int f, int n) { LINE *dotp; int size, doto; if (n < 0) return (FALSE); dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0; while (n--) { while (inword() != FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); ++size; } while (inword() == FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); ++size; } } curwp->w_dotp = dotp; curwp->w_doto = doto; return (ldelete(size, TRUE)); }
/* go back to the begining of the current paragraph here we look for a * <NL><NL> or <NL><TAB> or <NL><SPACE> combination to delimit the begining of * a paragraph */ int gotobop (int f, int n) { int suc; /* success of last backchar */ if (n < 0) /* the other way.. */ return (gotoeop (f, -n)); while (n-- > 0) { /* for each one asked for */ /* first scan back until we are in a word */ suc = backchar (FALSE, 1); while (!inword () && suc) suc = backchar (FALSE, 1); curwp->w_doto = 0; /* and go to the B-O-Line */ /* and scan back until we hit a <NL><NL> or <NL><TAB> or a <NL><SPACE> */ while (lback (curwp->w_dotp) != curbp->b_linep) if (llength (curwp->w_dotp) != 0 && lgetc (curwp->w_dotp, curwp->w_doto) != TAB && lgetc (curwp->w_dotp, curwp->w_doto) != ' ') curwp->w_dotp = lback (curwp->w_dotp); else break; /* and then forward until we are in a word */ suc = forwchar (FALSE, 1); while (suc && !inword ()) suc = forwchar (FALSE, 1); } curwp->w_flag |= WFMOVE; /* force screen update */ return (TRUE); }
/* * Move the cursor forward by the specified number of words. As you move, * convert any characters to upper case. Error if you try and move beyond the * end of the buffer. Bound to "M-U" */ int upperword(int f, int n) { int c; if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); } while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (c >= 'a' && c <= 'z') { c -= 'a' - 'A'; lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFHARD); } if (forwchar(FALSE, 1) == FALSE) return (FALSE); } } return (TRUE); }
/* * Move the cursor forward by the specified number of words. As you move * convert characters to lower case. Error if you try and move over the end of * the buffer. Bound to "M-L". */ int lowerword(int f, int n) { register int c; CELL ac; ac.a = 0; if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); } while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto).c; if (c>='A' && c<='Z') { ac.c (c += 'a'-'A'); lputc(curwp->w_dotp, curwp->w_doto, ac); lchange(WFHARD); } if (forwchar(FALSE, 1) == FALSE) return (FALSE); } } return (TRUE); }
/* * Go to the end of the current sentence. Like gotobosent(), if we skip into * an empty line, return at that point. */ int gotoeosent(int f, int n) { regexp *exp; int s; int empty = is_empty_line(DOT); exp = b_val_rexp(curbp, VAL_SENTENCES)->reg; /* if we're on the end of a sentence now, don't bother scanning further, or we'll miss the immediately following sentence */ if (!(lregexec(exp, DOT.l, DOT.o, llength(DOT.l)) && exp->startp[0] - lvalue(DOT.l) == DOT.o)) { if (findpat(f, n, exp, FORWARD) != TRUE) { DOT = curbp->b_line; } else if (empty || !is_at_end_of_line(DOT)) { s = forwchar(TRUE, RegexpLen(exp)); while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) { LINE *lp = DOT.l; s = forwchar(TRUE, 1); if (lp != DOT.l) break; } } } else { s = forwchar(TRUE, RegexpLen(exp)); while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) s = forwchar(TRUE, 1); } return TRUE; }
static int simple_fence(int sdir, int ch, int ofence) { int count = 1; /* Assmue that we're sitting at one end of the fence */ int c; /* scan for fence */ while (InDirection(sdir) && !interrupted()) { c = CurrentChar(); if (c == ch) { ++count; } else if (c == ofence) { if (--count <= 0) break; } } /* if count is zero, we have a match, move the sucker */ if (count <= 0) { if (!doingopcmd || doingsweep) sweephack = TRUE; else if (sdir == FORWARD) forwchar(TRUE,1); curwp->w_flag |= WFMOVE; return TRUE; } return FALSE; }
/* ARGSUSED */ int backchar(int f, int n) { struct line *lp; if (n < 0) return (forwchar(f, -n)); while (n--) { if (curwp->w_doto == 0) { if ((lp = lback(curwp->w_dotp)) == curbp->b_headp) { if (!(f & FFRAND)) { dobeep(); ewprintf("Beginning of buffer"); } return (FALSE); } curwp->w_dotp = lp; curwp->w_doto = llength(lp); curwp->w_rflag |= WFMOVE; curwp->w_dotline--; } else curwp->w_doto--; } return (TRUE); }
/* simple finder -- give it a compiled regex, a direction, and it takes you there if it can. no wrapping allowed */ int findpat(int f, int n, regexp * exp, int direc) { int s; MARK savepos; if (!exp) return FALSE; n = need_a_count(f, n, 1); s = TRUE; scanboundpos = curbp->b_line; /* was scanboundry(FALSE,savepos,0); */ scanbound_is_header = TRUE; savepos = DOT; while (s == TRUE && n--) { savepos = DOT; s = ((direc == FORWARD) ? forwchar(TRUE, 1) : backchar(TRUE, 1)); if (s == TRUE) s = scanner(exp, direc, FALSE, (int *) 0); } if (s != TRUE) DOT = savepos; return s; }
/* * Kill backwards by "n" words. Move backwards by the desired number of words, * counting the characters. When dot is finally moved to its resting place, * fire off the kill command. Bound to "M-Rubout" and to "M-Backspace". */ int delbword(int f, int n) { register long size; if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if (n < 0) return (FALSE); if (backchar(FALSE, 1) == FALSE) return (FALSE); size = 0L; while (n--) { while (inword() == FALSE) { if (backchar(FALSE, 1) == FALSE) return (FALSE); ++size; } while (inword() != FALSE) { if (backchar(FALSE, 1) == FALSE) return (FALSE); ++size; } } if (forwchar(FALSE, 1) == FALSE) return (FALSE); return (ldelete(size, kinsert)); }
/* * Move the cursor backwards by "n" characters. If "n" is less than zero call * "forwchar" to actually do the move. Otherwise compute the new cursor * location. Error if you try and move out of the buffer. Set the flag if the * line pointer for dot changes. */ PASCAL NEAR backchar( int f, int n )/* prefix flag and argument */ { register LINE *lp; if (n < 0) return(forwchar(f, -n)); while (n--) { if (curwp->w_doto == 0) { if ((lp=lback(curwp->w_dotp)) == curbp->b_linep) return(FALSE); curwp->w_dotp = lp; curwp->w_doto = llength(lp); curwp->w_flag |= WFMOVE; } else curwp->w_doto--; } #if DBCS return(stopback()); #else return(TRUE); #endif }
/* * Kill backwards by "n" words. Move backwards by the desired number of words, * counting the characters. When dot is finally moved to its resting place, * fire off the kill command. Bound to "M-Rubout" and to "M-Backspace" */ int delbword(int f, int n) { int size; if (n < 0) return (FALSE); if (backchar(FALSE, 1) == FALSE) return (FALSE); size = 0; while (n--) { while (inword() == FALSE) { if (backchar(FALSE, 1) == FALSE) return (FALSE); ++size; } while (inword() != FALSE) { if (backchar(FALSE, 1) == FALSE) return (FALSE); ++size; } } if (forwchar(FALSE, 1) == FALSE) return (FALSE); return (ldelete(size, TRUE)); }
/* ARGSUSED */ int capword(int f, int n) { int c, s; RSIZE size; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { dobeep(); ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } size = countfword(); undo_add_change(curwp->w_dotp, curwp->w_doto, size); if (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (ISLOWER(c) != FALSE) { c = TOUPPER(c); lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (ISUPPER(c) != FALSE) { c = TOLOWER(c); lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } } } return (TRUE); }
static int comment_fence(int sdir) { MARK comstartpos; int found = FALSE; int s = FALSE; int first = TRUE; comstartpos.l = null_ptr; while (!found) { if (!first && CurrentChar() == '/') { /* is it a comment-end? */ if (PrevCharIs('*')) { if (sdir == FORWARD) { found = TRUE; break; } else if (comstartpos.l != null_ptr) { DOT = comstartpos; found = TRUE; break; } else { return FALSE; } } /* is it a comment start? */ if (sdir == REVERSE && NextCharIs('*')) { /* remember where we are */ comstartpos = DOT; } } s = InDirection(sdir); if (s == FALSE) { if (comstartpos.l != null_ptr) { DOT = comstartpos; found = TRUE; break; } return FALSE; } if (interrupted()) return FALSE; first = FALSE; } /* if found, move the sucker */ if (found && !first) { if (!doingopcmd || doingsweep) sweephack = TRUE; else if (sdir == FORWARD) forwchar(TRUE,1); curwp->w_flag |= WFMOVE; return TRUE; } return FALSE; }
/* ARGSUSED */ int forwword(int f, int n) { if (n < 0) return (backword(f | FFRAND, -n)); while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } } return (TRUE); }
/* ARGSUSED */ int delfword(int f, int n) { RSIZE size; struct line *dotp; int doto; int s; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { dobeep(); ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); /* purge kill buffer */ if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0; while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } } out: curwp->w_dotp = dotp; curwp->w_doto = doto; return (ldelete(size, KFORW)); }
/* Word wrap on n-spaces. Back-over whatever precedes the point on the current * line and stop on the first word-break or the beginning of the line. If we * reach the beginning of the line, jump back to the end of the word and start * a new line. Otherwise, break the line at the word-break, eat it, and jump * back to the end of the word. * Returns TRUE on success, FALSE on errors. */ wrapword() { register int cnt; /* size of word wrapped to next line */ register int bp; /* index to wrap on */ register int first = -1; register int i; if(curwp->w_doto <= 0) /* no line to wrap? */ return(FALSE); for(bp = cnt = i = 0; cnt < llength(curwp->w_dotp) && !bp; cnt++, i++){ if(isspace((unsigned char) lgetc(curwp->w_dotp, cnt).c)){ first = 0; if(lgetc(curwp->w_dotp, cnt).c == TAB) while(i+1 & 0x07) i++; } else if(!first) first = cnt; if(first > 0 && i >= fillcol) bp = first; } if(!bp) return(FALSE); /* bp now points to the first character of the next line */ cnt = curwp->w_doto - bp; curwp->w_doto = bp; if(!lnewline()) /* break the line */ return(FALSE); /* * if there's a line below, it doesn't start with whitespace * and there's room for this line... */ if(!(curbp->b_flag & BFWRAPOPEN) && lforw(curwp->w_dotp) != curbp->b_linep && llength(lforw(curwp->w_dotp)) && !isspace((unsigned char) lgetc(lforw(curwp->w_dotp), 0).c) && (llength(curwp->w_dotp) + llength(lforw(curwp->w_dotp)) < fillcol)){ gotoeol(0, 1); /* then pull text up from below */ if(lgetc(curwp->w_dotp, curwp->w_doto - 1).c != ' ') linsert(1, ' '); forwdel(0, 1); gotobol(0, 1); } curbp->b_flag &= ~BFWRAPOPEN; /* don't open new line next wrap */ /* restore dot (account for NL) */ if(cnt && !forwchar(0, cnt < 0 ? cnt-1 : cnt)) return(FALSE); return(TRUE); }
int PASCAL NEAR stopforw() { /* don't stop on the second byte of a 2 byte character */ if (curwp->w_doto > 0 && is2byte(curwp->w_dotp->l_text, curwp->w_dotp->l_text + curwp->w_doto - 1)) return(forwchar(TRUE, 1)); return(TRUE); }
/* * Go to the beginning of the current sentence. If we skip into an empty line * (from a non-empty line), return at that point -- that's what vi does. */ int gotobosent(int f, int n) { MARK savepos; int looped = 0; int extra; int empty = is_empty_line(DOT); regexp *exp; int s = TRUE; savepos = DOT; exp = b_val_rexp(curbp, VAL_SENTENCES)->reg; while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) { s = backchar(TRUE, 1); if (is_empty_line(DOT) && !empty) return TRUE; } top: extra = 0; if (findpat(f, n, exp, REVERSE) != TRUE) { return gotobob(f, n); } s = forwchar(TRUE, RegexpLen(exp)); while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) { s = forwchar(TRUE, 1); extra++; } if (n == 1 && samepoint(savepos, DOT)) { /* try again */ if (looped > 10) return FALSE; s = backchar(TRUE, RegexpLen(exp) + extra + looped); while (s && is_at_end_of_line(DOT)) { if (!empty && is_empty_line(DOT)) return TRUE; s = backchar(TRUE, 1); } looped++; goto top; } return TRUE; }
/* Close fences are matched against their partners, and if on screen the cursor briefly lights there */ void fmatch(int rch) { MARK oldpos; /* original position */ register LINE *toplp; /* top line in current window */ register int count; /* current fence level count */ register char c; /* current character in scan */ int dir, lch; int backcharfailed = FALSE; /* get the matching left-fence char, if it exists */ lch = is_user_fence(rch, &dir); if (lch == 0 || dir != REVERSE) return; /* first get the display update out there */ (void)update(FALSE); /* save the original cursor position */ oldpos = DOT; /* find the top line and set up for scan */ toplp = lback(curwp->w_line.l); count = 1; backchar(TRUE, 2); /* scan back until we find it, or reach past the top of the window */ while (count > 0 && DOT.l != toplp) { c = CurrentChar(); if (c == rch) ++count; if (c == lch) --count; if (backchar(FALSE, 1) != TRUE) { backcharfailed = TRUE; break; } } /* if count is zero, we have a match, display the sucker */ if (count == 0) { if (!backcharfailed) forwchar(FALSE, 1); if (update(FALSE) == TRUE) /* the idea is to leave the cursor there for about a quarter of a second */ catnap(300, FALSE); } /* restore the current position */ DOT = oldpos; }
/* * Kill forward by "n" words. Remember the location of dot. Move forward by * the right number of words. Put dot back where it was and issue the kill * command for the right number of characters. Bound to "M-D". */ int delfword(int f, int n) { register long size; register LINE *dotp; register int doto; if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if (n < 0) return (FALSE); dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0L; while (n--) { #if NFWORD while (inword() != FALSE) { if (forwchar(FALSE,1) == FALSE) return(FALSE); ++size; } #endif while (inword() == FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); ++size; } #if NFWORD == 0 while (inword() != FALSE) { if (forwchar(FALSE, 1) == FALSE) return (FALSE); ++size; } #endif } curwp->w_dotp = dotp; curwp->w_doto = doto; return (ldelete(size, kinsert)); }
/* * Add a character, checking for word wrapping. * Check to see if we're past fillcol, and if so, * justify this line. As a last step, justify the line. */ int fillword (int f, int n, int k) { register char c; register int col, i, nce; for (i = col = 0; col <= fillcol; ++i, ++col) { if (i == curwp->w_dot.o) return selfinsert (f, n, k); c = lgetc (curwp->w_dot.p, i); if (c == '\t') col += (tabsize - col % tabsize) - 1; else if (ISCTRL (c) != FALSE) ++col; } if (curwp->w_dot.o != llength (curwp->w_dot.p)) { selfinsert (f, n, k); nce = llength (curwp->w_dot.p) - curwp->w_dot.o; } else nce = 0; curwp->w_dot.o = i; if ((c = lgetc (curwp->w_dot.p, curwp->w_dot.o)) != ' ' && c != '\t') do { backchar (FALSE, 1, KRANDOM); } while ((c = lgetc (curwp->w_dot.p, curwp->w_dot.o)) != ' ' && c != '\t' && curwp->w_dot.o > 0); if (curwp->w_dot.o == 0) do { forwchar (FALSE, 1, KRANDOM); } while ((c = lgetc (curwp->w_dot.p, curwp->w_dot.o)) != ' ' && c != '\t' && curwp->w_dot.o < llength (curwp->w_dot.p)); delwhite (FALSE, 1, KRANDOM); backdel (FALSE, 1, KRANDOM); lnewline (); curwp->w_dot.o = llength (curwp->w_dot.p) - nce; curwp->w_flag |= WFMOVE; if (nce == 0 && curwp->w_dot.o != 0) return (fillword (f, n, k)); return (TRUE); }
/* ARGSUSED */ int delbword(int f, int n) { RSIZE size; int s; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { dobeep(); ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); /* purge kill buffer */ if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ return (TRUE); /* one deleted */ size = 1; while (n--) { while (inword() == FALSE) { if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ goto out; ++size; } while (inword() != FALSE) { if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ goto out; ++size; } } if (forwchar(FFRAND, 1) == FALSE) return (FALSE); /* undo assumed delete */ --size; out: return (ldelete(size, KBACK)); }
/* * movetoword() - move to the first occurance of the word w * * returns: * TRUE upon success * FALSE otherwise */ int movetoword(UCS *w) { int i; int ret = FALSE; int olddoto; LINE *olddotp; register int off; /* curwp offset */ register LINE *lp; /* curwp line */ olddoto = curwp->w_doto; /* save where we are */ olddotp = curwp->w_dotp; curwp->w_bufp->b_mode |= MDEXACT; /* case sensitive */ while(forscan(&i, w, 0, NULL, 0, 1) == TRUE){ if(i) break; /* wrap NOT allowed! */ lp = curwp->w_dotp; /* for convenience */ off = curwp->w_doto; /* * We want to minimize the number of substrings that we report * as matching a misspelled word... */ if(off == 0 || !ucs4_isalpha(lgetc(lp, off - 1).c)){ off += ucs4_strlen(w); if((!ucs4_isalpha(lgetc(lp, off).c) || off == llength(lp)) && lgetc(lp, 0).c != '>'){ ret = TRUE; break; } } forwchar(0, 1); /* move on... */ } curwp->w_bufp->b_mode ^= MDEXACT; /* case insensitive */ if(ret == FALSE){ curwp->w_dotp = olddotp; curwp->w_doto = olddoto; } else curwp->w_flag |= WFHARD; return(ret); }
/* ARGSUSED */ int fillword(int f, int n) { char c; int col, i, nce; for (i = col = 0; col <= fillcol; ++i, ++col) { if (i == curwp->w_doto) return selfinsert(f, n); c = lgetc(curwp->w_dotp, i); if (c == '\t' #ifdef NOTAB && !(curbp->b_flag & BFNOTAB) #endif ) col |= 0x07; else if (ISCTRL(c) != FALSE) ++col; } if (curwp->w_doto != llength(curwp->w_dotp)) { (void)selfinsert(f, n); nce = llength(curwp->w_dotp) - curwp->w_doto; } else nce = 0; curwp->w_doto = i; if ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t') do { (void)backchar(FFRAND, 1); } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t' && curwp->w_doto > 0); if (curwp->w_doto == 0) do { (void)forwchar(FFRAND, 1); } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t' && curwp->w_doto < llength(curwp->w_dotp)); (void)delwhite(FFRAND, 1); (void)lnewline(); i = llength(curwp->w_dotp) - nce; curwp->w_doto = i > 0 ? i : 0; curwp->w_rflag |= WFMOVE; if (nce == 0 && curwp->w_doto != 0) return (fillword(f, n)); return (TRUE); }
/* * Move the cursor backward by "n" words. All of the details of motion are * performed by the "backchar" and "forwchar" routines. Error if you try to * move beyond the buffers. */ int backword(int f, int n) { if (n < 0) return (forwword(f, -n)); if (backchar_no_header_editor(FALSE, 1) == FALSE) return (FALSE); while (n--) { while (inword() == FALSE) { if (backchar_no_header_editor(FALSE, 1) == FALSE) return (FALSE); } while (inword() != FALSE) { if (backchar_no_header_editor(FALSE, 1) == FALSE) return (FALSE); } } return (forwchar(FALSE, 1)); }
/* * Move the cursor backwards by "n" characters. If "n" is less than zero call * "forwchar" to actually do the move. Otherwise compute the new cursor * location. Error if you try and move out of the buffer. Set the flag if the * line pointer for dot changes. */ int backchar (int f, int n) { LINE *lp; if (n < 0) return (forwchar (f, -n)); while (n--) { if (curwp->w_doto == 0) { if ((lp = lback (curwp->w_dotp)) == curbp->b_linep) return (FALSE); curwp->w_dotp = lp; curwp->w_doto = llength (lp); curwp->w_flag |= WFMOVE; } else curwp->w_doto--; } return (TRUE); }
/* * Move cursor backwards. Do the * right thing if the count is less than * 0. Error if you try to move back from * the beginning of the buffer. */ int backchar (int f, int n, int k) { register LINE *lp; if (n < 0) return (forwchar (f, -n, KRANDOM)); while (n--) { if (curwp->w_dot.o == 0) { if ((lp = lback (curwp->w_dot.p)) == curbp->b_linep) return (FALSE); curwp->w_dot.p = lp; curwp->w_dot.o = llength (lp); curwp->w_flag |= WFMOVE; } else curwp->w_dot.o--; } return (TRUE); }
/* * Move the cursor backwards by "n" characters. If "n" is less than zero call * "forwchar" to actually do the move. Otherwise compute the new cursor * location. Error if you try and move out of the buffer. Set the flag if the * line pointer for dot changes. */ int backchar(int f, int n) { LINE *lp; n = need_a_count(f, n, 1); if (n < 0) return (forwchar(f, -n)); while (n--) { if (DOT.o == w_left_margin(curwp)) { if ((lp = lback(DOT.l)) == buf_head(curbp)) return (FALSE); DOT.l = lp; DOT.o = llength(lp); curwp->w_flag |= WFMOVE; } else { DOT.o -= BytesBefore(DOT.l, DOT.o); } } return (TRUE); }
/* * Count characters in word, from current position */ RSIZE countfword() { RSIZE size; struct line *dotp; int doto; dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0; while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } out: curwp->w_dotp = dotp; curwp->w_doto = doto; return (size); }