From 7a33cf64306b33a1c2e5e8efbcf6ae148dca5ae8 Mon Sep 17 00:00:00 2001 From: Mikhail Kobuk Date: Sat, 22 Nov 2025 01:43:00 +0300 Subject: upd: add string search in array --- .gitignore | 2 ++ Makefile | 32 ++++++++++++++++++++++++++++++++ ark_string.c | 17 +++++++++++++++++ arktixord.c | 0 arktixord.h | 12 ++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 ark_string.c create mode 100644 arktixord.c create mode 100644 arktixord.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d22eb4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +*.so diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e5e8c89 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +AVER=1 +SRCA=arktixord.c +SRC=ark_string.c +OBJ=$(SRCA:%.c=%.o) +OBJ+=$(SRC:%.c=%.o) +INCDIR=/usr/local/include +LIBDIR=/usr/local/lib + +default: install + +install: libarktixord.so arktixord.h + install -v -m644 ./arktixord.h $(INCDIR)/arktixord.h + install -v -m755 -s ./libarktixord.so $(LIBDIR)/libarktixord.so.$(AVER) + ln -sf $(LIBDIR)/libarktixord.so.1 $(LIBDIR)/libarktixord.so + ldconfig + +libarktixord.so: $(OBJ) arktixord.h + gcc $(LDFLAGS) $(LDLIBS) -shared -o $@ $^ + +%.o: %.c + gcc $(CFLAGS) -c -fPIC $< -o $@ + +clean: + rm -f *.o libarktixord.so + +uninstall: + sudo rm -rf $(INCDIR)/arktixord.h + sudo rm -rf $(LIBDIR)/libarktixord.so + sudo rm -rf $(LIBDIR)/libarktixord.so.$(AVER) + ldconfig + +.PHONY: default lib install clean diff --git a/ark_string.c b/ark_string.c new file mode 100644 index 0000000..19ea175 --- /dev/null +++ b/ark_string.c @@ -0,0 +1,17 @@ +#include "arktixord.h" + +#include +#include +#include + +int +ark_check_str_in_array(const char *str, const char *array[], ssize_t array_size) +{ + for (ssize_t i = 0; i < array_size; ++i) { + if (!strcmp(str, array[i])) { + return 1; + } + } + + return 0; +} diff --git a/arktixord.c b/arktixord.c new file mode 100644 index 0000000..e69de29 diff --git a/arktixord.h b/arktixord.h new file mode 100644 index 0000000..1dc4c1a --- /dev/null +++ b/arktixord.h @@ -0,0 +1,12 @@ +#ifndef _ARKTIXORD_H +#define _ARKTIXORD_H + +#include + +#define ARK_CHK_STR_IN_ARR(string, array) \ + ark_check_str_in_array((string), (array), (sizeof(array)/sizeof(array[0]))) + +int +ark_check_str_in_array(const char *str, const char **array, ssize_t array_size); + +#endif /* _ARKTIXORD_H */ -- cgit v1.2.3-70-g09d2