home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / 4dos / samples.btm < prev    next >
Text File  |  1993-11-23  |  14KB  |  517 lines

  1. @echo off
  2. cls
  3. echo %@upper[%0]:
  4. text
  5.  
  6.      This file contains several sample batch files.  We invite you to study
  7.      them in conjunction with your 4DOS manual and documentation. You may
  8.      want to PRINT or LIST the contents and modify any part you wish. The
  9.      various segments are separated from each other by a line of hyphens
  10.      ("-") so you can easily extract the specific component you're most
  11.      interested in.
  12.  
  13.      Included are:
  14.  
  15.        STATUS.BTM    - Gives a quick description of your system.
  16.        4MENU.BTM     - A very simple menuing system.
  17.        ONCEADAY.BTM  - Runs a command during the first boot of the day.
  18.      * FRAC.BTM      - Computes the fractional part of a number
  19.      * HMENU.BTM     - A powerful menuing system which you must customize
  20.                        for your system.
  21.      * WHICH.BTM     - Ready to use convenient way to detect "WHICH" process
  22.                        (internal command, alias, executable extension,
  23.                        external command, or batch file) is run when you
  24.                        invoke a command.
  25.  
  26.    * Note: These three batch files were originally contributed by long-time 
  27.            4DOS user and supporter Ray Tackett. Thanks, Ray!
  28. endtext
  29. pause
  30.  
  31. : ---------------------------------------------------------------------
  32. rem STATUS.BTM
  33. rem
  34. rem      This sample batch file will use some internal 4DOS variable
  35. rem      functions to try to describe your current configuration.
  36. rem
  37. cls
  38. echo.^echo.
  39. echo System status:
  40. echo.
  41. echo Date: %_dow %_date
  42. echo Time: %_time
  43. echo 4DOS version: %_4ver
  44. echo OS: %_dos
  45. echo DOS version: %_dosver
  46. echos `CPU: `
  47. iff %_cpu == 86 then
  48.   echo 8088/8086
  49. elseiff %_cpu == 186 then
  50.   echo 80188/80186
  51. elseiff %_cpu == 200 then
  52.   echo V20/V30
  53. elseiff %_cpu == 286 then
  54.   echo 80286
  55. elseiff %_cpu == 386 then
  56.   echo 80386
  57. elseiff %_cpu == 486 then
  58.   echo 80486
  59. endiff
  60. if %_ndp ne 0 echo %_ndp Numeric Coprocessor detected
  61. echo Video: %_video
  62. echo Monitor type: %_monitor
  63. quit
  64.  
  65.  
  66. : ---------------------------------------------------------------------
  67. : 4MENU.BTM
  68. :      This sample batch file will create a simple "menu" to run
  69. :      your commonly used programs.
  70. :
  71. :      Note that, instead of REM statements, it uses the alternative
  72. :      practice of creating "do-nothing" labels by starting comment
  73. :      lines such as this one with a ":"
  74. :
  75. @echo off
  76. :      First, we define a couple of aliases which will be used several
  77. :      times in the remainder of this batch file, after first saving
  78. :      any existing alias by the same name with the SETLOCAL command.
  79. setlocal
  80. alias in `pushd %1 ^ %2& ^ popd`
  81. alias choice `elseiff "%userchoice" == "%1" then`
  82. :
  83. :       Start with a clear screen
  84. cls
  85. :dispmenu
  86. :       Position the cursor
  87. screen 8 0
  88. :       Display the menu choices
  89. text
  90.  
  91.  Enter your choice:
  92.  
  93.       0. EXIT
  94.       1. Word Processing
  95.       2. Spreadsheet
  96.       3. Communications
  97.  
  98. endtext
  99. :      Ask the user to enter a value for environment variable CHOICE
  100. inkey Which? %%userchoice
  101. :      Does the user want to exit the menu?
  102. iff "%userchoice" == "0" then ^ quit
  103. :      Check the valid options
  104. :      Each line correspond to a menu choice
  105. :      The paranmeters are a directory to go to, then the program to run
  106.   choice 1 ^ in c:\letters c:\ws\ws.exe
  107.   choice 2 ^ in d:\finance c:\quattro\q.exe
  108.   choice 3 ^ in c:\comm    c:\procomm\pcplus.exe /fprofile
  109. else
  110. :      The user entered an invalid option
  111.   scrput 23 0 bri whi on red Invalid choice, try again
  112. endiff
  113. :      Loop back to the beginning
  114. goto dispmenu
  115.  
  116.  
  117. : ---------------------------------------------------------------------
  118. : ONCEADAY.BTM
  119. @echo off
  120. :
  121. :       This batch file will start a specified command the first time it
  122. :       called each day after 6:00 in the morning
  123. :       example:
  124. :               ONCEADAY DEFRAG C:
  125. :
  126. :      Note that, instead of REM statements, it uses the alternative
  127. :      practice of creating "do-nothing" labels by starting comment
  128. :      lines such as this one with a ":"
  129. :
  130. :
  131. :       First, we reset environment variable LASTDATE after saving any
  132. :       current value it may already have with the SETLOCAL command
  133. setlocal
  134. set lastdate=0
  135. :       Is there already a file called ONCEADAY.DAT in the
  136. :       root directory of the boot drive?
  137. iff exist %_boot:\onceaday.dat then
  138. :       If so, set LASTDATE to the contents of the first line
  139.   set lastdate=%@line[%_boot:\onceaday.dat,0]
  140. endiff
  141. :       Is the date in the file greater than today's date?
  142. :       (the @DATE function turns a date into an integer number)
  143. iff %@date[%_date] gt %lastdate then
  144. :       If so, is it currently past 6:00? (an arbitrary time)
  145.   iff %@time[%_time] gt %@time[06:00] then
  146. :       Yes! Invoke whatever command was passed as an argument to this
  147. :       batch file, then return
  148.     call %&
  149. :       After executing the command, place today's date in integer
  150. :       format into file ONCEADAY.DAT
  151.     echo %@date[%_today] >! %_boot:\onceaday.dat
  152.   endiff
  153. endiff
  154. :
  155.  
  156.  
  157. : ---------------------------------------------------------------------
  158. : FRAC.BTM
  159. @echo off
  160. rem 4DOS provides an internal function, @int[], but not a way
  161. rem to get the fractional part of a number.  Here's a tool.
  162. rem This is also a simple illustration of modifying an environment
  163. rem variable whose name is passed in.
  164.  
  165. rem The key lesson in this example is the use and modification of
  166. rem the VALUE of a variable given its NAME in %1.
  167.  
  168. rem This .btm is meant to be CALLed from another batch file.
  169. rem
  170. if "%1" == "" .or. "%[%1]" == "" goto help
  171. rem  !                !
  172. rem  !                The VALUE of variable "name"
  173. rem  The NAME of a variable
  174.  
  175.  
  176. rem The following sets the given variable to the fractional part.
  177. rem Note the function nesting.
  178.  
  179. rem The third argument of @substr is omitted, referring to the rest
  180. rem of the string by default [4DOS 4.0 enhancement]
  181.  
  182. rem The length of the integer portion is used as the offset into the
  183. rem string to begin and extract the fraction portion.
  184.  
  185. set %1=%@substr[%[%1],%@len[%@int[%[%1]]]]
  186. :exit
  187. quit 0
  188.  
  189. :help
  190. rem
  191. rem  Note the use of the name of the command the user typed, even
  192. rem  though this .btm file may have been renamed.
  193. rem
  194. echo Usage: %@name[%0]  var
  195. echo.
  196. echo   var =  Any environment variable whose value is the input
  197. echo New value returned in var, replacing original value.
  198. echo New value is the fraction portion of a floating point value.
  199. echo Example: set foo=12.345
  200. echo          %@name[%0] foo
  201. echo          set foo
  202. echo          .345
  203. quit 4
  204.  
  205.  
  206. : ---------------------------------------------------------------------
  207. :  HMENU.BTM
  208.  
  209. rem This batch file will NOT run on your system without modification, and
  210. rem is provided as an example only.
  211.  
  212. @echo off
  213. cd d:\
  214. cd c:\
  215. set lastx=0
  216. set lasty=0
  217. :start
  218. unset thingie tofile fromfile wtf>& nul
  219. cls
  220. drawbox 0 0 24 79 2 white on blue fill blue
  221. scrput 2  8 white on blue --------- Function Keys ------   ------ Shift Function Keys ------
  222. scrput 3  8 white on blue f1  Kings                        *f1  Gomoku
  223. scrput 5  8 white on blue f2  Show document directory      *f2  Communications
  224. scrput 7  8 white on blue f3  Manual command               *f3  First Publisher
  225. scrput 9  8 white on blue f4  Edit a document              *f4  Shooting gallery
  226. scrput 11 8 white on blue f5  Mahjongg                     *f5  Breakout
  227. scrput 13 8 white on blue f6  Solitare                     *f6  Reset Trackball
  228. scrput 15 8 white on blue f7  Copy a file                  *f7  DB3+
  229. scrput 17 8 white on blue f8  Envelope on Daisy Wheel      *f8  Epson printer page eject
  230. scrput 19 8 white on blue f9  Epson printer reset          *f9  Super Fly
  231. scrput 21 8 white on blue f10 DOS Environment              *f10 Shut down system
  232. iff "%lastx%" ne "0" then^scrput %lasty% %lastx% bright white on blue @^endiff
  233. rem drawvline 0 39 25 1 white on blue
  234. :timeloop
  235. screen 0 0
  236. scrput 1 30 white on blue %_date   %_time
  237. inkey /w1 %%WTF
  238. if "%WTF%" == "" goto timeloop
  239. rem
  240. if %WTF% == @59 goto dof1
  241. if %WTF% == @60 goto dof2
  242. if %WTF% == @61 goto dof3
  243. if %WTF% == @62 goto dof4
  244. if %WTF% == @63 goto dof5
  245. if %WTF% == @64 goto dof6
  246. if %WTF% == @65 goto dof7
  247. if %WTF% == @66 goto dof8
  248. if %WTF% == @67 goto dof9
  249. if %WTF% == @68 goto dof10
  250. if %WTF% == @84 goto doshf1
  251. if %WTF% == @85 goto doshf2
  252. if %WTF% == @86 goto doshf3
  253. if %WTF% == @87 goto doshf4
  254. if %WTF% == @88 goto doshf5
  255. if %WTF% == @89 goto doshf6
  256. if %WTF% == @90 goto doshf7
  257. if %WTF% == @91 goto doshf8
  258. if %WTF% == @92 goto doshf9
  259. if %WTF% == @93 goto doshf10
  260. if %WTF% == @113 goto doshf10
  261. rem
  262. goto start
  263. :dof1
  264.  set lastx=11
  265.  set lasty=3
  266.  c:\games\kings
  267.  goto start
  268. :dof2
  269.  cls
  270.  dir /4apv c:\budnick\*.*
  271.  pause
  272.  set lastx=11
  273.  set lasty=5
  274.  goto start
  275. :dof3
  276.  scrput 2 27 bright yel on blue "?" will abort the command
  277.  scrput 8 8 white on blue Command:
  278.  scrput 8 16 bright yellow on blue _____________________________________________________________
  279.  screen 8 16
  280.  input %%thingie
  281.  cls
  282.  if "%thingie%" == "?" goto start
  283.  set lastx=11
  284.  set lasty=7
  285.  %thingie%
  286.  pause
  287.  goto start
  288. :dof4
  289.  scrput 2 27 bright yel on blue "?" will abort the command
  290.  scrput 10 8 white on blue Document name:
  291.  scrput 10 22 bright yellow on blue ____________
  292.  screen 10 22
  293.  input %%thingie
  294.  if "%thingie%" == "?" goto start
  295.  set lastx=11
  296.  set lasty=9
  297.  cls
  298.  rem call hdb %thingie%
  299.  ws c:\budnick\%thingie%
  300.  fr
  301.  goto start
  302. :dof5
  303.  scrput 12 8 white on blue Board number:
  304.  scrput 12 21 bright yellow on blue ______
  305.  screen 12 21
  306.  input %%thingie
  307.  set lastx=11
  308.  set lasty=11
  309.  iff "%thingie%" == "" then^c:\games\mahjongg -y -f -m -n^
  310.           else^c:\games\mahjongg -y -f -m -n -b%thingie%^endiff
  311.  goto start
  312. :dof6
  313.  keystack "NNS1Hanny" 13 "YYY" 0 0 "x"^c:\games\solitare
  314.  set lastx=11
  315.  set lasty=13
  316.  goto start
  317. :dof7
  318.  scrput 2 27 bright yel on blue "?" will abort the command
  319.  scrput 16 8 white on blue Copy from:
  320.  scrput 16 18 bright yellow on blue ___________________________________________________
  321.  screen 16 18
  322.  input %%fromfile
  323.  if "%fromfile%" == "" goto dof7
  324.  if "%fromfile%" == "?" goto start
  325.  if not exist %fromfile% goto dof7
  326. :doof7
  327.  scrput 16 8 white on blue Copy to:
  328.  scrput 16 16 bright yellow on blue ____________________________________________________
  329.  screen 16 16
  330.  input %%tofile
  331.  if "%tofile%" == "?" goto start
  332.  if "%tofile%" == "" goto doof7
  333.  set lastx=11
  334.  set lasty=15
  335.  cls
  336.  copy %fromfile% %tofile%
  337.  pause
  338.  goto start
  339. :dof8
  340.  scrput 2 27 bright yel on blue "?" will abort the command
  341.  scrput 18 8 white on blue Document name:
  342.  scrput 18 22 bright yellow on blue ____________
  343.  screen 18 22
  344.  input %%thingie
  345.  if "%thingie%" == "" goto dof8
  346.  if "%thingie%" == "?" goto start
  347.  if not exist c:\budnick\%thingie% goto dof8
  348.  set lastx=11
  349.  set lasty=17
  350.  envelope c:\budnick\%thingie% /c > com2
  351.  goto start
  352. :dof9
  353.  pinit
  354.  set lastx=11
  355.  set lasty=19
  356.  goto start
  357. :dof10
  358.  unset wtf
  359.  cls
  360.  echo type HMENU at any DOS prompt to return to the main menu
  361.  quit
  362. :doshf1
  363.  set lastx=45
  364.  set lasty=3
  365.  c:\games\gomoku
  366.  goto start
  367. :doshf2
  368.  cls
  369.  call tc
  370.  set lastx=45
  371.  set lasty=5
  372.  goto start
  373. :doshf3
  374.  e:
  375.  cd e:\pub
  376.  fp
  377.  cd e:\
  378.  c:
  379.  colset 17 50 5a 03
  380.  set lastx=45
  381.  set lasty=7
  382.  goto start
  383. :doshf4
  384.  to c:\games^shoot^fr
  385.  set lastx=45
  386.  set lasty=9
  387.  goto start
  388. :doshf5
  389.  c:\games\breakout S-6
  390.  set lastx=45
  391.  set lasty=11
  392.  goto start
  393. :doshf6
  394.  trakball dos
  395.  set lastx=45
  396.  set lasty=13
  397.  goto start
  398. :doshf7
  399.  trakball dbase^to db3^dbase^fr
  400.  set lastx=45
  401.  set lasty=15
  402.  goto start
  403. :doshf8
  404.  pff
  405.  set lastx=45
  406.  set lasty=17
  407.  goto start
  408. :doshf9
  409.  pushd c:\games
  410.  fly
  411.  popd
  412.  set lastx=45
  413.  set lasty=19
  414.  goto start
  415. :doshf10
  416.  cls
  417.  sysdown
  418.  quit
  419.  
  420.  
  421. : ---------------------------------------------------------------------
  422. :  WHICH.BTM
  423. rem Determine "WHICH" command will be executed -- internal,
  424. rem alias, external, executable extension, etc.
  425.  
  426. rem None of the rems is necessary to proper operation and may be
  427. rem deleted for ordinary use.
  428.  
  429. setlocal
  430.  
  431. rem See if a command to check was supplied.
  432.  
  433. iff "%1" == "" then ^ echo Syntax: where command ^ quit
  434.  else
  435.  rem
  436.  rem separate the name and the extension (if any)
  437.  rem
  438.  set targ=%@upper[%@name[%1]]
  439.  set ex=%@upper[%@ext[%1]]
  440. endiff
  441.  
  442. rem Skip some stuff if no extension
  443.  
  444. if "%ex" == "" goto noext
  445.  
  446. rem See if the extension is one of the usual executables
  447.  
  448. if %ex == COM .or. %ex == EXE .or. %ex == BTM .or. %ex == BAT goto catext
  449.  
  450. rem There is an extension, but it's not a normal executable.  See if there's
  451. rem such an extension in the environment -- i.e., a user-defined executable
  452. rem extension.
  453.  
  454. set ey=.%ex
  455. iff "%[%ey]" ne "" then
  456.  
  457.    rem It's a defined executable extension.  Tell the user.
  458.  
  459.    echo Executable extension: %@upper[%[%ey]]
  460.  
  461.    rem Now find out whether the program which is supposed to be run
  462.    rem against the executable extension file is there!
  463.  
  464.    iff "%@path[%[%ey]]" == "" then
  465.      %0 %@name[%[%ey]].%@ext[%[%ey]]
  466.    endiff
  467.    iff not exist %@full[%[%ey]] then
  468.      echo Extension program not found
  469.    endiff
  470.  else
  471.    echo Executable extension .%ex definition not found
  472. endiff
  473.  goto cleanup
  474.  
  475. rem Above was for executable extensions.  What follows is the branch
  476. rem label for normal executables (.BTM, .BAT, .COM, and .EXE)
  477.  
  478. :catext
  479.  
  480. rem Put the file name back together with its extension.
  481.  
  482. set targ=%targ.%ex
  483. :noext
  484.  
  485. rem Check for alias or internal first, because they would be found first.
  486.  
  487. iff isalias %targ then
  488.   echos Alias:` `
  489.   alias %targ
  490.   goto cleanup
  491.  elseiff isinternal %targ then
  492.   echo %@upper[%1] is an internal command
  493.   goto cleanup
  494. endiff
  495.  
  496. rem It wasn't an alias or an internal, look down the PATH
  497.  
  498. set targ=%@search[%targ]
  499. iff "%targ" ne "" then
  500.   iff "%@ext[%targ]" == "bat" .or. "%@ext[%targ]" == "btm" then
  501.     echo Batch File: %targ
  502.   else
  503.     echo Program: %targ
  504.   endiff
  505. else
  506.  echo %@upper[%1] is an unknown command!
  507.  beep
  508. endiff
  509. goto cleanup
  510. :cleanup
  511. endlocal
  512.  
  513. rem The branches to "cleanup" and the "endlocal" are not strictly necesary.
  514. rem They could all have been "quit", but I like programs to have a single
  515. rem exit point and exit in a way which is obviously clean.
  516.  
  517.