Projeto

Geral

Perfil

find_pregs.sh

Script principal - Alexandre Rocha Wendling Cassol, 15/06/2022 13:10 h

Baixar (1,42 KB)

 
1
#!/bin/bash
2
fphp=$(echo "$0" | sed 's#\.sh$#.php#');
3
fout=$(echo "$0" | sed 's#\.sh$#.out#');
4

    
5
flist=()
6
while (( "$#" )); do case "$1" in
7
	-x|--debug) debug=1;                                                    shift 1;;
8
	--no-save)  nosave=1;                                                   shift 1;;
9
	-o|--out)   fout=("$2");                                                shift 2;;
10
	-f|--file)  flist+=("$2");                                              shift 2;;
11
	--)                                                              shift 1; break;;
12
	-*|--*=)    echo "Error: Unsupported flag $1" >&2;                       exit 1;;
13
	*) flist+=("$1");                                                       shift 1;;
14
esac; done
15
if [[ "${#flist[@]}" -eq 0 ]]; then
16
	echo -n 'Searching files... ';
17
	while IFS= read -r -d $'\0' line; do flist+=("${line}"); done < <(find -type f -iname '*.php' -print0)
18
	echo -e "${R}${#flist[@]}${N} found. done."
19
fi
20
#if [[ ! -z "${debug}" ]]; then set -x; fi
21

    
22
rgrep -Hna -A 10 -Z --no-group-separator 'preg_[a-zA-Z0-9_]* *(' "${flist[@]}" |
23
	sed 's#\r##;s#\$preg_#$var#g;s#preg_quote#funct#g;s#^[^\x00]*\x0[0-9]\+\-#®#1' |
24
	sed ':a;N;$!ba;s#\n®#\x11#g;s#\x0#:#g' |
25
	grep -a 'preg_[a-zA-Z0-9_]* *(' |
26
	php -f "${fphp}" "${fout}" "${debug}"
27

    
28
# Comando para remover expressões vazias
29
# for n in $(php -f "${fout}" 2>&1 | grep 'Empty regular expression in' | grep -o '[0-9]\+$'); do sed -i "$n {s#^#//#}" "${fout}"; done