URL
https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk
Subversion Repositories qaz_libs
Compare Revisions
- This comparison shows the changes necessary to convert path
/qaz_libs/trunk/cli
- from Rev 27 to Rev 28
- ↔ Reverse comparison
Rev 27 → Rev 28
/cli/sys_cli.c
36,22 → 36,29
|
|
/*-----------------------------------------------------------*/ |
void clear_screen(void) |
{ |
PRINTF_MACRO("\033[H\033[J"); |
} |
|
|
/*-----------------------------------------------------------*/ |
#ifdef ANSI_ESCAPE_CODE |
#define ASCII_ESC '\x1b' |
|
static void send_csi( char c ) |
static void send_csi(char c) |
{ |
putchar( ASCII_ESC ); |
putchar( '[' ); |
putchar( c ); |
putchar(ASCII_ESC); |
putchar('['); |
putchar(c); |
} |
#else |
static void send_csi( char c ) {}; |
static void send_csi(char c) {}; |
#endif |
|
|
/*-----------------------------------------------------------*/ |
static char *cli_edit_buffer( char *in_buffer, char *out_buffer, unsigned int line_length ) |
static char *cli_edit_buffer(char *in_buffer, char *out_buffer, unsigned int line_length) |
{ |
static char *out_ptr; |
static char *begin_ptr; |
64,7 → 71,7
|
unsigned int i; |
|
if( out_buffer != NULL ) |
if(out_buffer != NULL) |
{ |
out_ptr = out_buffer; |
begin_ptr = out_buffer; |
76,43 → 83,43
#endif |
} |
|
for( i = 0 ; i < line_length ; i++ ) |
for(i = 0 ; i < line_length ; i++) |
{ |
|
if( out_ptr >= end_ptr ) |
if(out_ptr >= end_ptr) |
{ |
*end_ptr = '\0'; |
return( NULL ); |
return(NULL); |
} |
|
if( out_ptr < begin_ptr ) |
sys_error_fatal( FATAL_ERROR_CLI ); |
if(out_ptr < begin_ptr) |
sys_error_fatal(FATAL_ERROR_CLI); |
|
switch( in_buffer[i] ) |
switch(in_buffer[i]) |
{ |
case '\0': |
return( NULL ); |
return(NULL); |
break; |
|
case '\n': |
*out_ptr = '\0'; |
return( NULL ); |
return(NULL); |
break; |
|
case '\r': |
*out_ptr = '\0'; |
return( NULL ); |
return(NULL); |
break; |
|
case '\b': |
if( out_ptr != begin_ptr ) |
if(out_ptr != begin_ptr) |
{ |
send_csi( 'P' ); |
send_csi('P'); |
out_ptr--; |
} else |
{ |
putchar( ' ' ); |
send_csi( '\a' ); |
putchar(' '); |
send_csi('\a'); |
} |
break; |
|
121,7 → 128,7
break; |
|
case '[': |
if( prev_char == ASCII_ESC ) |
if(prev_char == ASCII_ESC) |
{ |
csi = 1; |
} else |
132,10 → 139,10
break; |
|
case 'A': |
if( csi ) |
if(csi) |
{ |
send_csi( 'B' ); |
send_csi( '\a' ); |
send_csi('B'); |
send_csi('\a'); |
|
csi = 0; |
} else |
146,7 → 153,7
break; |
|
case 'B': |
if( csi == 0 ) |
if(csi == 0) |
{ |
*out_ptr = in_buffer[i]; |
out_ptr++; |
154,10 → 161,10
break; |
|
case 'C': |
if( csi ) |
if(csi) |
{ |
send_csi( 'D' ); |
send_csi( '\a' ); |
send_csi('D'); |
send_csi('\a'); |
|
csi = 0; |
} else |
168,10 → 175,10
break; |
|
case 'D': |
if( csi ) |
if(csi) |
{ |
send_csi( 'C' ); |
send_csi( '\a' ); |
send_csi('C'); |
send_csi('\a'); |
|
csi = 0; |
} else |
193,12 → 200,12
#endif |
} |
|
return( out_ptr ); |
return(out_ptr); |
} |
|
|
/*-----------------------------------------------------------*/ |
void sys_cli_task( void ) |
void sys_cli_task(void) |
{ |
char last_return_value = EXIT_SUCCESS; |
char in_buffer[INPUT_LINE_LENGTH + 1]; |
212,62 → 219,59
|
cli_init(); |
|
PRINTF_MACRO( "\r\n" ); |
PRINTF_MACRO("\r\n"); |
|
for( ;; ) |
for(;;) |
{ |
PRINTF_MACRO( "%d > ", last_return_value ); |
PRINTF_MACRO("%d > ", last_return_value); |
|
cli_argc = 0; |
last_return_value = EXIT_SUCCESS; |
|
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) ); |
cli_ptr = cli_edit_buffer( in_buffer, out_buffer, bytes_read ); |
bytes_read = (unsigned int)read(STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer)); |
cli_ptr = cli_edit_buffer(in_buffer, out_buffer, bytes_read); |
|
while( cli_ptr != NULL ) |
while(cli_ptr != NULL) |
{ |
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) ); |
cli_ptr = cli_edit_buffer( in_buffer, NULL, bytes_read ); |
bytes_read = (unsigned int)read(STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer)); |
cli_ptr = cli_edit_buffer(in_buffer, NULL, bytes_read); |
} |
|
if( out_buffer[0] == '\0' ) |
{ |
PRINTF_MACRO( " NULL String! Command ignored\r\n" ); |
if(out_buffer[0] == '\0') |
last_return_value = EXIT_FAILURE; |
} |
|
while( last_return_value != EXIT_FAILURE ) |
while(last_return_value != EXIT_FAILURE) |
{ |
cli_ptr = strtok( out_buffer, " \t" ); |
cli_ptr = strtok(out_buffer, " \t"); |
|
strncpy( cmd_to_check.cmd, out_buffer, MAX_CMD_LENGTH ); |
cli_cmd = cli_find_command( &cmd_to_check ); |
strncpy(cmd_to_check.cmd, out_buffer, MAX_CMD_LENGTH); |
cli_cmd = cli_find_command(&cmd_to_check); |
|
if ( cli_cmd == NULL ) |
if (cli_cmd == NULL) |
{ |
PRINTF_MACRO( "\r\n Command not found!\r\n" ); |
PRINTF_MACRO("\r\n Command not found!\r\n"); |
last_return_value = EXIT_FAILURE; |
break; |
} |
|
if( cli_ptr == NULL ) |
if(cli_ptr == NULL) |
{ |
cli_argv[cli_argc] = out_buffer; |
cli_argc++; |
} else |
{ |
while( cli_ptr != NULL ) |
while(cli_ptr != NULL) |
{ |
cli_argv[cli_argc] = cli_ptr; |
cli_argc++; |
|
cli_ptr = strtok( NULL, " \t" ); |
cli_ptr = strtok(NULL, " \t"); |
} |
} |
|
PRINTF_MACRO( "\r\n" ); |
PRINTF_MACRO("\r\n"); |
|
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv ); |
last_return_value = cli_cmd->func(cli_argc, (const char **)cli_argv); |
break; |
} |
|
/cli/sys_cmd.c
37,9 → 37,9
void cli_init( void ) |
{ |
int i; |
|
|
for(i = 0; cli_commands[i].func != NULL; i++); |
|
|
cli_no_of_commands = i; |
} |
|
58,7 → 58,7
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check ) |
{ |
struct cli_cmd_tab_t *cli_cmd; |
|
|
cli_cmd = (struct cli_cmd_tab_t *) bsearch( cmd_to_check, cli_commands, cli_no_of_commands, sizeof(struct cli_cmd_tab_t), cmd_cmp ); |
|
return(cli_cmd); |
82,6 → 82,14
|
|
/*-----------------------------------------------------------*/ |
static char func_comment( const unsigned char argc, const char *argv[] ) |
{ |
PRINTF_MACRO( "# > "); |
return EXIT_SUCCESS; |
} |
|
|
/*-----------------------------------------------------------*/ |
static char func_peek( const unsigned char argc, const char *argv[] ) |
{ |
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) ); |
/cli/sys_cmd_table.h
39,13 → 39,13
struct cli_cmd_tab_t cli_commands[] = |
{ |
{ "help", func_help, " help ~ print help message\r" }, |
{ "md", func_md, " md [.b, .w, .l] address [# of objects] ~ memory display\r" }, |
{ "md.b", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" }, |
{ "md.w", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" }, |
{ "md", func_md, " md address [# of objects] ~ memory display\r" }, |
{ "md.b", func_md, " md.b address [# of objects] ~ memory display\r" }, |
{ "md.w", func_md, " md.w address [# of objects] ~ memory display\r" }, |
{ "memtest", func_memtest, " memtest base_address size\r" }, |
{ "mw", func_mw, " mw [.b, .w, .l] address value [count] ~ memory write (fill)\r" }, |
{ "mw.b", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" }, |
{ "mw.w", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" }, |
{ "mw", func_mw, " mw address value [count] ~ memory write (fill)\r" }, |
{ "mw.b", func_mw, " mw.b address value [count] ~ memory write (fill)\r" }, |
{ "mw.w", func_mw, " mw.w address value [count] ~ memory write (fill)\r" }, |
{ "peek", func_peek, " peek address\r" }, |
{ "poke", func_poke, " poke address value\r" }, |
{ "~", NULL, NULL } |