This is an automated email from the git hooks/post-receive script.

rubund-guest pushed a commit to branch master
in repository fyba.

commit f3dbbaf13714d13ced33ecf4def8a802c99a7563
Author: Anders Einar Hilden <hilde...@gmail.com>
Date:   Sat Oct 19 17:42:16 2013 +0200

    New, fully free SPLITPTH.cpp
---
 src/UT/SPLITPTH.cpp | 236 +++++++++++++++++++---------------------------------
 1 file changed, 85 insertions(+), 151 deletions(-)

diff --git a/src/UT/SPLITPTH.cpp b/src/UT/SPLITPTH.cpp
index d833085..60b99e2 100644
--- a/src/UT/SPLITPTH.cpp
+++ b/src/UT/SPLITPTH.cpp
@@ -1,161 +1,95 @@
 
///////////////////////////////////////////////////////////////////////////////////
 // SPLITPATH.cpp
+// Functions
+//        UT_splitpath - split a full path name
 //
-// Funksjoner
-//        PrikkFunnet - sjekker etter spesielle kataloger
-//        UT_splitpath - split a full path name (MSC compatible)
-//
-
-#include "stdafx.h"
-#include <string.h>
-
-#ifdef BORLAND
-#include <windows.h>
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include "fyut.h"
 
