home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 010 / xset420.zip / DEMO.BAT < prev    next >
DOS Batch File  |  1994-09-15  |  13KB  |  338 lines

  1. @echo off
  2.                   
  3. if "%1" == "second_time" goto begin
  4.  
  5. if exist XSET.EXE goto OK_to_go
  6. echo You must be in the directory containing XSET
  7. exit        
  8. goto end
  9.  
  10. :OK_to_go
  11. :: ┌───────────────────────────────────────────────────────────────────────┐
  12. :: │ Run a new shell with environment big enough (10,000 bytes to be sure) │
  13. :: └───────────────────────────────────────────────────────────────────────┘
  14.  
  15. :: run a new command.com with more environment space
  16. if "%comspec%" == "" command/e:10000/c demo.bat second_time
  17. if not "%comspec%" == "" %comspec%/e:10000/c demo.bat second_time
  18. goto end
  19.     
  20. :begin
  21.      
  22. cls
  23. echo            ╔═════════════════════════════════════════════════╗  
  24. echo            ║                                                 ║
  25. echo            ║  ░░░▒▒▒▓▓▓    Welcome to XSET demo    ▓▓▓▒▒▒░░░ ║
  26. echo            ║                                                 ║ 
  27. echo            ╚═════════════════════════════════════════════════╝
  28. echo: 
  29. echo  Hello,
  30. echo: 
  31. echo:
  32. echo  Although you always thought you cannot perform real programming with  DOS
  33. echo  batch files, this demo will show you it is feasible; furthermore, it will 
  34. echo  show you it is very easy to do.
  35. echo:
  36. echo  What really lacks in DOS is a way to handle environment variables.
  37. echo  The only thing DOS allows you to do is to assign a variable to a value
  38. echo  and to use its value.                                                 
  39. echo:
  40. echo  Did you ever dream to get a user's answer into an environment variable,
  41. echo  or the result of a calculation, or the output of a program ?
  42. echo  Did you ever try to find a way to write  a batch file  that will allow
  43. echo  a selective  behaviour  for different configurations  (like  different
  44. echo  processor types or day of the week,...) ?
  45. echo:
  46. pause  
  47.         
  48. cls
  49. echo  So, why do YOU need XSET ?
  50. echo:
  51. echo  1. Because you are PC support (like me) and often  have to write batch files
  52. echo     that will  be used  by a great  number  of people  and  they must be very
  53. echo     context-dependant and highly interactive (especially if users do not know
  54. echo     about DOS and they panic if they see 'Abort, Retry, Fail?').
  55. echo:
  56. echo  2. Because you need to work in different environments  ( for example you are
  57. echo     are connected to different networks,  or you swap between two development
  58. echo     environment - compilers,... )  and you have to maintain two sets of batch
  59. echo     files.                                                                 
  60. echo:
  61. echo  3. Because you do not like to see your batch files waiting for you the whole
  62. echo     night because you forgot to insert a floppy into drive A: and locking the 
  63. echo     computer instead of running your communication software.
  64. echo:
  65. echo  4. Because you simply want to interactively  edit  your path  ( or any other 
  66. echo     variable), save all your environment to restore it later,...
  67. echo     In other words, you want to have full control of your environment.
  68. echo:
  69. echo:
  70. pause
  71.  
  72. cls
  73. echo  The main goal of XSET is to put ANYTHING YOU WANT into an environment variable
  74. echo  and to modify it LIKE YOU WANT; it also by-passes the internal limits of plain
  75. echo  DOS like the 128 characters limit  (very useful if you need a very long path).
  76. echo  But XSET also provide  a lot of built-in facilities  like  full floating-point
  77. echo  calculation,  time  and  date handling,  system information (kind of CPU, is a
  78. echo  disk ready,...), customized prompts (also in color) and much more !!!                  
  79. echo:       
  80. echo  XSET is fully compatible with MS-DOS, DR-DOS, 4DOS, NDOS, Windows & OS/2.
  81. echo:
  82. echo  XSET is not only the most powerful  environment variables manipulation program
  83. echo  you ever saw,  but it also has a very easy and intuitive user interface  (very 
  84. echo  close to the DOS 'SET' command).
  85. echo:
  86. echo  Example 1:  to ask the user's name and store the result in a variable 'name'
  87. echo     XSET /PROMPT "Enter your name: " name
  88. echo:
  89. echo  Example 2:  to store the processor type in a variable 'cpu_kind'
  90. echo     XSET cpu_kind CPU
  91. echo:
  92. echo  Example 3:  to extract the 5 firsts characters of a string
  93. echo     XSET /LEFT 5 var="any string you want even with another variable %var%"
  94. echo:
  95. echo  Type any key to get XSET help on-line...
  96. pause > nul
  97.     
  98. xset
  99.  
  100. cls
  101. echo  Following is a demo which only goal is to show how powerful XSET is.
  102. echo  The demo itself is not very useful but it implements a kind of very
  103. echo  limited file manager.
  104. echo  None  of the messages,  colors,  default values or  behaviours  are
  105. echo  hard-coded  into the program;  they all are given  as parameters in 
  106. echo  the batch file. 
  107. echo  XSET is not limited  to this kind of handling;  I only had to choose 
  108. echo  something that has a great level of interaction because it is better
  109. echo  for a demo but the most powerful features of XSET are generally used
  110. echo  for non- interactive procedures.
  111. echo:
  112. echo  Note  for people  who have  a monochrome monitor  and  a color video 
  113. echo  board:  The demo displays messages in color  but you normally should
  114. echo  read everything correctly (you even will see highlight).
  115. echo:
  116. echo:       
  117. echo  Because of the way the information are displayed on the screen, the
  118. echo  drawing  may be very slow  ( especially  if you do not have  a disk 
  119. echo  cache  installed). This is because the XSET program is called a lot 
  120. echo  of times for the menu display (only to have fancy colors).
  121. echo:
  122. echo:
  123. pause             
  124.  
  125. cls
  126. echo  First of all, some system checks.
  127. echo  Note that all displayed results are actually stored into an environment 
  128. echo  variable; the following message are using the normal DOS 'echo' command.
  129. echo:
  130. echo:
  131.  
  132. XSET _xtmp CPU                
  133. if "%CPU%" == "86" set _xtmp=086
  134. echo  CPU kind:                  80%_xtmp%
  135.                                      
  136. :: the following trick would be useless if the 'FOR' command
  137. :: would allow to perform several actions in a loop
  138. :: (so we create and call a batch file)
  139. echo XSET _xtmp DRIVETEST %%1 > _xtmp.bat
  140. echo echo  drive %%1: status:           %%_xtmp%% >> _xtmp.bat
  141. for %%d in (A B C X) do call _xtmp.bat %%d
  142. del _xtmp.bat
  143.     
  144. XSET _xtmp TIME
  145. echo  Current time:              %_xtmp%
  146.                                      
  147. XSET _xtmp DIR c:
  148. echo  current dir  of drive C:   \%_xtmp%
  149.                                      
  150. XSET _xtmp VOLLABEL c:
  151. echo  volume label of drive C:   %_xtmp%
  152.                                      
  153. XSET _xtmp BYTEFREE c:
  154. echo  bytes free   on drive C:   %_xtmp%
  155.                                      
  156. XSET _xtmp FDATE c:\autoexec.bat
  157. echo  c:\autoexec.bat - date:    %_xtmp%
  158.                                      
  159. XSET _xtmp FSIZE c:\autoexec.bat
  160. echo  c:\autoexec.bat - size:    %_xtmp%
  161.                
  162. echo:
  163. echo:                      
  164. pause          
  165.  
  166. :: ----------------------------------------------------- 
  167. :demo
  168.      
  169. :: ┌─────────────────────────────────────────┐                         
  170. :: │Get current drive & path into environment│                             
  171. :: └─────────────────────────────────────────┘                             
  172. XSET _xdrive FDRIVE *                                                    
  173. XSET/MID 3 100 _xdir FDIR *                                              
  174.                                                                          
  175. :: ┌──────────────────────────────────────────────┐
  176. :: │ Store current path & add this directory to it│
  177. :: └──────────────────────────────────────────────┘
  178. XSET _xpath VARCOPY path
  179. set path=%_xdrive%%_xdir%;
  180. XSET/APPEND path varcopy _xpath
  181.  
  182. :: ┌──────────────────┐
  183. :: │Set default values│
  184. :: └──────────────────┘
  185. set _xfile=*.*
  186. set _xoptions=/P
  187.        
  188. XSET _xdate DATE                                                                  
  189. set _xpos=3
  190.           
  191. :: ┌─── Show menu on Screen ──────────────────────────────────────────────┐
  192. :: │                                                                      │
  193. :: ├─── This is purely examplative ───────────────────────────────────────┤
  194. :: ├─── Experiment with dir, changing drive path options, ... ────────────┤
  195. :: └──────────────────────────────────────────────────────────────────────┘
  196. :menu
  197. cls   
  198. set XSET=/BACKGROUND BLUE/COLOR YELLOW/WINDOW 3 1 75 17/BORDER
  199. XSET/XPOS 5/YPOS 2/PROMPT "████████████████████    X S E T:  Menu example    ███████████████████"
  200. set XSET=/BACKGROUND BLUE/COLOR WHITE/XPOS 7
  201. XSET/YPOS 5/PROMPT"D Drive    :"
  202. XSET/PROMPT "P Path     :"
  203. XSET/PROMPT "F FileSpec :"
  204. XSET/PROMPT "O Options  :"
  205. echo:
  206. XSET/XPOS 5/PROMPT"─────────────────────────────────────────────────────────────────────"
  207. echo:
  208. set XSET=/BACKGROUND BLUE/COLOR WHITE/XPOS 27
  209. XSET/PROMPT "1  List directory contents"
  210. XSET/PROMPT "2  List File contents"
  211. echo:
  212. XSET/PROMPT "Q  Quit menu"
  213.  
  214. :: ┌──────────────────────────────────────────────────────────────────────┐
  215. :: ├── Showing drive, path, _xfile and _xoptions ─────────────────────────┤
  216. :: └──────────────────────────────────────────────────────────────────────┘
  217.    
  218. XSET/YPOS 4/XPOS 60/COLOR GREEN/PROMPT"%_xdate%"
  219. XSET _xtmp DRIVETEST %_xdrive%
  220. set _xtmp=%_xdrive% (%_xtmp%)
  221. set XSET=/BACKGROUND BLUE/COLOR LIGHTGRAY/XPOS 20
  222. XSET/YPOS 5/PROMPT"%_xtmp%"
  223. XSET/PROMPT "%_xdir%"
  224. XSET/PROMPT "%_xfile%"    
  225. XSET/PROMPT "%_xoptions%"  
  226.  
  227. set XSET=/XPOS %_xpos%/YPOS 20
  228. XSET/UPPER/COLOR MAGENTA/PROMPT"Type a key to make a choice (1,2,3,D,P,F,O,Q)" _xkey KEY "123DPFOQ"
  229. set XSET=
  230.    
  231. :: ┌────────────────────────────────────────────────────────────────────────┐
  232. :: ├── Jump here after an option, if you do not have to redraw the screen ──┤
  233. :: └────────────────────────────────────────────────────────────────────────┘
  234. :waitkey
  235.  
  236. goto menu%_xkey%
  237.  
  238. :: ┌───────────────────────────────────────┐
  239. :: │  CHOICE 1: List the directory contents│
  240. :: └───────────────────────────────────────┘
  241. :menu1 
  242. cls             
  243. dir %_xoptions% %_xdrive%%_xdir%%_xfile%
  244. pause
  245. goto menu
  246.  
  247.  
  248. :: ┌─────────────────────────┐
  249. :: │  CHOICE 2: List a file  │
  250. :: └─────────────────────────┘
  251. :menu2
  252. XSET _xtmp FPATH %_xdrive%%_xdir%%_xfile%
  253. XSET/XPOS %_xpos%/COLOR HIGHLIGHT/PROMPT"Filename: "/DEFAULT _xtmp
  254. if exist %_xtmp% goto fexist
  255. XSET/XPOS %_xpos%/BLINK/COLOR RED/PROMT"Error: File does not exist."
  256. pause
  257. goto menu                   
  258. :fexist              
  259. :: Test for wildcards
  260. for %%f in (%_xtmp%) do set _xtmp2=%%f
  261. if "_xtmp2" == "_xtmp" goto listf
  262. XSET/XPOS %_xpos%/BLINK/COLOR RED/PROMT"Error: Only one file may be specified."
  263. pause
  264. goto menu                   
  265. :listf
  266. more < %_xtmp%
  267. pause
  268. goto menu
  269.  
  270.  
  271. :: ┌─────────────────────────┐
  272. :: │  CHOICE D: Change drive │
  273. :: └─────────────────────────┘
  274. :menuD
  275. XSET/XPOS %_xpos%/COLOR YELLOW/PROMPT"Choose a drive (A-Z)"/UPPER _xtmp KEY "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  276. XSET/SEARCH"READABLE" _xtmp2 DRIVETEST %_xtmp%
  277. if not "%_xtmp2%" == "" goto chdrv
  278. xset _xtmp2 DRIVETEST %_xtmp% 
  279. XSET/XPOS %_xpos%/BLINK/COLOR RED/PROMPT"Error - drive status %_xtmp%: = %_xtmp2%"
  280. pause
  281. goto menu
  282. :chdrv                           
  283. set _xdrive=%_xtmp%:
  284. %_xdrive%
  285. :: Get current directory
  286. XSET/MID 3 100 _xdir FDIR *
  287. goto menu
  288.  
  289.  
  290. :: ┌─────────────────────────────┐
  291. :: │  CHOICE P: Change directory │
  292. :: └─────────────────────────────┘
  293. :menuP                   
  294. set _xtmp=%_xdir%
  295. echo:
  296. echo:
  297. XSET/XPOS %_xpos%/BORDER/PROMPT "New directory:"/DEFAULT _xtmp
  298. XSET/SEARCH ":" _xtmp2 VARCOPY _xtmp
  299. if not "%_xtmp2%" == "" goto menuP
  300. :: remove trailing \ (if any)
  301. XSET/REGEXP/CHANGE "\\$" "" _xtmp="%_xtmp%"
  302. :: check if directory exist
  303. if not exist %_xtmp%\nul goto chdirError
  304. XSET _xdir VARCOPY _xtmp
  305. cd %_xdir% 
  306. set _xdir=%_xdir%\
  307. goto menu
  308. :chdirError 
  309. XSET/XPOS %_xpos%/BLINK/COLOR RED/PROMT"Error: Directory not existing."
  310. pause
  311. goto menu
  312.  
  313.  
  314. :: ┌─────────────────────────────┐
  315. :: │  CHOICE F: Filename         │
  316. :: └─────────────────────────────┘
  317. :menuF                   
  318. set _xtmp=%_xfile%
  319. XSET/XPOS %_xpos%/COLOR LIGHTBLUE/PROMPT"FileSpec: "/DEFAULT _xtmp
  320. XSET/SEARCH ":" _xtmp2 VARCOPY _xtmp
  321. if not "%_xtmp2%" == "" goto menuF
  322. XSET/SEARCH "\" _xtmp2 VARCOPY _xtmp
  323. if not "%_xtmp2%" == "" goto menuF
  324. XSET _xfile VARCOPY _xtmp
  325. goto menu
  326.  
  327.  
  328. :: ┌─────────────────────────────┐
  329. :: │  CHOICE O: Options          │
  330. :: └─────────────────────────────┘
  331. :menuO
  332. XSET/XPOS %_xpos%/COLOR GREEN/PROMPT"Dir options: "/DEFAULT _xoptions
  333. goto menu
  334.  
  335.       
  336. :menuQ 
  337. :end     
  338.