Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!oliveb!stratus!gbs From: gbs@stratus.UUCP (George B. Smith) Newsgroups: comp.sys.ibm.pc Subject: Re: pathnames Message-ID: <1623@stratus.UUCP> Date: 11 Feb 89 04:56:26 GMT References: <2569@pegasus.ATT.COM> <3847@cbnews.ATT.COM> <662@mks.UUCP> <10353@ut-emx.UUCP> Reply-To: gbs@stratus.UUCP (George B. Smith) Organization: Stratus Computer, Inc. Western Development Center Lines: 85 In article <10353@ut-emx.UUCP> nather@ut-emx.UUCP (Ed Nather) writes: >In article <662@mks.UUCP>, wheels@mks.UUCP (Gerry Wheeler) writes: >> If I may, I'd like to make a request of you software authors out there >> -- please write your programs so they will handle either type of slash >> in pathnames. It would make life easier for many people. > >It would indeed. Most of the MS-DOS utilities will accept either one, >but "subst" will not, and both MSC and Borland's linker demand backslashes. >A recent conversation about Borland's new debugger, which also demands > >"Well, OS2 doesn't allow it, so get used to backslashes." I have to whole heartedly agree with Gerry on this one. I would like to ask all software authors, commercial and public domain, please make sure your programs can handle either the forward slash or back slash character as the separator. You know it is sooOOOoooo easy to do, there is no reason that I can understand not to. Some people might say, "It is an undocumented feature so I won't use it!" Yet so much DOS software *must* use other undocumented stuff I can't see why *this* feature is singled out for avoidance. I have seen some programs published by PC Mag which uses every trick (not) in the book for TSRs but don't handle the '/' as a path separator. And it is very easy to do, as I said before. All a program has to do is find out the current setting of the switch char. This is a trivial task for a program. In fact, in Turbo C v2.0, in the file getopt.c supplied by Borland, there is the 3 lines necessary to get the current switch char. Then, if the current switch char is '-', then assume the path separator is the '/'; if the switch char is not the '-', then I would say it is safe that you can assume the path separator is the '\'. When I ported the BSD indent(1) program to DOS, I had to modify the code to handle creating backup file names. Enclosed below is the code segment for how I handled it: /* * copy input file to backup file. * * The strategy for handling appending a suffix has been modified * from the original for use on MS-DOS. * * If there is no suffix on the input file name then the suffix * ".BAK" will simply be concatenated. If there is a suffix, * then it will be stripped before the ".BAK" is concatenated. * * However, for MS-DOS, we must check to see what the *probable* * path separator character is by looking at the value of the current * command line switch character. If the 'switchar' is a '-' as in UNIX, * then we will assume the path separator is a '/'. If the 'switchar' * is not '-', then we assume it is a '/', the MS-DOS standard, and * assume the path separator character is the MS-DOS standard '\'. * * Then make the backup file the input and original input file the output. */ bakcopy() { int n, bakchn; char buff[BUFSIZ]; register char *p; char *rindex(); char path_separator; /* depends on current DOS switchar */ char suffix[4]; /* buffer for any filename suffix */ char *strsuffix(char *, char *); /* get string suffix */ /* first, construct the backup filename */ path_separator = (getswitchar() == '-') ? '/' : '\\'; if ((p = rindex(in_name, path_separator)) != NULL) p++; else p = in_name; (void)strcpy(bakfile, p); if (strsuffix(bakfile, suffix) != '\0') { p = rindex(bakfile, '.'); *p = '\0'; } (void)strcat(bakfile, ".BAK"); Again, I urge all software writers to add this very easy, nice to the user feature to their programs. It would sure make going between UNIX and DOS much more pleasant. George B. Smith Stratus Computer, Inc gbs@stratus.stratus.com {amdahl,oliveb,uunet}!stratus!gbs