libpayload: remove trailing whitespace and run dos2unix
[coreboot.git] / payloads / libpayload / curses / PDCurses-3.4 / x11 / pdcscrn.c
1 /* Public Domain Curses */
2
3 #include "pdcx11.h"
4
5 RCSID("$Id: pdcscrn.c,v 1.55 2008/07/14 04:24:52 wmcbrine Exp $")
6
7 /* COLOR_PAIR to attribute encoding table. */
8
9 short *xc_atrtab = (short *)NULL;
10
11 /* close the physical screen */
12
13 void PDC_scr_close(void)
14 {
15     PDC_LOG(("PDC_scr_close() - called\n"));
16 }
17
18 void PDC_scr_free(void)
19 {
20     XCursesExit();
21
22     xc_atrtab = (short *)NULL;
23 }
24
25 /* open the physical screen -- allocate SP, miscellaneous intialization */
26
27 int PDC_scr_open(int argc, char **argv)
28 {
29     extern bool sb_started;
30
31     PDC_LOG(("PDC_scr_open() - called\n"));
32
33     if ((XCursesInitscr(argc, argv) == ERR) || !SP)
34         return ERR;
35
36     SP->cursrow = SP->curscol = 0;
37     SP->orig_attr = FALSE;
38     SP->sb_on = sb_started;
39     SP->sb_total_y = 0;
40     SP->sb_viewport_y = 0;
41     SP->sb_cur_y = 0;
42     SP->sb_total_x = 0;
43     SP->sb_viewport_x = 0;
44     SP->sb_cur_x = 0;
45
46     return OK;
47 }
48
49 /* the core of resize_term() */
50
51 int PDC_resize_screen(int nlines, int ncols)
52 {
53     PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
54              nlines, ncols));
55
56     if (nlines || ncols || !SP->resized)
57         return ERR;
58
59     shmdt((char *)Xcurscr);
60     XCursesInstructAndWait(CURSES_RESIZE);
61
62     if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,
63         SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0)
64     {
65         perror("Cannot allocate shared memory for curscr");
66         kill(xc_otherpid, SIGKILL);
67         return ERR;
68     }
69
70     XCursesLINES = SP->lines;
71     XCursesCOLS = SP->cols;
72
73     PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d "
74              "SP->cols %d\n", XCLOGMSG, shmid_Xcurscr,
75              shmkey_Xcurscr, SP->lines, SP->cols));
76
77     Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0);
78     xc_atrtab = (short *)(Xcurscr + XCURSCR_ATRTAB_OFF);
79
80     SP->resized = FALSE;
81
82     return OK;
83 }
84
85 void PDC_reset_prog_mode(void)
86 {
87     PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
88 }
89
90 void PDC_reset_shell_mode(void)
91 {
92     PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
93 }
94
95 void PDC_restore_screen_mode(int i)
96 {
97 }
98
99 void PDC_save_screen_mode(int i)
100 {
101 }
102
103 void PDC_init_pair(short pair, short fg, short bg)
104 {
105     xc_atrtab[pair * 2] = fg;
106     xc_atrtab[pair * 2 + 1] = bg;
107 }
108
109 int PDC_pair_content(short pair, short *fg, short *bg)
110 {
111     *fg = xc_atrtab[pair * 2];
112     *bg = xc_atrtab[pair * 2 + 1];
113
114     return OK;
115 }
116
117 bool PDC_can_change_color(void)
118 {
119     return TRUE;
120 }
121
122 int PDC_color_content(short color, short *red, short *green, short *blue)
123 {
124     XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
125
126     tmp->pixel = color;
127
128     XCursesInstructAndWait(CURSES_GET_COLOR);
129
130     *red = ((double)(tmp->red) * 1000 / 65535) + 0.5;
131     *green = ((double)(tmp->green) * 1000 / 65535) + 0.5;
132     *blue = ((double)(tmp->blue) * 1000 / 65535) + 0.5;
133
134     return OK;
135 }
136
137 int PDC_init_color(short color, short red, short green, short blue)
138 {
139     XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);
140
141     tmp->pixel = color;
142
143     tmp->red = ((double)red * 65535 / 1000) + 0.5;
144     tmp->green = ((double)green * 65535 / 1000) + 0.5;
145     tmp->blue = ((double)blue * 65535 / 1000) + 0.5;
146
147     XCursesInstructAndWait(CURSES_SET_COLOR);
148
149     return OK;
150 }