@echo off

setlocal EnableDelayedExpansion

mkdir txts
del /q txts\*.txt

set /a nivel=0
set /a nivelAnterior=0
set "tab=│   "
set "flecha=├─»"
set ntab=

set "r="

call :lstPtoPas

call :imprimirArbol "%nivel%" "%1" "%ntab%"
set "ntab=%tab%%ntab%"			
set /a nivel=%nivel%+1

call :hijos %1

call :fin

:hijos
set c=%~1
if not exist "txts\%c%.txt" (
	
	echo Analizando %c% nivel %nivel%
	findstr /s /i /r /c:"=[ ]*class[ ]*([ ]*%c%[ ]*)"  /f:"txts\pas.txt" > txts\%c%.txt
	
	
	for /F "tokens=2,3 delims=:=" %%d in (txts\%c%.txt) do (
		
		call :imprimirArbol "%nivel%" "%%e" "%%d" "%ntab%"
	
		if not "%%d"=="" (
			set "ntab=%tab%%ntab%"			
			set /a nivel=%nivel%+1
			
			call :nietos %%e %%d
			
			set nivelAnterior=%nivel%
			::echo H%ntab% >> txts\Arbol.txt
			rem set "ntab=%tab%%ntab%"
		) 
	)
)	
goto:EOF

:nietos
set f=%~1
set f=%f: =%
set f=%f:	=%
rem echo %f%
rem pause
call :hijos "%f%" "%~2"
goto:eof

:imprimirArbol
rem echo arbol %~1 %~2
set h=%~2
set h=%h: =%
set h=%h:	=%
echo %~4%flecha% %~1 %h% %~3 >> txts\Arbol.txt

goto:eof

:lstPtoPas
::echo Crando lista de archivos .pas
dir /b /s *.pas > txts\pas.txt
goto:eof


:fin
echo 

exit /b

