lib: move poll_in from curses to file
authorJean Privat <jean@pryen.org>
Tue, 3 Jul 2012 23:40:38 +0000 (19:40 -0400)
committerJean Privat <jean@pryen.org>
Thu, 25 Oct 2012 15:53:39 +0000 (11:53 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

examples/leapfrog/leapfrog_curses.nit
lib/curses/curses.nit
lib/curses/curses.nit.c
lib/curses/curses.nit.h
lib/standard/file.nit
lib/standard/file_nit.c
lib/standard/file_nit.h

index 826165c..e894f8c 100644 (file)
@@ -121,7 +121,7 @@ redef class Scene
                sys.nanosleep(0, 48000000)
 
                # Keyboard input
-               while stdin.as(Stdin).poll_in do
+               while stdin.poll_in do
                        if stdin.eof then return
                        var c = stdin.read_char
                        if c == 'q'.ascii then
index 11d5ab6..fccf346 100644 (file)
@@ -29,9 +29,3 @@ extern Window
        fun delwin is extern
        fun endwin is extern
 end
-
-redef class Stdin
-       # Is these something to read? (non blocking)
-       # FIXME: should not be in the curses module
-       fun poll_in: Bool is extern
-end
index c6457a8..a58b22e 100644 (file)
@@ -4,7 +4,6 @@
 */
 
 #include "curses.nit.h"
-#include <poll.h>
 
 /*
 C implementation of curses::Window::init
@@ -64,17 +63,3 @@ void Window_endwin___impl( Window recv )
 {
        endwin();
 }
-
-/*
-C implementation of curses::Stdin::poll_in
-*/
-int Stdin_poll_in___impl( Stdin recv ) {
-       struct pollfd fd = {0, POLLIN, 0};
-       int res = poll(&fd, 1, 0);
-       if (res == -1) {
-               endwin();
-               perror("Error poll stdin");
-               exit(EXIT_FAILURE);
-       }
-       return res > 0;
-}
index 83d3c00..816fce3 100644 (file)
@@ -16,5 +16,4 @@ void Window_refresh___impl( Window recv );
 void Window_wclear___impl( Window recv );
 void Window_delwin___impl( Window recv );
 void Window_endwin___impl( Window recv );
-int Stdin_poll_in___impl( Stdin recv );
 #endif
index dc74b95..df819c4 100644 (file)
@@ -166,6 +166,10 @@ class Stdin
                _path = "/dev/stdin"
                prepare_buffer(1)
        end
+
+       # Is these something to read? (non blocking)
+       # FIXME: should be generalized
+       fun poll_in: Bool is extern "file_stdin_poll_in"
 end
 
 class Stdout
@@ -344,7 +348,7 @@ private extern NativeFile
 end
 
 # Standard input.
-fun stdin: IFStream do return once new Stdin
+fun stdin: Stdin do return once new Stdin
 
 # Standard output.
 fun stdout: OFStream do return once new Stdout
index 81e00eb..56b26da 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <string.h>
 #include <dirent.h>
+#include <poll.h>
 
 #include "file_nit.h"
 
@@ -98,3 +99,13 @@ void *file_NativeFile_NativeFile_file_stat_0(FILE *f){
 extern int string_NativeString_NativeString_file_delete_0(char *f){
   return (remove(f) == 0);
 }
+
+int file_stdin_poll_in_(void) {
+       struct pollfd fd = {0, POLLIN, 0};
+       int res = poll(&fd, 1, 0);
+       if (res == -1) {
+               perror("Error poll stdin");
+               exit(EXIT_FAILURE);
+       }
+       return res > 0;
+}
index 57f4dfc..4291f02 100644 (file)
@@ -48,5 +48,8 @@ extern int string_NativeString_NativeString_file_delete_0(char *f);
 #define file_FileStat_FileStat_size_0(self) (((struct stat*)self)->st_size)
 
 #define string_NativeString_NativeString_file_mkdir_0(p) (mkdir(p, 0777))
+
+#define file_stdin_poll_in(self) file_stdin_poll_in_()
+int file_stdin_poll_in_(void);
 #endif