--startSCol; --ptr; if (startSCol <= 0 && ScrnTstWrapped(screen, startSRow - 1)) { --startSRow; startSCol = LastTextCol(startSRow); ptr = SCRN_BUF_CHARS(screen, startSRow+screen->topline) + startSCol; }
--startSCol; if (startSCol <= 0 && ScrnTstWrapped(screen, startSRow - 1)) { --startSRow; startSCol = LastTextCol(startSRow); }
ComputeSelect(	int startRow,	int startCol,	int endRow,	int endCol,	Bool extend){	register TScreen *screen = &term->screen;	register Char *ptr;	register int length;	register int cclass;	if (Coordinate(startRow, startCol) <= Coordinate(endRow, endCol)) {		startSRow = startRRow = startRow;		startSCol = startRCol = startCol;		endSRow   = endRRow   = endRow;		endSCol   = endRCol   = endCol;	} else {	/* Swap them */		startSRow = startRRow = endRow;		startSCol = startRCol = endCol;		endSRow   = endRRow   = startRow;		endSCol   = endRCol   = startCol;	}	switch (selectUnit) {		case SELECTCHAR :			if (startSCol > (LastTextCol(startSRow) + 1)) {				startSCol = 0;				startSRow++;			}			if (endSCol > (LastTextCol(endSRow) + 1)) {				endSCol = 0;				endSRow++;			}			break;		case SELECTWORD :			if (startSCol > (LastTextCol(startSRow) + 1)) {				startSCol = 0;				startSRow++;			} else {				ptr = SCRN_BUF_CHARS(screen, startSRow+screen->topline)				 + startSCol;				cclass = charClass[*ptr];				do {					--startSCol;					--ptr;					if (startSCol <= 0					    && ScrnTstWrapped(screen, startSRow - 1)) {						--startSRow;						startSCol = LastTextCol(startSRow);						ptr = SCRN_BUF_CHARS(screen, startSRow+screen->topline)						 + startSCol;					}				} while (startSCol >= 0				 && charClass[*ptr] == cclass);				++startSCol;			}			if (endSCol > (LastTextCol(endSRow) + 1)) {				endSCol = 0;				endSRow++;			} else {				length = LastTextCol(endSRow);				ptr = SCRN_BUF_CHARS(screen, endSRow+screen->topline)				 + endSCol;				cclass = charClass[*ptr];				do {					++endSCol;					++ptr;					if (endSCol > length					    && ScrnTstWrapped(screen, endSRow)) {						endSCol = 0;						++endSRow;						length = LastTextCol(endSRow);						ptr = SCRN_BUF_CHARS(screen, endSRow+screen->topline)						 + endSCol;					}				} while (endSCol <= length				 && charClass[*ptr] == cclass);				/* Word select selects if pointing to any char				   in "word", especially in that it includes				   the last character in a word.  So no --endSCol				   and do special eol handling */				if (endSCol > length+1) {					endSCol = 0;					++endSRow;				}			}			saveStartWRow = startSRow;			saveStartWCol = startSCol;			break;		case SELECTLINE :			while (ScrnTstWrapped(screen, endSRow)) {				++endSRow;			}			if (term->screen.cutToBeginningOfLine			    || startSRow < saveStartWRow) {			    startSCol = 0;			    while (ScrnTstWrapped(screen, startSRow - 1)) {				--startSRow;			    }			} else if (!extend) {			    if ((startRow < saveStartWRow)				|| (startRow == saveStartWRow				    && startCol < saveStartWCol)) {				startSCol = 0;				while (ScrnTstWrapped(screen, startSRow - 1)) {				    --startSRow;				}			    } else {				startSRow = saveStartWRow;				startSCol = saveStartWCol;			    }			}			if (term->screen.cutNewline) {			    endSCol = 0;			    ++endSRow;			} else {			    endSCol = LastTextCol(endSRow) + 1;			}			break;	}	TrackText(startSRow, startSCol, endSRow, endSCol);	return;}