代码拉取完成,页面将自动刷新
同步操作将从 杰杰/cmd-parser 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-13 10:47:30
* @LastEditTime: 2019-12-17 13:38:02
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "cmd.h"
#include <stdio.h>
static cmd_t *_cmd_begin, *_cmd_end;
static int _cmd_to_lower(int c)
{
if ((c >= 'A') && (c <= 'Z'))
return c + ('a' - 'A');
return c;
}
static unsigned int _cmd_hash(const char* str)
{
unsigned int hash = CMD_HASH; /* 'jiejie' string hash */
int c = *str;
while(*str) {
hash = ((hash << 5) + (hash ^ c)) + (_cmd_to_lower(c));
str++;
c = *str;
}
return hash;
}
static void _cmd_init(const void *begin, const void *end)
{
_cmd_begin = (cmd_t*) begin;
_cmd_end = (cmd_t*) end;
}
static cmd_t* _get_next_cmd(cmd_t *cmd)
{
unsigned int *ptr;
ptr = (unsigned int*) (cmd + 1);
while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _cmd_end))
ptr ++;
return (cmd_t*) ptr;
}
static int _cmd_match(const char *str, const char *cmd)
{
int c1, c2;
do {
c1 = _cmd_to_lower(*str++);
c2 = _cmd_to_lower(*cmd++);
} while((c1 == c2) && c1);
return c1 - c2;
}
static void _list(void)
{
cmd_t *index;
for (index = _cmd_begin; index < _cmd_end; index = _get_next_cmd(index)) {
printf("%s\n",index->cmd);
}
}
REGISTER_CMD(_list, _list);
void cmd_init(void)
{
cmd_t *index;
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */
extern const int CMDS$$Base;
extern const int CMDS$$Limit;
_cmd_init(&CMDS$$Base, &CMDS$$Limit);
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
_cmd_init(__section_begin("CMDS"), __section_end("CMDS"));
#endif
for (index = _cmd_begin; index < _cmd_end; index = _get_next_cmd(index)) {
index->hash = _cmd_hash(index->cmd);
}
}
void cmd_parsing(char *str)
{
cmd_t *index;
unsigned int hash = _cmd_hash(str);
for (index = _cmd_begin; index < _cmd_end; index = _get_next_cmd(index)) {
if (hash == index->hash) {
if (_cmd_match(str, index->cmd) == 0) {
index->handler();
break;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。