Category : UNIX Files
Archive   : UUPC11QS.ZIP
Filename : EXPATH.C

 
Output of file : EXPATH.C contained in archive : UUPC11QS.ZIP
/*--------------------------------------------------------------------*/
/* e x p a t h . c */
/* */
/* Path expansion functions for UUPC/extended */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/* MS-DOS and OS/2 header files */
/*--------------------------------------------------------------------*/

#include
#include
#include
#include
#include
#include

/*--------------------------------------------------------------------*/
/* UUPC/extended header files */
/*--------------------------------------------------------------------*/

#include "lib.h"
#include "expath.h"
#include "hlib.h"
#include "hostable.h"
#include "security.h"
#include "usertabl.h"

/*--------------------------------------------------------------------*/
/* e x p a n d _ p a t h */
/* */
/* Expands ~, ~/ and relative paths */
/*--------------------------------------------------------------------*/

char *expand_path(char *path, /* Input/output path name */
const char *cur_dir, /* Default directory path */
const char *home, /* Default home directory */
const char *ftype ) /* Default extension */
{
char *p, *fname;
char save[FILENAME_MAX];
struct UserTable *userp;

/*--------------------------------------------------------------------*/
/* Convert backslashes to slashes */
/*--------------------------------------------------------------------*/

p = path;
while ((p = strchr(p,'\\')) != NULL)
*p++ = '/';

/*--------------------------------------------------------------------*/
/* Add optional extension, if needed */
/*--------------------------------------------------------------------*/

if ( ftype != NULL )
{
p = strrchr(path,'/'); /* Get the last slash in name */

if ( p == NULL ) /* No slash? */
p = path; /* Okay, look at entire name */

if ( strchr( p , '.') == NULL ) /* Does name have a period? */
strcat( strcat(p, ".") ,ftype );
/* No --> Add extension */
} /* if ( ftype != NULL ) */

/*--------------------------------------------------------------------*/
/* If a fully qualified path name, return */
/*--------------------------------------------------------------------*/

if (*path == '/')
return path; /* nothing to do */

/*--------------------------------------------------------------------*/
/* If non-default drive and not full path, reject the path */
/*--------------------------------------------------------------------*/

if (isalpha( *path ) && (path[1] == ':'))
{
if (path[2] == '/') /* Absolute path on drive? */
return path; /* Yes --> Leave it alone */

printmsg(0, "expand_path: Invalid path \"%s\"; \
relative path on non-default drive. (Use full path for file.)",path);
return NULL; /* nothing to do */
} /* if */
else
p = path; /* Copy entire path */

/*--------------------------------------------------------------------*/
/* Try to translate the file as a home directory path */
/*--------------------------------------------------------------------*/

strcpy(save, p);
if (save[0] == '~') {
if (save[1] == '/') {
strcpy(path, home); /* Use home dir for this user */
fname = save + 2; /* Step past directory for simple name */
}
else {
if ((fname = strchr(save + 1, '/')) == NULL)
{
printmsg(0,"expand_path: path \"%s\" illegal",p);
return NULL;
}

/*--------------------------------------------------------------------*/
/* Look in /etc/passwd for the user id */
/*--------------------------------------------------------------------*/

*fname++ = '\0'; /* End string, step past it */
userp = checkuser(save + 1); /* Locate user id in table */
if ( userp == BADUSER ) /* Invalid user id? */
{ /* Yes --> Dump in trash */
printmsg(0,"expand_path: User \"%s\" is invalid", save + 1);
return NULL;
} /* if */
strcpy(path, userp->homedir);
} /* else */
} /* if (save[0] == '~') */

/*--------------------------------------------------------------------*/
/* No user id appears in the path; just append the input data */
/* to the current directory to convert the relative path to an */
/* absolute path */
/*--------------------------------------------------------------------*/

else {
fname = save; /* Give it the file name - 6/23/91 */
if ( cur_dir == NULL )
getcwd( path, FILENAME_MAX);
else if ( equal(cur_dir,"."))
{
strcpy( path, save );
return path;
}
else
strcpy( path, cur_dir );
} /* else */

/*--------------------------------------------------------------------*/
/* Normalize the path, and then add the name */
/*--------------------------------------------------------------------*/

while ((p = strchr(p,'\\')) != NULL)
*p++ = '/';
if ( path[ strlen( path ) - 1 ] != '/' )
strcat( path, "/");
strlwr( path ); /* Can lower case path, but not the
name because name may be UNIX! */
strcat( path, fname );

/*--------------------------------------------------------------------*/
/* Return data to caller */
/*--------------------------------------------------------------------*/

return path;
} /* expand_path */


  3 Responses to “Category : UNIX Files
Archive   : UUPC11QS.ZIP
Filename : EXPATH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/