Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2005/11/07 09:51:35 $
- Version: $Revision: 1.175 $
+ Date: $Date: 2006/02/16 20:06:15 $
+ Version: $Revision: 1.183 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmUtil.h"
#include "gdcmDebug.h"
+
#include <iostream>
+#include <stdarg.h> // for va_list
// For GetCurrentDate, GetCurrentTime
#include <time.h>
*/
bool Util::IsCleanString(std::string const &s)
{
- //std::cout<< std::endl << s << std::endl;
for(unsigned int i=0; i<s.size(); i++)
{
if (!isprint((unsigned char)s[i]) )
return str;
}
/**
- * \brief Add a SEPARATOR to the end of the name is necessary
+ * \brief Add a SEPARATOR to the end of the name if necessary
* @param pathname file/directory name to normalize
*/
std::string Util::NormalizePath(std::string const &pathname)
{
+/*
const char SEPARATOR_X = '/';
const char SEPARATOR_WIN = '\\';
+#ifdef _WIN32
+ const std::string SEPARATOR = "\\";
+#else
const std::string SEPARATOR = "/";
+#endif
+*/
std::string name = pathname;
int size = name.size();
- if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN )
+// if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN )
+ if ( name[size-1] != GDCM_FILESEPARATOR )
{
- name += SEPARATOR;
+ name += GDCM_FILESEPARATOR;
}
return name;
}
std::string Util::GetPath(std::string const &fullName)
{
std::string res = fullName;
+/*
+
int pos1 = res.rfind("/");
int pos2 = res.rfind("\\");
if ( pos1 > pos2 )
{
res.resize(pos2);
}
-
+*/
+ int pos = res.rfind(GDCM_FILESEPARATOR);
+ res.resize(pos);
return res;
}
std::string Util::GetName(std::string const &fullName)
{
std::string filename = fullName;
-
+/*
std::string::size_type slash_pos = filename.rfind("/");
std::string::size_type backslash_pos = filename.rfind("\\");
- slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos;
+ // At least with my gcc4.0.1, unfound char results in pos =4294967295 ...
+ //slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos;
+ slash_pos = slash_pos < backslash_pos ? slash_pos : backslash_pos;
+*/
+ std::string::size_type slash_pos = filename.rfind(GDCM_FILESEPARATOR);
if (slash_pos != std::string::npos )
{
return filename.substr(slash_pos + 1);
/**
* \brief Safely check the equality of two Dicom String:
* - Both strings should be of even length
- * - We allow padding of even length string by either a null
- * character of a space
+ * - We allow padding of even length string by either
+ * a null character of a space
*/
bool Util::DicomStringEqual(const std::string &s1, const char *s2)
{
/**
* \brief Safely compare two Dicom String:
* - Both strings should be of even length
- * - We allow padding of even length string by either a null
- * character of a space
+ * - We allow padding of even length string by either
+ * a null character of a space
*/
bool Util::CompareDicomString(const std::string &s1, const char *s2, int op)
{
OUT AsnObjectIdentifier * supportedView);
#endif //_WIN32
+#ifdef __sgi
+static int SGIGetMacAddress(unsigned char *addr)
+{
+ FILE *f = popen("/etc/nvram eaddr","r");
+ if(f == 0)
+ {
+ return -1;
+ }
+ unsigned int x[6];
+ if(fscanf(f,"%02x:%02x:%02x:%02x:%02x:%02x",
+ x,x+1,x+2,x+3,x+4,x+5) != 6)
+ {
+ pclose(f);
+ return -1;
+ }
+ for(unsigned int i = 0; i < 6; i++)
+ {
+ addr[i] = static_cast<unsigned char>(x[i]);
+ }
+ return 0;
+}
+#endif
+
/// \brief gets current M.A.C adress (for internal use only)
int GetMacAddrSys ( unsigned char *addr );
int GetMacAddrSys ( unsigned char *addr )
return 0;
#endif //Win32 version
+#if defined(__sgi)
+ return SGIGetMacAddress(addr);
+#endif // __sgi
+
// implementation for POSIX system
#if defined(CMAKE_HAVE_NET_IF_ARP_H) && defined(__sun)
}
/**
- * \brief Encode the mac address on a fixed lenght string of 15 characters.
+ * \brief Encode the mac address on a fixed length string of 15 characters.
* we save space this way.
*/
std::string Util::GetMACAddress()
}
else
{
- gdcmWarningMacro("Problem in finding the MAC Address");
+ gdcmStaticWarningMacro("Problem in finding the MAC Address");
return "";
}
}
// If append is too long we need to rehash it
if ( (prefix + append).size() > 64 )
{
- gdcmErrorMacro( "Size of UID is too long." );
+ gdcmStaticErrorMacro( "Size of UID is too long." );
// we need a hash function to truncate this number
// if only md5 was cross plateform
// MD5(append);
#endif //GDCM_WORDS_BIGENDIAN
}
-
/**
* \brief binary_write binary_write
* @param os ostream to write to
#endif //GDCM_WORDS_BIGENDIAN
}
-
/**
* \brief binary_write binary_write
* @param os ostream to write to
return str;
}
+void Util::hfpswap(double *a, double *b)
+{
+ double tmp;
+ tmp=*a;
+ *a=*b;
+ *b=tmp;
+}
+
//-------------------------------------------------------------------------
} // end namespace gdcm