aboutsummaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@secunet.com>2011-07-07 15:41:53 +0200
committerStefan Reinauer <stefan.reinauer@coreboot.org>2011-08-04 08:10:41 +0200
commit3b77b723ca209199c8a224702812441e2196d452 (patch)
treecbf3be2c724139ec80a33dbf8e002b7871ef9307 /payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c
parent1ac19e28eed4f6c53a4f295eb55500c65fc80f8d (diff)
libpayload: Add PDCurses and ncurses' libform/libmenu
PDCurses provides an alternative implementation of the curses library standard in addition to tinycurses. Where tinycurses is really tiny, PDCurses is more complete and provides virtually unlimited windows and the full API. The PDCurses code is brought in "vanilla", with all local changes residing in curses/pdcurses-backend/ In addition to a curses library, this change also provides libpanel (as part of the PDCurses code), and libform and libmenu which were derived from ncurses-5.9. As they rely on ncurses internals (and PDCurses is not ncurses), more changes were required for these libraries to work. The build system is extended to install the right set of header files depending on the selected curses implementation. Change-Id: I9e5b920f94b6510da01da2f656196a993170d1c5 Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Reviewed-on: http://review.coreboot.org/106 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones <marcj303@gmail.com>
Diffstat (limited to 'payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c')
-rw-r--r--payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c b/payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c
new file mode 100644
index 0000000000..07b1a042ce
--- /dev/null
+++ b/payloads/libpayload/curses/PDCurses-3.4/x11/pdcscrn.c
@@ -0,0 +1,150 @@
+/* Public Domain Curses */
+
+#include "pdcx11.h"
+
+RCSID("$Id: pdcscrn.c,v 1.55 2008/07/14 04:24:52 wmcbrine Exp $")
+
+/* COLOR_PAIR to attribute encoding table. */
+
+short *xc_atrtab = (short *)NULL;
+
+/* close the physical screen */
+
+void PDC_scr_close(void)
+{
+ PDC_LOG(("PDC_scr_close() - called\n"));
+}
+
+void PDC_scr_free(void)
+{
+ XCursesExit();
+
+ xc_atrtab = (short *)NULL;
+}
+
+/* open the physical screen -- allocate SP, miscellaneous intialization */
+
+int PDC_scr_open(int argc, char **argv)
+{
+ extern bool sb_started;
+
+ PDC_LOG(("PDC_scr_open() - called\n"));
+
+ if ((XCursesInitscr(argc, argv) == ERR) || !SP)
+ return ERR;
+
+ SP->cursrow = SP->curscol = 0;
+ SP->orig_attr = FALSE;
+ SP->sb_on = sb_started;
+ SP->sb_total_y = 0;
+ SP->sb_viewport_y = 0;
+ SP->sb_cur_y = 0;
+ SP->sb_total_x = 0;
+ SP->sb_viewport_x = 0;
+ SP->sb_cur_x = 0;
+
+ return OK;
+}
+
+/* the core of resize_term() */
+
+int PDC_resize_screen(int nlines, int ncols)
+{
+ PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
+ nlines, ncols));
+
+ if (nlines || ncols || !SP->resized)
+ return ERR;
+
+ shmdt((char *)Xcurscr);
+ XCursesInstructAndWait(CURSES_RESIZE);
+
+ if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,
+ SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0)
+ {
+ perror("Cannot allocate shared memory for curscr");
+ kill(xc_otherpid, SIGKILL);
+ return ERR;
+ }
+
+ XCursesLINES = SP->lines;
+ XCursesCOLS = SP->cols;
+
+ PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d "
+ "SP->cols %d\n", XCLOGMSG, shmid_Xcurscr,
+ shmkey_Xcurscr, SP->lines, SP->cols));
+
+ Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0);
+ xc_atrtab = (short *)(Xcurscr + XCURSCR_ATRTAB_OFF);
+
+ SP->resized = FALSE;
+
+ return OK;
+}
+
+void PDC_reset_prog_mode(void)
+{
+ PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
+}
+
+void PDC_reset_shell_mode(void)
+{
+ PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
+}
+
+void PDC_restore_screen_mode(int i)
+{
+}
+
+void PDC_save_screen_mode(int i)
+{
+}
+
+void PDC_init_pair(short pair, short fg, short bg)
+{
+ xc_atrtab[pair * 2] = fg;
+ xc_atrtab[pair * 2 + 1] = bg;
+}
+
+int PDC_pair_content(short pair, short *fg, short *bg)
+{
+ *fg = xc_atrtab[pair * 2];
+ *bg = xc_atrtab[pair * 2 + 1];
+
+ return OK;
+}
+
+bool PDC_can_change_color(void)
+{
+ return TRUE;
+}
+
+int PDC_color_content(short color, short *red, short *green, short *blue)
+{
+ XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
+
+ tmp->pixel = color;
+
+ XCursesInstructAndWait(CURSES_GET_COLOR);
+
+ *red = ((double)(tmp->red) * 1000 / 65535) + 0.5;
+ *green = ((double)(tmp->green) * 1000 / 65535) + 0.5;
+ *blue = ((double)(tmp->blue) * 1000 / 65535) + 0.5;
+
+ return OK;
+}
+
+int PDC_init_color(short color, short red, short green, short blue)
+{
+ XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
+
+ tmp->pixel = color;
+
+ tmp->red = ((double)red * 65535 / 1000) + 0.5;
+ tmp->green = ((double)green * 65535 / 1000) + 0.5;
+ tmp->blue = ((double)blue * 65535 / 1000) + 0.5;
+
+ XCursesInstructAndWait(CURSES_SET_COLOR);
+
+ return OK;
+}