68 lines
1.2 KiB
Bash
Executable file
68 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
showfunc() {
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Uso:"
|
|
echo " showfunc FILE FUNZIONE"
|
|
echo
|
|
echo "Esempio:"
|
|
echo " showfunc public/js/map/mapboxMarkers.js updateSource"
|
|
return 1
|
|
fi
|
|
|
|
local FILE="$1"
|
|
local FUNC="$2"
|
|
|
|
if [ ! -f "$FILE" ]; then
|
|
echo "ERRORE: file non trovato:"
|
|
echo " $FILE"
|
|
return 1
|
|
fi
|
|
|
|
python3 - "$FILE" "$FUNC" <<'PY'
|
|
import sys
|
|
|
|
file = sys.argv[1]
|
|
func = sys.argv[2]
|
|
|
|
with open(file, "r", encoding="utf-8") as f:
|
|
text = f.read()
|
|
|
|
# Cerca "function nome("
|
|
needle = "function " + func + "("
|
|
start = text.find(needle)
|
|
|
|
if start == -1:
|
|
print("FUNZIONE NON TROVATA:", func)
|
|
sys.exit(1)
|
|
|
|
# Cerca la prima { dopo la dichiarazione
|
|
brace_start = text.find("{", start)
|
|
|
|
if brace_start == -1:
|
|
print("ERRORE: parentesi graffa iniziale non trovata")
|
|
sys.exit(1)
|
|
|
|
depth = 0
|
|
end = None
|
|
|
|
for i in range(brace_start, len(text)):
|
|
char = text[i]
|
|
|
|
if char == "{":
|
|
depth += 1
|
|
|
|
elif char == "}":
|
|
depth -= 1
|
|
|
|
if depth == 0:
|
|
end = i + 1
|
|
break
|
|
|
|
if end is None:
|
|
print("ERRORE: parentesi graffe non bilanciate")
|
|
sys.exit(1)
|
|
|
|
print(text[start:end])
|
|
PY
|
|
}
|