star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

commit 32af2942953e4d9b4f0cfe02816cb60a0149019f
parent 6ecc820e189bc891909adb5c2955231ef52a9eaf
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 15 Feb 2022 14:36:55 +0100

Rename the shtr_transitions structure in shtr_transitions_list

Diffstat:
Mcmake/CMakeLists.txt | 8++++----
Msrc/shtr.h | 28++++++++++++++--------------
Dsrc/shtr_transitions.c | 308-------------------------------------------------------------------------------
Asrc/shtr_transitions_list.c | 308+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_shtr_transitions.c | 62+++++++++++++++++++++++++++++++-------------------------------
5 files changed, 357 insertions(+), 357 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -47,11 +47,12 @@ set(SHTR_FILES_SRC shtr.c shtr_log.c shtr_isotope_metadata.c - shtr_transitions.c - shtr_param.c) + shtr_param.c + shtr_transitions_list.c) set(SHTR_FILES_INC shtr_c.h - shtr_log.h) + shtr_log.h + shtr_param.h) set(SHTR_FILES_INC_API shtr.h) @@ -102,4 +103,3 @@ install(TARGETS shtr RUNTIME DESTINATION bin) install(FILES ${SHTR_FILES_INC_API} DESTINATION include/star) install(FILES ${SHTR_FILES_DOC} DESTINATION share/doc/star-hitran) - diff --git a/src/shtr.h b/src/shtr.h @@ -103,7 +103,7 @@ static const struct shtr_transition SHTR_TRANSITION_NULL = /* Forward declarations of opaque data structures */ struct shtr; struct shtr_isotope_metadata; -struct shtr_transitions; +struct shtr_transitions_list; BEGIN_DECLS @@ -174,35 +174,35 @@ shtr_isotope_metadata_find_molecule * Transitions API ******************************************************************************/ SHTR_API res_T -shtr_transitions_load +shtr_transitions_list_load (struct shtr* shtr, const char* path, - struct shtr_transitions** transitions); + struct shtr_transitions_list** trlst); SHTR_API res_T -shtr_transitions_load_stream +shtr_transitions_list_load_stream (struct shtr* shtr, FILE* stream, const char* stream_name, /* NULL <=> use default stream name */ - struct shtr_transitions** transitions); + struct shtr_transitions_list** trlst); SHTR_API res_T -shtr_transitions_ref_get - (struct shtr_transitions* transitions); +shtr_transitions_list_ref_get + (struct shtr_transitions_list* trlst); SHTR_API res_T -shtr_transitions_ref_put - (struct shtr_transitions* transitions); +shtr_transitions_list_ref_put + (struct shtr_transitions_list* trlst); SHTR_API res_T -shtr_transitions_get_count - (const struct shtr_transitions* transitions, +shtr_transitions_list_get_size + (const struct shtr_transitions_list* trlst, size_t* ntransitions); SHTR_API res_T -shtr_transitions_get - (const struct shtr_transitions* transitions, - const struct shtr_transition* transitions_list[]); +shtr_transitions_list_get + (const struct shtr_transitions_list* trlst, + const struct shtr_transition* transitions[]); END_DECLS diff --git a/src/shtr_transitions.c b/src/shtr_transitions.c @@ -1,308 +0,0 @@ -/* Copyright (C) 2022 CNRS - LMD - * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) - * Copyright (C) 2022 Université Paul Sabatier - IRIT - * Copyright (C) 2022 Université Paul Sabatier - Laplace - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#ifndef SHTR_TRANSITIONS_H -#define SHTR_TRANSITIONS_H - -#include "shtr.h" -#include "shtr_c.h" -#include "shtr_log.h" -#include "shtr_param.h" - -#include <rsys/cstr.h> -#include <rsys/dynamic_array.h> -#include <rsys/text_reader.h> - -/* Generate the dynamic array of transitions */ -#define DARRAY_NAME transition -#define DARRAY_DATA struct shtr_transition -#include <rsys/dynamic_array.h> - -struct shtr_transitions { - /* List of transitions */ - struct darray_transition transitions; - - struct shtr* shtr; - ref_T ref; -}; - -/******************************************************************************* - * Helper functions - ******************************************************************************/ -static res_T -create_transitions - (struct shtr* shtr, - struct shtr_transitions** out_transitions) -{ - struct shtr_transitions* transitions = NULL; - res_T res = RES_OK; - ASSERT(shtr && out_transitions); - - transitions = MEM_CALLOC(shtr->allocator, 1, sizeof(*transitions)); - if(!transitions) { - log_err(shtr, "Could not allocate the transitions data structure.\n"); - res = RES_MEM_ERR; - goto error; - } - ref_init(&transitions->ref); - SHTR(ref_get(shtr)); - transitions->shtr = shtr; - darray_transition_init(shtr->allocator, &transitions->transitions); - -exit: - *out_transitions = transitions; - return res; -error: - goto exit; -} - -static res_T -parse_transition(struct shtr_transitions* transitions, struct txtrdr* txtrdr) -{ - struct shtr_transition tr = SHTR_TRANSITION_NULL; - struct param_desc param = PARAM_DESC_NULL; - struct shtr* shtr = NULL; - char* line = NULL; - char* str = NULL; - char* end = NULL; - char backup; - int molecule_id; - int isotope_id_local; - res_T res = RES_OK; - - ASSERT(transitions && txtrdr); - - line = txtrdr_get_line(txtrdr); - ASSERT(line); - - shtr = transitions->shtr; - param.path = txtrdr_get_name(txtrdr); - param.line = txtrdr_get_line_num(txtrdr); - - str = end = line; - backup = str[0]; - #define NEXT(Size) { \ - *end = backup; \ - str = end; \ - end = str+(Size); \ - backup = *end; \ - *end = '\0'; \ - } (void)0 - #define PARSE(Var, Size, Type, Name, Low, Upp, LowIncl, UppIncl) { \ - NEXT(Size); \ - param.name = (Name); \ - param.low = (Low); \ - param.upp = (Upp); \ - param.is_low_incl = (LowIncl); \ - param.is_upp_incl = (UppIncl); \ - res = parse_param_##Type(shtr, str, &param, Var); \ - if(res != RES_OK) goto error; \ - } (void)0 - - PARSE(&molecule_id, 2, int, "molecule identifier", 0,99,1,1); - tr.molecule_id = (int32_t)molecule_id; - - PARSE(&isotope_id_local, 1, int, "isotope local identifier", 0,9,1,1); - tr.isotope_id_local = (int32_t) - (isotope_id_local == 0 ? 9 : (isotope_id_local - 1)); - - PARSE(&tr.wavenumber, 12, double, "central wavenumber", 0,INF,0,1); - PARSE(&tr.intensity, 10, double, "reference intensity", 0,INF,0,1); - - NEXT(10); /* Skip the Enstein coef */ - - PARSE(&tr.gamma_air, 5, double, "air broadening half-width", 0,INF,0,1); - PARSE(&tr.gamma_self, 5, double, "self broadening half-width", 0,INF,0,1); - PARSE(&tr.lower_state_energy, 10, double, "lower state energy", 0,INF,1,1); - PARSE(&tr.n_air, 4, double, "temperature-dependent exponent", 0,INF,0,1); - PARSE(&tr.delta_air, 8, double, "air-pressure wavenumber shift", -INF,INF,1,1); - - /* Skip the remaining values */ - - #undef NEXT - #undef PARSE - - /* Check the size of the remaining data to ensure that there is at least the - * expected number of bytes wrt the HITRAN fileformat */ - *end = backup; - str = end; - if(strlen(str) != 93) { - log_err(transitions->shtr, "%s:%lu: missing data after delta air.\n", - param.path, (unsigned long)param.line); - res = RES_BAD_ARG; - goto error; - } - - res = darray_transition_push_back(&transitions->transitions, &tr); - if(res != RES_OK) { - log_err(transitions->shtr, - "%s:%lu: error storing the transition -- %s.\n", - param.path, (unsigned long)param.line, res_to_cstr(res)); - goto error; - } - -exit: - return res; -error: - goto exit; -} - -static res_T -load_stream - (struct shtr* shtr, - FILE* stream, - const char* name, - struct shtr_transitions** out_transitions) -{ - struct shtr_transitions* transitions = NULL; - struct txtrdr* txtrdr = NULL; - res_T res = RES_OK; - ASSERT(shtr && stream && name && out_transitions); - - res = create_transitions(shtr, &transitions); - if(res != RES_OK) goto error; - - res = txtrdr_stream(transitions->shtr->allocator, stream, name, - 0/*No comment char*/, &txtrdr); - if(res != RES_OK) { - log_err(shtr, "%s: error creating the text reader -- %s.\n", - name, res_to_cstr(res)); - goto error; - } - - for(;;) { - res = txtrdr_read_line(txtrdr); - if(res != RES_OK) { - log_err(shtr, "%s: error reading the line `%lu' -- %s.\n", - name, (unsigned long)txtrdr_get_line_num(txtrdr), res_to_cstr(res)); - goto error; - } - - if(!txtrdr_get_cline(txtrdr)) break; /* No more parsed line */ - res = parse_transition(transitions, txtrdr); - if(res != RES_OK) goto error; - } - -exit: - if(txtrdr) txtrdr_ref_put(txtrdr); - *out_transitions = transitions; - return res; -error: - if(transitions) { - SHTR(transitions_ref_put(transitions)); - transitions = NULL; - } - goto exit; -} - -static void -release_transitions(ref_T * ref) -{ - struct shtr* shtr = NULL; - struct shtr_transitions* transitions = CONTAINER_OF - (ref, struct shtr_transitions, ref); - ASSERT(ref); - shtr = transitions->shtr; - darray_transition_release(&transitions->transitions); - MEM_RM(shtr->allocator, transitions); - SHTR(ref_put(shtr)); -} - -/******************************************************************************* - * Exported functions - ******************************************************************************/ -res_T -shtr_transitions_load - (struct shtr* shtr, - const char* path, - struct shtr_transitions** transitions) -{ - FILE* file = NULL; - res_T res = RES_OK; - - if(!shtr || !path || !transitions) { - res = RES_BAD_ARG; - goto error; - } - - file = fopen(path, "r"); - if(!file) { - log_err(shtr, "%s: error opening file `%s'.\n", FUNC_NAME, path); - res = RES_IO_ERR; - goto error; - } - - res = load_stream(shtr, file, path, transitions); - if(res != RES_OK) goto error; - -exit: - if(file) fclose(file); - return res; -error: - goto exit; -} - -res_T -shtr_transitions_load_stream - (struct shtr* shtr, - FILE* stream, - const char* stream_name, - struct shtr_transitions** transitions) -{ - if(!shtr || !stream || !transitions) return RES_BAD_ARG; - return load_stream - (shtr, stream, stream_name ? stream_name : "<stream>", transitions); -} - -res_T -shtr_transitions_ref_get(struct shtr_transitions* transitions) -{ - if(!transitions) return RES_BAD_ARG; - ref_get(&transitions->ref); - return RES_OK; -} - -res_T -shtr_transitions_ref_put(struct shtr_transitions* transitions) -{ - if(!transitions) return RES_BAD_ARG; - ref_put(&transitions->ref, release_transitions); - return RES_OK; -} - -res_T -shtr_transitions_get_count - (const struct shtr_transitions* transitions, - size_t* ntransitions) -{ - if(!transitions || !ntransitions) return RES_BAD_ARG; - *ntransitions = darray_transition_size_get(&transitions->transitions); - return RES_OK; -} - -res_T -shtr_transitions_get - (const struct shtr_transitions* transitions, - const struct shtr_transition* transitions_list[]) -{ - if(!transitions || !transitions_list) return RES_BAD_ARG; - *transitions_list = darray_transition_cdata_get(&transitions->transitions); - return RES_OK; -} - -#endif /* SHTR_TRANSITIONS_H */ diff --git a/src/shtr_transitions_list.c b/src/shtr_transitions_list.c @@ -0,0 +1,308 @@ +/* Copyright (C) 2022 CNRS - LMD + * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2022 Université Paul Sabatier - IRIT + * Copyright (C) 2022 Université Paul Sabatier - Laplace + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SHTR_TRANSITIONS_H +#define SHTR_TRANSITIONS_H + +#include "shtr.h" +#include "shtr_c.h" +#include "shtr_log.h" +#include "shtr_param.h" + +#include <rsys/cstr.h> +#include <rsys/dynamic_array.h> +#include <rsys/text_reader.h> + +/* Generate the dynamic array of trlst */ +#define DARRAY_NAME transition +#define DARRAY_DATA struct shtr_transition +#include <rsys/dynamic_array.h> + +struct shtr_transitions_list { + /* List of trlst */ + struct darray_transition transitions; + + struct shtr* shtr; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static res_T +create_transitions_list + (struct shtr* shtr, + struct shtr_transitions_list** out_transitions) +{ + struct shtr_transitions_list* trlst = NULL; + res_T res = RES_OK; + ASSERT(shtr && out_transitions); + + trlst = MEM_CALLOC(shtr->allocator, 1, sizeof(*trlst)); + if(!trlst) { + log_err(shtr, "Could not allocate the trlst data structure.\n"); + res = RES_MEM_ERR; + goto error; + } + ref_init(&trlst->ref); + SHTR(ref_get(shtr)); + trlst->shtr = shtr; + darray_transition_init(shtr->allocator, &trlst->transitions); + +exit: + *out_transitions = trlst; + return res; +error: + goto exit; +} + +static res_T +parse_transition(struct shtr_transitions_list* trlst, struct txtrdr* txtrdr) +{ + struct shtr_transition tr = SHTR_TRANSITION_NULL; + struct param_desc param = PARAM_DESC_NULL; + struct shtr* shtr = NULL; + char* line = NULL; + char* str = NULL; + char* end = NULL; + char backup; + int molecule_id; + int isotope_id_local; + res_T res = RES_OK; + + ASSERT(trlst && txtrdr); + + line = txtrdr_get_line(txtrdr); + ASSERT(line); + + shtr = trlst->shtr; + param.path = txtrdr_get_name(txtrdr); + param.line = txtrdr_get_line_num(txtrdr); + + str = end = line; + backup = str[0]; + #define NEXT(Size) { \ + *end = backup; \ + str = end; \ + end = str+(Size); \ + backup = *end; \ + *end = '\0'; \ + } (void)0 + #define PARSE(Var, Size, Type, Name, Low, Upp, LowIncl, UppIncl) { \ + NEXT(Size); \ + param.name = (Name); \ + param.low = (Low); \ + param.upp = (Upp); \ + param.is_low_incl = (LowIncl); \ + param.is_upp_incl = (UppIncl); \ + res = parse_param_##Type(shtr, str, &param, Var); \ + if(res != RES_OK) goto error; \ + } (void)0 + + PARSE(&molecule_id, 2, int, "molecule identifier", 0,99,1,1); + tr.molecule_id = (int32_t)molecule_id; + + PARSE(&isotope_id_local, 1, int, "isotope local identifier", 0,9,1,1); + tr.isotope_id_local = (int32_t) + (isotope_id_local == 0 ? 9 : (isotope_id_local - 1)); + + PARSE(&tr.wavenumber, 12, double, "central wavenumber", 0,INF,0,1); + PARSE(&tr.intensity, 10, double, "reference intensity", 0,INF,0,1); + + NEXT(10); /* Skip the Enstein coef */ + + PARSE(&tr.gamma_air, 5, double, "air broadening half-width", 0,INF,0,1); + PARSE(&tr.gamma_self, 5, double, "self broadening half-width", 0,INF,0,1); + PARSE(&tr.lower_state_energy, 10, double, "lower state energy", 0,INF,1,1); + PARSE(&tr.n_air, 4, double, "temperature-dependent exponent", 0,INF,0,1); + PARSE(&tr.delta_air, 8, double, "air-pressure wavenumber shift", -INF,INF,1,1); + + /* Skip the remaining values */ + + #undef NEXT + #undef PARSE + + /* Check the size of the remaining data to ensure that there is at least the + * expected number of bytes wrt the HITRAN fileformat */ + *end = backup; + str = end; + if(strlen(str) != 93) { + log_err(trlst->shtr, "%s:%lu: missing data after delta air.\n", + param.path, (unsigned long)param.line); + res = RES_BAD_ARG; + goto error; + } + + res = darray_transition_push_back(&trlst->transitions, &tr); + if(res != RES_OK) { + log_err(trlst->shtr, + "%s:%lu: error storing the transition -- %s.\n", + param.path, (unsigned long)param.line, res_to_cstr(res)); + goto error; + } + +exit: + return res; +error: + goto exit; +} + +static res_T +load_stream + (struct shtr* shtr, + FILE* stream, + const char* name, + struct shtr_transitions_list** out_transitions) +{ + struct shtr_transitions_list* trlst = NULL; + struct txtrdr* txtrdr = NULL; + res_T res = RES_OK; + ASSERT(shtr && stream && name && out_transitions); + + res = create_transitions_list(shtr, &trlst); + if(res != RES_OK) goto error; + + res = txtrdr_stream(trlst->shtr->allocator, stream, name, + 0/*No comment char*/, &txtrdr); + if(res != RES_OK) { + log_err(shtr, "%s: error creating the text reader -- %s.\n", + name, res_to_cstr(res)); + goto error; + } + + for(;;) { + res = txtrdr_read_line(txtrdr); + if(res != RES_OK) { + log_err(shtr, "%s: error reading the line `%lu' -- %s.\n", + name, (unsigned long)txtrdr_get_line_num(txtrdr), res_to_cstr(res)); + goto error; + } + + if(!txtrdr_get_cline(txtrdr)) break; /* No more parsed line */ + res = parse_transition(trlst, txtrdr); + if(res != RES_OK) goto error; + } + +exit: + if(txtrdr) txtrdr_ref_put(txtrdr); + *out_transitions = trlst; + return res; +error: + if(trlst) { + SHTR(transitions_list_ref_put(trlst)); + trlst = NULL; + } + goto exit; +} + +static void +release_transitions(ref_T * ref) +{ + struct shtr* shtr = NULL; + struct shtr_transitions_list* trlst = CONTAINER_OF + (ref, struct shtr_transitions_list, ref); + ASSERT(ref); + shtr = trlst->shtr; + darray_transition_release(&trlst->transitions); + MEM_RM(shtr->allocator, trlst); + SHTR(ref_put(shtr)); +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +shtr_transitions_list_load + (struct shtr* shtr, + const char* path, + struct shtr_transitions_list** trlst) +{ + FILE* file = NULL; + res_T res = RES_OK; + + if(!shtr || !path || !trlst) { + res = RES_BAD_ARG; + goto error; + } + + file = fopen(path, "r"); + if(!file) { + log_err(shtr, "%s: error opening file `%s'.\n", FUNC_NAME, path); + res = RES_IO_ERR; + goto error; + } + + res = load_stream(shtr, file, path, trlst); + if(res != RES_OK) goto error; + +exit: + if(file) fclose(file); + return res; +error: + goto exit; +} + +res_T +shtr_transitions_list_load_stream + (struct shtr* shtr, + FILE* stream, + const char* stream_name, + struct shtr_transitions_list** trlst) +{ + if(!shtr || !stream || !trlst) return RES_BAD_ARG; + return load_stream + (shtr, stream, stream_name ? stream_name : "<stream>", trlst); +} + +res_T +shtr_transitions_list_ref_get(struct shtr_transitions_list* trlst) +{ + if(!trlst) return RES_BAD_ARG; + ref_get(&trlst->ref); + return RES_OK; +} + +res_T +shtr_transitions_list_ref_put(struct shtr_transitions_list* trlst) +{ + if(!trlst) return RES_BAD_ARG; + ref_put(&trlst->ref, release_transitions); + return RES_OK; +} + +res_T +shtr_transitions_list_get_size + (const struct shtr_transitions_list* trlst, + size_t* ntransitions) +{ + if(!trlst || !ntransitions) return RES_BAD_ARG; + *ntransitions = darray_transition_size_get(&trlst->transitions); + return RES_OK; +} + +res_T +shtr_transitions_list_get + (const struct shtr_transitions_list* trlst, + const struct shtr_transition* transitions_list[]) +{ + if(!trlst || !transitions_list) return RES_BAD_ARG; + *transitions_list = darray_transition_cdata_get(&trlst->transitions); + return RES_OK; +} + +#endif /* SHTR_TRANSITIONS_H */ diff --git a/src/test_shtr_transitions.c b/src/test_shtr_transitions.c @@ -87,7 +87,7 @@ test_load(struct shtr* shtr) const size_t ntransitions = sizeof(transitions) / sizeof(struct shtr_transition); - struct shtr_transitions* trs = NULL; + struct shtr_transitions_list* trs = NULL; const struct shtr_transition* trs_list = NULL; const char* filename = "test_transitions.txt"; FILE* fp = NULL; @@ -97,57 +97,57 @@ test_load(struct shtr* shtr) print_transitions(fp, transitions, ntransitions); rewind(fp); - CHK(shtr_transitions_load_stream(NULL, fp, NULL, &trs) == RES_BAD_ARG); - CHK(shtr_transitions_load_stream(shtr, NULL, NULL, &trs) == RES_BAD_ARG); - CHK(shtr_transitions_load_stream(shtr, fp, NULL, NULL) == RES_BAD_ARG); - CHK(shtr_transitions_load_stream(shtr, fp, NULL, &trs) == RES_OK); + CHK(shtr_transitions_list_load_stream(NULL, fp, NULL, &trs) == RES_BAD_ARG); + CHK(shtr_transitions_list_load_stream(shtr, NULL, NULL, &trs) == RES_BAD_ARG); + CHK(shtr_transitions_list_load_stream(shtr, fp, NULL, NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_load_stream(shtr, fp, NULL, &trs) == RES_OK); - CHK(shtr_transitions_get_count(NULL, &n) == RES_BAD_ARG); - CHK(shtr_transitions_get_count(trs, NULL) == RES_BAD_ARG); - CHK(shtr_transitions_get_count(trs, &n) == RES_OK); + CHK(shtr_transitions_list_get_size(NULL, &n) == RES_BAD_ARG); + CHK(shtr_transitions_list_get_size(trs, NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_get_size(trs, &n) == RES_OK); CHK(n == ntransitions); - CHK(shtr_transitions_get(NULL, &trs_list) == RES_BAD_ARG); - CHK(shtr_transitions_get(trs, NULL) == RES_BAD_ARG); - CHK(shtr_transitions_get(trs, &trs_list) == RES_OK); + CHK(shtr_transitions_list_get(NULL, &trs_list) == RES_BAD_ARG); + CHK(shtr_transitions_list_get(trs, NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_get(trs, &trs_list) == RES_OK); FOR_EACH(i, 0, n) CHK(transition_eq(trs_list+i, transitions+i)); - CHK(shtr_transitions_ref_get(NULL) == RES_BAD_ARG); - CHK(shtr_transitions_ref_get(trs) == RES_OK); - CHK(shtr_transitions_ref_put(NULL) == RES_BAD_ARG); - CHK(shtr_transitions_ref_put(trs) == RES_OK); - CHK(shtr_transitions_ref_put(trs) == RES_OK); + CHK(shtr_transitions_list_ref_get(NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_ref_get(trs) == RES_OK); + CHK(shtr_transitions_list_ref_put(NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_ref_put(trs) == RES_OK); + CHK(shtr_transitions_list_ref_put(trs) == RES_OK); CHK(fclose(fp) == 0); - CHK(shtr_transitions_load(NULL, filename, &trs) == RES_BAD_ARG); - CHK(shtr_transitions_load(shtr, NULL, &trs) == RES_BAD_ARG); - CHK(shtr_transitions_load(shtr, filename, NULL) == RES_BAD_ARG); - CHK(shtr_transitions_load(shtr, filename, &trs) == RES_OK); + CHK(shtr_transitions_list_load(NULL, filename, &trs) == RES_BAD_ARG); + CHK(shtr_transitions_list_load(shtr, NULL, &trs) == RES_BAD_ARG); + CHK(shtr_transitions_list_load(shtr, filename, NULL) == RES_BAD_ARG); + CHK(shtr_transitions_list_load(shtr, filename, &trs) == RES_OK); - CHK(shtr_transitions_get_count(trs, &n) == RES_OK); + CHK(shtr_transitions_list_get_size(trs, &n) == RES_OK); CHK(n == ntransitions); - CHK(shtr_transitions_get(trs, &trs_list) == RES_OK); + CHK(shtr_transitions_list_get(trs, &trs_list) == RES_OK); FOR_EACH(i, 0, n) CHK(transition_eq(trs_list+i, transitions+i)); - CHK(shtr_transitions_ref_put(trs) == RES_OK); + CHK(shtr_transitions_list_ref_put(trs) == RES_OK); } static void test_transition (struct shtr* shtr, const struct shtr_transition* tr, const res_T res) { - struct shtr_transitions* trs = NULL; + struct shtr_transitions_list* trs = NULL; FILE* fp = NULL; CHK(fp = tmpfile()); print_transitions(fp, tr, 1); rewind(fp); - CHK(shtr_transitions_load_stream(shtr, fp, NULL, &trs) == res); + CHK(shtr_transitions_list_load_stream(shtr, fp, NULL, &trs) == res); CHK(fclose(fp) == 0); - if(res == RES_OK) CHK(shtr_transitions_ref_put(trs) == RES_OK); + if(res == RES_OK) CHK(shtr_transitions_list_ref_put(trs) == RES_OK); } static void @@ -221,18 +221,18 @@ check_transition(const struct shtr_transition* tr) static void test_load_file(struct shtr* shtr, const char* path) { - struct shtr_transitions* trs = NULL; + struct shtr_transitions_list* trs = NULL; const struct shtr_transition* trs_list = NULL; size_t i, n; CHK(path); printf("Loading `%s'.\n", path); - CHK(shtr_transitions_load(shtr, path, &trs) == RES_OK); - CHK(shtr_transitions_get_count(trs, &n) == RES_OK); + CHK(shtr_transitions_list_load(shtr, path, &trs) == RES_OK); + CHK(shtr_transitions_list_get_size(trs, &n) == RES_OK); printf(" #transitions: %lu\n", n); - CHK(shtr_transitions_get(trs, &trs_list) == RES_OK); + CHK(shtr_transitions_list_get(trs, &trs_list) == RES_OK); FOR_EACH(i, 0, n) check_transition(trs_list+i); - CHK(shtr_transitions_ref_put(trs) == RES_OK); + CHK(shtr_transitions_list_ref_put(trs) == RES_OK); } int