void source_add_disasm_line(struct list_node *node, const char *line) { uint64_t addr = 0; struct source_line sline; char *colon = 0, colon_char = 0; sline.line = NULL; sbsetcount(sline.line, strlen(line) + 1); strcpy(sline.line, line); sline.line = detab_buffer(sline.line, node->file_buf.tabstop); sline.attrs = NULL; sline.len = sbcount(sline.line); colon = strchr((char*)line, ':'); if (colon) { colon_char = *colon; *colon = 0; } cgdb_hexstr_to_u64(line, &addr); if (colon) { *colon = colon_char; } sbpush(node->file_buf.addrs, addr); struct line_flags lf = { 0, 0 }; sbpush(node->file_buf.lines, sline); sbpush(node->lflags, lf); }
int source_highlight(struct list_node *node) { int do_color = sources_syntax_on && (node->language != TOKENIZER_LANGUAGE_UNKNOWN) && swin_has_colors(); /* Load the entire file */ if (!sbcount(node->file_buf.lines)) load_file_buf(&node->file_buf, node->path); /* If we're doing color and we haven't already loaded this file * with this language, then load and highlight it. */ if (do_color && (node->file_buf.language != node->language)) { node->file_buf.language = node->language; highlight_node(node); } /* Allocate the breakpoints array */ if (!node->lflags) { int count = sbcount(node->file_buf.lines); sbsetcount(node->lflags, count); memset(node->lflags, 0, sbcount(node->lflags)); } if (node->file_buf.lines) return 0; return -1; }
static void scroller_addline(struct scroller *scr, char *line, struct hl_line_attr *attrs, enum ScrInputKind kind) { struct scroller_line sl; /* Add attribute from last inferior line to start of this one */ if (kind == SCR_INPUT_INFERIOR && (scr->last_inferior_attr != -1)) { /* If there isn't already a color attribute for the first column */ if (!attrs || (attrs[0].col() != 0)) { int count = sbcount(attrs); /* Bump the count up and scoot the attributes over one */ sbsetcount(attrs, count + 1); memmove(attrs+1, attrs, count * sizeof(struct hl_line_attr)); attrs[0] = hl_line_attr(0, scr->last_inferior_attr); } scr->last_inferior_attr = -1; } sl.line = line; sl.line_len = strlen(line); sl.kind = kind; sl.attrs = attrs; sbpush(scr->lines, sl); scr->lines_to_display++; scroller_set_last_inferior_attr(scr); }
static void rline_free_completions() { int i; /* Set and index to 0. */ sbsetcount(completions_array, 0); completions_index = 0; }
void a2_delete_responses(struct annotate_two *a2) { int i; for (i = 0; i < sbcount(a2->responses); i++) tgdb_delete_response(a2->responses[i]); sbsetcount(a2->responses, 0); }
/** * Load file and fill tlines line pointers. * * \param buf * struct buffer pointer * * \param filename * name of file to load * * \return * 0 on sucess, -1 on error */ static int load_file_buf(struct buffer *buf, const char *filename) { FILE *file; long file_size; int ret = -1; /* Special buffer not backed by file */ if (filename[0] == '*') return 0; file = fopen(filename, "rb"); if (!file) return -1; file_size = get_file_size(file); if (file_size > 0) { size_t bytes_read; /* Set the stretchy buffer size to our file size plus one for nil */ sbsetcount(buf->file_data, file_size + 1); /* Read in the entire file */ bytes_read = fread(buf->file_data, 1, file_size, file); /* If we had a partial read, bail */ if (bytes_read != file_size) { sbfree(buf->file_data); buf->file_data = NULL; fclose(file); return -1; } /* Zero terminate buffer */ buf->file_data[bytes_read] = 0; /* Convert tabs to spaces */ buf->tabstop = cgdbrc_get_int(CGDBRC_TABSTOP); buf->file_data = detab_buffer(buf->file_data, buf->tabstop); { char *line_start = buf->file_data; char *line_feed = strchr(line_start, '\n'); while (line_feed) { size_t line_len; char *line_end = line_feed; /* Trim trailing cr-lfs */ while (line_end >= line_start && (*line_end == '\n' || *line_end == '\r')) line_end--; /* Update max length string found */ line_len = line_end - line_start + 1; if (line_len > buf->max_width) buf->max_width = line_len; struct source_line sline; sline.line = line_start; sline.len = line_len; sline.attrs = NULL; /* Add this line to lines array */ sbpush(buf->lines, sline); line_start = line_feed + 1; line_feed = strchr(line_start, '\n'); } if (*line_start) { struct source_line sline; sline.line = line_start; sline.len = strlen(line_start); sline.attrs = NULL; sbpush(buf->lines, sline); } ret = 0; } } fclose(file); return ret; }