Début du parsing

This commit is contained in:
Logikisto
2026-09-15 16:21:29 +02:00
parent dcf0cf547f
commit 7750d956cb
4 changed files with 17 additions and 80 deletions
+1 -13
View File
@@ -1,13 +1 @@
Commande `c-run` similaire à `go run` pour lancer un code `.c` avec les arguments de `gcc` **sans** laisser de traces. Refonte du projet en une commande C
Installation/update :
```bash
source <(curl -fsSL https://git.rv0.fr/Logikisto/crun/raw/branch/master/install.sh)
```
Suppresion :
```bash
sed -i '/# >>> c-run setup >>>/,/# <<< c-run setup <<</d' ~/.bashrc && unset -f c-run
```
Ne fait que **bashrc** pour le moment et qu'**un seul** fichier à la fois !
-58
View File
@@ -1,58 +0,0 @@
#!/bin/bash
BASHRC="$HOME/.bashrc"
MARKER_START="# >>> c-run setup >>>"
MARKER_END="# <<< c-run setup <<<"
# Crée le .bashrc s'il n'existe pas
touch "$BASHRC"
# Supprime l'ancienne version de la fonction si elle existe
if grep -q "$MARKER_START" "$BASHRC"; then
sed -i "/$MARKER_START/,/$MARKER_END/d" "$BASHRC"
fi
# Ajoute la fonction à la fin du .bashrc
cat >> "$BASHRC" << 'EOF'
# >>> c-run setup >>>
c-run() {
if [ -z "$1" ]; then
echo "c-run: erreur: nom de fichier manquant" >&2
return 1
fi
local source_file="$1"
shift
local exec_file
exec_file=$(mktemp)
trap 'rm -f "$exec_file"' INT
gcc "$source_file" -o "$exec_file" "$@"
local gcc_status=$?
if [ $gcc_status -ne 0 ]; then
echo "--- c-run: la compilation a échoué (gcc a retourné le code $gcc_status) ---" >&2
rm -f "$exec_file"
trap - INT
return $gcc_status
fi
"$exec_file"
local exec_status=$?
rm -f "$exec_file"
trap - INT
return $exec_status
}
# <<< c-run setup <<<
EOF
# Recharge le .bashrc dans le shell courant
source "$BASHRC"
# Utilise 'return' au lieu de 'exit' pour ne pas fermer le terminal de l'utilisateur
# si le script est sourcé. Si le script est exécuté normalement (sh install.sh),
# le 'return' va simplement ignorer l'erreur silencieusement.
return 0 2>/dev/null || exit 0
-9
View File
@@ -1,9 +0,0 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Nombre d'arguments : %d\n", argc);
for (int i = 0; i < argc; i++) {
printf("argv[%d] = \"%s\"\n", i, argv[i]);
}
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
printf("Nombre d'arguments : %d\n", argc);
for (int i = 0; i < argc; i++) {
if (strncmp(argv[i], "--cc=", 5) == 0) {
printf("arg --cc\n");
} else {
printf("argv[%d] = \"%s\"\n", i, argv[i]);
};
}
return 0;
}