/* umf..this should probably be outside this file */ R_API char* r_anal_reflines_str(RAnal *anal, RAnalRefline *list, ut64 addr, int opts) { int l, linestyle = opts & R_ANAL_REFLINE_TYPE_STYLE; int dir = 0, wide = opts & R_ANAL_REFLINE_TYPE_WIDE; char ch = ' ', *str = NULL; struct list_head *pos; RAnalRefline *ref; if (!list) return NULL; str = r_str_concat (str, " "); for (pos = linestyle?(&(list->list))->next:(&(list->list))->prev; pos != (&(list->list)); pos = linestyle?pos->next:pos->prev) { ref = list_entry (pos, RAnalRefline, list); dir = (addr == ref->to)? 1: (addr == ref->from)? 2: dir; if (addr == ref->to) { str = r_str_concat (str, (ref->from>ref->to)?".":"`"); ch = '-'; } else if (addr == ref->from) { str = r_str_concat (str, (ref->from>ref->to)?"`":","); ch = '='; } else if (ref->from < ref->to) { if (addr > ref->from && addr < ref->to) { if (ch=='-'||ch=='=') str = r_str_concatch (str, ch); else str = r_str_concatch (str, '|'); } else str = r_str_concatch (str, ch); } else { if (addr < ref->from && addr > ref->to) { if (ch=='-'||ch=='=') str = r_str_concatch (str, ch); else str = r_str_concatch (str, '|'); } else str = r_str_concatch (str, ch); } if (wide) str = r_str_concatch (str, (ch=='='||ch=='-')?ch:' '); } str = r_str_concat (str, (dir==1)?"-> ":(dir==2)?"=< ":" "); if (anal->lineswidth>0) { l = strlen (str); if (l>anal->lineswidth) r_str_cpy (str, str+l-anal->lineswidth); } for (l = anal->lineswidth-strlen (str);l-->0;) str = r_str_prefix (str, " "); return str; }
// TODO: move into another file // TODO: this is TOO SLOW. do not iterate over all reflines or gtfo R_API char* r_anal_reflines_str(void *core, ut64 addr, int opts) { int l, linestyle = opts & R_ANAL_REFLINE_TYPE_STYLE; int dir = 0, wide = opts & R_ANAL_REFLINE_TYPE_WIDE; char ch = ' ', *str = NULL; struct list_head *pos; RAnalRefline *ref, *list = ((RCore*)core)->reflines; if (!list) return NULL; str = r_str_concat (str, " "); for (pos = linestyle?(&(list->list))->next:(&(list->list))->prev; pos != (&(list->list)); pos = linestyle?pos->next:pos->prev) { ref = list_entry (pos, RAnalRefline, list); dir = (addr == ref->to)? 1: (addr == ref->from)? 2: dir; if (addr == ref->to) { str = r_str_concat (str, (ref->from>ref->to)? "." : "`"); ch = '-'; } else if (addr == ref->from) { str = r_str_concat (str, (ref->from>ref->to)? "`" : "," ); ch = '='; } else if (ref->from < ref->to) { if (addr > ref->from && addr < ref->to) { if (ch=='-' || ch=='=') str = r_str_concatch (str, ch); //else str = r_str_concat (str, ((RCore*)core)->cons->vline[LINE_VERT]); else str = r_str_concatch (str, '|'); } else str = r_str_concatch (str, ch); } else { if (addr < ref->from && addr > ref->to) { if (ch=='-' || ch=='=') str = r_str_concatch (str, ch); //else str = r_str_concat (str, ((RCore*)core)->cons->vline[LINE_VERT]); else str = r_str_concatch (str, '|'); } else str = r_str_concatch (str, ch); } if (wide) str = r_str_concatch (str, (ch=='=' || ch=='-')? ch : ' '); } //str = r_str_concat (str, (dir==1)?"-> ":(dir==2)?"=< ":" "); str = r_str_concat (str, (dir==1)? "-> " :(dir==2)? "=< " : " "); if (((RCore*)core)->anal->lineswidth>0) { l = r_str_len_utf8 (str); if (l > ((RCore*)core)->anal->lineswidth) r_str_cpy (str, str + l - ((RCore*)core)->anal->lineswidth); } /* HACK */ if (((RCore*)core)->utf8 && ((RCore*)core)->cons->vline) { RCons *cons = ((RCore*)core)->cons; //str = r_str_replace (str, "=", "-", 1); str = r_str_replace (str, "<", cons->vline[ARROW_LEFT], 1); str = r_str_replace (str, ">", cons->vline[ARROW_RIGHT], 1); str = r_str_replace (str, "|", cons->vline[LINE_VERT], 1); str = r_str_replace (str, "=", cons->vline[LINE_HORIZ], 1); str = r_str_replace (str, "-", cons->vline[LINE_HORIZ], 1); //str = r_str_replace (str, ".", "\xe2\x94\x8c", 1); str = r_str_replace (str, ",", cons->vline[LUP_CORNER], 1); str = r_str_replace (str, ".", cons->vline[LUP_CORNER], 1); str = r_str_replace (str, "`", cons->vline[LDWN_CORNER], 1); } if (((RCore*)core)->anal->lineswidth>0) { char pfx[128]; int l = ((RCore*)core)->anal->lineswidth-r_str_len_utf8 (str); memset (pfx, ' ', sizeof (pfx)); if (l>=sizeof(pfx)) l = sizeof (pfx)-1; pfx[l] = 0; str = r_str_prefix (str, pfx); } return str; }