Remove 2048, stiv, unused files (#57)

This commit is contained in:
Anton Kochkov 2020-10-30 17:44:01 +08:00 committed by GitHub
parent 2c3a62e6f1
commit bcfb5b067a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 4 additions and 513 deletions

View file

@ -1,195 +0,0 @@
/* rizin - LGPL - Copyright 2008-2020 - pancake */
#include <rz_cons.h>
static ut8 twok_buf[4][4];
static int score = 0;
static int moves = 0;
static void twok_init(void) {
int i, j;
score = 0;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
twok_buf[i][j] = 0;
}
}
}
static void twok_add(void) {
int i, j;
while (true) {
i = rz_num_rand (4);
j = rz_num_rand (4);
if (!twok_buf[i][j]) {
twok_buf[i][j] = 1 + (rz_num_rand (10) == 1);
break;
}
}
}
static bool twok_fin(void) {
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (!twok_buf[i][j]) {
return true;
}
}
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
if (twok_buf[i][j] == twok_buf[i][j + 1]) {
return true;
}
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
if (twok_buf[i][j] == twok_buf[i + 1][j]) {
return true;
}
}
}
return false;
}
static void twok_move(int u, int v) {
int i, j, k;
int nKI = 0, nKJ = 0, nIK = 0, nJK = 0;
int moved = 0;
for (k = 0; k < 4; k++) {
for (i = 0; i < 4; i++) {
for (j = i + 1; j < 4 && !twok_buf[nKJ = u ? k : v ? j : 3 - j][nJK = !u ? k : v ? j : 3 - j]; j++) {
;
}
if (j == 4) {
continue;
}
nKI = u? k: v? i: 3 - i;
nIK = !u? k: v? i: 3 - i;
if (!twok_buf[nKI][nIK]) {
twok_buf[nKI][nIK] = twok_buf[nKJ][nJK];
twok_buf[nKJ][nJK] = 0;
--i;
moved = 1;
} else if (twok_buf[nKI][nIK] == twok_buf[nKJ][nJK]) {
score += 1 << ++twok_buf[nKI][nIK];
twok_buf[nKJ][nJK] = 0;
moved = 1;
}
}
}
if (moved) {
twok_add ();
moves++;
}
}
static void getval(bool color, char *val0, int i, int x) {
const char * colorarray[] = {
Color_WHITE,
Color_RED,
Color_GREEN,
Color_MAGENTA,
Color_YELLOW,
Color_CYAN,
Color_BLUE,
Color_GRAY
};
if (twok_buf[i][x]) {
if (color) {
snprintf (val0,31, "%s%4d"Color_RESET, colorarray [twok_buf [i][x] % 8 ], 1 << twok_buf[i][x]);
} else {
snprintf (val0,31, "%4d", 1 << twok_buf[i][x]);
}
} else {
strcpy (val0, " ");
}
}
static void twok_print(bool color) {
char val0[32];
char val1[32];
char val2[32];
char val3[32];
int i;
if (color) {
printf (Color_BBLUE" +------+------+------+------+\n");
} else {
printf (" +------+------+------+------+\n");
}
for (i = 0; i < 4; i++) {
getval (color, val0, i, 0);
getval (color, val1, i, 1);
getval (color, val2, i, 2);
getval (color, val3, i, 3);
if (color) {
printf (Color_BBLUE" | | | | |\n");
printf (" |"Color_RESET" %s "Color_BBLUE"|"Color_RESET" %s "
Color_BBLUE"|"Color_RESET" %s "Color_BBLUE"|"Color_RESET" %s "Color_BBLUE"|\n",
val0, val1, val2, val3);
printf (" | | | | |\n");
printf (" +------+------+------+------+\n"Color_RESET);
} else {
printf (" | | | | |\n");
printf (" | %s | %s | %s | %s |\n",
val0, val1, val2, val3);
printf (" | | | | |\n");
printf (" +------+------+------+------+\n");
}
}
printf ("Hexboard: 'hjkl' and 'q'uit\n");
for (i = 0; i < 4; i++) {
printf (" %02x %02x %02x %02x\n",
twok_buf[i][0], twok_buf[i][1],
twok_buf[i][2], twok_buf[i][3]);
}
}
RZ_API void rz_cons_2048(bool color) {
int ch;
rz_cons_set_raw (1);
twok_init ();
twok_add ();
twok_add ();
while (twok_fin ()) {
rz_cons_clear00 ();
if (color) {
rz_cons_printf (Color_GREEN"[r2048]"Color_BYELLOW" score: %d moves: %d\n"Color_RESET, score, moves);
} else {
rz_cons_printf ("[r2048] score: %d moves: %d\n", score, moves);
}
rz_cons_flush ();
twok_print (color);
ch = rz_cons_readchar ();
ch = rz_cons_arrow_to_hjkl (ch);
switch (ch) {
case 'h':
twok_move (1, 1);
break;
case 'j':
twok_move (0, 0);
break;
case 'k':
twok_move (0, 1);
break;
case 'l':
twok_move (1, 0);
break;
}
if (ch < 1 || ch == 'q') {
break;
}
}
rz_cons_clear00 ();
rz_cons_printf ("[r2048] score: %d\n", score);
rz_cons_flush ();
twok_print (color);
rz_cons_printf ("\n [r2048.score] %d\n", score);
do {
ch = rz_cons_any_key ("Press 'q' to quit.");
} while (ch != 'q' && ch >= 1);
rz_cons_set_raw (0);
}

