diff --git a/clip-sanitizer.sh b/clip-sanitizer.sh deleted file mode 120000 index 3249fbe..0000000 --- a/clip-sanitizer.sh +++ /dev/null @@ -1 +0,0 @@ -/home/kof/.local/bin/clip-sanitizer.sh \ No newline at end of file diff --git a/clip-sanitizer.sh b/clip-sanitizer.sh new file mode 100755 index 0000000..277cbb9 --- /dev/null +++ b/clip-sanitizer.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +while clipnotify; do + # Grab what was just copied + current_content=$(xclip -selection clipboard -o 2>/dev/null) + + if [[ -n "$current_content" ]]; then + # Nuke NBSP (c2 a0) and ZWSP (e2 80 8b) + sanitized=$(echo -n "$current_content" | sed 's/\xc2\xa0/ /g; s/\xe2\x80\x8b//g') + + # Guard: Only write back if a cheesy space was actually destroyed + # This prevents an infinite event loop + if [[ "$current_content" != "$sanitized" ]]; then + echo -n "$sanitized" | xclip -selection clipboard -i + fi + fi +done diff --git a/dh b/dh deleted file mode 120000 index ce2d5c9..0000000 --- a/dh +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/metricTime/dh \ No newline at end of file diff --git a/dh b/dh new file mode 100755 index 0000000..8a4f7c3 Binary files /dev/null and b/dh differ diff --git a/mpdplayer b/mpdplayer deleted file mode 120000 index e1b77df..0000000 --- a/mpdplayer +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/player/mpdplayer \ No newline at end of file diff --git a/mpdplayer b/mpdplayer new file mode 100755 index 0000000..0851c56 Binary files /dev/null and b/mpdplayer differ diff --git a/pde2c b/pde2c deleted file mode 120000 index a05a50c..0000000 --- a/pde2c +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/RaylibProcessing/pde2c \ No newline at end of file diff --git a/pde2c b/pde2c new file mode 100755 index 0000000..251c3f1 Binary files /dev/null and b/pde2c differ diff --git a/pdecc b/pdecc deleted file mode 120000 index 2509a61..0000000 --- a/pdecc +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/RaylibProcessing/pdecc \ No newline at end of file diff --git a/pdecc b/pdecc new file mode 100755 index 0000000..d129edb --- /dev/null +++ b/pdecc @@ -0,0 +1,129 @@ +#!/bin/sh +# pdecc — one-shot Processing-to-Raylib compiler CLI. +# +# Transpile + compile a .pde sketch into an optimized native binary in one +# step, using the pde2c transpiler and the processing.h single-header runtime. +# Submitted as a single source file or a sketch directory (multi-tab), the +# resulting binary is written next to the sketch source by default. +# +# ./pdecc sketch in current directory +# ./pdecc sketch.pde single-file sketch +# ./pdecc ~/path/to/sketch sketch directory (all .pde tabs together) +# ./pdecc -o bin sketch.pde write binary to "bin" instead +# ./pdecc -O0 sketch.pde override default -O2 optimization +# ./pdecc -n sketch.pde build only (do not run) +# ./pdecc --keep sketch.pde keep the tmp build dir +# +# Exit status: 0 on success, non-zero on transpile/compile failure. +set -u + +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") + +OPT="2" # default optimization level (no leading 'O') +OUT="" # explicit -o output path (default: next to source) +RUN=1 # run after building unless -n +KEEP=0 # keep tmp dir when --keep + +# ---- argument parsing ----------------------------------------------------- +TARGET="" +while [ $# -gt 0 ]; do + case "$1" in + -o) shift; [ $# -eq 0 ] && { echo "pdecc: -o needs a path" >&2; exit 1; } + OUT="$1";; + -O|-O0|-O1|-O2|-O3|-Os) OPT="${1#-O}";; + -n|--no-run) RUN=0;; + --keep) KEEP=1;; + -h|--help) + sed -n '2,16p' "$0"; exit 0;; + -*) echo "pdecc: unknown option: $1" >&2; exit 1;; + *) [ -n "$TARGET" ] && { echo "pdecc: too many arguments: $1" >&2; exit 1; } + TARGET="$1";; + esac + shift +done + +# ---- resolve target: dir, .pde file, or current dir ----------------------- +if [ -z "$TARGET" ]; then + TARGET=$(pwd) +fi +TARGET=$(realpath "$TARGET") + +if [ -d "$TARGET" ]; then + SKETCH_DIR="$TARGET" + MAIN_PDE="$SKETCH_DIR/$(basename "$SKETCH_DIR").pde" + if [ ! -f "$MAIN_PDE" ]; then + echo "pdecc: expected main tab $MAIN_PDE (folder name must match the main .pde)" >&2 + exit 1 + fi + BNAME=$(basename "$SKETCH_DIR") +elif [ -f "$TARGET" ] && [ "${TARGET##*.}" = "pde" ]; then + MAIN_PDE="$TARGET" + SKETCH_DIR=$(dirname "$MAIN_PDE") + BNAME=$(basename "$MAIN_PDE" .pde) +else + echo "pdecc: invalid target: $TARGET (expected a .pde file or a sketch directory)" >&2 + exit 1 +fi + +OUT="${OUT:-$SKETCH_DIR/$BNAME}" + +# ---- build dir ------------------------------------------------------------- +TMP=$(mktemp -d /tmp/pdecc.XXXXXX) +cleanup() { [ "$KEEP" = "1" ] || rm -rf "$TMP"; } +trap cleanup EXIT INT TERM + +# rebuild transpiler only when its source changed +if [ "$SCRIPT_DIR/pde2c.c" -nt "$SCRIPT_DIR/pde2c" ] || [ ! -x "$SCRIPT_DIR/pde2c" ]; then + gcc "$SCRIPT_DIR/pde2c.c" -o "$SCRIPT_DIR/pde2c" || exit 1 +fi + +# rebuild precompiled header only when processing.h got newer; skip re-parsing +# raylib/rlgl/raymath on every compile (cuts turnaround from ~3s to ~0.2s). +if [ "$SCRIPT_DIR/processing.h" -nt "$SCRIPT_DIR/processing.h.gch" ] || \ + [ ! -f "$SCRIPT_DIR/processing.h.gch" ]; then + if ! gcc $("$SCRIPT_DIR/pdedeps" --includes) -x c-header "$SCRIPT_DIR/processing.h" \ + -o "$SCRIPT_DIR/processing.h.gch" 2>/dev/null; then + rm -f "$SCRIPT_DIR/processing.h.gch" # stale/broken PCH: fall back to + fi # slow path (never fatal) +fi + +# ---- merge tabs: main tab first, then the rest alphabetically ------------- +{ + printf '//@file %s\n' "$(basename "$MAIN_PDE")" + cat "$MAIN_PDE" + for f in $(find "$SKETCH_DIR" -maxdepth 1 -name '*.pde' | sort); do + [ "$f" = "$MAIN_PDE" ] && continue + printf '//@file %s\n' "$(basename "$f")" + cat "$f" + done +} > "$TMP/combined.pde" + +if ! grep -q '[^[:space:]]' "$TMP/combined.pde"; then + echo "pdecc: no .pde content found in $SKETCH_DIR" >&2 + exit 1 +fi + +# copy runtime resources so font loading resolves from the build dir +cp "$SCRIPT_DIR/terminus.ttf" "$TMP/terminus.ttf" 2>/dev/null || true + +# ---- transpile ------------------------------------------------------------- +if ! "$SCRIPT_DIR/pde2c" "$TMP/combined.pde" > "$TMP/sketch.c" 2> "$TMP/pde2c.err"; then + echo "pdecc: transpile failed for $BNAME" >&2 + cat "$TMP/pde2c.err" >&2 + exit 1 +fi + +# ---- compile to an optimized native binary --------------------------------- +if ! gcc -O"$OPT" $("$SCRIPT_DIR/pdedeps" --includes) "$TMP/sketch.c" -o "$OUT" \ + $("$SCRIPT_DIR/pdedeps" --libs) 2> "$TMP/gcc.err"; then + echo "pdecc: compilation failed for $BNAME" >&2 + head -20 "$TMP/gcc.err" >&2 + if [ "$KEEP" = "1" ]; then + echo "pdecc: kept build dir $TMP (set --keep or PDE_KEEP=1 to inspect)" >&2 + fi + exit 1 +fi + +echo "pdecc: built $OUT" +[ "$RUN" = "1" ] && (cd "$SKETCH_DIR" && exec "$OUT") +exit 0 diff --git a/pdeide b/pdeide deleted file mode 120000 index e0f0cfb..0000000 --- a/pdeide +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/RaylibProcessing/pdeide \ No newline at end of file diff --git a/pdeide b/pdeide new file mode 100755 index 0000000..bd5a90d Binary files /dev/null and b/pdeide differ diff --git a/pp2c b/pp2c deleted file mode 120000 index 223b82c..0000000 --- a/pp2c +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/RaylibProcessing/pp2c \ No newline at end of file diff --git a/pp2c b/pp2c new file mode 100755 index 0000000..91bfd95 --- /dev/null +++ b/pp2c @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +set -e # kill if it fails + +# Path to processing.h +PROCESSING_H_PATH="/home/kof/src/RaylibProcessing/processing.h" + +if [ -z "$1" ]; then + TARGET=`pwd` +else + TARGET=$(realpath "$1") +fi + +if [ -d "$TARGET" ]; then + SKETCH_DIR="$TARGET" + SKETCH_NAME=$(basename "$SKETCH_DIR") + MAIN_PDE="$SKETCH_DIR/$SKETCH_NAME.pde" +elif [ -f "$TARGET" ] && [ "${TARGET##*.}" = "pde" ]; then + MAIN_PDE="$TARGET" + SKETCH_DIR=$(dirname "$MAIN_PDE") + SKETCH_NAME=$(basename "$SKETCH_DIR") +else + echo "Error: Invalid target, it has to be sketch folder of .pde file." + exit 1 +fi + +if [ ! -f "$MAIN_PDE" ]; then + echo "Error: Main sketch file should be in the folder of the same name!" + echo "Expected: $SKETCH_DIR/$(basename "$SKETCH_DIR").pde" + exit 1 +fi + +BUILD_DIR=$(mktemp -d -t pde-build.XXXXXX) + +trap 'rm -rf "$BUILD_DIR"' EXIT + +COMBINED_PDE="$BUILD_DIR/combined.pde" +OUTPUT_C="$BUILD_DIR/sketch.c" +BINARY="$BUILD_DIR/$SKETCH_NAME" + +echo "Concating sketch: $SKETCH_NAME" + +cat "$MAIN_PDE" > "$COMBINED_PDE" +echo "" >> "$COMBINED_PDE" # Prevence, pokud chybí newline na konci souboru + +for f in "$SKETCH_DIR"/*.pde; do + if [ -f "$f" ] && [ "$f" != "$MAIN_PDE" ]; then + echo "// --- Tab: $(basename "$f") ---" >> "$COMBINED_PDE" + cat "$f" >> "$COMBINED_PDE" + echo "" >> "$COMBINED_PDE" + fi +done + +# HTML COLOR MASHING +# Přepíše mřížku (#ffcc00) na čistý C hex formát (0xffcc00) přímo v combined.pde +sed -i -E 's/#([0-9a-fA-F]{6})/HEX_COLOR_\1/g' "$COMBINED_PDE" + +# Kopírování headeru do build adresáře +cp "$PROCESSING_H_PATH" "$BUILD_DIR/processing.h" +HEADER_ROOT=$(dirname "$PROCESSING_H_PATH") +cp "$HEADER_ROOT/terminus.ttf" "$BUILD_DIR/terminus.ttf" + +if ! pde2c "$COMBINED_PDE" > "$OUTPUT_C"; then + echo "Error: Transpil failed!" + exit 1 +fi + +# HTML COLOR MASHING - Fáze 2: Překlopíme bezpečný název na čistý C hex literál pro GCC +# Z HEX_COLOR_ffcc11 se v hotovém sketch.c stane 0xffcc11 +sed -i -E 's/HEX_COLOR_([0-9a-fA-F]{6})/0x\1/g' "$OUTPUT_C" + +echo "Compiling in $BUILD_DIR..." +gcc "$OUTPUT_C" -o "$BINARY" -O2 -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + +echo "Running..." +(cd "$SKETCH_DIR" && "$BINARY") diff --git a/pprun b/pprun deleted file mode 120000 index e5224d5..0000000 --- a/pprun +++ /dev/null @@ -1 +0,0 @@ -run \ No newline at end of file diff --git a/pprun b/pprun new file mode 100755 index 0000000..a5025a1 --- /dev/null +++ b/pprun @@ -0,0 +1,76 @@ +#!/bin/sh +# run — transpile + compile + execute Processing sketches in one shot. +# +# ./run sketch from current directory +# ./run ~/path/to/sketch sketch elsewhere +# PDE_OPTS=-O2 ./run override fast -O0 default +# PDE_KEEP=1 ./run keep tmp dir for inspecting generated C +# +# All .pde files in the directory are treated as tabs of one sketch and +# compiled together (main tab named after the directory goes first). +set -u + +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +DIR="${1:-$PWD}" + +if [ ! -d "$DIR" ]; then + echo "run: no such directory: $DIR" >&2 + exit 1 +fi + +TMP=$(mktemp -d /tmp/pderun.XXXXXX) +cleanup() { rm -rf "$TMP"; } +trap cleanup EXIT INT TERM + +# rebuild transpiler only when its source changed +if [ "$SCRIPT_DIR/pde2c.c" -nt "$SCRIPT_DIR/pde2c" ] || [ ! -x "$SCRIPT_DIR/pde2c" ]; then + gcc "$SCRIPT_DIR/pde2c.c" -o "$SCRIPT_DIR/pde2c" || exit 1 +fi + +# rebuild precompiled header only when processing.h got newer. This skips +# re-parsing raylib/rlgl/raymath on every compile, cutting turnaround from +# ~3s to ~0.2s. It is built with the same -I flags used at consume time +# (gcc requires the flags to match). PDE_NOPCH=1 ever builds correctly but +# forces a from-scratch run if the PCH ever goes stale. +if [ "${PDE_NOPCH:-0}" != "1" ] && \ + { [ "$SCRIPT_DIR/processing.h" -nt "$SCRIPT_DIR/processing.h.gch" ] || [ ! -f "$SCRIPT_DIR/processing.h.gch" ]; }; then + gcc $("$SCRIPT_DIR/pdedeps" --includes) -x c-header "$SCRIPT_DIR/processing.h" \ + -o "$SCRIPT_DIR/processing.h.gch" || exit 1 +fi + +# collect tabs: main tab first, then the rest alphabetically +MAIN="$TMP/none.pde" +[ -f "$DIR/$(basename "$DIR").pde" ] && MAIN="$DIR/$(basename "$DIR").pde" +{ + [ "$MAIN" != "$TMP/none.pde" ] && { printf '//@file %s\n' "$(basename "$MAIN")"; cat "$MAIN"; } + for f in $(find "$DIR" -maxdepth 1 -name '*.pde' | sort); do + [ "$f" = "$MAIN" ] && continue + printf '//@file %s\n' "$(basename "$f")" + cat "$f" + done +} > "$TMP/combined.pde" + +if ! grep -q '[^[:space:]]' "$TMP/combined.pde"; then + echo "run: no .pde files found in $DIR" >&2 + exit 1 +fi + +# transpile (validation errors inside pde2c print file:line and exit 1) +"$SCRIPT_DIR/pde2c" "$TMP/combined.pde" > "$TMP/sketch.c" || exit 1 + +# compile fast; on failure show a readable, source-mapped excerpt +CFLAGS="${PDE_OPTS--O0 -pipe}" +if ! gcc $CFLAGS $("$SCRIPT_DIR/pdedeps" --includes) "$TMP/sketch.c" -o "$TMP/sketch" \ + $("$SCRIPT_DIR/pdedeps" --libs) \ + 2> "$TMP/gcc.err"; then + head -15 "$TMP/gcc.err" + if [ "${PDE_KEEP:-0}" = "1" ]; then + echo "run: compilation failed, kept build dir $TMP" >&2 + trap - EXIT + else + echo "run: compilation failed (set PDE_KEEP=1 to inspect generated C)" >&2 + fi + exit 1 +fi + +"$TMP/sketch" diff --git a/run b/run deleted file mode 120000 index 4722d47..0000000 --- a/run +++ /dev/null @@ -1 +0,0 @@ -/home/kof/src/RaylibProcessing/run \ No newline at end of file diff --git a/run b/run new file mode 100755 index 0000000..a5025a1 --- /dev/null +++ b/run @@ -0,0 +1,76 @@ +#!/bin/sh +# run — transpile + compile + execute Processing sketches in one shot. +# +# ./run sketch from current directory +# ./run ~/path/to/sketch sketch elsewhere +# PDE_OPTS=-O2 ./run override fast -O0 default +# PDE_KEEP=1 ./run keep tmp dir for inspecting generated C +# +# All .pde files in the directory are treated as tabs of one sketch and +# compiled together (main tab named after the directory goes first). +set -u + +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +DIR="${1:-$PWD}" + +if [ ! -d "$DIR" ]; then + echo "run: no such directory: $DIR" >&2 + exit 1 +fi + +TMP=$(mktemp -d /tmp/pderun.XXXXXX) +cleanup() { rm -rf "$TMP"; } +trap cleanup EXIT INT TERM + +# rebuild transpiler only when its source changed +if [ "$SCRIPT_DIR/pde2c.c" -nt "$SCRIPT_DIR/pde2c" ] || [ ! -x "$SCRIPT_DIR/pde2c" ]; then + gcc "$SCRIPT_DIR/pde2c.c" -o "$SCRIPT_DIR/pde2c" || exit 1 +fi + +# rebuild precompiled header only when processing.h got newer. This skips +# re-parsing raylib/rlgl/raymath on every compile, cutting turnaround from +# ~3s to ~0.2s. It is built with the same -I flags used at consume time +# (gcc requires the flags to match). PDE_NOPCH=1 ever builds correctly but +# forces a from-scratch run if the PCH ever goes stale. +if [ "${PDE_NOPCH:-0}" != "1" ] && \ + { [ "$SCRIPT_DIR/processing.h" -nt "$SCRIPT_DIR/processing.h.gch" ] || [ ! -f "$SCRIPT_DIR/processing.h.gch" ]; }; then + gcc $("$SCRIPT_DIR/pdedeps" --includes) -x c-header "$SCRIPT_DIR/processing.h" \ + -o "$SCRIPT_DIR/processing.h.gch" || exit 1 +fi + +# collect tabs: main tab first, then the rest alphabetically +MAIN="$TMP/none.pde" +[ -f "$DIR/$(basename "$DIR").pde" ] && MAIN="$DIR/$(basename "$DIR").pde" +{ + [ "$MAIN" != "$TMP/none.pde" ] && { printf '//@file %s\n' "$(basename "$MAIN")"; cat "$MAIN"; } + for f in $(find "$DIR" -maxdepth 1 -name '*.pde' | sort); do + [ "$f" = "$MAIN" ] && continue + printf '//@file %s\n' "$(basename "$f")" + cat "$f" + done +} > "$TMP/combined.pde" + +if ! grep -q '[^[:space:]]' "$TMP/combined.pde"; then + echo "run: no .pde files found in $DIR" >&2 + exit 1 +fi + +# transpile (validation errors inside pde2c print file:line and exit 1) +"$SCRIPT_DIR/pde2c" "$TMP/combined.pde" > "$TMP/sketch.c" || exit 1 + +# compile fast; on failure show a readable, source-mapped excerpt +CFLAGS="${PDE_OPTS--O0 -pipe}" +if ! gcc $CFLAGS $("$SCRIPT_DIR/pdedeps" --includes) "$TMP/sketch.c" -o "$TMP/sketch" \ + $("$SCRIPT_DIR/pdedeps" --libs) \ + 2> "$TMP/gcc.err"; then + head -15 "$TMP/gcc.err" + if [ "${PDE_KEEP:-0}" = "1" ]; then + echo "run: compilation failed, kept build dir $TMP" >&2 + trap - EXIT + else + echo "run: compilation failed (set PDE_KEEP=1 to inspect generated C)" >&2 + fi + exit 1 +fi + +"$TMP/sketch"