soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / kernel.c
blob1a2f8351255c4cb0a967c06a25da1650f913e174
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: kernel.c,v 1.78 2008/07/15 17:13:26 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: kernel
11 Synopsis:
12 int def_prog_mode(void);
13 int def_shell_mode(void);
14 int reset_prog_mode(void);
15 int reset_shell_mode(void);
16 int resetty(void);
17 int savetty(void);
18 int ripoffline(int line, int (*init)(WINDOW *, int));
19 int curs_set(int visibility);
20 int napms(int ms);
22 int draino(int ms);
23 int resetterm(void);
24 int fixterm(void);
25 int saveterm(void);
27 Description:
28 def_prog_mode() and def_shell_mode() save the current terminal
29 modes as the "program" (in curses) or "shell" (not in curses)
30 state for use by the reset_prog_mode() and reset_shell_mode()
31 functions. This is done automatically by initscr().
33 reset_prog_mode() and reset_shell_mode() restore the terminal to
34 "program" (in curses) or "shell" (not in curses) state. These
35 are done automatically by endwin() and doupdate() after an
36 endwin(), so they would normally not be called before these
37 functions.
39 savetty() and resetty() save and restore the state of the
40 terminal modes. savetty() saves the current state in a buffer,
41 and resetty() restores the state to what it was at the last call
42 to savetty().
44 curs_set() alters the appearance of the cursor. A visibility of
45 0 makes it disappear; 1 makes it appear "normal" (usually an
46 underline) and 2 makes it "highly visible" (usually a block).
48 ripoffline() reduces the size of stdscr by one line. If the
49 "line" parameter is positive, the line is removed from the top
50 of the screen; if negative, from the bottom. Up to 5 lines can
51 be ripped off stdscr by calling ripoffline() repeatedly. The
52 function argument, init, is called from within initscr() or
53 newterm(), so ripoffline() must be called before either of these
54 functions. The init function receives a pointer to a one-line
55 WINDOW, and the width of the window. Calling ripoffline() with a
56 NULL init function pointer is an error.
58 napms() suspends the program for the specified number of
59 milliseconds. draino() is an archaic equivalent.
61 resetterm(), fixterm() and saveterm() are archaic equivalents
62 for reset_shell_mode(), reset_prog_mode() and def_prog_mode(),
63 respectively.
65 Return Value:
66 All functions return OK on success and ERR on error, except
67 curs_set(), which returns the previous visibility.
69 Portability X/Open BSD SYS V
70 def_prog_mode Y Y Y
71 def_shell_mode Y Y Y
72 reset_prog_mode Y Y Y
73 reset_shell_mode Y Y Y
74 resetty Y Y Y
75 savetty Y Y Y
76 ripoffline Y - 3.0
77 curs_set Y - 3.0
78 napms Y Y Y
79 draino -
80 resetterm -
81 fixterm -
82 saveterm -
84 **man-end****************************************************************/
86 #include <string.h>
88 RIPPEDOFFLINE linesripped[5];
89 char linesrippedoff = 0;
91 static struct cttyset
93 bool been_set;
94 SCREEN saved;
95 } ctty[3];
97 enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY };
99 static void _save_mode(int i)
101 ctty[i].been_set = TRUE;
103 memcpy(&(ctty[i].saved), SP, sizeof(SCREEN));
105 PDC_save_screen_mode(i);
108 static int _restore_mode(int i)
110 if (ctty[i].been_set == TRUE)
112 memcpy(SP, &(ctty[i].saved), sizeof(SCREEN));
114 if (ctty[i].saved.raw_out)
115 raw();
117 PDC_restore_screen_mode(i);
119 if ((LINES != ctty[i].saved.lines) ||
120 (COLS != ctty[i].saved.cols))
121 resize_term(ctty[i].saved.lines, ctty[i].saved.cols);
123 PDC_curs_set(ctty[i].saved.visibility);
125 PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol);
128 return ctty[i].been_set ? OK : ERR;
131 int def_prog_mode(void)
133 PDC_LOG(("def_prog_mode() - called\n"));
135 _save_mode(PDC_PR_TTY);
137 return OK;
140 int def_shell_mode(void)
142 PDC_LOG(("def_shell_mode() - called\n"));
144 _save_mode(PDC_SH_TTY);
146 return OK;
149 int reset_prog_mode(void)
151 PDC_LOG(("reset_prog_mode() - called\n"));
153 _restore_mode(PDC_PR_TTY);
154 PDC_reset_prog_mode();
156 return OK;
159 int reset_shell_mode(void)
161 PDC_LOG(("reset_shell_mode() - called\n"));
163 _restore_mode(PDC_SH_TTY);
164 PDC_reset_shell_mode();
166 return OK;
169 int resetty(void)
171 PDC_LOG(("resetty() - called\n"));
173 return _restore_mode(PDC_SAVE_TTY);
176 int savetty(void)
178 PDC_LOG(("savetty() - called\n"));
180 _save_mode(PDC_SAVE_TTY);
182 return OK;
185 int curs_set(int visibility)
187 int ret_vis;
189 PDC_LOG(("curs_set() - called: visibility=%d\n", visibility));
191 if ((visibility < 0) || (visibility > 2))
192 return ERR;
194 ret_vis = PDC_curs_set(visibility);
196 /* If the cursor is changing from invisible to visible, update
197 its position */
199 if (visibility && !ret_vis)
200 PDC_gotoyx(SP->cursrow, SP->curscol);
202 return ret_vis;
205 int napms(int ms)
207 PDC_LOG(("napms() - called: ms=%d\n", ms));
209 if (ms)
210 PDC_napms(ms);
212 return OK;
215 int ripoffline(int line, int (*init)(WINDOW *, int))
217 PDC_LOG(("ripoffline() - called: line=%d\n", line));
219 if (linesrippedoff < 5 && line && init)
221 linesripped[(int)linesrippedoff].line = line;
222 linesripped[(int)linesrippedoff++].init = init;
224 return OK;
227 return ERR;
230 int draino(int ms)
232 PDC_LOG(("draino() - called\n"));
234 return napms(ms);
237 int resetterm(void)
239 PDC_LOG(("resetterm() - called\n"));
241 return reset_shell_mode();
244 int fixterm(void)
246 PDC_LOG(("fixterm() - called\n"));
248 return reset_prog_mode();
251 int saveterm(void)
253 PDC_LOG(("saveterm() - called\n"));
255 return def_prog_mode();