/* main: * * Description of test procedure here. */ int main(int argc, char *argv[]) { ibuf s = NULL; int result = 0; /* Create a tree */ debug("Creating string... "); s = ibuf_init(); if (s == NULL) { printf("FAILED\n"); return 1; } debug("Succeeded.\n"); /* Run tests */ result |= test_add(s); result |= test_addchar(s); result |= test_delchar(s); result |= test_dup(s); result |= test_trim(s); debug("Destroying string...\n"); ibuf_free(s); if (result) { printf("FAILED\n"); return 2; } printf("PASSED\n"); return 0; }
struct ibuf *ibuf_dup(struct ibuf *s) { struct ibuf *ns = ibuf_init(); ibuf_add(ns, ibuf_get(s)); return ns; }
int Ctgdb::Process_console_command(tgdb_request_ptr request) { struct ibuf *command; if (!request) return -1; if (!Can_issue_command()) return -1; if (request->header != TGDB_REQUEST_CONSOLE_COMMAND) return -1; command = ibuf_init (); ibuf_add (command, request->choice.console_command.command); ibuf_addchar (command, '\n'); if (Send(ibuf_get (command), TGDB_COMMAND_CONSOLE) == -1) { Logger_write_pos( __FILE__, __LINE__, "tgdb_send failed"); return -1; } ibuf_free (command); command = NULL; return 0; }
/* PUBLIC */ Ibuffer fd_read_to_ibuf(int fd) { Ibuffer ibuf = ibuf_init(); int csize = ISIZE * sizeof(int); int tibuf[ISIZE]; int rc; do { rc = read(fd, tibuf, csize); if (rc == -1) { perror(""); fatal_error("fd_read_to_ibuf, read error"); } else if (rc == 0) ; /* we're done */ else if (rc % sizeof(int) != 0) fatal_error("fd_read_to_ibuf, bad number of chars read"); else { ibuf_write_block(ibuf, tibuf, rc / sizeof(int)); } } while (rc > 0); return ibuf; } /* fd_read_to_ibuf */
struct state_machine *state_machine_initialize ( void ) { struct state_machine *sm = (struct state_machine * ) cgdb_malloc ( sizeof ( struct state_machine ) ); sm->tgdb_buffer = ibuf_init (); sm->tgdb_state = DATA; return sm; }
/** Initialize an \c ibuf by opening a file for reading. */ int ibuf_open(ibuf* in, const char* filename, unsigned bufsize) { int fd; if ((fd = open(filename, O_RDONLY)) == -1) return 0; if (!ibuf_init(in, fd, 0, IOBUF_SEEKABLE|IOBUF_NEEDSCLOSE, bufsize)) { close(fd); return 0; } return 1; }
static int starttls(void) { int fd; char *fdstr; int extrachars = 0; char c; /* STARTTLS must be the last command in a pipeline, otherwise we can * create a security risk (see CVE-2011-0411). Close input and * check for any extra pipelined commands, so we can give an error * message. Note that this will cause an error on the filehandle, * since we have closed it. */ close(0); while (!ibuf_eof(&inbuf) && !ibuf_error(&inbuf)) { if (ibuf_getc(&inbuf, &c)) ++extrachars; } if (!(fdstr=getenv("SSLCTLFD"))) return 0; if ((fd = atoi(fdstr)) <= 0) return 0; if (write(fd, "y", 1) < 1) return 0; if (!(fdstr=getenv("SSLREADFD"))) return 0; if ((fd = atoi(fdstr)) <= 0) return 0; if (dup2(fd, 0) != 0) return 0; if (!(fdstr=getenv("SSLWRITEFD"))) return 0; if ((fd = atoi(fdstr)) <= 0) return 0; if (dup2(fd, 1) != 1) return 0; /* Re-initialize stdin and clear input buffer */ ibuf_init(&inbuf,0,0,IOBUF_NEEDSCLOSE, 4096); if (extrachars) respond(&resp_earlytalker); return 1; }
int highlight_node(const char *filename, struct buffer *buf) { int ret; int length = 0; int lasttype = -1; struct ibuf *ibuf = ibuf_init(); struct tokenizer *t = tokenizer_init(); if (tokenizer_set_file(t, filename, buf->language) == -1) { if_print_message("%s:%d tokenizer_set_file error", __FILE__, __LINE__); return -1; } while ((ret = tokenizer_get_token(t)) > 0) { enum tokenizer_type e = tokenizer_get_packet_type(t); /*if_print_message ( "TOKEN(%d:%s)\n", e, tokenizer_get_printable_enum ( e ) ); */ if (e == TOKENIZER_NEWLINE) { sbpush(buf->tlines, strdup(ibuf_get(ibuf))); if (length > buf->max_width) buf->max_width = length; length = 0; lasttype = -1; ibuf_clear(ibuf); } else { const char *tok_data = tokenizer_get_data(t); enum hl_group_kind hlg = hlg_from_tokenizer_type(e, tok_data); if (hlg == HLG_LAST) { logger_write_pos(logger, __FILE__, __LINE__, "Bad hlg_type for '%s', e==%d\n", tok_data, e); hlg = HLG_TEXT; } /* Set the highlight group type */ add_type(ibuf, &lasttype, hlg); /* Add the text and bump our length */ length += ibuf_add(ibuf, tok_data); } } ibuf_free(ibuf); tokenizer_destroy(t); return 0; }
/* See interface.h for function descriptions. */ int if_init(void) { if (init_curses()) { clog_error(CLOG_CGDB, "Unable to initialize the ncurses library"); return -1; } hl_groups_instance = hl_groups_initialize(); if (!hl_groups_instance) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } if (hl_groups_setup(hl_groups_instance) == -1) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } /* Set up the signal handler to catch SIGWINCH */ if (set_up_signal() == -1) { clog_error(CLOG_CGDB, "Unable to handle signal: SIGWINCH"); return -1; } if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) { screen_size.ws_row = swin_lines(); screen_size.ws_col = swin_cols(); } /* Create the file dialog object */ fd = filedlg_new(0, 0, HEIGHT, WIDTH); /* Set up window layout */ window_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); switch (if_layout()) { case 2: return 4; } G_line_number = ibuf_init(); return 0; }
int Ctgdb::Send(char *command, enum tgdb_command_choice command_choice, ITarget* target) { struct tgdb_command *tc; struct ibuf *temp_command = ibuf_init (); int length = strlen (command); /* Add a newline to the end of the command if it doesn't exist */ ibuf_add (temp_command, command); if (command[length - 1] != '\n') ibuf_addchar (temp_command, '\n'); /* Create the client command */ tc = tgdb_command_create (ibuf_get (temp_command), command_choice, NULL); tc->ITarget = (void*) target; ibuf_free (temp_command); temp_command = NULL; if (Run_or_queue_command(tc) == -1) { Logger_write_pos( __FILE__, __LINE__, "tgdb_run_or_queue_command failed"); return -1; } if (tgdb_client_tgdb_ran_command(tcc) == -1) { Logger_write_pos( __FILE__, __LINE__, "tgdb_client_tgdb_ran_command failed"); return -1; } Process_client_commands(); return 0; }
struct filedlg *filedlg_new(int pos_r, int pos_c, int height, int width) { struct filedlg *fd; /* Allocate a new structure */ fd = (struct filedlg *)cgdb_malloc(sizeof(struct filedlg)); /* Initialize the structure */ fd->win = swin_newwin(height, width, pos_r, pos_c); /* Initialize the buffer */ fd->buf = (struct file_buffer *)cgdb_malloc(sizeof(struct file_buffer)); fd->G_line_number = ibuf_init(); fd->last_hlregex = NULL; fd->hlregex = NULL; fd->buf->files = NULL; fd->buf->max_width = 0; fd->buf->sel_line = 0; fd->buf->sel_col = 0; fd->buf->sel_rline = 0; return fd; }
static ChannelNP * create_channel(noPollConn * np_sock, int en_ssl, int server) { const int i = 1; ChannelNP * c; int sock = nopoll_conn_socket(np_sock); assert(np_sock >= 0); if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&i, sizeof(i)) < 0) { int error = errno; trace(LOG_ALWAYS, "Can't set TCP_NODELAY option on a socket: %s", errno_to_str(error)); errno = error; return NULL; } if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, sizeof(i)) < 0) { int error = errno; trace(LOG_ALWAYS, "Can't set SO_KEEPALIVE option on a socket: %s", errno_to_str(error)); errno = error; return NULL; } c = (ChannelNP *)loc_alloc_zero(sizeof *c); #if ENABLE_Splice if (pipe(c->pipefd) == -1) { int err = errno; loc_free(c); trace(LOG_ALWAYS, "Cannot create channel pipe : %s", errno_to_str(err)); errno = err; return NULL; } #endif /* ENABLE_Splice */ c->magic = CHANNEL_MAGIC; c->is_ssl = en_ssl; c->chan.inp.read = np_read_stream; c->chan.inp.peek = np_peek_stream; c->obuf = output_queue_alloc_obuf(); c->chan.out.cur = c->obuf->buf; c->chan.out.end = c->obuf->buf + sizeof(c->obuf->buf); c->chan.out.write = np_write_stream; c->chan.out.write_block = np_write_block_stream; c->chan.out.splice_block = np_splice_block_stream; list_add_last(&c->chan.chanlink, &channel_root); shutdown_set_normal(&channel_shutdown); c->chan.state = ChannelStateStartWait; c->chan.incoming = server; c->chan.start_comm = start_channel; c->chan.check_pending = channel_check_pending; c->chan.message_count = channel_get_message_count; c->chan.lock = np_lock; c->chan.unlock = np_unlock; c->chan.is_closed = np_is_closed; c->chan.close = send_eof_and_close; ibuf_init(&c->ibuf, &c->chan.inp); c->ibuf.post_read = np_post_read; c->ibuf.wait_read = np_wait_read; c->ibuf.trigger_message = np_trigger_message; c->socket = nopoll_conn_socket(np_sock); c->np_socket = np_sock; c->lock_cnt = 1; c->rd_req.done = np_channel_read_done; c->rd_req.client_data = c; c->rd_req.type = AsyncReqSelect; #if ENABLE_OutputQueue output_queue_ini(&c->out_queue); #endif return c; }
static const response* message_end(int fd) { const char* hostname; const char* tmp; ipv4port cmdport; ipv4addr ips[MAX_IPS]; int ip_count; int i; int offset; int result; struct timeval tv; int sock; unsigned long timeout; unsigned long connect_timeout; unsigned long send_timeout; unsigned long maxsize; ibuf netin; obuf netout; struct stat st; if ((hostname = session_getenv("CLAMAV_HOST")) != 0 || (hostname = session_getenv("CLAMD_HOST")) != 0) { if (fstat(fd, &st) != 0) return &resp_internal; /* For simplicity, this plugin just sends a single chunk, but each * chunk is limited to 2^32 bytes by the protocol. */ if (st.st_size > 0xffffffffLL) { warn1("ClamAV scanning skipped: message larger than chunk size"); return 0; } if ((tmp = session_getenv("CLAMAV_MAXSIZE")) != 0 && (maxsize = strtoul(tmp, (char**)&tmp, 10)) != 0 && *tmp == 0) { if (st.st_size > (ssize_t)maxsize){ warn1("ClamAV scanning skipped: message larger than maximum"); return 0; } } if (((tmp = session_getenv("CLAMAV_PORT")) == 0 && (tmp = session_getenv("CLAMD_PORT")) == 0) || (cmdport = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) cmdport = 3310; if (((tmp = session_getenv("CLAMAV_TIMEOUT")) == 0 && (tmp = session_getenv("CLAMD_TIMEOUT")) == 0) || (timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) timeout = 5000; if ((tmp = session_getenv("CLAMAV_CONNECT_TIMEOUT")) == 0 || (connect_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) connect_timeout = timeout; if ((tmp = session_getenv("CLAMAV_SEND_TIMEOUT")) == 0 || (send_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) send_timeout = timeout; if ((ip_count = resolve_ipv4name_n(hostname, ips, MAX_IPS)) <= 0) return &resp_no_hostname; gettimeofday(&tv, 0); offset = (tv.tv_sec ^ tv.tv_usec) % ip_count; for (i = 0; i < ip_count; ++i) { const ipv4addr* addr = &ips[(i + offset) % ip_count]; if (lseek(fd, 0, SEEK_SET) != 0) return &resp_internal; if ((sock = try_connect(addr, cmdport, connect_timeout)) < 0) continue; if (obuf_init(&netout, sock, 0, 0, 0)) { netout.io.timeout = send_timeout; result = obuf_puts(&netout, "nINSTREAM\n") && copystream(fd, st.st_size, &netout) && obuf_close(&netout); obuf_close(&netout); if (result) { if (ibuf_init(&netin, sock, 0, IOBUF_NEEDSCLOSE, 0)) { netin.io.timeout = timeout; result = ibuf_getstr(&netin, &line, LF); ibuf_close(&netin); sock = -1; if (result) { if (memcmp(line.s, "stream: ", 8) == 0) { str_lcut(&line, 8); str_rstrip(&line); if (str_diffs(&line, "OK") == 0) return 0; str_splices(&line, 0, 0, "5.7.0 Virus scan failed: "); resp_virus.message = line.s; return &resp_virus; } } } } } if (sock >= 0) close(sock); } } return &resp_no_scan; }
int internal_if_input(int key) { int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val; /* Normally, CGDB_KEY_ESC, but can be configured by the user */ int cgdb_mode_key = cgdbrc_get(CGDBRC_CGDB_MODE_KEY)->variant.int_val; /* The cgdb mode key, puts the debugger into command mode */ if (focus != CGDB && key == cgdb_mode_key) { /* Depending on which cgdb was in, it can free some memory here that * it was previously using. */ if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) { ibuf_free(cur_sbc); cur_sbc = NULL; } else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX) { ibuf_free(regex_cur); regex_cur = NULL; free(src_win->cur->buf.cur_line); src_win->cur->buf.cur_line = NULL; src_win->cur->sel_rline = orig_line_regex; src_win->cur->sel_line = orig_line_regex; } if_set_focus(CGDB); return 0; } /* If you are already in cgdb mode, the cgdb mode key does nothing */ else if (key == cgdb_mode_key) return 0; /* Check for global keystrokes */ switch (focus) { case CGDB: switch (key) { case 'i': if_set_focus(GDB); return 0; case 'I': if_set_focus(TTY); return 0; case ':': /* Set the type of the command the user is typing in the status bar */ sbc_kind = SBC_NORMAL; if_set_focus(CGDB_STATUS_BAR); /* Since the user is about to type in a command, allocate a buffer * in which this command can be stored. */ cur_sbc = ibuf_init(); return 0; case '/': case '?': if (src_win->cur != NULL) { regex_cur = ibuf_init(); regex_direction_cur = ('/' == key); orig_line_regex = src_win->cur->sel_line; sbc_kind = SBC_REGEX; if_set_focus(CGDB_STATUS_BAR); /* Capturing regular expressions */ source_search_regex_init(src_win); /* Initialize the function for finding a regex and tell user */ if_draw(); } return 0; case 'n': source_search_regex(src_win, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); break; case 'N': source_search_regex(src_win, ibuf_get(regex_last), 2, !regex_direction_last, regex_icase); if_draw(); break; case 'T': if (tty_win_on) { tty_win_on = 0; focus = CGDB; } else { tty_win_on = 1; focus = TTY; } if_layout(); break; case CGDB_KEY_CTRL_T: if (tgdb_tty_new(tgdb) == -1) { /* Error */ } else { scr_free(tty_win); tty_win = NULL; if_layout(); } break; case CGDB_KEY_F1: if_display_help(); return 0; case CGDB_KEY_F5: /* Issue GDB run command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_RUN); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F6: /* Issue GDB continue command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_CONTINUE); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F7: /* Issue GDB finish command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_FINISH); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F8: /* Issue GDB next command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_NEXT); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F10: /* Issue GDB step command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_STEP); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_CTRL_L: if_layout(); return 0; } source_input(src_win, key); return 0; break; case TTY: return tty_input(key); case GDB: return gdb_input(key); case FILE_DLG: { static char filedlg_file[MAX_LINE]; int ret = filedlg_recv_char(fd, key, filedlg_file); /* The user cancelled */ if (ret == -1) { if_set_focus(CGDB); return 0; /* Needs more data */ } else if (ret == 0) { return 0; /* The user picked a file */ } else if (ret == 1) { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_filename_pair(tgdb, filedlg_file); handle_request(tgdb, request_ptr); if_set_focus(CGDB); return 0; } } return 0; case CGDB_STATUS_BAR: return status_bar_input(src_win, key); } /* Never gets here */ return 0; }
/** * Send input to the CGDB source window. * * @param key * The key to send to the CGDB source window. * * @param last_key * An output parameter. When set, that will tell cgdb to use the set value, * instead of the current key, as the "last_key_pressed" in the next * call to cgdb_input. This is useful to set mainly when the current input * has consumed more than one character, and the "last_key_pressed" should * be not set on the next call to cgdb_input. * * @return * Currently only returns 0. */ static int cgdb_input(int key, int *last_key) { int regex_icase = cgdbrc_get_int(CGDBRC_IGNORECASE); if (src_viewer && src_viewer->cur) { int ret = 0; /* Handle setting (mX) and going ('X) to source buffer marks */ if (last_key_pressed == 'm') ret = source_set_mark(src_viewer, key); else if (last_key_pressed == '\'') ret = source_goto_mark(src_viewer, key); if (ret) { /* When m[a-zA-Z] matches, don't let the marker char * be treated as the last key. That would allow the * chars mgg, to set the marker g, and then move to the top * of the file via gg. * CGDB should see those as mg (set a local mark g), and then * an individual g. */ *last_key = 0; if_draw(); return 0; } } switch (key) { case 's': gdb_scroller->in_scroll_mode = 1; if_set_focus(GDB); return 0; case 'i': if_set_focus(GDB); return 0; case ':': /* Set the type of the command the user is typing in the status bar */ sbc_kind = SBC_NORMAL; if_set_focus(CGDB_STATUS_BAR); /* Since the user is about to type in a command, allocate a buffer * in which this command can be stored. */ cur_sbc = ibuf_init(); return 0; case '/': case '?': if (src_viewer->cur) { regex_cur = ibuf_init(); regex_direction_cur = ('/' == key); orig_line_regex = src_viewer->cur->sel_line; sbc_kind = SBC_REGEX; if_set_focus(CGDB_STATUS_BAR); /* Capturing regular expressions */ source_search_regex_init(src_viewer); /* Initialize the function for finding a regex and tell user */ if_draw(); } return 0; case 'n': source_search_regex(src_viewer, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); break; case 'N': source_search_regex(src_viewer, ibuf_get(regex_last), 2, !regex_direction_last, regex_icase); if_draw(); break; case CGDB_KEY_CTRL_T: if (tgdb_tty_new(tgdb) == -1) { /* Error */ } else { if_layout(); } break; case CGDB_KEY_CTRL_W: switch (cur_split_orientation) { case WSO_HORIZONTAL: cur_split_orientation = WSO_VERTICAL; break; case WSO_VERTICAL: cur_split_orientation = WSO_HORIZONTAL; break; } if_layout(); break; case CGDB_KEY_F1: if_display_help(); return 0; case CGDB_KEY_F5: /* Issue GDB run command */ tgdb_request_run_debugger_command(tgdb, TGDB_RUN); return 0; case CGDB_KEY_F6: /* Issue GDB continue command */ tgdb_request_run_debugger_command(tgdb, TGDB_CONTINUE); return 0; case CGDB_KEY_F7: /* Issue GDB finish command */ tgdb_request_run_debugger_command(tgdb, TGDB_FINISH); return 0; case CGDB_KEY_F8: /* Issue GDB next command */ tgdb_request_run_debugger_command(tgdb, TGDB_NEXT); case CGDB_KEY_F10: /* Issue GDB step command */ tgdb_request_run_debugger_command(tgdb, TGDB_STEP); return 0; case CGDB_KEY_CTRL_L: if_layout(); return 0; } source_input(src_viewer, key); return 0; }
IBuf *newIBuf(size_t sz) { IBuf *nu = talloc(IBuf); ibuf_init(nu, sz); return nu; }
/* gdb_input: Handles user input to the GDB window. * ---------- * * key: Keystroke received. * * Return Value: 0 if internal key was used, * 1 if input to gdb or ... * -1 : Error resizing terminal -- terminal too small */ static int gdb_input(int key, int *last_key) { int result = 0; if (gdb_scroller->in_search_mode) return gdb_input_regex_input(gdb_scroller, key); if (gdb_scroller->in_scroll_mode) { /* Handle setting (mX) and going ('X) to gdb buffer marks */ if (last_key_pressed == 'm' || last_key_pressed == '\'') { int ret = 0; if (last_key_pressed == 'm') ret = scr_set_mark(gdb_scroller, key); else if(last_key_pressed == '\'') ret = scr_goto_mark(gdb_scroller, key); if (ret) { *last_key = 0; if_draw(); } return 0; } /* In scroll mode, all extra characters are not passed to * the active GDB command. result = 0 above ensures that. */ switch (key) { case 'm': case '\'': /* Mark keys - ignore them */ break; case CGDB_KEY_CTRL_U: scr_up(gdb_scroller, get_gdb_height() / 2); break; case CGDB_KEY_PPAGE: scr_up(gdb_scroller, get_gdb_height() - 1); break; case CGDB_KEY_CTRL_D: scr_down(gdb_scroller, get_gdb_height() / 2); break; case CGDB_KEY_NPAGE: scr_down(gdb_scroller, get_gdb_height() - 1); break; case CGDB_KEY_HOME: case CGDB_KEY_F11: scr_home(gdb_scroller); break; case 'G': case CGDB_KEY_END: case CGDB_KEY_F12: scr_end(gdb_scroller); break; case 'k': case CGDB_KEY_UP: case CGDB_KEY_CTRL_P: scr_up(gdb_scroller, 1); break; case 'j': case CGDB_KEY_DOWN: case CGDB_KEY_CTRL_N: scr_down(gdb_scroller, 1); break; case 'g': if (last_key_pressed == 'g') { scr_home(gdb_scroller); } break; case 'q': case 'i': case '\r': case '\n': case CGDB_KEY_CTRL_M: scr_end(gdb_scroller); gdb_scroller->in_scroll_mode = 0; break; case 'n': scr_search_regex(gdb_scroller, ibuf_get(regex_last), 2, regex_direction_last, cgdbrc_get_int(CGDBRC_IGNORECASE)); break; case 'N': scr_search_regex(gdb_scroller, ibuf_get(regex_last), 2, !regex_direction_last, cgdbrc_get_int(CGDBRC_IGNORECASE)); break; case '/': case '?': /* Capturing regular expressions */ regex_cur = ibuf_init(); regex_direction_cur = ('/' == key); orig_line_regex = gdb_scroller->current.r; sbc_kind = SBC_REGEX; scr_search_regex_init(gdb_scroller); break; } } else { switch (key) { case CGDB_KEY_PPAGE: scr_up(gdb_scroller, get_gdb_height() - 1); break; case CGDB_KEY_CTRL_L: scr_clear(gdb_scroller); /* The return 1 tells readline that gdb did not handle the * Ctrl-l. That way readline will handle it. Because * readline uses TERM=dumb, that means that it will clear * a single line and put out the prompt. */ result = 1; break; default: /* This tells the input to go to active GDB command */ result = 1; } } if_draw(); return result; }
int main(int argc, char *argv[]) { /* Uncomment to debug and attach */ #if 0 int c; read(0, &c, 1); #endif parse_long_options(&argc, &argv); current_line = ibuf_init(); cgdbrc_init(); if (create_and_init_pair() == -1) { fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__); exit(-1); } /* First create tgdb, because it has the error log */ if (start_gdb(argc, argv) == -1) { fprintf(stderr, "%s:%d Unable to invoke GDB", __FILE__, __LINE__); exit(-1); } /* From here on, the logger is initialized */ /* Create the home directory */ if (init_home_dir() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "Unable to create home dir ~/.cgdb"); cleanup(); exit(-1); } if (init_readline() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "Unable to init readline"); cleanup(); exit(-1); } if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1) { logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error"); cleanup(); exit(-1); } if (init_kui() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "init_kui error"); cleanup(); exit(-1); } /* Initialize the display */ switch (if_init()) { case 1: logger_write_pos(logger, __FILE__, __LINE__, "Unable to initialize the curses library"); cleanup(); exit(-1); case 2: logger_write_pos(logger, __FILE__, __LINE__, "Unable to handle signal: SIGWINCH"); cleanup(); exit(-1); case 3: logger_write_pos(logger, __FILE__, __LINE__, "Unable to setup highlighting groups"); cleanup(); exit(-1); case 4: logger_write_pos(logger, __FILE__, __LINE__, "New GDB window failed -- out of memory?"); cleanup(); exit(-1); } /* Initialize the pipe that is used for resize */ if (init_resize_pipe() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "init_resize_pipe error"); cleanup(); exit(-1); } { char config_file[FSUTIL_PATH_MAX]; FILE *config; fs_util_get_path(cgdb_home_dir, "cgdbrc", config_file); config = fopen(config_file, "r"); if (config) { command_parse_file(config); fclose(config); } } /* Enter main loop */ main_loop(); /* Shut down curses and exit */ cleanup(); return 0; }
static int highlight_node ( struct list_node *node ) { struct tokenizer *t = tokenizer_init (); int ret; struct ibuf *ibuf = ibuf_init (); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); /* Initialize */ node->buf.length = 0; node->buf.tlines = NULL; node->buf.max_width = 0; if ( tokenizer_set_file ( t, node->path, node->language ) == -1 ) { if_print_message ("%s:%d tokenizer_set_file error", __FILE__, __LINE__); return -1; } while ( ( ret = tokenizer_get_token ( t ) ) > 0 ) { enum tokenizer_type e = tokenizer_get_packet_type ( t ); /*if_print_message ( "TOKEN(%d:%s)\n", e, tokenizer_get_printable_enum ( e ) );*/ switch ( e ) { case TOKENIZER_KEYWORD: ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_KEYWORD ); ibuf_add ( ibuf, tokenizer_get_data ( t ) ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_TYPE: ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TYPE ); ibuf_add ( ibuf, tokenizer_get_data ( t ) ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_LITERAL: ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_LITERAL ); ibuf_add ( ibuf, tokenizer_get_data ( t ) ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_NUMBER: ibuf_add ( ibuf, tokenizer_get_data ( t ) ); break; case TOKENIZER_COMMENT: ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_COMMENT ); ibuf_add ( ibuf, tokenizer_get_data ( t ) ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_DIRECTIVE: ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_DIRECTIVE ); ibuf_add ( ibuf, tokenizer_get_data ( t ) ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_TEXT: ibuf_add ( ibuf, tokenizer_get_data ( t ) ); break; case TOKENIZER_NEWLINE: node->buf.length++; node->buf.tlines = realloc ( node->buf.tlines, sizeof ( char *) * node->buf.length ); node->buf.tlines[node->buf.length-1] = strdup ( ibuf_get ( ibuf ) ); if ( ibuf_length ( ibuf ) > node->buf.max_width ) node->buf.max_width = ibuf_length ( ibuf ); ibuf_clear ( ibuf ); ibuf_addchar ( ibuf, HL_CHAR ); ibuf_addchar ( ibuf, HLG_TEXT ); break; case TOKENIZER_ERROR: ibuf_add ( ibuf, tokenizer_get_data ( t ) ); break; default: return -1; break; } } return 0; }