home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / input.doc < prev    next >
Text File  |  1994-03-04  |  4KB  |  151 lines

  1.  4-May-86 13:51:39-PDT,3775;000000000001
  2. Date: Sun, 4 May 86 15:49:25 cdt
  3. From: Peter Wu <pwu@unix.macc.wisc.edu>
  4. To: info-ibmpc-request@mosis
  5. Subject: INPUT.C
  6.  
  7. INPUT - read a string from console in a batch file
  8.  
  9. SYNTAX
  10.  
  11.   INPUT <prompt> <var name>
  12.  
  13. Where <prompt> is a "quoted" string and <var name> is the name of
  14. an environment variable to accept the input string.
  15.  
  16. Use \" to include the double quote character itself in the
  17. prompt.
  18.  
  19. BRIEF DESCRIPTION
  20.  
  21. Just like BASIC's INPUT statement, except this one works in
  22. batch files, so you can read a string from the user and use the
  23. string in your batch file.
  24.  
  25. E.g. For kicks, you can put this in your autoexec.bat:
  26.  
  27.     echo off
  28.     INPUT "Password:" pwd
  29.     if %pwd%.==who. goto ok
  30.     echo Access denied
  31.     crash
  32.     :ok
  33.     echo.                <- This prints an empty line
  34.     echo Permission Granted
  35.  
  36. The string enterd will always be converted to lower case before
  37. it is stored in the environment variable.
  38.  
  39. If the enviroment variable you specified already exist, it's
  40. contend will be replaced by the user's input.
  41.  
  42. Since this programs stores the string in an environment variable,
  43. you might run out of environment space. Here's a way to expand
  44. your environment space to 992 bytes:
  45.  
  46.     shell=c:\command.com /p /e:62
  47.  
  48. Put the above line in your config.sys file.  This is an
  49. undocumented feature.
  50.  
  51.  
  52. WARNING
  53.  
  54. This program relies on several undocumented features of DOS 3.1.
  55. It has been tested on PC AT and PC XT only.  For example, using
  56. %pwd% to refer to the value of environment variable pwd might not
  57. work in other DOS.  The INPUT program itself relies on
  58. undocumented memory allocation block structure used by DOS to
  59. find DOS's environment space.
  60.  
  61. I resort to undocumented features only because it's almost
  62. impossible to accomplish all these by using documented features
  63. alone.
  64.  
  65. If you try it on a clone and/or try it with a different version
  66. of DOS, let me know whether or not it works.
  67.  
  68.  
  69. EXAMPLES
  70.  
  71. There's this game called HACK that requires a configuration file
  72. to indicate many options, among which the drive name of your ram
  73. disk if you have one. I installed this game on a PC Network where
  74. some PC's have ram disk and some don't. So this is what I put in
  75. the HACK start up batch file:
  76.  
  77.     echo off
  78.     copy F:\games\hack\hack33.cnf hack33.cnf
  79.     INPUT "Drive name of your ram disk (if you have one)? " d
  80.     if %d%.==. goto noram
  81.     echo RAMDISK=%d% >> hack33.cnf
  82.     :noram
  83.     F:\games\hack\hack33
  84.            .
  85.            .
  86.  
  87. ***
  88.  
  89. Here's a simple shell using INPUT:
  90.  
  91.     echo off
  92.     :loop
  93.     INPUT "% " cmd
  94.     if %cmd%.==. goto loop
  95.     if %cmd%.==exit. goto dos
  96.     if %cmd%.==ls. goto ls
  97.     %cmd%
  98.     goto loop
  99.  
  100.     :ls
  101.     dir/w
  102.     goto loop
  103.  
  104.     :dos
  105.  
  106. This could be the cheapest way to con your friends into thinking
  107. that you are running unix.
  108.  
  109. ***
  110.  
  111. A user-friendly print command:
  112.  
  113.     echo off
  114.     set fname=%1
  115.     if not %1.==. goto doit
  116.     :noarg
  117.     INPUT "What file do you want to print? " fname
  118.     if %fname%.==. goto noarg
  119.     :doit
  120.     copy %fname% lpt1
  121.  
  122. If the user call the batch file with a file name, then the file
  123. will be printed, otherwise the user will be prompted for the name
  124. of the file.
  125.  
  126. ***
  127.  
  128. There are probably many other uses, but my imagination is quite
  129. limited, if you found a good use for it, please let me know.
  130.  
  131.  
  132. CREDIT
  133.  
  134. Michael Tsang of University of Wisconsin showed me how to locate DOS's
  135. environment space.
  136.  
  137. Someone posted news to net.micro.pc mentioned the %name% undocumented
  138. feature of DOS; this triggers me to write this program.
  139.  
  140.  
  141. AUTHOR
  142.  
  143. Peter Wu
  144. uucp: ..{ihnp4|seismo|harvard|topaz|allegra|ucbvax}!uwvax!uwmacc!pwu
  145. arpa: uwmacc!pwu@uwvax.ARPA
  146. USmail: 1309 Spring St. #206, Madison, WI 53715
  147.  
  148. Suggestions and comments are welcome.
  149.  
  150. [INPUT.C has been added to the Libary. -rag]
  151.