]> git.rmz.io Git - dotfiles.git/commitdiff
bin: mkcomponent to create .hpp/.cpp/.t.cpp component triplet
authorSamir Benmendil <me@rmz.io>
Thu, 9 Jun 2022 12:17:32 +0000 (13:17 +0100)
committerSamir Benmendil <me@rmz.io>
Thu, 9 Jun 2022 12:17:32 +0000 (13:17 +0100)
This currently includes the FPP copyright but can be changed easily in
future.

bin/mkcomponent [new file with mode: 0755]

diff --git a/bin/mkcomponent b/bin/mkcomponent
new file mode 100755 (executable)
index 0000000..9f3a833
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+version="0.1"
+
+function usage ()
+{
+    echo "Usage :  $0 [options]
+
+    Create a header/source/test triplet.
+
+    Options:
+    -h,--help       Display this message
+    -v,--version    Display script version"
+}
+
+# Parse arguments
+declare -a args
+while [[ $# -gt 0 ]]; do
+    opt="$1"
+
+    case $opt in
+        -h|--help)     usage; exit 0 ;;
+        -v|--version)  echo "$0 -- Version $version"; exit 0 ;;
+        -* )
+            echo -e "\n  Option does not exist : $opt\n"
+            usage; exit 1 ;;
+
+        *) args+=("$opt"); shift ;;
+    esac
+done
+
+read -d '' fpp_copy <<EOD
+// Copyright © Focal Point Positioning Limited 2022. All Rights Reserved.
+// This code is the copyright of Focal Point Positioning Limited and
+// cannot be used, copied or distributed without the express written
+// permission of Focal Point Positioning Limited.
+EOD
+
+_h=${COMPONENT_HEADER_SUFFIX:-.hpp}
+_c=${COMPONENT_SOURCE_SUFFIX:-.cpp}
+_t=${COMPONENT_TEST_SUFFIX:-.t.cpp}
+
+for f in "${args[@]}"; do
+    c=$(basename $f)
+    printf '%s\n\n#pragma once\n\n' "$fpp_copy" > $f$_h
+    printf '%s\n\n#include "%s"\n\n' "$fpp_copy" "$c$_h" > $f$_c
+    printf '%s\n\n#include <gtest/gtest.h>\n\n#include "%s"\n' "$fpp_copy" "$c$_h" > $f$_t
+done