diff options
Diffstat (limited to 'scripts/kconfig/libcurses/kernel.c')
| -rw-r--r-- | scripts/kconfig/libcurses/kernel.c | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/kernel.c b/scripts/kconfig/libcurses/kernel.c new file mode 100644 index 000000000..0f5a73c21 --- /dev/null +++ b/scripts/kconfig/libcurses/kernel.c | |||
| @@ -0,0 +1,299 @@ | |||
| 1 | /* PDCurses */ | ||
| 2 | |||
| 3 | #include "curspriv.h" | ||
| 4 | |||
| 5 | /*man-start************************************************************** | ||
| 6 | |||
| 7 | kernel | ||
| 8 | ------ | ||
| 9 | |||
| 10 | ### Synopsis | ||
| 11 | |||
| 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); | ||
| 21 | |||
| 22 | int draino(int ms); | ||
| 23 | int resetterm(void); | ||
| 24 | int fixterm(void); | ||
| 25 | int saveterm(void); | ||
| 26 | |||
| 27 | ### Description | ||
| 28 | |||
| 29 | def_prog_mode() and def_shell_mode() save the current terminal modes | ||
| 30 | as the "program" (in curses) or "shell" (not in curses) state for use | ||
| 31 | by the reset_prog_mode() and reset_shell_mode() functions. This is | ||
| 32 | done automatically by initscr(). | ||
| 33 | |||
| 34 | reset_prog_mode() and reset_shell_mode() restore the terminal to | ||
| 35 | "program" (in curses) or "shell" (not in curses) state. These are | ||
| 36 | done automatically by endwin() and doupdate() after an endwin(), so | ||
| 37 | they would normally not be called before these functions. | ||
| 38 | |||
| 39 | savetty() and resetty() save and restore the state of the terminal | ||
| 40 | modes. savetty() saves the current state in a buffer, and resetty() | ||
| 41 | restores the state to what it was at the last call to savetty(). | ||
| 42 | |||
| 43 | curs_set() alters the appearance of the cursor. A visibility of 0 | ||
| 44 | makes it disappear; 1 makes it appear "normal" (usually an underline) | ||
| 45 | and 2 makes it "highly visible" (usually a block). | ||
| 46 | |||
| 47 | ripoffline() reduces the size of stdscr by one line. If the "line" | ||
| 48 | parameter is positive, the line is removed from the top of the | ||
| 49 | screen; if negative, from the bottom. Up to 5 lines can be ripped off | ||
| 50 | stdscr by calling ripoffline() repeatedly. The function argument, | ||
| 51 | init, is called from within initscr() or newterm(), so ripoffline() | ||
| 52 | must be called before either of these functions. The init function | ||
| 53 | receives a pointer to a one-line WINDOW, and the width of the window. | ||
| 54 | Calling ripoffline() with a NULL init function pointer is an error. | ||
| 55 | |||
| 56 | napms() suspends the program for the specified number of | ||
| 57 | milliseconds. draino() is an archaic equivalent. Note that since | ||
| 58 | napms() attempts to give up a time slice and yield control back to | ||
| 59 | the OS, all times are approximate. (In DOS, the delay is actually | ||
| 60 | rounded down to 50ms (1/20th sec) intervals, with a minimum of one | ||
| 61 | interval; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms, etc.) | ||
| 62 | 0 returns immediately. | ||
| 63 | |||
| 64 | resetterm(), fixterm() and saveterm() are archaic equivalents for | ||
| 65 | reset_shell_mode(), reset_prog_mode() and def_prog_mode(), | ||
| 66 | respectively. | ||
| 67 | |||
| 68 | ### Return Value | ||
| 69 | |||
| 70 | All functions return OK on success and ERR on error, except | ||
| 71 | curs_set(), which returns the previous visibility. | ||
| 72 | |||
| 73 | ### Portability | ||
| 74 | |||
| 75 | Function | X/Open | ncurses | NetBSD | ||
| 76 | :---------------------|:------:|:-------:|:------: | ||
| 77 | def_prog_mode | Y | Y | Y | ||
| 78 | def_shell_mode | Y | Y | Y | ||
| 79 | reset_prog_mode | Y | Y | Y | ||
| 80 | reset_shell_mode | Y | Y | Y | ||
| 81 | resetty | Y | Y | Y | ||
| 82 | savetty | Y | Y | Y | ||
| 83 | ripoffline | Y | Y | Y | ||
| 84 | curs_set | Y | Y | Y | ||
| 85 | napms | Y | Y | Y | ||
| 86 | fixterm | - | Y | - | ||
| 87 | resetterm | - | Y | - | ||
| 88 | saveterm | - | Y | - | ||
| 89 | draino | - | - | - | ||
| 90 | |||
| 91 | **man-end****************************************************************/ | ||
| 92 | |||
| 93 | #include <string.h> | ||
| 94 | |||
| 95 | RIPPEDOFFLINE linesripped[5]; | ||
| 96 | char linesrippedoff = 0; | ||
| 97 | |||
| 98 | static struct cttyset | ||
| 99 | { | ||
| 100 | bool been_set; | ||
| 101 | SCREEN saved; | ||
| 102 | } ctty[3]; | ||
| 103 | |||
| 104 | enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY }; | ||
| 105 | |||
| 106 | static void _save_mode(int i) | ||
| 107 | { | ||
| 108 | ctty[i].been_set = TRUE; | ||
| 109 | |||
| 110 | memcpy(&(ctty[i].saved), SP, sizeof(SCREEN)); | ||
| 111 | |||
| 112 | PDC_save_screen_mode(i); | ||
| 113 | } | ||
| 114 | |||
| 115 | static int _restore_mode(int i) | ||
| 116 | { | ||
| 117 | if (ctty[i].been_set == TRUE) | ||
| 118 | { | ||
| 119 | memcpy(SP, &(ctty[i].saved), sizeof(SCREEN)); | ||
| 120 | |||
| 121 | if (ctty[i].saved.raw_out) | ||
| 122 | raw(); | ||
| 123 | |||
| 124 | PDC_restore_screen_mode(i); | ||
| 125 | |||
| 126 | if ((LINES != ctty[i].saved.lines) || | ||
| 127 | (COLS != ctty[i].saved.cols)) | ||
| 128 | resize_term(ctty[i].saved.lines, ctty[i].saved.cols); | ||
| 129 | |||
| 130 | PDC_curs_set(ctty[i].saved.visibility); | ||
| 131 | |||
| 132 | PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol); | ||
| 133 | } | ||
| 134 | |||
| 135 | return ctty[i].been_set ? OK : ERR; | ||
| 136 | } | ||
| 137 | |||
| 138 | int def_prog_mode(void) | ||
| 139 | { | ||
| 140 | PDC_LOG(("def_prog_mode() - called\n")); | ||
| 141 | |||
| 142 | if (!SP) | ||
| 143 | return ERR; | ||
| 144 | |||
| 145 | _save_mode(PDC_PR_TTY); | ||
| 146 | |||
| 147 | return OK; | ||
| 148 | } | ||
| 149 | |||
| 150 | int def_shell_mode(void) | ||
| 151 | { | ||
| 152 | PDC_LOG(("def_shell_mode() - called\n")); | ||
| 153 | |||
| 154 | if (!SP) | ||
| 155 | return ERR; | ||
| 156 | |||
| 157 | _save_mode(PDC_SH_TTY); | ||
| 158 | |||
| 159 | return OK; | ||
| 160 | } | ||
| 161 | |||
| 162 | int reset_prog_mode(void) | ||
| 163 | { | ||
| 164 | PDC_LOG(("reset_prog_mode() - called\n")); | ||
| 165 | |||
| 166 | if (!SP) | ||
| 167 | return ERR; | ||
| 168 | |||
| 169 | _restore_mode(PDC_PR_TTY); | ||
| 170 | PDC_reset_prog_mode(); | ||
| 171 | |||
| 172 | return OK; | ||
| 173 | } | ||
| 174 | |||
| 175 | int reset_shell_mode(void) | ||
| 176 | { | ||
| 177 | PDC_LOG(("reset_shell_mode() - called\n")); | ||
| 178 | |||
| 179 | if (!SP) | ||
| 180 | return ERR; | ||
| 181 | |||
| 182 | _restore_mode(PDC_SH_TTY); | ||
| 183 | PDC_reset_shell_mode(); | ||
| 184 | |||
| 185 | return OK; | ||
| 186 | } | ||
| 187 | |||
| 188 | int resetty(void) | ||
| 189 | { | ||
| 190 | PDC_LOG(("resetty() - called\n")); | ||
| 191 | |||
| 192 | if (!SP) | ||
| 193 | return ERR; | ||
| 194 | |||
| 195 | return _restore_mode(PDC_SAVE_TTY); | ||
| 196 | } | ||
| 197 | |||
| 198 | int savetty(void) | ||
| 199 | { | ||
| 200 | PDC_LOG(("savetty() - called\n")); | ||
| 201 | |||
| 202 | if (!SP) | ||
| 203 | return ERR; | ||
| 204 | |||
| 205 | _save_mode(PDC_SAVE_TTY); | ||
| 206 | |||
| 207 | return OK; | ||
| 208 | } | ||
| 209 | |||
| 210 | int curs_set(int visibility) | ||
| 211 | { | ||
| 212 | int ret_vis; | ||
| 213 | |||
| 214 | PDC_LOG(("curs_set() - called: visibility=%d\n", visibility)); | ||
| 215 | |||
| 216 | if (!SP || visibility < 0 || visibility > 2) | ||
| 217 | return ERR; | ||
| 218 | |||
| 219 | ret_vis = PDC_curs_set(visibility); | ||
| 220 | |||
| 221 | /* If the cursor is changing from invisible to visible, update | ||
| 222 | its position */ | ||
| 223 | |||
| 224 | if (visibility && !ret_vis) | ||
| 225 | PDC_gotoyx(SP->cursrow, SP->curscol); | ||
| 226 | |||
| 227 | return ret_vis; | ||
| 228 | } | ||
| 229 | |||
| 230 | int napms(int ms) | ||
| 231 | { | ||
| 232 | PDC_LOG(("napms() - called: ms=%d\n", ms)); | ||
| 233 | |||
| 234 | if (!SP) | ||
| 235 | return ERR; | ||
| 236 | |||
| 237 | if (SP->dirty) | ||
| 238 | { | ||
| 239 | int curs_state = SP->visibility; | ||
| 240 | bool leave_state = is_leaveok(curscr); | ||
| 241 | |||
| 242 | SP->dirty = FALSE; | ||
| 243 | |||
| 244 | leaveok(curscr, TRUE); | ||
| 245 | |||
| 246 | wrefresh(curscr); | ||
| 247 | |||
| 248 | leaveok(curscr, leave_state); | ||
| 249 | curs_set(curs_state); | ||
| 250 | } | ||
| 251 | |||
| 252 | if (ms) | ||
| 253 | PDC_napms(ms); | ||
| 254 | |||
| 255 | return OK; | ||
| 256 | } | ||
| 257 | |||
| 258 | int ripoffline(int line, int (*init)(WINDOW *, int)) | ||
| 259 | { | ||
| 260 | PDC_LOG(("ripoffline() - called: line=%d\n", line)); | ||
| 261 | |||
| 262 | if (linesrippedoff < 5 && line && init) | ||
| 263 | { | ||
| 264 | linesripped[(int)linesrippedoff].line = line; | ||
| 265 | linesripped[(int)linesrippedoff++].init = init; | ||
| 266 | |||
| 267 | return OK; | ||
| 268 | } | ||
| 269 | |||
| 270 | return ERR; | ||
| 271 | } | ||
| 272 | |||
| 273 | int draino(int ms) | ||
| 274 | { | ||
| 275 | PDC_LOG(("draino() - called\n")); | ||
| 276 | |||
| 277 | return napms(ms); | ||
| 278 | } | ||
| 279 | |||
| 280 | int resetterm(void) | ||
| 281 | { | ||
| 282 | PDC_LOG(("resetterm() - called\n")); | ||
| 283 | |||
| 284 | return reset_shell_mode(); | ||
| 285 | } | ||
| 286 | |||
| 287 | int fixterm(void) | ||
| 288 | { | ||
| 289 | PDC_LOG(("fixterm() - called\n")); | ||
| 290 | |||
| 291 | return reset_prog_mode(); | ||
| 292 | } | ||
| 293 | |||
| 294 | int saveterm(void) | ||
| 295 | { | ||
| 296 | PDC_LOG(("saveterm() - called\n")); | ||
| 297 | |||
| 298 | return def_prog_mode(); | ||
| 299 | } | ||
