📄 shell.c
字号:
printf( "\n" ); /* Restore shell setup (incl. ESR settings) */ shell_restore(); /* re-initialize context and make a return to the bottom of shell() */ EXCEP_exc_handler_ret_ss( &shell_restart_context );}/************************************************************************ * * shell_restore * Description : * ------------- * Restore shell setup to state before application was started. * Does not restore cpu registers. * * Return values : * --------------- * None * ************************************************************************/void shell_restore( void ){ /* Restore registered exception handlers */ EXCEP_set_handlers( EXCEP_HANDLERS_SHELL ); /* clean up ram vectors modified by application */ EXCEP_install_exc_in_ram(); /* Restart DMA */ sys_dma_enable( TRUE );}/************************************************************************ * shell_command_error ************************************************************************/voidshell_command_error( t_cmd *cmd, /* Command definition or NULL */ UINT32 err ) /* Error code */{ int i; t_sys_error_string error_string; failing_cmd = cmd; /* lookup syserror */ error_string.syserror = err; error_string.count = MAX_NUMBER_OF_ERROR_STRINGS; error_string.strings = err_strings; for (i=0; i<3; i++) { error_string.strings[i] = NULL; } SYSCON_read( SYSCON_ERROR_LOOKUP_ID, &error_string, sizeof( error_string ) ); /* CTRL-C is not an error */ if( err != SHELL_ERROR_CONTROL_C_DETECTED ) printf( "Error : " ); /* Check for user defined error message */ if( error_string.strings[SYSCON_ERRORMSG_IDX] ) { printf( "%s\n", error_string.strings[SYSCON_ERRORMSG_IDX] ); } /* Check for user defined diagnose message */ if( error_string.strings[SYSCON_DIAGMSG_IDX] ) { printf( "Diag : %s\n", error_string.strings[SYSCON_DIAGMSG_IDX] ); } /* Check for user defined hint message */ if( error_string.strings[SYSCON_HINTMSG_IDX] ) { printf( "Hint : %s\n", error_string.strings[SYSCON_HINTMSG_IDX] ); }}/************************************************************************ * * shell_decode_token * Description : * ------------- * * Decode token * * Return values : * --------------- * * TRUE -> OK, FALSE -> Failed (never happens) * ************************************************************************/boolshell_decode_token( char *token, /* Token to be decoded */ UINT32 *type, /* Type of token */ t_shell_option *decode ) /* Decoded value */{ if( !decode_option( decode, type, token) ) if( !shell_decode_number( decode, type, token) ) if( !decode_ip( decode, type, token) ) { /* String */ decode->string = token; *type = SHELL_TOKEN_STRING; } return TRUE;}/************************************************************************ * shell_decode_number ************************************************************************/boolshell_decode_number( t_shell_option *decode, UINT32 *type, char *token ){ UINT32 len, base; UINT32 len_temp; char *endp; UINT32 i; /* Lets see if it is a number */ len = 0; /* In case of no radix prefix */ base = SHELL_RADIX_DEFAULT; for( i=0; i < SHELL_PREFIX_NUMBER_COUNT; i++ ) { len_temp = strlen( sh_prefix[i].name ); if( strncmp( token, sh_prefix[i].name, len_temp ) == 0 ) { base = sh_prefix[i].base; len = len_temp; break; } } errno = 0; if( sys_64bit ) { decode->number64 = (UINT64)strtoull( &token[len], &endp, base ); if( (*endp == '\0') && (errno == 0) ) { if( decode->number64 > MAXUINT(sizeof(UINT32)) ) { if( type ) *type = SHELL_TOKEN_NUMBER64; } else { decode->number = (UINT32)decode->number64; if( type ) *type = SHELL_TOKEN_NUMBER; } return TRUE; } } else { decode->number = (UINT64)strtoul( &token[len], &endp, base ); if( (*endp == '\0') && (errno == 0) ) { if( type ) *type = SHELL_TOKEN_NUMBER; return TRUE; } } return FALSE;}/************************************************************************ * * shell_lookup_cmd * Description : * ------------- * * Search command line for (possibly partial) match in command array. * Also to be used for command completion. * * Return values : * --------------- * * Pointer to command found, if any (else NULL) * ************************************************************************/t_cmd *shell_lookup_cmd( char *name, /* Command name */ bool *ambivalent, /* TRUE -> match is not unique */ UINT32 *len, /* Number of valid chars */ t_cmd **cmd_list, /* array of ptr to commands */ UINT32 cmd_count ) /* Number of commands */{ t_cmd *cmd, *cmd_found; UINT32 i; char ch; cmd_found = NULL; if(ambivalent) *ambivalent = FALSE; /* Hack in order to handle case insensitivity of * Microsoft SDB commands. */ if( strlen( name ) == 1 ) { ch = *name; *name = tolower(*name); } /* Try to find a match */ for( i=0; i < cmd_count; i++ ) { cmd = cmd_list[i]; if( strstr( cmd->name, name ) == cmd->name ) { /* Found match */ if( strcmp( cmd->name, name ) == 0 ) { /* Exact match */ if(len) *len = strlen( cmd->name ); cmd_found = cmd; break; } if( cmd_found ) { /* Got one already */ UINT32 t; /* Determine the common characters */ for( t=0; cmd_found->name[t] == cmd->name[t]; t++ ); if(len) *len = MIN(t, *len); if(ambivalent) *ambivalent = TRUE; } else { if( strlen(name) > 1 ) /* Min 2 char for autocompletion */ { cmd_found = cmd; if(len) *len = strlen(cmd->name); } } } } /* Hack in order to handle case insensitivity of * Microsoft SDB commands. */ if( strlen( name ) == 1 ) { *name = ch; } return cmd_found;}/************************************************************************ * * shell_print_dot * Description : * ------------- * * Print dot on screen * * Return values : * --------------- * * void * ************************************************************************/boolshell_print_dot( UINT32 *count ){ PUTCHAR( DEFAULT_PORT, '.' ); if( ((++(*count) % 40) == 0) ) { PUTCHAR( DEFAULT_PORT, '\n' ); } return GETCHAR_CTRLC( DEFAULT_PORT );}/************************************************************************ * * shell_setmore * Description : * ------------- * * Enable/disable 'more' control from shell_puts and shell_putc * * Return values : * --------------- * * None * ************************************************************************/voidshell_setmore( bool enable_more ){ more = enable_more; linenum = 0; indent_prev = 0;}/************************************************************************ * * shell_puts * Description : * ------------- * * Print string to stdout * * Return values : * --------------- * * TRUE -> Ctrl^C was pressed * ************************************************************************/boolshell_puts( char *string, UINT32 indent ){ UINT32 count, len; UINT32 first_newline; bool nl; char ch; bool rc; UINT32 linemax, linewidth;#if 0 linemax = getenv( "linemax" ); linewidth = getenv( "linewidth" );#else linemax = MON_DEF_LINEMAX - 1; /* Space for 'Press Ctrl-c ... message */ linewidth = MON_DEF_LINEWIDTH;#endif if( linewidth <= indent ) /* This is an error */ return TRUE; while( *string != '\0' ) { if( linenum == linemax ) { /* Print 'press any key...' message */ PUTS( DEFAULT_PORT, continue_msg ); while( !GETCHAR( DEFAULT_PORT, &ch ) ); /* Remove 'press any key...' message */ len = strlen( continue_msg ); moveleft( len ); for(count=0; count<len; count++) { PUTCHAR( DEFAULT_PORT, ' ' ); } moveleft( len ); if( ch == CTRL_C ) { linenum = 1; /* Keep last line */ ctrl_c_flag = TRUE; return TRUE; } else { linenum = ( (ch == CR) || (ch == LF) ) ? linemax - 1 : 1; /* Keep last line */ indent_prev = 0; } } /* Indent */ if( indent ) { if (indent < indent_prev) indent = indent_prev; count = indent - indent_prev; indent_prev += count; } else count = 0; while(count--) { PUTCHAR( DEFAULT_PORT, ' ' ); } first_newline = strcspn( string, "\n" ); count = ( first_newline + indent <= linewidth ) ? first_newline + 1 : linewidth - indent; while( count-- && (*string != '\0') ) { nl = (*string == '\n'); PUTCHAR( DEFAULT_PORT, *(string++) ); indent_prev++; if(nl) { indent_prev = 0; if( more ) linenum++; } } if( (*string != '\0') && (!nl) ) { PUTCHAR( DEFAULT_PORT, '\n' ); indent_prev = 0; if( more ) linenum++; } } rc = GETCHAR_CTRLC( DEFAULT_PORT ); if( rc ) ctrl_c_flag = TRUE; return rc;}/************************************************************************ * * shell_putc * Description : * ------------- * * Print char to stdout * * Return values : * --------------- * * TRUE -> Ctrl^C was pressed * ************************************************************************/boolshell_putc( char ch, UINT32 indent ){ char s[2]; s[0] = ch; s[1] = '\0'; return shell_puts( s, indent );}/************************************************************************ * * shell_get_line * Description : * ------------- * * Get command line with handling of special characters * * Return values : * --------------- * * FALSE -> Ctrl^C was pressed * ************************************************************************/boolshell_get_line( char *line, /* Line buffer */ UINT32 maxchars, /* Max number of chars not counting terminating '\0' */ bool first_line, /* TRUE -> First line (ie not a \CR continuation) */ bool full, /* TRUE -> Handle command stack and autocompletion */ t_shell_line_buf *buf ) /* Command stack (only used if full == TRUE) */{ UINT32 cursor, eol; char ch; UINT32 slash_count; bool line_shift, line_done; UINT32 len; t_cmd *cmd; UINT32 current_from_buf; if( start ) { /* Use $start as the first command line */ strcpy( line, "$start" ); return TRUE; } *line = '\0'; cursor = 0; eol = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -