into main
This commit is contained in:
Ondřej Novák 2025-02-03 16:11:56 +01:00
parent 73b949fb2e
commit f67cfbcd24
11 changed files with 178 additions and 30 deletions

View file

@ -96,11 +96,11 @@ long ini_get_value_int(const char *value, int *conv_ok) {
if (value != NULL) {
long ret = strtol(value, &out, 10);
if (*out == 0) {
if (*conv_ok) *conv_ok = 1;
if (conv_ok) *conv_ok = 1;
return ret;
}
}
if (*conv_ok) *conv_ok = 0;
if (conv_ok) *conv_ok = 0;
return -1;
}
@ -110,11 +110,11 @@ double ini_get_value_double(const char *value, int *conv_ok) {
if (value != NULL) {
double ret = strtod(value, &out);
if (*out == 0) {
if (*conv_ok) *conv_ok = 1;
if (conv_ok) *conv_ok = 1;
return ret;
}
}
if (*conv_ok) *conv_ok = 0;
if (conv_ok) *conv_ok = 0;
return -1;
}

View file

@ -21,3 +21,85 @@ void strupr(char *c) {
++c;
}
}
// Funkce pro přeskakování bílých znaků
static const char *skip_whitespace(const char *str) {
while (*str && isspace((unsigned char)*str)) {
str++;
}
return str;
}
// Funkce porovnávající dvě slova bez ohledu na velikost písmen
static int compare_words(const char *word1, const char *word2, size_t length) {
for (size_t i = 0; i < length; i++) {
if (tolower((unsigned char)word1[i]) != tolower((unsigned char)word2[i])) {
return 0;
}
}
return 1;
}
// Hlavní vyhledávací funkce
int imatch(const char *text, const char *hledany) {
// Rozdělení hledaného podřetězce na slova
const char *text_ptr = text;
const char *search_ptr = hledany;
// Iteruj přes slova hledaného podřetězce
while (*search_ptr) {
search_ptr = skip_whitespace(search_ptr);
// Pokud jsme na konci hledaného textu, ukončíme
if (*search_ptr == '\0') {
break;
}
// Najdi konec aktuálního slova
const char *search_word_end = search_ptr;
while (*search_word_end && !isspace((unsigned char)*search_word_end)) {
search_word_end++;
}
size_t search_word_len = search_word_end - search_ptr;
// Hledání slova v textu
int found = 0;
while (*text_ptr) {
text_ptr = skip_whitespace(text_ptr);
if (*text_ptr == '\0') {
break;
}
const char *text_word_end = text_ptr;
while (*text_word_end && !isspace((unsigned char)*text_word_end)) {
text_word_end++;
}
size_t text_word_len = text_word_end - text_ptr;
// Porovnání aktuálního slova
if (text_word_len >= search_word_len) {
for (int i = text_word_len - search_word_len; i >= 0; --i) {
if (compare_words(text_ptr+i, search_ptr, search_word_len)) {
found = 1;
text_ptr = text_word_end; // Pokračujeme za slovem
break;
}
}
if (found) break;
}
text_ptr = text_word_end;
}
if (!found) {
return 0; // Nenalezeno
}
search_ptr = search_word_end;
}
return 1; // Všechny části byly nalezeny ve správném pořadí
}

View file

@ -70,6 +70,7 @@ FILE *fopen_icase(const char *pathname, const char *mode);
const char *file_icase_find(const char *pathname);
int stricmp(const char *a, const char *b);
int imatch(const char *haystack, const char *needle);
#define MIN(a, b) ((a)<(b)?(a):(b))
#define MAX(a, b) ((a)>(b)?(a):(b))
void strupr(char *c);