开发者

Shell Text Processing Libraries

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开发者_JAVA技巧 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


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.


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


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

ECMD Reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