home *** CD-ROM | disk | FTP | other *** search
- Additional Help on CS-DOS Batch Files
- Things the docs don't tell ya'
- 2/14/93
- Randy Winchester
-
- Here are a few pointers and suggestions about constructing CS-DOS batch
- files that were learned the hard way. Many of them weren't obvious from
- reading CS-DOS documentation. Some are probably just quirky little things
- that even Chris Smeets didn't even know about anyway. I'll basically just
- pick apart some commands from a few of the batch files in this collection.
-
- First, here's the batch file CD (because it's short) with a few added
- coments:
-
- pushdir
-
- This saves the logged drive. Other drives can then be logged by the
- batch file, and the original logged drive restored with popdir.
-
- if "%1"=" "goto noarg
-
- %1 refers to the first parameter of the command tail. If there is no
- command tail, a space is returned, not a null string.
-
- x$="%1"
-
- Command tail parameters can be assigned to other strings, x$ in this
- case. Any time a command parameter is compared to a string or assigned
- to a variable, it must be surrounded by double quotes.
-
- if mid$(x$,2,1)=":"then a=asc(x$):sys5888,a:x$=mid$(x$,3,len(x$)-2)
-
- This line is pure BASIC 7.0. It looks at x$ to see if the second
- character is a colon. If so, the first character must be a drive letter.
- The CS-DOS routine at 5888 takes the ASCII value of the character in the
- variable "a" and logs it as the new drive. The remainder of the line
- strips first two characters from x$.
-
- poke7136,0:if x$="/"then poke7136,1
- if errorlevel 1 goto root
-
- This little subterfuge is necessary because CS-DOS and BASIC commands
- don't mix well. It checks x$ to see if it is equal to the "/" character
- used for specifying the root directory. Unfortunately, a line like:
- if x$="/" goto root
- doesn't work. To get around this, the CS-DOS errorlevel is cleared by
- poking it with a 0. Then if x$="/" set errorlevel to one by poking it
- with 1. (Errorlevel is located at 7136). The second line checks
- errorlevel, and goes to the lable root if x$ was equal to "/".
-
- >/%1
- goto done
-
- This uses the CS-DOS shell's wedge to open the subdirectory named in the
- command tail. You have to be especially careful using the wedge ">"
- character in a batch file because unless it is the first character on a
- line, it can be mistaken for the output redirection ">" character.
-
- :root
- >/
- goto done
-
- Labels are always preceeded by a ":" and must start in the first column
- of the line. If a label is preceeded by a space or other character, it
- won't be found.
-
- :noarg
- echo Syntax: %0 [d:] directory
-
- The %0 parameter echos the name of the command itsself, in this case, cd.
- If the name of the command is changed, that is, if cd is renamed, the new
- will show up on the Syntax summary.
-
- :done
- popdir
-
- Popdir restores the drive that was logged when the batch file was run.
-
- The following tidbit is the entire string search routine from the dex
- batch file:
-
- if exist dex.txt grep -y %1 dex.txt
- if exist dex.txt goto done
- sys5888,90
- if exist dex.txt grep -y %1 dex.txt
- if not exist dex.txt goto notfound
- goto done
-
- If the file DEX.TXT is present on the logged drive, then GREP is used to
- to search for the string that was given on the command line. If DEX.TXT
- wasn't found, the routine falls through to sys5888,90 to log the boot
- drive (drive z), and try again. If DEX.TXT still isn't found, code after
- the label "notfound" lets the user know that the file isn't there.
-
- The next three lines appear in the batch file MAN:
-
- echo " Manual for "%1" "
- ?chr$(27)"t"
- char0,0,20,"",0
-
- You can include control characters such as HOME, CLR, Switch to Lower
- Case, and Rvs On, with the echo command if you preceed them with a
- a double quote. Complex screen formatting is possible by printing ESC
- sequences for windowing, and positioning the cursor with the CHAR
- command.
-
- lhx -p %1.lzh"
-
- This was just plain quirky! The LHX command couldn't successfully do
- the requested pattern matching when included in a batch file unless it
- followed by a double quote. I don't remember how I finally figured that
- out, but it wouldn't work any other way.
-
-
-