home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / SYSUTL / SETENVJW.ZIP / SETENV.DOC < prev    next >
Encoding:
Text File  |  1991-06-16  |  8.9 KB  |  241 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.         SETENV utility V1.6 (c) 14-Jun-1991
  7. The SETENV program for a DOS version 2 allows setting 
  8. an environment variable.  SETENV utility will run under 
  9. DOS 3.0 thru 4.0, and 5.0.  I have not seen DOS V1.x.  
  10.  
  11. SETENV : Copyright (c) 1988 to 1991 by John Wolchak.
  12.   I give permission to alter the code, but not to copy 
  13.   or redistribute the altered code without my explicit 
  14.   permission.  If you alter the code, please document 
  15.   changes and send me a copy, so all can have it.  
  16.   This document must always accompany the SETENV 
  17.   program when a copy is made for another machine.  
  18.   This code, to the best of my knowledge works well.  
  19.   I disclaim any responsibility for the codes actions 
  20.   (use at your own risk).  
  21.                         John
  22.  
  23. The syntax of the command is:
  24.  
  25.     SETENV <variable> <value>
  26.  
  27. <variable> is any valid environment variable you wish to 
  28. define or re-define.  
  29.  
  30. <value> is a string of printable characters.  Keys can be 
  31. embedded in the character string.  The Keys are:
  32.   %cwd will return the current directory.
  33.   %date will return the cuurent date.
  34.   %dosv will return the DOS major version.
  35.   %dosm will return the DOS minor version.
  36.   %drive will return the current disk drive letter.
  37.   %time will return the cuurent time.
  38.   %-n will return the current disk drive minus 'n' letter(s).
  39.   %+n will return the current disk drive plus 'n' letter(s).
  40.  
  41. <value> can be '%rep<del><text1><del><text2><del>', where <text1>
  42. will replace <text2> in the environment variable value.
  43.  
  44. <value> can be '%chgup' which will uppercase the existing environment variable.
  45.  
  46. <value> can be '%prompt <message>'
  47. <value> can be '%prompt %def<del><text><del> <message>'.  
  48. <value> can be '%prompt %def<del><text><del> %timo=hh:mm:ss <message>'.  
  49. <value> can be '%prompt %upper %def<del><text><del> <message>'.
  50. <value> can be '%prompt %noecho %upper %def<del><text><del> <message>', 
  51. where the <message> is displayed on the console and the response is set 
  52. into the variable.  %def is optional, and <text> is the <value> used, 
  53. if just a return is given.  <del> is a one character delimter, to quote 
  54. the <text>.  %noecho is optional meaning not to display the response on 
  55. the screen (passwords).  %upper is is optional meaning to convert the 
  56. lower case letters to upper case letters.  %timo is optional meaning to 
  57. time out the prompt message and exit after hh:mm:ss.  
  58.  
  59. No %timo means to prompt forever.  No %def and a %timo will assume %def//.
  60. The time out is for the first character entered, after the first character 
  61. is entered you have forever to enter the rest of the text.
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. Note: In batch (BAT files) use %% to represent a single % for use 
  69. to SETENV.   ie. SETENV DRV_DIR %%drive:%%cwd
  70.  
  71. Note:  SETENV can not expand the environment space.  The DOS SET 
  72. command can do that, by creating temporary variables with long 
  73. values and then removing them before any resident program is run.  
  74. Resident programs are PRINT, MODE.  Documentation is available for 
  75. versions of DOS 2 thru 3.20 that modify DOS to have a larger 
  76. environment area beyond the normal 160 bytes.  For DOS 3.30 and 
  77. above use the shell /E:xxxx option.  
  78.  
  79.  
  80.  
  81. SETENV terminates with int 21h, AH=4ch, the intention is 
  82. that the program can be called from another program.  
  83.  
  84.  
  85. SETENV returns errorlevel codes, which are:
  86.  
  87.     no command, help issued        00h
  88.     root environment set        01h
  89.     environment variable erased    02h
  90.     environment variable created    03h
  91.     environment space over written    04h
  92.     environment variable updated    05h
  93.     unmatched delimiter        06h
  94.     don't know about MS-DOS V1.x    07h
  95.     environment variable not found    08h
  96.     offset of drive will be invalid    09h
  97.     environment space is full    10h
  98.  
  99. Code 04h environment space over written means that there 
  100. was non-zero data bytes encountered in the environment 
  101. space.  This happens when environment variable is the 
  102. last one in the environment space and is deleted, the 
  103. variable is removed but the space is not erased.  Code 
  104. 04h will not have precedence over a higher code.
  105.  
  106.  
  107. Example:
  108.  
  109. This example batch file can demonstrate the usage of SETENV.
  110.  
  111. setenv version MS-DOS V%%dosv.%%dosm in %%drive:%%cwd drv/dir.
  112. setenv drvs Drive is %%+0:, with %%-1: prev and %%+1: next.
  113. setenv first %%prompt Your First Name: 
  114. setenv last %%prompt %first% Your Last Name: 
  115. setenv answer %%prompt %%def/Y/ %first% %last% [Y/N] <Y>: 
  116. set
  117.  
  118. First note the %% for a single % in batch.  In batch you can 
  119. use %<environ_var>% to reflect the value of a previous 
  120. environment variable.  Make sure you have enough environment 
  121. space to store this amount of data.
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. History:
  129.  
  130. At work we have Disk and File Serving using DOS version 3.  
  131. When a machine optional has or not a hard disk, one or more 
  132. hard disk partitions and maybe a ramdisk, locating the disk 
  133. or file server is a little tricky.  The disk and file servers 
  134. are located after your hard disk partitions.  To find them we 
  135. copy a file, to a redefined disk.  Then test to see if the 
  136. file exists.  If the file exists, then what drive are we on.
  137. Example is:
  138.     assign b=g >nul
  139.     assign b=h >nul
  140.     assign b=i >nul
  141.     assign b=j >nul
  142.     assign b=k >nul
  143.     copy command.com b:\
  144.     assign b=b >nul
  145.     if not exist k:\command.com goto jdrv
  146.     ...
  147.     jdrv:
  148.     if not exist j:\command.com goto idrv
  149.     ...
  150.     idrv:
  151.     ...
  152.     ...
  153.  
  154. (We no longer do this now that we have SETENV.)
  155.  
  156.  
  157. I wrote a program called CURDRV.  This program would put the 
  158. current disk drive letter in an environment variable called 
  159. CURDRV.  The first problem was that when I set the environment 
  160. variable, then exited the program it was gone, because a 
  161. program has a copy of the environment space.  
  162.  
  163. Then we went looking for a program that would return the current 
  164. disk drive, we came across a program written in C by Richard 
  165. Marks called SETENV.  He says that his program would not work 
  166. under DoubleDOS, so this program as well will not work under 
  167. DoubleDOS.  From Richard Marks's program I used the idea of 
  168. getting at the environment space by finding the program segment 
  169. prefix (PSP) of command.com.  This is where the real environment 
  170. space lies.
  171.  
  172. For the users of DOS version 3 there is int 21h, and register 
  173. AH=52h, call to find the PSP.  It is definitely alot easier 
  174. then what Richard Mark layed out, but his way is the only 
  175. way to find the PSP under DOS version 2 (to my knowledge).  
  176. This method still works under DOS version 3 and version 5, 
  177. but future releases may prove to be a problem.
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. Special section:
  185.  
  186. If SETENV is called from within a shell there is sometimes a need 
  187. to set the environment variable into the most root environment space.
  188. The means to set the root environment space is use %rce after the 
  189. program name followed by the usual arguments.  
  190. Example is:
  191.  
  192.     SETENV %rce <variable> <value>
  193.  
  194. A special note about calling Command.Com a second time is that all 
  195. environment variables are duplicated for the second call and that 
  196. changing any environment variable at this local call will not change 
  197. the original variable.  That is purpose of the special argument.  
  198. When the exit command is used the original environment varilables are 
  199. restored.  
  200.  
  201. Also note that environment space is allocated in 16 byte segments and 
  202. that when the environment space is copied only the necessary segments 
  203. are copied.  (DOS V3.30 and DOS V5.0 allow you to set the size of the 
  204. environment space.)  So if only one byte is in the last segment then 
  205. you have only 15 bytes to use.  In the 15 bytes you also have to count 
  206. the variable name space as well.  A way to get around this restriction 
  207. is to create a environment variable with a large environment space 
  208. before you call Command.Com, then remove the dummy environment variable.  
  209. This should give you some elbow room at the local Command.Com.
  210.  
  211.  
  212.  
  213. Restrictions:
  214.  
  215. SETENV programs traces the program segment prefix to find the environment 
  216. space, but when it finds the environment space SETENV first check if one 
  217. of PATH=, PROMPT= or COMSPEC= exists at the first segment boundary.  I 
  218. am finding that there can be allot of changes to these variables, which 
  219. causes SETENV to search for ever looking for this arrangement.  So SETENV 
  220. can now sink to a new variable SETENV=.  Remember that when you type SET
  221. to DOS PATH=, PROMPT=, COMSPEC=, or SETENV= must be the first varible.
  222.  
  223.  
  224.  
  225. Acknowledgement:
  226.  
  227. Richard Marks's C program because without it, I would not have found the 
  228. true system environment.  
  229. I wrote this program on a Rainbow, because that is what I have.  At work 
  230. I use SEDT as my editor by Anker Berg-Sonne, (also runs on IBM PC's) but 
  231. at home it is a little large for a diskette based system.  So at home I 
  232. use KEDT by Jay Jervey.  I would like to thank these people because without 
  233. a good editor it can become near impossible to write any program.  
  234.  
  235.  
  236. John Wolchak
  237. 56 Physics Building
  238. University of Saskatchewan    Phone: (306) 966-4852
  239. Saskatoon, Saskatchewan        NetNorth (BITNET): Wolchak@Sask
  240. Canada     S7K 0W0        Inter_Network:    Wolchak@Admin.Usask.CA
  241.