commit 285c910b3462c1b4aa2b88b7a528205725529c9e
parent 3db911364bcc348ddcb9f71077743d065cc0847f
Author: Christos Margiolis <christos@margiolis.net>
Date: Wed, 26 May 2021 18:56:53 +0300
cleanup
Diffstat:
6 files changed, 57 insertions(+), 69 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-(c) 2020-Present Christos Margiolis <christos@christosmarg.xyz>
+(c) 2020-Present Christos Margiolis <christos@margiolis.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
# See LICENSE file for copyright and license details.
-# cstring - a simple and lightweight string library for C
+# cstring - lightweight string library for C
.POSIX:
include config.mk
@@ -15,11 +15,11 @@ all: options ${LIB}
options:
@echo ${LIB} build options:
- @echo "CFLAGS = ${CFLAGS}"
- @echo "LDFLAGS = ${LDFLAGS}"
- @echo "ARFLAGS = ${ARFLAGS}"
- @echo "CC = ${CC}"
- @echo "AR = ${AR}"
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+ @echo "ARFLAGS = ${ARFLAGS}"
+ @echo "CC = ${CC}"
+ @echo "AR = ${AR}"
${LIB}: ${OBJ}
${AR} ${ARFLAGS} lib${LIB}.a ${OBJ}
@@ -28,29 +28,29 @@ ${LIB}: ${OBJ}
${CC} -c ${CFLAGS} $<
dist: clean
- ${MKDIR} ${DIST}
- ${CP} -R tests/ config.mk ${MAN3} ${SRC} cstring.h LICENSE Makefile \
- README.md ${DIST}
- ${TAR} ${DIST}.tar ${DIST}
- ${GZIP} ${DIST}.tar
- ${RM_DIR} ${DIST}
+ mkdir -p ${DIST}
+ cp -R tests config.mk cstring.3 cstring.c cstring.h LICENSE Makefile \
+ README ${DIST}
+ tar -cf ${DIST}.tar ${DIST}
+ gzip ${DIST}.tar
+ rm -rf ${DIST}
install: all
- ${MKDIR} ${DESTDIR}${LIB_DIR} ${DESTDIR}${INC_DIR} ${DESTDIR}${MAN_DIR}
- ${CP} ${LIB}.h ${DESTDIR}${INC_DIR}
- ${CP} lib${LIB}.a ${DESTDIR}${LIB_DIR}
- ${CP} ${MAN3} ${DESTDIR}${MAN_DIR}
- sed "s/VERSION/${VERSION}/g" < ${MAN3} > ${DESTDIR}${MAN_DIR}/${MAN3}
+ mkdir -p ${DESTDIR}${LIBDIR} ${DESTDIR}${INCDIR} ${DESTDIR}${MANPREFIX}/man3
+ cp -f ${LIB}.h ${DESTDIR}${INCDIR}
+ cp -f lib${LIB}.a ${DESTDIR}${LIBDIR}
+ cp -f ${MAN3} ${DESTDIR}${MANPREFIX}/man3
+ sed "s/VERSION/${VERSION}/g" < ${MAN3} > ${DESTDIR}${MANPREFIX}/man3/${MAN3}
chmod 755 ${DESTDIR}${INC_DIR}/${LIB}.h
chmod 644 ${DESTDIR}${LIB_DIR}/lib${LIB}.a
- chmod 644 ${DESTDIR}${MAN_DIR}/${MAN3}
+ chmod 644 ${DESTDIR}${MANPREFIX}/man3/${MAN3}
uninstall:
- ${RM} ${DESTDIR}${INC_DIR}/${LIB}.h
- ${RM} ${DESTDIR}${LIB_DIR}/lib${LIB}.a
- ${RM} ${DESTDIR}${MAN_DIR}/${MAN3}
+ rm -f ${DESTDIR}${INCDIR}/${LIB}.h \
+ ${DESTDIR}${LIBDIR}/lib${LIB}.a \
+ ${DESTDIR}${MANPREFIX}/man3/${MAN3}
clean:
- ${RM} ${LIB} ${OBJ} lib${LIB}.a ${DIST}.tar.gz
+ rm -f ${LIB} ${OBJ} lib${LIB}.a ${DIST}.tar.gz *.core
.PHONY: all options clean dist install uninstall
diff --git a/config.mk b/config.mk
@@ -4,12 +4,12 @@ VERSION = 0.1
# paths
PREFIX = /usr/local
-MAN_DIR = ${PREFIX}/share/man/man3
-INC_DIR = ${PREFIX}/include
-LIB_DIR = ${PREFIX}/lib
+MANPREFIX = ${PREFIX}/share/man
+INCDIR = ${PREFIX}/include
+LIBDIR = ${PREFIX}/lib
# includes and libs
-INCS = -Iinclude
+INCS = -Iinclude
LIBS = -Llib
# flags
@@ -19,16 +19,6 @@ CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
ARFLAGS = rs
-# utils
-CP = cp -f
-RM = rm -f
-RM_DIR = rm -rf
-MV = mv
-MKDIR = mkdir -p
-RM_DIR = rm -rf
-TAR = tar -cf
-GZIP = gzip
-
# compiler
CC = cc
AR = ar
diff --git a/cstring.3 b/cstring.3
@@ -242,4 +242,4 @@ Used with
in case the string is to be initliazed as empty.
.Sh AUTHORS
-.An Christos Margiolis Aq Mt christos@christosmarg.xyz
+.An Christos Margiolis Aq Mt christos@margiolis.net
diff --git a/cstring.c b/cstring.c
@@ -8,7 +8,6 @@
return (_found - cs->str); \
} while (0)
-/* statics */
static int cstring_is_one_of(char, const char *);
static void *emalloc(size_t);
static void csfree(cstring *);
@@ -69,7 +68,6 @@ cstring_cmp_char_less(const void *lhs, const void *rhs)
return -(*(char *)lhs - *(char *)rhs);
}
-/* externs */
cstring
cstring_create(const char *s)
{
@@ -298,7 +296,7 @@ cstring_rfind(const cstring *cs, const char *s)
if (found)
idx = i;
}
- return (idx == -1 ? CSTRING_NPOS : idx);
+ return (idx < 0 ? CSTRING_NPOS : idx);
}
size_t
diff --git a/cstring.h b/cstring.h
@@ -7,7 +7,7 @@
#include <string.h>
#ifdef __cplusplus
-extern "C" {
+"C" {
#endif /* __cplusplus */
#define CSTRING_NPOS -1
@@ -28,33 +28,33 @@ typedef struct _cstring {
typedef int (*cstring_sort_callback)(const void *, const void *);
-extern cstring cstring_create(const char *);
-extern void cstring_delete(cstring *);
-extern void cstring_assign(cstring *, const char *);
-extern void cstring_insert(cstring *, const char *, size_t);
-extern void cstring_erase(cstring *, size_t, size_t);
-extern void cstring_erase_matching(cstring *, const char *);
-extern void cstring_erase_all_matching(cstring *, const char *);
-extern void cstring_trim(cstring *, const char *);
-extern void cstring_push_back(cstring *, char);
-extern void cstring_pop_back(cstring *);
-extern void cstring_replace_char(cstring *, size_t, char);
-extern void cstring_replace_str(cstring *, const char *, size_t, size_t);
-extern cstring cstring_substr(const cstring *, size_t, size_t);
-extern void cstring_swap(cstring *, cstring *);
-extern void cstring_sort_partial(cstring *, size_t, size_t, int, cstring_sort_callback);
-extern void cstring_sort_chars_partial(cstring *cs, size_t, size_t, int, cstring_sort_callback);
-extern void cstring_clear(cstring *);
-extern size_t cstring_find(const cstring *, const char *);
-extern size_t cstring_rfind(const cstring *, const char *);
-extern size_t cstring_find_first_of(const cstring *, const char *);
-extern size_t cstring_find_first_not_of(const cstring *,const char *);
-extern size_t cstring_find_last_of(const cstring *, const char *);
-extern size_t cstring_find_last_not_of(const cstring *, const char *);
-extern int cstring_ends_with_str(const cstring *, const char *);
-extern char *cstring_copy(const char *);
-extern void cstring_resize(cstring *, size_t);
-extern cstring *cstring_getline(FILE *, cstring *, char);
+cstring cstring_create(const char *);
+void cstring_delete(cstring *);
+void cstring_assign(cstring *, const char *);
+void cstring_insert(cstring *, const char *, size_t);
+void cstring_erase(cstring *, size_t, size_t);
+void cstring_erase_matching(cstring *, const char *);
+void cstring_erase_all_matching(cstring *, const char *);
+void cstring_trim(cstring *, const char *);
+void cstring_push_back(cstring *, char);
+void cstring_pop_back(cstring *);
+void cstring_replace_char(cstring *, size_t, char);
+void cstring_replace_str(cstring *, const char *, size_t, size_t);
+cstring cstring_substr(const cstring *, size_t, size_t);
+void cstring_swap(cstring *, cstring *);
+void cstring_sort_partial(cstring *, size_t, size_t, int, cstring_sort_callback);
+void cstring_sort_chars_partial(cstring *cs, size_t, size_t, int, cstring_sort_callback);
+void cstring_clear(cstring *);
+size_t cstring_find(const cstring *, const char *);
+size_t cstring_rfind(const cstring *, const char *);
+size_t cstring_find_first_of(const cstring *, const char *);
+size_t cstring_find_first_not_of(const cstring *,const char *);
+size_t cstring_find_last_of(const cstring *, const char *);
+size_t cstring_find_last_not_of(const cstring *, const char *);
+int cstring_ends_with_str(const cstring *, const char *);
+char *cstring_copy(const char *);
+void cstring_resize(cstring *, size_t);
+cstring *cstring_getline(FILE *, cstring *, char);
/* static inlines */
static inline void cstring_prepend(cstring *, const char *);