[net.micro.pc] switchar

markz@microsoft.UUCP (Mark Zbiokowski) (08/31/83)

Amazing.  Using undocumented features that may (and probably will) change
in future releases is NOT the way to generate portable software.  Using
SWITCHAR itself is a great way to jump into non-portability.  Shell scripts
(oops, I mean BAT files) are no longer portable without porting the CONFIG.SYS
file also.  Somehow, the thought of rebooting between applications dows not
appeal to me.

Mfarber@UDel-Relay@sri-unix.UUCP (09/01/83)

In a previous message to Info-IBMPC, someone mentioned putting
"SWITCHAR = -" in the CONFIG.SYS file (in DOS 2.00).  I have written a
program that will either report or set the SWITCHAR from the DOS
command level.

By the way, does anyone know how to set a DOS 2.00 PATH from Assembly
Language?  Or how to read the directory character (\ normally, changes
to / if SWITCHAR is changed to -).

-Manny

I found out the data under "explanation" by disassembling some DOS 2.00
utilities.

***** Requires DOS 2.00
; ---------- Explanation

; This program uses the SWITCHAR function of the DOS function request
; interrupt.

; This DOS function, 37H is listed by IBM as "used internally by DOS".
; It is passed either 1 or 2 parameters, depending on usage.

; To get the current SWITCHAR, put 37H in the AH register, 00H in the
; AL register, and generate an INT 21H. The current SWTICHAR will be
; returned in the DL register.

; To change the current SWITCHAR, put 37H in the AH register, 01H in
; the AL register, the new SWITCHAR in the DL register and generate an
; INT 21H.

; ---------- Program Usage

; Syntax is SWITCHAR [n[n]] where "n" is a hex digit. If one
; if n[n] is supplied, the SWITCHAR is changed to the ASCII character
; that n[n] represents. For example, the command "SWITCHAR 21" would
; change the SWITCHAR to "!".

; Remember: EXE2BIN SWITCHAR.EXE SWITCHAR.COM after linking

sc	segment
	assume cs:sc,ds:sc
	mov bx,5dh			; point to parameter 1
	cmp byte ptr [bx],20h		; no parameters passed?
	jne set				; no-set SWITCHAR
	mov ax,3700h			; (yes)-read SWITCHAR
	int 21h
	mov byte ptr report+100h+12,dl	; prepare report string
	mov ah,9			; print report string
	mov dx,offset report+100h
	int 21h
	int 20h				; return to DOS
set:	cmp byte ptr [bx+2],20h		; parameter too long?
	jne error			; yes
	mov ax,[bx]			; (no)-get parameter
	cmp ah,20h			; is it a 1-digit hex number?
	jne s_1				; no
	mov ah,30h			; (yes)-make that digit a '0'
s_1:	xchg al,ah			; order L/H order bytes correctly
	sub ax,3030h			; convert AL & AH
	cmp al,22			; error?
	ja error			; yes
	cmp ah,22			; error?
	ja error			; yes
	mov bx,offset hex+100h		; table
	xlat				; translate AL
	cmp al,'E'			; error?
	je error			; yes
	mov dl,al			; (no)
	mov al,ah			; prepare H order digit for XLAT
	xlat				; translate it
	cmp al,'E'			; error?
	je error			; yes
	shl al,1			; (no)-store this nibble in the DL reg
	shl al,1
	shl al,1
	shl al,1
	add dl,al
	mov ax,3701h			; change the SWITCHAR
	int 21h
	int 20h				; return to DOS
error:	mov ah,9			; print ERRMSG
	mov dx,offset errmsg+100h
	int 21h
	int 20h				; return to DOS
report	db 'SWITCHAR is _',13,10,'$'
errmsg	db 'SWITCHAR must be a 1- or 2-digit hexadecimal number',13,10,'$'
hex	db 0,1,2,3,4,5,6,7,8,9,7 dup('E'),0ah,0bh,0ch,0dh,0eh,0fh
sc	ends
	end

[SWITCHAR.ASM has been added to the Info-IBMPC library.  -Ed.]

roper@uw-june.UUCP (10/26/86)

What is "switchar"?  I have stumbled across a couple of cryptic
references to it and my curiosity is piqued.  From what I was
able to infer, it seems to be an environment variable in DOS that
can be set to change the character used as a separator in pathnames.
I tried it several ways but couldn't get it to work (DOS 3.2).
I would like to be able to use the '/' character in any event.

