Good stuff, I also need...
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
@echo off
setlocal enabledelayedexpansion
echo.
echo Text Editor
echo Coded by neko, 2010. All rights reserved.
:: Temporary file setting
set tempfile=%temp%\edit.tmp
:: Control entry setting
set ctrcmd=!control
:: File name setting
if not "%1"=="" (set filename=%1
goto EDITOLD)
goto CONTROL
:CONTROL
echo.
:CONTCYCLE
set /p ecmd=">"
for /f "tokens=1" %%i in ("%ecmd%") do set ecmdf=%%i
for /f "tokens=2" %%i in ("%ecmd%") do set ecmd1=%%i
:: File operations
if "%ecmdf%"=="new" (
set filename=New Text Document.txt
echo.
goto CREATENEW
)
if "%ecmdf%"=="open" (
set filename=!ecmd1!
goto EDITOLD
)
if "%ecmdf%"=="save" (
if exist "!filename!.bak" del "!filename!.bak" /f
if exist "!filename!" move "!filename!" "!filename!.bak"
copy "%tempfile%" "!filename!"
goto EDITOLD
)
if "%ecmdf%"=="saveas" (
set filename=!ecmd1!
if exist "!filename!.bak" del "!filename!.bak" /f
if exist "!filename!" move "!filename!" "!filename!.bak"
copy "%tempfile%" "!filename!"
goto EDITOLD
)
if "%ecmdf%"=="back" (
if "%editstate%"=="CREATE_NEW" set /a line=!line!-1
echo.
goto EDITPARA
)
if "%ecmdf%"=="exit" (
if exist "%tempfile%" del "%tempfile%" /f
goto EOF
)
if "%ecmdf%"=="help" goto HELP
:: Line operations
if "%ecmdf%"=="insert" goto INSERT
if "%ecmdf%"=="line.insert" goto LINSERT
if "%ecmdf%"=="line.delete" goto LDELETE
if "%ecmdf%"=="line.edit" goto LEDIT
echo '%ecmdf%' is not a valid command, please type help to query control commands.
echo.
goto CONTCYCLE
:NOPEN
echo No editable file is opened.
goto CONTROL
:NOLINE
echo The specified line number does not exist.
goto CONTROL
:HELP
echo.
echo New new
echo Open open
echo Save save
echo Save as saveas
echo Back back
echo Exit exit
echo Help help
echo.
echo Insert segment insert
echo Insert line line.insert
echo Delete line line.delete
echo Edit line line.edit
goto CONTROL
:INSERT
if "!filename!"=="" goto NOPEN
if !ecmd1! LEQ 0 goto NOLINE
set /a line=!line!+1
if !ecmd1! GTR !line! goto NOLINE
echo.
if exist "%tempfile%.1" del "%tempfile%.1" /f
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! LSS !ecmd1! echo %%i>>"%tempfile%.1"
)
set /a line=!ecmd1!-1
:INSPARA
set /a line=!line!+1
set /p cLine="%line%: "
if not "%cLine%"=="%ctrcmd%" (
echo ^%cLine%>>"%tempfile%.1"
goto INSPARA)
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! GEQ !ecmd1! echo %%i>>"%tempfile%.1"
)
if exist "%tempfile%" del "%tempfile%" /f
move "%tempfile%.1" "%tempfile%"
goto EDITCUR
:LINSERT
if "!filename!"=="" goto NOPEN
if !ecmd1! LEQ 0 goto NOLINE
if !ecmd1! GTR !line! goto NOLINE
echo.
set /p cLine="!ecmd1!: "
if exist "%tempfile%.1" del "%tempfile%.1" /f
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! LSS !ecmd1! echo %%i>>"%tempfile%.1"
if !line! EQU !ecmd1! echo ^%cLine%>>"%tempfile%.1"
)
set /a ecmd1=!ecmd1!-1
for /f "skip=%ecmd1% tokens=*" %%i in (%tempfile%) do echo %%i>>"%tempfile%.1"
if exist "%tempfile%" del "%tempfile%" /f
move "%tempfile%.1" "%tempfile%"
goto EDITCUR
:LDELETE
if "!filename!"=="" goto NOPEN
if !ecmd1! LEQ 0 goto NOLINE
if !ecmd1! GTR !line! goto NOLINE
echo.
if exist "%tempfile%.1" del "%tempfile%.1" /f
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! LSS !ecmd1! echo %%i>>"%tempfile%.1"
if !line! GTR !ecmd1! echo %%i>>"%tempfile%.1"
)
if exist "%tempfile%" del "%tempfile%" /f
move "%tempfile%.1" "%tempfile%"
goto EDITCUR
:LEDIT
if "!filename!"=="" goto NOPEN
if !ecmd1! LEQ 0 goto NOLINE
if !ecmd1! GTR !line! goto NOLINE
echo.
if exist "%tempfile%.1" del "%tempfile%.1" /f
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! EQU !ecmd1! echo !ecmd1!: %%i
)
set /p cLine="!ecmd1!: "
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
if !line! LSS !ecmd1! echo %%i>>"%tempfile%.1"
if !line! EQU !ecmd1! echo ^%cLine%>>"%tempfile%.1"
if !line! GTR !ecmd1! echo %%i>>"%tempfile%.1"
)
if exist "%tempfile%" del "%tempfile%" /f
move "%tempfile%.1" "%tempfile%"
goto EDITCUR
:CREATENEW
echo.
echo Creating text - !filename!
echo.
set /a line=0
if exist "%tempfile%" del "%tempfile%" /f
set editstate=CREATE_NEW
:CRTPARA
set /a line=!line!+1
set /p cLine="%line%: "
if "%cLine%"=="%ctrcmd%" goto CONTROL
echo ^%cLine%>>"%tempfile%"
goto CRTPARA
:EDITOLD
if not exist "!filename!" (
echo File '!filename!' does not exist.
goto CONTROL
)
if exist "%tempfile%" del "%tempfile%" /f
for /f "tokens=*" %%i in (!filename!) do echo %%i>>"%tempfile%"
:EDITCUR
echo.
echo Editing text - !filename!
echo.
set /a line=0
for /f "tokens=*" %%i in (%tempfile%) do (set /a line=!line!+1
echo !line!: %%i)
goto CONTROL
:EOF
if exist "%tempfile%" del "%tempfile%" /f
set tempfile=
set ctrcmd=
set filename=
set editstate=
set line=
set cLine=
set ecmd=
set ecmdf=
set ecmd1=