struct tgdb_response *tgdb_create_response(enum tgdb_response_type header) { struct tgdb_response *response; response = (struct tgdb_response *)cgdb_calloc(1, sizeof(struct tgdb_response)); response->header = header; return response; }
struct annotate_two *a2_create_context(const char *debugger, int argc, char **argv, const char *config_dir, struct logger *logger_in) { struct annotate_two *a2 = (struct annotate_two *) cgdb_calloc(1, sizeof(struct annotate_two)); a2->debugger_stdin = -1; a2->debugger_out = -1; if (!tgdb_setup_config_file(a2, config_dir)) { logger_write_pos(logger_in, __FILE__, __LINE__, "tgdb_init_config_file error"); return NULL; } a2->debugger_pid = invoke_debugger(debugger, argc, argv, &a2->debugger_stdin, &a2->debugger_out, 0, a2->a2_gdb_init_file); /* Couldn't invoke process */ if (a2->debugger_pid == -1) return NULL; return a2; }
/* parse: Translates special characters in a string. (i.e. backspace, tab...) * ------ * * buf: The string to parse * * Return Value: A newly allocated copy of buf, with modifications made. */ static char *parse(struct scroller *scr, struct hl_line_attr **attrs, const char *orig, const char *buf, int buflen, enum ScrInputKind kind) { // Read in tabstop settings, but don't change them on the fly as we'd have to // store each previous line and recalculate every one of them. static const int tab_size = cgdbrc_get_int(CGDBRC_TABSTOP); int tabcount = count(buf, buflen, '\t'); int orig_len = strlen(orig); int length = MAX(orig_len, scr->current.pos) + buflen + (tab_size - 1) * tabcount + 1; char *rv = (char *) cgdb_calloc(length, 1); int i, j; int debugwincolor = cgdbrc_get_int(CGDBRC_DEBUGWINCOLOR); int width, height; height = swin_getmaxy(scr->win); width = swin_getmaxx(scr->win); /* Copy over original buffer */ strcpy(rv, orig); i = scr->current.pos; /* Expand special characters */ for (j = 0; j < buflen; j++) { switch (buf[j]) { /* Backspace/Delete -> Erase last character */ case 8: case 127: if (i > 0) i--; break; /* Tab -> Translating to spaces */ case '\t': do { rv[i++] = ' '; } while (i % tab_size != 0); break; /* Carriage return -> Move back to the beginning of the line */ case '\r': i = 0; if (buf[j + 1] != '\n') { sbfree(*attrs); *attrs = NULL; } break; case '\033': /* Handle ansi escape characters */ if (hl_ansi_color_support(hl_groups_instance) && debugwincolor) { int attr; int ansi_count = hl_ansi_get_color_attrs( hl_groups_instance, buf + j, &attr); if (ansi_count) { j += ansi_count - 1; sbpush(*attrs, hl_line_attr(i, attr)); } } else { rv[i++] = buf[j]; } break; default: rv[i++] = buf[j]; break; } } scr->current.pos = i; /** * The prompt should never be longer than the width of the terminal. * * The below should only be done for the readline prompt interaction, * not for text coming from gdb/inferior. Otherwise you'll truncate * their text in the scroller! * * When readline is working with the prompt (at least in "dumb" mode) * it assumes that the terminal will only display as many characters as * the terminal is wide. If the terminal is reduced in size (resized to a * smaller width) readline will only clear the number of characters * that will fit into the new terminal width. Our prompt may still * have a lot more characters than that (the characters that existed * in the prompt before the resize). This truncation of the prompt * is solving that problem. */ size_t rvlength = strlen(rv); if (kind == SCR_INPUT_READLINE && rvlength >= width) { rv[width - 1] = 0; } return rv; }
int hl_regex_search(struct hl_regex_info **info, char *line, const char *regex, int icase, int *start, int *end) { int result; regmatch_t pmatch; int recompile = 0; *start = -1; *end = -1; if (!regex || !regex[0]) return -1; if (!*info) { *info = (struct hl_regex_info *)cgdb_calloc(1, sizeof(struct hl_regex_info)); recompile = 1; } else if (!(*info)->regex) recompile = 1; else if ((*info)->regex == regex) recompile = 0; else if ((icase != -1) && (icase != (*info)->icase)) recompile = 1; else if (strcmp(regex, (*info)->regex)) recompile = 1; if (recompile) { if (*info && (*info)->regex) { regfree(&(*info)->t); free((*info)->regex); (*info)->regex = NULL; } /* Compile the regular expression */ if (regcomp(&(*info)->t, regex, REG_EXTENDED | (icase ? REG_ICASE : 0)) != 0) { hl_regex_free(info); return -1; } (*info)->regex = strdup(regex); (*info)->icase = icase; } char *lf = strchr(line, '\n'); if (lf) *lf = '\0'; result = regexec(&(*info)->t, line, 1, &pmatch, 0); if (lf) *lf = '\n'; if ((result == 0) && (pmatch.rm_eo > pmatch.rm_so)) { *start = pmatch.rm_so; *end = pmatch.rm_eo; return 1; } return 0; }