summaryrefslogtreecommitdiff
path: root/include/glautils/fgla.h
blob: d9a946bf75d5a72d30401614263c2fbaffd65099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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 */
Back to https://optics-design.com