xref: /csrg-svn/lib/libcurses/insch.c (revision 56596)
122669Sdist /*
234677Sbostic  * Copyright (c) 1981 Regents of the University of California.
334677Sbostic  * All rights reserved.
434677Sbostic  *
542653Sbostic  * %sccs.include.redist.c%
622669Sdist  */
722669Sdist 
822669Sdist #ifndef lint
9*56596Selan static char sccsid[] = "@(#)insch.c	5.7 (Berkeley) 10/20/92";
1055964Sbostic #endif	/* not lint */
1122669Sdist 
1255964Sbostic #include <curses.h>
133532Sarnold 
143532Sarnold /*
1555964Sbostic  * winsch --
1655964Sbostic  *	Do an insert-char on the line, leaving (_cury,_curx) unchanged.
173532Sarnold  */
1855964Sbostic int
1955964Sbostic winsch(win, ch)
2055964Sbostic 	register WINDOW *win;
2155964Sbostic 	int ch;
2255964Sbostic {
233532Sarnold 
2455964Sbostic 	register char *end, *temp1, *temp2;
253532Sarnold 
2656238Selan 	end = &win->lines[win->cury]->line[win->curx];
2756238Selan 	temp1 = &win->lines[win->cury]->line[win->maxx - 1];
283532Sarnold 	temp2 = temp1 - 1;
29*56596Selan 	while (temp1 > end) {
30*56596Selan 		*temp1 = *temp2;
31*56596Selan 		/* standout array */
32*56596Selan 		*(temp1 + win->maxx) = *(temp2 + win->maxx);
33*56596Selan 		temp1--, temp2--;
34*56596Selan 	}
3555964Sbostic 	*temp1 = ch;
36*56596Selan 	*(temp1 + win->maxx) &= ~__STANDOUT;
3756238Selan 	touchline(win, win->cury, win->curx, win->maxx - 1);
3856238Selan 	if (win->cury == LINES - 1 &&
39*56596Selan 	    (win->lines[LINES - 1]->line[COLS - 1] != ' ' ||
40*56596Selan 	    win->lines[LINES -1]->standout[COLS - 1] & __STANDOUT))
4156238Selan 		if (win->flags & __SCROLLOK) {
423532Sarnold 			wrefresh(win);
433532Sarnold 			scroll(win);
4456238Selan 			win->cury--;
4555964Sbostic 		} else
4655964Sbostic 			return (ERR);
4755964Sbostic 	return (OK);
483532Sarnold }
49