⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy.c

📁 自动联想命令行处理代码
💻 C
字号:
#if !BASIC_BIOS

#include <stdio.h>
#include "cli.h"
#include "uart.h"

static CommandNode CLI_NAME_COPY =
{
    "copy",                 // node command hint pointer
    "内存copy",             // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_FROM =
{
    "from",                 // node command hint pointer
    "源地址(HEX)",          // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    CLI_COPY                // node command value
};

static CommandNode CLI_NAME_TO =
{
    "to",                   // node command hint pointer
    "目的地址(HEX)",        // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_SIZE =
{
    "size",                 // node command hint pointer
    "大小(HEX)",            // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_HEX,       // node type
    NULL                    // node command value
};

CommandNode *CLI_Copy[] =
{
    &CLI_NAME_COPY,     // copy
    &CLI_NAME_FROM,     // from
    &CLI_NAME_TO,       // to
    &CLI_NAME_SIZE,     // size
    NULL
};

void CLI_CopyProc( void )
{
    char *s, *d, *str;
    unsigned long src, dst, size, i;
    
    str = CLI_GetCommandKey( 0 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &src ))
        {
            s = (char*)src;
        }
        else
        {
            UART_Printf("\r\nError start");
        }
    }

    str = CLI_GetCommandKey( 1 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &dst ))
        {
            d = (char*)dst;
        }
        else
        {
            UART_Printf("\r\nError end");
        }
    }

    str = CLI_GetCommandKey( 2 );
    if( str != NULL )
    {
        if( 1 == sscanf( str, "%lx", &size ))
        {
        }
        else
        {
            UART_Printf("\r\nError size");
        }
    }

	if( src > dst )
	{
		src^=dst^=src;
	}
	
	if( src + size < dst )
	{
		for( i = 0; i < size; i++ )
		{
		    *d = *s;
		    s++;
		    d++;
		}
	}
	else
	{
		d+=size;
		s+=size;
		for( i = 0; i < size; i++ )
		{
		    *d = *s;
		    s--;
		    d--;
		}
	}

    UART_Printf("\r\nCopy from 0X%X to 0X%X, size 0X%X OK", src, dst, size );
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -