1/* @title: Parsing */
2#pragma once
3#include <math/fixed.h>
4#include <smp/topology.h>
5#include <stdbool.h>
6#include <stddef.h>
7#include <stdint.h>
8#include <types/types.h>
9
10struct cmdline_range;
11
12/* Just a container for the list */
13struct parse_list {
14 size_t count;
15 char **items; /* Dynamically allocated array of null terminated strings */
16};
17
18/* Returns true if the string matches the type,
19 * and stores parsed value in *out */
20bool parse_is_bool(const char *str, bool *out);
21bool parse_is_data_size(const char *str, uint64_t *out);
22bool parse_is_duration(const char *str, time_ns_t *out);
23bool parse_is_cpu_mask(const char *str, struct cpu_mask *out, size_t n_cpus);
24bool parse_is_mac(const char *str, uint64_t *out);
25bool parse_is_fx(const char *str, fx32_32_t *out);
26bool parse_is_int(const char *str, int64_t *out);
27bool parse_is_uint(const char *str, uint64_t *out);
28bool parse_is_range(const char *str, uint64_t *start, uint64_t *end);
29bool parse_is_list(const char *str, struct parse_list *out);
30
31void parse_list_free(struct parse_list *list);
32
33#define parse_list_for_each(item_var, list) \
34 for (size_t __i = 0; \
35 __i < (list)->count && ((item_var = (list)->items[__i]), true); \
36 __i++)
37