bug-ncurses
[Top][All Lists]
Advanced

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

Reading the current timeout value


From: Sören Brinkmann
Subject: Reading the current timeout value
Date: Thu, 13 Mar 2014 21:18:56 -0700
User-agent: Mutt/1.5.22 (2013-10-16)

Hi,

I hope this list is open and I don't need to subscribe to post.

Anyway, I was recently writing a program and at some point I needed to
change things like the timeout and cursor visibility for a code section.

For cursor visibility this is easy. curs_set() returns the current
visibility, so that SW can store and restore that value.

Unfortunately I couldn't find any interface to read the current value of
timeout() and was pretty disappointed to see that timeout() and
wtimeout() are void functions.

So, my question is, is there a way to read the current timeout and I
just didn't find it?
Would it be acceptable to change the prototypes of timeout() and
wtimeout() to return the current timeout (see patch below)?

Changing an API function is probably an absolute no-go, though going
from a void to int return type should usually work - I guess.
But well, there may be a lot more short comings with this patch.

        Thanks,
        Sören

------------8<--------------8<------------8<------------8<------------8<--------
Date: Thu, 13 Mar 2014 20:16:42 -0700
Subject: [PATCH] ncurses: Make timeout() return old timeout

---
 c++/cursesw.h               | 2 +-
 include/curses.h.in         | 4 ++--
 man/curs_inopts.3x          | 8 +++++---
 ncurses/llib-lncurses       | 8 ++++----
 ncurses/tinfo/lib_options.c | 7 +++++--
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/c++/cursesw.h b/c++/cursesw.h
index b8e921a9b7aa..04456142e2e8 100644
--- a/c++/cursesw.h
+++ b/c++/cursesw.h
@@ -649,7 +649,7 @@ inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int 
y, int x)
 #endif
 
 #ifdef timeout
-inline void UNDEF(timeout)(int delay) { timeout(delay); }
+inline int UNDEF(timeout)(int delay) { return timeout(delay); }
 #undef timeout
 #define timeout UNDEF(timeout)
 #endif
diff --git a/include/curses.h.in b/include/curses.h.in
index 5774154e8538..2f76dc7285a1 100644
--- a/include/curses.h.in
+++ b/include/curses.h.in
@@ -750,7 +750,7 @@ extern NCURSES_EXPORT(WINDOW *) subwin (WINDOW *, int, int, 
int, int);      /* implem
 extern NCURSES_EXPORT(int) syncok (WINDOW *, bool);                    /* 
implemented */
 extern NCURSES_EXPORT(chtype) termattrs (void);                                
/* implemented */
 extern NCURSES_EXPORT(char *) termname (void);                         /* 
implemented */
-extern NCURSES_EXPORT(void) timeout (int);                             /* 
generated */
+extern NCURSES_EXPORT(int) timeout (int);                              /* 
generated */
 extern NCURSES_EXPORT(int) touchline (WINDOW *, int, int);             /* 
generated */
 extern NCURSES_EXPORT(int) touchwin (WINDOW *);                                
/* generated */
 extern NCURSES_EXPORT(int) typeahead (int);                            /* 
implemented */
@@ -817,7 +817,7 @@ extern NCURSES_EXPORT(int) wstandout (WINDOW *);            
        /* generated */
 extern NCURSES_EXPORT(int) wstandend (WINDOW *);                       /* 
generated */
 extern NCURSES_EXPORT(void) wsyncdown (WINDOW *);                      /* 
implemented */
 extern NCURSES_EXPORT(void) wsyncup (WINDOW *);                                
/* implemented */
-extern NCURSES_EXPORT(void) wtimeout (WINDOW *,int);                   /* 
implemented */
+extern NCURSES_EXPORT(int) wtimeout (WINDOW *,int);                    /* 
implemented */
 extern NCURSES_EXPORT(int) wtouchln (WINDOW *,int,int,int);            /* 
implemented */
 extern NCURSES_EXPORT(int) wvline (WINDOW *,chtype,int);               /* 
implemented */
 
diff --git a/man/curs_inopts.3x b/man/curs_inopts.3x
index aecb2e3714f8..13852e9198f9 100644
--- a/man/curs_inopts.3x
+++ b/man/curs_inopts.3x
@@ -81,9 +81,9 @@
 .br
 \fBint notimeout(WINDOW *win, bool bf);\fR
 .br
-\fBvoid timeout(int delay);\fR
+\fBint timeout(int delay);\fR
 .br
-\fBvoid wtimeout(WINDOW *win, int delay);\fR
+\fBint wtimeout(WINDOW *win, int delay);\fR
 .br
 \fBint typeahead(int fd);\fR
 .br
@@ -186,7 +186,9 @@ input).  If \fIdelay\fR is zero, then non-blocking read is 
used
 milliseconds, and returns \fBERR\fR if there is still no input.
 Hence, these routines provide the same functionality as \fBnodelay\fR,
 plus the additional capability of being able to block for only
-\fIdelay\fR milliseconds (where \fIdelay\fR is positive).
+\fIdelay\fR milliseconds (where \fIdelay\fR is positive).  The return value of
+\fBtimeout\fR and \fBwtimeout\fR is the old delay timeout value.
+
 .PP
 The \fBcurses\fR library does ``line-breakout optimization'' by looking for
 typeahead periodically while updating the screen.  If input is found,
diff --git a/ncurses/llib-lncurses b/ncurses/llib-lncurses
index 48f42830272a..898cc32088fe 100644
--- a/ncurses/llib-lncurses
+++ b/ncurses/llib-lncurses
@@ -1000,9 +1000,9 @@ int       standend(void)
                { return(*(int *)0); }
 
 #undef timeout
-void   timeout(
+int    timeout(
                int     z)
-               { /* void */ }
+               { return(*(int *)0); }
 
 #undef touchline
 int    touchline(
@@ -3195,10 +3195,10 @@ int     notimeout(
                { return(*(int *)0); }
 
 #undef wtimeout
-void   wtimeout(
+int    wtimeout(
                WINDOW  *win, 
                int     delay)
-               { /* void */ }
+               { return(*(int *)0); }
 
 #undef keypad
 int    keypad(
diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c
index 654bf940aa1f..005b2e4e1f81 100644
--- a/ncurses/tinfo/lib_options.c
+++ b/ncurses/tinfo/lib_options.c
@@ -126,15 +126,18 @@ notimeout(WINDOW *win, bool f)
        returnCode(ERR);
 }
 
-NCURSES_EXPORT(void)
+NCURSES_EXPORT(int)
 wtimeout(WINDOW *win, int delay)
 {
     T((T_CALLED("wtimeout(%p,%d)"), (void *) win, delay));
 
+    int delay_old;
+
     if (win) {
+       delay_old = win->_delay;
        win->_delay = delay;
     }
-    returnVoid;
+    returnCode(delay_old);
 }
 
 NCURSES_EXPORT(int)
-- 
1.9.0




reply via email to

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