liblash

Basic tools written and used by lash in c programming.
Log | Files | Refs

commit 59ea400111fefbed37e70759005777ed88936dc6
parent 7bffe37678d93d4d5c5d401adbe0623eedb1e91b
Author: lash <dev@holbrook.no>
Date:   Fri, 31 May 2024 22:35:24 +0100

Add case symbols

Diffstat:
Msrc/Makefile | 11+++++++----
Asrc/case/Makefile | 27+++++++++++++++++++++++++++
Asrc/case/case.c | 29+++++++++++++++++++++++++++++
Asrc/case/case.h | 7+++++++
Asrc/case/test.c | 40++++++++++++++++++++++++++++++++++++++++
5 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -6,28 +6,29 @@ all: make -C hex all make -C llog all make -C rerr all - #make -C case all + make -C case all clean: make -C endian clean make -C hex clean make -C llog clean make -C rerr clean - #make -C case clean + make -C case clean test: all make -C endian test make -C hex test make -C llog test make -C rerr test - #make -C case test + make -C case test shared: all make -C endian shared make -C hex shared make -C llog shared make -C rerr shared - $(CC) $(CFLAGS) -shared -o liblash.so endian/strip.so.o endian/endian.so.o hex/hex.so.o llog/llog.so.o rerr/rerr.so.o + make -C case shared + $(CC) $(CFLAGS) -shared -o liblash.so endian/strip.so.o endian/endian.so.o hex/hex.so.o llog/llog.so.o rerr/rerr.so.o case/case.so.o install: shared cat -v endian/*.h >> $(DESTDIR)/include/lash.h @@ -38,6 +39,8 @@ install: shared install -m0644 -v llog/*.h -t $(DESTDIR)/include cat -v rerr/*.h >> $(DESTDIR)/include/lash.h install -m0644 -v rerr/*.h -t $(DESTDIR)/include + cat -v case/*.h >> $(DESTDIR)/include/lash.h + install -m0644 -v case/*.h -t $(DESTDIR)/include #cp -v liblash.so $(DESTDIR)/lib/ install -m0644 -v liblash.so -t $(DESTDIR)/lib cd $(DESTDIR)/lib && ln -svf liblash.so liblash.so.$(VERSION) diff --git a/src/case/Makefile b/src/case/Makefile @@ -0,0 +1,27 @@ +OBJS := $(patsubst %.c,%.o,$(filter-out test.c,$(wildcard *.c))) +SOBJS := $(patsubst %.c,%.so.o,$(filter-out test.c,$(wildcard *.c))) +INCLUDES := -I. +CFLAGS += $(INCLUDES) +VERSION = 0.0.1 +CFLAGS += -Wall -Werror + +all: $(OBJS) + +test: all + $(CC) $(CFLAGS) test.c case.o -o test.out $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS) + +clean: + rm -vf *.o + rm -vf *.out + rm -vf *.tar.gz + +archive: + git archive --format=tar.gz HEAD -o case-$(VERSION).tar.gz + +%.so.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ -fpic + +shared: $(SOBJS) diff --git a/src/case/case.c b/src/case/case.c @@ -0,0 +1,29 @@ +void uc(char *b) { + int i; + char v; + + i = 0; + v = 1; + while(v > 0) { + v = *(b+i); + if (v > 0x60 && v < 0x7b) { + *(b+i) -= 0x20; + } + i++; + } +} + +void lc(char *b) { + int i; + char v; + + i = 0; + v = 1; + while(v > 0) { + v = *(b+i); + if (v > 0x40 && v < 0x5b) { + *(b+i) += 0x20; + } + i++; + } +} diff --git a/src/case/case.h b/src/case/case.h @@ -0,0 +1,7 @@ +#ifndef LASH_CASE_H_ +#define LASH_CASE_H_ + +void uc(char *b); +void lc(char *b); + +#endif diff --git a/src/case/test.c b/src/case/test.c @@ -0,0 +1,40 @@ +#include <string.h> + +#include "case.h" + + +int test_uc() { + char data[] = "fO13_oBar"; + + uc(data); + if (strcmp(data, "FO13_OBAR")) { + return 1; + } + return 0; +} + +int test_lc() { + char data[] = "FooB12_aR"; + + lc(data); + if (strcmp(data, "foob12_ar")) { + return 1; + } + return 0; +} + +int main() { + int r; + + r = test_uc(); + if (r) { + return 1; + } + + r = test_lc(); + if (r) { + return 2; + } + + return 0; +}