[comp.sys.amiga.tech] Is there a routine to generate full-path names?

greg@noel.CTS.COM (J. Gregory Noel) (01/21/90)

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.
The important thing is that the path generated should be rooted a a volume
name, not the device name.

The code for this must exist -- the CLI and shell seem to be capable of doing
it when there's a %S in the prompt string.  It also seems to me that I have
seen a discussion of this before, but in typical fashion, I didn't need it at
the time, so I didn't keep it.

Many thanks,
-- 
-- J. Gregory Noel, UNIX Guru       greg@noel.cts.com  or  greg@noel.uucp

rogers@iris.ucdavis.edu (Brewski Rogers) (01/22/90)

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!*/

cmcmanis@stpeter.Sun.COM (Chuck McManis) (01/23/90)

In article <6522@ucdavis.ucdavis.edu> (Brewski Rogers) writes:
>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

Bruce, you should get a copy of the program ShowLocks, you would notice
that after running your code that there were a bunch of filelocks 
hanging around. The reason is that you don't ever "UnLock" anything
that you "Lock". So in your code ...

>    lock=ParentDir(lock);
>    if (lock!=NULL) SeekRoot(lock);

This has to be changed to something like :
	newlock = ParentDir(oldlock);
	UnLock(oldlock);
	oldlock = newlock;
	if (newlock != NULL) ...


And somewhere near the end of this routine you should have a statement :
>    lock=Lock(dirName,ACCESS_READ);
	...
	UnLock(lock);

Otherwise you will be losing little chunks of memory right and left.

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@Eng.Sun.COM
These opinions are my own and no one elses, but you knew that didn't you.
"If it didn't have bones in it, it wouldn't be crunchy now would it?!"

rogers@iris.ucdavis.edu (Brewski Rogers) (01/23/90)

In article <130545@sun.Eng.Sun.COM> cmcmanis@sun.UUCP (Chuck McManis) writes:
]Bruce, you should get a copy of the program ShowLocks, you would notice
]that after running your code that there were a bunch of filelocks 
]hanging around. The reason is that you don't ever "UnLock" anything
]that you "Lock". So in your code ...
]
]>    lock=ParentDir(lock);
]>    if (lock!=NULL) SeekRoot(lock);
]
]This has to be changed to something like :
]	newlock = ParentDir(oldlock);
]	UnLock(oldlock);
]	oldlock = newlock;
]	if (newlock != NULL) ...
]And somewhere near the end of this routine you should have a statement :
]>    lock=Lock(dirName,ACCESS_READ);
]	...
]	UnLock(lock);

oops!
you're right!
OKAY, fixing the original source I posted will be left as an exercise for
the reader...

]--Chuck McManis
]"If it didn't have bones in it, it wouldn't be crunchy now would it?!"
	^^^ time for a new one.

------------------------------------------------------          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!