From 82e865e0d45f86957cf1eccb5b93bcae4ec8588e Mon Sep 17 00:00:00 2001 From: tovjemam Date: Sat, 4 Jan 2025 22:24:52 +0100 Subject: [PATCH] kodovani (splint mrdka) --- errors.c | 88 +++++++++++++++---------------- errors.h | 132 +++++++++++++++++++++++------------------------ lex.c | 2 +- lex.h | 4 +- math_functions.h | 2 +- parser.c | 2 +- parser.h | 2 +- ps_graph.h | 2 +- tree.h | 2 +- 9 files changed, 117 insertions(+), 119 deletions(-) diff --git a/errors.c b/errors.c index 3484803..991379e 100644 --- a/errors.c +++ b/errors.c @@ -1,45 +1,45 @@ -#include "errors.h" -#include -#include -#include - -void error_buffer_init(struct error_buffer *eb) { - eb->err = ERR_NO_ERR; - eb->text_len = 0; - eb->text[0] = 0; -} - -void error_set(struct error_buffer *eb, enum error_code err) { - eb->err = err; -} - -enum error_code error_get(const struct error_buffer *eb) { - return eb->err; -} - -void error_printf(struct error_buffer *eb, const char *format, ...) { - va_list args; - int space = MAX_ERROR_MESSAGE_LENGTH - eb->text_len; - int write_size; - - if (space == 0) - return; - - va_start(args, format); - write_size = vsnprintf(eb->text + eb->text_len, MAX_ERROR_MESSAGE_LENGTH - eb->text_len, format, args); - va_end(args); - - if (write_size < 0) - return; - - if (write_size < space) { - eb->text_len += write_size; - } - else { - eb->text_len = MAX_ERROR_MESSAGE_LENGTH; - } -} - -const char *error_get_text(const struct error_buffer *eb) { - return eb->text; +#include "errors.h" +#include +#include +#include + +void error_buffer_init(struct error_buffer *eb) { + eb->err = ERR_NO_ERR; + eb->text_len = 0; + eb->text[0] = 0; +} + +void error_set(struct error_buffer *eb, enum error_code err) { + eb->err = err; +} + +enum error_code error_get(const struct error_buffer *eb) { + return eb->err; +} + +void error_printf(struct error_buffer *eb, const char *format, ...) { + va_list args; + int space = MAX_ERROR_MESSAGE_LENGTH - eb->text_len; + int write_size; + + if (space == 0) + return; + + va_start(args, format); + write_size = vsnprintf(eb->text + eb->text_len, MAX_ERROR_MESSAGE_LENGTH - eb->text_len, format, args); + va_end(args); + + if (write_size < 0) + return; + + if (write_size < space) { + eb->text_len += write_size; + } + else { + eb->text_len = MAX_ERROR_MESSAGE_LENGTH; + } +} + +const char *error_get_text(const struct error_buffer *eb) { + return eb->text; } \ No newline at end of file diff --git a/errors.h b/errors.h index 59c0f4f..4699bcc 100644 --- a/errors.h +++ b/errors.h @@ -1,67 +1,67 @@ -#ifndef ERRORS_H -#define ERRORS_H - -#include - -#define MAX_ERROR_MESSAGE_LENGTH 512 - -/** - * @brief Chybové kódy - */ -enum error_code { - ERR_NO_ERR = 0, /* Žádná chyba */ - ERR_INVALID_ARGS = 1, /* Neplatné argumenty programu */ - ERR_INVALID_FUNCTION = 2, /* Zadaná matematická funkce je neplatná */ - ERR_INVALID_FILENAME = 3, /* Zadaný název souboru není platný */ - ERR_INVALID_LIMITS = 4, /* Zadané hranice jsou ve špatném formátu */ - ERR_BAD_ALLOC = 5 /* Při alokaci paměti nastala chyba */ -}; - -/** - * @brief Zásobník pro chybový kód a řetězec popisující chybu - */ -struct error_buffer { - enum error_code err; - char text[MAX_ERROR_MESSAGE_LENGTH]; - size_t text_len; -}; - -/** - * @brief Inicializuje zásobník - * - * @param eb Zásobník - */ -void error_buffer_init(struct error_buffer *eb); - -/** - * @brief Nastaví chybový kód - * - * @param eb Zásobník - * @param err Chybový kód - */ -void error_set(struct error_buffer *eb, enum error_code err); - -/** - * @brief Přidá do zásobníku formátovaný řetězec - * - * @param eb Zásobník - */ -void error_printf(struct error_buffer *eb, const char *format, ...); - -/** - * Vrátí chybový kód - * - * @param eb Zásobník - * @return Chybový kód - */ -enum error_code error_get(const struct error_buffer *eb); - -/** - * Vrátí řetězec popisující chybu - * - * @param eb Zásobník - * @return Řetězec popisující chybu - */ -const char *error_get_text(const struct error_buffer *eb); - +#ifndef ERRORS_H +#define ERRORS_H + +#include + +#define MAX_ERROR_MESSAGE_LENGTH 512 + +/** + * @brief Chybové kódy + */ +enum error_code { + ERR_NO_ERR = 0, /* Žádná chyba */ + ERR_INVALID_ARGS = 1, /* Neplatné argumenty programu */ + ERR_INVALID_FUNCTION = 2, /* Zadaná matematická funkce je neplatná */ + ERR_INVALID_FILENAME = 3, /* Zadaný název souboru není platný */ + ERR_INVALID_LIMITS = 4, /* Zadané hranice jsou ve špatném formátu */ + ERR_BAD_ALLOC = 5 /* Při alokaci paměti nastala chyba */ +}; + +/** + * @brief Zásobník pro chybový kód a řetězec popisující chybu + */ +struct error_buffer { + enum error_code err; + char text[MAX_ERROR_MESSAGE_LENGTH]; + size_t text_len; +}; + +/** + * @brief Inicializuje zásobník + * + * @param eb Zásobník + */ +void error_buffer_init(struct error_buffer *eb); + +/** + * @brief Nastaví chybový kód + * + * @param eb Zásobník + * @param err Chybový kód + */ +void error_set(struct error_buffer *eb, enum error_code err); + +/** + * @brief Přidá do zásobníku formátovaný řetězec + * + * @param eb Zásobník + */ +void error_printf(struct error_buffer *eb, const char *format, ...); + +/** + * Vrátí chybový kód + * + * @param eb Zásobník + * @return Chybový kód + */ +enum error_code error_get(const struct error_buffer *eb); + +/** + * Vrátí řetězec popisující chybu + * + * @param eb Zásobník + * @return Řetězec popisující chybu + */ +const char *error_get_text(const struct error_buffer *eb); + #endif /* ERRORS_H */ \ No newline at end of file diff --git a/lex.c b/lex.c index c52c8fe..dadda47 100644 --- a/lex.c +++ b/lex.c @@ -1,4 +1,4 @@ -#include "lex.h" +#include "lex.h" #include #include diff --git a/lex.h b/lex.h index 304737a..0589889 100644 --- a/lex.h +++ b/lex.h @@ -1,10 +1,8 @@ -#ifndef LEX_H +#ifndef LEX_H #define LEX_H #include "errors.h" -#define LEX_DEBUG - /** * @brief Typ tokenu */ diff --git a/math_functions.h b/math_functions.h index 1798462..f42175b 100644 --- a/math_functions.h +++ b/math_functions.h @@ -1,4 +1,4 @@ -#ifndef MATH_FUNCTIONS_H +#ifndef MATH_FUNCTIONS_H #define MATH_FUNCTIONS_H #include diff --git a/parser.c b/parser.c index 005ace4..3b176e1 100644 --- a/parser.c +++ b/parser.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "parser.h" diff --git a/parser.h b/parser.h index b3d9d3c..1f597a7 100644 --- a/parser.h +++ b/parser.h @@ -1,4 +1,4 @@ -#ifndef PARSER_H +#ifndef PARSER_H #define PARSER_H #include "tree.h" diff --git a/ps_graph.h b/ps_graph.h index 2c0631f..4991582 100644 --- a/ps_graph.h +++ b/ps_graph.h @@ -11,4 +11,4 @@ struct graph_range { void ps_generate_graph(FILE *file, const struct expr_node *node, const struct graph_range *range, const char *function); -#endif \ No newline at end of file +#endif /* PS_GRAPH_H */ diff --git a/tree.h b/tree.h index 9158011..61db871 100644 --- a/tree.h +++ b/tree.h @@ -1,4 +1,4 @@ -#ifndef TREE_H +#ifndef TREE_H #define TREE_H #include "lex.h"