[comp.os.msdos.programmer] misc

Rob.Wedlock@samba.acs.unc.edu (Rob Wedlock) (01/07/91)

D
For those of you looking for 
DOS undocumented: The editor is Schulman, the publisher Addison-Westly
I falied to mention that when I mentioned the book before.

For anyone that can use it: A dos interrupt from this book...

ah=60h
ds:si:pointer to asciiz file name or path input
es:di pointer to 128 byte buffer top hold output, an asciiz string
int 21h

you feed it a file name which can include '.','*',network drive letter
susbt drives, joined drives, or even files that dont exist yet
it spits out a carry if there was an error, or else a fully
expanded file name path all capitalized, * -> ??? , capitalized
subst drives expanded, networkdrives become \\....
However it can expand it to refer to a physical drive pathname , it will.

Hope this helps someone! Thanks for all the help yall have given me
!!!

rob.wedlock@samba.acs.unc.edu

wallis@labc.enet.dec.com (Barry L. Wallis) (01/08/91)

In article <2117@beguine.UUCP>, Rob.Wedlock@samba.acs.unc.edu (Rob Wedlock) writes...
!>For those of you looking for 
!>DOS undocumented: The editor is Schulman, the publisher Addison-Westly
!>I falied to mention that when I mentioned the book before.
!> 
!>For anyone that can use it: A dos interrupt from this book...
!> 
!>ah=60h
!>ds:si:pointer to asciiz file name or path input
!>es:di pointer to 128 byte buffer top hold output, an asciiz string
!>int 21h
!> 
!>you feed it a file name which can include '.','*',network drive letter
!>susbt drives, joined drives, or even files that dont exist yet
!>it spits out a carry if there was an error, or else a fully
!>expanded file name path all capitalized, * -> ??? , capitalized
!>subst drives expanded, networkdrives become \\....
!>However it can expand it to refer to a physical drive pathname , it will.
!> 
!>Hope this helps someone! Thanks for all the help yall have given me
!>!!!
!> 

Thanks! This is just the function I was looking for this weekend (trying to
implement reliable Directory and File objects under C++). What versions of DOS
does it work under?

---
Barry L. Wallis			USENET: wallis@labc.dec.com
Database Consultant		Prodigy (don't laugh): DNMX41A
U.S. DECtp Resource Center	DECUServe: EISNER::WALLIS (not on the net yet)
Los Angeles, CA			"No one voted for me, I represent myself"
---

williams@umaxc.weeg.uiowa.edu (Kent Williams) (01/08/91)

DOS Versions > 3.1 I believe support the full path function.  The
problem with it is that if you get a path back and there's a joined drive
in it, you can't open the resulting filename, since DOS conveniently
forgets about that drive.

Try this.  It does roughly the same thing.  There are some assembly functions
that get called that aren't here, but you shouldn't have any trouble rolling
your own.

/*
** $Log:   C:/shell/vcs/abspath.c_v  $
**
**   Rev 3.6   02 Oct 1986 13:09:28   kent
**lint pass over everything
**
**   Rev 3.5   01 Oct 1986 13:23:10   kent
**Put all globals into shell.h
**
**   Rev 3.4   01 Oct 1986  9:24:04   kent
**Initial revision.
*/
#include "iolib.h"

#ifndef NULL
#define NULL ((void *)0)
#endif
#include <ctype.h>
extern char *strncpy(char *,char *,int);
extern char *strchr(char *,int);
extern int strncmp(char *,char *,int);
#ifndef MSDOS
extern unsigned int strlen(char *);
extern unsigned int strcat(char *,char *);
#endif

static char *
massage(buf)
char *buf;
{
	register char *bp = buf;
	while (*bp)
	{
		*bp = (*bp == '\\') ? '/' : tolower(*bp);
		bp++;
	}
	return buf;
}

char *
abspath(relpath)
char *relpath;
{
	static char absolute[65];

	/* handle drive part */
	if (relpath[1] == ':') {
		/* drive is part of the relative path */
		strncpy(absolute,relpath,2);
		absolute[0] = tolower(absolute[0]);	/* lowercase drive letter */
		absolute[2] = '\0';
		relpath += 2;	/* worry about rest of the path */
	} else {
		absolute[0] = current_drive() + 'a';
		absolute[1] = ':';
		absolute[2] = '\0';
	}
	if ('\0' == *relpath || NULL == strchr("\\/",*relpath))	{
		/* if first char is not a slash, it is a relative path */
		absolute[2] = '/';
		absolute[3] = '\0';	/* terminate string */
		if (-1 == _getdir(absolute+3,absolute[0]-'a'+1))
			return NULL;
		(void)massage(absolute);		/* lower case and forward slash it */
		if ('\0' == *relpath) /* no path past drive */
			return absolute;
		/* parent directory */
		if(0 == strncmp(relpath,"..",2)) {
			int i;
			if (absolute[2] == '/' &&
				absolute[3] == '\0') /* in root ? */
				return NULL;				/* no dot dot for root */
			/* strip off trailing path component */
			for (i = strlen(absolute)-1 ; i != 0 && 
				absolute[i] != '/' ; i--)
				absolute[i] = '\0';
			relpath += 2;	/* skip .. */
		}
		else if ('.' == *relpath)	/* in current directory */
			++relpath;				/* skip it */
		if ('\0' == *relpath)		/* no more path ? */
			return absolute;
		/* if rest of relpath starts with a slash, bump past it */
		if (NULL != strchr("\\/",*relpath))
			++relpath;
		/* make sure absolute has a trailing backslash */
		if (absolute[strlen(absolute)-1] != '/')
			strcat(absolute,"/");
		/* copy rest of relpath into absolute */
		strcat(absolute,relpath);
		return massage(absolute);
	}
	/* an absolute path */
	strcat(absolute,relpath);
	return massage(absolute);
}


--
             Kent Williams --- williams@umaxc.weeg.uiowa.edu 
"'Is this heaven?' --- 'No, this is Iowa'" - from the movie "Field of Dreams"
"This isn't heaven, ... this is Cleveland" - Harry Allard, in "The Stupids Die"