/* input_backspace: does a backspace in the input buffer */ void input_backspace(char key, char *blah) { cursor_to_input(); if (THIS_POS > MIN_POS) { char *ptr = NULL; int pos; malloc_strcpy(&ptr, &(THIS_CHAR)); strcpy(&(PREV_CHAR), ptr); new_free(&ptr); THIS_POS--; term_cursor_left(); if (THIS_CHAR) { if (term_delete()) update_input(UPDATE_FROM_CURSOR); { pos = str_start + term_cols - 1; pos += count_ansi(&(current_screen->input_buffer[str_start]), zone); if (pos < strlen(INPUT_BUFFER)) { term_move_cursor(term_cols - 1, input_line); term_putchar(INPUT_BUFFER[pos]); } update_input(UPDATE_JUST_CURSOR); } } else { term_putchar(' '); term_cursor_left(); update_input(NO_UPDATE); } } in_completion = STATE_NORMAL; *new_nick = 0; }
/* * input_transpose_characters: swaps the positions of the two characters * before the cursor position */ void input_transpose_characters(char unused, char *not_used) { cursor_to_input(); if (current_screen->buffer_pos > MIN_POS) { u_char c1[3] = { 0 }; int pos, end_of_line = 0; if (THIS_CHAR) pos = THIS_POS; else if (strlen(get_input()) > MIN_POS + 2) { pos = THIS_CHAR - 1; end_of_line = 1; } else return; c1[0] = INPUT_BUFFER[pos]; c1[1] = INPUT_BUFFER[pos] = INPUT_BUFFER[pos - 1]; INPUT_BUFFER[pos - 1] = c1[0]; term_cursor_left(); if (end_of_line) term_cursor_left(); term_putchar(c1[0]); term_putchar(c1[1]); if (!end_of_line) term_cursor_left(); update_input(NO_UPDATE); } }
void term_putn_udec(uint32_t number) { if(number==0) // exit early { term_putchar('0'); return; } char buf[10]; for(int i=0;i<10;++i) { buf[9-i]=dtoc(number%10); number/=10; } uint8_t encountered_nonzero=0; for(int i=0;i<10;++i) { if(buf[i]!='0') { encountered_nonzero=1; } if(encountered_nonzero) { term_putchar(buf[i]); } } }
void write_string(char *s, int cnt) { int i; char *p; for(i = 0, p = s; i <= cnt; ++i) { switch(*p) { case BELL_CHAR: if(GET_BIT(options, DO_BELLS)) { term_beep(1); } else { if(!term_standout_status()) { term_standout_on(); term_putchar(*p + 'A' - 1); term_standout_off(); } else { term_putchar(*p + 'A' - 1); } } ++p; break; case BOLD_CHAR: term_toggle_boldface(); ++p; break; case INVERSE_CHAR: term_toggle_standout(); ++p; break; case UNDERLINE_CHAR: term_toggle_underline(); ++p; break; default: term_putchar(*p); ++p; break; } } }
void term_puts(const char* str) { for(size_t i=0;str[i]!=0;++i) { term_putchar(str[i]); } }
/* input_delete_character: deletes a character from the input line */ void input_delete_character(char unused, char *not_used) { cursor_to_input(); if (THIS_CHAR) { char *ptr = NULL; int pos; malloc_strcpy(&ptr, &(NEXT_CHAR)); strcpy(&(THIS_CHAR), ptr); new_free(&ptr); if (term_delete()) update_input(UPDATE_FROM_CURSOR); else { pos = str_start + term_cols - 1; pos += count_ansi(&(current_screen->input_buffer[str_start]), zone); if (pos < strlen(INPUT_BUFFER)) { term_move_cursor(term_cols - 1, input_line); term_putchar(INPUT_BUFFER[pos]); term_move_cursor(cursor, input_line); } update_input(NO_UPDATE); } } in_completion = STATE_NORMAL; }
static int safe_puts(char *str, int len) { int i = 0; while (*str && i < len) term_putchar(*str++), i++; return i; }
int printf(const char* fmt, ...) { va_list va; va_start(va, fmt); for(unsigned int i=0;fmt[i];++i) { char c=fmt[i]; if(c=='%') { ++i; // skip the % sign switch(fmt[i]) { case 'd': // signed integer case 'i': term_putn_dec(va_arg(va, int)); break; case 'u': term_putn_udec(va_arg(va, uint32_t)); break; case 's': // string term_puts(va_arg(va, const char*)); break; case 'c': term_putchar(va_arg(va, int)); break; case 'X': term_putn_hex_ucase(va_arg(va, uint32_t)); break; case 'x': term_putn_hex_lcase(va_arg(va, uint32_t)); break; case 'p': // pointer term_puts("0x"); term_putn_hex_ucase(va_arg(va, uint32_t)); break; case '%': term_putchar('%'); break; } } else term_putchar(c); } va_end(va); return 0; }
void term_putn_bin(uint32_t number) { for(int i=0;i<32;++i) { char c=((number & 0x80000000 )>> 31 == 1)?'1':'0'; term_putchar(c); number<<=1; } }
/* * input_add_character: adds the character c to the input buffer, repecting * the current overwrite/insert mode status, etc */ void input_add_character(char c, char *unused) { int display_flag = NO_UPDATE; cursor_to_input(); if (THIS_POS < INPUT_BUFFER_SIZE) { if (get_int_var(INSERT_MODE_VAR)) { if (THIS_CHAR) { char *ptr = NULL; ptr = strdup(&(THIS_CHAR)); THIS_CHAR = c; NEXT_CHAR = 0; ADD_TO_INPUT(ptr); free(ptr); if (term_insert(c)) { term_putchar(c); if (NEXT_CHAR) display_flag = UPDATE_FROM_CURSOR; else display_flag = NO_UPDATE; } } else { THIS_CHAR = c; NEXT_CHAR = 0; term_putchar(c); } } else { if (THIS_CHAR == 0) NEXT_CHAR = 0; THIS_CHAR = c; term_putchar(c); } THIS_POS++; update_input(display_flag); } if (in_completion == STATE_COMPLETE && c == ' ' && input_lastmsg) { new_free(&input_lastmsg); *new_nick = 0; in_completion = STATE_NORMAL; } }
void kprint(const char* fmt, ...) { va_list ap; va_start(ap, fmt); const char* next; for (const char* tmp = fmt; *tmp; tmp++) { switch(*tmp) { default: term_putchar(*tmp); break; case '%': next = tmp + 1; if (*next == '%') { term_putchar('%'); } else { char* str = va_arg(ap, const char*); kprint(str); } } } }
/* XXXX Only used here anyhow XXXX */ static int safe_puts (char *str, int len, int echo) { int i = 0; while (*str && i < len) { term_putchar(*str); str++, i++; } return i; }
static void input_delete_char_from_screen (void) { /* * Remove the current character from the screen's display. * * If we cannot do a character delete then we do a wholesale * redraw of the input line (ugh). */ if (!(termfeatures & TERM_CAN_DELETE)) update_input(UPDATE_FROM_CURSOR); else { int pos; /* * Delete the character. This is the simple part. */ term_delete(1); /* * So right now we have a blank space at the right of the * screen. If there is a character in the input buffer that * is out in that position, we need to find it and display it. */ if (INPUT_ONSCREEN == 0) /* UGH! */ pos = last_input_screen->co - INPUT_PROMPT_LEN - 1; else pos = INPUT_ONSCREEN + last_input_screen->co - 1; if (pos < (int)strlen(INPUT_BUFFER)) { term_move_cursor(last_input_screen->co - 1, INPUT_LINE); term_putchar(INPUT_BUFFER[pos]); term_move_cursor(INPUT_CURSOR, INPUT_LINE); cursor_not_in_display(last_input_screen); } /* XXX - Very possibly, this is pointless */ update_input(NO_UPDATE); } }
void irq_handler(struct registers_t regs) { if(regs.interrupt_number >= 40) // sent by slave PIC { outb(0xA0, 0x20); // slave EOI } outb(0x20, 0x20); // master EOI if(handlers[regs.interrupt_number]!=0) { handlers[regs.interrupt_number](regs); } else { #ifndef NDEBUG term_debug("received unhandled IRQ interrupt\n"); term_debug("IRQ interrupt number in decimal: "); term_putn_dec(regs.interrupt_number); term_putchar('\n'); #endif if(panic_on_unhandled==true) panic("unhandled IRQ!"); } }
void term_puts_P(terminal_t* term, PGM_P str) { char c; while((c = pgm_read_byte(str++)) != '\0') { term_putchar(term, c); } }
void term_puts(terminal_t* term, const char* str) { while(*str) { term_putchar(term, *str++); } }
static inline int term_putchar_wrapper(char c, FILE* stream) { term_putchar(term_redirected, c); return 0; }
static void term_puts(const char *str) { while (*str) if (term_putchar(*str++)) return; }