Shell 文本处理库
我需要在微控制器上编写一个非常基本的命令解释器,该解释器将通过虚拟串行端口进行通信。在我继续编写自己的版本之前,我想知道是否有人知道任何用于非常简单、类似 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了在微控制器中实现一个带有行缓冲的真正简单的“shell”(行缓冲意味着仅在“enter”或“\n”之后进行处理),我会做这样的事情(在主循环的中间:
然后的秘密,将是
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:
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.尝试寻找 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
查看ECMD,它是Ethersex 平台。
ECMD 参考。
Check out ECMD, which is a part of the Ethersex platform.
ECMD Reference.