Skip to content

Commit

Permalink
Splitting out some utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Meisrimel authored and Peter Meisrimel committed Jul 22, 2024
1 parent 4809dff commit e714f83
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
26 changes: 0 additions & 26 deletions src/XML/src/FMI3/fmi3_xml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,6 @@ void fmi3_xml_parse_free_context(fmi3_xml_parser_context_t* context) {
context->callbacks->free(context);
}

void fmi3_xml_parse_fatal(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
jm_log_fatal_v(context->callbacks, module, fmt, args);
va_end (args);
XML_StopParser(context->parser,0);
}

void fmi3_xml_parse_error(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
if (context->parser)
jm_log_info(context->callbacks, module, "[Line:%u] Detected during parsing:", XML_GetCurrentLineNumber(context->parser));
jm_log_error_v(context->callbacks, module, fmt, args);
va_end (args);
}

void fmi3_xml_parse_warning(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
if (context->parser)
jm_log_info(context->callbacks, module, "[Line:%u] Detected during parsing:", XML_GetCurrentLineNumber(context->parser));
jm_log_warning_v(context->callbacks, module, fmt, args);
va_end (args);
}

/**
* Raises a generic parse error for the given attribute.
*/
Expand Down
5 changes: 1 addition & 4 deletions src/XML/src/FMI3/fmi3_xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "fmi3_xml_model_description_parser.h"
#include "fmi3_xml_terminals_and_icons_parser.h"
#include "fmi3_xml_parser_context_impl.h"
#include "fmi3_xml_parser_util.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -86,10 +87,6 @@ int fmi3_xml_alloc_parse_buffer(fmi3_xml_parser_context_t* context, size_t items
void fmi3_xml_free_variable_start_values(fmi3_xml_parser_context_t* context);
void fmi3_xml_free_parse_buffer(fmi3_xml_parser_context_t* context);

void fmi3_xml_parse_fatal (fmi3_xml_parser_context_t* context, const char* fmt, ...);
void fmi3_xml_parse_error (fmi3_xml_parser_context_t* context, const char* fmt, ...);
void fmi3_xml_parse_warning(fmi3_xml_parser_context_t* context, const char* fmt, ...);

/**
* Raises generic parse error for given attribute.
*/
Expand Down
29 changes: 28 additions & 1 deletion src/XML/src/FMI3/fmi3_xml_parser_util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2023 Modelon AB
Copyright (C) 2024 Modelon AB
This program is free software: you can redistribute it and/or modify
it under the terms of the BSD style license.
Expand All @@ -14,5 +14,32 @@
*/

#include "fmi3_xml_parser_util.h"
#include "JM/jm_portability.h"

static const char* module = "FMI3XML";

void fmi3_xml_parse_fatal(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
jm_log_fatal_v(context->callbacks, module, fmt, args);
va_end (args);
XML_StopParser(context->parser,0);
}

void fmi3_xml_parse_error(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
if (context->parser)
jm_log_info(context->callbacks, module, "[Line:%u] Detected during parsing:", XML_GetCurrentLineNumber(context->parser));
jm_log_error_v(context->callbacks, module, fmt, args);
va_end (args);
}

void fmi3_xml_parse_warning(fmi3_xml_parser_context_t* context, const char* fmt, ...) {
va_list args;
va_start (args, fmt);
if (context->parser)
jm_log_info(context->callbacks, module, "[Line:%u] Detected during parsing:", XML_GetCurrentLineNumber(context->parser));
jm_log_warning_v(context->callbacks, module, fmt, args);
va_end (args);
}
8 changes: 7 additions & 1 deletion src/XML/src/FMI3/fmi3_xml_parser_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2023 Modelon AB
Copyright (C) 2024 Modelon AB
This program is free software: you can redistribute it and/or modify
it under the terms of the BSD style license.
Expand All @@ -16,10 +16,16 @@
#ifndef FMI3_XML_XMLPARSER_UTIL_H
#define FMI3_XML_XMLPARSER_UTIL_H

#include "fmi3_xml_parser_context_impl.h"

#ifdef __cplusplus
extern "C" {
#endif

void fmi3_xml_parse_fatal (fmi3_xml_parser_context_t* context, const char* fmt, ...);
void fmi3_xml_parse_error (fmi3_xml_parser_context_t* context, const char* fmt, ...);
void fmi3_xml_parse_warning(fmi3_xml_parser_context_t* context, const char* fmt, ...);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 0 additions & 1 deletion src/XML/src/FMI3/fmi3_xml_terminals_and_icons.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <stdio.h>


#include "JM/jm_named_ptr.h"
#include "fmi3_xml_parser.h"
#include "fmi3_xml_terminals_and_icons_impl.h"
Expand Down

0 comments on commit e714f83

Please sign in to comment.