home *** CD-ROM | disk | FTP | other *** search
/ CBM Funet Archive / cbm-funet-archive-2003.iso / cbm / c128 / os / cs-dos / cs-batch.sfx / batchfiles.txt next >
Encoding:
Text File  |  1990-02-12  |  4.1 KB  |  115 lines

  1. Additional Help on CS-DOS Batch Files
  2. Things the docs don't tell ya'
  3. 2/14/93
  4. Randy Winchester
  5.  
  6. Here are a few pointers and suggestions about constructing CS-DOS batch
  7. files that were learned the hard way.  Many of them weren't obvious from
  8. reading CS-DOS documentation.  Some are probably just quirky little things
  9. that even Chris Smeets didn't even know about anyway.  I'll basically just
  10. pick apart some commands from a few of the batch files in this collection.
  11.  
  12. First, here's the batch file CD (because it's short) with a few added
  13. coments:
  14.  
  15. pushdir
  16.  
  17.   This saves the logged drive.  Other drives can then be logged by the
  18.   batch file, and the original logged drive restored with popdir.
  19.  
  20. if "%1"=" "goto noarg
  21.  
  22.   %1 refers to the first parameter of the command tail.  If there is no
  23.   command tail, a space is returned, not a null string.
  24.  
  25. x$="%1"
  26.  
  27.   Command tail parameters can be assigned to other strings, x$ in this
  28.   case.  Any time a command parameter is compared to a string or assigned
  29.   to a variable, it must be surrounded by double quotes.
  30.  
  31. if mid$(x$,2,1)=":"then a=asc(x$):sys5888,a:x$=mid$(x$,3,len(x$)-2)
  32.  
  33.   This line is pure BASIC 7.0.  It looks at x$ to see if the second
  34.   character is a colon.  If so, the first character must be a drive letter.
  35.   The CS-DOS routine at 5888 takes the ASCII value of the character in the
  36.   variable "a" and logs it as the new drive.  The remainder of the line
  37.   strips first two characters from x$.
  38.  
  39. poke7136,0:if x$="/"then poke7136,1
  40. if errorlevel 1 goto root
  41.  
  42.   This little subterfuge is necessary because CS-DOS and BASIC commands
  43.   don't mix well.  It checks x$ to see if it is equal to the "/" character
  44.   used for specifying the root directory.  Unfortunately, a line like:
  45.        if x$="/" goto root
  46.   doesn't work.  To get around this, the CS-DOS errorlevel is cleared by
  47.   poking it with a 0.  Then if x$="/" set errorlevel to one by poking it
  48.   with 1.  (Errorlevel is located at 7136).  The second line checks
  49.   errorlevel, and goes to the lable root if x$ was equal to "/".
  50.  
  51. >/%1
  52. goto done
  53.  
  54.   This uses the CS-DOS shell's wedge to open the subdirectory named in the
  55.   command tail.  You have to be especially careful using the wedge ">"
  56.   character in a batch file because unless it is the first character on a
  57.   line, it can be mistaken for the output redirection ">" character.
  58.  
  59. :root
  60. >/
  61. goto done
  62.  
  63.   Labels are always preceeded by a ":" and must start in the first column
  64.   of the line.  If a label is preceeded by a space or other character, it
  65.   won't be found.
  66.  
  67. :noarg
  68. echo Syntax: %0 [d:] directory
  69.  
  70.   The %0 parameter echos the name of the command itsself, in this case, cd.
  71.   If the name of the command is changed, that is, if cd is renamed, the new
  72.   will show up on the Syntax summary.
  73.  
  74. :done
  75. popdir
  76.  
  77.   Popdir restores the drive that was logged when the batch file was run.
  78.  
  79.   The following tidbit is the entire string search routine from the dex
  80.   batch file:
  81.  
  82. if exist dex.txt grep -y %1 dex.txt
  83. if exist dex.txt goto done
  84. sys5888,90
  85. if exist dex.txt grep -y %1 dex.txt
  86. if not exist dex.txt goto notfound
  87. goto done
  88.  
  89.   If the file DEX.TXT is present on the logged drive, then GREP is used to
  90.   to search for the string that was given on the command line.  If DEX.TXT
  91.   wasn't found, the routine falls through to sys5888,90 to log the boot
  92.   drive (drive z), and try again.  If DEX.TXT still isn't found, code after
  93.   the label "notfound" lets the user know that the file isn't there.
  94.  
  95.   The next three lines appear in the batch file MAN:
  96.  
  97. echo " Manual for "%1" "
  98. ?chr$(27)"t"
  99. char0,0,20,"",0
  100.  
  101.   You can include control characters such as HOME, CLR, Switch to Lower
  102.   Case, and Rvs On, with the echo command if you preceed them with a
  103.   a double quote.  Complex screen formatting is possible by printing ESC
  104.   sequences for windowing, and positioning the cursor with the CHAR
  105.   command.
  106.  
  107. lhx -p %1.lzh"
  108.  
  109.   This was just plain quirky!  The LHX command couldn't successfully do
  110.   the requested pattern matching when included in a batch file unless it
  111.   followed by a double quote.  I don't remember how I finally figured that
  112.   out, but it wouldn't work any other way.
  113.  
  114.  
  115.