Commits

Anonymous committed 0940b19

نقلت المخطوطات الإدارية إلى \tools تمهيدا لتعميمها على باقي الوحدات

Comments (0)

Files changed (7)

modules/s/parts/genheader.sh

-#!/bin/bash
-
-
-header='scts.h'
-
-
-echo "#ifndef SCTS_H
-#define SCTS_H" > $header
-
-
-echo "
-// STATIC SECTION" >> $header
-cat init.h >> $header
-
-
-echo "
-// PARTIALS SECTION: AUTOMATICLY GENERATED" >> $header
-# prototypes and macros
-for f in *.c; do
-    [[ "$f" == "init.c" ]] && continue    
-    
-    echo "//--${f::-2}" >> $header
-
-
-    IFS=':'
-    BEGIN=($(grep -b "//HEADER" "$f"))
-    END=($(grep -b "//LIB" "$f"))
-
-    [[ "$BEGIN" ]] || {
-        echo "'//HEADER' was not found in '$f'"
-        exit 1
-    }
-    [[ "$END" ]] || {
-        echo "'//LIB' was not found in '$f'"
-        exit 1
-    }
-    
-    ((LENGTH = END-BEGIN))
-    
-    dd bs=1 count=$LENGTH skip=$BEGIN if="$f" 2>/dev/null | tail -n +2 >> $header
-    
-    echo "
-    " >> $header
-    
-done
-
-
-echo "#endif" >> $header

modules/s/parts/part.c.template

-#include "scts.h"
-
-//HEADER
-#ifndef SCTS_PART_[PARTNAME]
-#define SCTS_PART_[PARTNAME]
-size_t scts_[partname]_c(...);
-size_t scts_[partname]_u(...);
-#define scts_[partname](primary) (_Generic( (0, primary), \
-    char32_t *:         scts_[partname]_iu, \
-    char32_t **:        scts_[partname]_mu, \
-    const char32_t *:   scts_[partname]_iu, \
-    const char32_t **:  scts_[partname]_mu, \
-    char *:             scts_[partname]_ic, \
-    char **:            scts_[partname]_mc, \
-    const char *:       scts_[partname]_ic, \
-    const char **:      scts_[partname]_mc  \
-    )(primary))
-
-/*
-sctdoc:scts_[partname]:
-
-NAME
-    scts_[partname]
-
-SYNOPSIS
-    int generic_dummy([char*][char32_t*] primary)
-    
-    int generic_dummy_c(char *primary)
-    int generic_dummy_u(char32_t *primary)
-    
-DESCRIPTION
-    ...
-
-RETURN
-    ...
-
-EXAMPLE
-    ...
-
-SEE ALSO
-    ...
-*/
-
-#endif
-
-//LIB
-size_t scts_[partname]_...(...){
-    // input checks
-    // logic
-}
-
-
-//TEST
-#ifdef test_[partname]
-
-#include <assert.h>
-#include <stdio.h>
-
-int main() {
-    debug_fd = stderr;
-    assert(...);
-    return 0;
-}
-
-#endif

modules/s/parts/part.template

+#include "scts.h"
+
+//HEADER
+#ifndef SCTS_PART_[PARTNAME]
+#define SCTS_PART_[PARTNAME]
+size_t scts_[partname]_c(...);
+size_t scts_[partname]_u(...);
+#define scts_[partname](primary) (_Generic( (0, primary), \
+    char32_t *:         scts_[partname]_iu, \
+    char32_t **:        scts_[partname]_mu, \
+    const char32_t *:   scts_[partname]_iu, \
+    const char32_t **:  scts_[partname]_mu, \
+    char *:             scts_[partname]_ic, \
+    char **:            scts_[partname]_mc, \
+    const char *:       scts_[partname]_ic, \
+    const char **:      scts_[partname]_mc  \
+    )(primary))
+
+/*
+sctdoc:scts_[partname]:
+
+NAME
+    scts_[partname]
+
+SYNOPSIS
+    int generic_dummy([char*][char32_t*] primary)
+    
+    int generic_dummy_c(char *primary)
+    int generic_dummy_u(char32_t *primary)
+    
+DESCRIPTION
+    ...
+
+RETURN
+    ...
+
+EXAMPLE
+    ...
+
+SEE ALSO
+    ...
+*/
+
+#endif
+
+//LIB
+size_t scts_[partname]_...(...){
+    // input checks
+    // logic
+}
+
+
+//TEST
+#ifdef test_[partname]
+
+#include <assert.h>
+#include <stdio.h>
+
+int main() {
+    debug_fd = stderr;
+    assert(...);
+    return 0;
+}
+
+#endif

