diff options
author | admin <admin@optics-design.com> | 2025-08-05 11:28:41 +0200 |
---|---|---|
committer | admin <admin@optics-design.com> | 2025-08-05 11:28:41 +0200 |
commit | 04b3fcb479f5aaae06d18b315a8bdc8c298f4eae (patch) | |
tree | 92f60caef26f98a83681aa0e1f360df03203bbe4 /include/glautils/fgla.h | |
parent | 9496ae0a50e6848121c7e913ca2dc55c8e6c84c1 (diff) |
removed clustering
Diffstat (limited to 'include/glautils/fgla.h')
-rw-r--r-- | include/glautils/fgla.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/include/glautils/fgla.h b/include/glautils/fgla.h new file mode 100644 index 0000000..d9a946b --- /dev/null +++ b/include/glautils/fgla.h @@ -0,0 +1,113 @@ +/**
+ * fgla.h - Find Glass utility header
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+
+#ifndef FGLA_H
+#define FGLA_H
+
+#include "glamac/core/glamacdef.h"
+#include "glamac/core/security.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Output format types
+typedef enum {
+ FGLA_OUTPUT_CSV = 0,
+ FGLA_OUTPUT_TABLE = 1,
+ FGLA_OUTPUT_JSON = 2
+} FglaOutputFormat;
+
+// Error handling
+typedef enum {
+ FGLA_SUCCESS = 0,
+ FGLA_ERROR_INVALID_ARGS = 1,
+ FGLA_ERROR_INVALID_SEARCH_TERM = 2,
+ FGLA_ERROR_NO_DATABASE = 3,
+ FGLA_ERROR_NO_MATCHES = 4,
+ FGLA_ERROR_MEMORY = 5
+} FglaResult;
+
+/**
+ * @brief Safely converts string to lowercase with length limit
+ * @param str String to convert (modified in place)
+ * @param max_len Maximum length to process
+ */
+void fgla_to_lowercase_safe(char* str, size_t max_len);
+
+/**
+ * @brief Safely normalizes string by removing dashes and converting to lowercase
+ * @param input Input string to normalize
+ * @param output Buffer for normalized output
+ * @param output_size Size of output buffer
+ * @return 0 on success, -1 on error
+ */
+int fgla_normalize_string_safe(const char* input, char* output, size_t output_size);
+
+/**
+ * @brief Safely checks if needle is found in haystack (case-insensitive, dash-insensitive)
+ * @param haystack String to search in
+ * @param needle String to search for
+ * @return 1 if found, 0 if not found or error
+ */
+int fgla_contains_substring_safe(const char* haystack, const char* needle);
+
+/**
+ * @brief Checks if manufacturer matches any of the specified catalogs
+ * @param manufacturer Manufacturer name to check
+ * @param catalog_list Array of catalog names to match against
+ * @param catalog_count Number of catalogs in the list
+ * @return 1 if matches, 0 if no match
+ */
+int fgla_matches_catalog(const char* manufacturer, const char* catalog_list[], int catalog_count);
+
+/**
+ * @brief Validates search term input for security and format
+ * @param term Search term to validate
+ * @return 1 if valid, 0 if invalid
+ */
+int fgla_validate_search_term(const char* term);
+
+/**
+ * @brief Checks if a search term is a glass code pattern
+ * @param term Search term to check
+ * @return 1 if glass code pattern, 0 otherwise
+ */
+int fgla_is_glass_code_pattern(const char* term);
+
+/**
+ * @brief Safely checks if a glass code matches a pattern
+ * @param glass_code Glass code to check
+ * @param pattern Pattern to match (can contain 'x' wildcards)
+ * @return 1 if matches, 0 if no match
+ */
+int fgla_matches_glass_code_pattern_safe(const char* glass_code, const char* pattern);
+
+/**
+ * @brief Prints usage information for fgla utility
+ * @param program_name Name of the program (argv[0])
+ */
+void fgla_print_usage(const char* program_name);
+
+/**
+ * @brief Prints error message with helpful suggestions
+ * @param error Error code from FglaResult enum
+ * @param context Optional context string for the error
+ */
+void fgla_print_error_with_suggestion(FglaResult error, const char* context);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FGLA_H */
\ No newline at end of file |