From 69515af77f36bad1f501f3145eba4436e8216965 Mon Sep 17 00:00:00 2001 From: Mikhail Romanko Date: Tue, 11 Mar 2025 09:49:43 +0300 Subject: Fix styling issues, rename scripts --- doc/Examples/PakReader.c | 1 + include/BH/Common.h | 1 - include/BH/Hashmap.h | 1 - include/BH/Thread.h | 1 - include/BH/Util.h | 4 --- src/Hashmap.c | 1 - src/IO.c | 2 +- src/Math/Ray2f.c | 1 + src/Util.c | 4 +++ test/src/TestArgs.c | 1 - test/src/TestHashmap.c | 6 ++++ unit/src/Unit.c | 2 +- util/run-tests.sh | 42 -------------------------- util/style.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ util/tests.sh | 42 ++++++++++++++++++++++++++ util/trim-whitespace.sh | 3 -- util/whitespace.sh | 3 ++ 17 files changed, 136 insertions(+), 56 deletions(-) delete mode 100755 util/run-tests.sh create mode 100755 util/style.sh create mode 100755 util/tests.sh delete mode 100755 util/trim-whitespace.sh create mode 100755 util/whitespace.sh diff --git a/doc/Examples/PakReader.c b/doc/Examples/PakReader.c index 671903a..e350b67 100644 --- a/doc/Examples/PakReader.c +++ b/doc/Examples/PakReader.c @@ -10,6 +10,7 @@ #define HEADER_SIZE 12 #define ENTRY_SIZE 64 + typedef struct PakHeader { char id[4]; diff --git a/include/BH/Common.h b/include/BH/Common.h index 1467b25..78fd503 100644 --- a/include/BH/Common.h +++ b/include/BH/Common.h @@ -23,4 +23,3 @@ typedef size_t (*BH_HashCallback)(const void *); typedef void (*BH_GenericCallback)(void *); #endif /* BH_COMMON_H */ - diff --git a/include/BH/Hashmap.h b/include/BH/Hashmap.h index 57d04fc..7dda9ec 100644 --- a/include/BH/Hashmap.h +++ b/include/BH/Hashmap.h @@ -221,4 +221,3 @@ void *BH_HashmapIterValue(void *iter); #endif /* BH_HASHMAP_H */ - diff --git a/include/BH/Thread.h b/include/BH/Thread.h index 794abc5..b31b8ef 100644 --- a/include/BH/Thread.h +++ b/include/BH/Thread.h @@ -248,7 +248,6 @@ int BH_ConditionBroadcast(BH_Condition *condition); void BH_SpinlockLock(int *lock); - /** * Tries to lock the \a spinlock. * diff --git a/include/BH/Util.h b/include/BH/Util.h index 1b1c53f..d88e47a 100644 --- a/include/BH/Util.h +++ b/include/BH/Util.h @@ -105,7 +105,6 @@ uint32_t BH_Read32BEu(const char *buffer); int32_t BH_Read32BEs(const char *buffer); - /** * Reads 64-bit unsigned integer from the \a buffer in big-endian format. * @@ -136,7 +135,6 @@ void BH_Write16LEu(char *buffer, uint16_t value); - /** * Writes 16-bit signed integer to the \a buffer in little-endian format. * @@ -177,7 +175,6 @@ void BH_Write64LEu(char *buffer, uint64_t value); - /** * Writes 64-bit signed integer to the \a buffer in little-endian format. * @@ -208,7 +205,6 @@ void BH_Write16BEs(char *buffer, int16_t value); - /** * Writes 32-bit unsigned integer to the \a buffer in big-endian format. * diff --git a/src/Hashmap.c b/src/Hashmap.c index ad8e7bd..8253ec6 100644 --- a/src/Hashmap.c +++ b/src/Hashmap.c @@ -387,4 +387,3 @@ void *BH_HashmapIterValue(void *iter) { return ((BH_HashmapNode *)iter)->value; } - diff --git a/src/IO.c b/src/IO.c index c8516da..2b2b302 100644 --- a/src/IO.c +++ b/src/IO.c @@ -135,6 +135,7 @@ int BH_IOWrite(BH_IO *io, return code; } + int BH_IOPeek(BH_IO *io, char *buffer, size_t size, @@ -227,7 +228,6 @@ int BH_IOClear(BH_IO *io) } - BH_IO *BH_BufferNew(BH_IO *io) { (void)io; diff --git a/src/Math/Ray2f.c b/src/Math/Ray2f.c index ea2572b..7e217ea 100644 --- a/src/Math/Ray2f.c +++ b/src/Math/Ray2f.c @@ -155,6 +155,7 @@ int BH_Segment2fIntersectSegment(const float *aStart, return BH_OK; } + int BH_Ray2fIntersectBox2f(const float *aStart, const float *aDirection, const float *bMin, diff --git a/src/Util.c b/src/Util.c index 110f1ae..b388fed 100644 --- a/src/Util.c +++ b/src/Util.c @@ -110,6 +110,7 @@ int16_t BH_Read16BEs(const char *buffer) return tmp.s; } + uint32_t BH_Read32BEu(const char *buffer) { union I32 tmp; @@ -120,6 +121,7 @@ uint32_t BH_Read32BEu(const char *buffer) return tmp.u; } + int32_t BH_Read32BEs(const char *buffer) { union I32 tmp; @@ -130,6 +132,7 @@ int32_t BH_Read32BEs(const char *buffer) return tmp.s; } + uint64_t BH_Read64BEu(const char *buffer) { union I64 tmp; @@ -144,6 +147,7 @@ uint64_t BH_Read64BEu(const char *buffer) return tmp.u; } + int64_t BH_Read64BEs(const char *buffer) { union I64 tmp; diff --git a/test/src/TestArgs.c b/test/src/TestArgs.c index 940a9c6..0175dd9 100644 --- a/test/src/TestArgs.c +++ b/test/src/TestArgs.c @@ -401,7 +401,6 @@ BH_UNIT_TEST(Aesthetics) } - int main(int argc, char **argv) { (void)argc; diff --git a/test/src/TestHashmap.c b/test/src/TestHashmap.c index da73e4b..233a279 100644 --- a/test/src/TestHashmap.c +++ b/test/src/TestHashmap.c @@ -31,6 +31,7 @@ static int NewFree(void) return 0; } + static int GrowShrink(void) { BH_Hashmap *hashmap; @@ -102,6 +103,7 @@ static int GrowShrink(void) return 0; } + static int InsertRemove(void) { BH_Hashmap *hashmap; @@ -138,6 +140,7 @@ static int InsertRemove(void) return 0; } + static int Lookup(void) { BH_Hashmap *hashmap; @@ -173,6 +176,7 @@ static int Lookup(void) return 0; } + static int Clear(void) { BH_Hashmap *hashmap; @@ -195,6 +199,7 @@ static int Clear(void) return 0; } + static int Fields(void) { BH_Hashmap *hashmap; @@ -217,6 +222,7 @@ static int Fields(void) return 0; } + int main(int argc, char **argv) { (void)argc; diff --git a/unit/src/Unit.c b/unit/src/Unit.c index a0b61e1..654839d 100644 --- a/unit/src/Unit.c +++ b/unit/src/Unit.c @@ -1,6 +1,7 @@ #include #include + typedef struct BH_Unit { struct BH_Unit *next; @@ -77,4 +78,3 @@ int BH_UnitRun(void) BH_UnitCleanup(); return result; } - diff --git a/util/run-tests.sh b/util/run-tests.sh deleted file mode 100755 index 1ee2183..0000000 --- a/util/run-tests.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -# Set of compilers and profiles for testing -compilers="gcc clang" -profiles="Debug Release Asan" - -# Build and run tests -build_and_run() { - compiler=$1 - mode=$2 - - # Reconfigure project - rm -rf build - cmake -S . -B build -DCMAKE_BUILD_TYPE=${mode} -DCMAKE_C_COMPILER=${compiler} - if [ $? -ne 0 ]; then - return 1 - fi - - # Build - cmake --build build - if [ $? -ne 0 ]; then - return 1 - fi - - # Test - ctest -T test --test-dir build - if [ $? -ne 0 ]; then - return 1 - fi - - return 0 -} - -# For each compiler and profile - run test -for compiler in $compilers; do - for profile in $profiles; do - if ! build_and_run $compiler $profile; then - echo "Tests failed for $compiler $profile" - exit 1 - fi - done -done diff --git a/util/style.sh b/util/style.sh new file mode 100755 index 0000000..c892f7d --- /dev/null +++ b/util/style.sh @@ -0,0 +1,77 @@ +#!/bin/sh + + +# Check args +if [ $# -lt 1 ]; then + echo "error: specify file" + exit 1 +fi + +if [ ! -f $1 ]; then + echo "error: file '$1' not found" + exit 1 +fi + + +# Message about trailing space before EOL +eolerrors=$(grep -n "\s$" "$1" | cut -f1 -d: | while read -r line; do + if [ "$line" ]; then + echo "$1:$line: error: whitepace before EOL" + fi +done) + + +# Message about non-empty last-line +linecount=$(($(wc -l "$1" | cut -f1 -d " ") + 1)) +lastline=$(tail -n "+$linecount" $1) + +llerrors=$(if [ "$lastline" ]; then + echo "$1:$linecount: error: no EOL before EOF" +fi) + + +# Compute ranges of new lines +count=0; start=0; next=0 +lines="$(grep -n "^$" "$1" | cut -f1 -d:) +0" +ranges=$(echo "$lines" | while read -r line; do + if [ "$line" ]; then + if [ $start -eq 0 ]; then + start="$line"; count=1; next=$(($start + 1)) + elif [ "$line" -ne $next ]; then + echo $start $count + start="$line"; count=1; next=$(($start + 1)) + else + count=$(($count + 1)); next=$(($next + 1)) + fi + fi +done) + + +# Check that we have no more then 3 EOLs in the row +fewerrors=$(echo "$ranges" | while read -r line; do + number=$(echo $line | cut -f1 -d " ") + size=$(echo $line | cut -f2 -d " ") + if [ $size -gt 2 ]; then + echo "$1:$number: error: too many EOLs" + fi +done) + +# Print out errors +code=0 +if [ "$eolerrors" ]; then + echo "$eolerrors" 1>&2 + code=1 +fi + +if [ "$llerrors" ]; then + echo "$llerrors" 1>&2 + code=1 +fi + +if [ "$fewerrors" ]; then + echo "$fewerrors" 1>&2 + code=1 +fi + +exit $code diff --git a/util/tests.sh b/util/tests.sh new file mode 100755 index 0000000..1ee2183 --- /dev/null +++ b/util/tests.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# Set of compilers and profiles for testing +compilers="gcc clang" +profiles="Debug Release Asan" + +# Build and run tests +build_and_run() { + compiler=$1 + mode=$2 + + # Reconfigure project + rm -rf build + cmake -S . -B build -DCMAKE_BUILD_TYPE=${mode} -DCMAKE_C_COMPILER=${compiler} + if [ $? -ne 0 ]; then + return 1 + fi + + # Build + cmake --build build + if [ $? -ne 0 ]; then + return 1 + fi + + # Test + ctest -T test --test-dir build + if [ $? -ne 0 ]; then + return 1 + fi + + return 0 +} + +# For each compiler and profile - run test +for compiler in $compilers; do + for profile in $profiles; do + if ! build_and_run $compiler $profile; then + echo "Tests failed for $compiler $profile" + exit 1 + fi + done +done diff --git a/util/trim-whitespace.sh b/util/trim-whitespace.sh deleted file mode 100755 index f661aa3..0000000 --- a/util/trim-whitespace.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -find . \( -iname "*.h" -o -iname "*.c" \) -exec sed -i .bak "s/[ ]*$//" {} \; -find . -iname "*.bak" -exec rm {} \; diff --git a/util/whitespace.sh b/util/whitespace.sh new file mode 100755 index 0000000..f661aa3 --- /dev/null +++ b/util/whitespace.sh @@ -0,0 +1,3 @@ +#!/bin/sh +find . \( -iname "*.h" -o -iname "*.c" \) -exec sed -i .bak "s/[ ]*$//" {} \; +find . -iname "*.bak" -exec rm {} \; -- cgit v1.2.3