summaryrefslogtreecommitdiff
path: root/usr/src/ucblib/libcurses/addch.c
diff options
context:
space:
mode:
authorstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
committerstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
commit7c478bd95313f5f23a4c958a745db2134aa03244 (patch)
treec871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/ucblib/libcurses/addch.c
downloadillumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz
OpenSolaris Launch
Diffstat (limited to 'usr/src/ucblib/libcurses/addch.c')
-rw-r--r--usr/src/ucblib/libcurses/addch.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/usr/src/ucblib/libcurses/addch.c b/usr/src/ucblib/libcurses/addch.c
new file mode 100644
index 0000000000..69259a02e3
--- /dev/null
+++ b/usr/src/ucblib/libcurses/addch.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#ifndef lint
+static char
+sccsid[] = "@(#)addch.c 1.6 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
+#endif /* not lint */
+
+#include "curses.ext"
+
+/* forward declaration */
+static void set_ch(WINDOW *, int, int, int);
+
+/*
+ * This routine adds the character to the current position
+ */
+
+int
+waddch(WINDOW *win, char c)
+{
+ int x, y;
+ int newx;
+
+ x = win->_curx;
+ y = win->_cury;
+#ifdef FULLDEBUG
+ fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x);
+#endif
+ switch (c) {
+ case '\t':
+ for (newx = x + (8 - (x & 07)); x < newx; x++)
+ if (waddch(win, ' ') == ERR)
+ return (ERR);
+ return (OK);
+
+ default:
+#ifdef FULLDEBUG
+ fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d,"
+ " lastch = %d\n", y, x, win->_firstch[y],
+ win->_lastch[y]);
+#endif
+ if (win->_flags & _STANDOUT)
+ c |= _STANDOUT;
+ set_ch(win, y, x, c);
+ win->_y[y][x++] = c;
+ if (x >= win->_maxx) {
+ x = 0;
+newline:
+ if (++y >= win->_maxy)
+ if (win->_scroll) {
+ (void) scroll(win);
+ --y;
+ }
+ else
+ return (ERR);
+ }
+#ifdef FULLDEBUG
+ fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d,"
+ " lastch = %d\n", y, x, win->_firstch[y],
+ win->_lastch[y]);
+#endif
+ break;
+ case '\n':
+ (void) wclrtoeol(win);
+ if (!NONL)
+ x = 0;
+ goto newline;
+ case '\r':
+ x = 0;
+ break;
+ case '\b':
+ if (--x < 0)
+ x = 0;
+ break;
+ }
+ win->_curx = (short)x;
+ win->_cury = (short)y;
+ return (OK);
+}
+
+/*
+ * set_ch:
+ * Set the first and last change flags for this window.
+ */
+
+static void
+set_ch(WINDOW *win, int y, int x, int ch)
+{
+#ifdef FULLDEBUG
+ fprintf(outf, "SET_CH(%0.2o, %d, %d)\n", win, y, x);
+#endif
+ if (win->_y[y][x] != ch) {
+ x += win->_ch_off;
+ if (win->_firstch[y] == _NOCHANGE)
+ win->_firstch[y] = win->_lastch[y] = (short)x;
+ else if (x < win->_firstch[y])
+ win->_firstch[y] = (short)x;
+ else if (x > win->_lastch[y])
+ win->_lastch[y] = (short)x;
+#ifdef FULLDEBUG
+ fprintf(outf, "SET_CH: change gives f/l: %d/%d [%d/%d]\n",
+ win->_firstch[y], win->_lastch[y],
+ win->_firstch[y] - win->_ch_off,
+ win->_lastch[y] - win->_ch_off);
+#endif
+ }
+}