From c6cbdee77b9889ce74ddd7b0677580c31acf68bc Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 21 Mar 2025 23:15:03 +0100 Subject: [PATCH] wip --- makefile | 330 +++++++++++++++------------------- morep_server.c | 138 ++++++++++++++ morep_valid.c => morep_test.c | 15 +- 3 files changed, 294 insertions(+), 189 deletions(-) create mode 100644 morep_server.c rename morep_valid.c => morep_test.c (96%) diff --git a/makefile b/makefile index 6183d8b..79f6077 100644 --- a/makefile +++ b/makefile @@ -1,231 +1,195 @@ -# Messaging over raw Ethernet Packets communication library - -MDIR = $(shell pwd) - -PACKAGE = morep - -IFLAGS += -I. -I../src/debug -I../src/gpio -OFLAGS = -O4 -minline-all-stringops -fsingle-precision-constant -#OFLAGS += -msse -msse2 -CFLAGS += -Wall -W -Wextra -g $(OFLAGS) $(IFLAGS) -fpic -LFLAGS += -g -L$(MDIR) -Wl,-rpath=$(MDIR) - -LIBDEP = $(wildcard *.ld) -NAMES = $(LIBDEP:.ld=) -DEBIAN = $(addprefix debian-,$(NAMES)) -PACKS = $(addprefix pack-,$(NAMES)) -LIBPRE = lib -LIBEXT = so -LIBFUL = $(shell cat $(wildcard *.ld) | sed 's/:.*//') -LIBNIC = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\.[0-9]*\)\..*:.*/\1/') -LIBNAM = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\)\..*:.*/\1/') -LIBSTA = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\)\..*:.*/.a/') - -TESTS += $(shell [ "$(wildcard test/*.c)" ] && grep -l '/\* *linker:' test/*.c | sed 's/\.c//g') +# Default flags + +CC = gcc + +#INCLUDES = -I../debug -D__MEMORY_ALLOCATION__ +INCLUDES = +OFLAGS = -O4 -Os +#OFLAGS = -O0 +#OFLAGS = -O4 -ffast-math -finline-functions +#OFLAGS = -O4 -finline-functions +#OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow +#OFLAGS += -minline-all-stringops -fsingle-precision-constant +#OFLAGS += -malign-double +CFLAGS += -W -Wall -Wextra -g +#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 +CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS) +LDFLAGS += -g $(LDOPTS) $(OPTIONS) + +LDOPT = linker +MV = mv +ifneq (, $(findstring linux, $(MAKE_HOST))) +# Linux +else ifneq (, $(findstring mingw, $(MAKE_HOST))) +# Windows MinGw +CFLAGS += -DWIN32 +#LDLIBS += -lws2_32 +LDOPT = winlnk +else ifneq (, $(findstring cygwin, $(MAKE_HOST))) +CFLAGS += -DWIN32 +# Windows CygWin +LDOPT = winlnk +else ifneq (, $(findstring msdos, $(MAKE_HOST))) +# MSDOS +LDOPT = doslnk +MV = move +endif -TARBALL = $(PACKAGE)_$(shell date +%F).tgz +# Targets -ALLDOC = $(wildcard *.3) $(wildcard $(addprefix README.,$(NAMES))) -ALLHEA = $(wildcard *.h) $(wildcard test/*.h) -ALLSRC = $(wildcard *.c) $(wildcard test/*.c) -ALLDEP = $(ALLSRC:.c=.d) $(addprefix $(LIBPRE),$(LIBDEP:.ld=.d)) -ALLTST = $(subst /,_,$(TESTS)) +ALLEXE = +ALLEXE += more_server +ALLEXE += more_test SHELL = bash +#MAKE = mingw32-make MAKEFLAGS += -s - -DEBPKG = ../debian-pkg - -# Install - -DOCS = $(wildcard $(addprefix README.,$(NAMES))) COPYING makefile -INCS = $(wildcard *.h) -LIBS = $(LIBFUL) $(LIBNIC) $(LIBNAM) $(LIBSTA) -MANS = $(wildcard *.3) -TESS = $(wildcard test/*.c) $(wildcard test/*.h) test/makefile - -ifeq ($(DESTDIR),) -DESTDIR = /usr/local -endif - -BINDIR = $(DESTDIR)/bin -LIBDIR = $(DESTDIR)/lib -INCDIR = $(DESTDIR)/include/thales -DOCDIR = $(DESTDIR)/share/doc/$(PACKAGE) -MANDIR = $(DESTDIR)/share/man/man3 -TESDIR = $(DESTDIR)/share/doc/$(PACKAGE)/test - -INSTBIN = $(addprefix $(BINDIR)/, $(EXECS)) -INSTDOC = $(addprefix $(DOCDIR)/, $(DOCS)) -INSTINC = $(addprefix $(INCDIR)/, $(INCS)) -INSTLIB = $(addprefix $(LIBDIR)/, $(LIBS)) -INSTMAN = $(addprefix $(MANDIR)/, $(MANS)) -INSTTES = $(addprefix $(DOCDIR)/, $(TESS)) - -FILES = $(INSTBIN) $(INSTDOC) $(INSTINC) $(INSTLIB) $(INSTMAN) $(INSTTES) +include $(wildcard .makefile) # Functions -TITLE = { tput colors 2>/dev/null | grep -qE '8|256' && echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t" || echo -en "$(strip $(1)):\t"; } -INFO = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;34m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; } -PASS = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;32m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; } -WARN = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;33m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; } -FAIL = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;31m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; } - -_GET = awk '{sub(/\/\/.*/,"")} /\/\* *$(1):.*\*\// { sub(/^.*\/\* *$(1): */, ""); sub(/ *\*\/.*$$/, ""); print }' $(2) -GET = $(shell $(call _GET,$(1),$(2))) -# $(shell ./getcomments.pl -p='$(1):\s' -f='%' $(2)) - -_VER = sed 's/.*\.$(LIBEXT)\.\([0-9.]*\):.*/\1/' $(1) -VER = $(shell $(call _VER,$(1))) -PVER = $(shell $(call _VER,$(subst pack-,,$(1).ld))) +TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t" +PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m" +WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m" +FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m" MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1) -INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && { chmod a+rX,go-w -f $(2); true; } +INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2) + +VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; } -VALID = $(call TITLE, $(1)) && { $(2); } && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; } +GETCOMMENTS = awk '/\/\*\s*$(1):/,/\*\// { sub(/.*\/\*\s*$(1):/, ""); sub (/\s*\*\/.*/, ""); print } /\/\/\s*$(1):/ {sub (/.*\/\/\s*$(1):/, ""); print }' $(2) +#GETCOMMENTS = perl -- getcomments.pl -p='$(1):\s' -f='%' $(2) ## Generic rules all: depends - make $(LIBNAM) $(LIBNIC) $(LIBSTA) $(TESTS) - -archive: - $(call VALID, "Archiving $(TARBALL)", hg archive $(PACKAGE) && tar cfz ../$(TARBALL) $(PACKAGE); rm -rf $(PACKAGE)) - -depends: $(ALLDEP) + $(MAKE) $(ALLEXE:%=%.exe) count: - $(call TITLE, "Counting") - echo - wc $(ALLHEA) $(ALLSRC) makefile $(ALLDOC) + wc $(wildcard *.c *.h) $(MAKEFILE_LIST) clean: $(call TITLE, "Cleaning") touch clean - rm -f $(wildcard *.[do] *.ho *~ test/*.[do] test/*.ho test/*~ web/*~ $(TESTS:=.log) $(TESTS:=.test)) clean + rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out _) $(call PASS, SUCCESS) -documentation: doxygen.conf $(wildcard *.[ch]) - $(call TITLE, "Publishing $@") - doxygen $<; true - $(call PASS, SUCCESS) - -gcov: - make purge - CFLAGS="-O0 -fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs" make - -headers: $(ALLHEA:.h=.ho) +depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) -install: $(FILES) +gcovs: + $(MAKE) $(addprefix gcov_,$(ALLEXE)) -$(INSTBIN):$(BINDIR)/%:% - $(call VALID, "File [$@]", $(call INSTALL, $<, $@)) - -$(INSTDOC):$(DOCDIR)/%:% - $(call VALID, "Documentation [$@]", $(call INSTALL, $<, $@)) - -$(INSTINC):$(INCDIR)/%:% - $(call VALID, "Include [$@]", $(call INSTALL, $<, $@)) - -$(INSTLIB):$(LIBDIR)/%:% - $(call VALID, "Library [$@]", $(call INSTALL, $<, $@)) - -$(INSTMAN):$(MANDIR)/%:% - $(call VALID, "Manpage [$@]", $(call INSTALL, $<, $@)) - -$(INSTTES):$(TESDIR)/%:test/% - $(call VALID, "Test file [$@]", $(call INSTALL, $<, $@)) - $(call VALID, "Adapt test [$@]", sed -i 's/"..\/\(.*\)"//;/depend:/ s/: .* /: /' $@) +gprofs: + $(MAKE) $(addprefix gprof_,$(ALLEXE)) purge: clean $(call TITLE, "Purging") touch purge - rm -rf $(TESTS) $(LIBFUL) $(LIBNIC) $(LIBNAM) $(LIBSTA) $(wildcard *.gcda *.gcno *.gcov test/*.gcda test/*.gcno test/*.gcov) documentation purge + rm -f purge $(ALLEXE:%=%.exe) $(call PASS, SUCCESS) -%.test: %.c makefile - $(call VALID, "Extracting $@", $(call _GET,test, $<) | sed 's;{};${<:.c=};g' > $@) - -test_%: test/%.test test/% - $(call WARN, "Testing ${@:test_=}"); - IFS=$$'\n'; \ - LOGFILE=${<:.test=.log}; \ - rm -f $$LOGFILE; \ - for test in `cat $<`; do \ - $(call INFO, "=== $$test"); \ - eval $(VALGRIND) $$test 2>>$$LOGFILE; \ - done; \ - [ "`cat $<`" ] || { $(call INFO, "=== ${<:.test=}"); eval $(VALGRIND) ${<:.test=} 2>>$$LOGFILE; }; \ - true +valgrinds: + $(MAKE) all + $(MAKE) $(addprefix valgrind_,$(ALLEXE)) -tests: $(ALLTST) +wipe: purge + $(call TITLE, "Wiping") + touch wipe + rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog) + $(call PASS, SUCCESS) -valgrind_%: - $(call WARN, "Activate valgrind") - VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \ +tests: + -rm -f $(ALLEXE) + $(MAKE) all + $(MAKE) $(addprefix test_,$(ALLEXE)) + +## Main rules + +include $(wildcard *.d) +include $(wildcard *.ld) + +gcov_%: + $(MAKE) purge + $(MAKE) depends + OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe + $(MAKE) test_$(@:gcov_%=%) + gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)` + touch gcov + rm -f gcov $(wildcard *.gcda *.gcno) + $(MAKE) purge + grep '^ *#####' *.c.gcov || true + +gprof_%: + $(MAKE) purge + $(MAKE) depends + OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe + $(MAKE) ${@:gprof_%=%}.test + IFS=$$'\n'; id=1; \ + for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \ + log=${@:gprof_%=%}.prof-$$id.glog; \ + $(call TITLE, test: $$test); \ + echo $$test > $$log; \ + eval $$test >> $$log; \ + [ $$? -eq 0 ] \ + && echo -e "\033[1;32mSUCCESS\033[0;0m" \ + || echo -e "\033[1;31mFAILED\033[0;0m"; \ + [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \ + let id++; \ + done; + $(MAKE) purge + +%.test: %.c + $(call TITLE, "Building $@") + $(call GETCOMMENTS,test, $<) > $@ + $(call PASS, SUCCESS) + -rm -f _ + +test_%: %.test %.exe + IFS=$$'\n'; RC=0; \ + for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \ + echo "=== $$test ==="; \ + eval $$test; \ + [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \ + || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \ + test "$$RC" = 1 -a "$(STOP)" = 1 && break; \ + done; \ + test "$$RC" -ne 1 + +valgrind_%: %.exe + VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \ export VALGRIND; \ - make ${@:valgrind_%=test_%} + $(MAKE) $(@:valgrind_%=test_%) 3>$@.log %.d: %.c - $(call VALID, "Creating $@", { \ - $(CC) $(IFLAGS) -MM $< -o - | sed "s;^`basename $(<:.c=.o)`;$(<:.c=.o);"; \ - echo $(call GET,depend, $<) | sed "s;^;$(<:.c=): $(<:.c=.o) ;"; \ - } > $@) - -lib%.d: %.ld - $(call VALID, "Creating $@", sed 's/-l[^ ]*//g;s/\(.*\)\.$(LIBEXT)\.\([0-9]*\)\.\(.*\): \(.*\)/.\1.$(LIBEXT): \4\n\1.a: \4\n\1.$(LIBEXT).\2.\3: .\1.$(LIBEXT)\n\t$$(call VALID, "Assembling $$@", cp -f $$< $$@ \&\& rm $$<)\n\1.$(LIBEXT) \1.$(LIBEXT).\2: \1.$(LIBEXT).\2.\3\n\t$$(call VALID, "Assembling $$@", ln -sf $$< $$@)/' $< > $@) - -%.o: %.c - $(call VALID, "Building $@", $(CC) $(CFLAGS) $(call GET,cflags, $<) -c $< -o $@) - -%.ho: %.h - $(call VALID, "Building $@", $(CC) $(CFLAGS) $(call GET,cflags, $<) -x c -c $< -o $@) - -%.a: - $(call VALID, "Archive $@", $(AR) -rc $@ $^) - -.$(LIBPRE)%: - $(call TITLE, "Linking `echo $@ | sed 's/^\.//'`") - $(CC) $(LDFLAGS) $$(cat `echo $@ | sed 's/\.$(LIBPRE)\(.*\)\.$(LIBEXT)/\1.ld/'` | sed 's/.*://') -shared -Wl,-soname=$$(cat `echo $@ | sed 's/\.$(LIBPRE)\(.*\)\.$(LIBEXT)/\1.ld/'` | sed 's/^\(.*\.$(LIBEXT)\.[0-9]*\)\..*/\1/') -o $@ || { $(call FAIL, FAILED); test; } + $(call TITLE, "Building $@") + $(CC) $(INCLUDES) -MM $< -o $@~ + echo ${<:.c=.o}: $(shell $(call GETCOMMENTS,depends, $<)) >> $@~ + $(MV) $@~ $@ $(call PASS, SUCCESS) -$(PACKS):pack-%: %.ld depends - $(call TITLE, "Packing $@-$(call VER,$<).tgz") - [ ! -e $@ ] || rm -rf $@ - mkdir $@ - awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /\.o:/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if (prev != a[k]) print a[k]; prev=a[k] } }' `sed 's/.*://;s/\.o/.d/g;s/-l[^ ]*//' $<` | xargs -i% cp % $@ - cp $< makefile COPYING $(wildcard ${<:.ld=.3} README.${<:.ld=}) $@ - mkdir $@/test - awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /$(LIBPRE)$(<:.ld=.$(LIBEXT))/ && ! /^$(LIBPRE)$(<:.ld=.$(LIBEXT))/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if ((prev != a[k]) && (a[k] != "$(LIBPRE)$(<:.ld=.$(LIBEXT))")) print a[k]; prev=a[k] } }' test/*.d | xargs awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /\.o:/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if ((prev != a[k]) && (a[k] != "\\") && !(a[k] ~ /\.\./)) print a[k]; prev=a[k] } }' | xargs -i% cp % $@/test - cp test/makefile $@/test - tar czf $@-$(call VER,$<).tgz $@ - rm -rf $@ +%.ld: %.c + $(call TITLE, "Building $@") + echo ${<:.c=.exe}: $(shell $(call GETCOMMENTS,$(LDOPT), $<) | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@ $(call PASS, SUCCESS) -packages: $(PACKS) +%.o: %.c + $(call TITLE, "Building $@") + $(CC) $(CFLAGS) $(INCLUDES) $(shell $(call GETCOMMENTS,cflags, $<)) -c $< -o $@ + $(call PASS, SUCCESS) -$(DEBIAN):debian-%: pack-% - $(call TITLE, "Debian package: $(<:pack-%=%) "$(call PVER,$<)) - [ -d $(DEBPKG) ] || mkdir $(DEBPKG) - [ ! -d $(DEBPKG)/$<-$(call PVER,$<) ] || rm -rf $(DEBPKG)/$<-$(call PVER,$<) - [ ! -d $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) ] || rm -rf $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) - tar xfz $<-$(call PVER,$<).tgz -C $(DEBPKG) - mv $(DEBPKG)/$< $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) - cd $(DEBPKG); tar czf $(<:pack-%=%)_$(call PVER,$<).orig.tar.gz $(<:pack-%=%)-$(call PVER,$<) - cp -par debian $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) - for f in $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<)/debian/*.$(<:pack-%=%); do mv $$f $${f/.$(<:pack-%=%)}; done - cd $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) && { echo; debuild; } -debian: $(DEBIAN) +%.exe: %.o %.d + $(call TITLE, "Building $@") + $(CC) $(LDFLAGS) $< $(shell $(call GETCOMMENTS,$(LDOPT), ${<:.o=.c})) $(LDLIBS) -o $@ + $(call PASS, SUCCESS) -test/%: test/%.o test/%.d - $(call VALID, "Linking $@", $(CC) $(LDFLAGS) $(LFLAGS) $< $(call GET,linker, $(<:.o=.c)) -o $@) +## Phony -include $(wildcard *.d) $(wildcard test/*.d) +.PHONY: all clean count depends gcovs purge tests -## Phony +## Precious -.PHONY: all archive clean count depends headers install packages purge +.PRECIOUS: %.d %.o diff --git a/morep_server.c b/morep_server.c new file mode 100644 index 0000000..d4b3e58 --- /dev/null +++ b/morep_server.c @@ -0,0 +1,138 @@ +/* + File name : morep_server.c + Projet : MERLIN + Date of creation : 2025/03/18 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : Raw Ethernet packet server for MOREP library + + History : + - initial version +*/ + +/* depend: */ +/* cflags: */ +/* linker: morep.o */ +/* winlnk: morep.o */ + +#include +#include +#include +#include +#include +#include +#include + +#include "debug.h" + +#include "morep.h" + +int stop = 0; + +void sig_handler (int sig) +{ + switch (sig) { + case SIGINT: + stop = 1; + break; + case SIGTERM: + exit (0); + break; + } +} + +int morep_server (char *url) { +{ + VERBOSE (morep, TRACE, PRINTF ("morep_server\n")); + + int fd = MOREP_connect (url); + + VERBOSE (morep, INFO, PRINTF ("server started at '%s'\n", url)); + + int morep = MOREP_Connect (local_address, remote_address); + if (morep < 0) { + VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url)); + return -1; + } + + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + + int i = 0; + char *words[] = {"Quo", "cognito", "Constantius", "ultra", "mortalem", "modum", "exarsit", "ac", "nequo", "casu", "idem", "Gallus", "de", "futuris", "incertus", "agitare", "quaedam", "conducentia", "saluti", "suae", "per", "itinera", "conaretur,", "remoti", "sunt", "omnes", "de", "industria", "milites", "agentes", "in", "civitatibus", "perviis.", NULL}; + while (stop) { + + int len = MOREP_Receive (fd) + VERBOSE (morep, INFO, PRINTF ("receive %d bytes\n", len)); + + uint8_t buffer = MOREP_Get_Tx_Buffer (fd); + len = strlen (words[i]); + memcpy (buffer, words[i++], len); + if (words[i] == NULL) { + i = 0; + } + len = MOREP_Send (fd); + VERBOSE (morep, INFO, PRINTF ("send %d bytes\n", len)); + + } + + return 0; +} + +/** + Verbose level +*/ +DECLARE_VERBOSE_LEVEL (morep, INFO); + +int main (int argc, char **argv) +{ + char *url = NULL; + + /* get basename */ + char *pt = progname = argv[0]; + while (*pt) { + if ((*pt == '/') || (*pt == '\\')) { + progname = pt + 1; + } + pt++; + } + + /* process argument */ + while (argc-- > 1) { + char *arg = *(++argv); + if (arg[0] != '-') { + url = arg[0]; + } + char c = arg[1]; + switch (c) { + case 'v': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (ERROR, fprintf (stderr, "%s: no directory name\n", progname)); + return usage (1); + } + CHANGE_VERBOSE_LEVEL (morep, atoi (arg)); + break; + case 'h': + default: + printf ("usage: %s [-h] [-v int] \n"); + return (c != 'h'); + } + } + + if (url) { + server (url); + } + + return (url == NULL); +} + +/* test-depend: morep_valid */ + +/* test: morep_server */ +/* test: morep_server -h */ +/* test: morep_server -v 4 */ + +/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/ diff --git a/morep_valid.c b/morep_test.c similarity index 96% rename from morep_valid.c rename to morep_test.c index e5e84af..ba8b9f8 100644 --- a/morep_valid.c +++ b/morep_test.c @@ -1,17 +1,22 @@ /* - File name : morep_valid.c + File name : morep_test.c Projet : MERLIN Date of creation : 2025/03/18 Version : 1.0 Copyright : Thales SIX Author : Laurent Mazet - Description : Validation test suite for MOREP library + Description : Test programm for MOREP library History : - initial version */ +/* depend: */ +/* cflags: */ +/* linker: morep.o */ +/* winlnk: morep.o */ + #include #include #include @@ -214,9 +219,7 @@ int main (int argc, char **argv) return failed ? EXIT_FAILURE : EXIT_SUCCESS; } -/* test-depend: morep_valid */ - -/* test: morep_valid */ -/* test: morep_valid 1 */ +/* test: morep_test */ +/* test: morep_test 1 */ /* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/ -- 2.30.2