Shell 文本处理库

发布于 2024-11-14 06:46:56 字数 203 浏览 4 评论 0原文

我需要在微控制器上编写一个非常基本的命令解释器,该解释器将通过虚拟串行端口进行通信。在我继续编写自己的版本之前,我想知道是否有人知道任何用于非常简单、类似 shell 的文本处理的库。我想要 shell 中的标准功能,例如仅在用户输入新行后才可以使用收到的文本,按退格键会删除队列中的最后一个字符,而不是在队列中添加另一个字符,诸如此类。

有什么想法吗?

谢谢

I need to write a very basic command interpreter on a micro controller that will communicate over a virtual serial port. Before I go ahead and write my own version of this, I was wondering if anyone knew of any libraries for very simple, shell-like text processing. I'd like the features that are standard in a shell, such as text received only being available after the user types in a new line, pressing backspace removes the last character in the queue rather than adding another char in the queue, stuff like that.

Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杯别 2024-11-21 06:46:56

为了在微控制器中实现一个带有行缓冲的真正简单的“shell”(行缓冲意味着仅在“enter”或“\n”之后进行处理),我会做这样的事情(在主循环的中间:

char * p = my_read_buffer; //this is in the initialization, rather than the main loop

if (byte_from_my_uart_avaliable()) {
    *p = read_uart_byte();

    if (*p == '\n') {
        process_input(my_read_buffer);
        p = my_read_buffer; //reset the linebuffer
    }
    else 
        p++;
}

然后的秘密,将是 process_input() 函数,您将在其中解析命令及其参数,以便您可以调用适当的函数来处理它们。

这只是一个远未完成的想法,您需要这样做。对之前收到的字符数进行限制'\n' 以防止溢出。

to achieve a truly simple "shell" with line buffering (line buffering means processing only after an "enter" or '\n') in a microcontroller, i would do something like this (in the middle of the main loop:

char * p = my_read_buffer; //this is in the initialization, rather than the main loop

if (byte_from_my_uart_avaliable()) {
    *p = read_uart_byte();

    if (*p == '\n') {
        process_input(my_read_buffer);
        p = my_read_buffer; //reset the linebuffer
    }
    else 
        p++;
}

The secret then, would be the process_input() function, where you would parse the commands and its parameters, so you could call the appropriate functions to handle them.

This is just an idea far from finished, you would need to put a limit to the number of chars received before a '\n' to prevent overflow.

揽清风入怀 2024-11-21 06:46:56

尝试寻找 Forth 解释器。这是一个庞大的生态系统,您会发现许多旨在在固件中使用的实现,例如 Open固件1实现OpenBIOS。例如,开放固件² 是 BSD 许可的,包含终端访问代码,您可以重复使用。我不知道开放固件代码的可移植性如何,但如果它不适合您,我建议搜索其他满足您的可移植性和许可要求并具有终端访问组件的 Forth 系统。

1 规格
² 程序

Try looking for a Forth interpreter. This is a large ecosystem, and you'll find many implementations that are intended to be used in firmware, such as Open Firmware¹ implementations OpenBIOS. For example Open Firmware² is BSD-licensed and includes code for terminal access, which you may be able to reuse. I don't know how portable the Open Firmware code is, but if it doesn't suit you, I suggest searching for other Forth systems meeting your portability and licensing requirements and having a terminal access component.

¹ the specification
² the program

雪花飘飘的天空 2024-11-21 06:46:56

查看ECMD,它是Ethersex 平台。

ECMD 参考

Check out ECMD, which is a part of the Ethersex platform.

ECMD Reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文