mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 13:49:50 +00:00
* Split install-includes from install: libr/ mk target
* Rename some enums in r_cons (C_ -> Color_) - Export colors in vapi and swig * Initial dummy work with r_cons_instance singleton - Added _new() and _free() methods for r_cons - Redefine RCons structure * Added r_cons python example
This commit is contained in:
parent
368aeaf974
commit
8f3e91b9bb
@ -59,7 +59,11 @@ install-pkgconfig:
|
||||
@${INSTALL_DIR} ${PFX}/lib/pkgconfig
|
||||
for a in ../pkgcfg/*.pc ; do ${INSTALL_DATA} $$a ${PFX}/lib/pkgconfig ; done
|
||||
|
||||
install: install-vapi install-pkgconfig
|
||||
install-includes:
|
||||
@${INSTALL_DIR} ${PFX}/include/libr
|
||||
(cd include && ${INSTALL_DATA} * ${PFX}/include/libr)
|
||||
|
||||
install: install-includes install-vapi install-pkgconfig
|
||||
# TODO :Use INSTALL_DATA_DIR instead of mkdir
|
||||
# libraries
|
||||
@${INSTALL_DIR} ${PFX}/lib
|
||||
@ -68,9 +72,6 @@ install: install-vapi install-pkgconfig
|
||||
# object archives
|
||||
@for a in `find * | grep -e '\.a$$'` ; do \
|
||||
echo "$$a ${PFX}/lib"; ${INSTALL_DATA} $$a ${PFX}/lib ; done
|
||||
# includes
|
||||
@${INSTALL_DIR} ${PFX}/include/libr
|
||||
(cd include && ${INSTALL_DATA} * ${PFX}/include/libr)
|
||||
# programs
|
||||
@${INSTALL_DIR} ${PFX}/bin
|
||||
@for a in `find */t -perm /u+x -type f | grep 2`; \
|
||||
|
@ -51,29 +51,29 @@ void r_cons_invert(int set, int color)
|
||||
}
|
||||
|
||||
const char *r_cons_colors[CONS_COLORS_SIZE+1] = {
|
||||
C_BLACK, // 0
|
||||
C_GRAY, // 1
|
||||
C_WHITE, // 2
|
||||
C_RED, // 3
|
||||
C_MAGENTA, // 4
|
||||
C_BLUE, // 5
|
||||
C_GREEN, // 6
|
||||
C_YELLOW, // 7
|
||||
C_TURQOISE, // 8
|
||||
Color_BLACK, // 0
|
||||
Color_GRAY, // 1
|
||||
Color_WHITE, // 2
|
||||
Color_RED, // 3
|
||||
Color_MAGENTA, // 4
|
||||
Color_BLUE, // 5
|
||||
Color_GREEN, // 6
|
||||
Color_YELLOW, // 7
|
||||
Color_TURQOISE, // 8
|
||||
/* BOLD */
|
||||
C_BBLACK, // a
|
||||
C_BGRAY, // b
|
||||
C_BWHITE, // c
|
||||
C_BRED, // d
|
||||
C_BMAGENTA, // e
|
||||
C_BBLUE, // f
|
||||
C_BGREEN, // g
|
||||
C_BYELLOW, // h
|
||||
C_BTURQOISE, // i
|
||||
Color_BBLACK, // a
|
||||
Color_BGRAY, // b
|
||||
Color_BWHITE, // c
|
||||
Color_BRED, // d
|
||||
Color_BMAGENTA, // e
|
||||
Color_BBLUE, // f
|
||||
Color_BGREEN, // g
|
||||
Color_BYELLOW, // h
|
||||
Color_BTURQOISE, // i
|
||||
/* SPECIAL */
|
||||
C_RESET, // r
|
||||
C_BGBLACK, //
|
||||
C_BGRED,
|
||||
Color_RESET, // r
|
||||
Color_BGBLACK, //
|
||||
Color_BGRED,
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -150,7 +150,7 @@ int r_cons_palette_init(const unsigned char *pal)
|
||||
}
|
||||
} else {
|
||||
j = 0;
|
||||
strcpy(r_cons_palette[i], C_RESET);
|
||||
strcpy(r_cons_palette[i], Color_RESET);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#define MOAR_VALUE 4096*4
|
||||
|
||||
RCons r_cons;
|
||||
RCons r_cons_instance;
|
||||
|
||||
int r_cons_stdout_fd = 1;
|
||||
FILE *r_cons_stdin_fd = NULL; // TODO use int fd here too!
|
||||
@ -78,6 +78,17 @@ R_API void r_cons_break_end()
|
||||
#endif
|
||||
}
|
||||
|
||||
R_API RCons *r_cons_new ()
|
||||
{
|
||||
return &r_cons_instance;
|
||||
}
|
||||
|
||||
R_API RCons *r_cons_free ()
|
||||
{
|
||||
/* do nothing */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_cons_init()
|
||||
{
|
||||
r_cons_stdin_fd = stdin;
|
||||
|
@ -10,43 +10,43 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
typedef struct r_cons_t {
|
||||
int r_cons_is_interactive;
|
||||
int r_cons_is_html;
|
||||
int r_cons_rows;
|
||||
int r_cons_columns;
|
||||
int r_cons_lines;
|
||||
int r_cons_noflush;
|
||||
} RCons;
|
||||
|
||||
#define CONS_MAX_USER 102400
|
||||
#define CONS_BUFSZ 0x4f00
|
||||
#define STR_IS_NULL(x) (!x || !x[0])
|
||||
|
||||
typedef struct r_cons_t {
|
||||
int is_html;
|
||||
int rows;
|
||||
int columns;
|
||||
/* TODO: moar */
|
||||
} RCons;
|
||||
|
||||
extern RCons r_cons_instance;
|
||||
|
||||
/* plain colors */
|
||||
#define C_BLACK "\x1b[30m"
|
||||
#define C_BGBLACK "\x1b[40m"
|
||||
#define C_RED "\x1b[31m"
|
||||
#define C_BGRED "\x1b[41m"
|
||||
#define C_WHITE "\x1b[37m"
|
||||
#define C_RESET "\x1b[0m"
|
||||
#define C_GREEN "\x1b[32m"
|
||||
#define C_MAGENTA "\x1b[35m"
|
||||
#define C_YELLOW "\x1b[33m"
|
||||
#define C_TURQOISE "\x1b[36m"
|
||||
#define C_BLUE "\x1b[34m"
|
||||
#define C_GRAY "\x1b[38m"
|
||||
#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"
|
||||
/* bold colors */
|
||||
#define C_BBLACK "\x1b[1;30m"
|
||||
#define C_BRED "\x1b[1;31m"
|
||||
#define C_BBGRED "\x1b[1;41m"
|
||||
#define C_BWHITE "\x1b[1;37m"
|
||||
#define C_BGREEN "\x1b[1;32m"
|
||||
#define C_BMAGENTA "\x1b[1;35m"
|
||||
#define C_BYELLOW "\x1b[1;33m"
|
||||
#define C_BTURQOISE "\x1b[1;36m"
|
||||
#define C_BBLUE "\x1b[1;34m"
|
||||
#define C_BGRAY "\x1b[1;38m"
|
||||
#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"
|
||||
|
||||
/* palette */
|
||||
#define CONS_PALETTE_SIZE 22
|
||||
@ -85,10 +85,11 @@ enum {
|
||||
#define COLOR_AD C_GREEN
|
||||
#endif
|
||||
|
||||
// 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_fd;
|
||||
//extern int r_cons_stdout_file;
|
||||
extern int r_cons_breaked;
|
||||
extern const char *r_cons_palette_default;
|
||||
|
@ -5,6 +5,22 @@ namespace Radare {
|
||||
[Compact]
|
||||
[CCode (cname="struct r_cons_t", free_function="r_cons_free", cprefix="r_cons_")]
|
||||
public class RCons {
|
||||
public RCons ();
|
||||
[CCode (cname="Color_RED")]
|
||||
public static const string RED;
|
||||
#if 0
|
||||
BLACK,
|
||||
BGRED,
|
||||
WHITE,
|
||||
RESET,
|
||||
MAGENTA,
|
||||
YELLOW,
|
||||
TURQOISE,
|
||||
BLUE,
|
||||
GRAY,
|
||||
/* TODO: bold colors */
|
||||
}
|
||||
#endif
|
||||
public static bool init (); /* you have to call this before using it */
|
||||
|
||||
public static bool is_interactive;
|
||||
@ -15,16 +31,24 @@ namespace Radare {
|
||||
public static int rows;
|
||||
public static int columns;
|
||||
|
||||
public static void clear();
|
||||
public static void clear00();
|
||||
public static void reset();
|
||||
public static void gotoxy(int x, int y);
|
||||
public static void set_raw(bool b);
|
||||
|
||||
/* output */
|
||||
public static void printf(string fmt, ...);
|
||||
public static void strcat(string str);
|
||||
public static void memcat(string str, int len);
|
||||
public static void newline();
|
||||
public static void flush();
|
||||
|
||||
//public static int fgets(out string buf, int len, int argc, string argv[]);
|
||||
/* input */
|
||||
public static int readchar();
|
||||
public static void any_key();
|
||||
public static int get_size(out int rows);
|
||||
//public static int get_columns();
|
||||
//public static int get_real_columns();
|
||||
public static bool yesno(bool def, string fmt, ...);
|
||||
}
|
||||
}
|
||||
|
93
swig/python/r_cons.i.experimental
Normal file
93
swig/python/r_cons.i.experimental
Normal file
@ -0,0 +1,93 @@
|
||||
%module r_cons
|
||||
%{
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
#include <r_cons.h>
|
||||
%}
|
||||
%include <r_cons.h>
|
||||
|
||||
extern bool r_cons_init ();
|
||||
extern bool r_cons_eof ();
|
||||
extern void r_cons_clear ();
|
||||
extern void r_cons_clear00 ();
|
||||
extern void r_cons_reset ();
|
||||
extern void r_cons_gotoxy (int x, int y);
|
||||
extern void r_cons_set_raw (bool b);
|
||||
extern void r_cons_printf (const char* fmt);
|
||||
extern void r_cons_strcat (const char* str);
|
||||
extern void r_cons_memcat (const char* str, int len);
|
||||
extern void r_cons_newline ();
|
||||
extern void r_cons_flush ();
|
||||
extern int r_cons_readchar ();
|
||||
extern void r_cons_any_key ();
|
||||
extern int r_cons_get_size (int* rows);
|
||||
extern bool r_cons_yesno (bool def, const char* fmt);
|
||||
|
||||
//%rename(r_cons_is_html) jeje;
|
||||
%inline %{
|
||||
//#define RCons_is_html r_cons_is_html
|
||||
extern int r_cons_is_html;
|
||||
%}
|
||||
|
||||
%extend RCons {
|
||||
RCons () {
|
||||
return r_cons_new ();
|
||||
}
|
||||
|
||||
~RCons () {
|
||||
r_cons_free (self);
|
||||
}
|
||||
|
||||
bool init () {
|
||||
return r_cons_init ();
|
||||
}
|
||||
bool eof () {
|
||||
return r_cons_eof ();
|
||||
}
|
||||
void clear () {
|
||||
r_cons_clear ();
|
||||
}
|
||||
void clear00 () {
|
||||
r_cons_clear00 ();
|
||||
}
|
||||
void reset () {
|
||||
r_cons_reset ();
|
||||
}
|
||||
void gotoxy (int x, int y) {
|
||||
r_cons_gotoxy (x, y);
|
||||
}
|
||||
void set_raw (bool b) {
|
||||
r_cons_set_raw (b);
|
||||
}
|
||||
void printf (const char* fmt) {
|
||||
r_cons_printf (fmt);
|
||||
}
|
||||
void strcat (const char* str) {
|
||||
r_cons_strcat (str);
|
||||
}
|
||||
void memcat (const char* str, int len) {
|
||||
r_cons_memcat (str, len);
|
||||
}
|
||||
void newline () {
|
||||
r_cons_newline ();
|
||||
}
|
||||
void flush () {
|
||||
r_cons_flush ();
|
||||
}
|
||||
int readchar () {
|
||||
return r_cons_readchar ();
|
||||
}
|
||||
void any_key () {
|
||||
r_cons_any_key ();
|
||||
}
|
||||
%apply int* OUTPUT { int* rows };
|
||||
int get_size (int* rows) {
|
||||
return r_cons_get_size (rows);
|
||||
}
|
||||
bool yesno (bool def, const char* fmt) {
|
||||
return r_cons_yesno (def, fmt);
|
||||
}
|
||||
};
|
||||
//} RCons;
|
||||
|
23
swig/python/test-r_cons.py
Normal file
23
swig/python/test-r_cons.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
from r_cons import RCons, Color_RED, Color_GREEN, Color_RESET, RCons_is_html
|
||||
|
||||
# Get the singleton instance
|
||||
con = RCons()
|
||||
|
||||
# init is not necessary at all ..
|
||||
# the _new () should initialize the singleton
|
||||
# and return the instance itself
|
||||
#con.init()
|
||||
size = con.get_size()
|
||||
print "COLUMNS %d"%size[0]
|
||||
print "ROWS %d"%size[1]
|
||||
|
||||
con.printf("Hello World\n")
|
||||
con.flush()
|
||||
|
||||
con.any_key()
|
||||
con.clear()
|
||||
|
||||
print "IS HTML %d"%RCons_is_html
|
||||
con.printf(Color_RED + "Hello "+Color_GREEN + "World\n" + Color_RESET)
|
||||
con.flush();
|
Loading…
Reference in New Issue
Block a user