feature/max abgeschlossen

- Verzeichnistiefe und maximale Anzahl an Dateien über Parameter steuerbar
 - weitere Features implementiert wie Laufzeitmessung
This commit is contained in:
Adam Skotarczak 2025-05-14 22:34:13 +02:00
parent 7dd51d3ebd
commit fc219ceac1
Signed by: realAscot
GPG Key ID: 4CB9B8D93A96A538
12 changed files with 198 additions and 94 deletions

View File

@ -1,6 +1,17 @@
# Changelog: treeScanner.exe
- **11-05-25 - v1.0.1** [UNCOMMITET]
- **2025-05-14 - v1.1.0**
- **Hinzugefügt:**
- [x] Laufzeitmessung per `GetTickCount64()` in `main.c`
- [x] Ausgabe der Gesamtzeit in Millisekunden nach Scanabschluss
- [x] `scanner_config.h/.c` mit `ScannerConfig`-Struktur für zentrale Parameterverwaltung
- [x] CLI-Parameter `--depth` für maximale Verzeichnistiefe (`main.c`)
- [x] CLI-Parameter `--limit` für max. Dateien pro Verzeichnis (`main.c`)
- [x] Erweiterung von `scan_directory()` zur Einhaltung der Limits (`app.c`)
- [x] Neue Funktionssignatur in `app.h`: Übergabe der Konfiguration
- **2025-05-11 - v1.0.1**
- [x] `favicon.ico` erstellt und hinzugefügt
- [X] `desktop.ini` erstellt
- [x] `version.rc`erstellt und `build.cmd`entsprechend angepasst das Metadaten compiliert werden

View File

@ -1,32 +1,39 @@
# Haupt-Makefile
# Makefile Buildsystem für scanner.exe unter MSVC
# Aufruf über build.cmd (ruft vcvars64.bat auf) → dann make
# Zentrale Konfiguration laden
include Makefile.config
# Wenn DEBUG=1 gesetzt ist: zusätzliche Flags anhängen
ifeq ($(DEBUG),1)
CFLAGS = $(BASE_CFLAGS) /Zi /Od /DDEBUG
LDFLAGS = $(BASE_LDFLAGS) /DEBUG /PDB:$(OUTDIR)\scanner.pdb
else
CFLAGS = $(BASE_CFLAGS) /O2
LDFLAGS = $(BASE_LDFLAGS)
endif
# Standardziel
all: $(EXE)
# ---- Kompilieren der Quellcodedateien ----
# main.c → main.obj
$(OUTDIR)\main.obj: $(SRCDIR)\main.c
@if not exist $(OUTDIR) mkdir $(OUTDIR)
$(CC) $(CFLAGS) /c /Fo:$@ $<
# app.c → app.obj
$(OUTDIR)\app.obj: $(SRCDIR)\app.c
$(CC) $(CFLAGS) /c /Fo:$@ $<
# scanner_config.c → scanner_config.obj
$(OUTDIR)\scanner_config.obj: $(SRCDIR)\scanner_config.c
$(CC) $(CFLAGS) /c /Fo:$@ $<
# Ressourcen-Datei → version.res
$(RES): $(RESDIR)\version.rc
$(RC) /nologo /fo $@ $<
# ---- Linken der Executable ----
# Alle Objektdateien + Ressourcen → scanner.exe
$(EXE): $(OBJ) $(RES)
$(LINK) $(LDFLAGS) $(OBJ) $(RES)
# ---- Aufräumen ----
clean:
@if exist $(OUTDIR) del /Q $(OUTDIR)\*.*
@if exist vc140.pdb del vc140.pdb

View File

