bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incorrect interaction of slk_init and ripoffline


From: Clive Nicolson
Subject: Re: Incorrect interaction of slk_init and ripoffline
Date: Fri, 11 May 2007 01:34:38 +1200 (NZST)

On Tue, 8 May 2007, Thomas Dickey wrote:

On Tue, 8 May 2007, Clive Nicolson wrote:

In ncurses (at least version 5.5):

slk_init behaves as if it has been called after all calls to ripoffline, when
it emulates slk's. I would have expected it to have reserved a line before
any lines reserved by calls to ripoffline. This means that the slk line may
not be on the bottom of the screen.

Documentation for some versions of curses say that slk_init must be called
before ripoffline. slk_init on curses under OpenSolaris appears to reserve a
line before any reserved by ripoffline.

I see the comment in X/Open's description of slk_init - which is useful.
Will investigate (thanks)



Here is a patch against ncurses-5.6 which corrects the slk_init/ripoffline bug.

This provides the following functionality (some of which may have been
present in ncurses-5.6):

To be effective slk_init must be called before initscr or newterm is called.

slk_init will return an error if is is called more than once before initscr or
newterm is called.

slk_init should be called before any call to ripoffline, but will cause "expected" behavior if not, ie the slk line may not be the bottom line.

slk_init effectively calls ripoffline, however no line may be ripped off if
the terminal hardware can support the request slk format.

diff -r -u ncurses-5.6/ncurses/base/lib_set_term.c 
ncurses-5.6_ripoffline/ncurses/base/lib_set_term.c
--- ncurses-5.6/ncurses/base/lib_set_term.c     2006-05-21 02:58:02.000000000 
+1200
+++ ncurses-5.6_ripoffline/ncurses/base/lib_set_term.c  2007-05-11 
01:07:24.000000000 +1200
@@ -164,7 +164,7 @@

 static ripoff_t rippedoff[5];
 static ripoff_t *rsp = rippedoff;
-#define N_RIPS SIZEOF(SP->_rippedoff)
+#define N_RIPS SIZEOF(rippedoff)

 static bool
 no_mouse_event(SCREEN *sp GCC_UNUSED)
@@ -223,7 +223,6 @@
                int slk_format)
 {
     int bottom_stolen = 0;
-    int i;
     bool support_cookies = USE_XMC_SUPPORT;

     T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
@@ -259,17 +258,6 @@
        T(("filter screensize %dx%d", LINES, COLS));
     }

-    /* If we must simulate soft labels, grab off the line to be used.
-       We assume that we must simulate, if it is none of the standard
-       formats (4-4  or 3-2-3) for which there may be some hardware
-       support. */
-    if (num_labels <= 0 || !SLK_STDFMT(slk_format)) {
-       if (slk_format) {
-           if (ERR == _nc_ripoffline(-SLK_LINES(slk_format),
-                                     _nc_slk_initialize))
-               returnCode(ERR);
-       }
-    }
 #ifdef __DJGPP__
     T(("setting output mode to binary"));
     fflush(output);
@@ -525,31 +513,36 @@
     def_shell_mode();
     def_prog_mode();

-    for (i = 0, rsp = rippedoff; rsp->line && (i < (int) N_RIPS); rsp++, i++) {
-       T(("ripping off line %d at %s", i, rsp->line < 0 ? "bottom" : "top"));
-       SP->_rippedoff[i] = rippedoff[i];
-       if (rsp->hook) {
-           int count = (rsp->line < 0) ? -rsp->line : rsp->line;
-
-           SP->_rippedoff[i].w = newwin(count,
-                                        scolumns,
-                                        ((rsp->line < 0)
-                                         ? SP->_lines_avail - count
-                                         : 0),
-                                        0);
-           if (SP->_rippedoff[i].w != 0)
-               SP->_rippedoff[i].hook(SP->_rippedoff[i].w, scolumns);
+    ripoff_t *rop;
+
+    for (rop = rippedoff; rop != rsp; rop++) {
+       /* If we must simulate soft labels, grab off the line to be used.
+          We assume that we must simulate, if it is none of the standard
+          formats (4-4 or 3-2-3) for which there may be some hardware
+          support. */
+       if (rop->hook == _nc_slk_initialize)
+           if (!(num_labels <= 0 || !SLK_STDFMT(slk_format)))
+               continue;
+       if (rop->hook) {
+           int count;
+           WINDOW *w;
+
+           count = (rop->line < 0) ? -rop->line : rop->line;
+           T(("ripping off %i lines at %s", count, rop->line < 0 ? "bottom" : 
"top"));
+
+           w = newwin(count, scolumns,
+                      (rop->line < 0) ? SP->_lines_avail - count : 0, 0);
+           if (w)
+               rop->hook(w, scolumns);
            else
                returnCode(ERR);
-           if (rsp->line < 0)
+           if (rop->line < 0)
                bottom_stolen += count;
            else
                SP->_topstolen += count;
            SP->_lines_avail -= count;
        }
-       rsp->line = 0;
     }
-    SP->_rip_count = i;
     /* reset the stack */
     rsp = rippedoff;

@@ -571,13 +564,11 @@
     T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));

     if (line != 0) {
-
        if (rsp >= rippedoff + N_RIPS)
            returnCode(ERR);

        rsp->line = line;
        rsp->hook = init;
-       rsp->w = 0;
        rsp++;
     }

diff -r -u ncurses-5.6/ncurses/base/lib_slkinit.c 
ncurses-5.6_ripoffline/ncurses/base/lib_slkinit.c
--- ncurses-5.6/ncurses/base/lib_slkinit.c      2000-12-10 15:43:27.000000000 
+1300
+++ ncurses-5.6_ripoffline/ncurses/base/lib_slkinit.c   2007-05-10 
19:01:33.000000000 +1200
@@ -44,8 +44,10 @@
 slk_init(int format)
 {
     T((T_CALLED("slk_init(%d)"), format));
-    if (format < 0 || format > 3)
-       returnCode(ERR);
-    _nc_slk_format = 1 + format;
-    returnCode(OK);
+    if (format >= 0 && format <= 3 && !_nc_slk_format) {
+        _nc_slk_format = 1 + format;
+        returnCode(_nc_ripoffline(-SLK_LINES(_nc_slk_format),
+                                 _nc_slk_initialize));
+    } else
+        returnCode(ERR);
 }
diff -r -u ncurses-5.6/ncurses/curses.priv.h 
ncurses-5.6_ripoffline/ncurses/curses.priv.h
--- ncurses-5.6/ncurses/curses.priv.h   2006-12-10 13:55:14.000000000 +1300
+++ ncurses-5.6_ripoffline/ncurses/curses.priv.h        2007-05-10 
18:59:15.000000000 +1200
@@ -366,7 +366,6 @@
 typedef        struct {
        int     line;           /* lines to take, < 0 => from bottom*/
        int     (*hook)(WINDOW *, int); /* callback for user        */
-       WINDOW *w;              /* maybe we need this for cleanup   */
 } ripoff_t;

 #if USE_GPM_SUPPORT
@@ -410,8 +409,6 @@

        short           _lines_avail;   /* lines available for stdscr       */
        short           _topstolen;     /* lines stolen from top            */
-       ripoff_t        _rippedoff[5];  /* list of lines stolen             */
-       int             _rip_count;     /* ...and total lines stolen        */

        WINDOW          *_curscr;       /* current screen                   */
        WINDOW          *_newscr;       /* virtual screen to be updated to  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]