WSWAP

Version 1.2
February 1995
Shareware


INTRODUCTION

Do you find yourself altering your windows configuration files/settings depending upon how you've booted your PC?  Although Microsoft with DOS 6 has given us a menuing facility for Config.sys, there is nothing to help manage possible variations in System.ini and Win.ini.  This utility addresses that particular need, as well as others.


HOW IT WORKS

This program works for any text file that supports comments.  This includes .INI files (which use a semicolon ";") batch files (which use the reserved word "REM") and others.  In these cases, optional lines are surrounded by comments which look as such:
	<COMMENT-KEY> SWAP KEYWORD OPTION(s)
		[optional line(s)]
	<COMMENT-KEY> SWAP KEYWORD END

NB - all tokens including the COMMENT-KEY are case-sensitive, SWAP and END must be in uppercase, and the COMMENT-KEY must be followed by a space before SWAP.

When the WSWAP program is executed, a single KEYWORD and OPTION selection is included on the program's command line.  If there is a match between the keyword listed on the command line with a keyword in the input file, the optional lines are uncommented.  Lines which don't match are commented out.  Where multiple options are possible for the same keyword, groups can be specified one after the other with the END line being the last line.  Such an example from System.ini follows:
	;
	[boot]
	; SWAP NET NetWare
	; network.drv=NETWARE.DRV
	; SWAP NET Vines VinesAsync
	; network.drv=VINES.DRV
	; SWAP NET END

[NOTE:  The semicolon starting each line must be followed by a space character in this example, and the semicolon in the beginning of the file tells WSWAP what the COMMENT-KEY is.]

In the above example, the keyword is NET and depending upon which option we select (NetWare, Vines or VinesAsync) we will end up with the appropriate network.drv driver loaded.  For example, we might have our Config.sys file present us with a menu to load either Novell or Banyan network protocol drivers, and then depending upon which is selected our Windows environment will be set correctly to load the corresponding Windows drivers (by using the %CONFIG% variable that DOS supplies us).


SOME MORE EXAMPLES

Variable Protocol.ini or Net.cfg

You can setup your NIC card configuration files with settings for different card combinations.  Altering your NIC card can then be made as simple as running a batch file to select the new card.

PROTOCOL.INI file
;
[PROTOCOL MANAGER]
	DRIVERNAME = PROTMAN$

[VINES_XIF]
	DRIVERNAME = NDISBAN$
; SWAP NIC XIRCOMP1 XIRCOMP2 XIRCOMP3 XIRCOMCE XIRCOMCE_IBM
	BINDINGS   = XIRCOMNET
; SWAP NIC ETHPOCK
;	BINDINGS   = ETHPOCK
; SWAP NIC END

[XIRCOMNET]
	DRIVERNAME = XIRCOM$
; SWAP NIC XIRCOMCE
;  	IOADDRESS = 0x300
;  	INT = 5
;  	MEM = 0xD000
;  	IOWORDSIZE = 16
;  	SOCKET = 1
; SWAP NIC XIRCOMCE_IBM
 	IOADDRESS = 0x300
 	INT = 5
 	MEM = 0xD400
 	IOWORDSIZE = 16
 	SOCKET = 2
; SWAP NIC XIRCOMP1
; 	INTERRUPT=7
; 	PRINTERPORT=LPT1
; SWAP NIC XIRCOMP2 XIRCOMP3
; 	INTERRUPT=7
; SWAP NIC END


NIC.BAT
@echo off
cls
echo Changing NIC card settings to %1
pause
wswap NIC %1 \config.sys \autoexec.bat \ndis\protocol.ini \net.cfg


NOTE: In the above PROTOCOL.INI example, the line with 
	; SWAP NIC XIRCOMP1 XIRCOMP2 etc
can be abbreviated as
	; SWAP NIC XIRCOM*
See below on the section on Usage for further information.


Batch files

You may want to vary the type of mouse driver used by the system.

MOUSE.BAT
REM
@echo off
REM SWAP MOUSE MSMOUSE
REM set mouse=C:\msmouse
REM C:\msmouse\mouse.exe
REM WSWAP MOUSE MS %Windows%\system.ini
REM SWAP MOUSE BALLPT
REM SET MOUSE=C:\BALLPT
REM C:\BALLPT\MOUSE
REM WSWAP MOUSE BALLPT %Windows%\system.ini
REM SWAP MOUSE DOS
SET MOUSE=C:\DOS
C:\DOS\MOUSE
WSWAP MOUSE DOS %Windows%\system.ini
REM SWAP MOUSE END

Then to select a different mouse driver, you'd type something like:
wswap MOUSE MS mouse.bat

Now whenever you run MOUSE.BAT, you'll get the right mouse driver for both DOS and Windows.


Smart CONFIG.SYS

Now your CONFIG.SYS files can remember the setting chosen during the last boot and make it the default for the next boot.  For example, in the office I want my network driver loaded (the default) but when at home I select a Standalone configuration and from that point on I want the default during reboots to be Standalone (until I return to the office).  This config file demonstrates this usage:

CONFIG.SYS

REM
[Menu]
MenuItem=Standalone
MenuItem=Vines
SubMenu FullMenu,--> Full Menu Selection
REM SWAP NET Vines
REM MenuDefault=Vines,5
REM SWAP NET Standalone
MenuDefault=Standalone,5
REM SWAP NET DEFAULT
REM MenuDefault=FullMenu
REM SWAP NET END

Now in my Autoexec.bat I place the line:
wswap NET %CONFIG% \config.sys

Note that the %CONFIG% variable is automatically set for you by DOS.