modules/s/parts/test.sh

-#!/bin/bash
-
-die(){
-    printf "\n\e[1;31m[error] $1\n\e[0m" 
-    exit 1 
-}
-ok(){
-    [[ "$1" ]] && m="$1" || m='[ok]'
-    printf "\n\e[1;32m$m\n\e[0m" 
-    exit 0
-}
-
-# if the first argument is a file, test it only, otherwise test every source file
-[[ -f "$1" ]] && list="$1" || list=*.c
-
-# generate a common header for inter-dependant parts to compile
-./genheader.sh || {
-    echo "could not generate header"
-    exit 1
-}
-
-for f in $list; do
-    [[ "$f" == "init.c" ]] && continue    
-    f="${f::-2}"
-
-    echo "testing '$f.c' (test_$f)"
-    
-    # compile
-    clang -o "$f".test.bin -g -Wall -Wextra -pedantic -std=c1x  -D"test_$f" *.c ../../a/scta.c -I ../../a || die "'$f.c' build error"'!'
-    # fast test
-    ./"$f".test.bin || die "'$f.c' run error"'!'
-    # memcheck (could be merged with fast test, but seperate for now)
-    valgrind --tool=memcheck --leak-check=full --error-exitcode=1 ./"$f".test.bin 2>/dev/null 1>&2 || die "'$f.c' valgrind error"'!'
-    # scan-build?
-    # clang --analyze -o "$f".test.bin -g -Wall -Wextra -pedantic -std=c1x  -D"test_$f" *.c ../../a/scta.c -I ../../a
-        
-done
-rm *.test.bin
-ok

tools/parts.gen.header.sh

