void show_mem_line(char *str, int offset, int size) { int i; my_putnbr_base_size(offset, 8); my_putstr(" "); i = 0; while (i < size) { my_putnbr_base_size(*(str + i + offset), 2); if ((i + 1) % 2 == 0) my_putstr(" "); else if (!(i + 1 < size)) my_putstr(" "); ++i; } while (i < 16) my_putstr((i++ + 1) % 2 == 0 ? " " : " "); i = 0; while (i < size) { if (my_is_printable(*(str + offset + i++)) == 1) write(1, str + offset + i - 1, 1); else write(1, ".", 1); } }
int my_str_isprintable(char *str) { int i; i = 0; while (*(str + i) != '\0') if (my_is_printable(*(str + i++)) == 0) return (0); return (1); }
void my_showmem_print_chars(char *str, int num_chars) { int i; i = 0; while (i < 16 && i < num_chars) { if (my_is_printable(str[i])) my_putchar(str[i]); else my_putchar('.'); ++i; } }
static int pull_input(nhandle * h) { Stream *s = h->input; int count; char buffer[1024]; char *ptr, *end; ptr = buffer; if (h->excess_utf_count) { memcpy(buffer, h->excess_utf, h->excess_utf_count); ptr += h->excess_utf_count; } if ((count = read(h->rfd, ptr, sizeof(buffer) - h->excess_utf_count)) > 0) { if (h->binary) { stream_add_string(s, raw_bytes_to_binary(buffer, count)); server_receive_line(h->shandle, reset_stream(s)); h->last_input_was_CR = 0; h->excess_utf_count = 0; } else { for (ptr = buffer, end = buffer + count; ptr < end && ptr + clearance_utf(*ptr) <= end;) { int c = get_utf((const char **)&ptr); if (my_is_printable(c)) stream_add_utf(s, c); #ifdef INPUT_APPLY_BACKSPACE else if (c == 0x08 || c == 0x7F) stream_delete_utf(s); #endif else if (c == '\r' || (c == '\n' && !h->last_input_was_CR)) server_receive_line(h->shandle, reset_stream(s)); h->last_input_was_CR = (c == '\r'); } if (ptr < end) { h->excess_utf_count = end - ptr; memcpy(h->excess_utf, ptr, end - ptr); } h->excess_utf_count = end - ptr; } return 1; } else return (count == 0 && !proto.believe_eof) || (count < 0 && (errno == eagain || errno == ewouldblock)); }