@ -1,21 +1,30 @@
# Makefile.config zentrale Konfigurationsdatei für MSVC-Build
# Toolchain
# Makefile.config zentrale Buildkonfiguration
# Tools
CC = cl
RC = rc
LINK = link.exe
# Pfade
OUTDIR = build\output
INCLUDEDIR = include
# Verzeichnisse
SRCDIR = src
RESDIR = resources
OUTDIR = build\output
INCLUDEDIR = include
# Source-Dateien
SRC = $(SRCDIR)\main.c $(SRCDIR)\app.c
OBJ = $(OUTDIR)\main.obj $(OUTDIR)\app.obj
# Flags
BASE_CFLAGS = /nologo /W4 /I $(INCLUDEDIR)
BASE_LDFLAGS = /nologo /SUBSYSTEM:CONSOLE /OUT:$(OUTDIR)\scanner.exe
# Debug-abhängige Erweiterungen
ifeq ($(DEBUG),1)
CFLAGS = $(BASE_CFLAGS) /Zi /Od /DDEBUG
LDFLAGS = $(BASE_LDFLAGS) /DEBUG /PDB:$(OUTDIR)\scanner.pdb
else
CFLAGS = $(BASE_CFLAGS) /O2
LDFLAGS = $(BASE_LDFLAGS)
endif
# Quell- und Ausgabedateien
OBJ = $(OUTDIR)\main.obj $(OUTDIR)\app.obj $(OUTDIR)\scanner_config.obj
RES = $(OUTDIR)\version.res
EXE = $(OUTDIR)\scanner.exe
# Standard-Flags (werden dynamisch erweitert)
BASE_CFLAGS = /nologo /I $(INCLUDEDIR)
BASE_LDFLAGS = /nologo /SUBSYSTEM:CONSOLE /OUT:$(EXE)

140
README.md
View File