+#!/bin/bash
+die(){
+    printf "\e[1;31m[("$(basename "$0")"):ERROR] $1\n\e[0m" 
+    exit 1 
+}
+warn(){
+    printf "\e[1;33m[("$(basename "$0")"):WARNING] $1\n\e[0m" 
+}
+print(){
+    printf "\e[1;37m("$(basename "$0")"):$1\n\e[0m" 
+}
+ok(){
+    [[ "$1" ]] && m="$1" || m='[ok]'
+    printf "\e[1;32m("$(basename "$0")"):$m\n\e[0m" 
+    exit 0
+}
+
+[[ "$(pwd)" == */libsct/modules/*/parts ]] || die "This is not a standard parts path. This script should be run inside the directory that contains the parts: */libsct/modules/*/parts"
+
+[[ -f init.h ]] || warn "Could not find init.h"
+
+
+prefix="sct$(basename $(cd ..; pwd))"
+CAPSPF=$(echo "$prefix" | tr [:lower:] [:upper:])
+header="$prefix.h"
+
+
+print "generating $header"
+
+echo '#ifndef '"$CAPSPF"'_H
+#define '"$CAPSPF"'_H' > $header
+
+
+echo "
+// STATIC SECTION" >> $header
+[[ -f init.h ]] && cat init.h >> $header
+
+
+echo "
+// PARTIALS SECTION: AUTOMATICLY GENERATED" >> $header
+# prototypes and macros
+for f in *.c; do
+    [[ "$f" == "init.c" ]] && continue    
+    
+    echo "//--${f::-2}" >> $header
+
+
+    IFS=':'
+    BEGIN=($(grep -b "//HEADER" "$f"))
+    END=($(grep -b "//LIB" "$f"))
+
+    [[ "$BEGIN" ]] || {
+        echo "'//HEADER' was not found in '$f'"
+        exit 1
+    }
+    [[ "$END" ]] || {
+        echo "'//LIB' was not found in '$f'"
+        exit 1
+    }
+    
+    ((LENGTH = END-BEGIN))
+    
+    dd bs=1 count=$LENGTH skip=$BEGIN if="$f" 2>/dev/null | tail -n +2 >> $header
+    
+    echo "
+    " >> $header
+    
+done
+
+
+echo "#endif" >> $header
+
+ok

tools/parts.gen.part.sh

+#!/bin/bash
+
+die(){
+    printf "\e[1;31m[("$(basename "$0")"):ERROR] $1\n\e[0m" 
+    exit 1 
+}
+warn(){
+    printf "\e[1;33m[("$(basename "$0")"):WARNING] $1\n\e[0m" 
+}
+print(){
+    printf "\e[1;37m("$(basename "$0")"):$1\n\e[0m" 
+}
+ok(){
+    [[ "$1" ]] && m="$1" || m='[ok]'
+    printf "\e[1;32m("$(basename "$0")"):$m\n\e[0m" 
+    exit 0
+}
+
+[[ "$(pwd)" == */libsct/modules/*/parts ]] || die "This is not a standard parts path. This script should be run inside the directory that contains the parts: */libsct/modules/*/parts"
+
+# find tool branch
+curdir=$(pwd)
+while true; do
+    cd ..
+    [[ $(basename $(pwd)) == libsct ]] && {
+        PATH=$PATH:"$(pwd)/tools"
+        break
+    }
+    [[ $(basename $(pwd)) == "/" ]] && die "Could not find libsct tool directory"
+done
+cd $curdir
+#done
+
+[[ -f "part.template" ]] || die "'part.template' required but not found"
+[[ "$1" ]] || die "template name required"
+[[ -f "${1,,}.c" ]] && die "${1,,}.c already exists"
+
+name="$1"
+
+cat part.template | sed "s/\[partname\]/$name/g" | sed "s/\[PARTNAME\]/${name^^}/g" > "${1,,}.c"
+
+
+ok

tools/parts.test.sh

+#!/bin/bash
+
+die(){
+    printf "\e[1;31m[("$(basename "$0")"):ERROR] $1\n\e[0m" 
+    exit 1 
+}
+warn(){
+    printf "\e[1;33m[("$(basename "$0")"):WARNING] $1\n\e[0m" 
+}
+print(){
+    printf "\e[1;37m("$(basename "$0")"):$1\n\e[0m" 
+}
+ok(){
+    [[ "$1" ]] && m="$1" || m='[ok]'
+    printf "\e[1;32m("$(basename "$0")"):$m\n\e[0m" 
+    exit 0
+}
+
+[[ "$(pwd)" == */libsct/modules/*/parts ]] || die "This is not a standard parts path. This script should be run inside the directory that contains the parts: */libsct/modules/*/parts"
+
+# find tool branch
+curdir=$(pwd)
+while true; do
+    cd ..
+    [[ $(basename $(pwd)) == libsct ]] && {
+        PATH=$PATH:"$(pwd)/tools"
+        break
+    }
+    [[ $(basename $(pwd)) == "/" ]] && die "Could not find libsct tool directory"
+done
+cd $curdir
+#done
+
+
+
+# generate a common header for inter-dependant parts to compile
+parts.gen.header.sh || die "could not generate header"
+
+# if the first argument is a file, test it only, otherwise test every source file
+if [[ "$1" ]]; then 
+    [[ -f "$1" ]] && list="$1" || warn "'$1' does not exist, cominicng full tests..."
+fi 
+[[ "$list" ]] || list=*.c
+
+
+for f in $list; do
+    [[ "$f" == "init.c" ]] && continue    
+    f="${f::-2}"
+
+    echo "testing '$f.c' (test_$f)"
+    
+    # compile
+    clang -o "$f".test.bin -g -Wall -Wextra -pedantic -std=c1x  -D"test_$f" *.c ../../a/scta.c -I ../../a || die "'$f.c' build error"'!'
+    # fast test
+    ./"$f".test.bin || die "'$f.c' run error"'!'
+    # memcheck (could be merged with fast test, but seperate for now)
+    valgrind --tool=memcheck --leak-check=full --error-exitcode=1 ./"$f".test.bin 2>/dev/null 1>&2 || die "'$f.c' valgrind error"'!'
+    # scan-build?
+    # clang --analyze -o "$f".test.bin -g -Wall -Wextra -pedantic -std=c1x  -D"test_$f" *.c ../../a/scta.c -I ../../a
+        
+done
+ls | grep -E '.test.bin' >/dev/null 2>&1 && rm *.test.bin
+ok