rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
log_numbers.h
Go to the documentation of this file.
1
30
31#pragma once
32
33#include <stdbool.h>
34#include <stddef.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
43#define LOG_DIGITS_MAX 40
45#define LOG_UNIT_MAX 12
46
53
61
65typedef enum {
68 LOG_EV_DE,
69 LOG_EV_EN
71
75typedef struct {
78 int sign;
79 int exp;
81
93bool log_split_value(const char *raw, log_value_t *out);
94
101log_evidence_t log_evidence_of(const char *digits);
102
106typedef struct {
107 int de;
108 int en;
112
119
128void log_votes_add(log_votes_t *v, const char *raw);
129
143 bool *confident, bool *conflict);
144
156bool log_is_well_formed(const char *digits, log_conv_t convention);
157
168bool log_parse_with(const char *raw, log_conv_t convention,
169 double *value, char *unit, size_t unit_size);
170
179bool log_parse_loose(const char *raw, log_ambig_t fallback, double *value);
180
184#define LOG_UNIT_SLOTS 4
185/* --------------------------------------------------------------- units --- */
186
194
201
208void log_unit_tally_add(log_unit_tally_t *t, const char *unit);
209
218void log_unit_dominant(const log_unit_tally_t *t, char *out, size_t out_size,
219 bool *mixed);
220
232void log_unit_from_header(const char *header, char *name, size_t name_size,
233 char *unit, size_t unit_size);
234
242double log_time_unit_scale(const char *unit);
243
244#ifdef __cplusplus
245}
246#endif
log_conv_t log_votes_result(const log_votes_t *v, log_ambig_t fallback, bool *confident, bool *conflict)
Decide the convention from the tally.
Definition log_numbers.c:429
void log_votes_reset(log_votes_t *v)
Clear the tally.
Definition log_numbers.c:397
log_conv_t
Decimal convention of a file.
Definition log_numbers.h:48
@ LOG_CONV_AUTO
Definition log_numbers.h:49
@ LOG_CONV_DE
Definition log_numbers.h:50
@ LOG_CONV_EN
Definition log_numbers.h:51
log_evidence_t
What one numeric string proves about the convention.
Definition log_numbers.h:65
@ LOG_EV_NONE
Definition log_numbers.h:66
@ LOG_EV_AMBIGUOUS
Definition log_numbers.h:67
bool log_parse_loose(const char *raw, log_ambig_t fallback, double *value)
Parse a standalone value, inferring the convention from it alone.
Definition log_numbers.c:597
double log_time_unit_scale(const char *unit)
Seconds per unit for a time column, or 0 when the name is not a time unit.
Definition log_numbers.c:864
bool log_is_well_formed(const char *digits, log_conv_t convention)
Is digits well formed under convention?
Definition log_numbers.c:485
#define LOG_UNIT_MAX
Longest unit suffix the parser reads in one cell, characters.
Definition log_numbers.h:45
void log_unit_tally_add(log_unit_tally_t *t, const char *unit)
Add a unit suffix to a tally.
Definition log_numbers.c:615
#define LOG_DIGITS_MAX
Longest numeric body and unit suffix the parser reads in one cell.
Definition log_numbers.h:43
void log_unit_tally_reset(log_unit_tally_t *t)
Clear a unit tally.
Definition log_numbers.c:608
bool log_split_value(const char *raw, log_value_t *out)
Split a raw cell into numeric text, exponent and unit.
Definition log_numbers.c:214
log_evidence_t log_evidence_of(const char *digits)
Inspect one already-split numeric string and report what it proves.
Definition log_numbers.c:341
void log_votes_add(log_votes_t *v, const char *raw)
Feed one raw cell.
Definition log_numbers.c:404
#define LOG_UNIT_SLOTS
Tally of unit suffixes seen in one column, in first-seen order.
Definition log_numbers.h:184
log_ambig_t
What a wholly ambiguous file defaults to.
Definition log_numbers.h:57
@ LOG_AMBIG_DECIMAL
Definition log_numbers.h:59
@ LOG_AMBIG_THOUSANDS
Definition log_numbers.h:58
void log_unit_dominant(const log_unit_tally_t *t, char *out, size_t out_size, bool *mixed)
The most common non-empty suffix. mixed reports more than one.
Definition log_numbers.c:642
void log_unit_from_header(const char *header, char *name, size_t name_size, char *unit, size_t unit_size)
Pull a unit out of a column header: "voltage (V)", "current [A]", "speed km/h", "power (W)"....
Definition log_numbers.c:751
bool log_parse_with(const char *raw, log_conv_t convention, double *value, char *unit, size_t unit_size)
Parse one cell with a known convention.
Definition log_numbers.c:544
Tally of unit suffixes seen in one column, in first-seen order.
Definition log_numbers.h:188
char units[LOG_UNIT_SLOTS][LOG_UNIT_MAX]
Definition log_numbers.h:189
int used
Definition log_numbers.h:191
int counts[LOG_UNIT_SLOTS]
Definition log_numbers.h:190
bool overflowed
Definition log_numbers.h:192
A cell split into its parts. digits keeps its separators.
Definition log_numbers.h:75
char digits[LOG_DIGITS_MAX]
Definition log_numbers.h:76
int exp
Definition log_numbers.h:79
int sign
Definition log_numbers.h:78
char unit[LOG_UNIT_MAX]
Definition log_numbers.h:77
Running tally of the evidence seen so far.
Definition log_numbers.h:106
int en
Definition log_numbers.h:108
int de
Definition log_numbers.h:107
char ambiguous_sep
Definition log_numbers.h:110
int ambiguous
Definition log_numbers.h:109