commit 5c2f11217d8feda664b828c5741be467b355cf0a
parent 05ab9a77eb38b07d196f7c934df023d4c03d0e6e
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Tue, 14 Jan 2025 13:01:42 +0100
Set sphin_config to read the input file
Diffstat:
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -25,7 +25,9 @@
#include "sphin.h"
#include "sphin_c.h"
+#include <rsys/cstr.h> /* res_to_cstr */
#include <rsys/ref_count.h> /* ref_T */
+#include <rsys/text_reader.h>
#include <errno.h>
#include <stdio.h> /* fopen, fclose */
@@ -91,23 +93,51 @@ load_stream
(struct sphin* sphin,
FILE* stream,
const char* streamname,
- struct sphin_config** config)
+ struct sphin_config** out_config)
{
+ struct sphin_config* config = NULL;
+ struct txtrdr* txtrdr = NULL;
res_T res = RES_OK;
ASSERT(NULL != sphin);
ASSERT(NULL != stream);
ASSERT(NULL != streamname);
- ASSERT(NULL != config);
+ ASSERT(NULL != out_config);
+
+ res = config_create(sphin, &config);
+ if (res != RES_OK) {
+ goto error;
+ }
- res = config_create(sphin, config);
+ res = txtrdr_stream(sphin->allocator, stream, streamname, '#', &txtrdr);
if (res != RES_OK) {
goto error;
}
+ res = txtrdr_read_line(txtrdr);
+ if (res != RES_OK) {
+ goto error;
+ }
+
+ while (NULL != txtrdr_get_line(txtrdr)) {
+ /* TODO */
+ }
+
exit:
+ *out_config = config;
+ if (NULL != txtrdr) {
+ txtrdr_ref_put(txtrdr);
+ }
return res;
error:
+ if (NULL != config) {
+ SPHIN(config_ref_put(config));
+ config = NULL;
+ }
+ ERROR
+ (sphin,
+ "%s: %s: Error while loading stream -- %s\n",
+ __FILE__, FUNC_NAME, res_to_cstr(res));
goto exit;
}