Coder Social home page Coder Social logo

chendong-2023 / cmd-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jiejietop/cmd-parser

0.0 0.0 0.0 39 KB

一个非常简单好用的命令解析器,占用资源极少极少,采用哈希算法超快匹配命令!

License: Apache License 2.0

C 100.00%

cmd-parser's Introduction

license

cmd-parser

一个非常简单好用的命令解析器...

这个命令解析器有什么用??

简单来说,我希望我的开发板,可以通过命令执行一些处理,比如说我用串口发一个命令A,开发板就执行A的一些处理,或者,在调试某些AT模组的时候,当我收到模组返回的一些指令后,自动执行一些处理。当然,还有其他的地方可以用得上的,兄弟们自行挖掘!!欢迎提交pr与点个star~

问题

欢迎以 GitHub Issues 的形式提交问题和bug报告

版权和许可

cmd-parser 遵循 Apache License v2.0 开源协议。鼓励代码共享和尊重原作者的著作权,可以自由的使用、修改源代码,也可以将修改后的代码作为开源或闭源软件发布,但必须保留原作者版权声明

使用方法

  1. 注册命令

在工程中的任意位置均可调用(在函数外)

REGISTER_CMD(test1, test1_cmd);
  1. cmd初始化
cmd_init();
  1. 解析命令
cmd_parsing("test1");

特色

  • 用户无需关心命令的存储区域与大小,由编译器静态分配。
  • 加入哈希算法超快速匹配命令,时间复杂度从O(n*m)变为O(n)。
  • 命令支持忽略大小写。
  • 非常易用与非常简洁的代码(不足150行)。

注意事项

  • 本代码目前只支持MDKIAR的编译器,对于gcc尚未移植,欢迎参与贡献

test.c

#include "cmd.h"

void test1_cmd(void)
{
    printf("test1_cmd\n");
}

void test2_cmd(void)
{
    printf("test2_cmd\n");
}

void test3_cmd(void)
{
    printf("test3_cmd\n");
}

REGISTER_CMD(test1, test1_cmd);
REGISTER_CMD(test2, test2_cmd);
REGISTER_CMD(test3, test3_cmd);

int main(void)
{
    cmd_init();

    while (1)
    {
        cmd_parsing("test1");
        cmd_parsing("test2");
        cmd_parsing("test3");
    }
    
    return 0;
}

cmd-parser's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.