[fyba] 18/77: replace FULLPATH and SPLITPTH with non-proprietary alternative
Ruben Undheim
rubund-guest at moszumanska.debian.org
Mon Sep 22 15:11:24 UTC 2014
This is an automated email from the git hooks/post-receive script.
rubund-guest pushed a commit to branch master
in repository fyba.
commit 8f5202b6f26090d845e4a9da439d351e09f5d399
Author: Thomas Hirsch <thomas.hirsch at statkart.no>
Date: Tue Oct 15 10:18:34 2013 +0200
replace FULLPATH and SPLITPTH with non-proprietary alternative
---
src/UT/FULLPATH.cpp | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/UT/Makefile.am | 2 +-
src/UT/SPLITPTH.cpp | 161 +++++++++++++++++++++++++++++++++
3 files changed, 415 insertions(+), 1 deletion(-)
diff --git a/src/UT/FULLPATH.cpp b/src/UT/FULLPATH.cpp
new file mode 100644
index 0000000..cd56ec9
--- /dev/null
+++ b/src/UT/FULLPATH.cpp
@@ -0,0 +1,253 @@
+/* ------------------------------
+ * Fil: FullPath.c
+ * ------------------------------ */
+
+#include "stdafx.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef LINUX
+# include <unistd.h>
+#endif
+
+#ifdef UNIX
+# include <ctype.h>
+#endif
+
+#ifdef OS2
+# define INCL_DOSFILEMGR
+# define INCL_DOSERRORS
+# include <os2.h>
+#endif
+
+#ifdef BORLAND
+# include <windows.h>
+#endif
+
+#ifdef WIN32
+# include <windows.h>
+#endif
+
+#include "fyut.h"
+
+
+#ifdef UNIX
+
+#define wchar_t char
+#define wcschr strchr
+
+///////////////////////////////////////////////////////////////////////////////////////
+// FULLPATH.cpp
+
+///////////////////////////////////////////////////////////////////////////////////////
+// ErSlash()
+int ErSlash (int chr)
+{
+ return (chr == '\\' || chr == '/');
+}
+
+///////////////////////////////////////////////////////////////////////////////////////
+// FullPath()
+wchar_t * FullPath(wchar_t *Buffer,
+ const wchar_t *PathName,
+ size_t nMaxlen
+ )
+{
+ wchar_t *TempBuf;
+ wchar_t *dst, *src;
+ int c, Drive;
+ size_t nLen;
+
+
+ /* Allocate a temporary buffer to hold the fully qualified path.
+ */
+ if ((TempBuf = (wchar_t*)malloc(_MAX_PATH*2+1)) == NULL)
+ return (NULL);
+
+
+ Drive = 7;
+ src = (wchar_t *)PathName;
+
+
+ /* If supplied path is relative, append it to the drivename
+ * and its current directory. Otherwise append it to the
+ * drivename only.
+ */
+ if (!ErSlash(src[0])) { /* path is relative? */
+ /* Get drivename and its current directory.
+ */
+ if (getcwd(TempBuf,_MAX_PATH*2+1) == NULL) {
+ free(TempBuf);
+ return (NULL);
+ }
+ dst = &TempBuf[strlen(TempBuf)];
+ if (!ErSlash(*(dst-1))) /* if directory doesn't end in slash */
+ *dst++ = UT_SLASH; /* append one */
+
+ } else {
+ /* Path is absolute. Store the drivename only.*/
+ dst = TempBuf;
+ }
+ strcpy(dst,src); /* concatenate supplied path */
+
+ /* Scan the path, squeezing out "../" and "./", and
+ * squeezing out the previous directory when "../" is found.
+ */
+ src = dst = TempBuf;
+
+ for (;;) {
+ /* If this the end of the path, or end of a directory,
+ * we must check for "." or ".."
+ */
+ if ((c = *src++) == '\0' || ErSlash(c)) {
+ /* If last directory copied was "/.", back up over it.
+ * Skip test if we are still at the beginning of TempBuf.
+ */
+ if (src != (TempBuf+1)) {
+ if (*(dst-1) == '.' && ErSlash(*(dst-2))) {
+ dst -= 2;
+
+ /* If last directory copied was "/..", back up over it
+ * AND the previous directory.
+ */
+ } else if (*(dst-1) == '.' && *(dst-2) == '.' && ErSlash(*(dst-3))) {
+ dst -= 3; /* back up over "/.." */
+ if (*(dst-1) == ':') { /* can't back up over drivename */
+ free(TempBuf);
+ return(NULL);
+ }
+ while (!ErSlash(*--dst))
+ ; /* back up to start of prev. dir. */
+ }
+
+ if (c == '\0') { /* end of path? */
+ if (ErSlash(*(dst-1))) /* if last wchar_t is slash */
+ dst--; /* back up over it */
+ if (*(dst-1) == ':') /* if path is just a drivename */
+ *dst++ = '/'; /* append a slash */
+ *dst = '\0'; /* append null terminator */
+ break;
+
+ } else {
+ *dst++ = c; /* copy the slash */
+ }
+ }
+
+ } else {
+ *dst++ = c; /* copy the character */
+ }
+ }
+
+ /* Copy the temp buffer to the user's buffer, if present.
+ * Otherwise shrink the temp buffer and return a pointer to it.
+ */
+ nLen = strlen(TempBuf) + 1; /* length of path and null */
+ if (Buffer != NULL) {
+ if (nLen > nMaxlen) { /* user buffer too small? */
+ free(TempBuf);
+ return (NULL);
+
+ } else {
+ strcpy(Buffer,TempBuf);
+ free(TempBuf);
+ return (Buffer);
+ }
+
+ } else {
+ return (wchar_t*)(realloc(TempBuf,nLen)); /* shrink the buffer */
+ }
+}
+#endif
+
+
+/*
+AR-930423
+CH UT_FullPath Finn fullstendig filnavn
+CD ==================================================================
+CD Form�l:
+CD Lag absolutt path navn fra relativt path navn.
+CD I tilleg tolker denne environment-variabler inn i filnavnet.
+CD Environment-varialen skrives i parantes.
+CD
+CD Eks:
+CD SET FKB=D:\DATA\SOSI\FKB
+CD
+CD Filnavnet (FKB)\CV03851V.SOS
+CD pakkes ut til D:\DATA\SOSI\FKB\CV03851V.SOS
+CD
+CD PARAMETERLISTE:
+CD Type Navn I/U Merknad
+CD ------------------------------------------------------------------
+CD wchar_t *pszBuffer u Komplett filnavn
+CD const wchar_t *pszPath i Forkortet filnavn
+CD size_t maxlen i Max lengde av pszBuffer
+CD short sStatus r Status; 0=OK, annen verdi er feil.
+CD
+CD Bruk: sStatus = UT_FullPath(szBuffer,szPath,maxlen);
+ ==================================================================
+*/
+SK_EntPnt_UT short UT_FullPath(wchar_t *pszBuffer, const wchar_t *pszPath, size_t maxlen)
+{
+ wchar_t szFilnavn[_MAX_PATH];
+ wchar_t *pszStart,*pszSlutt;
+ wchar_t *env;
+#ifdef BORLAND
+ wchar_t *pszOrgPath;
+#endif
+
+ /* S�k start- og sluttparantes */
+ UT_StrCopy(szFilnavn,pszPath,_MAX_PATH);
+ pszStart = wcschr(szFilnavn,'(');
+ pszSlutt = wcschr(szFilnavn,')');
+
+ /* B�de start- og sluttparantes er funnet,
+ og starten er f�rst i strengen */
+ if (pszStart != NULL && pszSlutt != NULL && pszStart < pszSlutt) {
+ *pszStart++ = '\0';
+ *pszSlutt++ = '\0';
+#ifdef LINUX
+ env = getenv( UT_StrUpper(pszStart));
+#else
+ size_t len;
+ _wdupenv_s(&env, &len, UT_StrUpper(pszStart));
+#endif
+
+ /* Navnet er ikke funnet */
+ if (env == NULL) {
+ UT_StrCopy(szFilnavn,pszPath,_MAX_PATH);
+
+ } else {
+ UT_StrCat(szFilnavn,env,_MAX_PATH);
+ UT_ClrTrailsp(szFilnavn);
+ UT_StrCat(szFilnavn,pszPath+(pszSlutt-szFilnavn),_MAX_PATH);
+ }
+ }
+
+ /* Hent filopplysninger */
+#ifdef UNIX
+ return (short)(FullPath(pszBuffer,szFilnavn,maxlen) != NULL)? 0 : 1;
+#endif
+
+#ifdef OS232
+ return (short) DosQueryPathInfo(szFilnavn,FIL_QUERYFULLNAME,pszBuffer,maxlen);
+#endif
+
+#ifdef OS216
+ return (short) DosQPathInfo(szFilnavn,FIL_QUERYFULLNAME,(PBYTE)pszBuffer,(USHORT)maxlen,0);
+#endif
+
+#ifdef WIN32
+ return (short)(_wfullpath(pszBuffer,szFilnavn,maxlen) != NULL)? 0 : 1;
+#endif
+
+#ifdef BORLAND
+ pszOrgPath = FullPath(pszBuffer,szFilnavn,maxlen);
+
+ if (pszOrgPath != NULL)
+ return((short)0);
+ else
+ return ((short)1);
+#endif
+
+}
+
diff --git a/src/UT/Makefile.am b/src/UT/Makefile.am
index 66cd768..450aba0 100644
--- a/src/UT/Makefile.am
+++ b/src/UT/Makefile.am
@@ -2,7 +2,7 @@ AM_CPPFLAGS = --pedantic -Wno-long-long -Wall -O2 -D_FILE_OFFSET_BITS=64 -DUNIX
ACLOCAL_AMFLAGS = -I m5
lib_LTLIBRARIES = libfyut.la
-libfyut_la_SOURCES = ANFORSEL.cpp DELDIR.cpp FILNACMP.cpp INQTID.cpp UT1.cpp UT4.cpp CopyFile.cpp DELFILE.cpp MAKEPATH.cpp stdafx.cpp UT2.cpp CREDIR.cpp DISKINFO.cpp INQSIZE.cpp SETSIZE.cpp StrtPros.cpp UT3.cpp fyut.h stdafx.h
+libfyut_la_SOURCES = ANFORSEL.cpp DELDIR.cpp FILNACMP.cpp INQTID.cpp UT1.cpp UT4.cpp CopyFile.cpp DELFILE.cpp MAKEPATH.cpp stdafx.cpp UT2.cpp CREDIR.cpp DISKINFO.cpp INQSIZE.cpp SETSIZE.cpp StrtPros.cpp UT3.cpp fyut.h stdafx.h FULLPATH.cpp SPLITPTH.cpp
libfyut_la_LDFLAGS = -version-info 0:0:0
library_includedir=$(includedir)/fyba
diff --git a/src/UT/SPLITPTH.cpp b/src/UT/SPLITPTH.cpp
new file mode 100644
index 0000000..d833085
--- /dev/null
+++ b/src/UT/SPLITPTH.cpp
@@ -0,0 +1,161 @@
+///////////////////////////////////////////////////////////////////////////////////
+// SPLITPATH.cpp
+//
+// 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;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// 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
+CD
+CD Bruk: UT_splitpath(szPath,szDrive,szDir,szNavn,szExt);
+ ==================================================================
+*/
+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);
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/fyba.git
More information about the Pkg-grass-devel
mailing list