R_API char *r_cons_canvas_to_string(RConsCanvas *c) { int x, y, olen = 0; char *o; const char* b; const char**atr; int is_first = R_TRUE; if (!c) return NULL; b = c->b; o = calloc (sizeof(char), (c->w * (c->h + 1)) * (CONS_MAX_ATTR_SZ)); if (!o) return NULL; for (y = 0; y < c->h; y++) { if (!is_first) { o[olen++] = '\n'; } is_first = R_FALSE; for (x = 0; x<c->w; x++) { const int p = x + (y * c->w); atr = attr_at (c,p); if(atr) { strcat (o, *atr); olen += strlen (*atr); } if (!b[p] || b[p]=='\n') break; o[olen++] = b[p]; } } o[olen] = '\0'; return o; }
static void stamp_attr(RConsCanvas *c,int length) { int i; const char ** s; const int loc = c->x + (c->y * c->w); s = attr_at(c, loc); if (s) { //If theres already an attr there, just replace it. *s = c->attr; } else { c->attrs[c->attrslen].loc = loc; c->attrs[c->attrslen].a = c->attr; c->attrslen++; sort_attrs(c); } for(i=0; i<length; i++) { s = attr_at(c,loc+i); if(s) *s = c->attr; } }
R_API char *r_cons_canvas_to_string(RConsCanvas *c) { int x, y, olen = 0; char *o; const char *b; const char **atr; int is_first = true; if (!c) return NULL; b = c->b; o = calloc (1, (c->w * (c->h + 1)) * (CONS_MAX_ATTR_SZ)); if (!o) return NULL; for (y = 0; y < c->h; y++) { if (!is_first) { o[olen++] = '\n'; } is_first = false; for (x = 0; x < c->w; x++) { const int p = x + (y * c->w); atr = attr_at (c, p); if (atr) { strcat (o, *atr); olen += strlen (*atr); } if (!b[p] || b[p] == '\n') { break; } const char *rune = r_cons_get_rune((const ut8)b[p]); if (rune) { strcpy (o + olen, rune); olen += strlen (rune); } else { o[olen++] = b[p]; } } } o[olen] = '\0'; return o; }