Files
hcie-rust-v3.05/countlines.sh
T
2026-07-09 02:59:53 +03:00

445 lines
18 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ============================================================
# countlines.sh — HCIE-Rust Projesi Satır Sayma Aracı
# ============================================================
# Bu script, projedeki tüm kod dosyalarının satır
# sayılarını dosya tipine göre ayrı ayrı ve toplam
# olarak hesaplar ve detaylı bir rapor dosyasına yazar.
#
# Desteklenen Dosya Tipleri:
# - Rust (.rs)
# - C++ (.cpp, .h)
# - JavaScript (.js)
# - Svelte (.svelte)
# - TypeScript (.ts)
# - Python (.py)
# - HTML (.html)
# - Shell Script (.sh)
# - CSS (.css)
# - JSON (.json)
# - Markdown (.md)
#
# Kullanım: bash countlines.sh
# Çıktı: line_count_report.txt
# ============================================================
# ---- AYARLAR ----
# Projenin ana dizini (bu scriptin bulunduğu yer)
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Raporun yazılacağı dosya
OUTPUT_FILE="line_count_report.txt"
# ---- FONKSİYON: Belirli bir dizindeki, belirli uzantıdaki dosyaların
# toplam satır sayısını hesapla ----
# Kullanım: count_lines "dizin_yolu" "uzantı" ["exclude_pattern"]
# Örnek: count_lines "src" "svelte"
# → src/ altındaki tüm .svelte dosyalarının satır sayısını döndürür
count_lines() {
# $1 = aranacak dizin (parametre 1)
local search_dir="$1"
# $2 = dosya uzantısı (parametre 2), nokta olmadan (örneğin "svelte")
local extension="$2"
# $3 = isteğe bağlı hariç tutma deseni (örneğin "tests" veya "node_modules")
local exclude_pattern="${3:-}"
# find komutu için filtreleri oluştur
local find_cmd=(find "$search_dir" -type f -iname "*.$extension")
# Eğer hariç tutma deseni verilmişse, ekle
if [ -n "$exclude_pattern" ]; then
find_cmd+=(-not -path "*/$exclude_pattern/*")
fi
# find ile dosyaları bul, wc -l ile satır sayısını hesapla
local result
result=$("${find_cmd[@]}" 2>/dev/null \
| xargs wc -l 2>/dev/null \
| tail -1 \
| awk '{print $1}')
# Eğer sonuç boşsa (hiç dosya bulunamadıysa) 0 yaz
if [ -z "$result" ]; then
echo 0
else
echo "$result"
fi
}
# ---- FONKSİYON: Birden fazla dizinde aynı uzantıdaki dosyaları say ----
# Kullanım: count_lines_multi "dizin1" "dizin2" "uzantı" ["exclude_pattern"]
count_lines_multi() {
local total=0
local extension="$3"
local exclude_pattern="${4:-}"
# İlk iki parametre dizinler, geri kalanlar atlanır (extension ve exclude_pattern zaten alındı)
shift 3
for dir in "$@"; do
if [ -d "$dir" ]; then
local lines
lines=$(count_lines "$dir" "$extension" "$exclude_pattern")
total=$((total + lines))
fi
done
echo "$total"
}
# ---- RAPOR DOSYASINI SIFIRLA (üzerine yaz) ----
echo "=========================================" > "$OUTPUT_FILE"
echo "SATIR SAYISI RAPORU" >> "$OUTPUT_FILE"
echo "Proje: HCIE-Rust v4" >> "$OUTPUT_FILE"
echo "Konum: $PROJECT_DIR" >> "$OUTPUT_FILE"
echo "Tarih: $(date '+%Y-%m-%d %H:%M:%S')" >> "$OUTPUT_FILE"
echo "=========================================" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 1. RUST DOSYALARI (.rs)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " RUST (.rs) — hcie-* dizinleri (her paket)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
# Proje kök dizinindeki hcie-* dizinleri (her bir Rust paketi) için döngü
grand_total_rust=0
for dir in "$PROJECT_DIR"/hcie-*/; do
# Dizinin sadece adını al (örneğin "hcie-protocol")
crate_name=$(basename "$dir")
# Bu crate içindeki tüm .rs dosyalarının satır sayısını hesapla
# (test dosyalarını sayma: */tests/* ve test_* ile başlayanları atla)
lines=$(find "$dir" -type f -name '*.rs' \
-not -path '*/tests/*' \
-not -name 'test_*' \
-not -name '*.rs.bak' \
2>/dev/null \
| xargs wc -l 2>/dev/null \
| tail -1 \
| awk '{print $1}')
# Eğer satır sayısı boş değilse (yani dosya varsa) ekrana ve dosyaya yaz
if [ -n "$lines" ] && [ "$lines" -gt 0 ] 2>/dev/null; then
# printf: formatlı yazdırma
# %-25s → sola yaslı 25 karakter (paket adı)
# %6s → sağa yaslı 6 karakter (satır sayısı)
printf " %-25s %6s satır\n" "$crate_name" "$lines" | tee -a "$OUTPUT_FILE"
grand_total_rust=$((grand_total_rust + lines))
fi
done
# Rust toplamını yaz
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM RUST:" "$grand_total_rust" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 2. C++ VE HEADER DOSYALARI (.cpp, .h)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " C++ / HEADER (.cpp, .h)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_cpp=0
# C++ dosyaları (build dizini hariç)
if [ -d "$PROJECT_DIR/hcie-qt-app/src" ]; then
cpp_lines=$(count_lines "$PROJECT_DIR/hcie-qt-app/src" "cpp" "build")
h_lines=$(count_lines "$PROJECT_DIR/hcie-qt-app/src" "h" "build")
printf " %-25s %6s satır\n" "hcie-qt-app/src/*.cpp" "$cpp_lines" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "hcie-qt-app/src/*.h" "$h_lines" | tee -a "$OUTPUT_FILE"
grand_total_cpp=$((cpp_lines + h_lines))
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM C++ / HEADER:" "$grand_total_cpp" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 3. JAVASCRIPT DOSYALARI (.js)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " JAVASCRIPT (.js)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_js=0
# Tauri frontend JavaScript dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app/src" ]; then
js_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app/src" "js" "node_modules")
printf " %-25s %6s satır\n" "hcie-tauri-app/src/" "$js_lines" | tee -a "$OUTPUT_FILE"
grand_total_js=$((grand_total_js + js_lines))
fi
# _tools klasöründeki JavaScript dosyaları
if [ -d "$PROJECT_DIR/_tools" ]; then
js_tools_lines=$(count_lines "$PROJECT_DIR/_tools" "js")
if [ "$js_tools_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "_tools/" "$js_tools_lines" | tee -a "$OUTPUT_FILE"
grand_total_js=$((grand_total_js + js_tools_lines))
fi
fi
# hcie-egui-app plugins klasöründeki JavaScript dosyaları
if [ -d "$PROJECT_DIR/hcie-egui-app/plugins" ]; then
js_plugins_lines=$(count_lines "$PROJECT_DIR/hcie-egui-app/plugins" "js")
if [ "$js_plugins_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-egui-app/plugins/" "$js_plugins_lines" | tee -a "$OUTPUT_FILE"
grand_total_js=$((grand_total_js + js_plugins_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM JAVASCRIPT:" "$grand_total_js" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 4. SVELTE DOSYALARI (.svelte)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " SVELTE (.svelte)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_svelte=0
# Tauri frontend Svelte dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app/src" ]; then
svelte_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app/src" "svelte" "node_modules")
if [ "$svelte_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-tauri-app/src/" "$svelte_lines" | tee -a "$OUTPUT_FILE"
grand_total_svelte=$((grand_total_svelte + svelte_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM SVELTE:" "$grand_total_svelte" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 5. TYPESCRIPT DOSYALARI (.ts)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " TYPESCRIPT (.ts)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_ts=0
# Tauri frontend TypeScript dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app/src" ]; then
ts_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app/src" "ts" "node_modules")
if [ "$ts_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-tauri-app/src/" "$ts_lines" | tee -a "$OUTPUT_FILE"
grand_total_ts=$((grand_total_ts + ts_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM TYPESCRIPT:" "$grand_total_ts" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 6. PYTHON DOSYALARI (.py)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " PYTHON (.py)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_python=0
# _tools klasöründeki Python dosyaları
if [ -d "$PROJECT_DIR/_tools" ]; then
py_tools_lines=$(count_lines "$PROJECT_DIR/_tools" "py")
if [ "$py_tools_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "_tools/" "$py_tools_lines" | tee -a "$OUTPUT_FILE"
grand_total_python=$((grand_total_python + py_tools_lines))
fi
fi
# logs klasöründeki Python dosyaları
if [ -d "$PROJECT_DIR/logs" ]; then
py_logs_lines=$(count_lines "$PROJECT_DIR/logs" "py")
if [ "$py_logs_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "logs/" "$py_logs_lines" | tee -a "$OUTPUT_FILE"
grand_total_python=$((grand_total_python + py_logs_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM PYTHON:" "$grand_total_python" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 7. HTML DOSYALARI (.html)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " HTML (.html)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_html=0
# Tauri frontend HTML dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app/src" ]; then
html_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app/src" "html" "node_modules")
if [ "$html_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-tauri-app/src/" "$html_lines" | tee -a "$OUTPUT_FILE"
grand_total_html=$((grand_total_html + html_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM HTML:" "$grand_total_html" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 8. CSS DOSYALARI (.css)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " CSS (.css)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_css=0
# Tauri frontend CSS dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app/src" ]; then
css_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app/src" "css" "node_modules")
if [ "$css_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-tauri-app/src/" "$css_lines" | tee -a "$OUTPUT_FILE"
grand_total_css=$((grand_total_css + css_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM CSS:" "$grand_total_css" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 9. SHELL SCRIPT DOSYALARI (.sh)
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " SHELL SCRIPT (.sh)" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_shell=0
# Kök dizindeki shell scriptler
sh_root_lines=$(count_lines "$PROJECT_DIR" "sh" ".git")
if [ "$sh_root_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "(kök dizin)" "$sh_root_lines" | tee -a "$OUTPUT_FILE"
grand_total_shell=$((grand_total_shell + sh_root_lines))
fi
# logs klasöründeki shell scriptler
if [ -d "$PROJECT_DIR/logs" ]; then
sh_logs_lines=$(count_lines "$PROJECT_DIR/logs" "sh")
if [ "$sh_logs_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "logs/" "$sh_logs_lines" | tee -a "$OUTPUT_FILE"
grand_total_shell=$((grand_total_shell + sh_logs_lines))
fi
fi
# tools klasöründeki shell scriptler
if [ -d "$PROJECT_DIR/tools" ]; then
sh_tools_lines=$(count_lines "$PROJECT_DIR/tools" "sh")
if [ "$sh_tools_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "tools/" "$sh_tools_lines" | tee -a "$OUTPUT_FILE"
grand_total_shell=$((grand_total_shell + sh_tools_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM SHELL:" "$grand_total_shell" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 10. DOKÜMANTASYON / VERİ DOSYALARI
# ============================================================
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
echo " DOKÜMANTASYON / VERİ DOSYALARI" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
# JSON dosyaları
echo "" >> "$OUTPUT_FILE"
echo " JSON (.json)" | tee -a "$OUTPUT_FILE"
echo " --------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_json=0
# Kök dizindeki JSON dosyaları (package.json, Cargo.toml, vs.)
json_root_lines=$(count_lines "$PROJECT_DIR" "json" ".git")
if [ "$json_root_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "(kök dizin)" "$json_root_lines" | tee -a "$OUTPUT_FILE"
grand_total_json=$((grand_total_json + json_root_lines))
fi
# hcie-tauri-app klasöründeki JSON dosyaları
if [ -d "$PROJECT_DIR/hcie-tauri-app" ]; then
json_tauri_lines=$(count_lines "$PROJECT_DIR/hcie-tauri-app" "json" "node_modules")
if [ "$json_tauri_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "hcie-tauri-app/" "$json_tauri_lines" | tee -a "$OUTPUT_FILE"
grand_total_json=$((grand_total_json + json_tauri_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM JSON:" "$grand_total_json" | tee -a "$OUTPUT_FILE"
# Markdown dosyaları
echo "" >> "$OUTPUT_FILE"
echo " MARKDOWN (.md)" | tee -a "$OUTPUT_FILE"
echo " --------------------------------" | tee -a "$OUTPUT_FILE"
grand_total_md=0
# Kök dizindeki markdown dosyaları
md_root_lines=$(count_lines "$PROJECT_DIR" "md" ".git")
if [ "$md_root_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "(kök dizin)" "$md_root_lines" | tee -a "$OUTPUT_FILE"
grand_total_md=$((grand_total_md + md_root_lines))
fi
# crates klasöründeki markdown dosyaları
if [ -d "$PROJECT_DIR/crates" ]; then
md_crates_lines=$(count_lines "$PROJECT_DIR/crates" "md")
if [ "$md_crates_lines" -gt 0 ] 2>/dev/null; then
printf " %-25s %6s satır\n" "crates/" "$md_crates_lines" | tee -a "$OUTPUT_FILE"
grand_total_md=$((grand_total_md + md_crates_lines))
fi
fi
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TOPLAM MARKDOWN:" "$grand_total_md" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# ============================================================
# 11. GRAND TOTAL (KOD SATIRLARI TOPLAMI)
# Sadece kod dosyalarının satır sayılarını topla
# ============================================================
grand_total=$((grand_total_rust + grand_total_cpp + grand_total_js + grand_total_svelte + grand_total_ts + grand_total_python + grand_total_html + grand_total_css + grand_total_shell))
echo "=========================================" | tee -a "$OUTPUT_FILE"
echo " KOD SATIRLARI TOPLAMI (GRAND TOTAL)" | tee -a "$OUTPUT_FILE"
echo "=========================================" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "Rust:" "$grand_total_rust" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "C++ / Header:" "$grand_total_cpp" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "JavaScript:" "$grand_total_js" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "Svelte:" "$grand_total_svelte" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "TypeScript:" "$grand_total_ts" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "Python:" "$grand_total_python" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "HTML:" "$grand_total_html" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "CSS:" "$grand_total_css" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "Shell Script:" "$grand_total_shell" | tee -a "$OUTPUT_FILE"
echo "-----------------------------------------" | tee -a "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "KOD TOPLAMI:" "$grand_total" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
printf " %-25s %6s satır\n" "RUST + C++/H TOPLAMI:" "$((grand_total_rust + grand_total_cpp))" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo " (JSON ve Markdown dosyaları yukarıda ayrı olarak gösterilmiştir)" | tee -a "$OUTPUT_FILE"
echo "=========================================" | tee -a "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Rapor dosyaya kaydedildi: $(realpath "$OUTPUT_FILE")" | tee -a "$OUTPUT_FILE"