@echo off
title Kernel DOC generator
COLOR 2A
prompt ]
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
mode con:cols=40 lines=24

cls
echo                Apple //e

set DOCFILE=%~dp0..\_Docs\KERNEL.md

echo # A2osX Kernel API  >!DOCFILE!
echo *** Auto generated by docgen.cmd ***  >!DOCFILE!

echo.
echo Scanning KERNEL Src Files...
echo.


for /f %%F in ('dir /b /ogn %~dp0..\SYS\KERNEL.S*.txt') do (
 set FN=%%F
 set /p "=!FN!, " <NUL
 set bInDoc=0
 for /F "tokens=*" %%L in (%~dp0..\SYS\!FN!) do (
  set LINE=%%L
  if defined LINE (
   set bOut=1
   if "!LINE:~0,2!" EQU "*/" (
    set bInDoc=1
    set bOut=0
    )
   if "!LINE:~0,2!" EQU "*\" (
    set bInDoc=0
    set bOut=0
    )
   if !bInDoc! EQU 1 (
    if !bOut! EQU 1 (
     if "!line:~0,4!" EQU "*   " set LINE= + !LINE:~4!
     if "!line:~0,3!" EQU "*  " set LINE=+ !LINE:~3!
     if "!line:~0,2!" EQU "* " set LINE=!LINE:~2!
     echo !LINE!  >>!DOCFILE!
     )
    )
   )
  )
 )
echo.
echo.
echo All done.
echo.
echo (I know, this batch is stupid ;-)
echo.