-#ifdef LINUX
-#define wchar_t char
-#define wcslen  strlen
-#endif
-
-///////////////////////////////////////////////////////////////////////
-//
-// PrikkFunnet - sjekker etter spesielle kataloger
-
-static size_t PrikkFunnet(wchar_t *pB)
-{
-        if (*(pB-1) == '.')
-                pB--;
-        switch (*--pB) {
-           case ':'  :
-              if (*(pB-2) != '\0') {
-                 break;
-              } else {
-                 return UT_TRUE;
-              }
-           case '/'  :
-           case '\\' :
-           case '\0' :
-              return UT_TRUE;
-        }
-        return UT_FALSE;
+#include <cstring>
+#include <fyut.h>
+
+void UT_splitFN(char *filename, char* name, char* ext) {
+       char* lastDot = strrchr(filename, '.');
+       if(lastDot != NULL) {
+               UT_StrCopy(ext, lastDot, _MAX_EXT);
+               if(strlen(filename) > _MAX_EXT) {
+                       name[_MAX_EXT-1] = '\0';
+               }
+               /* replace the posisiton of last dot in filename
+               with end-of-sting */
+           (*lastDot) = '\0'; 
+       } else {
+               (*ext) = '\0';
+       }
+       UT_StrCopy(name, filename, _MAX_FNAME);
+       if(strlen(filename) > _MAX_FNAME) {
+                       name[_MAX_FNAME-1] = '\0';
+       }
 }
 
-//////////////////////////////////////////////////////////////////////////////////////
-// UT_splitpath - splits a full path name into its components
-
 /*
-AR-930423
-CH UT_splitpath                                       Splitt filnavn
-CD ==================================================================
-CD Form´┐Żl:
-CD UT_splitpath splitter et fullstendig filnavn i enkelte komponenter.
-CD Filnavnet:  X:\DIR\SUBDIR\NAME.EXT
-CD blir til:      X er drive
-CD                \DIR\SUBDIR\ er gitt av dir
-CD                NAME.EXT er gitt av name og ext
-CD
-CD PARAMETERLISTE:
-CD Type         Navn       I/U  Merknad
-CD --------------------------------------------------------------
-CD wchar_t        *pszPath   i   Komplett filnavn
-CD const wchar_t  *pszDrive  u   Disk
-CD const wchar_t  *pszDir    u   Katalog
-CD const wchar_t  *pszNavn   u   Navn
-CD const wchar_t  *pszExt    u   Extension
+CH UT_splitpath
+CD ==============================================================
+CD Splits a path into drive (X: for windows, "" for linux),
+CD directory, filename (w/o extension) and extension.
 CD
-CD Bruk:  UT_splitpath(szPath,szDrive,szDir,szNavn,szExt);
-   ==================================================================
+CD Parameters:
+CD Type        Name             I/O  Explanation
+CD -------------------------------------------------------------
+CD const char *pathP             i  Path to split
+CD char       *driveP            o  Drive-part of path
+CD char       *dirP              o  Directory-part
+CD char       *nameP             o  Filename w/o extension
+CD char       *extP              o  extension
+CD  ==============================================================
 */
-SK_EntPnt_UT void UT_splitpath(const wchar_t *pathP, wchar_t *driveP, wchar_t 
*dirP, wchar_t *nameP, wchar_t *extP)
-{
-        wchar_t   *pB;
-        size_t Wrk;
-        int    ExtFunnet;
-
-        wchar_t buf[ _MAX_PATH+2 ];
-
-        /*
-         * Set all string to default value zero
-         */
-        ExtFunnet = UT_FALSE;
-        if (driveP)
-                *driveP = 0;
-        if (dirP)
-                *dirP = 0;
-        if (nameP)
-                *nameP = 0;
-        if (extP)
-                *extP = 0;
-
-        /*
-         * Copy filename into template up to _MAX_PATH characters
-         */
-        pB = buf;
-        while (*pathP == ' ')
-                pathP++;
-
-        if ((Wrk = wcslen(pathP)) >= _MAX_PATH)
-                Wrk = _MAX_PATH - 1;
-        *pB++ = 0;
-        UT_StrCopy(pB, pathP, Wrk+1);
-
-        *(pB += Wrk) = 0;
-
-        /*
-         * Split the filename and fill corresponding nonzero pointers
-         */
-        Wrk = 0;
-        for (; ; ) {
-                switch (*--pB) {
-                case '.'  :
-                        if (!Wrk && (*(pB+1) == '\0'))
-                                Wrk = PrikkFunnet(pB);
-                        if ((!Wrk) && (!ExtFunnet)) {
-                                ExtFunnet = UT_TRUE;
-                                UT_StrCopy(extP, pB, _MAX_EXT);
-                                *pB = 0;
-                        }
-                        continue;
-                case ':'  :
-                        if (pB != &buf[2])
-                                continue;
-                case '\0' :
-                        if (Wrk) {
-                                pB++;
-                                UT_StrCopy(dirP, pB, _MAX_DIR);
-                                *pB-- = 0;
-                                break;
-                        }
-                case '/'  :
-                case '\\' :
-                        if (!Wrk) {
-                                Wrk++;
-                                pB++;
-                                UT_StrCopy(nameP, pB, _MAX_FNAME);
-                                *pB-- = 0;
-                                if (*pB == 0 || (*pB == ':' && pB == &buf[2]))
-                                        break;
-                        }
-                        continue;
-
-                case '*'  :
-                case '?'  :
-                        continue;
-
-                default :
-                        continue;
-                }
-                break;
-        }
-
-        if (*pB == ':') {
-                UT_StrCopy(driveP, &buf[1], _MAX_DRIVE);
-        }
+SK_EntPnt_UT void UT_splitpath(const char *pathP, char *driveP, char *dirP, 
char *nameP, char *extP) {
+       char local_path[PATH_MAX]; /* Copy of pathP i case we modify it */
+       char tmp[PATH_MAX]; /* Copy of pathP i case we modify it */
+       char filename[PATH_MAX];
+       (*driveP) = (*dirP) = (*nameP) = (*extP) = '\0';
+
+       strcpy(local_path, pathP);
+       strcpy(tmp, local_path);
+       /* Under linux, driveP is always \0 */
+       #ifdef WIN32
+               /* Afaik, there is only ONE : in windows filenames */
+               char* theColon = strrchr(tmp, ':');
+               if(theColon != NULL) {
+                       /* We overwrite local_path here, because after this the 
code
+                       is equal for win/lin if the drive-part is removed */
+                       UT_StrCopy(local_path, theColon+1, PATH_MAX);
+                       (*(theColon + 1)) = '\0'; // set a \0 after the color 
(inside tmp!)
+                       UT_StrCopy(driveP, tmp, _MAX_DRIVE);
+                       if (strlen(tmp) > _MAX_DRIVE) { // how would this even 
happen?
+                               driveP[_MAX_DRIVE-1] = '\0';
+                       }
+               }
+       #endif
+
+       strcpy(tmp, local_path);
+       
+       char* lastSlash = strrchr(tmp, UT_SLASH);
+       
+       /* Set dirP */
+       if(lastSlash != NULL) {
+               /* +1 because we don't want the / in the filename */
+               char filename[PATH_MAX]; /* UT_splitFN might modify filename */
+               strcpy(filename,lastSlash+1);
+               if (strcmp(filename, ".") != 0) {
+                       UT_splitFN(filename, nameP, extP);
+                   (*(tmp + (lastSlash - tmp + 1))) = '\0';    
+               }
+               UT_StrCopy(dirP, tmp, _MAX_DIR);
+               // No null-character is implicitly appended at the end of 
destination if source is longer than num.
+               if (strlen(tmp) > _MAX_DIR) {
+                       dirP[_MAX_DIR-1] = '\0';
+               }
+       } else {
+               if (strcmp(".", local_path) == 0) { /* Hard-coded to mimic old 
behaviour */
+                       strcpy(dirP, ".");
+               } else {
+                       UT_splitFN(tmp, nameP, extP);
+               }
+       }
 }
+

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/fyba.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to