]> Shamusworld >> Repos - rln/commitdiff
Clean up of path_tail() function; now uses defined path delimiter.
authorJames Hammons <jlhamm@acm.org>
Thu, 29 Dec 2011 17:13:33 +0000 (17:13 +0000)
committerJames Hammons <jlhamm@acm.org>
Thu, 29 Dec 2011 17:13:33 +0000 (17:13 +0000)
rln.c
rln.h

diff --git a/rln.c b/rln.c
index beb8c9330983fe94c8eab7b4bb288093ba5bb27d..a27dde0be010702efd704a7e12c40d08abb37a22 100644 (file)
--- a/rln.c
+++ b/rln.c
@@ -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
 }
 
 
diff --git a/rln.h b/rln.h
index d4591b329c4bd51ceea6670b9874d0caea1eb616..cec6409b2096ed07f97e6316157926d23963bcdb 100644 (file)
--- a/rln.h
+++ b/rln.h
@@ -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))