Giter Club home page Giter Club logo

lwshell's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lwshell's Issues

Unnecessary/duplicate argc clear

    /* Must be more than `1` character since we have to include end of line */
    if (lw->buff_ptr > 0) {
        /* Set default values */
        lw->argc = 0;
        lw->argv[0] = lw->buff;

        /* Process complete input */
        str = lw->buff;

        /* Process complete string */
        lw->argc = 0;
        while (*str != '\0') {

Line 112 in lwshell.c

You clear argc, then clear it again before anything could have changed.

Request: Add _ex feature to address multiple shells

As topic.

I have a primary shell I use for on-module CLI access, as well as another shell that allows access to a bootloader CLI of off-board module. This latter terminal has different inputs and a tokenizer.

It would be nice to set both shells up differently and use this framework to address either.

carriage return line feed while cmd handling

Hi,

Really great simple shell but for me there is one handling really bad. So if as an example the user inputs some command (calc) using a terminal which gives /r/n at the end of the command then the input string looks like this

calc 1 2/r/n

So then in the handle function of calc i do some printing to the terminal. But after that /r and /n will be printed also i think that is not a behavior for everyone.

So a quick fix for me was change parse input. And if the parser found some command i will ignore the output of CR or LF but maybe there is a better solution.

best regards,
mathias

input buffer overflow

@MaJerle - I can do a pull request for the below issue, but want to know your preference first.

when the input buffer is full, we get an overflow while parsing the args:

            } else {
                lw->argv[lw->argc++] = str;     /* Set start of argument directly on character */
                while (*str != ' ' && *str != '\0') {
                    if (*str == '"') {          /* Quote should not be here... */
                        *str = '\0';            /* ...add NULL termination to end token */
                    }
                    ++str;
                }
                *str = '\0';
                ++str;   /* <<<==== here str increment over the input buff when the above while stop on the last byte of the buff */
            }

Since this is a light shell, I assume you want to keep performance as good as possible:

  • the first option is less intuitive, but it just adds one byte to the memory usage :)
  • the second option adds more execution code :(

1.
add 2 extra bytes (instead of +1) to the input buffer and change the ADD macro. this way we guarantee an extra NULL at the end:

char buff[LWSHELL_CFG_MAX_INPUT_LEN + 2]; /*!< Shell command input buffer */

 /* Add character to instance */
#define LWSHELL_ADD_CH(lw, ch)      do {            \
    if ((lw)->buff_ptr < (LWSHELL_ARRAYSIZE(lw->buff) - 2)) {   \
        (lw)->buff[(lw)->buff_ptr] = ch;            \
        (lw)->buff[++(lw)->buff_ptr] = '\0';        \
    }                                               \
} while (0)

2.
Stop the loop with some pointer calculation:

            /* Check for number of arguments */
            if (lw->argc == LWSHELL_ARRAYSIZE(lw->argv)) {
                break;
            }

            /* Consume all input buffer... */
            if (str - lw->buff >= sizeof((lw)->buff)) {
                break;
            }
        }

Minimal example code newline character missing

In minimal example code, input string const char* input_str = "mycmd param1 \"param 2 with space\""; is missing a newline or carriage return character. Until one of these characters is detected by lwshell_input function, parsing will not begin and the mycmd_fn function in example will not run.
Changing the input string to const char* input_str = "mycmd param1 \"param 2 with space\"\n"; (or \r) solves the issue and produces the expected behaviour.

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.