mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 10:39:08 +00:00
cli: Support macro processing with a fixed-size buffer
At present cli_simple_process_macros() requires that the caller provide an output buffer that is exactly CONFIG_SYS_CBSIZE bytes in length. This makes sense since it is designed to be used from the command line. But we also want to use it for bootargs substitution. Update the function to allow the caller to specify the buffer size. Also return an error if the buffer is exhausted. The caller can ignore that if preferred. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
488d89afb8
commit
1a62d64c7d
3 changed files with 19 additions and 8 deletions
|
@ -60,13 +60,14 @@ int cli_simple_parse_line(char *line, char *argv[])
|
|||
return nargs;
|
||||
}
|
||||
|
||||
void cli_simple_process_macros(const char *input, char *output)
|
||||
int cli_simple_process_macros(const char *input, char *output, int max_size)
|
||||
{
|
||||
char c, prev;
|
||||
const char *varname_start = NULL;
|
||||
int inputcnt = strlen(input);
|
||||
int outputcnt = CONFIG_SYS_CBSIZE;
|
||||
int outputcnt = max_size;
|
||||
int state = 0; /* 0 = waiting for '$' */
|
||||
int ret;
|
||||
|
||||
/* 1 = waiting for '(' or '{' */
|
||||
/* 2 = waiting for ')' or '}' */
|
||||
|
@ -157,13 +158,18 @@ void cli_simple_process_macros(const char *input, char *output)
|
|||
prev = c;
|
||||
}
|
||||
|
||||
if (outputcnt)
|
||||
ret = inputcnt ? -ENOSPC : 0;
|
||||
if (outputcnt) {
|
||||
*output = 0;
|
||||
else
|
||||
} else {
|
||||
*(output - 1) = 0;
|
||||
ret = -ENOSPC;
|
||||
}
|
||||
|
||||
debug_parser("[PROCESS_MACROS] OUTPUT len %zd: \"%s\"\n",
|
||||
strlen(output_start), output_start);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -239,7 +245,8 @@ int cli_simple_run_command(const char *cmd, int flag)
|
|||
debug_parser("token: \"%s\"\n", token);
|
||||
|
||||
/* find macros in this token and replace them */
|
||||
cli_simple_process_macros(token, finaltoken);
|
||||
cli_simple_process_macros(token, finaltoken,
|
||||
sizeof(finaltoken));
|
||||
|
||||
/* Extract arguments */
|
||||
argc = cli_simple_parse_line(finaltoken, argv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue