Remove pending newabi stuff from RCons

This commit is contained in:
pancake 2024-11-22 17:31:39 +01:00
parent f69820c46e
commit 4213649eca
6 changed files with 6 additions and 209 deletions

View File

@ -58,23 +58,19 @@ typedef struct {
void *event_interrupt_data;
} RConsBreakStack;
#if R2_USE_NEW_ABI
static void r_cons_grep_word_free(RConsGrepWord *gw) {
if (gw) {
free (gw->str);
free (gw);
}
}
#endif
static void cons_grep_reset(RConsGrep *grep) {
if (grep) {
R_FREE (grep->str);
ZERO_FILL (*grep);
#if R2_USE_NEW_ABI
r_list_free (grep->strings);
grep->strings = r_list_newf ((RListFree)r_cons_grep_word_free);
#endif
grep->line = -1;
grep->sort = -1;
grep->sort_invert = false;
@ -923,17 +919,10 @@ R_API int r_cons_get_buffer_len(void) {
R_API void r_cons_filter(void) {
/* grep */
#if R2_USE_NEW_ABI
if (C->filter || r_list_length (C->grep.strings) > 0 || C->grep.tokens_used || C->grep.less || C->grep.json) {
(void)r_cons_grepbuf ();
C->filter = false;
}
#else
if (C->filter || C->grep.nstrings > 0 || C->grep.tokens_used || C->grep.less || C->grep.json) {
(void)r_cons_grepbuf ();
C->filter = false;
}
#endif
/* html */
if (C->is_html) {
int newlen = 0;
@ -1039,11 +1028,7 @@ R_API void r_cons_last(void) {
static bool lastMatters(void) {
return (C->buffer_len > 0 &&
#if R2_USE_NEW_ABI
(C->lastEnabled && !C->filter && r_list_empty (C->grep.strings))
#else
(C->lastEnabled && !C->filter && C->grep.nstrings < 1)
#endif
(C->lastEnabled && !C->filter && r_list_empty (C->grep.strings)) \
&& !C->grep.tokens_used && !C->grep.less \
&& !C->grep.json && !C->is_html);
}

View File

@ -703,7 +703,6 @@ R_API const char *r_line_hist_get(int n) {
return NULL;
}
#if R2_USE_NEW_ABI
R_API int r_line_hist_list(bool full) {
int i = 0;
inithist ();
@ -716,19 +715,6 @@ R_API int r_line_hist_list(bool full) {
}
return i;
}
#else
R_API int r_line_hist_list(void) {
int i = 0;
inithist ();
if (I.history.data) {
for (i = 0; i < I.history.size && I.history.data[i]; i++) {
const char *pad = r_str_pad (' ', 32 - strlen (I.history.data[i]));
r_cons_printf ("%s %s # !%d\n", I.history.data[i], pad, i);
}
}
return i;
}
#endif
R_API void r_line_hist_free(void) {
int i;
@ -763,9 +749,7 @@ R_API bool r_line_hist_load(const char *file) {
}
memset (buf, 0, R_LINE_BUFSIZE);
}
#if R2_USE_NEW_ABI
I.history.load_index = I.history.index;
#endif
fclose (fd);
free (buf);
return true;
@ -2428,11 +2412,7 @@ _end:
// shouldnt be here
if (r_str_startswith (I.buffer.data, "!history")) {
#if R2_USE_NEW_ABI
r_line_hist_list (true);
#else
r_line_hist_list ();
#endif
return "";
}
return I.buffer.data[0] != '\0'? I.buffer.data: "";

View File

@ -22,14 +22,12 @@ static char *strchr_ns(char *s, const char ch) {
return p;
}
#if R2_USE_NEW_ABI
static void r_cons_grep_word_free(RConsGrepWord *gw) {
if (gw) {
free (gw->str);
free (gw);
}
}
#endif
static RCoreHelpMessage help_detail_tilde = {
"Usage: [command]~[modifier][word,word][endmodifier][[column]][:line]\n"
@ -140,11 +138,9 @@ R_API void r_cons_grep_expression(const char *str) {
ctx->sorted_column = 0;
size_t i;
for (i = 0; i < ptrs_length; i++) {
#if R2_USE_NEW_ABI
bool gw_begin = false;
bool gw_neg = false;
bool gw_end = false;
#endif
ptr = ptrs[i];
end_ptr = ptr2 = ptr3 = NULL;
while (*ptr) {
@ -254,7 +250,6 @@ R_API void r_cons_grep_expression(const char *str) {
goto while_end;
}
break;
#if R2_USE_NEW_ABI
case '^':
ptr++;
gw_begin = true;
@ -263,16 +258,6 @@ R_API void r_cons_grep_expression(const char *str) {
ptr++;
gw_neg = true;
break;
#else
case '^':
ptr++;
grep->begin[grep->nstrings] = true;
break;
case '!':
ptr++;
grep->neg[grep->nstrings] = true;
break;
#endif
case '?':
ptr++;
grep->counter = 1;
@ -377,11 +362,7 @@ R_API void r_cons_grep_expression(const char *str) {
len = strlen (ptr) - 1;
if (len > 1 && ptr[len] == '$' && ptr[len - 1] != '\\') {
#if R2_USE_NEW_ABI
gw_end = true;
#else
grep->end[i] = true;
#endif
ptr[len] = '\0';
}
@ -402,7 +383,6 @@ R_API void r_cons_grep_expression(const char *str) {
if (!wlen) {
continue;
}
#if R2_USE_NEW_ABI
RConsGrepWord *gw = R_NEW0 (RConsGrepWord);
gw->str = strdup (optr);
gw->begin = gw_begin;
@ -410,23 +390,9 @@ R_API void r_cons_grep_expression(const char *str) {
gw->end = gw_end;
gw_end = false;
r_list_append (grep->strings, gw);
#else
if (wlen >= R_CONS_GREP_WORD_SIZE - 1) {
R_LOG_ERROR ("grep string too long");
continue;
}
grep->nstrings++;
if (grep->nstrings > R_CONS_GREP_WORDS - 1) {
R_LOG_ERROR ("too many grep strings");
break;
}
r_str_ncpy (grep->strings[grep->nstrings - 1],
optr, R_CONS_GREP_WORD_SIZE);
#endif
} while (ptr);
}
}
#if R2_USE_NEW_ABI
// XXX this is a hack
if (!grep->str) {
RConsGrepWord *gw = R_NEW0 (RConsGrepWord);
@ -434,13 +400,6 @@ R_API void r_cons_grep_expression(const char *str) {
grep->str = strdup ("");
r_list_append (grep->strings, gw);
}
#else
if (!grep->str) {
grep->str = strdup ("");
grep->nstrings++;
grep->strings[0][0] = 0;
}
#endif
}
// Finds and returns next intgrep expression,
@ -895,21 +854,9 @@ R_API void r_cons_grepbuf(void) {
cons->context->grep_color = true;
// R2R db/cmd/cmd_iz
R_FREE (grep->str);
#if R2_USE_NEW_ABI
cons->context->grep_color = false;
RConsGrepWord *gw = r_list_pop_head (grep->strings);
r_cons_grep_word_free (gw);
#else
if (grep->nstrings > 0) {
cons->context->grep_color = false;
// shift them all!!
int i;
for (i = 0; i < grep->nstrings; i++) {
r_str_cpy (grep->strings[i], grep->strings[i + 1]);
}
grep->nstrings--;
}
#endif
if (grep->hud) {
grep->hud = false;
r_cons_hud_string (cons->context->buffer);
@ -921,15 +868,9 @@ R_API void r_cons_grepbuf(void) {
return;
}
}
#if R2_USE_NEW_ABI
if (r_list_empty (grep->strings)) {
return;
}
#else
if (grep->nstrings < 1) {
return;
}
#endif
buf = cons->context->buffer;
len = cons->context->buffer_len;
grep->range_line = 1;
@ -1034,7 +975,6 @@ continuation:
if (show) {
char *str = r_str_ndup (tline, ret);
if (cons->context->grep_highlight) {
#if R2_USE_NEW_ABI
RListIter *iter;
RConsGrepWord *gw;
r_list_foreach (grep->strings, iter, gw) {
@ -1048,20 +988,6 @@ continuation:
}
free (newstr);
}
#else
int i;
for (i = 0; i < grep->nstrings; i++) {
char *newstr = r_str_newf (Color_INVERT"%s"Color_RESET, grep->strings[i]);
if (str && newstr) {
if (grep->icase) {
str = r_str_replace_icase (str, grep->strings[i], newstr, 1, 1);
} else {
str = r_str_replace (str, grep->strings[i], newstr, 1);
}
}
free (newstr);
}
#endif
}
if (str) {
r_strbuf_append (ob, str);
@ -1176,18 +1102,13 @@ R_API int r_cons_grep_line(char *buf, int len) {
return 0;
}
memcpy (in, buf, len);
#if R2_USE_NEW_ABI
const bool have_strings = !r_list_empty (grep->strings);
#else
const bool have_strings = grep->nstrings > 0;
#endif
if (have_strings) {
bool all_hits = true;
if (grep->icase) {
r_str_case (in, false);
}
#if R2_USE_NEW_ABI
RListIter *iter;
RConsGrepWord *gw;
r_list_foreach (grep->strings, iter, gw) {
@ -1216,34 +1137,6 @@ R_API int r_cons_grep_line(char *buf, int len) {
break;
}
}
#else
for (i = 0; i < grep->nstrings; i++) {
char *str = grep->strings[i];
if (grep->icase) {
r_str_case (str, false);
}
const char *p = r_strstr_ansi (in, grep->strings[i]);
if (!p) {
hit = grep->neg[i];
all_hits &= hit;
continue;
}
hit = grep->begin[i]
? grep->neg[i]
? p != in
: p == in
: !grep->neg[i];
// TODO: optimize without strlen without breaking t/feat_grep (grep end)
if (grep->end[i] && (strlen (grep->strings[i]) != strlen (p))) {
hit = false;
}
all_hits &= hit;
if (!grep->amp) {
break;
}
}
#endif
if (grep->amp) {
hit = all_hits;
}

View File

@ -456,20 +456,6 @@ struct duplicate_flag_t {
const char *word;
};
#if !R2_USE_NEW_ABI
extern int Gload_index;
static void __line_hist_list(bool full) {
RLineHistory *hist = &r_cons_singleton()->line->history;
if (hist && hist->data) {
int i = full? 0: Gload_index;
for (; i < hist->size && hist->data[i]; i++) {
const char *pad = r_str_pad (' ', 32 - strlen (hist->data[i]));
r_cons_printf ("%s %s # !%d\n", hist->data[i], pad, i);
}
}
}
#endif
static bool duplicate_flag(RFlagItem *flag, void *u) {
struct duplicate_flag_t *user = (struct duplicate_flag_t *)u;
/* filter per flag spaces */
@ -3492,20 +3478,12 @@ static int cmd_system(void *data, const char *input) {
free (cmd);
}
} else {
#if R2_USE_NEW_ABI
r_line_hist_list (false);
#else
__line_hist_list (false);
#endif
}
}
break;
case '\0':
#if R2_USE_NEW_ABI
r_line_hist_list (true);
#else
r_line_hist_list ();
#endif
break;
case '?': // "!?"
cmd_help_exclamation (core);

View File

@ -58,13 +58,6 @@ extern "C" {
#define CONS_PALETTE_SIZE 22
#define CONS_COLORS_SIZE 21
#if R2_USE_NEW_ABI
// no limits
#else
#define R_CONS_GREP_WORDS 10
#define R_CONS_GREP_WORD_SIZE 64
#endif
// R2_600 - remove more limits
#define R_CONS_GREP_TOKENS 64
#define R_CONS_GREP_COUNT 10
@ -116,22 +109,15 @@ typedef struct {
const char *script;
} RConsTheme;
#if R2_USE_NEW_ABI
typedef struct r_cons_grep_word_t {
char *str;
bool neg;
bool begin;
bool end;
} RConsGrepWord;
#endif
typedef struct r_cons_grep_t {
#if R2_USE_NEW_ABI
RList *strings; // words
#else
char strings[R_CONS_GREP_WORDS][R_CONS_GREP_WORD_SIZE];
int nstrings;
#endif
char *str;
int counter;
bool charCounter;
@ -154,12 +140,6 @@ typedef struct r_cons_grep_t {
int amp;
int zoom;
int zoomy; // if set then its scaled unproportionally
#if R2_USE_NEW_ABI
#else
int neg[R_CONS_GREP_WORDS];
int begin[R_CONS_GREP_WORDS];
int end[R_CONS_GREP_WORDS];
#endif
bool xml;
bool icase;
bool ascart;
@ -1100,9 +1080,7 @@ typedef struct r_line_hist_t {
int top;
int autosave;
bool do_setup_match;
#if R2_USE_NEW_ABI
int load_index;
#endif
} RLineHistory;
typedef struct r_line_buffer_t {
@ -1197,11 +1175,7 @@ R_API int r_line_hist_add(const char *line);
R_API bool r_line_hist_save(const char *file);
R_API int r_line_hist_label(const char *label, void(*cb)(const char*));
R_API void r_line_label_show(void);
#if R2_USE_NEW_ABI
R_API int r_line_hist_list(bool full);
#else
R_API int r_line_hist_list(void);
#endif
R_API int r_line_hist_get_size(void);
R_API void r_line_hist_set_size(int size);
R_API const char *r_line_hist_get(int n);

View File

@ -4201,20 +4201,17 @@ R_API char *r_str_md2txt(const char *page, bool usecolor) {
int col = 0;
const int maxcol = 75;
bool codeblock = false;
bool contline = false;
bool title = false;
bool codeblockline = false;
while (*b) {
int ch = *b;
repeat:
switch (ch) {
case 10:
case 10: // '\n'
if (codeblock || title) {
const int j = title? maxcol + 2: maxcol - 4;
if (usecolor) {
if (!contline) {
fill_line (sb, j - col);
}
fill_line (sb, j - col);
if (title) {
r_strbuf_append (sb, Color_BLACK);
r_strbuf_append (sb, Color_BGBLUE);
@ -4223,11 +4220,7 @@ repeat:
}
title = false;
}
if (contline) {
contline = false;
} else {
col = 0;
}
col = 0;
if (usecolor) {
r_strbuf_append (sb, Color_RESET);
}
@ -4262,13 +4255,6 @@ repeat:
} else {
r_strbuf_append (sb, "-");
}
#if 0
contline = true;
if (codeblock) {
r_strbuf_append (sb, "\n");
col = 0;
}
#endif
}
b--;
goto repeat;
@ -4283,7 +4269,8 @@ repeat:
r_strbuf_append (sb, Color_RESET_BG);
}
continue;
} else if (!codeblock && r_str_startswith (b, "###")) {
}
if (!codeblock && r_str_startswith (b, "###")) {
if (usecolor) {
r_strbuf_append (sb, Color_BLACK);
r_strbuf_append (sb, Color_BGBLUE);