[comp.sys.ibm.pc] using "/" in pathnames

sullivan@marge.math.binghamton.edu (fred sullivan) (05/30/88)

Some time ago someone complained about having to use "\" in MSDOS
pathnames.  I just submitted to comp.binaries.ibm.pc a program to
fix this.  Similar programs are available as part of Dan Norton's
package of tools (swchar) and from simtel20 
(pd1:<msdos.keyboard>switchar.*).

Fred Sullivan
Department of Mathematical Sciences
State University of New York at Binghamton
Binghamton, New York  13903
Email: sullivan@marge.math.binghamton.edu

nelson@sun.soe.clarkson.edu (Russ Nelson) (05/30/88)

In article <1238@bingvaxu.cc.binghamton.edu> sullivan@marge.math.binghamton.edu (fred sullivan) writes:
>Some time ago someone complained about having to use "\" in MSDOS
>pathnames.  I just submitted to comp.binaries.ibm.pc a program to
>fix this.  Similar programs are available as part of Dan Norton's
>package of tools (swchar) and from simtel20 
>(pd1:<msdos.keyboard>switchar.*).

Several caveats about '/' vs '\' in pathnames:

  o Theoretically, '/' is usable in pathnames at all times.
  o The Set Switchar (3701h) and Get Switchar (3700h) DOS functions *are*
    documented.  Don't let Microsoft tell you otherwise.  I will send a
    photocopy of the page in Zenith's Programmers Utility Package that
    documents the call to anyone who sends me an SASE.
  o Command.com thinks that '/' is the switchar.  Using the Set Switchar
    DOS call, you can set the switchar to '-'.  This lets you use '/' as
    a pathname separator.
  o Most PC Magazine programs and the Norton Utilities ignore the
    switchar='-' setting.  In certain places, they parse the pathname,
    looking ONLY for '\'.
  o DOS Backup is rumored to go whacko with switchar=-.
  o Turbo C has two undocumented functions in its library: setswitchar(char c),
    and char getswitchar().  They do just what you think they do.
  o All of the software I write is guaranteed to work with switchar=-.  :-)

If you are interested in writing software that works with switchar=-,
then do this:
  o if (getswitchar() == '/') Pathchar = '\\' else Pathchar = '/';
  o When parsing pathnames, search for '\' OR Pathchar.
  o Of course, when parsing parameters, look for your switches to begin
    with getswitchar().

Typically, when I find a useful PC Magazine utility, I modify it to use
switchar=-.  Thank goodness that they have the good sense to publish
source!

-- 
char *reply-to-russ(int network) {
if(network == BITNET) return "NELSON@CLUTX";
else return "nelson@clutx.clarkson.edu"; }

wheels@mks.UUCP (Gerry Wheeler) (05/31/88)

In article <1238@bingvaxu.cc.binghamton.edu>, sullivan@marge.math.binghamton.edu (fred sullivan) writes:
> Some time ago someone complained about having to use "\" in MSDOS
> pathnames.  I just submitted to comp.binaries.ibm.pc a program to
> fix this.
> Fred Sullivan

MKS includes such a program in the MKS Toolkit.  Changing the switch
character to '-' (or anything other than '/') can have unexpected side
effects, though.  I get calls from users who have problems doing that. 
For example:

1) Programs that use command.com to execute a sub-task (some makes, some
editors, etc.) may fail.  They assume that the switch character is '/',
so they try to do "command /c foo" (or whatever).  Of course,
command.com checks the switch character, sees it has been set to '-',
and decides that "/c" must refer to a directory.  It prints an error
message when it can't find /c, and enters interactive mode.  The user
has to type EXIT to return to the application. 

Note that the code in Microsoft's C Compiler's system() function
exhibits this behaviour.  Since they wrote both the OS and the compiler,
you'd think they'd write code that checked for this. 

2) As a side side effect, once users start using '/' in path names,
they use them everywhere, including environment variables. This is
to be expected. However, some programs, like Microsoft C, won't
correctly read variables that contain '/'. They will only accept
'\' in path names.

3) As of version 3.2 (I think) of DOS, you may not use '/' in
config.sys.  Prior to that, you could use either slash.  How much code
did they have to add to ensure you used only one kind?

However, in general, if you are looking for a more Unix-like interface,
this is probably the first thing you'll want to change. Most programs
work fine. Just remember to keep yours eyes open for the oddballs.
-- 
     Gerry Wheeler                           Phone: (519)884-2251
Mortice Kern Systems Inc.               UUCP: uunet!watmath!mks!wheels
   35 King St. North                             BIX: join mks
Waterloo, Ontario  N2J 2W9                  CompuServe: 73260,1043

nather@ut-sally.UUCP (Ed Nather) (06/01/88)

In article <460@mks.UUCP>, wheels@mks.UUCP (Gerry Wheeler) writes:
> 
> MKS includes such a program in the MKS Toolkit.  Changing the switch
> character to '-' (or anything other than '/') can have unexpected side
> effects, though.
> For example:
> 
> Note that the code in Microsoft's C Compiler's system() function
> exhibits this behaviour.  Since they wrote both the OS and the compiler,
> you'd think they'd write code that checked for this. 
> 

But they didn't.  However, Tony Movshon wrote a sane version of system() that
checks, and it solves the problem entirely.  He posted it a long time ago, so
it's probably in the net.sources.pc archives, wherever *they* are.  I can
re-post it (or mail it) if there is any interest.  I use it all the time.

> 2) As a side side effect, once users start using '/' in path names,
> they use them everywhere, including environment variables. This is
> to be expected. However, some programs, like Microsoft C, won't
> correctly read variables that contain '/'. They will only accept
> '\' in path names.

Actually, I've found that the MSC compiler-linker system will accept 
"/" in environment pathnames for everything except the path to "lib" -- 
apparently whoever wrote the linker didn't bother the check. (Also true 
of "tlink," Borland's linker.

> 3) As of version 3.2 (I think) of DOS, you may not use '/' in
> config.sys.  Prior to that, you could use either slash.  How much code
> did they have to add to ensure you used only one kind?
> 
In most programs it involves 2 assembly-language instructions to check. I
use 3.1 and can use "/" in config.sys; I was astounded to learn I couldn't
use it in 3.2.

> However, in general, if you are looking for a more Unix-like interface,
> this is probably the first thing you'll want to change. Most programs
> work fine. Just remember to keep yours eyes open for the oddballs.

Several programs have been posted that allow the DOS variable SWITCHAR to be
displayed or changed.  When all else fails you can use it.  I've managed to
live using "/" in pathnames for several years, but it has been, at best, an
uneasy truce.

-- 
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather@astro.AS.UTEXAS.EDU