00001
00011
00012
00013
00014
00015 #include <ncurses.h>
00016 #include <stdlib.h>
00017 #include <dlfcn.h>
00018
00019 #include "FBlib.h"
00020 #include "FBpriv.h"
00021
00022
00023
00024
00025 int (*getch_) (void);
00026 WINDOW* (*initscr_) (void);
00027 int (*cbreak_) (void);
00028 int (*noecho_) (void);
00029 int (*keypad_) (WINDOW *win, bool bf);
00030 int (*nodelay_) (WINDOW *win, bool bf);
00031 int (*endwin_) (void);
00032 int (*nonl_) (void);
00033
00034 void *handle;
00035 WINDOW *stdscr_;
00036
00037 int FB_kb_init()
00038 {
00039 uses_keyboard = 0;
00040
00041 handle = dlopen("libncurses.so.5",RTLD_LAZY);
00042
00043 if(!handle)
00044 {
00045 fprintf(stderr,"%s\n",dlerror());
00046 exit(1);
00047 }
00048
00049 uses_keyboard=1;
00050
00051 getch_ = dlsym(handle,"getch");
00052 initscr_ = dlsym(handle,"initscr");
00053 cbreak_ = dlsym(handle,"cbreak");
00054 noecho_ = dlsym(handle,"noecho");
00055 keypad_ = dlsym(handle,"keypad");
00056 nodelay_ = dlsym(handle,"nodelay");
00057 endwin_ = dlsym(handle,"endwin");
00058 nonl_ = dlsym(handle,"nonl");
00059
00060 if(uses_keyboard==1)
00061 {
00062 stdscr_ = (*initscr_)();
00063 (*cbreak_)();
00064 (*noecho_)();
00065 (*nonl_)();
00066 (*keypad_)(stdscr_, TRUE);
00067 (*nodelay_)(stdscr_, TRUE);
00068 return OK;
00069 }
00070 else
00071 {
00072 return ERR;
00073 }
00074 }
00075
00076 int FB_get_key()
00077 {
00078 int key = NO_KEY;
00079 if(uses_keyboard==1)
00080 {
00081 key = (*getch_)();
00082 if(key == ERR)
00083 return NO_KEY;
00084 }
00085 return key;
00086 }
00087
00088 void FB_kb_end()
00089 {
00090 if(uses_keyboard==1)
00091 (*endwin_)();
00092 return;
00093 }