diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 13:48:15 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 13:48:15 -0400 |
| commit | def009c1f2d1d71eb269c9398a0476a3f7150b1e (patch) | |
| tree | 8613f669b2b5355b112e28d323ee3406d868bd4b | |
| parent | 093ffe93d0ab486229e36b2a97466ddd51e9fd0e (diff) | |
| download | volute-def009c1f2d1d71eb269c9398a0476a3f7150b1e.zip | |
sort compressor names
| -rw-r--r-- | compressor.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compressor.c b/compressor.c index 1de978a..d54a777 100644 --- a/compressor.c +++ b/compressor.c @@ -25,6 +25,7 @@ static int parse_mass_flow(double val, const char *unit, Flow *flow); static int parse_volume_flow(double val, const char *unit, Flow *flow); static int toml_filter(const struct dirent *de); static int cmp_flow_unit(const void *key, const void *datum); +static int cmp_comp(const void *keyval, const void *datum); /* Load descriptions of all of the compressor maps. @@ -67,6 +68,8 @@ load_compressors(Compressor **comps, int *n) { } free(files); + qsort(*comps, *n, sizeof(**comps), cmp_comp); + return 0; } @@ -250,3 +253,19 @@ toml_filter(const struct dirent *de) { } return strcmp(".toml", extension) == 0; /* extension is ".toml". */ } + +static int +cmp_comp(const void *keyval, const void *datum) { + Compressor a, b; + int ord; + + a = *(Compressor *) keyval; + b = *(Compressor *) datum; + + if ((ord = strncmp(a.brand, b.brand, sizeof(a.brand)))) { + return ord; + } else if ((ord = strncmp(a.series, b.series, sizeof(a.series)))) { + return ord; + } + return strncmp(a.model, b.model, sizeof(a.model)); +} |