Lightweight string library for C
git clone git://git.christosmarg.xyz/cstring.git
Log | Files | Refs | README | LICENSE

commit 5479902387b7982d2f5fe2f330a91ba7de5985f4
parent e24fb7a48da9300b9c2d0e9f64312db037c7fd1d
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed, 14 Oct 2020 23:59:58 +0300

added LICENSE and updated Makefile

ALICENSE | 29+++++++++++++++++++++++++++++
MMakefile | 44+++++++++++++++++++++++++++++---------------
MREADME.md | 6++++--
Mcstring.3 | 4++--
Mtests/test.c | 1-
5 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020-present, Christos Margiolis. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of images.weserv.nl nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile @@ -1,48 +1,62 @@ LIB = cstring +VERSION = 0.1 +DIST = ${BIN}-${VERSION} MAN3 = ${LIB}.3 PREFIX = /usr/local MAN_DIR = ${PREFIX}/man/man3 HDR_DIR = ${PREFIX}/include LIB_DIR = ${PREFIX}/lib -SRC = ${wildcard *.c} -OBJ = ${SRC:%.c=%.o} +EXT = c +SRC = ${wildcard *.${EXT}} +OBJ = ${SRC:%.${EXT}=%.o} AR = ar ARFLAGS = rs CC = gcc -CPPFLAGS += -Iinclude -pedantic -CFLAGS += -Wall -std=c99 -O3 -DCSTRING_DBG +CPPFLAGS += -Iinclude -DCSTRING_DBG -DVERSION=\"${VERSION}\" +CFLAGS += -Wall -std=c99 -pedantic -O3 LDFLAGS += -Llib #LDLIBS += -CP=cp -f +CP = cp -f +RM = rm -f +RM_DIR = rm -rf MKDIR = mkdir -p - -.PHONY: all clean +TAR = tar -cf +GZIP = gzip all: ${LIB} ${LIB}: ${OBJ} ${AR} ${ARFLAGS} lib${LIB}.a ${OBJ} -%.o: %.c +%.o: %.${EXT} ${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@ +dist: clean + ${MKDIR} ${DIST} + ${CP} -R tests ${SRC} ${MAN3} cstring.h Makefile README.md ${DIST} + ${TAR} ${DIST}.tar ${DIST} + ${GZIP} ${DIST}.tar + ${RM_DIR} ${DIST} + install: all - ${MKDIR} ${DESTDIR}${LIB_DIR} ${DESTDIR}${HDR_DIR} + ${MKDIR} ${DESTDIR}${LIB_DIR} ${DESTDIR}${HDR_DIR} ${DESTDIR}${MAN_DIR} ${CP} ${LIB}.h ${DESTDIR}${HDR_DIR} ${CP} lib${LIB}.a ${DESTDIR}${LIB_DIR} + ${CP} ${MAN3} ${DESTDIR}${MAN_DIR} + sed "s/VERSION/${VERSION}/g" < ${MAN3} > ${DESTDIR}${MAN_DIR}/${MAN3} chmod 644 ${DESTDIR}${HDR_DIR}/${LIB}.h chmod 644 ${DESTDIR}${LIB_DIR}/lib${LIB}.a - ${MKDIR} ${DESTDIR}${MAN_DIR} - ${CP} ${MAN3} ${DESTDIR}${MAN_DIR} chmod 644 ${DESTDIR}${MAN_DIR}/${MAN3} -uninstall: - sudo ${RM} ${DESTDIR}${HDR_DIR}/${LIB}.h - sudo ${RM} ${DESTDIR}${LIB_DIR}/lib${LIB}.a - sudo ${RM} ${DESTDIR}${MAN_DIR}/${MAN3} +uninstall: all + ${RM} ${DESTDIR}${HDR_DIR}/${LIB}.h + ${RM} ${DESTDIR}${LIB_DIR}/lib${LIB}.a + ${RM} ${DESTDIR}${MAN_DIR}/${MAN3} clean: ${RM} ${OBJ} ${LIB} lib${LIB}.a + +.PHONY: all clean dist install uninstall diff --git a/README.md b/README.md @@ -21,7 +21,9 @@ $ cd /path/to/cstring $ sudo make uninstall ``` -In order to link `cstring` to your project use the `-lcstring` flag during compilation. +In order to link `cstring` to your project use the `-lcstring` flag during compilation. +In case you want to run your project in debug mode, compile every file using `cstring` with the +`-DCSTRING_DBG` option. ## Usage @@ -86,7 +88,7 @@ The recommended way of initializing an empty string is by doing `cstring foo = c * `CSTRING_OUT_OF_BOUNDS`: Check if `pos` is out of bounds. * `CSTRING_ARR_LEN`: Determine an array's length. The macro must be called in the same function the array is declared. * `CSTRING_FLAG_CHECK`: Check if flag is on. -* `CSTRING_MALLOC`: Allocate memory with error checking. +* `CSTRING_MALLOC`: Allocate memory with error checking. The following macros can only be used in debug mode * `CSTIRNG_DBG_LOG`: Prints a message in the format of `DEBUG: file:line:func(): msg`. * `CSTRING_DBG_LOG_CSTR_INFO`: Prints all the contents of a `cstring` struct. The argument *has* to be a pointer. diff --git a/cstring.3 b/cstring.3 @@ -1,4 +1,4 @@ -.TH cstring 3 +.TH cstring 3 cstring\-VERSION .SH NAME .B cstring \- A simple and lightweight string library for C inspired by C++'s @@ -20,7 +20,7 @@ option. .P In case you want to run the program in debug mode, compile it with the -.B -DCSTRING_DEBUG +.B -DCSTRING_DBG option. .SH STRUCTURES AND ENUMS .TP diff --git a/tests/test.c b/tests/test.c @@ -2,7 +2,6 @@ // Compilation: gcc test.c -lcstring - int main(int argc, char **argv) {