home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
ez-btm11.exe
/
HELPTEXT.BTM
< prev
next >
Wrap
Text File
|
1994-03-30
|
5KB
|
137 lines
:: [This line is left for writing the filename]
set source=%@search[%0]
:: %@filename[%source] - This batch demonstrates how you can insert
:: a short explanation text at the top of your batch file and have it
:: displayed as a HELP text. This saves you from inserting a more or less
:: duplicate text at some ":help" label in that batch file. Moreover, you
:: can make use of my "master help procedure" (MASTHELP.BTM) as an external
:: routine. The current batch indeed works that way. If you wish to test
:: how this works via an internal routine, run batch with an "i" switch.
:: ----------------------
:: The idea is taken from a program in REXX. The procedure in 4DOS
:: does not work as fast as it does in REXX, but you both gain elegance
:: and save work, which is especially important if you often modify a
:: program.
:: ----------------------
:: Syntax:
:: %@name[%source] [filespecs]
:: You can put here some further explanation
:: Switches:
:: (for example:) h, or ? -- This HELP
:: (This is an example for describing switches / options)
:: NOTE:
:: (1) the line
:: set source=%@search[%0]
:: must be inserted above the description text. Otherwise, the HELP
:: procedure will not know from which file to read its lines.
:: It is a precondition for this to work that your batch is located
:: in a subdirectory defined in your PATH command.
:: (2) The description text MUST end with a blank line.
:: If you prefer some other demarcation sign, you must edit the procedure
:: accordingly.
:: For more details about the structure of this procedure and other
:: options read below, and MASTHELP.BTM.
:: setlocal
:: If you prefer your batch to execute its proper task rather than display
:: a HELP text when run without arguments, activate the following (remove
:: the double colons from the following and the "quit" line for these
:: lines to work.)
:: if %@index[%&,h] eq 0 .or. %@index[%&,?] eq 0 goto help
:: (The actual batch file comes here)
:: quit
:internal
:: I've added this to allow the internal routine to work.
iff "%1"=="i" then
setlocal
goto help_2
endiff
:: ----sub-routines--------
:help
:: The EXTERNAL routine MASTHELP.BTM is called from this section.
:: See below how you can have it as an INTERNAL routine.
:: set lnumber=x
:: ==>remove '::' and put a number instead of 'x' if you wish
:: the HELP text to begin with some other line than the 3rd line.
:: (The 3rd line is the default of this procedure. It is defined
:: in the external procedure MASTEHELP.BTM. Remember that the first
:: line in 4DOS is "0".)
iff exist %@search[masthelp] then
call masthelp
cancel
else
cls^screen 3 0
screen %@eval[%_row+1] 4 You must have %@upper[masthelp.btm]
screen %@eval[%_row+1] 4 for this HELP procedure to work
echo.
quit
endiff
:: ---- Making the external HELP procedure an internal procedure ---
:: =================================================================
:: NOTE: The external procedure can be inserted as an internal procedure
:: at the ":help" label. If you prefer that, here's how it can look
:: (with detailed line-by-line explanation below).
:help_2
cls^screen 2 0
:: ==>Change number below if you wish the HELP text to begin
:: at some other line than the 3rd line. (Remember that the first line
:: in 4DOS is "0".)
set num=2
do forever
set hl=%@instr[3,70,%@line[%source,%num]]
set num=%@eval[%num+1]
if "%hl"=="" leave
screen %@eval[%_row+1] 4 %hl
enddo
endlocal
echo.
quit
:: ----a line-by-line-explanation of the above procedure---
cls^screen 2 0
:: this clears the screen and puts the cursor on row #2
set num=2
:: this sets a counter for "2", which means that you wish to
:: start reading the lines from the file from the THIRD line.
do forever
:: this means that the loop will go on as long as it is not told
:: explicitly to stop. This option is available only in 4DOS 5.x.
:: For prior versions the loop must be written a bit differently.
set hl=%@instr[3,70,%@line[%source,%num]]
:: save line number 1 (2,3,4,...) from the batch file on the variable
:: "hl", then extract from each line of the description text only the
:: part that begins on position 4 [first position is 0 in 4DOS].
:: Note: This can be written in two different lines: one line for
:: saving the relevant line:
:: set hl=%@line[%source,%num]
:: then one line for extracting the desired section:
:: set hl=%@instr[3,70,%hl]
:: I preferred using one line for both procedures for the sake of
:: brevity; but sometimes readability is more important.
:: Note_2: Note that @instr[] and not @substr[] is used, since
:: @subsrt[] has problems with commas in lines (RFM for details.)
set num=%@eval[%num+1]
:: increment now the counter by 1
if "%hl"=="" leave
:: if the line was empty, stop the loop (and go to the lines after
:: "enddo")
screen %@eval[%_row+1] 4 %hl
:: put the relevant line one row below the current row on the 4th
:: column.
enddo
:: end / go back to beginning of loop)
endlocal
:: erase the temporary variables set in this file from the environment.
echo.
:: add one blank line to the text displayed on screen.
quit