/* s = refname:1000-2000 */ static void parse_definition( const char *s, char * name, size_t len, uint64_t *start, uint64_t *end ) { size_t n = string_size( s ); *start = 0; *end = 0; name[ 0 ] = 0; if ( n > 0 ) { size_t i, st, dst = 0; char tmp[ 4096 ]; st = RR_NAME; for ( i = 0; i < n; ++i ) { char c = s[ i ]; switch( st ) { case RR_NAME : if ( c == ':' ) { finish_txt( name, len, &dst ); st = RR_START; } else { put_c( name, len, &dst, c ); } break; case RR_START : if ( c == '-' ) { *start = finish_num( tmp, sizeof tmp, &dst ); st = RR_END; } else if ( ( c >= '0' )&&( c <= '9' ) ) { put_c( tmp, sizeof tmp, &dst, c ); } break; case RR_END : if ( ( c >= '0' )&&( c <= '9' ) ) { put_c( tmp, sizeof tmp, &dst, c ); } break; } } switch( st ) { case RR_NAME : finish_txt( name, len, &dst ); break; case RR_START : *start = finish_num( tmp, sizeof tmp, &dst ); break; case RR_END : *end = finish_num( tmp, sizeof tmp, &dst ); break; } } }
// Our custom key handler function void key_handler(uint8_t code, bool special) { put_str_P(uart, special ? PSTR("Special: ") : PSTR("Char: ")); put_c(uart, code); // the actual character put_c(uart, ' '); // space put_u8(uart, code); // as number put_nl(uart); // crlf }
void prtB(BLOCK* b, int x, int y) { set_put_c_color(b->str_col,b->bg_col); set_cur(2*(b->p.x+x)+0,b->p.y+y+0); put_c(b->b[0]); set_cur(2*(b->p.x+x)+1,b->p.y+y+0); put_c(b->b[1]); set_put_c_color(0,0); }
void clrB(BLOCK* b, int x, int y) { set_put_c_color(_COLOR_BLACK,_COLOR_BLACK); set_cur(2*(b->p.x+x)+0,b->p.y+y+0); put_c(b->b[0]); set_cur(2*(b->p.x+x)+1,b->p.y+y+0); put_c(b->b[1]); set_put_c_color(0,0); }
int vfprintf(char *format, va_list arg) { int flag = 0, ret = 0; const char *p = format; while (*p) { switch (*p) { case '%': if (flag) { flag = 0; put_c(*p); ret++; } else { flag = 1; } break; case 'd': if (flag) { char buf[16]; flag = 0; itoa(va_arg(arg, int), buf, 10); put_s(buf); ret += strlen(buf); } else { put_c(*p); ret++; } break; case 'x': if (flag) { char buf[64]; flag = 0; itoa(va_arg(arg, int), buf, 16); put_s(buf); ret += strlen(buf); } else { put_c(*p); ret++; } break; case 'b': if (flag) { char buf[16]; flag = 0; itoa(va_arg(arg, int), buf, 2); put_s(buf); ret += strlen(buf); } else {
void get_s(char* s,int size) { int i=0; while(i<size-1){ char cc=get_c(); if(cc!='\r'){ s[i++]=cc; put_c(cc); } else break; } s[i]='\0'; put_c('\n'); }
static void printint(int n, int base, int sign) { static char digits[] = "0123456789ABCDEF"; char buf[BUF_LEN]; int i = 0, flag = 0; uint32_t ui = n; if(sign && n < 0) { ui = - n; flag = 1; } do { buf[i++] = digits[ui % base]; } while((ui /= base) != 0); if(flag) buf[i++] = '-'; if(base == 2) buf[i++] = 'b'; else if(base == 8) buf[i++] = 'o'; else if(base == 16) buf[i++] = 'x'; if(base != 10) buf[i++] = '0'; while(--i >= 0) put_c(buf[i]); }
/* swi demone */ void swi_test(int num) { put_s("swi : "); print_int_hex(num); put_c('\n'); return; }
void put_s(char *string) { int i=0; while(string[i]!='\0'){ put_c(string[i]); ++i; } }
void put_s(char * ptr) { while ((*ptr)) { put_c(*ptr++); } }
// only understands %d, %b, %o, %x, %p, %s void printk(char *fmt, ...) { int i; char c, *s; uint32_t *ap; if(fmt == '\0') // should panic here return; ap = (uint32_t *)(void *)(&fmt + 1); for(i=0; (c=fmt[i]) != '\0'; i++) { if(c != '%') { put_c(c); continue; } c = fmt[++i]; if(c == '\0') break; switch(c) { case 'd': printint(*ap++, 10, 1); break; case 'b': printint(*ap++, 2, 0); break; case 'o': printint(*ap++, 8, 0); break; case 'x': case 'p': printint(*ap++, 16, 0); break; case 'c': put_c(*ap++); break; case 's': for(s = (char *)*ap++; *s; s++) put_c(*s); break; default: break; } } }
void put_c(char c) { volatile unsigned int *stat=(unsigned int *)UTRSTAT0; while(!((*stat) & 0x2)); volatile unsigned int *utx=(unsigned int *)UTX0; *utx=c; if(c=='\n') put_c('\r'); }
/* s = 1000-2000 */ static void parse_matepair_definition( const char *s, uint64_t *start, uint64_t *end ) { size_t n = string_size( s ); if ( n > 0 ) { size_t i, st, dst = 0; char tmp[ 32 ]; st = RR_START; for ( i = 0; i < n; ++i ) { char c = s[ i ]; switch( st ) { case RR_START : if ( c == '-' ) { *start = finish_num( tmp, sizeof tmp, &dst ); st = RR_END; } else if ( ( c >= '0' )&&( c <= '9' ) ) { put_c( tmp, sizeof tmp, &dst, c ); } break; case RR_END : if ( ( c >= '0' )&&( c <= '9' ) ) { put_c( tmp, sizeof tmp, &dst, c ); } break; } } switch( st ) { case RR_START : *start = finish_num( tmp, sizeof tmp, &dst ); break; case RR_END : *end = finish_num( tmp, sizeof tmp, &dst ); break; } } }
void LCDUI::printMenu( char *menuItems[], size_t menuLen, int top, int pos ) { _lcd->clear(); int height = min( menuLen, ROWS ); int start = top; int cursor = pos - start; // cursor offset from top of screen for ( int i = 0; i < height; i++ ) { put_s( menuItems[(start+i)%menuLen], 1, i ); } put_c( R_ARROW, 0, cursor ); // draw cursor }
unsigned char get_hex() { unsigned char value = 0; while(1){ unsigned char v; v = get_c(); if (v >= '0' && v <= '9'){ put_c(v); v -= 0x30; value = (value << 4) | v; }else if (v >= 'a' && v <= 'f'){ put_c(v); v = v - 'a' + 10; value = (value << 4) | v; }else if (v == 0xd){ put_c(v); return value; } } }
/*JUST FOR TEST*/ void swi_test(void) { unsigned char c; uart0_init(); // 波特率115200,8N1(8个数据位,无校验位,1个停止位) led_on(0x9); while(1) { // 从串口接收数据后,判断其是否数字或子母,若是则加1后输出 c = getc(); if (isDigit(c) || isLetter(c)) put_c(c+1); } }
int sys_write(void) { int fd, len; char *p; int s; fd = argint(0); argstr(1, &p); len = argint(2); if(fd == 1 || fd == 2){ // print to stdout if(len == 1) put_c(*p); else printk("%s", p); } else { sf_write(fd, p, len); } return 0; }
/*---------------------------------------------------------------------*/ void putc_console_ex( u8 c, u8 color ) { put_c( &textbox, c, color ); }
static void put_question_marks(int count) { while (count--) put_c('?'); }