Article View: comp.sys.amiga.tech
Article #2878Re: Is there a routine to generate full-path names?
From: Brewski Rogers
Date: Mon, 22 Jan 1990 03:10
Date: Mon, 22 Jan 1990 03:10
111 lines
4120 bytes
4120 bytes
In article <1271.AA1271@noel> greg@noel.CTS.COM (J. Gregory Noel) writes:
>I badly need a routine that will convert an arbitrary path name into its
>equivalent full-path name. That is, I need a routine that will take a
>name like "SYS:C" and return "System:1.3/C" if that is where the directory
>actually is. It would be handy if the routine also converted "DF0:name"
>into "Volume:name" of the volume currently in DF0, but that's not essential.
>
..
>Many thanks,
>--
>-- J. Gregory Noel, UNIX Guru greg@noel.cts.com or greg@noel.uucp
I had the same problem a couple of weeks ago. Here's the source.
and it does return the volume name, not the device name.
enjoy - Bruce
/*!*******************************************************************
* FindRoot by Bruce Rogers 1/20/90
*********************************************************************/
#include <stdio.h>
#include <exec/types.h>
#include <libraries/dos.h>
#define MAXPATHSTRING 140
void *AllocMem();
char absDir[MAXPATHSTRING];
char absDirName[MAXPATHSTRING];
/*!*******************************************************************
* Kludges disk:name/directory with filename so we can just read it.
*********************************************************************/
void DosConcatenate(string1,string2,result)
char string1[],string2[],result[];
{
short i,j;
for(i=0; string1[i] != '\0'; i++)
result[i]=string1[i];
if ((result[i-1] != ':') && (result[i-1] != '/') && (i!=0) && string2[0]!=0)
{
result[i]='/';
++i;
}
for(j=0; string2[j] != '\0'; j++)
result[i+j] = string2[j];
result[i+j] = '\0';
}
/*!*******************************************************************
* Recursively go up parent chain, looking for oldest parent.
* Create the absolute path string as we go.
*********************************************************************/
SeekRoot(lock)
ULONG lock;
{
short i;
struct FileInfoBlock *fileInfo;
fileInfo=AllocMem(sizeof(struct FileInfoBlock),0);
Examine(lock,fileInfo);
DosConcatenate(fileInfo->fib_FileName,absDirName,absDir);
for(i=0;i<MAXPATHSTRING;i++) absDirName[i]=absDir[i];
lock=ParentDir(lock);
if (lock!=NULL) SeekRoot(lock);
FreeMem(fileInfo,sizeof(struct FileInfoBlock));
}
/*!*******************************************************************
* Given a path, sets absDirName equal to the absolute path
*********************************************************************/
void MakeAbsName(dirName)
char *dirName;
{
short i;
char tempc[40];
ULONG lock;
for(i=0;i<MAXPATHSTRING;i++) absDirName[i]=absDir[i]=0;
lock=Lock(dirName,ACCESS_READ);
if (lock==NULL) return;
SeekRoot(lock);
for(i=0;i<MAXPATHSTRING;i++)
{
if (absDirName[i]=='/')
{
absDirName[i]=':';
break;
}
}
}
main(argc,argv)
int argc;
char *argv[];
{
char dirName[100];
MakeAbsName(argv[1]);
printf("AbsBasename: %s\n",absDirName);
}
/*
------------------------------------------------------ Quantum _\/_
2727 Eel Bruce (6502 RULES!) Rogers |\ Duck ( 0 0)
Davis, Ca 95616 Quantum Duck Software, |\ \______/ / \\\
916-756-2684 rogers@iris.ucdavis.edu |\ < < | \/
"My brain is on fire!" \________/ Quark!*/
Technical Details
Message-ID:
<6522@ucdavis.ucdavis.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ucdavis!iris!rogersReferences:
<1271.AA1271@noel>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ucdavis!iris!rogers From: rogers@iris.ucdavis.edu (Brewski Rogers) Newsgroups: comp.sys.amiga.tech Subject: Re: Is there a routine to generate full-path names? Summary: yes Message-ID: <6522@ucdavis.ucdavis.edu> Date: 22 Jan 90 03:10:29 GMT References: <1271.AA1271@noel> Sender: uucp@ucdavis.ucdavis.edu Reply-To: rogers@iris.ucdavis.edu (Brewski Rogers) Organization: U.C. Davis - Department of Electrical Engineering and Computer Science Lines: 111