@ -1,5 +1,7 @@
# ⚙️ CLI-Template für C (MSVC)
![TreeScanner-Logo](./media/logo-alpha-512x512.png)
Ein leichtgewichtiges C-Projekttemplate für die Kommandozeile unter Windows, vorbereitet für den Microsoft Visual C Compiler (MSVC).
## Inhalt
@ -9,19 +11,28 @@ Ein leichtgewichtiges C-Projekttemplate für die Kommandozeile unter Windows, vo
- [Features](#features)
- [Struktur](#struktur)
- [Voraussetzungen](#voraussetzungen)
- [Compiler (MSVC)](#compiler-msvc)
- [Make (empfohlen: MSYS2)](#make-empfohlen-msys2)
- [Nutzung](#nutzung)
- [Build](#build)
- [Optionen](#optionen)
- [Dokumentation](#dokumentation)
- [Plattformhinweis](#plattformhinweis)
- [Geplante Features](#geplante-features)
- [Lizenz](#lizenz)
---
## Features
- Rekursive Verzeichnissuche mit ASCII-Ausgabe
- Kompatibel mit `cl.exe` über `build.cmd`
- Debugging per `launch.json` (VS Code)
- Unicode-Ausgabe (📁 📄) für unterstützende Terminals
- Struktur für sauberen Code (main + Module)
- Rekursive Verzeichnissuche mit Unicode-Symbolen (📁 📄)
- Optionale Tiefenbegrenzung via `--depth N`
- Limitierung der Dateiausgabe pro Verzeichnis via `--limit N`
- Unicode-fähige Konsolenausgabe auf Windows (`SetConsoleOutputCP`)
- Debugging vorbereitet via `launch.json` (VS Code)
- Sauber modularisierter Code (main + Module + Config)
- MSVC-kompatibles Buildsystem (`cl.exe` + `rc.exe` + `link.exe`)
- Unterstützt `Makefile` + `Makefile.config` für Debug/Release
[](#inhalt)
@ -29,39 +40,29 @@ Ein leichtgewichtiges C-Projekttemplate für die Kommandozeile unter Windows, vo
## Struktur
Alle notwendigen Verzeichnisse und Dateien wurden mit ✅ markiert, diese sind unverzichtbar für das Projekt.
Ohne diese, ist ein compilieren nicht möglich.
Dateien und Verzeichnisse die mit ❌ markiert wurden, können theoretisch gelöscht werden und für den Buildprozess nicht notwendig.
Alle notwendigen Verzeichnisse und Dateien wurden mit ✅ markiert, diese sind unverzichtbar für den Buildprozess.
❌ markiert alles, was optional ist oder ignoriert werden kann.
```plaintext
📁 treescanner # Projekt-Wurzelverzeichnis (Repository-Root)
📁 .vscode # ❌ Konfigurationsverzeichnis für Visual Studio Code
📄 c_cpp_properties.json # ❌ IntelliSense-Einstellungen (Compilerpfade, Defines etc.)
📄 extensions.json # ❌ Empfehlung installierbarer VS Code Extensions
📄 launch.json # ❌ Debug-Konfiguration (z.B. Programm, Argumente, Terminal)
📄 settings.json # ❌ Editor-spezifische Projekteinstellungen (z.B. Tabs, Formatierung)
📄 tasks.json # ❌ Build-Tasks (z.B. MSVC Build über build.cmd)
📁 build # ✅ Build-Artefakte (ausgabeorientiertes Verzeichnis)
📄 .gitkeep # ❌ Platzhalterdatei, damit Git leere Verzeichnisse behält
📁 output # ✅ Output-Ordner für kompilierte Binärdateien und Objekte
📄 app.obj # ❌ Objektdatei aus app.c
📄 main.obj # ❌ Objektdatei aus main.c
📄 treescanner.exe # ❌ Kompilierte lauffähige .exe-Datei
📁 doc # ❌ Dokumentation und Templates
📁 media # ❌ Dateien für GitHub und Dokumentation
📁 resources # ✅ Dateien die zum compilieren benötigt werden (Icon, Metadaten etc.)
📁 include # ✅ Header-Dateien für Funktionsprototypen
📄 app.h # ✅ Deklaration von `scan_directory()`
📄 LICENSE # ❌ Lizenzdatei (hier: MIT License)
📄 README.md # ❌ Projektdokumentation (Nutzung, Build, Features etc.)
📁 src # ✅ Quellcode-Verzeichnis (.c-Dateien)
📄 app.c # ✅ Implementierung der rekursiven Verzeichnissuche
📄 main.c # ✅ Einstiegspunkt (main-Funktion)
📄 VERSION # ❌ Datei mit Versionsnummer (z.B. „0.1.0-dev“)
📄 .gitattributes # ❌ Git-spezifische Datei (z.B. Zeilenenden, Binärdateien, Sprache)
📄 .gitignore # ❌ Liste auszuschließender Dateien und Verzeichnisse (z.B. *.exe, /build/)
📄 build.cmd # ✅ Build-Skript für MSVC (ruft cl.exe via vcvars64.bat)
📄 clean.cmd # ❌ Hilfsskript zum Löschen von build/output
📁 treescanner
📁 .vscode # ❌ VS Code-Konfiguration (Debug, Build, Editor-Style)
📄 launch.json # ❌ Debug-Konfiguration (z.B. scanner.exe + Breakpoints)
📄 tasks.json # ❌ Build-Task für Make unter Windows
📁 build # ✅ Buildverzeichnis
📁 output # ✅ Kompilierte .exe und .obj-Dateien
📁 include # ✅ Header-Dateien
📄 app.h # ✅ Schnittstelle für scan_directory()
📄 scanner_config.h # ✅ Konfiguration für Tiefen-/Limitsteuerung
📁 resources # ✅ Ressourcen wie version.rc
📄 version.rc # ✅ Icon- und Versionsdefinition
📁 src # ✅ Quellcode (.c-Dateien)
📄 main.c # ✅ Einstiegspunkt mit Argumentverarbeitung
📄 app.c # ✅ rekursiver Verzeichnisscan (Windows API)
📄 scanner_config.c # ✅ Initialisierung und Verwaltung der Konfiguration
📄 build.cmd # ✅ Buildskript (ruft `vcvars64.bat` und `make` auf)
📄 clean.cmd # ✅ Löscht `/build/output` + ggf. `.pdb`
📄 README.md # ❌ Diese Datei
📄 .gitignore # ❌ Ignoriert z.B. *.obj, *.pdb, /build/
```
[](#inhalt)
@ -70,16 +71,14 @@ Dateien und Verzeichnisse die mit ❌ markiert wurden, können theoretisch gelö
## Voraussetzungen
### Compiler
#### MSVC
### Compiler (MSVC)
- [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
- MSVC `cl.exe` + `vcvars64.bat` korrekt eingebunden
- Umgebung wird über `vcvars64.bat` gesetzt
### Make (empfohlen: MSYS2)
- [x] MSYS2 -> <https://www.msys2.org/>
- [x] `make` aus MSYS2 installieren: `pacman -S make`
[](#inhalt)
@ -87,12 +86,27 @@ Dateien und Verzeichnisse die mit ❌ markiert wurden, können theoretisch gelö
## Nutzung
### Build
```cmd
build.cmd
```
**Ausgabe:**
`build/output/scanner.exe`
→ erzeugt `build/output/scanner.exe`
### Optionen
```cmd
scanner.exe [verzeichnis] [--depth N] [--limit N]
```
Beispiele:
```cmd
scanner.exe
scanner.exe "D:\Projekte" --depth 3
scanner.exe . --limit 5
```
[](#inhalt)
@ -100,8 +114,8 @@ build.cmd
## Dokumentation
- [x] [C Code Style Guide für CLI-Projekte](./doc/code_style.md)
- [x] [Windows API Referenz CLI-Toolkit](./doc/index.md)
- [x] [Code Style Guide (C für CLI-Projekte)](./doc/code_style.md)
- [x] [Windows API Referenz](./doc/index.md)
[](#inhalt)
@ -109,9 +123,39 @@ build.cmd
## Plattformhinweis
> Dieses Projekt ist aktuell auf **Windows** ausgelegt (MSVC, Windows API).
> Es enthält jedoch bereits `#ifdef _WIN32`-Konstrukte zur Vorbereitung einer plattformübergreifenden Umsetzung.
> Die POSIX-Version (`opendir`, `readdir`) kann später leicht ergänzt werden.
> Aktuell ausschließlich für **Windows** (MSVC / WinAPI) vorgesehen.
> POSIX-Implementierung (`opendir`, `readdir`) ist vorbereitet aber nicht aktiv.
[](#inhalt)
---
## Geplante Features
| Funktion / Option | Beschreibung | Status |
| -------------------------- | --------------------------------------------------------------- | ------------- |
| `--depth N` | Maximale Verzeichnistiefe | ✅ Fertig |
| `--limit N` | Max. Dateien pro Verzeichnis | ✅ Fertig |
| `--ignore DIR` | Verzeichnisse ausschließen | ⬜ Geplant |
| `--output FILE` | Ausgabedatei (Standard: `tree.md`) mit `plaintext`-Block | ⬜ Geplant |
| ASCII-Baumstruktur (`├──`) | grafische Darstellung mit Baumzeichen → **Standardmäßig aktiv** | ⬜ Geplant |
| `--no-tree-symbols` | Option zum Deaktivieren der Baumzeichensymbole | ⬜ Geplant |
| `--console` | explizite Konsolenausgabe einschalten | ⬜ Geplant |
| `--align-comments` | Ausrichtung von Kommentaren in Spalte | ⬜ Geplant |
| `--language de/en` | Sprache der Ausgaben und Zusammenfassung | ⬜ Geplant |
| Scan-Zusammenfassung | Ausgabe: `📦 23 Dateien in 5 Ordnern`, ggf. mit Pfad | ⬜ Geplant |
| Fortschrittsanzeige | Zeitgesteuerte Live-Ausgabe | ⬜ Optional |
| POSIX-Kompatibilität | Unterstützung für Linux (`opendir`, `readdir`) | ⬜ Vorbereitet |
| Symbol-Set anpassbar | Benutzerdefinierte Icons (📁, 📄 etc.) | ⬜ Optional |
| Laufzeit erfassen | Zu Benchmarkzwecken Durchlaufzeit erfassen von Start bis Ende | ✅ Fertig |
[](#inhalt)
---
## Lizenz
MIT siehe Datei [LICENSE](./LICENSE)
[](#inhalt)

View File

@ -1 +1 @@
1.0.2
1.1.0

View File

@ -1,6 +1,7 @@
#ifndef APP_H
#define APP_H
#include "scanner_config.h"
/**
* @brief Recursively scans the specified directory and prints an ASCII tree.
*
@ -11,6 +12,6 @@
* @param base_path The root directory to scan
* @param depth Current recursion depth, used for visual indentation
*/
void scan_directory(const char *base_path, int depth);
void scan_directory(const char *path, int depth, const ScannerConfig *config);
#endif
#endif

11
include/scanner_config.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef SCANNER_CONFIG_H
#define SCANNER_CONFIG_H
typedef struct {
int max_depth;
int max_files_per_dir;
} ScannerConfig;
void init_config_defaults(ScannerConfig *config);
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View File

@ -18,7 +18,9 @@
* @param base_path Root path to scan
* @param depth Recursion depth for indentation
*/
void scan_directory(const char *base_path, int depth) {
void scan_directory(const char *base_path, int depth, const ScannerConfig *config) {
if (config->max_depth >= 0 && depth > config->max_depth)
return;
#ifdef _WIN32
WIN32_FIND_DATA find_data;
char search_path[MAX_PATH];
@ -31,6 +33,8 @@ void scan_directory(const char *base_path, int depth) {
return;
}
int file_count = 0;
do {
const char *name = find_data.cFileName;
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
@ -41,8 +45,11 @@ void scan_directory(const char *base_path, int depth) {
printf("📁 %s\n", name);
char sub_path[MAX_PATH];
snprintf(sub_path, MAX_PATH, "%s\\%s", base_path, name);
scan_directory(sub_path, depth + 1);
scan_directory(sub_path, depth + 1, config);
} else {
if (config->max_files_per_dir >= 0 && file_count >= config->max_files_per_dir)
continue;
file_count++;
printf("📄 %s\n", name);
}

View File

@ -1,28 +1,36 @@
#ifdef _WIN32
#include <windows.h>
#endif
#include <windows.h> // hinzugefügt für GetTickCount64
#include <stdio.h>
#include <string.h>
#include "app.h"
#include "scanner_config.h"
/**
* @brief Entry point of the CLI tool.
*
* Initializes UTF-8 output on Windows, then calls scan_directory()
* with the provided argument or current directory.
*
* @param argc Number of arguments
* @param argv Array of argument strings
* @return int Exit status
*/
int main(int argc, char *argv[]) {
#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8); // Enable Unicode output on Windows
SetConsoleOutputCP(CP_UTF8);
#endif
printf("[INFO] 🔍 CLI Tool gestartet\n");
ScannerConfig config;
init_config_defaults(&config);
const char *pfad = (argc > 1) ? argv[1] : ".";
scan_directory(pfad, 0);
const char *pfad = ".";
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--depth") == 0 && i + 1 < argc)
config.max_depth = atoi(argv[++i]);
else if (strcmp(argv[i], "--limit") == 0 && i + 1 < argc)
config.max_files_per_dir = atoi(argv[++i]);
else
pfad = argv[i];
}
printf("\n[] 🔍 CLI Tool gestartet\n\n");
ULONGLONG start_ms = GetTickCount64();
scan_directory(pfad, 0, &config);
ULONGLONG end_ms = GetTickCount64();
printf("\n[] ⌛ Laufzeit des Scans: %llu ms\n\n", end_ms - start_ms);
return 0;
}

6
src/scanner_config.c Normal file
View File

@ -0,0 +1,6 @@
#include "scanner_config.h"
void init_config_defaults(ScannerConfig *config) {
config->max_depth = -1; // unbegrenzt
config->max_files_per_dir = -1; // unbegrenzt
}