diff --git a/examples/Makefile b/examples/Makefile index b71917c..ef6045e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -10,7 +10,7 @@ TARGET=microrl_test all: microrl_test -microrl_test: example.o ../src/microrl.o unix_misc/unix_misc.o +microrl_test: example.o ../src/microrl.o unix_misc/unix_misc.o $(CC) $^ -o $@ $(LDFLAGS) %.o: %.c diff --git a/examples/avr_misc/avr_misc.c b/examples/avr_misc/avr_misc.c index 1962401..d8cce94 100644 --- a/examples/avr_misc/avr_misc.c +++ b/examples/avr_misc/avr_misc.c @@ -29,6 +29,8 @@ char * set_clear_key [] = {_SCMD_PB, _SCMD_PD}; char * compl_world [_NUM_OF_CMD + 1]; +void put_char (unsigned char ch); + //***************************************************************************** void init (void) @@ -40,6 +42,13 @@ void init (void) DDRD=0xFF; } +////***************************************************************************** +//void put_char (unsigned char ch) +//{ +// while (!( UCSRA & (1< #include #include #include #include "microrl.h" +#ifdef _USE_LIBC_STDIO +#include +#endif //#define DBG(...) fprintf(stderr, "\033[33m");fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\033[0m"); @@ -221,16 +223,49 @@ inline static void terminal_newline (microrl_t * this) this->print ("\n\r"); } +#ifndef _USE_LIBC_STDIO +//***************************************************************************** +// convert 16 bit value to string +// 0 value not supported!!! just make empty string +static void u16bit_to_str (unsigned int nmb, char * buf) +{ + char tmp_str [6] = {0,}; + int i = 0; + if (nmb <= 0xFFFF) { + while (nmb > 0) { + tmp_str[i++] = (nmb % 10) + '0'; + nmb /=10; + } + for (int j = 0; j < i; ++j) + *(buf++) = tmp_str [i-j-1]; + } + *buf = '\0'; +} +#endif + + //***************************************************************************** // set cursor at position from begin cmdline (after prompt) + offset static void terminal_move_cursor (microrl_t * this, int offset) { char str[16] = {0,}; +#ifdef _USE_LIBC_STDIO if (offset > 0) { snprintf (str, 16, "\033[%dC", offset); } else if (offset < 0) { snprintf (str, 16, "\033[%dD", -(offset)); } +#else + strcpy (str, "\033["); + if (offset > 0) { + u16bit_to_str (offset, str+2); + strcat (str, "C"); + } else if (offset < 0) { + u16bit_to_str (-(offset), str+2); + strcat (str, "D"); + } else + return; +#endif this->print (str); } @@ -238,8 +273,17 @@ static void terminal_move_cursor (microrl_t * this, int offset) static void terminal_reset_cursor (microrl_t * this) { char str[16]; - snprintf (str, 16, "\033[%dD\033[%dC", _COMMAND_LINE_LEN + _PROMPT_LEN + 2, - _PROMPT_LEN); +#ifdef _USE_LIBC_STDIO + snprintf (str, 16, "\033[%dD\033[%dC", \ + _COMMAND_LINE_LEN + _PROMPT_LEN + 2, _PROMPT_LEN); + +#else + strcpy (str, "\033["); + u16bit_to_str ( _COMMAND_LINE_LEN + _PROMPT_LEN + 2,str+2); + strcat (str, "D\033["); + u16bit_to_str (_PROMPT_LEN, str+strlen(str)); + strcat (str, "C"); +#endif this->print (str); }