Ticket #2988: add commented-out debugging logging mechanism. - Denys Vlasenko <vda.linux@googlemail.com> - 2012-10-22 1749.patch

File add commented-out debugging logging mechanism. - Denys Vlasenko <vda.linux@googlemail.com> - 2012-10-22 1749.patch, 5.7 KB (added by slavazanko, 11 years ago)
  • lib/tty/key.c

    From: Denys Vlasenko <vda.linux@googlemail.com>
    Date: Mon, 22 Oct 2012 16:49:42 +0200
    Subject: [PATCH 2/5] keyboard input: add commented-out debugging logging mechanism.
    
    Figuring out what exactly happens in get_key_code() when user
    uses various function keys is not trivial.
    While working on some fixes, I added a debugging code
    which records a log in /tmp/mc_key.log; I would like
    to save future developers from doing this again.
    
    This patch adds my debugging code, disabled via "#if 0".
    
    Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
    ---
     lib/tty/key.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
     1 files changed, 55 insertions(+), 0 deletions(-)
    
    diff --git a/lib/tty/key.c b/lib/tty/key.c
    index d2142fa..33732db 100644
    a b is_idle (void) 
    18111811} 
    18121812 
    18131813/* --------------------------------------------------------------------------------------------- */ 
     1814#if 0 
     1815# define key_debug 1 
     1816static void keylog (const char *fmt, ...) 
     1817{ 
     1818    static int logfd = -1; 
     1819 
     1820    if (logfd < 0) { 
     1821        logfd = open ("/tmp/mc_key.log", O_CREAT | O_WRONLY | O_APPEND, 0666); 
     1822        if (logfd < 0) 
     1823            return; 
     1824    } 
     1825 
     1826    va_list ap; 
     1827    va_start (ap, fmt); 
     1828    char *p = NULL; 
     1829    vasprintf (&p, fmt, ap); 
     1830    va_end (ap); 
     1831 
     1832    if (p) 
     1833    { 
     1834        write (logfd, p, strlen(p)); 
     1835        free (p); 
     1836    } 
     1837} 
     1838#else 
     1839# define key_debug 0 
     1840# define keylog(...) ((void)0) 
     1841#endif 
    18141842 
    18151843int 
    18161844get_key_code (int no_delay) 
    get_key_code (int no_delay) 
    18201848    static struct timeval esctime = { -1, -1 }; 
    18211849    static int lastnodelay = -1; 
    18221850 
     1851    keylog ("entered %s(no_delay:%d)\n", __func__, no_delay); 
     1852 
    18231853    if (no_delay != lastnodelay) 
    18241854    { 
    18251855        this = NULL; 
    get_key_code (int no_delay) 
    18321862        int m; 
    18331863 
    18341864        m = parse_extended_mouse_coordinates (); 
     1865        keylog (" pending_keys!=NULL. m=%d\n", m); 
    18351866        if (m == 1) 
    18361867        { 
    18371868            pending_keys = seq_append = NULL; 
    18381869            this = NULL; 
     1870            keylog ("return MCKEY_EXTENDED_MOUSE\n"); 
    18391871            return MCKEY_EXTENDED_MOUSE; 
    18401872        } 
    18411873        if (m == -1) 
    18421874        { 
    18431875            int d = *pending_keys++; 
     1876            keylog (" d=*pending_keys++=%d\n", d); 
    18441877          check_pend: 
    18451878            if (*pending_keys == 0) 
    18461879            { 
    get_key_code (int no_delay) 
    18501883            else if (d == ESC_CHAR) 
    18511884            { 
    18521885                d = ALT (*pending_keys++); 
     1886                keylog (" d=ALT(*pending_keys++)=ALT(%d)=%d\n", pending_keys[-1], d); 
    18531887                goto check_pend; 
    18541888            } 
    18551889            if ((d > 127 && d < 256) && use_8th_bit_as_meta) 
     1890            { 
    18561891                d = ALT (d & 0x7f); 
     1892                keylog (" d=ALT(d & 0x7f)=ALT(%d)=%d\n", d & 0x7f, d); 
     1893            } 
    18571894            this = NULL; 
     1895            keylog ("return correct_key_code(%d)\n", d); 
    18581896            return correct_key_code (d); 
    18591897        } 
    18601898        /* else if (m == 0), just let it continue */ 
    get_key_code (int no_delay) 
    18651903        tty_nodelay (TRUE); 
    18661904 
    18671905    c = tty_lowlevel_getch (); 
     1906    keylog (" c=tty_lowlevel_getch()=%d\n", c); 
    18681907#if (defined(USE_NCURSES) || defined(USE_NCURSESW)) && defined(KEY_RESIZE) 
    18691908    if (c == KEY_RESIZE) 
    18701909        goto nodelay_try_again; 
    get_key_code (int no_delay) 
    19411980                pending_keys = seq_append = NULL; 
    19421981                code = this->code; 
    19431982                this = NULL; 
     1983                keylog ("2 return correct_key_code(%d)\n", code); 
    19441984                return correct_key_code (code); 
    19451985            } 
    19461986            /* No match yet, but it may be a prefix for a valid seq */ 
    19471987 
    19481988            if (!push_char (c)) 
    19491989            { 
     1990                keylog (" push_char(%d) failure (no more space)\n", c); 
    19501991                pending_keys = seq_buffer; 
    19511992                goto pend_send; 
    19521993            } 
     1994            keylog (" push_char(%d) ok\n", c); 
    19531995            parent = this; 
    19541996            this = this->child; 
    19551997            if (parent->action == MCKEY_ESCAPE && old_esc_mode) 
    get_key_code (int no_delay) 
    19672009                } 
    19682010                esctime.tv_sec = -1; 
    19692011                c = xgetch_second (); 
     2012                keylog (" c=xgetch_second()=%d\n", c); 
    19702013                if (c == -1) 
    19712014                { 
    19722015                    pending_keys = seq_append = NULL; 
    19732016                    this = NULL; 
     2017                    keylog ("return ESC_CHAR\n"); 
    19742018                    return ESC_CHAR; 
    19752019                } 
    19762020                continue; 
    get_key_code (int no_delay) 
    19782022            if (no_delay) 
    19792023                goto nodelay_try_again; 
    19802024            c = tty_lowlevel_getch (); 
     2025            keylog (" 2 c=tty_lowlevel_getch()=%d\n", c); 
    19812026            continue; 
    19822027        } 
    19832028 
    get_key_code (int no_delay) 
    20002045 
    20012046            pending_keys = seq_append = NULL; 
    20022047            this = NULL; 
     2048            keylog ("3 return correct_key_code(%d)\n", c); 
    20032049            return correct_key_code (c); 
    20042050        } 
    20052051 
    20062052        /* Unknown sequence. Maybe a prefix of a longer one. Save it. */ 
     2053        keylog (" push_char(%d)\n", c); 
    20072054        push_char (c); 
     2055        if (key_debug) 
     2056        { 
     2057            int i = 0; 
     2058            do 
     2059                keylog ("  seq_buffer[%d]:%d\n", i, seq_buffer[i]); 
     2060            while (seq_buffer[i++]); 
     2061        } 
    20082062        pending_keys = seq_buffer; 
    20092063        goto pend_send; 
    20102064 
    20112065    } /* while (this != NULL) */ 
    20122066 
    20132067    this = NULL; 
     2068    keylog ("4 return correct_key_code(%d)\n", c); 
    20142069    return correct_key_code (c); 
    20152070} 
    20162071