diff --git a/examples/chat/chat_main.c b/examples/chat/chat_main.c index 35390793d..fe791bd29 100644 --- a/examples/chat/chat_main.c +++ b/examples/chat/chat_main.c @@ -74,7 +74,7 @@ struct chat_app int argc; /* number of command-line arguments */ FAR char** argv; /* command-line arguments */ char tty[CHAT_TTYNAME_SIZE]; /* modem TTY device node */ - FAR char* script; /* raw chat script - input to the parser */ + FAR const char *script; /* raw chat script - input to the parser */ bool script_dynalloc; /* true iff the script should be freed */ }; @@ -84,10 +84,10 @@ struct chat_app /* Preset chat scripts */ -FAR char g_chat_script0[] = CONFIG_EXAMPLES_CHAT_PRESET0; -FAR char g_chat_script1[] = CONFIG_EXAMPLES_CHAT_PRESET1; -FAR char g_chat_script2[] = CONFIG_EXAMPLES_CHAT_PRESET2; -FAR char g_chat_script3[] = CONFIG_EXAMPLES_CHAT_PRESET3; +FAR const char g_chat_script0[] = CONFIG_EXAMPLES_CHAT_PRESET0; +FAR const char g_chat_script1[] = CONFIG_EXAMPLES_CHAT_PRESET1; +FAR const char g_chat_script2[] = CONFIG_EXAMPLES_CHAT_PRESET2; +FAR const char g_chat_script3[] = CONFIG_EXAMPLES_CHAT_PRESET3; /**************************************************************************** * Private Functions @@ -105,7 +105,7 @@ static void chat_show_usage(void) "-v : verbose mode\n"); } -static int chat_chardev(FAR struct chat_app* priv) +static int chat_chardev(FAR struct chat_app *priv) { int flags; @@ -124,7 +124,7 @@ static int chat_chardev(FAR struct chat_app* priv) return 0; } -static int chat_script_preset(FAR struct chat_app* priv, int script_number) +static int chat_script_preset(FAR struct chat_app *priv, int script_number) { int ret = 0; @@ -159,21 +159,21 @@ static int chat_script_preset(FAR struct chat_app* priv, int script_number) static int chat_script_read(FAR struct chat_app* priv, FAR const char* filepath) { - FAR char* scriptp; - size_t spare_size = CONFIG_EXAMPLES_CHAT_SIZE-1; + FAR char *scriptp; + size_t spare_size = CONFIG_EXAMPLES_CHAT_SIZE - 1; ssize_t read_size; bool eof = false; int ret = 0; int fd; - priv->script = malloc(CONFIG_EXAMPLES_CHAT_SIZE); - if (!priv->script) + scriptp = malloc(CONFIG_EXAMPLES_CHAT_SIZE); + if (scriptp == NULL) { return -ENOMEM; } priv->script_dynalloc = true; - scriptp = priv->script; + priv->script = scriptp; memset(scriptp, 0, CONFIG_EXAMPLES_CHAT_SIZE); fd = open(filepath, O_RDONLY); @@ -219,8 +219,7 @@ static int chat_script_read(FAR struct chat_app* priv, static int chat_parse_args(FAR struct chat_app* priv) { - /* - * -d TTY device node (non-Linux feature) + /* -d TTY device node (non-Linux feature) * -e echo to stderr * -f script file * -p preprogrammed script (non-Linux feature) @@ -383,7 +382,7 @@ with_tty_dev: with_script: if (priv.script_dynalloc) { - free(priv.script); + free((FAR char *)priv.script); } no_script: diff --git a/include/netutils/chat.h b/include/netutils/chat.h index b86641250..b1ff0a5c3 100644 --- a/include/netutils/chat.h +++ b/include/netutils/chat.h @@ -69,7 +69,7 @@ extern "C" #define EXTERN extern #endif -int chat(FAR struct chat_ctl* ctl, FAR char* script); +int chat(FAR struct chat_ctl *ctl, FAR const char *script); #undef EXTERN #ifdef __cplusplus diff --git a/netutils/chat/chat.c b/netutils/chat/chat.c index c837ccaf5..f2b7949ba 100644 --- a/netutils/chat/chat.c +++ b/netutils/chat/chat.c @@ -75,7 +75,7 @@ struct chat_token * Private Functions ****************************************************************************/ -void chat_init(FAR struct chat* priv, FAR struct chat_ctl* ctl) +void chat_init(FAR struct chat *priv, FAR struct chat_ctl *ctl) { DEBUGASSERT(priv != NULL && ctl != NULL && ctl->timeout >= 0); @@ -85,20 +85,20 @@ void chat_init(FAR struct chat* priv, FAR struct chat_ctl* ctl) /* Linear one-pass tokenizer. */ -static int chat_tokenise(FAR struct chat* priv, - FAR char* script, - FAR struct chat_token** first_tok) +static int chat_tokenise(FAR struct chat *priv, + FAR const char *script, + FAR struct chat_token **first_tok) { - FAR char *cursor = script; /* pointer to the current character */ - unsigned int quoted = 0; /* two-valued: - * 1: quoted (expecting a closing quote) - * 0: not quoted */ - unsigned int escaped = 0; /* two-valued */ - char tok_str[CHAT_TOKEN_SIZE]; /* current token buffer */ - int tok_pos = 0; /* current length of the current token */ + FAR const char *cursor = script; /* pointer to the current character */ + unsigned int quoted = 0; /* two-valued: + * 1: quoted (expecting a closing quote) + * 0: not quoted */ + unsigned int escaped = 0; /* two-valued */ + char tok_str[CHAT_TOKEN_SIZE]; /* current token buffer */ + int tok_pos = 0; /* current length of the current token */ FAR struct chat_token *tok = NULL; /* the last complete token */ - bool no_termin; /* line termination property: - * true iff line terminator is deasserted */ + bool no_termin; /* line termination property: + * true iff line terminator is deasserted */ int ret = 0; /* Delimiter handler */ @@ -285,12 +285,12 @@ static int chat_tokenise(FAR struct chat* priv, /* Creates the internal representation of a tokenised chat script. */ -static int chat_internalise(FAR struct chat* priv, - FAR struct chat_token* tok) +static int chat_internalise(FAR struct chat *priv, + FAR struct chat_token *tok) { unsigned int rhs = 0; /* 1 iff processing the right-hand side, * 0 otherwise */ - FAR struct chat_line* line = NULL; + FAR struct chat_line *line = NULL; int len; /* length of the destination string when variable */ int ret = 0; @@ -412,7 +412,7 @@ static int chat_internalise(FAR struct chat* priv, /* Chat token list deallocator */ -static void chat_tokens_free(FAR struct chat_token* first_tok) +static void chat_tokens_free(FAR struct chat_token *first_tok) { FAR struct chat_token* next_tok; @@ -431,9 +431,9 @@ static void chat_tokens_free(FAR struct chat_token* first_tok) /* Main parsing function. */ -static int chat_script_parse(FAR struct chat* priv, FAR char* script) +static int chat_script_parse(FAR struct chat *priv, FAR const char *script) { - FAR struct chat_token* first_tok; + FAR struct chat_token *first_tok; int ret; ret = chat_tokenise(priv, script, &first_tok); @@ -451,7 +451,7 @@ static int chat_script_parse(FAR struct chat* priv, FAR char* script) * returns a negative error code. */ -static int chat_readb(FAR struct chat* priv, FAR char* c, int timeout_ms) +static int chat_readb(FAR struct chat *priv, FAR char *c, int timeout_ms) { struct pollfd fds; int ret; @@ -483,16 +483,16 @@ static int chat_readb(FAR struct chat* priv, FAR char* c, int timeout_ms) return 0; } -static void chat_flush(FAR struct chat* priv) +static void chat_flush(FAR struct chat *priv) { char c; _info("starting\n"); - while (chat_readb(priv, (FAR char*) &c, 0) == 0); + while (chat_readb(priv, (FAR char *) &c, 0) == 0); _info("done\n"); } -static int chat_expect(FAR struct chat* priv, FAR const char* s) +static int chat_expect(FAR struct chat *priv, FAR const char *s) { char c; struct timespec abstime; @@ -545,7 +545,7 @@ static int chat_expect(FAR struct chat* priv, FAR const char* s) return ret; } -static int chat_send(FAR struct chat* priv, FAR const char* s) +static int chat_send(FAR struct chat *priv, FAR const char *s) { int ret = 0; int len = strlen(s); @@ -658,9 +658,9 @@ static int chat_line_run(FAR struct chat* priv, return ret; } -static int chat_script_run(FAR struct chat* priv) +static int chat_script_run(FAR struct chat *priv) { - FAR struct chat_line* line = priv->script; + FAR struct chat_line *line = priv->script; int ret = 0; #ifdef CONFIG_DEBUG_INFO int line_num = 0; @@ -682,7 +682,7 @@ static int chat_script_run(FAR struct chat* priv) return ret; } -static int chat_script_free(FAR struct chat* priv) +static int chat_script_free(FAR struct chat *priv) { FAR struct chat_line* line = priv->script; FAR struct chat_line* next_line; @@ -709,7 +709,7 @@ static int chat_script_free(FAR struct chat* priv) * Public Functions ****************************************************************************/ -int chat(FAR struct chat_ctl* ctl, FAR char* script) +int chat(FAR struct chat_ctl *ctl, FAR const char *script) { int ret = 0; struct chat priv;