*********************************************** * XSET 5.01 : Extended SET Instruction * * * * (C) 1991-1997 Stern Marc * *********************************************** Everything you always wanted to put in an environment variable but were afraid to ask DOS for . . . XSET: The easy way to write efficient batch files. XSET allows you to put EVERYTHING you want in a variable of the current DOS environment and use it as if you had assigned it the value with the standard DOS command 'SET'. You will be able to write very efficient batch files including string manipulation, calculation, ... XSET is the most powerful environment variable manipulation program you have ever seen. It also has a very easy and intuitive user interface (very close to the DOS 'SET' command). It is not a resident program; so it will not interfere with any of your other applications. XSET is fully compatible with MS-DOS (from 3.30), DR-DOS, NDOS, 4DOS, OS/2, Windows 95 and Windows NT. XSET has seven major features: ----------------------------- - XSET permits you to catch the output of any command (internal or external) or program and put it into an environment variable. - XSET has built-in commands to modify the output of a program or a string given on the command-line (extract a part of a string, ...) - XSET has a built-in full floating-point calculation functionality: You can program incremental loops, input a calculation string and output the resulting number, ... - XSET can manage variable contents of more than 128 characters (your path can now be as long as you want). - XSET has other built-in commands to give you access to some system data (date, time, ...) - XSET has built-in commands to clear the whole environment or restore a previously saved one. - XSET gives you access to high-level input/output user interface (line-editing, colors, windows, boxes, ...). More than sixty commands to do all that you need. Page 1 ******************************* * Table of contents * ******************************* The Shareware concept .................................... Page 2 How to use XSET .......................................... Page 3 Examples of use .......................................... Page 4 Input explanation ........................................ Page 8 Syntax explanation ....................................... Page 8 Options and commands description ......................... Page 9 Input commands ......................................... Page 9 Date & time commands ................................... Page 10 Disk & file commands ................................... Page 11 Other commands ......................................... Page 14 Input related flags .................................... Page 15 Prompt related flags ................................... Page 16 String related flags ................................... Page 17 Regular Expressions .................................... Page 19 Other flags ............................................ Page 20 Special flags .......................................... Page 21 Data file ................................................ Page 22 XSET & XSET_MSG variables ................................ Page 24 Errorlevel / return codes ................................ Page 24 Installation ............................................. Page 25 Windows NT & OS/2 specifics .............................. Page 25 Problems ................................................. Page 26 Batch file programming: Hints & tips ..................... Page 28 Windows features ................... ..................... Page 29 How to contact the author ................................ Page 30 How to register .......................................... Page 31 Page 2 ******************************* * The Shareware concept * ******************************* This package is Shareware. That means that you may try it for evaluation and, if you like it, you should consider paying the registration fee (see the file 'REGISTER.TXT')at the end of the documentation. You will then be a registered user and so have access to free support and free correction of acknowledged bugs. The essence of "user-supported" software is to provide personal computer users with quality software without the high prices, and yet to provide incentive for programmers to continue to develop new products. If you find this program useful and find that you are using XSET and continue to use it after a reasonable trial period, you should register it. Shareware also mean that you may distribute this package everywhere and to anyone you want, providing that you always distribute the complete package. If you have access to any BBS, FTP server, E-mail server or any other kind of software distribution, feel free to share it with other people; this may be useful for them and the more people that use (and register) a shareware program, the more stable it will become and the more functionalities and enhancements will be added. Warning: If you paid to get this package (e.g., it was onto a floppy ------- with other programs, you downloaded it from a BBS), you only paid for the physical support (the floppy, the transmission fee, ...); this does not replace the registration fee. Note to software distributors: ----------------------------- Nobody is allowed to make any benefit by distributing the XSET package. Only regular distribution fees are allowed (price of the floppy, of the network connection, ...). Standard disclaimer and agreement: --------------------------------- XSET is supplied as is. The author disclaims all warranties, expressed or implied, including, without limitation, the warranties of merchantability and of fitness for any purpose. The author assumes no liability for damages, direct or consequential, which may result from the use of XSET. Page 3 How to use XSET: --------------- XSET will always assign what you tell it into a DOS environment variable. The main goals of XSET are: - to ask a question to the user (through the keyboard), - to catch the output of a program or a command, - to get pieces of information like current date and time, timestamp or size of a file, ... - to modify a string (contained in another variable, in a parameter, ...) like changing it to lower-/upper-case, performing a search on it, calculating the result of a mathematical expression, substituting a sub-string by another or extracting a part of it, - to handle variables longer than 128 characters. There are four ways to use XSET. 1. Like the normal DOS 'SET' command: XSET myvar="This is a test string" 2. To get an input from the user: XSET answer 3. To catch the output of a program or a command: dir c:\programs\myprog.c | XSET myvar 4. To get various system or environment information: XSET myvar DATE Furthermore, to attain a high level of functionality you may add, to each of the above syntaxs, several option flags to modify the default behavior of XSET (for example /UPPER to translate into upper-cases, ...). Syntax: 1. XSET [/OPTIONS...] ------ read a string from standard input 2. XSET [/OPTIONS...] ="string" equivalent to the DOS command 'SET' 3. XSET [/OPTIONS...] COMMAND [arguments ...] Page 4 Type XSET /? to get online the full description of all functionalities (parameters and effects). Remark: Intensive use of XSET (and more generally of DOS environment variables) may require that you expand the size of your DOS environment space through the SHELL command. See the PROBLEMS section for more details. Examples of use: --------------- These examples are only intended to show you how powerful and intuitive the usage of XSET could be. The syntax of all the functionalities is described just after. Remark: In all the examples, the command XSET and its built-in commands are typed in upper-case and the environment variables names are in lower-case. This is only for readability; when you type it, you may mix lower-case and upper-case as you like. The case is only significant for argument strings you enter on the command-line. 1) XSET datevar DATE DD-MM-YY Assigns the current system date into the variable 'datevar' Type the DOS command 'SET' to see all the environment variables; you will get something like this: ... COMSPEC=... DATEVAR=dd-mm-yy (where dd,mm,yy are replaced by current day, month and year) ... (other variables) You can now use the variable 'datevar' in a batch file: ECHO the date is %datevar% 2) XSET /COLOR LIGHTRED /PROMPT "Enter your name: " name Inputs a string from the keyboard (as usual, the answer is terminated by ) and assigns it into the variable 'name'. The prompt appears in the specified color (or the equivalent attribute on monochrome displays). You can now use the variable 'name' in a batch file to select a personalized environment for each user: ECHO Hello %name%, have a good work session CD \%name% Page 5 3) You can write a batch file with automatic loops rem ------------------ set loop=1 :next ....... anything you want ....... rem Increments variable value XSET /MATH loop=%loop% + 1 rem Test if value equals 20 if not %loop% == 20 goto next rem ------------------ 4) You can write a batch file where the user may enter a calculation and use it as a number rem ------------------ XSET /PROMPT "Enter your calculation: " /MATH calc echo result = %calc% rem ------------------ Page 6 5) More elaborate example of a login procedure rem ---------------------- LOGIN.BAT -------------------------------- @echo off cls :BEGIN rem Ask login name from keyboard rem ---------------------------- XSET /PROMPT "Enter login name : " login rem Test if directory corresponding to login name already exist rem ----------------------------------------------------------- if exist c:\%login%\*.* goto OK rem Directory does not exist, ask to create it rem ------------------------------------------ echo: echo Login '%login%' does not exist. rem Only "yYnN" keys are allowed rem ---------------------------- XSET /PROMPT "Do you want to create it? (Y/N)" /UPPER ask KEY "YN" if %ask% == N goto BEGIN rem Create directory rem ---------------- md c:\%login% :OK set ask= rem Go to user's directory and branch to personal rem batch file if any. rem --------------------------------------------- cd \%login% if exist autouser.bat autouser.bat rem ----------------------------------------------------------------- Page 7 6) You are able to use a single password input for several network connections rem ----------------------------------------------------------------- echo off cls rem Ask login name from keyboard rem ---------------------------- XSET /PROMPT "Enter login name : " login rem Ask password from keyboard (it is hidden while typing) rem ------------------------------------------------------ XSET /PROMPT "Enter password : " pass PASSWD rem Connection to several network nodes rem ----------------------------------- net use node1 ... %login% %pass% net use node2 ... %login% %pass% net use node3 ... %login% %pass% rem Overwrite variable containing password (to be sure) rem -------------------------------------- set pass=something_longer_than_password_to_be_sure rem Clear variable containing password (to free environment) rem ---------------------------------- set passwd= rem ----------------------------------------------------------------- 7) And much more ... See also README.BAT, ENVEDIT.BAT, EASY.BAT and DEMO.BAT Page 8 Input editing: ============= When you input a string from the keyboard, you may use several edition facilities: When a default string is proposed: - if any editing character (Home, <-, ->, ...) is hit you may edit the proposed string, - otherwise, default string is erased and replaced by the new input you type in; this feature is only active for the first key you hit. Valid keys: Home Begin of line End End of line Left/Right One character left/right Insert Toggle insert on/off Delete Delete current character BackSpace Delete previous character Ctrl-home Erase to begin-of-line Ctrl-end Erase to end-of-line Escape Erase whole input Enter Accept input If a timeout is specified (see /TIMEOUT flag) the function may automatically return if no key is hit before the specified time. Syntax explanation: ================== [...] are optional arguments; if they are not specified, a default is assumed. {...} are mandatory arguments; if they are missing from the command-line, they are read from the standard input device (usually the keyboard or, if using redirection, a file or the output of another command). String arguments have to be included in double quotes (") if they contain any special characters like characters interpreted by COMMAND.COM. See remark in section 'Problems'. This implies that all double quotes will be removed from the strings arguments. String arguments to option flags also have to be quoted ("") if they contain spaces, tabs or slashes (/). Page 9 Options and commands description: ================================ Remarks: - In the following descriptions, the word 'function' stands for both 'option flag' and 'command'; in other words, any functionality of XSET. - The word 'result' in the option flags description stands for the current contents of the variable at the moment the considered flag is processed (i.e., after the already executed functions). Input commands: -------------- KEY [string] This waits for a key to be pressed and assigns the result to a DOS environment variable. If a string argument is added to the command, only the characters appearing in the string are allowed; if another key is hit, you will hear a beep. Printable characters (ASCII code from 32 to 255) return the character corresponding to the key (ex: A returns 'A'). Non-printable characters (ASCII code lower than 32) return their decimal ASCII code preceded by a '#' (ex: Ctrl-A returns '#1'). Extended keys (arrows, function keys, Home/end, PageUp/PageDown, ...) return their decimal scan code added to 256 preceded by a '#' (ex: F1 returns '#315'). See your technical documentation for a list of your keyboard scan codes. If you used the /TIMEOUT flag, the program will return after the specified time if no valid key was hit. The resulting variable will be empty. ex: XSET k KEY 123aAbB only keys '123aAbB' are allowed ex: XSET k KEY all keys are allowed ex: XSET/UPPER k KEY abc only keys 'aAbBcC' are allowed PASSWD This reads characters from keyboard without echo on screen. It is intended to input a password or secret information. Page 10 Date & time commands: -------------------- DATE [format] This returns the system date & time. In parameter 'format', special characters will be replaced by system date and time: D day M month Y year h hour m minutes s seconds If you double the character, it will be preceeded by a '0' if only one digit. ex: 3 April 1996 ex: YYMMDD -> 960403 D-MM-Y -> 3-04-96 hh:mm:ss -> 14:23:12 DAYOFWEEK This returns the system day in the week (0 = sunday, 1 = monday, ... ) DIFFDATE date1 date2 This returns the number of days between and . date1 format may be 'yyyymmdd', 'dd-mm-yyyy' or 'dd/mm/yyy'. You may even mix them. If is before , the result will be negative. Rem: if yyyy is lesser than 100, 1900 is added (1994 is the same as 94). Page 11 Disk & file commands: -------------------- Remarks: - The filenames given as arguments to these commands may be any valid or invalid filenames. They may be an absolute pathname or a relative one. They will never be checked for existence, only their name will be resolved (canonized) following the normal DOS conventions. - The drive given as arguments to these commands must be a letter from 'a' to 'z' (or 'A' to Z') optionally followed by a period ':'. FPATH {file} This returns the full pathname of a filename. ex: XSET myvar FPATH ..\myprog.exe will put in myvar something like 'C:\PROGRAMS\MYPROG.EXE' FDRIVE {file} This returns the drive of a filename. ex: XSET myvar FDRIVE myprog.exe will put in myvar 'C:' FDIR {file} This returns the drive & directory of a filename. ex: XSET myvar FDIR c:myprog.exe will put in myvar 'C:\PROGRAMS\EXE\' FEXT {file} This returns the extension of a file name (no period included). ex: XSET myvar FEXT c:\exe\myprog.exe will put in myvar 'EXE' FNAME {file} This returns the name of a file without extension. ex: XSET myvar FNAME c:\exe\myprog.exe will put in myvar 'MYPROG' FXNAME {file} This returns the name & extension of a file. ex: XSET myvar FXNAME h:myprog.exe will put in myvar 'MYPROG.EXE' Page 12 TRUENAME {file} This returns the full truename of a file, solving all SUBST, ASSIGN and JOIN commands and some network names (for those networks compatible with MS_LAN redirector). ex: XSET myvar TRUENAME myprog.exe will put in myvar something like 'C:\PROGRAMS\EXE\MYPROG.EXE' XSET myvar TRUENAME h:myprog.dat (where h: is SUBSTed to C:\DATA) will put in myvar something like 'C:\DATA\MYPROG.DAT' XSET myvar TRUENAME h:myprog.dat (where h: is a network drive) will put in myvar something like '\\SERVER1\SMITH%SMITH\MYPROG.DAT' FSIZE {file} This returns the size of a file (in bytes). FDATE {file} This returns the modification date of a file (dd-mm-yy). FTIME {file} This returns the modification time of a file (hh:mm:ss). DIR [drive] This returns the current directory of the specified drive. If no drive is specified, the current one is assumed. VOLLABEL [drive] This returns the volume label of the specified drive. If no drive is specified, the current one is assumed. BYTEFREE [drive] This returns the number of bytes free on the specified drive. If no drive is specified, the current one is assumed. Page 13 DENSITY [drive] This returns the drive density (in KBytes - 360, 720, 1200, 1440, 2880) of the specified floppy drive. If no drive is specified, the current one is assumed. This command returns the density of the drive, not of the floppy that currently is in it (it isn't even necessary for a floppy to be in the drive). The program returns '0' if the drive has an unknown density or it is not a floppy drive. DRIVETEST [drive] This returns the status of the specified drive. If no drive is specified, the current one is assumed. The result is a concatenation of one or more string(s) from 'READABLE', 'WRITEABLE', 'NOFORMAT', 'NOTINSERTED', 'INVALID', 'REMOVABLE', 'REMOTE', 'SUBST', 'RAM', 'HARDDISK', 'TAPE', 'OPTICAL', 'FLOPPY', 'CDROM' separated by '-'. ex: XSET test DRIVETEST a: This assigns to the variable 'test' a string like: 'READABLE - WRITEABLE - REMOVABLE' (floppy not protected) or 'READABLE - REMOVABLE' (floppy protected) or 'NOTINSERTED - REMOVABLE' (floppy not inserted) or 'NOFORMAT - REMOVABLE' (floppy not formatted) So, to test if you have write-access to a drive: XSET/SEARCH "WRITEABLE" test DRIVETEST a: Variable 'test' will contain 'WRITEABLE' or will be empty. Page 14 Other commands: -------------- MIN / {str1...strn} MAX \ {num1...numn} This returns the minimum/maximum value of numbers or strings list. If not all arguments are numbers, a string comparison (i.e., a comparison of ASCII codes of their characters) will be performed. Rem: A string may not contain or . ex: XSET var MIN 3.6 -4 9.02 %num% 'var' will contains '-4' (providing than %num% >= -4) XSET var MAX 3.6 $5 abc 3.9j 'var' will contains '$5' CPU This returns the processor type: 0 for 8088/8086/8186, 2 for 8286, 3 for 8386, 4 for 486, 5 for Pentium There is no difference between DX and SX processors. Any non supported processor compatible with a Pentium should be reported as Pentium. Remark: some DOS emulators (like OS/2) emulate a 386 CPU and will report it even with a 486 or Pentium. RANDOM n1 n2 This function returns a random integer number between n1 and n2 (included). This may be useful to choose a random message from a collection, ... ERRORLEVEL This returns the errorlevel code of the last command issued. This function is only valid for - MS-DOS COMMAND.COM 3.30, 4.00, 4.01, 5.00, 6.00, 6.20, 7.00 (Win 95) - NDOS 6.0, 4DOS 4.02 - IBM PC-DOS 3.30, 6.10, 6.30 - OS/2 DOS box 1.30, 2.10, 2.11 and 3.0 - Windows NT 3.51 If a version is not supported, this returns -1 but you may force XSET to know about your version: - run the program ERRLEVEL.EXE included in the package - if it displays one line (and no more than one) like: ERRORLEVEL=xxx (where xxxx is a 4-digits hexadecimal number), type the command 'ERRLEVEL > XSET.INI' - the XSET.INI file just created must always stay in the same directory as the program XSET.EXE to be used. VARCOPY variable This is strictly equivalent to 'set dosvar=%variable%' but allows the copying of variables longer than 128 characters. ex: XSET var2 VARCOPY var1 Page 15 Input related flags: ------------------- These are modifiers that can be used to customize the user's input. /DEFAULT set current value of variable as default value for input. - this option may be disabled with /-DEFAULT ex: set name=SMITH XSET/DEFAULT/PROMPT "Enter your name:" name /TIMEOUT n breaks the input if no key was hit after n seconds; once any key has been hit, you may edit your line during any time you need. If you didn't hit any key before n seconds, the input is cancelled and the resulting DOS environment variable is set to empty (i.e., deleted) or to its previous value if the /DEFAULT flag was used. - if the time-out delay has been reached, the program will set the DOS environment variable XSET_MSG to TIME-OUT (to let you check for it), - if n = 0, the program will check for type-ahead (i.e., XSET will enter into edit mode only if a key was hit at the moment of the check), - if n < 0, time-out will be active during the whole input process; if you wait more than abs(n) seconds between two keys, the program will return the string typed so far. - this option is only active if standard input is not redirected, - this option is also active with the KEY command (see further). - this option may be disabled with /-TIMEOUT /LINE n This reads the th line from the standard input device (instead of the first one). -1 will read the last line, -2 will read the line before, ... ex: dir *.exe | XSET /LINE -2 /WORD 3 filenb This will get the number of files matching *.exe and assign it to DOS environment variable 'filenb': - read the line before the last one from the output of the 'dir' command (something like ' 15 file(s) 87912 bytes'). - pick up the third word on this line. Page 16 Prompt related flags: -------------------- These flags are interpreted immediately, before any function. /CLS Clears the screen. /PROMPT string Display a message on the screen. /COLOR color Set color for prompt (and border if any). Valid colors: BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, DARKGRAY, LIGHTGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE Remark: If a monochrome video card is detected, the /COLOR and /BACKGROUND options will be ignored; if you have a color video card and a monochrome display screen, the colors will be mapped by the screen itself as with any other program. /BACKGROUND color Set background color for prompt (and window if any). Valid colors: BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY /BLINK To choose a blinking prompt (compatible with /COLOR). - this option may be disabled with /-BLINK. /XPOS x Set cursor to column x before displaying prompt. +x or -x sets the cursor to x columns after or before current /YPOS y Set cursor to line y before displaying prompt. +y or -y sets the cursor to y lines after or before current /WINDOW left top right bottom Draw a window (using color specified with /BACKGROUND). ex: XSET/BACKGROUND RED /WINDOW 3 2 12 8 Draw a red window from position (column 3, line 2) to position (column 12, line 8). /BOX Draw a window (using color specified with /BACKGROUND) around the prompt (specified with /PROMPT); your answer (if any) will be outside the box. ex: XSET/BACKGROUND RED /BOX /PROMPT "Hello" Draw a red window with the prompt inside. /BORDER Add a border inside a window (specified with /WINDOW or /BOX). - this option may be disabled with /-BORDER. ex: XSET/BACKGROUND RED /BOX /BORDER /PROMPT "Hello" XSET/BACKGROUND RED /BORDER /WINDOW 3 2 12 8 /-BORDER /WINDOW 3 12 12 15 Page 17 String related flags: -------------------- /UPPER and /LOWER This translates the result into upper/lower-cases. Characters like ... are also translated to EA... (or ea...). - This also affects the arguments given to the KEY command, - This also affects the first argument given to the /SEARCH, /INDEX and /CHANGE option flags. May be negated by /-UPPER or /-LOWER. /LEFT n, /RIGHT n This picks the leftmost / rightmost characters of the result (or less if result is shorter than ). ex: XSET/LEFT 2 drive=%full_pathname% Remark: if n < 0 it will be interpreted as {string length - n} ex: XSET/LEFT -5 t="12345678" returns "123" XSET/RIGHT -5 t="12345678" returns "678" /MID m n This picks the characters starting from the th one of the result (or less if result is shorter than + ). First character has index 1. ex: XSET/MID 2 5 var=%other% Assigns characters 2, 3, 4, 5 & 6 from %other% to 'var'. Remark: if m < 0 it will be interpreted as {string length - m} ex: XSET/MID -3 2 t="12345678" returns "67" /COUNT This returns the number of words (separated from other ones by any number of blanks) in the result. Other word separators may be specified with the /SEPARATOR flag. /WORD n This picks the th word (separated from other ones by any number of blanks) of the result. Other separators may be specified with the /SEPARATOR flag. If no word is found, an empty string is returned. /SEPARATOR string This uses the characters from 'string' as word separator. This option is intended to be used with /WORD and /COUNT. ex: XSET/SEPARATOR "+-*/()" /WORD 3 var="25+6*(-72+3)" Assigns the string 72 to 'var' (25 is first word, 6 is second, ...). /LENGTH This returns the length of the result. Page 18 /REVERSE This reverts the result string (the first character becomes the last one). /SEARCH string This returns the portion of the result matching . ex: XSET/PROMPT "Enter your name: "/UPPER/SEARCH "SMITH" var If the answer contains 'SMITH' (even in lower-cases), variable 'var' will be assigned to 'SMITH'; otherwise, variable 'var' will be empty. /*SEARCH string The argument is a 'Regular Expression' (see further). /INDEX string This returns the index (position) of the portion of the result matching . First character has index 1. /*INDEX string The argument is a 'Regular Expression' (see further). /CHANGE string1 string2 This changes (substitutes) all occurrences of to in the result. ex: XSET/CHANGE "oldstr" "newstring" var=%answer% /*CHANGE string1 string2 The first argument is a 'Regular Expression' (see further). /MATH This performs a mathematical calculation on the string. Mathematical operators: - on integer and floating point values: + - * / () ^ (exponent) - on integer values: % (modulo) Logical operators: = < > <= >= <> return 1 if true, 0 if false Rem: '*' may be used to 'and' values, '+' to 'or' them. Precedence: + and - have the highest precedence, all other expressions are evaluated from left to right. ex: XSET /MATH var = "3+(2*5) + %new% + (%loop% <= 5)" XSET /MATH /PROMPT "Enter your calculation" result Page 19 Regular Expressions: ------------------- UNIX-like regular expressions are a way to describe a string template to match; it may be used to specify the format of a string: - only digits, - only upper-case letters, - at least one letter and afterward digits and letters, ... They are very powerful tool to express the argument given to a string searching mechanism. They are used with the /*SEARCH, /*INDEX and /*CHANGE option flags. A regular expression is one or more occurrences of one or more characters. The following symbols have a special meaning: ^ start of line (see also below: 'inside set of characters') $ end of line . any character \ quote next character (i.e., do not treat it as a special character) * match zero or more time preceding character (or character set) + match one or more time preceding character (or character set) ? match one or zero time preceding character (or character set) [] set of characters inside set of characters: ^ means non-inclusion - means range ex: [aeiou0-9] match a, e, i, o, u, and 0 through 9 [^ae0-9] match anything but a, e and 0 through 9 ex: ^[a-z]* match the first string of a line containing only lower-case letters [a-zA-Z0-9]$ match the last string of a line containing only letters (upper-case and lower-case) or digits ex: XSET /*SEARCH "[a-zA-Z]:[a-zA-Z0-9_\\.]+" myvar will search for a standard DOS filename (from standard input) [a-zA-Z] match any characters included in the range 'a' to 'z' and 'A' to 'Z'. : match the character ':' [a-zA-Z0-9_\\.] match any characters included in the range 'a' to 'z', 'A' to 'Z', '0' to '9' and the characters '_', '\' and '.'. \\ match the character following the first '\', in this case a second '\'. + match one or several characters (the preceding one, which here is a set of characters). This instruction matches any filename of the form 'drive:pathname' (ex: C:\DIR\OTHERDIR\FILE.EXT). XSET/*SEARCH "[0-9]+" var=%answer% Variable 'var' will be assigned to the first occurrence of a string containing only digits (like 2056) from the variable 'answer'. Page 20 Other flags: ----------- /APPEND This adds the result to the existing variable instead of overwriting it. This allows you to bypass the 128 character limit of DOS (see /VIEW). May be negated by /-APPEND. ex: XSET/APPEND path=";c:\msc600\bin;c:\msc600\binb" /ALL This modifies all DOS environments in memory; i.e., not only the current shell (COMMAND.COM) environment but also the previous ones (if any). ex: XSET /ALL /APPEND path=";c:\bin" Warning: If one of the environments is not big enough to contain the new variable, no error message is displayed. May be negated by /-ALL. Page 21 Special flags: ------------- Note: Except if you only use XSET as an enhanced display program (to allow you to use colors, windows, boxes, ...), you always need a DOS environment variable name except for the flags described below. XSET /ALL modifies all environments in memory. XSET /CLEAR deletes all variables from the current DOS environment. XSET /VIEW shows all variables from the current DOS environment. This is strictly equivalent to 'SET' but will show variables longer than 128 characters. Rem: If you use XSET to assign values longer than 128 characters to a variable, they will appear truncated when displayed by the DOS command 'SET'. This is only a display problem of the command 'SET'; all the variables are correctly stored and can be used without problem by any program. XSET /VIEW var displays the value of variable 'var'. This is intended to be used to pass a variable's content to the standard input of another program. This is equivalent to 'ECHO %var%|..." except that it can handle variables longer than 128 characters and you can use option flags with it. ex: XSET/LEFT 7 /VIEW myvar | LABEL a: feed the program 'LABEL' with the first 7 characters of environment 'myvar'. XSET /VIEW > SAVEFILE.VAR save all environment variables into the file SAVEFILE.VAR. XSET /LOAD loads variables from standard input. Variables must have been saved with command 'XSET /VIEW'. ex: XSET /LOAD < SAVEFILE.VAR load all environment variables from the file SAVEFILE.VAR. Page 22 XSET Data file: ============== In order to speed up execution time and to break the 255 character limit of the command-line, you may put several XSET command-line in a data file and execute them as a whole (you only load XSET once). XSET /FILE filename section To use it, just create a file containing a section name between square brackets followed by the XSET command-line you want. These lines are the same as the ones you put in a batch file but without the XSET program name. ex: XSET /FILE mydata.xst test1 Data file MYDATA.XST: ... anything ... [Test1] # This is a comment line # To uppercase all following functions /UPPER # Get current date datevar DATE # Ask user's name /CLS /BACKGROUND RED /COLOR WHITE /BORDER /WINDOW 1 1 80 25 /XPOS 10 /YPOS 5 /BLINK /PROMPT "Enter your name: " namevar # Echo answer /CLS /PROMPT "Hello %namevar%, current date is %datevar%" [End] Page 23 Remarks: 1. The % character will be used in the same way as in batch files to delimit variable names. To use an actual % character, you have to double it. 2. All the option flags you use in the same run (in either the command-line or inside a data file) are remembered in the following command-lines. 3. A data file cannot be called from another data file, although you may call several data files on the same line. 4. Section names are not case-sensitive 5. You must end your section with another section name between square brackets. A good practice would be to end each section with something like [END]. 6. A line may be commented by preceeding it with a # character. 7. If not found in the current directory (or as an absolute filename), XSET will automatically add the 'BAT' or 'BTM' extension if no extension is specified and search in the PATH. This should allow you to specify %0 as filename. Warning: XSET may not find it if it is not in your path and you change the current drive/directory inside your batch file. 8. In order to let you put your XSET data inside the batch file itself, you may preceed the data lines with two : characters; in this way they will be skipped by the batch file procesing. ex: Batch file THISFILE.BAT ... XSET /FILE thisfile.bat test1 :: [Test1] :: # Ask user's name :: /CLS /BACKGROUND RED :: /COLOR WHITE :: /PROMPT "Enter your name: " namevar ::# Echo answer ::/PROMPT "Hello %namevar%" ::[End] Page 24 XSET variable: ============= Because you sometimes want to use the same flags for a group of XSET commands (like /UPPER, /DEFAULT, ...), it would be nice to have a way to give default options to XSET. And there is such a functionality: the XSET environment variable. Before scanning the command line, the XSET program will look for the 'XSET' variable into the current DOS environment. If it exists, the XSET program will use the variable contents like option flags you would have given onto the command line. After that, it will use the option flags given onto the command line. Note that the command line options may overwrite those contained in the 'XSET' variable. ex: set XSET=/UPPER/DEFAULT/XPOS 5 /BLINK XSET /YPOS 12 /PROMPT "First name: " name1 XSET /PROMPT "Last name: " name2 This is also a way to reduce the length of your command line (remember that COMMAND.COM truncates all lines longer than 128 characters). Note that you may use XSET/APPEND to assign a very long line to the 'XSET' variable. XSET_MSG variable: ================= This variable is intended to be assigned by the XSET program itself to a message to specify special events (like a time-out on input, ...). This variable is updated (or deleted from the environment) each time the program is called. See the related options and commands to get a description of the variable contents. - options and commands using the XSET_MSG variable: /TIMEOUT Errorlevel: ========== XSET returns several values you can check with the 'if errorlevel ...' command (see your DOS manual): 0: normal termination 1: syntax error 2: environment space is full 3: not enough memory to perform operation 10: other error Rem: with the ENVFREE command, XSET returns as errorlevel the number of bytes available in the environment. Because errorlevel is limited to 255, XSET will return 255 if more environment space is available. Page 25 Installation: ============ - XSET.EXE is ready to use; no installation. Just copy XSET.EXE and XSET.TXT in a directory of your hard drive (usually a directory included in your path). If you are using Windows NT, also copy XSET32.BAT (see next section). If you want to use the demos included in this package (DEMO*.BAT), they must be copied in the same directory as the XSET program. Remember this is a SHAREWARE version intended to be used for evaluation. - To get a registered version of XSET, print the last page of this document, fill it in and send it to indicated address (by e-mail if you have access); you will then receive the password required to register your version with XSET/REGISTER. Windows NT & OS/2 specifics: =========================== XSET runs perfectly in a DOS box, either under NT or under OS/2. As long as you want to execute XSET inside a DOS batch file, it is very simple: OS/2 automatically launches a DOS box when executing a batch file (.BAT extension). NT launches, by default, .BAT files in a NT command prompt box; you have either to associate COMMAND.COM to .BAT extension (to have it permanently) or to manually launch batch file with 'COMMAND/C filename.bat'. If you want to use XSET features to modify the NT or OS/2 native environment variables, here is the solution. I developed a solution using an intermediate batch file (you do not see anything, it's transparent). Instead of using directly XSET.EXE, call XSET32.CMD with all the same arguments as XSET. Ex: XSET VAR TIME becomes CALL XSET32 VAR TIME There is a limitation, you cannot use redirections with a batch file. If you want to pipe the output of a program to XSET, just write what you want to redirect to XSET in a file called %TEMP%\_XSET_IN.TXT (this file will be erased automatically). Ex: program | XSET /UPPER VAR becomes program > %TEMP%\_XSET_IN.TXT CALL XSET32 /UPPER VAR You only need to redirect the output of XSET for the /VIEW command. Therefor, you do not even have to call XSET32, just use XSET as normal (because this command does not modify environment variables, it just displays them). Warning: be sure the environment variable TEMP points to a directory where you have write access (and there is no backslash '\' at the end). Page 26 Problems: ======== - If the size of your environment space is not large enough, you will receive an error message 'XSET : not enough environment space.' This is not a bug, it is because the environment space reserved for the variables is too small. You must increase it by modifying the line 'SHELL=...' in your CONFIG.SYS. By default, DOS reserves 256 bytes environment space; this is generally insufficient. Try 640 bytes (or more if you need it) by adding '/e:640' at the line 'SHELL=...' ex: SHELL=COMMAND.COM /E:640 /P If this problem is encountered in a secondary shell (i.e., you run the batch file from a menu that runs a secondary shell) here is a way to work around the problem (this is a DOS problem that could be avoided by the program that runs the secondary shell): put in your AUTOEXEC.BAT a line such as: SET TO_DELETE=something_very_long_to_be_sure_this_takes_a_lot_of_space and, before using variables in the secondary shell delete this --------- variable with the command: SET TO_DELETE= An other way to work around this limitation is to patch COMMAND.COM; see file 'PATCHDOS.TXT' for more details. Page 27 - If you use special characters like <>| you will have a problem because COMMAND.COM interprets these characters as redirection commands before giving the control to the program you call. This is a general DOS problem, but it is very easy to work around. ex: XSET /MATH var=(%loop% + 3) > 2 (suppose loop=1) Although you think you call XSET to check if 4 is greater than 2, COMMAND.COM interprets it as "put into a file named 2 the result of 'XSET /MATH var (1+3)'" You will have the same result with '<' and '|'. The best way to ensure that all special characters you use will be given 'as is' to the program you call (XSET or another one) is to enclose your strings between double quotes: XSET /MATH var="(%loop% + 3) > 2" Be careful not to quote XSET reserved words (commands or flags) and variable names. So do not write XSET var "MIN abc gh" or XSET "var MIN abc gh" but XSET var MIN "abc gh" - If you want to use the character '%' in a batch file, remember that this character is reserved for DOS environment variables; so, if you want to use a 'real' % character, you have to write '%%' in your batch file. ex: XSET /MATH var="%other_var% %% 7" This line in a batch file will put into variable 'var' the result of '(contents of variable other_var) modulo 7'. Notice that the use of double quotes doesn't affect the way that COMMAND.COM interprets the % character; you must double the % character even if it is quoted. - Blinking usually does not work in a Windows DOS box (3.1, 95 or NT). Instead, a light background is displayed. This is the same for any DOS program. Page 28 Batch file programming: Hints & tips ==================================== 1. Whenever it is possible, use 'SET var=...' instead of 'XSET var=...' because SET is an internal COMMAND.COM's command and is quicker than calling an external program. ex: To clear a variable, use SET myvar= instead of XSET myvar= If you are sure that the variable 'var1' is shorter than 100 characters, use SET var2=%var1% instead of XSET var2 VARCOPY var1 2. COMMAND.COM reads and executes batch files one line at a time; that means that it reads one line, execute it and rereads the file from the beginning to the next line. If you do not have a good disk-cache installed, it is not efficient. Furthermore, when using 'REM' in your batch files to insert a remark, COMMAND.COM reads the comment line, execute it (i.e., does nothing) and rereads the file from the beginning to the next line. To avoid this, there is a trick: use '::' instead of 'REM'. ':' is understood as a label to be used by the 'GOTO' statement (see your DOS documentation); this line will never be executed. As a label cannot begin with a ':', this line will not be considered as an executable line, nor as a label. ex: replace REM This batch file is intended to ... by :: This batch file is intended to ... 3. To echo an empty line on the screen, use 'ECHO:' 4. To test for the existence of a directory, test for the existence of the file 'nul.ext' in it (the filename 'nul' should be sufficient except on a Novell network, NTFS,... ). ex: if exist c:\mydir\nul.ext echo The directory 'MYDIR' exists. 5. If an environment variable contains a directory name ending with a '\', COMMAND.COM will not accept to chdir to this directory. ex: set dir=c:\mydir\ cd %mydir% ==> Error message: Invalid directory The trick (to avoid removing the trailing '\') is to add a '.' ex: cd %mydir%. (note the trailing '.') See also DEMO.BAT in this package for other tricks. Page 29 Windows features: ================ Windows uses a special variable 'windir' which determines the directory for Windows *.ini files. As it is in lowercase, you normally cannot use it - even to check it. If you give it as parameter to XSET (in lowercase), it will preserve it and allow you to use it - for example to copy it to a normal variable. Interesting note: ---------------- You may use it to have a different profile for each user. If you set 'windir' BEFORE starting windows, it will use that value. That way you don't need to have WIN.COM in each user's directory. page 30 Additional information: ====================== Feel free to contact me with any problem or question. If you have an electronic mail connection, this is the quickest, cheapest and easiest way (this would allow me to test your batch files in case of problems or bug). Marc Stern Av. de la Basilique 376 bte 19 1081 Bruxelles Belgium Tel: +32-2 427.98.52 ( after 18h Central European Time ) Web: http://members.tripod.com/~marcstern/xset.htm E-mail: mstern@cscmail.csc.com (internet) >INTERNET:mstern@cscmail.csc.com (compuserve) If this internet address is not available, try this one: marcstern@hotmail.com If both addresses are not available, ask my new one to vgoovaer@csc.com or mrappe@cscmail.csc.com or brsp@ti.com Page 31 How to register =============== 1. Check for latest version --------------------------- First try to connect to XSET Web site (see previous page) to get the most up-to-date version. 2. Registration info -------------------- Please complete the following form and send it to me (via E-mail if possible). You will then receive the password to register your version of XSET (Type 'XSET/REGISTER'). Try to answer the questions, as it will serve for my statistics to enhance the program in the best way (that means your way!). 3. How to pay ------------- Without additional fee ---------------------- * Cash Almost any currency is accepted, please ask for the exact amount. * Euro-cheque * International Postal Money Order: You give the money at your local mail office, this is no cheque. In US it is called 'USPS Authorization to Issue an International Money Order'. With 500 BEF additional fee --------------------------- * International Cheque * Put the money onto my bank account * American Express International Money Order: Almost any currency is accepted, please ask for the exact amount. If you have any problems due to change or whatever, please contact me and I will explain to you how to pay in another currency. Do not be discouraged by money transfer problems, simple solutions exist to easily register from anywhere around the world (they generally are dedicated to each geographical and/or social situation, so I cannot describe them all in this document). XSET 5.01 Registration Form Date ________________ Name: _____________________________________________________________ (Company:) _____________________________________________________________ Address: _____________________________________________________________ _____________________________________________________________ _____________________________________________________________ Tel: _____________________ Fax: _______________________ E-mail: __________________________________________ From where did you find XSET : ____________________________________ XSET features you find most useful: ____________________________________ ________________________________________________________________________ Features you find least or not useful: _________________________________ ________________________________________________________________________ Features you would like to see added (use additional pages, if necessary): _________________________________________________________________________ _________________________________________________________________________ MS-DOS (or DR-DOS,...) version : ___ shell (4DOS, NDOS,...) : ________ Windows or OS/2 version: ___ Price: Personal use : 600 BEF x .... ________ upgrade : 300 BEF x .... ________ Company : 1200 BEF x .... ________ upgrade : 600 BEF x .... ________ Network - Site : 10000 BEF ________ upgrade : 5000 BEF ________ Signature: