From 1e2cc5ef162f81eeefc4790ef75d3c55c26b0984 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sat, 20 Sep 2025 19:57:13 -0400 Subject: [PATCH] scripts: Add sloc --- scripts/count-lines-simple.sh | 20 ++++++++ scripts/count-lines.sh | 90 +++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100755 scripts/count-lines-simple.sh create mode 100755 scripts/count-lines.sh diff --git a/scripts/count-lines-simple.sh b/scripts/count-lines-simple.sh new file mode 100755 index 0000000..5c233da --- /dev/null +++ b/scripts/count-lines-simple.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Simple script to show just the C/C++ line count summary + +# Change to project root directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +cd "$PROJECT_ROOT" + +# Count lines +CPP_LINES=$(find . -name "*.cpp" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}' || echo "0") +H_LINES=$(find . -name "*.h" -o -name "*.hpp" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}' || echo "0") +C_LINES=$(find . -name "*.c" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}' || echo "0") + +TOTAL=$((CPP_LINES + H_LINES + C_LINES)) + +echo "Salmanoff Project C/C++ Lines: $TOTAL" +echo " C++ Source: $CPP_LINES" +echo " Headers: $H_LINES" +echo " C Source: $C_LINES" diff --git a/scripts/count-lines.sh b/scripts/count-lines.sh new file mode 100755 index 0000000..c4135cb --- /dev/null +++ b/scripts/count-lines.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Script to count C/C++ lines of code in the salmanoff project +# Excludes third-party dependencies, build artifacts, and generated files + +# set -e # Commented out to prevent early exit on empty file lists + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${BLUE}=== Salmanoff Project C/C++ Line Count ===${NC}" +echo + +# Change to project root directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +cd "$PROJECT_ROOT" + +echo -e "${YELLOW}Project root: $PROJECT_ROOT${NC}" +echo + +# Find all C/C++ files, excluding third-party and build artifacts +CPP_FILES=$(find . -name "*.cpp" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles) +H_FILES=$(find . -name "*.h" -o -name "*.hpp" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles) +C_FILES=$(find . -name "*.c" | grep -v third_party | grep -v build | grep -v b/ | grep -v "Livox-sdk-git" | grep -v CMakeFiles) + +# Count lines for each file type +echo -e "${BLUE}=== C++ Source Files (.cpp) ===${NC}" +CPP_LINES=0 +if [ -n "$CPP_FILES" ]; then + echo "$CPP_FILES" | xargs wc -l + CPP_LINES=$(echo "$CPP_FILES" | xargs wc -l | tail -1 | awk '{print $1}') +else + echo "No C++ source files found" +fi +echo + +echo -e "${BLUE}=== Header Files (.h, .hpp) ===${NC}" +H_LINES=0 +if [ -n "$H_FILES" ]; then + echo "$H_FILES" | xargs wc -l + H_LINES=$(echo "$H_FILES" | xargs wc -l | tail -1 | awk '{print $1}') +else + echo "No header files found" +fi +echo + +echo -e "${BLUE}=== C Source Files (.c) ===${NC}" +C_LINES=0 +if [ -n "$C_FILES" ]; then + echo "$C_FILES" | xargs wc -l + C_LINES=$(echo "$C_FILES" | xargs wc -l | tail -1 | awk '{print $1}') +else + echo "No C source files found" +fi +echo + +# Calculate total +TOTAL_LINES=$((CPP_LINES + H_LINES + C_LINES)) + +echo -e "${GREEN}=== SUMMARY ===${NC}" +echo -e "C++ Source Files (.cpp): ${YELLOW}$CPP_LINES${NC} lines" +echo -e "Header Files (.h/.hpp): ${YELLOW}$H_LINES${NC} lines" +echo -e "C Source Files (.c): ${YELLOW}$C_LINES${NC} lines" +echo -e "${GREEN}─────────────────────────${NC}" +echo -e "${GREEN}Total C/C++ Lines: ${YELLOW}$TOTAL_LINES${NC} lines${NC}" +echo + +# Show what's excluded +echo -e "${BLUE}=== Excluded from count: ===${NC}" +echo "• third_party/ directory (googletest, etc.)" +echo "• build*/ directories (build artifacts)" +echo "• b/ directories (build artifacts)" +echo "• Livox-sdk-git/ directory (third-party SDK)" +echo "• CMakeFiles/ directories (generated files)" +echo "• Generated files (*.d, *.o, etc.)" +echo + +# Optional: Show file count breakdown by directory +echo -e "${BLUE}=== Files by directory: ===${NC}" +echo "C++ Source Files:" +echo "$CPP_FILES" | sed 's|^\./||' | cut -d'/' -f1 | sort | uniq -c | sort -nr | head -10 + +echo +echo "Header Files:" +echo "$H_FILES" | sed 's|^\./||' | cut -d'/' -f1 | sort | uniq -c | sort -nr | head -10