Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Test your batch vocabulary :)

7 views
Skip to first unread message

Ritchie

unread,
Apr 25, 2003, 9:48:09 AM4/25/03
to
Test your batch vocabulary with batch Hangman. The rules are obvious,
(you guess the word, one letter at a time) however they are explained
here:-

http://reed.kfar-olami.org.il/resources/games/instruc/hangman.htm
http://www.cyberscorpion.com/experimental/HMRules.html

If you can't reach level eight, shame on you.
--
Ritchie

============================ start hm.cmd ================================
@echo off&setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: Check current cmd interpreter is Windows 2000 or higher
if not CMDEXTVERSION 2 (
>&2echo/This script requires a Win2000 or higher command interpreter.
md;2>nul&goto :EOF
)
:: Check %comspec% interpreter is Windows 2000 or higher
%comspec% /cexit /b 0 2>nul||(
>&2echo/This script requires that the %%COMSPEC%% environment variable
>&2echo/is set to a Win2000 or higher command interpreter.
md;2>nul&goto :EOF
)

set "Progress=(echo/|set /p=^.)"

:: Minimum and maximum length of word to guess. 4 & 10 give good results
set iMinRange=4 & set iMaxRange=10

:: Set game starting level, valid values 1 through to 10
set iLevel=1

:Start
cls&(echo/|set /p=^Loading)
set /a iMaxGuesses=11-iLevel, iGuesses=iLevel-1

:: Randomly set the minimum word length from 5 to 13
set /a iMinWordLen=%random%%%(iMaxRange-iMinRange+1)+iMinRange

:: Initialise array to hold help commands
for /f "delims==" %%a in ('set zCMD 2^>nul') do (set %%a=)

:: Put all the commands from 'help' into array
set i=0&for /f %%a in ('help^|findstr /v /b /c:" "') do (
set/a i+=1&set zCMD!i!=%%a&(set iCMD=!i!)&%Progress%
)

:Main Randomly decide which help cmd to use and store in sCMD
set /a i=%RANDOM%%%iCMD+1&call set sCMD=%%zCMD!i!%%

:: Initialise array to hold the command helpscreen
for /f "delims==" %%a in ('set zLine 2^>nul') do (set %%a=)

:: Put helpscreen into an array, rejecting lines containing % or "
set i=0&for /f "tokens=*" %%a in (
'help %sCMD%^|findstr /v "[%%"""]"'
) do (set /a i+=1&set zLine!i!="%%a")

:: Randomly decide which line to use and store in sLine
set /a j=%RANDOM%%%%i%+1&call set sLINE=%%zLine!j!%%

:: Change symbols to spaces to increase vocabulary
set sLine=%sLine:^= %
set sLine=%sLine:|= %
set sLine=%sLine:&= %
set sLine=%sLine:>= %
set sLine=%sLine:<= %
set sLine=%sLine:[= %
set sLine=%sLine:]= %
set sLine=%sLine:(= %
set sLine=%sLine:)= %
set sLine=%sLine:\= %
set sLine=%sLine:/= %
set sLine=%sLine:.= %
set sLine=%sLine::= %
set sLine=%sLine:,= %
set sLine=%sLine:"= %

:: Load any suitable words in sLine into an array
%Progress%&set i=0&for %%a in (%sLine%) do (
set sWord=%%a&Call :GetStrLen iLen sWord
if !iLen! GEQ !iMinWordLen! (
call :IsWordAlpha !sWord!&&(
call :IsWordCommon !sWord!||(set /a i+=1&set zWord!i!=!sWord!)
)
)
)

:: If no suitable words found choose another command
if %i% EQU 0 goto :Main

:: Randomly decide which word to use and store in sWord
set /a j=%RANDOM%%%%i%+1&call set sWord=%%zWord!j!%%

:: Convert chosen word to uppercase
call :WordToUpper sWord

:: Make 'sSoFar' same length as 'sWord', but fill with dots
Call :GetStrLen iWordLen sWord
set sSoFar=&for /l %%a in (1,1,%iWordLen%) do (set sSoFar=!sSoFar!.)
set sHistory=&set iDone=0

:Main.Loop
call :UpdateScreen %iGuesses% %sSoFar% %iWordLen% %iLevel% %sHistory%
call :GetChar sGuess "Guess a letter: "||(
echo/&echo/ INVALID INPUT^^!
echo/&echo/|set /p=^ Please any key to continue...&pause>nul
goto :Main.Loop
)
call :ProcessGuess sSoFar sHistory !sGuess! !sWord!||set /a iGuesses+=1
if !sWord! NEQ !sSoFar! if %iGuesses% LSS 10 goto :Main.Loop

call :UpdateScreen %iGuesses% %sSoFar% %iWordLen% %iLevel% %sHistory%

