[PATCH v2 04/13] pxe_utils: extract per-entry key parsing into parse_label_keys()
Alexey Charkov <[email protected]>
| Newsgroups | org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <[email protected]> |
Split the body of parse_label() into a standalone parse_label_keys() helper that walks key/value lines and populates a pre-existing struct pxe_label. parse_label() becomes a thin wrapper that creates the label, reads its name, attaches it to the menu, and delegates. This is a pure refactor: the new helper contains the original loop verbatim, with the local variable declarations moved to its scope. No call sites or behaviour change. A subsequent change will export this helper so callers parsing formats that lack a 'label' header (notably Boot Loader Specification type #1 entries) can populate a label directly from a file body without duplicating the parser. Signed-off-by: Alexey Charkov <[email protected]> --- boot/pxe_utils.c | 64 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 078eb2d0c244..25159bbc36f8 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -1287,35 +1287,27 @@ static int parse_label_kernel(char **c, struct pxe_label *label) return 1; } -/* - * Parses a label and adds it to the list of labels for a menu. +/** + * parse_label_keys() - Parse the body of a label * - * A label ends when we either get to the end of a file, or - * get some input we otherwise don't have a handler defined - * for. + * Walks the sequence of key/value lines that follow a 'label NAME' header, + * populating @label. Stops at end-of-file or at a token that does not + * belong inside a label (which is pushed back so the caller can handle it). * + * @c: Pointer to the cursor into the file being parsed; updated on return + * @cfg: Menu the label belongs to (used for 'menu default' bookkeeping) + * @label: Label to populate; must already be allocated and (when called for + * a file that has a 'label' header) attached to @cfg->labels + * Return: 1 on success, < 0 on error */ -static int parse_label(char **c, struct pxe_menu *cfg) +static int parse_label_keys(char **c, struct pxe_menu *cfg, + struct pxe_label *label) { struct token t; + char *s; int len; - char *s = *c; - struct pxe_label *label; int err; - label = label_create(); - if (!label) - return -ENOMEM; - - err = parse_sliteral(c, &label->name); - if (err < 0) { - printf("Expected label name: %.*s\n", (int)(*c - s), s); - label_destroy(label); - return -EINVAL; - } - - list_add_tail(&label->list, &cfg->labels); - while (1) { s = *c; get_token(c, &t, L_KEYWORD); @@ -1397,6 +1389,36 @@ static int parse_label(char **c, struct pxe_menu *cfg) } } +/* + * Parses a label and adds it to the list of labels for a menu. + * + * A label ends when we either get to the end of a file, or + * get some input we otherwise don't have a handler defined + * for. + * + */ +static int parse_label(char **c, struct pxe_menu *cfg) +{ + char *s = *c; + struct pxe_label *label; + int err; + + label = label_create(); + if (!label) + return -ENOMEM; + + err = parse_sliteral(c, &label->name); + if (err < 0) { + printf("Expected label name: %.*s\n", (int)(*c - s), s); + label_destroy(label); + return -EINVAL; + } + + list_add_tail(&label->list, &cfg->labels); + + return parse_label_keys(c, cfg, label); +} + /* * This 16 comes from the limit pxelinux imposes on nested includes. * -- 2.54.0