2009-02-05 21:08:46 +00:00
|
|
|
#ifndef _INCLUDE_CONS_R_
|
|
|
|
#define _INCLUDE_CONS_R_
|
|
|
|
|
2009-04-07 11:28:22 +00:00
|
|
|
#define HAVE_DIETLINE 0
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2011-06-26 21:49:11 +00:00
|
|
|
#include <r_types.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2010-01-30 13:02:53 +00:00
|
|
|
#if __UNIX__
|
|
|
|
#include <termios.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#if __WINDOWS__
|
|
|
|
#include <windows.h>
|
2011-07-06 09:48:16 +00:00
|
|
|
#include <wincon.h>
|
2010-01-30 13:02:53 +00:00
|
|
|
#endif
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2010-01-30 13:02:53 +00:00
|
|
|
/* constants */
|
2009-02-27 00:18:19 +00:00
|
|
|
#define CONS_MAX_USER 102400
|
2009-02-05 21:08:46 +00:00
|
|
|
#define CONS_BUFSZ 0x4f00
|
|
|
|
#define STR_IS_NULL(x) (!x || !x[0])
|
|
|
|
|
2010-01-30 13:02:53 +00:00
|
|
|
/* palette */
|
|
|
|
#define CONS_PALETTE_SIZE 22
|
|
|
|
#define CONS_COLORS_SIZE 21
|
|
|
|
|
|
|
|
typedef struct r_cons_grep_t {
|
|
|
|
char strings[10][64];
|
|
|
|
int nstrings;
|
|
|
|
char *str;
|
|
|
|
int counter;
|
|
|
|
int line;
|
2010-08-03 09:36:41 +00:00
|
|
|
int tokenfrom;
|
|
|
|
int tokento;
|
2010-01-30 13:02:53 +00:00
|
|
|
int neg;
|
|
|
|
} RConsGrep;
|
|
|
|
|
2011-01-23 12:12:16 +00:00
|
|
|
typedef void (*RConsEvent)(void *);
|
|
|
|
|
2010-01-27 00:50:26 +00:00
|
|
|
typedef struct r_cons_t {
|
2010-01-30 13:02:53 +00:00
|
|
|
RConsGrep grep;
|
|
|
|
char *buffer;
|
2010-06-24 23:44:15 +00:00
|
|
|
int line;
|
2010-01-30 13:02:53 +00:00
|
|
|
int buffer_len;
|
|
|
|
int buffer_sz;
|
|
|
|
char *lastline;
|
2010-01-27 00:50:26 +00:00
|
|
|
int is_html;
|
2010-01-30 13:02:53 +00:00
|
|
|
int is_interactive;
|
|
|
|
int lines;
|
2010-01-27 00:50:26 +00:00
|
|
|
int rows;
|
|
|
|
int columns;
|
2010-01-30 13:02:53 +00:00
|
|
|
int breaked;
|
|
|
|
int noflush;
|
|
|
|
FILE *fdin; // FILE? and then int ??
|
|
|
|
int fdout; // only used in pipe.c :?? remove?
|
2011-03-01 18:06:22 +00:00
|
|
|
const char *teefile;
|
2010-01-30 13:02:53 +00:00
|
|
|
int (*user_fgets)(char *buf, int len);
|
2011-01-23 12:12:16 +00:00
|
|
|
RConsEvent event_interrupt;
|
|
|
|
RConsEvent event_resize;
|
|
|
|
void *data;
|
2010-01-30 13:02:53 +00:00
|
|
|
#if __UNIX__
|
|
|
|
struct termios term_raw, term_buf;
|
|
|
|
#elif __WINDOWS__
|
|
|
|
LPDWORD term_raw, term_buf;
|
|
|
|
#endif
|
2011-06-26 21:49:11 +00:00
|
|
|
RNum *num;
|
2010-01-27 00:50:26 +00:00
|
|
|
} RCons;
|
2010-01-30 13:02:53 +00:00
|
|
|
|
|
|
|
// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */
|
|
|
|
/* XXX : global variables? or a struct with a singleton? */
|
|
|
|
//extern FILE *stdin_fd;
|
|
|
|
//extern FILE *r_cons_stdin_fd;
|
|
|
|
//extern int r_cons_stdout_fd;
|
|
|
|
//extern int r_cons_stdout_file;
|
|
|
|
//extern char *r_cons_filterline;
|
|
|
|
//extern char *r_cons_teefile;
|
|
|
|
// not needed anymoar
|
2010-02-11 23:43:11 +00:00
|
|
|
//extern int (*r_cons_user_fgets)(char *buf, int len);
|
2010-01-30 13:02:53 +00:00
|
|
|
|
2011-06-05 18:36:22 +00:00
|
|
|
#define R_CONS_KEY_F1 0xf1
|
|
|
|
#define R_CONS_KEY_F2 0xf2
|
|
|
|
#define R_CONS_KEY_F3 0xf3
|
|
|
|
#define R_CONS_KEY_F4 0xf4
|
|
|
|
#define R_CONS_KEY_F5 0xf5
|
|
|
|
#define R_CONS_KEY_F6 0xf6
|
|
|
|
#define R_CONS_KEY_F7 0xf7
|
|
|
|
#define R_CONS_KEY_F8 0xf8
|
|
|
|
#define R_CONS_KEY_F9 0xf9
|
|
|
|
#define R_CONS_KEY_F10 0xfa
|
|
|
|
#define R_CONS_KEY_F11 0xfb
|
|
|
|
#define R_CONS_KEY_F12 0xfc
|
|
|
|
|
|
|
|
#define R_CONS_KEY_ESC 0x1b
|
|
|
|
|
2011-12-05 08:55:44 +00:00
|
|
|
#define Color_INVERT "\x1b[7m"
|
|
|
|
#define Color_INVERT_RESET "\x1b[27m"
|
2009-02-05 21:08:46 +00:00
|
|
|
/* plain colors */
|
2010-01-27 00:50:26 +00:00
|
|
|
#define Color_BLACK "\x1b[30m"
|
|
|
|
#define Color_BGBLACK "\x1b[40m"
|
|
|
|
#define Color_RED "\x1b[31m"
|
|
|
|
#define Color_BGRED "\x1b[41m"
|
|
|
|
#define Color_WHITE "\x1b[37m"
|
|
|
|
#define Color_RESET "\x1b[0m"
|
|
|
|
#define Color_GREEN "\x1b[32m"
|
|
|
|
#define Color_MAGENTA "\x1b[35m"
|
|
|
|
#define Color_YELLOW "\x1b[33m"
|
|
|
|
#define Color_TURQOISE "\x1b[36m"
|
|
|
|
#define Color_BLUE "\x1b[34m"
|
|
|
|
#define Color_GRAY "\x1b[38m"
|
2009-02-05 21:08:46 +00:00
|
|
|
/* bold colors */
|
2010-01-27 00:50:26 +00:00
|
|
|
#define Color_BBLACK "\x1b[1;30m"
|
|
|
|
#define Color_BRED "\x1b[1;31m"
|
|
|
|
#define Color_BBGRED "\x1b[1;41m"
|
|
|
|
#define Color_BWHITE "\x1b[1;37m"
|
|
|
|
#define Color_BGREEN "\x1b[1;32m"
|
|
|
|
#define Color_BMAGENTA "\x1b[1;35m"
|
|
|
|
#define Color_BYELLOW "\x1b[1;33m"
|
|
|
|
#define Color_BTURQOISE "\x1b[1;36m"
|
|
|
|
#define Color_BBLUE "\x1b[1;34m"
|
|
|
|
#define Color_BGRAY "\x1b[1;38m"
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PAL_PROMPT = 0,
|
|
|
|
PAL_ADDRESS,
|
|
|
|
PAL_DEFAULT,
|
|
|
|
PAL_CHANGED,
|
|
|
|
PAL_JUMP,
|
|
|
|
PAL_CALL,
|
|
|
|
PAL_PUSH,
|
|
|
|
PAL_TRAP,
|
|
|
|
PAL_CMP,
|
|
|
|
PAL_RET,
|
|
|
|
PAL_NOP,
|
|
|
|
PAL_METADATA,
|
|
|
|
PAL_HEADER,
|
|
|
|
PAL_PRINTABLE,
|
|
|
|
PAL_LINES0,
|
|
|
|
PAL_LINES1,
|
|
|
|
PAL_LINES2,
|
|
|
|
PAL_00,
|
|
|
|
PAL_7F,
|
|
|
|
PAL_FF
|
|
|
|
};
|
|
|
|
|
2009-04-03 11:11:17 +00:00
|
|
|
/* default byte colors */
|
|
|
|
#if 0
|
|
|
|
#define COLOR_00 C_TURQOISE
|
|
|
|
#define COLOR_FF C_RED
|
|
|
|
#define COLOR_7F C_MAGENTA
|
|
|
|
#define COLOR_PR C_YELLOW
|
|
|
|
#define COLOR_HD C_GREEN
|
|
|
|
// addresses
|
|
|
|
#define COLOR_AD C_GREEN
|
|
|
|
#endif
|
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
#ifdef R_API
|
2010-02-11 23:43:11 +00:00
|
|
|
R_API RCons *r_cons_new ();
|
2010-02-18 15:36:55 +00:00
|
|
|
R_API RCons *r_cons_singleton ();
|
2010-12-26 22:38:53 +00:00
|
|
|
R_API RCons *r_cons_free ();
|
2010-02-11 23:43:11 +00:00
|
|
|
|
2010-01-12 01:12:18 +00:00
|
|
|
R_API void r_cons_break(void (*cb)(void *u), void *user);
|
|
|
|
R_API void r_cons_break_end();
|
|
|
|
|
|
|
|
/* pipe */
|
|
|
|
R_API int r_cons_pipe_open(const char *file, int append);
|
|
|
|
R_API void r_cons_pipe_close(int fd);
|
|
|
|
|
2010-06-27 20:14:06 +00:00
|
|
|
#if __WINDOWS__
|
2011-12-02 13:32:04 +00:00
|
|
|
R_API int r_cons_w32_print(ut8 *ptr, int empty);
|
2010-06-27 20:14:06 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
/* control */
|
|
|
|
R_API void r_cons_reset();
|
|
|
|
R_API void r_cons_clear();
|
|
|
|
R_API void r_cons_clear00();
|
2011-11-19 01:49:11 +00:00
|
|
|
R_API void r_cons_clear_line();
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API void r_cons_stdout_open(const char *file, int append);
|
|
|
|
R_API int r_cons_stdout_set_fd(int fd);
|
|
|
|
R_API void r_cons_gotoxy(int x, int y);
|
2011-12-02 00:58:34 +00:00
|
|
|
R_API void r_cons_show_cursor (int cursor);
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API void r_cons_set_raw(int b);
|
|
|
|
|
|
|
|
/* output */
|
|
|
|
R_API void r_cons_printf(const char *format, ...);
|
|
|
|
R_API void r_cons_strcat(const char *str);
|
2011-10-10 23:21:38 +00:00
|
|
|
#define r_cons_puts(x) r_cons_strcat(x)
|
2011-05-21 13:45:43 +00:00
|
|
|
R_API void r_cons_strcat_justify (const char *str, int j, char c);
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API void r_cons_memcat(const char *str, int len);
|
|
|
|
R_API void r_cons_newline();
|
2010-08-16 23:27:24 +00:00
|
|
|
R_API void r_cons_filter();
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API void r_cons_flush();
|
2011-05-21 12:27:46 +00:00
|
|
|
R_API void r_cons_memset(char ch, int len);
|
2010-02-28 13:49:26 +00:00
|
|
|
R_API void r_cons_visual_flush();
|
|
|
|
R_API void r_cons_visual_write (char *buffer);
|
2009-12-24 02:17:53 +00:00
|
|
|
|
|
|
|
/* input */
|
2010-02-11 23:43:11 +00:00
|
|
|
//R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API int r_cons_readchar();
|
|
|
|
R_API void r_cons_any_key();
|
|
|
|
R_API int r_cons_eof();
|
|
|
|
|
|
|
|
R_API int r_cons_palette_init(const unsigned char *pal);
|
2010-01-26 00:28:33 +00:00
|
|
|
R_API int r_cons_get_size(int *rows);
|
2010-01-30 13:02:53 +00:00
|
|
|
R_API int r_cons_arrow_to_hjkl(int ch);
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API int r_cons_html_print(const char *ptr);
|
|
|
|
|
2010-10-27 22:55:07 +00:00
|
|
|
// TODO: use gets() .. MUST BE DEPRECATED
|
2010-03-11 00:04:59 +00:00
|
|
|
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
|
2012-01-31 01:45:17 +00:00
|
|
|
R_API char *r_cons_hud(RList *list);
|
|
|
|
R_API char *r_cons_hud_string(const char *s);
|
|
|
|
R_API char *r_cons_hud_file(const char *f);
|
2010-03-11 00:04:59 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API const char *r_cons_get_buffer();
|
|
|
|
R_API void r_cons_grep(const char *str);
|
2010-06-24 23:44:15 +00:00
|
|
|
R_API int r_cons_grep_line(char *buf, int len); // must be static
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API int r_cons_grepbuf(char *buf, int len);
|
|
|
|
|
|
|
|
R_API void r_cons_invert(int set, int color);
|
|
|
|
R_API int r_cons_yesno(int def, const char *fmt, ...);
|
2011-05-15 23:47:01 +00:00
|
|
|
R_API void r_cons_set_cup(int enable);
|
2011-05-21 12:27:46 +00:00
|
|
|
R_API void r_cons_column(int c);
|
2011-09-12 01:01:07 +00:00
|
|
|
R_API int r_cons_get_column();
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#endif
|