]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_set_term.c
ncurses 5.7 - patch 20090912
[ncurses.git] / ncurses / base / lib_set_term.c
1 /****************************************************************************
2  * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Thomas E. Dickey                        1996-on                 *
33  *     and: Juergen Pfeifer                         2009                    *
34  ****************************************************************************/
35
36 /*
37 **      lib_set_term.c
38 **
39 **      The routine set_term().
40 **
41 */
42
43 #include <curses.priv.h>
44
45 #include <tic.h>
46
47 #ifndef CUR
48 #define CUR SP_TERMTYPE
49 #endif
50
51 MODULE_ID("$Id: lib_set_term.c,v 1.126 2009/09/05 18:18:10 tom Exp $")
52
53 #ifdef USE_TERM_DRIVER
54 #define MaxColors      InfoOf(sp).maxcolors
55 #define NumLabels      InfoOf(sp).numlabels
56 #else
57 #define MaxColors      max_colors
58 #define NumLabels      num_labels
59 #endif
60
61 NCURSES_EXPORT(SCREEN *)
62 set_term(SCREEN *screenp)
63 {
64     SCREEN *oldSP;
65     SCREEN *newSP;
66
67     T((T_CALLED("set_term(%p)"), screenp));
68
69     _nc_lock_global(curses);
70
71     oldSP = SP;
72     _nc_set_screen(screenp);
73     newSP = SP;
74
75     if (newSP != 0) {
76         TINFO_SET_CURTERM(newSP, newSP->_term);
77 #if !USE_REENTRANT
78         curscr = newSP->_curscr;
79         newscr = newSP->_newscr;
80         stdscr = newSP->_stdscr;
81         COLORS = newSP->_color_count;
82         COLOR_PAIRS = newSP->_pair_count;
83 #endif
84     } else {
85         TINFO_SET_CURTERM(oldSP, 0);
86 #if !USE_REENTRANT
87         curscr = 0;
88         newscr = 0;
89         stdscr = 0;
90         COLORS = 0;
91         COLOR_PAIRS = 0;
92 #endif
93     }
94
95     _nc_unlock_global(curses);
96
97     T((T_RETURN("%p"), oldSP));
98     return (oldSP);
99 }
100
101 static void
102 _nc_free_keytry(TRIES * kt)
103 {
104     if (kt != 0) {
105         _nc_free_keytry(kt->child);
106         _nc_free_keytry(kt->sibling);
107         free(kt);
108     }
109 }
110
111 static bool
112 delink_screen(SCREEN *sp)
113 {
114     SCREEN *last = 0;
115     SCREEN *temp;
116     bool result = FALSE;
117
118     for (each_screen(temp)) {
119         if (temp == sp) {
120             if (last)
121                 last = sp->_next_screen;
122             else
123                 _nc_screen_chain = sp->_next_screen;
124             result = TRUE;
125             break;
126         }
127         last = temp;
128     }
129     return result;
130 }
131
132 /*
133  * Free the storage associated with the given SCREEN sp.
134  */
135 NCURSES_EXPORT(void)
136 delscreen(SCREEN *sp)
137 {
138     int i;
139
140     T((T_CALLED("delscreen(%p)"), sp));
141
142     _nc_lock_global(curses);
143     if (delink_screen(sp)) {
144 #ifdef USE_SP_RIPOFF
145         ripoff_t *rop;
146         if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
147             for (rop = safe_ripoff_stack;
148                  rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
149                  rop++) {
150                 if (rop->win) {
151                     (void) delwin(rop->win);
152                     rop->win = 0;
153                 }
154             }
155         }
156 #endif
157
158         (void) _nc_freewin(sp->_curscr);
159         (void) _nc_freewin(sp->_newscr);
160         (void) _nc_freewin(sp->_stdscr);
161
162         if (sp->_slk != 0) {
163             if (sp->_slk->ent != 0) {
164                 for (i = 0; i < sp->_slk->labcnt; ++i) {
165                     FreeIfNeeded(sp->_slk->ent[i].ent_text);
166                     FreeIfNeeded(sp->_slk->ent[i].form_text);
167                 }
168                 free(sp->_slk->ent);
169             }
170             free(sp->_slk);
171             sp->_slk = 0;
172         }
173
174         _nc_free_keytry(sp->_keytry);
175         sp->_keytry = 0;
176
177         _nc_free_keytry(sp->_key_ok);
178         sp->_key_ok = 0;
179
180         FreeIfNeeded(sp->_current_attr);
181
182         FreeIfNeeded(sp->_color_table);
183         FreeIfNeeded(sp->_color_pairs);
184
185         FreeIfNeeded(sp->oldhash);
186         FreeIfNeeded(sp->newhash);
187         FreeIfNeeded(sp->hashtab);
188
189         FreeIfNeeded(sp->_acs_map);
190         FreeIfNeeded(sp->_screen_acs_map);
191
192         /*
193          * If the associated output stream has been closed, we can discard the
194          * set-buffer.  Limit the error check to EBADF, since fflush may fail
195          * for other reasons than trying to operate upon a closed stream.
196          */
197         if (sp->_ofp != 0
198             && sp->_setbuf != 0
199             && fflush(sp->_ofp) != 0
200             && errno == EBADF) {
201             free(sp->_setbuf);
202         }
203
204         NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term);
205         free(sp);
206
207         /*
208          * If this was the current screen, reset everything that the
209          * application might try to use (except cur_term, which may have
210          * multiple references in different screens).
211          */
212         if (sp == SP) {
213 #if !USE_REENTRANT
214             curscr = 0;
215             newscr = 0;
216             stdscr = 0;
217             COLORS = 0;
218             COLOR_PAIRS = 0;
219 #endif
220             _nc_set_screen(0);
221         }
222     }
223     _nc_unlock_global(curses);
224
225     returnVoid;
226 }
227
228 static bool
229 no_mouse_event(SCREEN *sp GCC_UNUSED)
230 {
231     return FALSE;
232 }
233
234 static bool
235 no_mouse_inline(SCREEN *sp GCC_UNUSED)
236 {
237     return FALSE;
238 }
239
240 static bool
241 no_mouse_parse(SCREEN *sp GCC_UNUSED, int code GCC_UNUSED)
242 {
243     return TRUE;
244 }
245
246 static void
247 no_mouse_resume(SCREEN *sp GCC_UNUSED)
248 {
249 }
250
251 static void
252 no_mouse_wrap(SCREEN *sp GCC_UNUSED)
253 {
254 }
255
256 #if NCURSES_EXT_FUNCS && USE_COLORFGBG
257 static char *
258 extract_fgbg(char *src, int *result)
259 {
260     char *dst = 0;
261     long value = strtol(src, &dst, 0);
262
263     if (dst == 0) {
264         dst = src;
265     } else if (value >= 0) {
266         *result = value;
267     }
268     while (*dst != 0 && *dst != ';')
269         dst++;
270     if (*dst == ';')
271         dst++;
272     return dst;
273 }
274 #endif
275
276 #if NCURSES_SP_FUNCS
277 /*
278  * In case of handling multiple screens, we need to have a screen before
279  * initialization in setupscreen takes place.  This is to extend the substitute
280  * for some of the stuff in _nc_prescreen, especially for slk and ripoff
281  * handling which should be done per screen.
282  */
283 NCURSES_EXPORT(SCREEN *)
284 new_prescr(void)
285 {
286     SCREEN *sp = _nc_alloc_screen_sp();
287     if (sp) {
288         sp->rsp = sp->rippedoff;
289         sp->_filtered = _nc_prescreen.filter_mode;
290         sp->_use_env = _nc_prescreen.use_env;
291 #if NCURSES_NO_PADDING
292         sp->_no_padding = _nc_prescreen._no_padding;
293 #endif
294         sp->slk_format = 0;
295         sp->_slk = 0;
296         sp->_prescreen = TRUE;
297         SP_PRE_INIT(sp);
298 #if USE_REENTRANT
299         sp->_TABSIZE = _nc_prescreen._TABSIZE;
300         sp->_ESCDELAY = _nc_prescreen._ESCDELAY;
301 #endif
302         _nc_set_screen(sp);
303     }
304     return sp;
305 }
306 #endif
307
308 #define ReturnScreenError() _nc_set_screen(0); \
309                             returnCode(ERR)
310
311 /* OS-independent screen initializations */
312 NCURSES_EXPORT(int)
313 _nc_setupscreen(int slines GCC_UNUSED,
314                 int scolumns GCC_UNUSED,
315                 FILE *output,
316                 bool filtered,
317                 int slk_format)
318 {
319 #if NCURSES_SP_FUNCS
320     SCREEN *sp = CURRENT_SCREEN;
321 #endif
322     char *env;
323     int bottom_stolen = 0;
324     bool support_cookies = USE_XMC_SUPPORT;
325     ripoff_t *rop;
326
327     T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
328        slines, scolumns, output, filtered, slk_format));
329
330     assert(SP == 0);            /* has been reset in newterm() ! */
331     if (!_nc_alloc_screen()
332         || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
333         || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
334         returnCode(ERR);
335     }
336
337     T(("created SP %p", SP));
338 #if NCURSES_SP_FUNCS
339     sp = SP;                    /* fixup so SET_LINES and SET_COLS works */
340 #endif
341     SP->_next_screen = _nc_screen_chain;
342     _nc_screen_chain = SP;
343
344     if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
345         returnCode(ERR);
346
347     /*
348      * We should always check the screensize, just in case.
349      */
350     _nc_get_screensize(SP, &slines, &scolumns);
351     SET_LINES(slines);
352     SET_COLS(scolumns);
353     T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
354
355     SP->_filtered = filtered;
356
357     /* implement filter mode */
358     if (filtered) {
359         slines = 1;
360         SET_LINES(slines);
361 #ifdef USE_TERM_DRIVER
362         CallDriver(sp, setfilter);
363 #else
364         clear_screen = 0;
365         cursor_down = parm_down_cursor = 0;
366         cursor_address = 0;
367         cursor_up = parm_up_cursor = 0;
368         row_address = 0;
369
370         cursor_home = carriage_return;
371 #endif
372         T(("filter screensize %dx%d", LINES, COLS));
373     }
374 #ifdef __DJGPP__
375     T(("setting output mode to binary"));
376     fflush(output);
377     setmode(output, O_BINARY);
378 #endif
379     _nc_set_buffer(output, TRUE);
380     SP->_term = cur_term;
381     SP->_lines = slines;
382     SP->_lines_avail = slines;
383     SP->_columns = scolumns;
384     SP->_cursrow = -1;
385     SP->_curscol = -1;
386     SP->_nl = TRUE;
387     SP->_raw = FALSE;
388     SP->_cbreak = 0;
389     SP->_echo = TRUE;
390     SP->_fifohead = -1;
391     SP->_endwin = TRUE;
392     SP->_ofp = output;
393     SP->_cursor = -1;           /* cannot know real cursor shape */
394
395     SetNoPadding(SP);
396
397 #if NCURSES_EXT_FUNCS
398     SP->_default_color = FALSE;
399     SP->_has_sgr_39_49 = FALSE;
400
401     /*
402      * Set our assumption of the terminal's default foreground and background
403      * colors.  The curs_color man-page states that we can assume that the
404      * background is black.  The origin of this assumption appears to be
405      * terminals that displayed colored text, but no colored backgrounds, e.g.,
406      * the first colored terminals around 1980.  More recent ones with better
407      * technology can display not only colored backgrounds, but all
408      * combinations.  So a terminal might be something other than "white" on
409      * black (green/black looks monochrome too), but black on white or even
410      * on ivory.
411      *
412      * White-on-black is the simplest thing to use for monochrome.  Almost
413      * all applications that use color paint both text and background, so
414      * the distinction is moot.  But a few do not - which is why we leave this
415      * configurable (a better solution is to use assume_default_colors() for
416      * the rare applications that do require that sort of appearance, since
417      * is appears that more users expect to be able to make a white-on-black
418      * or black-on-white display under control of the application than not).
419      */
420 #ifdef USE_ASSUMED_COLOR
421     SP->_default_fg = COLOR_WHITE;
422     SP->_default_bg = COLOR_BLACK;
423 #else
424     SP->_default_fg = C_MASK;
425     SP->_default_bg = C_MASK;
426 #endif
427
428     /*
429      * Allow those assumed/default color assumptions to be overridden at
430      * runtime:
431      */
432     if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) {
433         int fg, bg;
434         char sep1, sep2;
435         int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
436         if (count >= 1) {
437             SP->_default_fg = (fg >= 0 && fg < MaxColors) ? fg : C_MASK;
438             if (count >= 3) {
439                 SP->_default_bg = (bg >= 0 && bg < MaxColors) ? bg : C_MASK;
440             }
441             TR(TRACE_CHARPUT | TRACE_MOVE,
442                ("from environment assumed fg=%d, bg=%d",
443                 SP->_default_fg,
444                 SP->_default_bg));
445         }
446     }
447 #if USE_COLORFGBG
448     /*
449      * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
450      * default colors.  Note that rxvt (mis)uses bold colors, equating a bold
451      * color to that value plus 8.  We'll only use the non-bold color for now -
452      * decide later if it is worth having default attributes as well.
453      */
454     if (getenv("COLORFGBG") != 0) {
455         char *p = getenv("COLORFGBG");
456         TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p));
457         p = extract_fgbg(p, &(SP->_default_fg));
458         p = extract_fgbg(p, &(SP->_default_bg));
459         if (*p)                 /* assume rxvt was compiled with xpm support */
460             p = extract_fgbg(p, &(SP->_default_bg));
461         TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
462                                         SP->_default_fg, SP->_default_bg));
463         if (SP->_default_fg >= MaxColors) {
464             if (set_a_foreground != ABSENT_STRING
465                 && !strcmp(set_a_foreground, "\033[3%p1%dm")) {
466                 set_a_foreground = "\033[3%?%p1%{8}%>%t9%e%p1%d%;m";
467             } else {
468                 SP->_default_fg %= MaxColors;
469             }
470         }
471         if (SP->_default_bg >= MaxColors) {
472             if (set_a_background != ABSENT_STRING
473                 && !strcmp(set_a_background, "\033[4%p1%dm")) {
474                 set_a_background = "\033[4%?%p1%{8}%>%t9%e%p1%d%;m";
475             } else {
476                 SP->_default_bg %= MaxColors;
477             }
478         }
479     }
480 #endif
481 #endif /* NCURSES_EXT_FUNCS */
482
483     SP->_maxclick = DEFAULT_MAXCLICK;
484     SP->_mouse_event = no_mouse_event;
485     SP->_mouse_inline = no_mouse_inline;
486     SP->_mouse_parse = no_mouse_parse;
487     SP->_mouse_resume = no_mouse_resume;
488     SP->_mouse_wrap = no_mouse_wrap;
489     SP->_mouse_fd = -1;
490
491     /*
492      * If we've no magic cookie support, we suppress attributes that xmc would
493      * affect, i.e., the attributes that affect the rendition of a space.
494      */
495     SP->_ok_attributes = termattrs();
496     if (has_colors()) {
497         SP->_ok_attributes |= A_COLOR;
498     }
499 #if USE_XMC_SUPPORT
500     /*
501      * If we have no magic-cookie support compiled-in, or if it is suppressed
502      * in the environment, reset the support-flag.
503      */
504     if (magic_cookie_glitch >= 0) {
505         if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
506             support_cookies = FALSE;
507         }
508     }
509 #endif
510
511     if (!support_cookies && magic_cookie_glitch >= 0) {
512         T(("will disable attributes to work w/o magic cookies"));
513     }
514
515     if (magic_cookie_glitch > 0) {      /* tvi, wyse */
516
517         SP->_xmc_triggers = SP->_ok_attributes & (
518                                                      A_STANDOUT |
519                                                      A_UNDERLINE |
520                                                      A_REVERSE |
521                                                      A_BLINK |
522                                                      A_DIM |
523                                                      A_BOLD |
524                                                      A_INVIS |
525                                                      A_PROTECT
526             );
527 #if 0
528         /*
529          * We "should" treat colors as an attribute.  The wyse350 (and its
530          * clones) appear to be the only ones that have both colors and magic
531          * cookies.
532          */
533         if (has_colors()) {
534             SP->_xmc_triggers |= A_COLOR;
535         }
536 #endif
537         SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD);
538
539         T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
540         /*
541          * Supporting line-drawing may be possible.  But make the regular
542          * video attributes work first.
543          */
544         acs_chars = ABSENT_STRING;
545         ena_acs = ABSENT_STRING;
546         enter_alt_charset_mode = ABSENT_STRING;
547         exit_alt_charset_mode = ABSENT_STRING;
548 #if USE_XMC_SUPPORT
549         /*
550          * To keep the cookie support simple, suppress all of the optimization
551          * hooks except for clear_screen and the cursor addressing.
552          */
553         if (support_cookies) {
554             clr_eol = ABSENT_STRING;
555             clr_eos = ABSENT_STRING;
556             set_attributes = ABSENT_STRING;
557         }
558 #endif
559     } else if (magic_cookie_glitch == 0) {      /* hpterm */
560     }
561
562     /*
563      * If magic cookies are not supported, cancel the strings that set
564      * video attributes.
565      */
566     if (!support_cookies && magic_cookie_glitch >= 0) {
567         magic_cookie_glitch = ABSENT_NUMERIC;
568         set_attributes = ABSENT_STRING;
569         enter_blink_mode = ABSENT_STRING;
570         enter_bold_mode = ABSENT_STRING;
571         enter_dim_mode = ABSENT_STRING;
572         enter_reverse_mode = ABSENT_STRING;
573         enter_standout_mode = ABSENT_STRING;
574         enter_underline_mode = ABSENT_STRING;
575     }
576
577     /* initialize normal acs before wide, since we use mapping in the latter */
578 #if !USE_WIDEC_SUPPORT
579     if (_nc_unicode_locale() && _nc_locale_breaks_acs(cur_term)) {
580         acs_chars = NULL;
581         ena_acs = NULL;
582         enter_alt_charset_mode = NULL;
583         exit_alt_charset_mode = NULL;
584         set_attributes = NULL;
585     }
586 #endif
587     _nc_init_acs();
588 #if USE_WIDEC_SUPPORT
589     _nc_init_wacs();
590
591     SP->_screen_acs_fix = (_nc_unicode_locale()
592                            && _nc_locale_breaks_acs(cur_term));
593 #endif
594     env = _nc_get_locale();
595     SP->_legacy_coding = ((env == 0)
596                           || !strcmp(env, "C")
597                           || !strcmp(env, "POSIX"));
598     T(("legacy-coding %d", SP->_legacy_coding));
599
600     _nc_idcok = TRUE;
601     _nc_idlok = FALSE;
602
603     SP->oldhash = 0;
604     SP->newhash = 0;
605
606     T(("creating newscr"));
607     if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
608         returnCode(ERR);
609
610     T(("creating curscr"));
611     if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
612         returnCode(ERR);
613
614 #if !USE_REENTRANT
615     newscr = SP->_newscr;
616     curscr = SP->_curscr;
617 #endif
618 #if USE_SIZECHANGE
619     SP->_resize = NCURSES_SP_NAME(resizeterm);
620 #endif
621
622     newscr->_clear = TRUE;
623     curscr->_clear = FALSE;
624
625     def_shell_mode();
626     def_prog_mode();
627
628     for (rop = safe_ripoff_stack;
629          rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
630          rop++) {
631
632         /* If we must simulate soft labels, grab off the line to be used.
633            We assume that we must simulate, if it is none of the standard
634            formats (4-4 or 3-2-3) for which there may be some hardware
635            support. */
636         if (rop->hook == _nc_slk_initialize)
637             if (!(NumLabels <= 0 || !SLK_STDFMT(slk_format)))
638                 continue;
639         if (rop->hook) {
640             int count;
641             WINDOW *w;
642
643             count = (rop->line < 0) ? -rop->line : rop->line;
644             T(("ripping off %i lines at %s", count,
645                ((rop->line < 0)
646                 ? "bottom"
647                 : "top")));
648
649             w = newwin(count, scolumns,
650                        ((rop->line < 0)
651                         ? SP->_lines_avail - count
652                         : 0),
653                        0);
654             if (w) {
655                 rop->win = w;
656                 rop->hook(w, scolumns);
657             } else {
658                 returnCode(ERR);
659             }
660             if (rop->line < 0)
661                 bottom_stolen += count;
662             else
663                 SP->_topstolen += count;
664             SP->_lines_avail -= count;
665         }
666     }
667     /* reset the stack */
668     safe_ripoff_sp = safe_ripoff_stack;
669
670     T(("creating stdscr"));
671     assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
672     if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0)
673         returnCode(ERR);
674
675     SET_LINES(SP->_lines_avail);
676 #if !USE_REENTRANT
677     stdscr = SP->_stdscr;
678 #endif
679
680     returnCode(OK);
681 }
682
683 /*
684  * The internal implementation interprets line as the number of lines to rip
685  * off from the top or bottom.
686  */
687 NCURSES_EXPORT(int)
688 NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
689                                  int line,
690                                  int (*init) (WINDOW *, int))
691 {
692     T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
693
694     if (line != 0) {
695
696         if (safe_ripoff_sp == 0)
697             safe_ripoff_sp = safe_ripoff_stack;
698         if (safe_ripoff_sp >= safe_ripoff_stack + N_RIPS)
699             returnCode(ERR);
700
701         safe_ripoff_sp->line = line;
702         safe_ripoff_sp->hook = init;
703         safe_ripoff_sp++;
704     }
705
706     returnCode(OK);
707 }
708
709 #if NCURSES_SP_FUNCS
710 NCURSES_EXPORT(int)
711 _nc_ripoffline(int line, int (*init) (WINDOW *, int))
712 {
713     return NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN, line, init);
714 }
715 #endif
716
717 NCURSES_EXPORT(int)
718 NCURSES_SP_NAME(ripoffline) (NCURSES_SP_DCLx
719                              int line,
720                              int (*init) (WINDOW *, int))
721 {
722     START_TRACE();
723     T((T_CALLED("ripoffline(%d,%p)"), line, init));
724
725     if (line == 0)
726         returnCode(OK);
727
728     returnCode(NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_ARGx
729                                                 (line < 0) ? -1 : 1,
730                                                 init));
731 }
732
733 #if NCURSES_SP_FUNCS
734 NCURSES_EXPORT(int)
735 ripoffline(int line, int (*init) (WINDOW *, int))
736 {
737     return NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN, line, init);
738 }
739 #endif