Clean up of path_tail() function; now uses defined path delimiter.

This commit is contained in:
James Hammons 2011-12-29 17:13:33 +00:00
parent 7a68775424
commit 741d94dd19
2 changed files with 21 additions and 19 deletions

30
rln.c
View File

@ -2043,10 +2043,12 @@ int dolist(void)
//
char * path_tail(char * name)
{
char * temp = max(strrchr(name,'/'), max(strrchr(name,':'), strrchr(name, 92)));
// char * temp = MAX(strrchr(name, '/'), MAX(strrchr(name, ':'), strrchr(name, '\\')));
char * temp = strrchr(name, PATH_DELIMITER);
// Return what was passed in if path delimiter was not found
if (temp == NULL)
temp = (name - 1);
return name;
return temp + 1;
}
@ -2059,34 +2061,34 @@ int pladd(char * ptr, char * fname)
{
if (plist == NULL)
{
plist = new_ofile(); // First time object record allocation
plast = plist; // Update last object record pointer
plist = new_ofile(); // First time object record allocation
plast = plist; // Update last object record pointer
}
else
{
plast->o_next = new_ofile(); // Next object record allocation
plast = plast->o_next; // Update last object record pointer
plast->o_next = new_ofile(); // Next object record allocation
plast = plast->o_next; // Update last object record pointer
}
if (plast == NULL)
{
printf("Out of memory.\n"); // Error if memory allocation fails
printf("Out of memory.\n"); // Error if memory allocation fails
return 1;
}
if (strlen(path_tail(fname)) > FNLEN-1)
if (strlen(path_tail(fname)) > FNLEN - 1)
{ // Error on excessive filename length
printf("File name too long: %s (sorry!)\n",fname);
return 1;
}
strcpy(plast->o_name, path_tail(fname)); // Store filename, not path
*plast->o_arname = 0; // No archive name for this file
plast->o_image = ptr; // Store data pointer
plast->o_flags = O_USED; // File is used
plast->o_next = NULL; // Initialise next record pointer
strcpy(plast->o_name, path_tail(fname)); // Store filename, not path
*plast->o_arname = 0; // No archive name for this file
plast->o_image = ptr; // Store data pointer
plast->o_flags = O_USED; // File is used
plast->o_next = NULL; // Initialise next record pointer
return 0; // Return without errors
return 0; // Return without errors
}

10
rln.h
View File

@ -16,7 +16,7 @@
#ifdef WIN32
//#define _OPEN_FLAGS _O_BINARY|_O_RDWR
#define _OPEN_FLAGS _O_BINARY|_O_RDONLY
#define _BACKSLASH '\\'
#define PATH_DELIMITER '\\'
#ifdef _MSC_VER
#if _MSC_VER > 1000
#pragma warning(disable:4996)
@ -38,7 +38,7 @@
#ifdef __GCCUNIX__
//#define _OPEN_FLAGS O_RDWR
#define _OPEN_FLAGS O_RDONLY
#define _BACKSLASH '/'
#define PATH_DELIMITER '/'
#include <sys/fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@ -68,9 +68,9 @@
#define warn(x, f) printf("Warning: repeated flag `%c'%s\n", x, f ? "; previous one(s) ignored." : ".")
// Macro for max: good because longs, shorts, or pointers can be compared
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif // max
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
// Macro to swap the 16-bit words of a 32-bit integer
#define _SWAPWORD(x) (((unsigned)(x) >> 16) | ((unsigned)(x) << 16))