apps/netutils/chat and apps/examples/chat: 'constify' chat variables and parameters

This commit is contained in:
Xiang Xiao 2018-11-07 11:55:09 -06:00 committed by Gregory Nutt
parent 42ce384259
commit c1f0653c85
3 changed files with 43 additions and 44 deletions

View File

@ -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
@ -166,14 +166,14 @@ static int chat_script_read(FAR struct chat_app* priv,
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:

View File

@ -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

View File

@ -86,10 +86,10 @@ 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 const char *script,
FAR struct chat_token **first_tok)
{
FAR char *cursor = script; /* pointer to the current character */
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 */
@ -431,7 +431,7 @@ 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;
int ret;
@ -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;