Article View: comp.os.msdos.programmer
Article #4168Re: misc
From: Kent Williams
Date: Mon, 07 Jan 1991 21:08
Date: Mon, 07 Jan 1991 21:08
111 lines
3663 bytes
3663 bytes
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"
Technical Details
Message-ID:
<3818@ns-mx.uiowa.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ns-mx!umaxc.weeg.uiowa.edu!williamsReferences:
<18744@shlump.nac.dec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ns-mx!umaxc.weeg.uiowa.edu!williams From: williams@umaxc.weeg.uiowa.edu (Kent Williams) Newsgroups: comp.os.msdos.programmer Subject: Re: misc Message-ID: <3818@ns-mx.uiowa.edu> Date: 7 Jan 91 21:08:26 GMT References: <18744@shlump.nac.dec.com> Sender: news@ns-mx.uiowa.edu Reply-To: williams@umaxc.weeg.uiowa.edu.UUCP (Kent Williams) Organization: U of Iowa, Iowa City, IA Lines: 111