View file

@ -2,8 +2,8 @@ include ../config.mk
NAME=rz_cons
OBJS=cons.o cpipe.o output.o grep.o less.o more.o pager.o cutf8.o
OBJS+=line.o hud.o rgb.o input.o pal.o editor.o 2048.o html.o
OBJS+=canvas.o canvas_line.o stiv.o
OBJS+=line.o hud.o rgb.o input.o pal.o editor.o html.o
OBJS+=canvas.o canvas_line.o
RZ_DEPS=rz_util
include ../rules.mk

View file

@ -1,5 +1,4 @@
rz_cons_sources = [
'2048.c',
'canvas.c',
'canvas_line.c',
'cons.c',
@ -10,7 +9,6 @@ rz_cons_sources = [
'hud.c',
'input.c',
'less.c',
'stiv.c',
'line.c',
'more.c',
'output.c',

View file

@ -1,169 +0,0 @@
/* tiv - terminal image viewer - MIT 2013-2019 - pancake */
#include <rz_cons.h>
#define XY(b,x,y) ( b+((y)*(w*3))+(x*3) )
#define ABS(x) (((x)<0)?-(x):(x))
#define POND(x,y) (ABS((x)) * (y))
void (*renderer)(PrintfCallback cb_printf, const ut8*, const ut8 *);
static int reduce8 (int r, int g, int b) {
int colors_len = 8;
int select = 0;
int odistance = -1;
int i, k = 1;
int colors[][3] = {
{ 0x00,0x00,0x00 }, // black
{ 0xd0,0x10,0x10 }, // red
{ 0x10,0xe0,0x10 }, // green
{ 0xf7,0xf5,0x3a }, // yellow
{ 0x10,0x10,0xf0 }, // blue // XXX
{ 0xfb,0x3d,0xf8 }, // pink
{ 0x10,0xf0,0xf0 }, // turqoise
{ 0xf0,0xf0,0xf0 }, // white
};
r /= k; r *= k;
g /= k; g *= k;
b /= k; b *= k;
// B&W
if (r<30 && g<30 && b<30) return 0;
if (r>200&& g>200&& b>200) return 7;
odistance = -1;
for (i = 0; i<colors_len; i++) {
int distance =
POND (colors[i][0]-r, r)
+ POND (colors[i][1]-g, g)
+ POND (colors[i][2]-b, b);
if (odistance == -1 || distance < odistance) {
odistance = distance;
select = i;
}
}
return select;
}
static void render_ansi(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
int fg = 0;
int color = reduce8 (c[0], c[1], c[2]);
if (color == -1)return;
//if (c[0]<30 && c[1]<30 && c[2]<30) fg = 1;
cb_printf ("\x1b[%dm", color+(fg?30:40));
}
static int rgb(int r, int g, int b) {
r = RZ_DIM (r, 0, 255);
g = RZ_DIM (g, 0, 255);
b = RZ_DIM (b, 0, 255);
r = (int)(r/50.6);
g = (int)(g/50.6);
b = (int)(b/50.6);
return 16 + (r*36) + (g*6) + b;
}
static void render_256(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
cb_printf ("\x1b[%d;5;%dm", 38, rgb (c[0], c[1], c[2]));
cb_printf ("\x1b[%d;5;%dm", 48, rgb (d[0], d[1], d[2]));
}
static void render_rgb(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
cb_printf ("\x1b[38;2;%d;%d;%dm", c[0], c[1], c[2]);
cb_printf ("\x1b[48;2;%d;%d;%dm", d[0], d[1], d[2]);
}
static void render_greyscale(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
int color1, color2, k;
color1 = (c[0]+c[1]+c[2]) / 3;
color2 = (d[0]+d[1]+d[2]) / 3;
k = 231 + ((int)((float)color1/10.3));
if (k<232) k = 232;
cb_printf ("\x1b[%d;5;%dm", 48, k); // bg
k = 231 + ((int)((float)color2/10.3));
if (k<232) k = 232;
cb_printf ("\x1b[%d;5;%dm", 38, k); // fg
}
static void render_ascii(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
const char *pal = " `.,-:+*%$#";
int idx, pal_len = strlen (pal);
float p = (c[0]+c[1]+c[2])/3;
float q = (d[0]+d[1]+d[2])/3;
idx = ((p+q)/2) / (255/pal_len);
if (idx >= pal_len) idx = pal_len-1;
cb_printf ("%c", pal[idx]);
}
static void dorender (PrintfCallback cb_printf, const ut8 *buf, int len, int w, int h) {
const ut8 *c, *d;
int x, y;
for (y=0; y<h; y+=2) {
for (x=0; x<w; x++) {
c = XY (buf, x, y);
d = XY (buf, x, y+1);
if (d> (buf+len)) break;
renderer (cb_printf, c, d);
if (renderer != render_ascii) {
render_ascii (cb_printf, c, d);
}
}
cb_printf ((renderer==render_ascii)?"\n":"\x1b[0m\n");
}
}
static void selectrenderer(int mode) {
switch (mode) {
case 'a':
renderer = render_ascii;
break;
case 'A':
renderer = render_ansi;
break;
case 'g': renderer = render_greyscale; break;
case '2': renderer = render_256; break;
default:
renderer = render_rgb;
break;
}
}
RZ_API void rz_cons_image(const ut8 *buf, int bufsz, int width, int mode) {
int height = (bufsz / width) / 3;
selectrenderer (mode);
dorender (rz_cons_printf, buf, bufsz, width, height);
}
#if 0
int
main(int argc, const char **argv) {
ut8 *buf, *c, *d;
int n, x, y, w, h, imgsz, readsz;
if (argc<3) {
printf ("stiv . suckless terminal image viewer\n");
printf ("Usage: stiv [width] [height] [ascii|ansi|grey|256|rgb] < rgb24\n");
return 1;
}
w = atoi (argv[1]);
h = atoi (argv[2]);
if (argc>3) {
selectrenderer (argv[3]);
} else renderer = render_rgb;
if (w<1 || h<1) {
printf ("Invalid arguments\n");
return 1;
}
imgsz = w * h * 3;
buf = malloc (imgsz);
readsz = 0;
do {
n = read(0, buf+readsz, imgsz);
if (n<1) break;
readsz += n;
} while (readsz < imgsz);
dorender (buf, readsz, w, h);
free (buf);
return 0;
}
#endif

View file

@ -90,7 +90,6 @@ static const char* help_msg_pr[] = {
"Usage: pr[glx]", "[size]", "print N raw bytes",
"prc", "[=fep..]", "print bytes as colors in palette",
"prg", "[?]", "print raw GUNZIPped block",
"pri", "[aA2r]", "print raw image, honor hex.cols",
"prl", "", "print raw with lines offsets",
"prx", "", "printable chars with real offset (hyew)",
"prz", "", "print raw zero terminated string",
@ -5803,17 +5802,6 @@ l = use_blocksize;
break;
case 'r': // "pr"
switch (input[1]) {
case 'i': // "pri" // color raw image
{
// TODO: do colormap and palette conversions here
int mode = 0;
if (rz_config_get (core->config, "scr.color") == 0) {
mode = 'a';
}
int cols = rz_config_get_i (core->config, "hex.cols");
rz_cons_image (core->block, core->blocksize, cols, mode);
}
break;
case 'c': // "prc" // color raw dump
if (input[2] == '?') {
rz_cons_printf ("prc=e # colorblocks of entropy\n");

View file

@ -159,7 +159,7 @@ static const char *menus_settings_screen[] = {
static const char *menus_Help[] = {
"Toggle Help",
"License", "Version",
"Fortune", "2048",
"Fortune",
NULL
};
@ -196,7 +196,6 @@ static const char *help_msg_panels[] = {
"_", "start the hud input mode",
"\\", "show the user-friendly hud",
"?", "show this help",
"!", "run r2048 game",
".", "seek to PC or entrypoint",
"*", "show decompiler in the current panel",
"\"", "create a panel from the list and replace the current one",
@ -515,7 +514,6 @@ static int __watch_points_cb(void *user);
static int __references_cb(void *user);
static int __help_cb(void *user);
static int __fortune_cb(void *user);
static int __game_cb(void *user);
static int __license_cb(void *user);
static int __version_cb(void *user);
static int __quit_cb(void *user);
@ -3761,12 +3759,6 @@ int __fortune_cb(void *user) {
return 0;
}
int __game_cb(void *user) {
RzCore *core = (RzCore *)user;
rz_cons_2048 (core->panels->can->color);
return 0;
}
int __help_cb(void *user) {
RzCore *core = (RzCore *)user;
__toggle_help (core);
@ -4762,8 +4754,6 @@ bool __init_panels_menu(RzCore *core) {
__add_menu (core, parent, menus_Help[i], __version_cb);
} else if (!strcmp (menus_Help[i], "Fortune")) {
__add_menu (core, parent, menus_Help[i], __fortune_cb);
} else if (!strcmp (menus_Help[i], "2048")) {
__add_menu (core, parent, menus_Help[i], __game_cb);
} else {
__add_menu (core, parent, menus_Help[i], __help_cb);
}

View file

@ -1,77 +0,0 @@
#!/bin/sh
#
# Usage : perl depgraph.pl dot | dot -Tpng > deps.png
#
grep -e DEPS */Makefile | sed -e 's,/Makefile,,' > /tmp/rdeps.txt
if [ -z "$1" ]; then
MODE=dot
#MODE=gml
MODE=r2
else
MODE="$1"
fi
if [ "$MODE" = "-h" ]; then
echo "Usage: depgraph [r2|dot|gml]"
exit 0
elif [ $MODE = "r2" ]; then
cat /tmp/rdeps.txt | perl -ne '
use List::MoreUtils qw(uniq);
/(.*):(.*)=(.*)$/;
my $lib=$1;
@deps=split(/ /, $3);
foreach $dep (uniq @deps) {
print "agn $dep\n";
}
foreach $dep (@deps) {
print "age $dep r_$lib\n";
}'
echo "agg"
elif [ $MODE = "dot" ]; then
echo "digraph G {"
cat /tmp/rdeps.txt | perl -ne '
/(.*):(.*)=(.*)$/;
my $lib=$1;
@deps=split(/ /, $3);
foreach $dep (@deps) {
print " $dep -> r_$lib;\n";
}';
echo "}";
else
echo "graph [";
#cat /tmp/rdeps.txt | cut -d : -f 1 | perl -ne '
# /(.*)/
#';
cat /tmp/rdeps.txt | perl -ne '
BEGIN { $id = 0; my %libs={}; }
/(.*):(.*)=(.*)$/;
my $lib=$1;
$id++;
unless($libs{"r_$lib"}) {
print "node [\n id \"r_$lib\"\n label \"r_$lib\"\n]\n";
print STDERR "r_$lib\n";
$libs{"r_$lib"}=1;
}
$libs["r_$lib"]=1;
@deps=split(/ /, $3);
foreach $dep (@deps) {
unless ($libs{$dep}) {
print STDERR "$dep ***\n";
print "node [\n id \"$dep\"\n label \"$dep\"\n]\n";
$libs{$dep} = 1;
}
#print "edge [\n source \"r_$lib\"\n target \"$dep\"\n]\n"
print "edge [\n source \"$dep\"\n target \"r_$lib\"\n]\n"
#print " $dep -> r_$lib;\n";
}';
echo "]";
fi

View file

@ -798,7 +798,6 @@ typedef struct rz_cons_canvas_line_style_t {
#ifdef RZ_API
RZ_API void rz_cons_image(const ut8 *buf, int bufsz, int width, int mode);
RZ_API RzConsCanvas* rz_cons_canvas_new(int w, int h);
RZ_API void rz_cons_canvas_free(RzConsCanvas *c);
RZ_API void rz_cons_canvas_clear(RzConsCanvas *c);
@ -910,7 +909,6 @@ RZ_API void rz_cons_print_fps (int col);
RZ_API void rz_cons_last(void);
RZ_API int rz_cons_less_str(const char *str, const char *exitkeys);
RZ_API void rz_cons_less(void);
RZ_API void rz_cons_2048(bool color);
RZ_API void rz_cons_memset(char ch, int len);
RZ_API void rz_cons_visual_flush(void);
RZ_API void rz_cons_visual_write(char *buffer);

View file

@ -1,11 +0,0 @@
LIBS0= util
LIBS1= hash socket
LIBS2=
LIBS3= fs #anal bin parse
LIBS4=
LIBS5=
LIBS6=
LIBS7=
LIBS8=
LIBS=$(LIBS0) $(LIBS1) $(LIBS2) $(LIBS3) $(LIBS4) $(LIBS5) $(LIBS6) $(LIBS7) $(LIBS8)

View file

@ -10,7 +10,7 @@ FILE=$1
PFX=$2
LIST=$1.list
if [ "${PFX}" = "r_util" ]; then
if [ "${PFX}" = "rz_util" ]; then
echo "=> No stripping any symbol in librz_util O:)"
exit 0
PFX="r_"

View file

@ -1,31 +0,0 @@
#!/bin/sh
t="/tmp/symgraph"
rm -rf "$t"
mkdir -p "$t/b" "$t/l"
if [ "`uname`" = Darwin ]; then
SO=dylib
else
SO=so
fi
dolib() {
rz_bin -i $1/libr_$1.${SO} | grep -v mports | cut -d = -f 6 > $t/l/$1.i
rz_bin -s $1/libr_$1.${SO} | grep -v xports | cut -d = -f 6 > $t/l/$1.s
}
dobin() {
rz_bin -i ../binrz/$1/$1 | grep -v mports | cut -d = -f 9 > $t/b/$1.i
# rz_bin -s ../binrz/$1/$1 | cut -d = -f 8 > $t/b/$1.s
}
LIBS="anal asm bin bp config cons crypto debug diff flags hash io lang parse reg search socket syscall util core"
for a in $LIBS ; do
dolib ${a}
done
BINS="rz_bin rz_asm rizin rz_ax ranal2 rz_hash rz_diff rz_find rz_agent"
for a in $BINS ; do
dobin ${a}
done
cat $t/l/*.i $t/l/*.s $t/b/*.i | sort | uniq -c | sort -n | grep r_