bug-ncurses
[Top][All Lists]
Advanced

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

Corrections for 20030906


From: Philippe Blain
Subject: Corrections for 20030906
Date: Wed, 10 Sep 2003 20:48:09 +0200

>From Philippe Blain, Bordeaux, France.
My computer: P133 - 8,4 Go - 32 Mo Red Hat Linux 7.0

Corrections for ncurses-5.3-20030906+

1-----------------------------------------------------------------------
File : ncurses/tinfo/strings.c

As s_size (s_free will be a better name) is initialized at sizeof(buffer)-1,
lines 111 & 132 should be :

==>     if (len <= dst->s_size) {

NOTE also that the changes (NEWS 20030802) in _nc_safe_strcat()
and _nc_safe_strcpy(), has been reverted (due to some backup ??) :
    s_size is decremented even if s_tail is NULL, and src not copied.

NCURSES_EXPORT (bool)
_nc_safe_strcat (string_desc * dst, const char *src)
{
    if (src != 0) {
        size_t len = strlen (src);

        if (len <= dst->s_size) {
            if (dst->s_tail != 0) {
                strcpy (dst->s_tail, src);
                dst->s_tail += len;
==>             dst->s_size -= len;
==>             return TRUE;
==>         }
        }
    }
    return FALSE;
}

2-----------------------------------------------------------------------
File : ncurses/tty/lib_mvcur.c

Moving the label 'nonlocal' just before the second gettimeofday() to
be able to compute the diff time when 'goto nonlocal' used.

Better to rename 'msec' in 'microsec'.

        ....................
    #if defined(MAIN) || defined(NCURSES_TEST)
        struct timeval before, after;

        gettimeofday(&before, NULL);
    #endif /* MAIN */
        ....................
==> nonlocal:

    #if defined(MAIN) || defined(NCURSES_TEST)
        gettimeofday(&after, NULL);
        diff = after.tv_usec - before.tv_usec
        + (after.tv_sec - before.tv_sec) * 1000000;
        if (!profiling)
            fprintf(stderr,
==>             "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
                (int) diff, diff / 288);
    #endif /* MAIN */

        if (usecost != INFINITY) {
            TPUTS_TRACE ("mvcur");
            ....................

3-----------------------------------------------------------------------
File : ncurses/tty/lib_mvcur.c

Lines 897 & 904
Using ncurses '_nc_outch()' instead of 'putchar' which goes to stdout.

    while (l > 0) {
        if (newline) {
            TPUTS_TRACE ("newline");
            putp (newline);
        }
==>     else _nc_outch ('\n');
        l--;

/* Why the case (xold > 0) treated in the while() loop ??? */

        if (xold > 0) {
            if (carriage_return) {
                TPUTS_TRACE ("carriage_return");
                putp (carriage_return);
            }
==>         else _nc_outch ('\r');
            xold = 0;
        }
    }

4-----------------------------------------------------------------------
File : ncurses/tty/lib_tputs.c

    static int (*my_outch) (int c) = _nc_outch;

Introduced for delay_output(), static 'my_outch' can be removed by
passing delay_output() the same parameter as tputs() :

    delay_output (int ms, int (*outc) (int))

5-----------------------------------------------------------------------
File : ncurses/curses.priv.h

Because SP->_buffered is set only by _nc_set_buffer(), should be a
BOOLEAN (buffered or not) and then simplify the corresponding macro :

    #define NC_BUFFERED(flag) \
==>     if (SP->_buffered != flag) \
            _nc_set_buffer(SP->_ofp, flag)

NOTE that the test can be incorporated in _nc_set_buffer() directly.

6-----------------------------------------------------------------------
File : ncurses/tinfo/setbuf.c

The boolean SP->_buffered must be set at the end of operations
when all has been success. (typeMalloc can fail)

NCURSES_EXPORT (void) _nc_set_buffer (FILE * ofp, bool buffered)
{
    /* optional optimization hack -- do before any output to ofp */
#if HAVE_SETVBUF || HAVE_SETBUFFER

    unsigned buf_len;
    char *buf_ptr;

    if (getenv ("NCURSES_NO_SETBUF") != 0) return;

    fflush (ofp);
==> if (buffered) {
==>     if (SP->_setbuf == 0) {
==>      buf_len = min (LINES * (COLS + 6), 2800);
            if ((buf_ptr = typeMalloc (char, buf_len)) == NULL)
                  return;
            SP->_setbuf = buf_ptr;
            /* Don't try to free this! */
        }
        else return;
    }
    else {
        buf_len = 0;
        buf_ptr = 0;
    }

#if HAVE_SETVBUF
    #ifdef SETVBUF_REVERSED            /* pre-svr3? */
        (void) setvbuf (ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF);
    #else
        (void) setvbuf (ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len);
    #endif
#elif HAVE_SETBUFFER
    (void) setbuffer (ofp, buf_ptr, (int) buf_len);
#endif

==> SP->_buffered = buffered;

#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
}

7-----------------------------------------------------------------------
nl() & nonl()

If the ICRNL mode is simulated (lib_getstr.c),  the translation
NL -> CRLF on OUTPUT seems NOT to be done by software (see PutAttrChar).
Think it's easier to call _nc_set_tty_mode() with correct flags in nl()
and nonl() and let the tty driver do the job than the software way
adopted.

curs_outopts(3X) says :

       The  nl  and  nonl routines control whether the underlying
       display device translates the return key into  newline  on
==>    input,  and  whether it translates newline into return and
==>    line-feed on output (in either case, the call  addch('\n')
       does the equivalent of return and line feed on the virtual
       screen).  Initially, these translations do occur.  If  you
       disable  them using nonl, curses will be able to make bet­
       ter use of the line-feed capability, resulting  in  faster
       cursor  motion.   Also, curses will then be able to detect
       the return key.

------------------------------------------------------------------------
- Philippe






reply via email to

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