void source_set_breakpoints(struct sviewer *sview, struct tgdb_breakpoint *breakpoints) { int i; struct list_node *node; source_clear_breaks(sview); for (i = 0; i < sbcount(breakpoints); i++) { if (breakpoints[i].path) { node = source_get_node(sview, breakpoints[i].path); if (!load_file(node)) { int line = breakpoints[i].line; int enabled = breakpoints[i].enabled; if (line > 0 && line <= sbcount(node->lflags)) { node->lflags[line - 1].breakpt = enabled ? 1 : 2; } } } else if (breakpoints[i].addr) { int line = 0; node = source_get_asmnode(sview, breakpoints[i].addr, &line); if (node) { node->lflags[line].breakpt = breakpoints[i].enabled ? 1 : 2; } } } }
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 int clamp_line(struct filedlg *fd, int line) { if (line < 0) line = 0; if (line >= sbcount(fd->buf->files)) line = sbcount(fd->buf->files) - 1; return line; }
static int clamp_line(struct sviewer *sview, int line) { if (line < 0) line = 0; if (line >= sbcount(sview->cur->file_buf.lines)) line = sbcount(sview->cur->file_buf.lines) - 1; return line; }
static void scroller_set_last_inferior_attr(struct scroller *scr) { int index = sbcount(scr->lines) - 1; struct scroller_line *sl = index >= 0 ? &scr->lines[index] : 0; /* If this is an inferior line and we've got color attributes */ if (sl && (sl->kind == SCR_INPUT_INFERIOR) && sbcount(sl->attrs)) { /* Grab last attribute */ int attr = sl->attrs[sbcount(sl->attrs) - 1].as_attr(); /* Store last attribute for following inferior lines */ scr->last_inferior_attr = attr ? attr : -1; } }
static struct list_node *source_get_asmnode(struct sviewer *sview, uint64_t addr, int *line) { struct list_node *node = NULL; if (addr) { /* Search for a node which contains this address */ for (node = sview->list_head; node; node = node->next) { if (addr >= node->addr_start && addr <= node->addr_end) break; } } if (node && line) { int i; for (i = 0; i < sbcount(node->file_buf.addrs); i++) { if (node->file_buf.addrs[i] == addr) { *line = i; break; } } } return node; }
static char *detab_buffer(char *buffer, int tabstop) { int i; int dst = 0; char *newbuf = NULL; int size = sbcount(buffer); char *tab = strchr(buffer, '\t'); if (!tab) return buffer; for (i = 0; i < size; i++) { if (buffer[i] == '\t') { int spaces = tabstop - dst % tabstop; while(spaces--) { sbpush(newbuf, ' '); dst++; } } else { sbpush(newbuf, buffer[i]); dst++; } if (buffer[i] == '\n' || buffer[i] == '\r') dst = 0; } sbfree(buffer); return newbuf; }
int32_t drn_writer_map_chunk(drn_writer_t * cache, drn_chunk_id_t desc, uint64_t map_count, const drn_map_id_t * map_ids, const char ** key_values) { uint64_t i; for (i = 0; i < map_count; ++i) { drn_writer_map_t * map; int32_t match; drn_writer_key_t * key = 0; if (sbcount(cache->maps) < map_count) return -1; map = cache->maps + map_ids[i]; match = find_key(map->keys, (void*) key_values[i]); if (match == -1) { key = sbadd(map->keys, 1); key->value = (char*) ALLOCATE(strlen(key_values[i])*sizeof(char)+1); key->descriptors = 0; strcpy(key->value, key_values[i]); } else { key = map->keys + match; } * (sbadd(key->descriptors, 1)) = desc; } return 0; }
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); }
static void release_file_buffer(struct buffer *buf) { if (buf) { int i; for (i = 0; i < sbcount(buf->lines); i++) { sbfree(buf->lines[i].attrs); buf->lines[i].attrs = NULL; if (!buf->file_data) { sbfree(buf->lines[i].line); buf->lines[i].line = NULL; } } /* Free entire file buffer */ sbfree(buf->file_data); buf->file_data = NULL; sbfree(buf->lines); buf->lines = NULL; sbfree(buf->addrs); buf->addrs = NULL; buf->max_width = 0; buf->language = TOKENIZER_LANGUAGE_UNKNOWN; } }
int a2_shutdown(struct annotate_two *a2) { int i; cgdb_close(a2->debugger_stdin); a2->debugger_stdin = -1; state_machine_shutdown(a2->sm); commands_shutdown(a2->c); a2_delete_responses(a2); sbfree(a2->responses); a2->responses = NULL; for (i = 0; i < sbcount(a2->client_commands); i++) { struct tgdb_command *tc = a2->client_commands[i]; free(tc->gdb_command); free(tc); } sbfree(a2->client_commands); a2->client_commands = NULL; return 0; }
static void scr_scroll_lines(struct scroller *scr, int *r, int *c, int nlines) { int i; int width = swin_getmaxx(scr->win); int row = *r; int col = (*c / width) * width; int amt = (nlines < 0) ? -width : width; if (nlines < 0) nlines = -nlines; for (i = 0; i < nlines; i++) { col += amt; if (col < 0) { if (row <= 0) break; row--; col = get_last_col(scr, row); } else if (col >= scr->lines[row].line_len) { if (row >= sbcount(scr->lines) - 1) break; row++; col = 0; } *r = row; *c = col; } }
void scr_free(struct scroller *scr) { int i; /* Release the buffer */ for (i = 0; i < sbcount(scr->lines); i++) { free(scr->lines[i].line); sbfree(scr->lines[i].attrs); } sbfree(scr->lines); scr->lines = NULL; hl_regex_free(&scr->last_hlregex); scr->last_hlregex = NULL; hl_regex_free(&scr->hlregex); scr->hlregex = NULL; free(scr->last_inferior_line); scr->last_inferior_line = NULL; swin_delwin(scr->win); scr->win = NULL; /* Release the scroller object */ free(scr); }
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); }
int source_search_regex(struct sviewer *sview, const char *regex, int opt, int direction, int icase) { struct list_node *node = sview ? sview->cur : NULL; if (!node) return -1; if (regex && *regex) { int line; int line_end; int line_inc = direction ? +1 : -1; int line_start = node->sel_rline; line = wrap_line(node, line_start + line_inc); if (cgdbrc_get_int(CGDBRC_WRAPSCAN)) { // Wrapping is on so stop at the line we started on. line_end = line_start; } else { // No wrapping. Stop at line 0 if searching down and last line // if searching up. line_end = direction ? 0 : sbcount(node->file_buf.lines) - 1; } for(;;) { int ret; int start, end; char *line_str = node->file_buf.lines[line].line; ret = hl_regex_search(&sview->hlregex, line_str, regex, icase, &start, &end); if (ret > 0) { /* Got a match */ node->sel_line = line; /* Finalized match - move to this location */ if (opt == 2) { node->sel_rline = line; hl_regex_free(&sview->last_hlregex); sview->last_hlregex = sview->hlregex; sview->hlregex = 0; } return 1; } line = wrap_line(node, line + line_inc); if (line == line_end) break; } } /* Nothing found - go back to original line */ node->sel_line = node->sel_rline; return 0; }
int32_t find_map(const drn_writer_map_t * array, const char * name) { int32_t idx; for (idx = 0; idx < sbcount(array); ++idx) if (!strcmp(array[idx].name, name)) return idx; return -1; }
int32_t find_key(const drn_writer_key_t * array, const char * value) { int32_t idx; for (idx = 0; idx < sbcount(array); ++idx) if (!strcmp(array[idx].value, value)) return idx; return -1; }
int scr_search_regex(struct scroller *scr, const char *regex, int opt, int direction, int icase) { if (regex && *regex) { int line; int line_end; int line_inc = direction ? +1 : -1; int line_start = scr->search_r; line = wrap_line(scr, line_start + line_inc); if (cgdbrc_get_int(CGDBRC_WRAPSCAN)) { // Wrapping is on so stop at the line we started on. line_end = line_start; } else { // No wrapping. Stop at line 0 if searching down and last line // if searching up. line_end = direction ? 0 : sbcount(scr->lines) - 1; } for (;;) { int ret; int start, end; char *line_str = scr->lines[line].line; ret = hl_regex_search(&scr->hlregex, line_str, regex, icase, &start, &end); if (ret > 0) { /* Got a match */ scr->current.r = line; scr->current.c = get_last_col(scr, line); /* Finalized match - move to this location */ if (opt == 2) { scr->search_r = line; hl_regex_free(&scr->hlregex); scr->last_hlregex = scr->hlregex; scr->hlregex = 0; } return 1; } line = wrap_line(scr, line + line_inc); if (line == line_end) break; } } /* Nothing found - go back to original line */ scr->current.r = scr->search_r; scr->current.c = get_last_col(scr, scr->search_r); return 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); }
int source_length(struct sviewer *sview, const char *path) { struct list_node *cur = source_get_node(sview, path); /* Load the file if it's not already */ if (load_file(cur)) return -1; return sbcount(cur->file_buf.lines); }
static int filedlg_search_regex(struct filedlg *fd, const char *regex, int opt, int direction, int icase) { if (!fd || !fd->buf) return -1; if (regex && regex[0]) { int line; int line_end; int line_inc = direction ? +1 : -1; int line_start = fd->buf->sel_rline; line = wrap_line(fd->buf, line_start + line_inc); if (cgdbrc_get_int(CGDBRC_WRAPSCAN)) { // Wrapping is on so stop at the line we started on. line_end = line_start; } else { // No wrapping. Stop at line 0 if searching down and last line // if searching up. line_end = direction ? 0 : sbcount(fd->buf->files) - 1; } for(;;) { int ret; int start, end; char *file = fd->buf->files[line]; ret = hl_regex_search(&fd->hlregex, file, regex, icase, &start, &end); if (ret > 0) { /* Got a match */ fd->buf->sel_line = line; /* Finalized match - move to this location */ if (opt == 2) { fd->buf->sel_rline = line; fd->last_hlregex = fd->hlregex; fd->hlregex = 0; } return 1; } line = wrap_line(fd->buf, line + line_inc); if (line == line_end) break; } } /* Nothing found - go back to original line */ fd->buf->sel_line = fd->buf->sel_rline; return 0; }
static int wrap_line(struct scroller *scr, int line) { int count = sbcount(scr->lines); if (line < 0) line = count - 1; else if (line >= count) line = 0; return line; }
static int wrap_line(struct file_buffer *buffer, int line) { int count = sbcount(buffer->files); if (line < 0) line = count - 1; else if (line >= count) line = 0; return line; }
static void source_clear_breaks(struct sviewer *sview) { struct list_node *node; for (node = sview->list_head; node != NULL; node = node->next) { int i; for (i = 0; i < sbcount(node->lflags); i++) node->lflags[i].breakpt = 0; } }
static int wrap_line(struct list_node *node, int line) { int count = sbcount(node->file_buf.lines); if (line < 0) line = count - 1; else if (line >= count) line = 0; return line; }
drn_map_id_t drn_writer_create_map(drn_writer_t *cache, const char * mapname) { drn_writer_map_t * map; int32_t match = find_map(cache->maps, (void*) mapname); if (match != -1) return (drn_map_id_t) match; map = sbadd(cache->maps, 1); map->name = (char*) ALLOCATE(strlen(mapname)*sizeof(char)+1); map->keys = 0; strcpy(map->name, mapname); return sbcount(cache->maps) - 1; }
void source_set_sel_line(struct sviewer *sview, int line) { if (sview->cur) { if (line == -1) { sview->cur->sel_line = sbcount(sview->cur->file_buf.lines) - 1; } else { /* Set line (note correction for 0-based line counting) */ sview->cur->sel_line = clamp_line(sview, line - 1); } sview->cur->sel_rline = sview->cur->sel_line; } }
void filedlg_clear(struct filedlg *fd) { int i; ibuf_clear(fd->G_line_number); for (i = 0; i < sbcount(fd->buf->files); i++) free(fd->buf->files[i]); sbfree(fd->buf->files); fd->buf->files = NULL; fd->buf->max_width = 0; fd->buf->sel_line = 0; fd->buf->sel_col = 0; fd->buf->sel_rline = 0; }
static void filedlg_hscroll(struct filedlg *fd, int offset) { int lwidth; int max_width; int width; if (fd->buf) { width = swin_getmaxx(fd->win); lwidth = log10_uint(sbcount(fd->buf->files)) + 1; max_width = fd->buf->max_width - width + lwidth + 6; fd->buf->sel_col += offset; if (fd->buf->sel_col > max_width) fd->buf->sel_col = max_width; if (fd->buf->sel_col < 0) fd->buf->sel_col = 0; } }
void source_hscroll(struct sviewer *sview, int offset) { int lwidth; int max_width; int width, height; if (sview->cur) { height = swin_getmaxy(sview->win); width = swin_getmaxx(sview->win); lwidth = log10_uint(sbcount(sview->cur->file_buf.lines)) + 1; max_width = sview->cur->file_buf.max_width - width + lwidth + 6; sview->cur->sel_col += offset; if (sview->cur->sel_col > max_width) sview->cur->sel_col = max_width; if (sview->cur->sel_col < 0) sview->cur->sel_col = 0; } }