-- 

--Michael Roper      ARPA:  roper@june.cs.washington.edu
                     UUCP:  {ihnp4|decvax|ucbvax}!uw-beaver!uw-june!roper
                    CSNET:  roper.uw-june@rand-relay

  

jallen@netxcom.UUCP (John Allen) (10/27/86)

In article <1402@uw-june> roper@uw-june.UUCP writes:
>What is "switchar"?  I have stumbled across a couple of cryptic
>references to it and my curiosity is piqued.  From what I was
>able to infer, it seems to be an environment variable in DOS that
>can be set to change the character used as a separator in pathnames.
>I tried it several ways but couldn't get it to work (DOS 3.2).
>I would like to be able to use the '/' character in any event.

There is an undocumented DOS function (sorry, I don't have it at hand)
which allows the switch character to be read or set.  The switch character,
as the name implies, is used to delineate command line switches.  The
default character is '/' under DOS.  I like to use '-' instead, since
I'm likely to type that without thinking about it.  Every DOS command,
Microsoft C, and many others seem to use the undocumented call to read
the switch character, or atleast accept the '-' that I like to use.

When the switch character is something other than a slash, Unix-like
path names may be used in almost all circumstances.

John Allen
=========================================================================
NetExpress Communications, Inc.      seismo!{sundc|hadron}!netxcom!jallen
1953 Gallows Road, Suite 300         (703) 749-2238
Vienna, Va., 22180
=========================================================================

bill@hp-pcd.UUCP (bill) (10/27/86)

I've never used it, and Microsoft doesn't support it, but I can
tell you what it's for.  By changing the switch character from "/" to "-",
DOS will allow Unix-style forward slashes in path names; you then have
to use the hyphen (dash) character, like Unix, to indicate command line
switches.

Changing the switch character may make things "friendlier" and more "Unix-
like" for you, but watch out.  Any batch files you create probably won't
work on other people's machines; any that you acquire from elsewhere will
probably have to be modified to run on your machine.  Also, you may run
into problems with applications that programmatically EXEC another file
(possibly passing command line switches) or with programs that parse
path names.  Microsoft didn't document SWITCHAR because they didn't want
people to use it, since it can potentially add a lot of confusion.

bill frolik
hp-pcd!bill
Hewlett-Packard Portable Computer Division
Corvallis, Oregon

wtm@neoucom.UUCP (Bill Mayhew) (10/28/86)

Hi,

You are correct that switchar seems to be broken in DOS 3.x.
Following is a brief batch file that you can run that uses debug to
to create a small .com file that allows you to set the switch
character at the prompt level in (seemingly) any version of DOS.
Be careful though, some programs are to dumb to realize that you've
changed the switchar, and will bomb when they call their overlays.

Bill Mayhew:  (wtm@neoucom.UUCP  ...!cbatt!neoucom!wtm)

------------------------previous article-----------------------

>From few@well.UUCP Wed May 28 01:33:54 1986
>Newsgroups: net.micro
>Subject: Re: Changing SWITCHAR in dos 3.x
>
>In article <883@brl-smoke.ARPA> bridger@RAND-UNIX.arpa writes:
>>The MS-DOS COMMAND.COM shell uses the forward slash '/'
>>as its SWITCHAR to designate command-line parameters.
>>In dos versions 2.x the following line could be added
>>to the CONFIG.SYS file to change that character to a '-',
>>allowing the '/' to be used as a separator for directory
>>names in a path:
>>        SWITCHAR=-
>>This doesn't work for dos 3.1.  Is there another way to do it?
>
>I've posted this program a couple of times, but never this way before.
>Save the following as SW.BAT:
>-----
goto END
e 100 F6 06 80 00 FF 74 09 8A 16 82 00 B8 01 37 CD 21
e 110 B8 00 37 CD 21 88 16 30 01 BA 22 01 B4 09 CD 21
e 120 CD 20 53 77 69 74 63 68 20 63 68 61 72 20 3D 20
e 130 00 0D 0A 24
rcx
34
n switch.com
w
q
:END
debug <sw.bat
>-----
>SWITCH will tell you what the current switch character is, while
>SWITCH c will set the switch character to c.
>-- 
>Frank Whaley
>EFS Management Software, Inc.

kneller@ucsfcgl.UUCP (Don Kneller%Langridge) (10/30/86)

In article <145@netxcom.UUCP> jallen@netxcom.UUCP (John Allen) writes:
>In article <1402@uw-june> roper@uw-june.UUCP writes:
>>What is "switchar"?  I have stumbled across a couple of cryptic
>>references to it and my curiosity is piqued.
>
>The switch character,
>as the name implies, is used to delineate command line switches.  The
>default character is '/' under DOS.  I like to use '-' instead, since
>I'm likely to type that without thinking about it.  Every DOS command,
>Microsoft C, and many others seem to use the undocumented call to read
>the switch character, or atleast accept the '-' that I like to use.

Be careful though.  LINK and LIB don't use switchar, relying on / only.
Also, when switchar is -, for COMMAND.COM you *must* give the path to
executable files with /; \ won't work anymore.  Eg. \bin\cl is now /bin/cl.
The above applies for DOS 3.1
-- 
	Don Kneller
UUCP:	...ucbvax!ucsfcgl!kneller
ARPA:	kneller@cgl.ucsf.edu
BITNET:	kneller@ucsfcgl.BITNET

guido@mcvax.uucp (Guido van Rossum) (11/01/86)

In article <15200040@hpcvlo.UUCP> bill@hp-pcd.UUCP (bill frolik) writes:
>Microsoft didn't document SWITCHAR because they didn't want
>people to use it, since it can potentially add a lot of confusion.

Yeah, the real question is, why did they add the code in the first
place?  Sounds like somebody working on the code added it without
approval.  An alternative theory is that when MS-DOS 2.0 was first
created, they weren't so sure that they were right in making / the
option characer and \ the filename separator, and added some Trojan
horse to their own software so that at a later time they could switch
and people with old copies of MS-DOS would be able to use new software
without getting a new copy of MS-DOS.  Obviously, the switch never came,
so maybe it should be removed from MS-DOS 3.0 (or has it already been
removed?).

Incidentally, the file system always accepts both / and \ in file names;
it's only the shell (COMMAND.COM) and some applications that don't grok
/ in file names because it is always seen as an option, even in the
middle of a word!
-- 
	Guido van Rossum, CWI, Amsterdam <guido@mcvax.uucp>

landauer@sun.uucp (Doug Landauer) (11/07/86)

In article <15200040@hpcvlo.UUCP> bill@hp-pcd.UUCP (bill frolik) writes:
>Microsoft didn't document SWITCHAR because they didn't want
>people to use it, since it can potentially add a lot of confusion.

In article <7129@boring.mcvax.UUCP> guido@boring (Guido van Rossum) writes:
>Yeah, the real question is, why did they add the code in the first
>place?  Sounds like somebody working on the code added it without
>approval.

My guess (total speculation, since I don't know anyone who was involved):

Microsoft had some people familiar with Unix, and when they got DOS-86 (or
whatever it was called) from SCP, they wanted to start adding Unix features
to the system.  They wanted to add a Unix-like hierarchical file system, but
DOS-86 already used "/" for the command switches.  (DOS-86 used "/" because
CP/M did; CP/M used it because of the DEC systems (RT11?) that Kildall had
used when he developed CP/M.)

So they added SWITCHAR so that they could use "/" for the filename separator
without provoking the wrath of the marketing people who thought that MS-DOS
had to retain its command-level similarity to CP/M.

Why the awful choice of backslash (with a different location on every
different keyboard) was made, I'll never know (unless anyone at Microsoft is
listening and would like to correct me.  (Except, I don't think they're
allowed to post news.))  Why not hyphen, semicolon or comma?

>Obviously, the switch never came, so maybe it should be removed from MS-DOS
>3.0 (or has it already been removed?).

The "SWITCHAR=?" option in CONFIG.SYS doesn't work in PC-DOS 3.XX,
but the system call (INT 21/Function ??) still works.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Anyway, It's clear that this whole problem is primarily DEC's fault, for
being so slow to recognize Unix' benefits, and for hanging on to their
"rainbow" of PDP11 operating systems instead of jumping on the Unix
bandwagon ten or twelve years ago when it was only a rubber-band wagon.
									:-)
--
	Doug Landauer		    Sun's Net:		 landauer@morocco
	Phone:   415 691-7655	    ARPANET (aka DDN):   landauer@sun.com
	UUCP:  {amdahl, decwrl, hplabs, seismo, ...}!sun!landauer