diff options
author | 2023-03-01 16:11:17 +0100 | |
---|---|---|
committer | 2023-03-01 16:11:17 +0100 | |
commit | 8d81ffef00f5cf2c267fb855715b76cdf004bc52 (patch) | |
tree | d1ffe2485627e8f64d6b1a908fad2ae872d1eee6 | |
parent | 2392a52c10fdb32e504cb76d5f1989df7a643655 (diff) | |
download | string2-8d81ffef00f5cf2c267fb855715b76cdf004bc52.tar.gz string2-8d81ffef00f5cf2c267fb855715b76cdf004bc52.zip |
Keep it simple
-rw-r--r-- | Makefile | 61 | ||||
-rw-r--r-- | README.md | 24 | ||||
-rw-r--r-- | config.mk | 19 | ||||
-rwxr-xr-x | makemk | 29 | ||||
-rw-r--r-- | src/string2.c | 51 | ||||
-rw-r--r-- | src/string2.h | 12 | ||||
-rw-r--r-- | string2.h | 17 | ||||
-rw-r--r-- | target.mk | 8 | ||||
-rw-r--r-- | test/Makefile | 21 | ||||
-rw-r--r-- | test/main.c | 13 | ||||
-rw-r--r-- | test/test.c | 14 | ||||
-rw-r--r-- | test/test.h | 8 | ||||
-rw-r--r-- | test/test1.c | 39 | ||||
-rw-r--r-- | test/test1.h | 10 |
14 files changed, 24 insertions, 302 deletions
@@ -1,59 +1,10 @@ # See LICENSE file for copyright and license details. -include config.mk +PREFIX=/usr/local +INStALL_DIR=${PREFIX}/include -CC = cc +instal: + cp string2.h ${INSTALL_DIR}/string2.h -# Used for debugging and not as usual -OBJ = ${SRC:.c=.o} - -OPTIM = -O2 -pipe -STD = -ansi --std=c89 -pedantic -WARNS = -Werror -Wall - -LDFLAGS = -CFLAGS = ${WARNS} ${STD} -DLIBVER=\"${LIBVER}\" ${OPTIM} - -# CFLAGS for debugging -CDFLAGS = ${WARNS} ${STD} -DLIBVER=\"${LIBVER}\" -g - -all: ${LIBNAME:=.a} ${LIBNAME:=.so} - @echo All done. - -debug: ${OBJ} - -.c.o: - ${CC} ${CDFLAGS} -c $< -o $@ - -# Make shared and archive directories -${ARDIR} ${SHDIR}: - mkdir -p $@ - -# Make archive file -${LIBNAME:=.a}: ${ARDIR} ${AROBJ} - ar rcs $@ ${AROBJ} - -# Make shared file -${LIBNAME:=.so}: ${SHDIR} ${SHOBJ} - ${CC} ${LDFLAGS} -shared ${SHOBJ} -o $@ - -clean: - rm -rf bin ${LIBNAME}.* *.core ${OBJ} - cd test && make clean - -tests: all - cd test && make clean tests - -${INSTALL_LIB_DIR}: - mkdir -p $@ - -${INSTALL_INC_DIR}: - mkdir -p $@ - -install: all ${INSTALL_LIB_DIR} ${INSTALL_INC_DIR} - cp ${LIBNAME:=.a} ${INSTALL_LIB_DIR}/${LIBNAME:=.a} - cp ${LIBNAME:=.so} ${INSTALL_LIB_DIR}/${LIBNAME:=.so} - cp src/string2.h ${INSTALL_INC_DIR}/string2.h - -# Generated by makemk script -include target.mk +uninstall: + rm -f ${INSTALL_DIR}/string2.h @@ -1,23 +1 @@ -## Adding new source files -Be free to add new source files! After adding files, it must be runned this -script: -``` -$ ./makemk -``` -So will be generated a new `target.mk`. This one must be committed, to avoid -running `makemk` on cloning repository. - -## Build instruction -It's simple, just: -``` -$ make -``` - -## Installation -As root: -``` -# make install -``` - -## Note -This project is compatible with both BSD make and GNU make. +Just an include file. diff --git a/config.mk b/config.mk deleted file mode 100644 index 6bd3e66..0000000 --- a/config.mk +++ /dev/null @@ -1,19 +0,0 @@ -# See LICENSE file for copyright and license details. - -NAME = string2 -LIBNAME = lib${NAME} -LIBVER = 0.0.0-a3 - -PREFIX = /usr/local -INSTALL_LIB_DIR = ${PREFIX}/lib/aiezzi/${NAME} -INSTALL_INC_DIR = ${PREFIX}/include/aiezzi/${NAME} - -# Directories -SRCDIR = src -ARDIR = bin/archive -SHDIR = bin/shared - -# Sources and object files. We need two kind of object files, the first ones are for archive -SRC != find ${SRCDIR} -name '*.c' -AROBJ = ${SRC:${SRCDIR}/%.c=${ARDIR}/%.o} -SHOBJ = ${SRC:${SRCDIR}/%.c=${SHDIR}/%.o} @@ -1,29 +0,0 @@ -#!/bin/sh - -MKFILE=target.mk -SRCDIR=src/ -ARDIR=bin/archive/ -SHDIR=bin/shared/ - -cat > $MKFILE << EOF -# See LICENSE file for copyright and license details. - -EOF - -for srcf in `find $SRCDIR -name '*.c'` -do - TARGETAR=`echo $srcf | sed -E "s|$SRCDIR(.*).c|$ARDIR\1.o|"` - TARGETSH=`echo $srcf | sed -E "s|$SRCDIR(.*).c|$SHDIR\1.o|"` - LINEAR='${CC} ${CFLAGS} -c '$srcf' -o $@' - LINESH='${CC} ${CFLAGS} -fPIC -c '$srcf' -o $@' - -cat >> $MKFILE << EOF -$TARGETAR: $srcf - $LINEAR - -$TARGETSH: $srcf - $LINESH - -EOF - -done diff --git a/src/string2.c b/src/string2.c deleted file mode 100644 index b356a67..0000000 --- a/src/string2.c +++ /dev/null @@ -1,51 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#include <string.h> - -int -strrgt(const char *str, const char *end) -{ - int size_s1 = strlen(str); - int size_s2 = strlen(end); - - int i = size_s1 - 1, j = size_s2 - 1; - - if (size_s2 > size_s1) { - return 1; - } - - for (; i >= 0 && j >= 0; i--, j--) { - if (str[i] != end[j]) { - return 1; - } - } - - return 0; -} - -int -strlft(const char *str, const char *end) -{ - int size_s1 = strlen(str); - int size_s2 = strlen(end); - - int i = 0; - - if (size_s2 > size_s1) { - return 1; - } - - for (; i < size_s2; i++) { - if (str[i] != end[i]) { - return 1; - } - } - - return 0; -} - -char * -string2libver(void) -{ - return LIBVER; -} diff --git a/src/string2.h b/src/string2.h deleted file mode 100644 index 9e10fd5..0000000 --- a/src/string2.h +++ /dev/null @@ -1,12 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#ifndef __STRING2_H__ -#define __STRING2_H__ - -#include <string.h> - -int strrgt(const char *, const char *); -int strlft(const char *, const char *); -char *string2libver(void); - -#endif /* __STRING2_H__ */ diff --git a/string2.h b/string2.h new file mode 100644 index 0000000..228cc8e --- /dev/null +++ b/string2.h @@ -0,0 +1,17 @@ +/* See LICENSE file for copyright and license details. */ + +#ifndef __STRING2_H__ +#define __STRING2_H__ + +#include <string.h> + +#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) + +static int +strends(const char *str, const char *suffix) +{ + int offset = strlen(str) - strlen(suffix); + return offset < 0 ? 0 : strcmp(str + offset, suffix) == 0; +} + +#endif /* __STRING2_H__ */ diff --git a/target.mk b/target.mk deleted file mode 100644 index 2d3e61e..0000000 --- a/target.mk +++ /dev/null @@ -1,8 +0,0 @@ -# See LICENSE file for copyright and license details. - -bin/archive/string2.o: src/string2.c - ${CC} ${CFLAGS} -c src/string2.c -o $@ - -bin/shared/string2.o: src/string2.c - ${CC} ${CFLAGS} -fPIC -c src/string2.c -o $@ - diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 6b65bb0..0000000 --- a/test/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# See LICENSE file for copyright and license details. - -CC = cc -SRC != find * -name '*.c' -OBJ = ${SRC:.c=.o} - -CFLAGS = -Wall -ansi --std=c89 -pedantic\ - -I../src/ -LDFLAGS = -L../ -l:libstr.a - -tests: test-app - ./test-app - -.c.o: - ${CC} ${CFLAGS} -c $< -o $@ - -test-app: ${OBJ} - ${CC} ${LDFLAGS} -o $@ ${OBJ} - -clean: - rm -f test-app ${OBJ} *.core diff --git a/test/main.c b/test/main.c deleted file mode 100644 index 25e1993..0000000 --- a/test/main.c +++ /dev/null @@ -1,13 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#include "test1.h" - -int -main(int argc, char **argv) -{ - test1(); - test2(); - test3(); - - return 0; -} diff --git a/test/test.c b/test/test.c deleted file mode 100644 index a47adb6..0000000 --- a/test/test.c +++ /dev/null @@ -1,14 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -/* See LICENSE file for copyright and license details. */ - -#include <stdlib.h> -#include <stdio.h> - -void -asserti(int expected, int value) -{ - if (expected != value) { - exit(1); - } -} diff --git a/test/test.h b/test/test.h deleted file mode 100644 index cbd0a84..0000000 --- a/test/test.h +++ /dev/null @@ -1,8 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#ifndef __TEST_H__ -#define __TEST_H__ - -void asserti(int, int); - -#endif /* __TEST_H__ */ diff --git a/test/test1.c b/test/test1.c deleted file mode 100644 index 586be35..0000000 --- a/test/test1.c +++ /dev/null @@ -1,39 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#include <string2.h> -#include <stdio.h> - -#include "test.h" - -void -test1(void) -{ - printf("executing test1... "); - asserti(0, strrgt("alexander", "xander")); - asserti(1, strrgt("alexander", "dander")); - asserti(1, strrgt("alexander", "alex")); - asserti(0, strrgt("alexander", "alexander")); - asserti(1, strrgt("dwm", "dwmdwm")); - - printf("OK\n"); -} - -void -test2(void) -{ - printf("executing test2... "); - asserti(0, strlft("alexander", "alex")); - asserti(1, strlft("alexander", "dalex")); - asserti(1, strlft("alexander", "xander")); - asserti(0, strlft("alexander", "alexander")); - asserti(1, strlft("dwm", "dwmdwm")); - - printf("OK\n"); -} - -void -test3() -{ - printf("executing %s... OK\n", __func__); - printf("%s\n", string2ver()); -} diff --git a/test/test1.h b/test/test1.h deleted file mode 100644 index 79bab4c..0000000 --- a/test/test1.h +++ /dev/null @@ -1,10 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#ifndef __TEST1_H__ -#define __TEST1_H__ - -void test1(void); -void test2(void); -void test3(void); - -#endif /* __TEST1_H__ */ |