#include "ded.h" #include "char.h" /************************************************************************ * * * copyright Richard Bornat 1981 * * * ************************************************************************/ /************************************************************************ * * * the Harold Thimbleby * * word boundary algorithm * * * ************************************************************************/ wordb(str, scol, lmarg, rmarg) char *str; register int scol; int lmarg, rmarg; { register char *rp = str+scol; register char c = *rp--; /* point rp one position back */ if (scol<=lmarg || scol>rmarg) return(true); else if (c==c_SPACE) /* only if previous char is space and one before that isn't */ return(scol>lmarg+1 && *rp--==c_SPACE && *rp--!=c_SPACE); else if (alphmer(c)) return(!alphmer(*rp)); else return(true); /* always word boundary at punctuation */ } /************************************************************************ * * * find start of word back (left) or next (right) * * * ************************************************************************/ left_word(scol) int scol; { register int vcr = virt_c.row; char *rp = rowmap[vcr]; return(l_word(rp, scol, lmargin(vcr), rmargin(vcr))); } l_word(rp, scol, lmarg, rmarg) char *rp; register int scol; register int lmarg; register int rmarg; { if (scol<=lmarg) scol=lmarg; else if (scol>rmarg+1) scol=rmarg+1; else do scol--; while (!wordb(rp, scol, lmarg, rmarg)); return(scol); } right_word(scol) int scol; { register int vcr = virt_c.row, rgc = rightcol; char *rp = rowmap[vcr]; register int rw; rw = r_word(rp, scol, lmargin(vcr), rmargin(vcr)); if (rw>rgc && rp[rgc]==c_SPACE) rw=rgc; return(rw); } r_word(rp, scol, lmarg, rmarg) register char *rp; register int scol; int lmarg; register int rmarg; { if (scol>=rmarg) scol=rmarg+1; else if (scol