| 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 | |
| 10 | struct cmdline_range; |
| 11 | |
| 12 | /* Just a container for the list */ |
| 13 | struct 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 */ |
| 20 | bool parse_is_bool(const char *str, bool *out); |
| 21 | bool parse_is_data_size(const char *str, uint64_t *out); |
| 22 | bool parse_is_duration(const char *str, time_ns_t *out); |
| 23 | bool parse_is_cpu_mask(const char *str, struct cpu_mask *out, size_t n_cpus); |
| 24 | bool parse_is_mac(const char *str, uint64_t *out); |
| 25 | bool parse_is_fx(const char *str, fx32_32_t *out); |
| 26 | bool parse_is_int(const char *str, int64_t *out); |
| 27 | bool parse_is_uint(const char *str, uint64_t *out); |
| 28 | bool parse_is_range(const char *str, uint64_t *start, uint64_t *end); |
| 29 | bool parse_is_list(const char *str, struct parse_list *out); |
| 30 | |
| 31 | void 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 | |