:: Level is finished, now decide what to do (fanfare, next level or quit)
if %iGuesses% LSS 10 (
if !iLevel! EQU 10 (
echo/ CONGRATULATIONS^^!&echo/
echo/ You've completed all the levels^^!
exit /b 0
) ^
else (
set /a iLevel+=1
echo/&echo/ WELL DONE^^!&echo/
echo/|^set /p=^ Press any key to start level !iLevel!
pause >nul&goto :Start
)
) else (
echo/ BAD LUCK^^! You reached level !iLevel!
echo/&echo/ The word was [%sWord%]
exit /b 1
)

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:ProcessGuess sSoFar sHistory !sGuess! !sWord!
::
:: Func: Checks to see if the letter entered by the user is contained in
:: the word being guessed. The guess history (sHistory) is updated.
:: If guess is good, sSoFar is updated and true is returned, else
:: false returned. For 2K/XP.
::
:: Args: %1 var containing correct guesses so for, this is updated (by ref)
:: %2 var containing guess history, this is updated (by ref)
:: %3 users guess, will always be a single uppercase letter (by val)
:: %4 the word being guessed (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f %%a in ('echo/%%%1%%') do set sSoFar=%%a
if defined %2 (for /f %%a in ('echo/%%%2%%') do set sHistory=%%a)
(set sTemp=)
set Word=%4&Call :GetStrLen i Word&set /a i-=1
md;2>nul&for /l %%a in (0,1,%i%) do (
set letter=!Word:~%%a,1!
if %3 EQU !letter! (
set sTemp=!sTemp!!letter!&ver>nul
) else (set sTemp=!sTemp!!sSoFar:~%%a,1!)
)
endlocal&set %1=%sTemp%&set %2=%sHistory%%3&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetChar cChar %sPrompt%
::
:: Func: Gets input from user, removes any poison chars, trims leading and
:: trailing whitespace converts to uppercase and ignores anything
:: after first word. Returns true if result is a single character in
:: A-Z else returns false. For 2K/XP.
::
:: Args: %1 var to receive character (by ref)
:: %2 var containing user input prompt (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1*" %%a in ('echo/%*') do set sPrompt=%%b
call :GetSafeStr sBuf %sPrompt%
for /f %%a in ('echo/%sBuf%') do set sBuf=%%a
call :GetStrLen iLen sBuf&call :WordToUpper sBuf
md;2>nul&if %iLen% EQU 1 call :IsWordAlpha %sBuf%&&ver>nul
endlocal&set %1=%sBuf%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetSafeStr sBuf %sPrompt%
::
:: Func: Gets input from user and removes any poison chars. For 2K/XP.
::
:: Args: %1 var to receive user input (by ref)
:: %2 var containing user input prompt (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1*" %%a in ('echo/%*') do set sBuf=&set sPrompt=%%~b
set /p sBuf=%sPrompt%&if not defined sBuf endlocal&set %1=&goto :EOF
set sBuf="%sBuf:"=%"
set sBuf=%sBuf:^=%
set sBuf=%sBuf:&=%
set sBuf=%sBuf:|=%
set sBuf=%sBuf:<=%
set sBuf=%sBuf:>=%
set sBuf=%sBuf:(=%
set sBuf=%sBuf:)=%
set sBuf=%sBuf:!=%
endlocal&set %1=%sBuf:~1,-1%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetStrLen len str
::
:: Func: Returns length of a string. Function is tolerant of posion
:: characters if they have been correctly escaped. For NT4/2K/XP.
::
:: Args: %1 var to receive length of string (by ref)
:: %2 var containing string to be measured (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
call set str="%%%2%%"&set i=-4
set str="%str:"= %"
set str=%str:^= %
set str=%str:&= %
set str=%str:|= %
set str=%str:<= %
set str=%str:>= %
set str=%str:(= %
set str=%str:)= %
set str=%str:!= %
:GetStrLen.Loop
set /a i+=1&set str=%str:~1%
if defined str goto GetStrLen.Loop
endlocal&set %1=%i%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WordToUpper sWord
::
:: Func: Converts word (not string) in %1 to uppercase. For NT4/2K/XP.
::
:: Args: %1 word to be converted to uppercase (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
call set sWord=%%%1%%&if not defined sWord endlocal&goto :EOF
for /f "tokens=3 delims=:" %%a in ('fc :%%%1%%: : 2^>^&1') do set sUpp=%%a
endlocal&set %1=%sUpp%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsWordAlpha %word%
::
:: Func: Tests if characters in %1 are all in range a-z, A-Z. If so
:: true is returned, else false. For NT4/2K/XP.
::
:: Args: %1 word to be checked (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
if "%1"=="" endlocal&md;2>nul&goto :EOF
set "alphabet=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
ver>nul&for /f "delims=%alphabet%" %%a in ('echo/%1') do md;2>nul
endlocal&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:UpdateScreen %stage% %sWord% %iWordLen% %iLevel% %sHistory%
::
:: Func: Draws a hangman at specified stage
:: characters if they have been correctly escaped. For NT4/2K/XP.
::
:: Args: %1 stage at which to draw hangman, 0 to 10 (by val)
:: %2 Correct guesses so far (by val)
:: %3 History of guesses (by val)
:: %4 Current level (by val)
:: %5 Length of word being guessed (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
(set sDATA=: ===== I +---+ (^
) I II I /II I /II\ I / I /\ I )
set L1=0000000030303030303030&set L2=0000002020404040404040
set L3=0000002020205060707070&set L4=0000202020202020208090
set L5=0000202020202020202020&set L6=0010101010101010101010
cls&goto :UpdateScreen.Main
:UpdateScreen.Loop
set LN=%1&set /a STEP=%2*2
call set /a OFFSET=%%L%LN%:~%STEP%,2%%
call set DATA=%%sDATA:~%OFFSET%,10%%
set DATA=%DATA:I=^^^|%
echo%DATA%&goto :EOF
:UpdateScreen.Main
for /l %%a in (1,1,6) do call :UpdateScreen.Loop %%a %1
set /a iRemain=10-%1
echo/&echo/Word to guess: [%2] ^(%3 letters^)
echo/Guess history: [%5]&echo/Guesses left : [%iRemain%]
echo/Current level: [%4]&echo/
endlocal&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsWordCommon %word%
::
:: Func: Returns true if %1 is in list of the most commonly generated words
:: else returns false. For NT4/2K/XP.
::
:: Args: %1 word to be checked (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for %%a in (SPECIFIES DIRECTORY EXTENSIONS DISPLAYS COMMAND PARAMETERS ^
SPECIFIED DESTINATION INFORMATION FILENAME DRIVE ATTRIBUTES CHARACTERS ^
CURRENT ENVIRONMENT DIRECTORIES FILES PROCESSING ATTRIBUTE) do (
if /i %1==%%a endlocal&ver>nul&goto :EOF
)
endlocal&md;2>nul&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
============================ end hm.cmd ================================


Nut Cracker

unread,
Apr 25, 2003, 12:55:47 PM4/25/03
to
cant get it to run....

tries to load, then says "I was unexpected at this time"

Also, you might want to comment out the first last lines (===start and
===end)... if that is included in the .cmd file, it opens
23,130,135,125,696,487,875.788 .cmd windows and tanks the system...

It looks interesting tho...

NuTs


"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message
news:b8bear$8be10$1...@ID-156657.news.dfncis.de...

Ritchie

unread,
Apr 25, 2003, 1:23:25 PM4/25/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:#lIeQu0C...@TK2MSFTNGP12.phx.gbl...

> Also, you might want to comment out the first last lines (===start and
> ===end)... if that is included in the .cmd file, it opens
> 23,130,135,125,696,487,875.788 .cmd windows and tanks the system...

> ============================ start hm.cmd ================================
big snip
> ============================ end hm.cmd ================================

LOL, the lines that begin with ======== are not the first and last
lines of the script, but indicate where the script starts and where
it ends! If you saved the script as HM.CMD and included those lines,
then when you ran the script the '=' are ignored but 'start hm.cmd'
is executed and so on, and so on, and so on...

I bet your system was well 'tanked'. Sorry about that - I should have
made the purpose of those lines more obvious.

Anyway, its been tested it on 5 different PC's; 2 x Win2000, 2 x WinXP
and 1 x NT4 (using CMD.EXE from Win2000) without any probs, try again
without the 'first' and 'last' lines.

--
Ritchie


Nut Cracker

unread,
Apr 25, 2003, 2:57:08 PM4/25/03
to
after the bazzillion windows opened and i hard-rebooted my box (win2k sp3) i
removed those lines from the file. That is when it get the
"loading..............................................I was unexpected at
this time" message appears.

do i need anything funky setup in my env variables or something?

NuTs


"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8bquf$8bb6t$1...@ID-156657.news.dfncis.de...

Ritchie

unread,
Apr 25, 2003, 6:14:17 PM4/25/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:e4uqEy1C...@TK2MSFTNGP10.phx.gbl...

> removed those lines from the file. That is when it get the
> "loading..............................................I was unexpected at
> this time" message appears.
> do i need anything funky setup in my env variables or something?

It was intended that the script would run on Win2000/XP (or NT4 using a
later CMD interpreter) without any special settings. I've now tested
it on seven machines without any probs (including cutting and pasting
the script from the original post).

If, in the unlikely event, you feel your time would be best spent
debugging the script rather than doing something else, then turn on
echoing and email me the captured output and the script you used.

--
Ritchie, (cmdprompt dot admin at commandline dot co dot uk)


Thanatos

unread,
Apr 26, 2003, 2:06:53 AM4/26/03
to
Worked for me copied "as is" from the post.

Nice work Ritchie.

"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8cbvr$8gaui$1...@ID-156657.news.dfncis.de...

Musafir

unread,
Apr 26, 2003, 8:23:38 PM4/26/03
to
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message news:<b8bear$8be10$1...@ID-156657.news.dfncis.de>...

> Test your batch vocabulary with batch Hangman. The rules are obvious,
> (you guess the word, one letter at a time) however they are explained
> here:-
>
> http://reed.kfar-olami.org.il/resources/games/instruc/hangman.htm
> http://www.cyberscorpion.com/experimental/HMRules.html
>
> If you can't reach level eight, shame on you.

Nice job, Ritchie!

Either there is a bug or I suck at cut/paste or I am an expert, but it
allowed me a bunch more tries than was fair:

======
+---+
() |
/||\ |
/ |
|
=====

Word to guess: [FOLLOWS] (7 letters)
Guess history: [AEIOUYHTSTMNDFRTNQWRTYUIOPL]
Guesses left : [1]
Current level: [10]

CONGRATULATIONS!

You've completed all the levels!
======

Warm regards,
Sharad Agarwal 'Musafir'

Ritchie

unread,
Apr 27, 2003, 5:56:22 AM4/27/03
to
"Musafir" <bh...@mailcity.com> wrote in message news:ddfbb7a7.03042...@posting.google.com...

> Either there is a bug or I suck at cut/paste or I am an expert, but it

A bug sounds most likely. Are you able to reproduce it? I must have played
hundreds of times by now, and have never seen that happen. Maybe I'm making
assumptions about other users configurations. Is there anything unusual
about yours, BTW whats your O/S?

--
Ritchie


Garry Deane

unread,
Apr 27, 2003, 8:37:46 AM4/27/03
to

I got the same thing - both W2k and XP version of Cmd on NT4.

Word to guess: [.HERE] (5 letters)
Guess history: [ABCDEFGHIJKLMNOPQRSTUVXYZ]
Guesses left : [10]
Current level: [1]

The problem is occurring in the :ProcessGuess routine. For some reason
I can't explain, the following statement in the FOR loop sets
errorlevel to 0.

set letter=!Word:~%%a,1!

However if I set up a small test routine with just the FOR loop, the
errorlevel behaves as expected (is not affected).

Another minor thing is that the program allows multiple letters to be
entered but never returns a match if you do so. I haven't tried to
track that problem.

Word to guess: [.........] (9 letters)
Guess history: [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
Guesses left : [9]
Current level: [2]

Garry

Ritchie

unread,
Apr 27, 2003, 2:36:15 PM4/27/03
to
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3eabbda2...@192.168.0.2...

> The problem is occurring in the :ProcessGuess routine. For some reason
> I can't explain, the following statement in the FOR loop sets
> errorlevel to 0.
>
> set letter=!Word:~%%a,1!

Garry, thanks for working that out. It's quite frustrating not being to
re-produce this bug. I guess in future I should place the command that
changes the errorlevel, at the very end of subroutines, maybe even after
the ENDLOCAL command.

> Another minor thing is that the program allows multiple letters to be

That'll almost certainly be caused by the same kind of bug in the :GetChar
routine (returning TRUE instead of FALSE) as 'normally' it will only accept
a single letter.

BTW, all the O/S's I used for testing were all running the lastest service
pack.

--
Ritchie


Mo

unread,
Apr 29, 2003, 6:07:58 AM4/29/03
to
OK here too - on Windows XP Sp1

"Thanatos" <nob...@noway.net> wrote in message
news:vak8c81...@corp.supernews.com...

Nut Cracker

unread,
Apr 29, 2003, 11:09:44 AM4/29/03
to
i must be inept... i still cannot get it to run.

Should i check the autoexec.nt file to make sure it is allocating enough
widgets to the VDM where this thing will be running?

NuTs


"Mo" <maurice...@nospam.ps.net> wrote in message
news:O4AT3cjD...@TK2MSFTNGP11.phx.gbl...

Ritchie

unread,
Apr 29, 2003, 11:43:55 AM4/29/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:uTQKtFmD...@TK2MSFTNGP12.phx.gbl...

> i must be inept... i still cannot get it to run.
>
> Should i check the autoexec.nt file to make sure it is allocating enough
> widgets to the VDM where this thing will be running?

No, its a widget free script. Try again, by copying the text _between_
the line that indicate the start and end of the script, paste it into
notepad and save as a .bat or .cmd file. Depending on how your system
is configured, notepad might add a .txt extension - so watch out for
that.

Then from a CMD.EXE prompt (_NOT_ a COMMAND.COM prompt) run it. If that
doesn't work, explain what happened (you need to elaborate on 'cannot
get it to run'!). If you're using NT, you'll need to use a Win 2000/XP
command interpreter AND update the COMSPEC variable, but the script
will warn you this.

--
Ritchie


Nut Cracker

unread,
Apr 29, 2003, 2:10:40 PM4/29/03
to
as i have indicated in previous posts... I removed the first and last lines
the begin with "====".

I have given a specific description of my operating system (win2k sp3).

I have attempted to run this via the command prompt (cmd.exe)... what else
would a serious engineer use?

I saved the file as .cmd. I have saved it as ..bat (.cmd files run in a
32bit environement, and .bat files run in a 16bit environment).

my %comspec% variable is c:\winnt\system32\cmd.exe

Further elaboration that I can offer other that this text which is quoted
from a previous post:
' "loading..............................................I was unexpected at
this time" message appears. '

There is nothing in the evenlogs...

without matterially changing anything, i added some echo statements as
debuggers...

I added an "echo Line #" in a few placee... line 39, 53, 70, and 94.

The following is the output:

Loading..........................
ne 39
line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 53
line 70
.line 94
I was unexpected at this time.
C:\>

and that was after re-copying the code from the post (without the "======"
lines, and saved as a .bat file).

Seems there is something in the :Main.Loop function... maybe my newsreader
(outlook express) is monkeying with carriage returns, or spaces, or other
characters or something????

Any ideas?

NuTs

"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8m6jv$bbglu$1...@ID-156657.news.dfncis.de...

Ritchie

unread,
Apr 29, 2003, 3:23:39 PM4/29/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:uQ3I0qnD...@TK2MSFTNGP11.phx.gbl...

> Further elaboration that I can offer other that this text which is quoted
> from a previous post:

<Quote from another previous post:>

If, in the unlikely event, you feel your time would be best spent
debugging the script rather than doing something else, then turn on
echoing and email me the captured output and the script you used.

--
Ritchie, (cmdprompt dot admin at commandline dot co dot uk)

</Quote from another previous post:>

--
Ritchie


Nut Cracker

unread,
Apr 29, 2003, 3:51:15 PM4/29/03
to
thanks for the effort... im done with this one.

Cheers,

NuTs


"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8mjfu$be4ht$1...@ID-156657.news.dfncis.de...

Musafir

unread,
Apr 29, 2003, 5:30:46 PM4/29/03
to
Ritchie - how about running your line number program on it and
re-posting it? That will make it easy for readers to get rid of the
spurious line wraps thrown in by newsreaders.

Just a thought. Warm regards,
Sharad Agarwal 'Musafir'

"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:<uQ3I0qnD...@TK2MSFTNGP11.phx.gbl>...

Ritchie

unread,
Apr 29, 2003, 6:49:57 PM4/29/03
to
"Musafir" <bh...@mailcity.com> wrote in message news:ddfbb7a7.03042...@posting.google.com...
> Ritchie - how about running your line number program on it and
> re-posting it? That will make it easy for readers to get rid of the
> spurious line wraps thrown in by newsreaders.

Good idea (see below). I don't normally number my posted scripts,
because I can't think anything worse that unnumbering them (slight
exageration). Therefore, I retrict maximun line length of my
scripts to 75 characters. But maybe even this is too much for some
setups?

BTW when a cut'n'paste from my original post and compare it with
the original script, there are no differences - I use Outlook
Express 5.5.

I have just noticed something that is relevant to some of the
issues that have been reported. When I wrote the script, I gave
it a .bat extension which worked fine as I've said earlier.

When I cut'n'pasted earlier, it was saved as a .cmd script. After
verifying the scripts were identical, I ran the .cmd version and
basically it doesn't work. I'm getting the same results that you
and Garry reported earlier - So hopefully I'll fix it tomorrow.

Every day's a school day! BAT and CMD definetaly are not equal.

In future I'll test using only a .CMD extension, and add a few
lines of code to check the scripts extension.

Here is the original script. Every line is preceded by three
numbers, a period and a space. These all need removing.

====================================================
IMPORTANT: Save the script as a .BAT file (not .CMD)
====================================================
--
Ritchie

001. @echo off&setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
002.
003. :: Check current cmd interpreter is Windows 2000 or higher
004. if not CMDEXTVERSION 2 (
005. >&2echo/This script requires a Win2000 or higher command interpreter.
006. md;2>nul&goto :EOF
007. )
008.
009. :: Check %comspec% interpreter is Windows 2000 or higher
010. %comspec% /cexit /b 0 2>nul||(
011. >&2echo/This script requires that the %%COMSPEC%% environment variable
012. >&2echo/is set to a Win2000 or higher command interpreter.
013. md;2>nul&goto :EOF
014. )
015.
016. set "Progress=(echo/|set /p=^.)"
017.
018. :: Minimum and maximum length of word to guess. 4 & 10 give good results
019. set iMinRange=4 & set iMaxRange=10
020.
021. :: Set game starting level, valid values 1 through to 10
022. set iLevel=1
023.
024. :Start
025. cls&(echo/|set /p=^Loading)
026. set /a iMaxGuesses=11-iLevel, iGuesses=iLevel-1
027.
028. :: Randomly set the minimum word length from 5 to 13
029. set /a iMinWordLen=%random%%%(iMaxRange-iMinRange+1)+iMinRange
030.
031. :: Initialise array to hold help commands
032. for /f "delims==" %%a in ('set zCMD 2^>nul') do (set %%a=)
033.
034. :: Put all the commands from 'help' into array
035. set i=0&for /f %%a in ('help^|findstr /v /b /c:" "') do (
036. set/a i+=1&set zCMD!i!=%%a&(set iCMD=!i!)&%Progress%
037. )
038.
039. :Main Randomly decide which help cmd to use and store in sCMD
040. set /a i=%RANDOM%%%iCMD+1&call set sCMD=%%zCMD!i!%%
041.
042. :: Initialise array to hold the command helpscreen
043. for /f "delims==" %%a in ('set zLine 2^>nul') do (set %%a=)
044.
045. :: Put helpscreen into an array, rejecting lines containing % or "
046. set i=0&for /f "tokens=*" %%a in (
047. 'help %sCMD%^|findstr /v "[%%"""]"'
048. ) do (set /a i+=1&set zLine!i!="%%a")
049.
050. :: Randomly decide which line to use and store in sLine
051. set /a j=%RANDOM%%%%i%+1&call set sLINE=%%zLine!j!%%
052.
053. :: Change symbols to spaces to increase vocabulary
054. set sLine=%sLine:^= %
055. set sLine=%sLine:|= %
056. set sLine=%sLine:&= %
057. set sLine=%sLine:>= %
058. set sLine=%sLine:<= %
059. set sLine=%sLine:[= %
060. set sLine=%sLine:]= %
061. set sLine=%sLine:(= %
062. set sLine=%sLine:)= %
063. set sLine=%sLine:\= %
064. set sLine=%sLine:/= %
065. set sLine=%sLine:.= %
066. set sLine=%sLine::= %
067. set sLine=%sLine:,= %
068. set sLine=%sLine:"= %
069.
070. :: Load any suitable words in sLine into an array
071. %Progress%&set i=0&for %%a in (%sLine%) do (
072. set sWord=%%a&Call :GetStrLen iLen sWord
073. if !iLen! GEQ !iMinWordLen! (
074. call :IsWordAlpha !sWord!&&(
075. call :IsWordCommon !sWord!||(set /a i+=1&set zWord!i!=!sWord!)
076. )
077. )
078. )
079.
080. :: If no suitable words found choose another command
081. if %i% EQU 0 goto :Main
082.
083. :: Randomly decide which word to use and store in sWord
084. set /a j=%RANDOM%%%%i%+1&call set sWord=%%zWord!j!%%
085.
086. :: Convert chosen word to uppercase
087. call :WordToUpper sWord
088.
089. :: Make 'sSoFar' same length as 'sWord', but fill with dots
090. Call :GetStrLen iWordLen sWord
091. set sSoFar=&for /l %%a in (1,1,%iWordLen%) do (set sSoFar=!sSoFar!.)
092. set sHistory=&set iDone=0
093.
094. :Main.Loop
095. call :UpdateScreen %iGuesses% %sSoFar% %iWordLen% %iLevel% %sHistory%
096. call :GetChar sGuess "Guess a letter: "||(
097. echo/&echo/ INVALID INPUT^^!
098. echo/&echo/|set /p=^ Please any key to continue...&pause>nul
099. goto :Main.Loop
100. )
101. call :ProcessGuess sSoFar sHistory !sGuess! !sWord!||set /a iGuesses+=1
102. if !sWord! NEQ !sSoFar! if %iGuesses% LSS 10 goto :Main.Loop
103.
104. call :UpdateScreen %iGuesses% %sSoFar% %iWordLen% %iLevel% %sHistory%
105.
106. :: Level is finished, now decide what to do (fanfare, next level or quit)
107. if %iGuesses% LSS 10 (
108. if !iLevel! EQU 10 (
109. echo/ CONGRATULATIONS^^!&echo/
110. echo/ You've completed all the levels^^!
111. exit /b 0
112. ) ^
113. else (
114. set /a iLevel+=1
115. echo/&echo/ WELL DONE^^!&echo/
116. echo/|^set /p=^ Press any key to start level !iLevel!
117. pause >nul&goto :Start
118. )
119. ) else (
120. echo/ BAD LUCK^^! You reached level !iLevel!
121. echo/&echo/ The word was [%sWord%]
122. exit /b 1
123. )
124.
125. goto :EOF
126.
127. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
128. :ProcessGuess sSoFar sHistory !sGuess! !sWord!
129. ::
130. :: Func: Checks to see if the letter entered by the user is contained in
131. :: the word being guessed. The guess history (sHistory) is updated.
132. :: If guess is good, sSoFar is updated and true is returned, else
133. :: false returned. For 2K/XP.
134. ::
135. :: Args: %1 var containing correct guesses so for, this is updated (by ref)
136. :: %2 var containing guess history, this is updated (by ref)
137. :: %3 users guess, will always be a single uppercase letter (by val)
138. :: %4 the word being guessed (by val)
139. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
140. setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
141. for /f %%a in ('echo/%%%1%%') do set sSoFar=%%a
142. if defined %2 (for /f %%a in ('echo/%%%2%%') do set sHistory=%%a)
143. (set sTemp=)
144. set Word=%4&Call :GetStrLen i Word&set /a i-=1
145. md;2>nul&for /l %%a in (0,1,%i%) do (
146. set letter=!Word:~%%a,1!
147. if %3 EQU !letter! (
148. set sTemp=!sTemp!!letter!&ver>nul
149. ) else (set sTemp=!sTemp!!sSoFar:~%%a,1!)
150. )
151. endlocal&set %1=%sTemp%&set %2=%sHistory%%3&goto :EOF
152. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
153.
154. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
155. :GetChar cChar %sPrompt%
156. ::
157. :: Func: Gets input from user, removes any poison chars, trims leading and
158. :: trailing whitespace converts to uppercase and ignores anything
159. :: after first word. Returns true if result is a single character in
160. :: A-Z else returns false. For 2K/XP.
161. ::
162. :: Args: %1 var to receive character (by ref)
163. :: %2 var containing user input prompt (by val)
164. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
165. setlocal ENABLEEXTENSIONS
166. for /f "tokens=1*" %%a in ('echo/%*') do set sPrompt=%%b
167. call :GetSafeStr sBuf %sPrompt%
168. for /f %%a in ('echo/%sBuf%') do set sBuf=%%a
169. call :GetStrLen iLen sBuf&call :WordToUpper sBuf
170. md;2>nul&if %iLen% EQU 1 call :IsWordAlpha %sBuf%&&ver>nul
171. endlocal&set %1=%sBuf%&goto :EOF
172. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
173.
174. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
175. :GetSafeStr sBuf %sPrompt%
176. ::
177. :: Func: Gets input from user and removes any poison chars. For 2K/XP.
178. ::
179. :: Args: %1 var to receive user input (by ref)
180. :: %2 var containing user input prompt (by val)
181. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
182. setlocal ENABLEEXTENSIONS
183. for /f "tokens=1*" %%a in ('echo/%*') do set sBuf=&set sPrompt=%%~b
184. set /p sBuf=%sPrompt%&if not defined sBuf endlocal&set %1=&goto :EOF
185. set sBuf="%sBuf:"=%"
186. set sBuf=%sBuf:^=%
187. set sBuf=%sBuf:&=%
188. set sBuf=%sBuf:|=%
189. set sBuf=%sBuf:<=%
190. set sBuf=%sBuf:>=%
191. set sBuf=%sBuf:(=%
192. set sBuf=%sBuf:)=%
193. set sBuf=%sBuf:!=%
194. endlocal&set %1=%sBuf:~1,-1%&goto :EOF
195. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
196.
197. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
198. :GetStrLen len str
199. ::
200. :: Func: Returns length of a string. Function is tolerant of posion
201. :: characters if they have been correctly escaped. For NT4/2K/XP.
202. ::
203. :: Args: %1 var to receive length of string (by ref)
204. :: %2 var containing string to be measured (by ref)
205. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
206. setlocal ENABLEEXTENSIONS
207. call set str="%%%2%%"&set i=-4
208. set str="%str:"= %"
209. set str=%str:^= %
210. set str=%str:&= %
211. set str=%str:|= %
212. set str=%str:<= %
213. set str=%str:>= %
214. set str=%str:(= %
215. set str=%str:)= %
216. set str=%str:!= %
217. :GetStrLen.Loop
218. set /a i+=1&set str=%str:~1%
219. if defined str goto GetStrLen.Loop
220. endlocal&set %1=%i%&goto :EOF
221. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
222.
223. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
224. :WordToUpper sWord
225. ::
226. :: Func: Converts word (not string) in %1 to uppercase. For NT4/2K/XP.
227. ::
228. :: Args: %1 word to be converted to uppercase (by ref)
229. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
230. setlocal ENABLEEXTENSIONS
231. call set sWord=%%%1%%&if not defined sWord endlocal&goto :EOF
232. for /f "tokens=3 delims=:" %%a in ('fc :%%%1%%: : 2^>^&1') do set sUpp=%%a
233. endlocal&set %1=%sUpp%&goto :EOF
234. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
235.
236. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
237. :IsWordAlpha %word%
238. ::
239. :: Func: Tests if characters in %1 are all in range a-z, A-Z. If so
240. :: true is returned, else false. For NT4/2K/XP.
241. ::
242. :: Args: %1 word to be checked (by val)
243. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
244. setlocal ENABLEEXTENSIONS
245. if "%1"=="" endlocal&md;2>nul&goto :EOF
246. set "alphabet=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
247. ver>nul&for /f "delims=%alphabet%" %%a in ('echo/%1') do md;2>nul
248. endlocal&goto :EOF
249. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
250.
251. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
252. :UpdateScreen %stage% %sWord% %iWordLen% %iLevel% %sHistory%
253. ::
254. :: Func: Draws a hangman at specified stage
255. :: characters if they have been correctly escaped. For NT4/2K/XP.
256. ::
257. :: Args: %1 stage at which to draw hangman, 0 to 10 (by val)
258. :: %2 Correct guesses so far (by val)
259. :: %3 History of guesses (by val)
260. :: %4 Current level (by val)
261. :: %5 Length of word being guessed (by val)
262. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
263. setlocal ENABLEEXTENSIONS
264. (set sDATA=: ===== I +---+ (^
265. ) I II I /II I /II\ I / I /\ I )
266. set L1=0000000030303030303030&set L2=0000002020404040404040
267. set L3=0000002020205060707070&set L4=0000202020202020208090
268. set L5=0000202020202020202020&set L6=0010101010101010101010
269. cls&goto :UpdateScreen.Main
270. :UpdateScreen.Loop
271. set LN=%1&set /a STEP=%2*2
272. call set /a OFFSET=%%L%LN%:~%STEP%,2%%
273. call set DATA=%%sDATA:~%OFFSET%,10%%
274. set DATA=%DATA:I=^^^|%
275. echo%DATA%&goto :EOF
276. :UpdateScreen.Main
277. for /l %%a in (1,1,6) do call :UpdateScreen.Loop %%a %1
278. set /a iRemain=10-%1
279. echo/&echo/Word to guess: [%2] ^(%3 letters^)
280. echo/Guess history: [%5]&echo/Guesses left : [%iRemain%]
281. echo/Current level: [%4]&echo/
282. endlocal&goto :EOF
283. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
284.
285. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
286. :IsWordCommon %word%
287. ::
288. :: Func: Returns true if %1 is in list of the most commonly generated words
289. :: else returns false. For NT4/2K/XP.
290. ::
291. :: Args: %1 word to be checked (by val)
292. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
293. setlocal ENABLEEXTENSIONS
294. for %%a in (SPECIFIES DIRECTORY EXTENSIONS DISPLAYS COMMAND PARAMETERS ^
295. SPECIFIED DESTINATION INFORMATION FILENAME DRIVE ATTRIBUTES CHARACTERS ^
296. CURRENT ENVIRONMENT DIRECTORIES FILES PROCESSING ATTRIBUTE) do (
297. if /i %1==%%a endlocal&ver>nul&goto :EOF
298. )
299. endlocal&md;2>nul&goto :EOF
300. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Nut Cracker

unread,
Apr 29, 2003, 8:59:23 PM4/29/03
to
The problem for me (now that I have the line numbers correct) occurs in the
block that begins with this at line 263:

setlocal ENABLEEXTENSIONS


(set sDATA=: ===== I +---+ (^

) I II I /II I /II\ I / I /\ I )


if i put the line 'echo bob' and 'echo bob 2' like such:

setlocal ENABLEEXTENSIONS
echo bob


(set sDATA=: ===== I +---+ (^

) I II I /II I /II\ I / I /\ I )

echo bob 2

and leave all else the same... this is the output (using the .bat extention)
from the cmd.exe prompt:

Loading........................
...line 94
bob


I was unexpected at this time.

C:\>

It seems that for some reason, my computer does not liek the "set sDATA=: "
portion of this block...

Just thought i would share...

NuTs

<snipped to save bandwidth and space>


Jim Robinson

unread,
Apr 30, 2003, 1:56:03 AM4/30/03
to
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in
news:b8bear$8be10$1...@ID-156657.news.dfncis.de:

> Test your batch vocabulary with batch Hangman. The rules are

<snip>

Ritchie,
You should see what the script looks like through groups.google.com.
Here's the first line that gets mangled (displayed as all one line):


:: Check current cmd interpreter is Windows 2000 or higher if not
CMDEXTVERSION 2 (

Then it gets weird. I got most of it figured out, the labels get
appended to the :::... separator lines, etc, but couldn't get the
counter to work or the hungman to render. BTW, it looks the same in
IE6 SP1 and Mozilla 1.something.

So I had to check it out at home with a newsreader and it works as
expected. Who says you can't do anything worthwile with the NT
shell!

Nice work!


--
Jim Robinson

Without a dot before the at, that's my
address and I'm sticking to it.

Ritchie

unread,
Apr 30, 2003, 2:54:12 AM4/30/03
to
"Jim Robinson" <jim....@ix.netcom.com> wrote in message news:b8nohj$19c$1...@slb0.atl.mindspring.net...

> You should see what the script looks like through groups.google.com.
> Here's the first line that gets mangled (displayed as all one line):
> :: Check current cmd interpreter is Windows 2000 or higher if not
> CMDEXTVERSION 2 (

Point taken. If Google is used to view the post in its 'original
format', then it does bear a close resemblance to what was posted.

Several lines now have a leading space (with doesn't affect the
scripts function). And notably, the colons that indicate the routine
label names have been stripped. Obviously this does affect the scripts
functionality. After replacing the colons, the file compares ok.

> Then it gets weird. I got most of it figured out, the labels get
> appended to the :::... separator lines, etc, but couldn't get the

See above, it certainly appears that way at first glance. They have
actually been removed by Google. Count the colons or note that ALL
the separator lines are the same length (75 colons) instead of some
being 75 and others 76.

> counter to work or the hungman to render. BTW, it looks the same in
> IE6 SP1 and Mozilla 1.something.

I used IE5.5, I also tried WGET but got an error: "ERROR 403: Forbidden"

> So I had to check it out at home with a newsreader and it works as
> expected. Who says you can't do anything worthwile with the NT
> shell!

If anyone else is trying to run the script from Google, it was posted
again about 8 hours ago, this time with line numbers which appears to
have preserved the formatting. Here's a link to it:

http://groups.google.com/groups?selm=b8mvir%24blne5%241%40ID-156657.news.dfncis.de&output=gplain

Thanks Jim,
--
Ritchie


Ritchie

unread,
Apr 30, 2003, 3:44:04 AM4/30/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:e3AfOPrD...@TK2MSFTNGP10.phx.gbl...

> setlocal ENABLEEXTENSIONS
> echo bob
> (set sDATA=: ===== I +---+ (^
> ) I II I /II I /II\ I / I /\ I )
> echo bob 2
>
> and leave all else the same... this is the output (using the .bat extention)
> from the cmd.exe prompt:
>
> Loading........................
> ...line 94
> bob
> I was unexpected at this time.

I thought you were done with this one, just couldn't put it down eh? :))

Whats happened is that you have leading space in front of the opening
bracket in line 265.

This is what you have:-

264. (set sDATA=: ===== I +---+ (^
265. ) I II I /II I /II\ I / I /\ I )

This is what line 265 needs changing to:-

264. (set sDATA=: ===== I +---+ (^
265. ) I II I /II I /II\ I / I /\ I )

HTH. Thanks for hanging in there.

--
Ritchie


Nut Cracker

unread,
Apr 30, 2003, 11:35:40 AM4/30/03
to
I thought i was done too... but the puzzle is just interesting to walk away
from... I am sure you know what i am talking about ; )
'
actually... there a zillion spaces since the code I was using preserved the
tabs...

I think i will write a little perl file that yanks the tabs (a little
s/\t//; ) or something....

will let you know what happens..

NuTs

"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8nusa$bsf3b$1...@ID-156657.news.dfncis.de...

Nut Cracker

unread,
Apr 30, 2003, 11:51:39 AM4/30/03
to
actually... the tabs were not preserved... they were converted to blank
spaces...

since the script needs to have a certain number of blank spaces, i am really
not in the mood to come up with a regex that can tell the difference between
the ones that need to be there and the ones that dont need to be there.

I will take a different approach..

NuTs


"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message

news:e4jZ64yD...@TK2MSFTNGP12.phx.gbl...

Nut Cracker

unread,
Apr 30, 2003, 12:10:35 PM4/30/03
to
For those that are interested... this tiny perl script rips all the numbers
and leading spaces out of the lines:


open(HM2, ">>c:/hm3.bat");
open(HM, "c:/hangman.bat");
while (defined($line=<HM>)) {
$line =~ (s/^\d{3}.\s//ig);
select (HM2);
print "$line";
}


its a very easy way to de-linenumber scirpts...

NuTs

"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message

news:%23Udi2Bz...@TK2MSFTNGP11.phx.gbl...

Nut Cracker

unread,
Apr 30, 2003, 12:11:09 PM4/30/03
to
AND WITH THAT I GOT THE THING TO WORK !!!!!!


woooo hoooo!!!!


NuTs


"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message

news:%23Udi2Bz...@TK2MSFTNGP11.phx.gbl...

Musafir

unread,
Apr 30, 2003, 3:25:46 PM4/30/03
to
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message news:<b8mvir$blne5$1...@ID-156657.news.dfncis.de>...

> "Musafir" <bh...@mailcity.com> wrote in message news:ddfbb7a7.03042...@posting.google.com...
> > Ritchie - how about running your line number program on it and
> > re-posting it? That will make it easy for readers to get rid of the
> > spurious line wraps thrown in by newsreaders.
>
> Good idea (see below). I don't normally number my posted scripts,
> because I can't think anything worse that unnumbering them (slight
> exageration).

Since this script is Win2K+, you might post an 'Un-number script' to
go with it ;-)

:::::: Begin UnNumber.cmd
@echo off&setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%a in (t1.txt) do (
set line=%%a
@echo !line:~5!
)
:::::: End UnNumber.cmd

Oh yes, leave UnNumber.cmd un-numbered!!

> BTW when a cut'n'paste from my original post and compare it with
> the original script, there are no differences - I use Outlook
> Express 5.5.

I use google. Google tries to 'undo' line wrappings and in the process
messes up your scripts. This is one of the rare places where Google
errs. But, as you mentioned, the Original Format offers something to
go with. Line Numbering fixes it great!

> Every day's a school day! BAT and CMD definetaly are not equal.

Good catch!

Ritchie

unread,
Apr 30, 2003, 4:45:16 PM4/30/03
to
"Nut Cracker" <nutcr...@internationalhacker.org> wrote in message news:OcOevMzD...@TK2MSFTNGP10.phx.gbl...

> AND WITH THAT I GOT THE THING TO WORK !!!!!!

WELL DONE that man! I hope it was worth it.

--
Ritchie


Nut Cracker

unread,
Apr 30, 2003, 5:01:10 PM4/30/03
to
its a fun little program... nice work.

Now... can you create a version of "drug wars" that runs as a .bat or .cmd
file?

lol...

NuTs


"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message

news:b8pcl0$c2tgu$1...@ID-156657.news.dfncis.de...

Ritchie

unread,
Apr 30, 2003, 6:08:32 PM4/30/03
to
"Musafir" <bh...@mailcity.com> wrote in message news:ddfbb7a7.03043...@posting.google.com...

> Since this script is Win2K+, you might post an 'Un-number script' to
> go with it ;-)

One day (maybe soon) I'll get round to writing a single script that
numbers and de-numbers scripts. It'll probably support redirection
of stdin/stdout to make it slighty more useful.

> :::::: Begin UnNumber.cmd
> @echo off&setlocal ENABLEDELAYEDEXPANSION
> for /f "tokens=*" %%a in (t1.txt) do (
> set line=%%a
> @echo !line:~5!
> )
> :::::: End UnNumber.cmd

He-he, if only it was that simple - if that works, I'll eat my hat :)

--
Ritchie


Phil Robyn

unread,
May 1, 2003, 12:29:21 PM5/1/03
to

Well, it's not *quite* that simple. :-) Ideally, you would want a process that
recognizes the length of the number-plus-separator. Hard-coding '5' will yield
proper results only for files where the number-plus-separator string is 'nnn. '.
So a file of fewer than 100 lines or more than 999 lines will not be 'unnumbered'
correctly.

Here's another alternative to remove line numbers:

Assuming that 'Quick edit' mode is checked for your CMD window, and that your
CMD window has been flexibly set to scroll backwards and wide enough to display
the file without line wrapping ('mode con lines=5000 cols=140'):

- type the numbered file

- use the mouse to highlight (select) the content of the file
excluding the line numbers and separators and copy it to the
Windows clipboard

- issue the command 'copy con (new file name) >nul'

- paste from the clipboard

- press <F6> to add an EOF character

- press <Enter> to complete the 'copy con' operation.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Nut Cracker

unread,
May 1, 2003, 1:40:58 PM5/1/03
to
I know this isnt necessarily a command line solution, but this works
regardless of the number of digits (as long as it is followed by a "." and a
white character (spaces), then 001. or 1. or 100000. will all be stripped
successfully):

open(HM2, ">>c:/hm3.bat");
open(HM, "c:/hangman.bat");

select (HM2);
while (defined($line=<HM>)) {
$line =~ (s/^\d{.}.\s//ig); 'any number of digits with a . and
space will be removed
print "$line";
}

Its pretty clean and has great flexability through the handling of the
regular experssion.

NuTs

BTW: this is written in PERL....


"Phil Robyn" <zipp...@uclink.berkeley.edu> wrote in message
news:OtS3l4$DDHA...@TK2MSFTNGP12.phx.gbl...

Musafir

unread,
May 1, 2003, 6:51:59 PM5/1/03
to
Phil Robyn <zipp...@uclink.berkeley.edu> wrote in message news:<OtS3l4$DDHA...@TK2MSFTNGP12.phx.gbl>...
> Ritchie wrote:
> > "Musafir" <bh...@mailcity.com> wrote in message news:ddfbb7a7.03043...@posting.google.com...
> >
> >>Since this script is Win2K+, you might post an 'Un-number script' to
> >>go with it ;-)
> >
> >
> > One day (maybe soon) I'll get round to writing a single script that
> > numbers and de-numbers scripts. It'll probably support redirection
> > of stdin/stdout to make it slighty more useful.
> >
> >
> >>:::::: Begin UnNumber.cmd
> >>@echo off&setlocal ENABLEDELAYEDEXPANSION
> >>for /f "tokens=*" %%a in (t1.txt) do (
> >>set line=%%a
> >>@echo !line:~5!
> >>)
> >>:::::: End UnNumber.cmd
> >
> > He-he, if only it was that simple - if that works, I'll eat my hat :)
> >
> > --
> > Ritchie
> >
>
> Well, it's not *quite* that simple. :-) Ideally, you would want a process that
> recognizes the length of the number-plus-separator. Hard-coding '5' will yield
> proper results only for files where the number-plus-separator string is 'nnn. '.
> So a file of fewer than 100 lines or more than 999 lines will not be 'unnumbered'
> correctly.

While that is one of the problem with this scriptlet, the bigger
hurdle I see (to be honest, after Ritchie's comment) is that it
gobbles up the '!' character. Can anyone think of a way to escape the
'!' mark (convert it to a '^^!')? This is one of the several things I
have tried without success:

@echo off&setlocal ENABLEDELAYEDEXPANSION

for /f "tokens=*" %%a in (%1) do (
set line=%%a
@echo set line=!line:^^!=^^^^^!!
@echo !line:~4!
)

> Here's another alternative to remove line numbers:
>
> Assuming that 'Quick edit' mode is checked for your CMD window, and that your
> CMD window has been flexibly set to scroll backwards and wide enough to display
> the file without line wrapping ('mode con lines=5000 cols=140'):
>
> - type the numbered file
>
> - use the mouse to highlight (select) the content of the file
> excluding the line numbers and separators and copy it to the
> Windows clipboard
>
> - issue the command 'copy con (new file name) >nul'
>
> - paste from the clipboard
>
> - press <F6> to add an EOF character
>
> - press <Enter> to complete the 'copy con' operation.

Quick, working solution for most scripts posted here!

Phil Robyn

unread,
May 1, 2003, 8:05:01 PM5/1/03
to

Here's a solution utilizing QBASIC:

=====begin C:\cmd\demo\RemoveLineNumbers.cmd====================
01. @echo off
02. ::
03. :: remove line numbers from left of each record and change '===begin'
04. :: and '===end' lines to comments
05. ::
06. ::
07. if [%1]==[] goto :syntax
08. if [%2]==[] goto :syntax
09. if not exist %1 goto :nofile
10. set INFILE=%~sf1
11. set OUTFILE=%2
12. echo>%temp%\stripnum.bas DIM inrec AS STRING, infile AS STRING, outfile AS STRING
13. echo>>%temp%\stripnum.bas infile = ENVIRON$("INFILE")
14. echo>>%temp%\stripnum.bas outfile = "%temp%\qbstrip.out"
15. echo>>%temp%\stripnum.bas OPEN infile FOR INPUT AS #1
16. echo>>%temp%\stripnum.bas OPEN outfile FOR OUTPUT AS #2
17. echo>>%temp%\stripnum.bas DO WHILE NOT EOF(1)
18. echo>>%temp%\stripnum.bas LINE INPUT #1, inrec
19. echo>>%temp%\stripnum.bas IF LEFT$(inrec, 5) = "=====" THEN
20. echo>>%temp%\stripnum.bas inrec = " :: " + inrec
21. echo>>%temp%\stripnum.bas END IF
22. echo>>%temp%\stripnum.bas inrec = MID$(inrec, INSTR(inrec, " ")+1)
23. echo>>%temp%\stripnum.bas PRINT #2, inrec
24. echo>>%temp%\stripnum.bas LOOP
25. echo>>%temp%\stripnum.bas CLOSE
26. echo>>%temp%\stripnum.bas SYSTEM
27. start /min /wait command /c QBASIC /run %temp%\stripnum.bas
28. if exist %outfile% del %outfile%
29. move %temp%\qbstrip.out %outfile% > nul
30. goto :EOF
31. :nofile
32. echo Cannot find input file %1. Please check the file name and try again.
33. :syntax
34. echo Removes line numbers and changes '===begin' and '===end' lines to comments.
35. echo.
36. echo %0 ^<input file^> ^<output file^>
37. goto :EOF
=====end C:\cmd\demo\RemoveLineNumbers.cmd====================

Here's essentially the same thing using Rexx (no batch file needed):

=====begin c:\rexx\RemoveLineNumbers.rexx====================
01. /* Rexx - remove line numbers and lines beginning with '=====' */
02. parse arg infile outfile
03. if stream(infile, 'C', 'QUERY EXISTS') = ''
04. then do
05. say 'File' infile 'does not exist.'
06. exit
07. end
08. if outfile = ''
09. then outfile = 'c:\temp\RexxUnnum.txt'
10. cmd = 'type' infile
11. rc = popen(cmd,"lines.")
12. do x = 1 to lines.0
13. if substr(lines.x, 1, 5) <> '====='
14. then rc = lineout(outfile, substr(lines.x, index(lines.x,'. ')+2))
15. end
=====end c:\rexx\RemoveLineNumbers.rexx====================

Ritchie

unread,
May 2, 2003, 8:09:13 AM5/2/03
to
"Phil Robyn" <zipp...@uclink.berkeley.edu> wrote in message news:OtS3l4$DDHA...@TK2MSFTNGP12.phx.gbl...
> Well, it's not *quite* that simple. :-) Ideally, you would want a process that
> recognizes the length of the number-plus-separator. Hard-coding '5' will yield

Thats a good idea, and is likely to be the simplest way to de-number
a script for most. I'm just about to post a numbering and de-numbering
script, so your method could be used to de-number that!

--
Ritchie


Phil Robyn

unread,
May 2, 2003, 1:32:42 PM5/2/03
to

Hi, Ritchie,

Saw your number and de-number script -- great job! Of course, any text
editor that does column blocks is also great for removing line numbers.
I recommend TextPad (shareware) from http://www.textpad.com.

Musafir

unread,
May 5, 2003, 2:38:01 PM5/5/03
to
Phil Robyn <zipp...@uclink.berkeley.edu> wrote in message news:<#wefnDNE...@TK2MSFTNGP12.phx.gbl>...
> Ritchie wrote:
...

> > Thats a good idea, and is likely to be the simplest way to de-number
> > a script for most. I'm just about to post a numbering and de-numbering
> > script, so your method could be used to de-number that!
> >
> > --
> > Ritchie
>
> Hi, Ritchie,
>
> Saw your number and de-number script -- great job! Of course, any text
> editor that does column blocks is also great for removing line numbers.
> I recommend TextPad (shareware) from http://www.textpad.com.

Very professional job on the script Ritchie. Thanks! The first one for
our (dream) FREE NT Shell Scripts collection :)

Phil - another way to achieve the same effect in Textpad is to use the
regexp search/replace:
1) Replace expression ^[[:digit:]]*\.\s with (nothing)
2) Replace expression ^[[:digit:]]*\. with (nothing)

Your technique is quicker for small scripts. This might be handy for
longer scripts.

0 new messages