USAGE

	WSWAP KEYWORD OPTION_SELECTION file_list

file_list is any number of file names seperated by spaces.  Each file can be prefixed by either of or a combination of the "+", "-", "*", "^" or "!" symbols which cause special processing to take place (there is also a "=" for debug messages).

A "+" will activate lines that match, but will not touch lines that do not, so that if other options are already active they will remain so (useful to add driver lines in .ini files).  For example, you may load a Vines driver in System.ini and then wish to activate a FTP TCP/IP driver in addition to the Vines driver.  Typing:
wswap NET Vines system.ini
wswap NET FTP's +system.ini

results in
; SWAP NET Vines VinesAsync
network.drv=VINES.DRV
; SWAP NET ENS
;      network.drv=ENSNETW.DRV
; SWAP NET FTP's
network.drv=PCTCPNET.DRV
; SWAP NET SunNFS
;      network.drv=PCNFS.DRV
; SWAP NET NONE DEFAULT
;      network.drv=
; SWAP NET END

Without using the "+" in front of system.ini on the second line, the Vines driver would be deactivated.

The "-" symbol does the reverse of "+" where it comments out the match and leaves the other choices unaltered.

The exclamation "!" symbol will prevent special error checking from taking place.  Special error checking includes the file difference warning that is printed out at the end of processing if the resultant file is different in size from the original file by 5% or more (this is an error check which might produce false warnings if the input files are small - using the "!" option disables this checking).

The "*" symbol will include the lines that match and DELETE the lines that do not match.  It is useful for "cleaning" the file (NB - if necessary, make a copy of the original before doing this because the deletions are permanent).  Note that the OPTION lines are also similarly affected.

A "^" will change all comparisons made to be case insensitive (note: this includes the COMMENT-KEY, KEYWORDS, OPTIONS and the END and DEFAULT special options - any of these can be a mix of lower and upper case).

The word DEFAULT is a reserved selection option that will be chosen if none of the other options match.  It should be the last option listed, and can be combined with other valid options as shown in the above example (NONE and DEFAULT).  Typing "wswap NET NONE system.ini" or "wswap NET XXX system.ini" (where XXX doesn't match any of the options in the input file) will result in the "network.drv=" line being selected in the previous example.  Without the DEFAULT option, all the selections would be commented out.  So specify a DEFAULT option if you want at least one selection to be made active.

Lastly, OPTIONS in both the input file and on the program command line can use the * character as a wildcard at the end of the string.  For example, a file with
	; SWAP NET Vines*
would be matched by the command:
	WSWAP NET Vines  -or-  WSWAP NET VinesAsync

And the input file
	; SWAP NIC XIRCOMP1 XIRCOMP2
would be matched by the command:
	WSWAP NIC XIRCOM*

Because of this, if you do not want to use wildcards then DO NOT use the wildcard character in your selected option names.


INPUT FILE FORMAT

The first line of any input files must contain the token id used for comments.  It will usually either be ";" or "REM" (without the quotes).  So the first line of your System.ini and Win.ini files should contain a single semi-colon and nothing else if its going to be used with WSWAP.  Note that unless you switch off case sensitivity, the comment key case must match exactly.

The comment token must be followed by either a space or tab character.  On identifier lines (where the SWAP KEYWORD is specified) the comment token should be followed by a space and then the word SWAP (in uppercase).

If you wish to include comment lines inside the selections, then one way of doing this is to mix the cases using a different combination from what is used in the first line of the file (eg. use Rem if the first line reads REM) - note this will only work if case sensitivity is left enabled.  Some characters may be repeated (the semicolon for example - if the first line reads ; then lines with ;; or even ;;; will remain as is).


OPTION LINES

Option lines are lines which contain environment variables which you want substitued.  These lines can be either contained in "<COMMENT-KEY> SWAP" configuration groups, or on their own.  The following is an example of an internet configuration file:

	; OPTION IP host address = %IP_ADDR%
	blank line (or any dummy line) - this line will be replaced
	; More configuration lines

Running WSWAP IP X with IP_ADDR=129.1.0.1 (set with SET IP_ADDR=129.1.0.1 at the DOS prompt) will result in:

	; OPTION IP host address = %IP_ADDR%
	host address = 129.1.0.1
	; More configuration lines

Changing the DOS environment variable IP_ADDR and running WSWAP again will alter the second line to reflect the new address.  Note that it is important to have a blank (or filled in) line following the OPTION line because that line will be overwritten with the new setting.  In the above WSWAP command line, the X would normally be used to select other WSWAP groups.  If the file does not have ; SWAP lines, then the X can be anything and is not used (but whatever it is, it must be included on the command line).


CREDITS

The initial idea for this program came from need and an earlier program, called WINSWAP, which I found somewhere on the internet.  It went part way to solving the particular problem I had - I just added more bells and whistles.  I'm sorry that I can't personally give the author of that program credit for his idea - I've since lost the program.


MODIFICATION HISTORY

1.0	August 94 - Initial release to the public domain
1.01	November 94 - Minor changes to accompanying documentation
1.1	January 95 - Now check for disk full condition and more sanity checking.  Added ^ and = (debug) prefix options to file list, and added wildcard '*' support in options selection list.
1.2	Added OPTION selection and "!" prefix.  Prefixes can now be combined.


SUGGESTIONS FOR IMPROVEMENTS

If you want to offer suggestions for possible improvements, send an internet email to:
	Steve.Karra@east.sun.COM

Or if you receive an undeliverable mail notification for the above email address, drop a postcard to:
	Steve Karra
	184 Captain Eames Circle
	Ashland  MA  01721
	USA

Enjoy.
Steve Karra.