xref: /csrg-svn/lib/libcurses/insch.c (revision 56647)
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*56647Selan static char sccsid[] = "@(#)insch.c	5.8 (Berkeley) 10/26/92";
1055964Sbostic #endif	/* not lint */
1122669Sdist 
1255964Sbostic #include <curses.h>
133532Sarnold 
143532Sarnold /*
1555964Sbostic  * winsch --
16*56647Selan  *	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 
24*56647Selan 	register __LDATA *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;
2956596Selan 	while (temp1 > end) {
30*56647Selan 		bcopy(temp2, temp1, sizeof(__LDATA));
3156596Selan 		temp1--, temp2--;
3256596Selan 	}
33*56647Selan 	temp1->ch = ch;
34*56647Selan 	temp1->attr &= ~__STANDOUT;
3556238Selan 	touchline(win, win->cury, win->curx, win->maxx - 1);
3656238Selan 	if (win->cury == LINES - 1 &&
37*56647Selan 	    (win->lines[LINES - 1]->line[COLS - 1].ch != ' ' ||
38*56647Selan 	    win->lines[LINES -1]->line[COLS - 1].attr != 0))
3956238Selan 		if (win->flags & __SCROLLOK) {
403532Sarnold 			wrefresh(win);
413532Sarnold 			scroll(win);
4256238Selan 			win->cury--;
4355964Sbostic 		} else
4455964Sbostic 			return (ERR);
4555964Sbostic 	return (OK);
463532Sarnold }
47