diff options
Diffstat (limited to 'debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform')
30 files changed, 2757 insertions, 0 deletions
diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/config.h.in b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/config.h.in new file mode 100644 index 00000000..47a5a043 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/config.h.in @@ -0,0 +1,65 @@ +/* libplatform/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Define to 1 if LFS should be activated */ +#undef NEED_LFS_ACTIVATION + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/endian.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/endian.h new file mode 100644 index 00000000..83fe69e0 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/endian.h @@ -0,0 +1,42 @@ +#ifndef MP4V2_PLATFORM_ENDIAN_H +#define MP4V2_PLATFORM_ENDIAN_H + +/////////////////////////////////////////////////////////////////////////////// + +#define MP4V2_BYTESWAP_16(x) \ + mp4v2::platform::uint16_t( ((mp4v2::platform::uint16_t(x) & 0xff00U) >> 8) \ + | ((mp4v2::platform::uint16_t(x) & 0x00ffU) << 8) ) + +#define MP4V2_BYTESWAP_32(x) \ + mp4v2::platform::uint32_t( ((mp4v2::platform::uint32_t(x) & 0xff000000U) >> 24) \ + | ((mp4v2::platform::uint32_t(x) & 0x00ff0000U) >> 8) \ + | ((mp4v2::platform::uint32_t(x) & 0x0000ff00U) << 8) \ + | ((mp4v2::platform::uint32_t(x) & 0x000000ffU) << 24) ) + +#define MP4V2_BYTESWAP_64(x) \ + mp4v2::platform::uint64_t( ((mp4v2::platform::uint64_t(x) & 0xff00000000000000ULL) >> 56) \ + | ((mp4v2::platform::uint64_t(x) & 0x00ff000000000000ULL) >> 40) \ + | ((mp4v2::platform::uint64_t(x) & 0x0000ff0000000000ULL) >> 24) \ + | ((mp4v2::platform::uint64_t(x) & 0x000000ff00000000ULL) >> 8) \ + | ((mp4v2::platform::uint64_t(x) & 0x00000000ff000000ULL) << 8) \ + | ((mp4v2::platform::uint64_t(x) & 0x0000000000ff0000ULL) << 24) \ + | ((mp4v2::platform::uint64_t(x) & 0x000000000000ff00ULL) << 40) \ + | ((mp4v2::platform::uint64_t(x) & 0x00000000000000ffULL) << 56) ) + +/////////////////////////////////////////////////////////////////////////////// + +#if defined( __BIG_ENDIAN__ ) +# define MP4V2_HTONS(x) (x) +# define MP4V2_HTONL(x) (x) +# define MP4V2_NTOHS(x) (x) +# define MP4V2_NTOHL(x) (x) +#else +# define MP4V2_HTONS(x) MP4V2_BYTESWAP_16(x) +# define MP4V2_HTONL(x) MP4V2_BYTESWAP_32(x) +# define MP4V2_NTOHS(x) MP4V2_BYTESWAP_16(x) +# define MP4V2_NTOHL(x) MP4V2_BYTESWAP_32(x) +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_ENDIAN_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/impl.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/impl.h new file mode 100644 index 00000000..6c0068ce --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/impl.h @@ -0,0 +1,13 @@ +#ifndef MP4V2_PLATFORM_IMPL_H +#define MP4V2_PLATFORM_IMPL_H + +/////////////////////////////////////////////////////////////////////////////// + +#include "libplatform/platform.h" +#if defined _WIN32 +#include "libplatform/platform_win32_impl.h" +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_IMPL_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp new file mode 100644 index 00000000..893f98c0 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp @@ -0,0 +1,185 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +namespace { + const File::Size __maxChunkSize = 1024*1024; +} + +/////////////////////////////////////////////////////////////////////////////// + +File::File( std::string name_, Mode mode_, FileProvider* provider_ ) + : _name ( name_ ) + , _isOpen ( false ) + , _mode ( mode_ ) + , _size ( 0 ) + , _position ( 0 ) + , _provider ( provider_ ? *provider_ : standard() ) + , name ( _name ) + , isOpen ( _isOpen ) + , mode ( _mode ) + , size ( _size ) + , position ( _position ) +{ +} + +/////////////////////////////////////////////////////////////////////////////// + +File::~File() +{ + close(); + delete &_provider; +} + +/////////////////////////////////////////////////////////////////////////////// + +void +File::setMode( Mode mode_ ) +{ + _mode = mode_; +} + +void +File::setName( const std::string& name_ ) +{ + _name = name_; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +File::open( std::string name_, Mode mode_ ) +{ + if( _isOpen ) + return true; + + if( !name_.empty() ) + setName( name_ ); + if( mode_ != MODE_UNDEFINED ) + setMode( mode_ ); + + if( _provider.open( _name, _mode )) + return true; + + FileSystem::getFileSize( _name, _size ); + + _isOpen = true; + return false; +} + +bool +File::seek( Size pos ) +{ + if( !_isOpen ) + return true; + + if( _provider.seek( pos )) + return true; + _position = pos; + return false; +} + +bool +File::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) +{ + nin = 0; + + if( !_isOpen ) + return true; + + if( _provider.read( buffer, size, nin, maxChunkSize )) + return true; + + _position += nin; + if( _position > _size ) + _size = _position; + + return false; +} + +bool +File::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) +{ + nout = 0; + + if( !_isOpen ) + return true; + + if( _provider.write( buffer, size, nout, maxChunkSize )) + return true; + + _position += nout; + if( _position > _size ) + _size = _position; + + return false; +} + +bool +File::close() +{ + if( !_isOpen ) + return false; + if( _provider.close() ) + return true; + + _isOpen = false; + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +CustomFileProvider::CustomFileProvider( const MP4FileProvider& provider ) + : _handle( NULL ) +{ + memcpy( &_call, &provider, sizeof(MP4FileProvider) ); +} + +bool +CustomFileProvider::open( std::string name, Mode mode ) +{ + MP4FileMode fm; + switch( mode ) { + case MODE_READ: fm = FILEMODE_READ; break; + case MODE_MODIFY: fm = FILEMODE_MODIFY; break; + case MODE_CREATE: fm = FILEMODE_CREATE; break; + + case MODE_UNDEFINED: + default: + fm = FILEMODE_UNDEFINED; + break; + } + + _handle = _call.open( name.c_str(), fm ); + return _handle == NULL; +} + +bool +CustomFileProvider::seek( Size pos ) +{ + return _call.seek( _handle, pos ); +} + +bool +CustomFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) +{ + return _call.read( _handle, buffer, size, &nin, maxChunkSize ); +} + +bool +CustomFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) +{ + return _call.write( _handle, buffer, size, &nout, maxChunkSize ); +} + +bool +CustomFileProvider::close() +{ + return _call.close( _handle ); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h new file mode 100644 index 00000000..67bb2b6d --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h @@ -0,0 +1,208 @@ +#ifndef MP4V2_PLATFORM_IO_FILE_H +#define MP4V2_PLATFORM_IO_FILE_H + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +class MP4V2_EXPORT FileProvider +{ +public: + static FileProvider& standard(); + +public: + //! file operation mode flags + enum Mode { + MODE_UNDEFINED, //!< undefined + MODE_READ, //!< file may be read + MODE_MODIFY, //!< file may be read/written + MODE_CREATE, //!< file will be created/truncated for read/write + }; + + //! type used to represent all file sizes and offsets + typedef int64_t Size; + +public: + virtual ~FileProvider() { } + + virtual bool open( std::string name, Mode mode ) = 0; + virtual bool seek( Size pos ) = 0; + virtual bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ) = 0; + virtual bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) = 0; + virtual bool close() = 0; + +protected: + FileProvider() { } +}; + +/////////////////////////////////////////////////////////////////////////////// +/// +/// File implementation. +/// +/// File objects model real filesystem files in a 1:1 releationship and always +/// treated as binary; there are no translations of text content performed. +/// +/// The interface represents all sizes with a signed 64-bit value, thus +/// the limit to this interface is 63-bits of size, roughly 9.22 million TB. +/// +/////////////////////////////////////////////////////////////////////////////// + +class MP4V2_EXPORT File : public FileProvider +{ +public: + /////////////////////////////////////////////////////////////////////////// + //! + //! Constructor. + //! + //! A new file object is constructed but not opened. + //! + //! @param name filename of file object, or empty-string. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @param mode bitmask specifying mode flags. + //! See #Mode for bit constants. + //! @param provider a fileprovider instance. If NULL a standard file + //! provider will be used otherwise the supplied provider must be + //! new-allocated and will be delete'd via ~File(). + //! + /////////////////////////////////////////////////////////////////////////// + + explicit File( std::string name = "", Mode mode = MODE_UNDEFINED, FileProvider* = NULL ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Destructor. + //! + //! File object is destroyed. If the file is opened it is closed prior + //! to destruction. + //! + /////////////////////////////////////////////////////////////////////////// + + ~File(); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Open file. + //! + //! @param name filename of file object, or empty-string to use #name. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + bool open( std::string name = "", Mode mode = MODE_UNDEFINED ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Closes file. + //! + //! If the file has not been opened or is not considered the + //! owner of a filehandle, no action is taken. + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + bool close(); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Set current file position in bytes. + //! + //! @param pos new file position in bytes. + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + bool seek( Size pos ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Binary stream read. + //! + //! The function reads up to a maximum <b>size</b> bytes from file, + //! storing them in <b>buffer</b>. The number of bytes actually read are + //! returned in <b>nin</b>. + //! + //! @param buffer storage for data read from file. + //! @param size maximum number of bytes to read from file. + //! @param nin output indicating number of bytes read from file. + //! @param maxChunkSize maximum chunk size for reads issued to operating + //! system or 0 for default. + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + bool read( void* buffer, Size size, Size& nin, Size maxChunkSize = 0 ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Binary stream write. + //! + //! The function writes up to a maximum <b>size</b> bytes from + //! <b>buffer</b> to file. The number of bytes actually written are + //! returned in <b>nout</b>. + //! + //! @param buffer data to be written out to file. + //! @param size maximum number of bytes to read from file. + //! @param nout output indicating number of bytes written to file. + //! @param maxChunkSize maximum chunk size for writes issued to operating + //! system or 0 for default. + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize = 0 ); + +private: + std::string _name; + bool _isOpen; + Mode _mode; + Size _size; + Size _position; + FileProvider& _provider; + +public: + const std::string& name; //!< read-only: file pathname or empty-string if not applicable + const bool& isOpen; //!< read-only: true if file is open + const Mode& mode; //!< read-only: file mode + const Size& size; //!< read-only: file size + const Size& position; //!< read-only: file position + +public: + void setName( const std::string& name ); + void setMode( Mode mode ); +}; + +/////////////////////////////////////////////////////////////////////////////// + +class CustomFileProvider : public FileProvider +{ +public: + CustomFileProvider( const MP4FileProvider& ); + + bool open( std::string name, Mode mode ); + bool seek( Size pos ); + bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); + bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); + bool close(); + +private: + MP4FileProvider _call; + void* _handle; +}; + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io + +#endif // MP4V2_PLATFORM_IO_FILE_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp new file mode 100644 index 00000000..073b0261 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp @@ -0,0 +1,103 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +void +FileSystem::pathnameCleanup( string& name ) +{ + string bad; + + // fold repeating directory separators + bad = DIR_SEPARATOR; + bad += DIR_SEPARATOR; + for( string::size_type pos = name.find( bad ); + pos != string::npos; + pos = name.find( bad, pos ) ) + { + name.replace( pos, bad.length(), DIR_SEPARATOR ); + } + + // replace occurances of /./ with / + bad = DIR_SEPARATOR; + bad += '.'; + bad += DIR_SEPARATOR; + for( string::size_type pos = name.find( bad ); + pos != string::npos; + pos = name.find( bad, pos ) ) + { + name.replace( pos, bad.length(), DIR_SEPARATOR ); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +void +FileSystem::pathnameOnlyExtension( string& name ) +{ + // compute basename + string::size_type dot_pos = name.rfind( '.' ); + string::size_type slash_pos = name.rfind( DIR_SEPARATOR ); + + // dot_pos must be after slash_pos + if( slash_pos != string::npos && dot_pos < slash_pos ) + dot_pos = string::npos; + + // return empty-string if no dot + if( dot_pos == string::npos ) { + name.resize( 0 ); + return; + } + + name = name.substr( dot_pos + 1 ); + pathnameCleanup( name ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void +FileSystem::pathnameStripExtension( string& name ) +{ + pathnameCleanup( name ); + + // compute basename + string::size_type dot_pos = name.rfind( '.' ); + string::size_type slash_pos = name.rfind( DIR_SEPARATOR ); + + // dot_pos must be after slash_pos + if( slash_pos != string::npos && dot_pos < slash_pos ) + dot_pos = string::npos; + + // chop extension + if( dot_pos != string::npos ) + name.resize( dot_pos ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void +FileSystem::pathnameTemp( string& name, string dir, string prefix, string suffix ) +{ + ostringstream buf; + + if( !dir.empty() ) { + buf << dir; + + // add dir separator if needed + // TODO there's a platform specific bug here, if someone passes in a pathname ending + // in '\', which would be legitimate on Windows. + if( dir[dir.length()-1] != '/' ) + buf << '/'; + } + + buf << prefix; + buf << setfill('0') << setw(8) << number::random32(); + buf << suffix; + + name = buf.str(); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h new file mode 100644 index 00000000..b348752a --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h @@ -0,0 +1,215 @@ +#ifndef MP4V2_PLATFORM_IO_FILESYSTEM_H +#define MP4V2_PLATFORM_IO_FILESYSTEM_H + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// +/// +/// General file-system abstraction. +/// +/// FileSystem abstracts operations on files and directories. +/// +/////////////////////////////////////////////////////////////////////////////// +class MP4V2_EXPORT FileSystem +{ +public: + static string DIR_SEPARATOR; //!< separator string used in file pathnames + static string PATH_SEPARATOR; //!< separator string used in search-paths + + /////////////////////////////////////////////////////////////////////////// + //! + //! Query file presence. + //! Check if <b>name</b> exists. + //! @param name filename to query. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @return true if present, false otherwise. + //! + /////////////////////////////////////////////////////////////////////////// + + static bool exists( std::string name ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Query directory type. + //! Check if <b>name</b> exists and is a directory. + //! @param name pathname to query. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @return true if directory, false otherwise. + //! + /////////////////////////////////////////////////////////////////////////// + + static bool isDirectory( std::string name ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Query file type. + //! Check if <b>name</b> exists and is a file. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @param name filename to query. + //! @return true if file, false otherwise. + //! + /////////////////////////////////////////////////////////////////////////// + + static bool isFile( std::string name ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Query file size. + //! Check if <b>name</b> exists and is a file. + //! @param name filename to query. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @param size output indicating file size in bytes. + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + static bool getFileSize( std::string name, File::Size& size ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Rename file or directory. + //! + //! Rename <b>oldname</b> to <b>newname</b>. + //! If <b>newname</b> exists, it is first removed. + //! Both <b>oldname</b> and <b>newname</b> must be of the same type; + //! that is, both must be either files or directories and must reside on + //! the same filesystem. + //! + //! @param oldname existing pathname to rename. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! @param newname new pathname. + //! On Windows, this should be a UTF-8 encoded string. + //! On other platforms, it should be an 8-bit encoding that is + //! appropriate for the platform, locale, file system, etc. + //! (prefer to use UTF-8 when possible). + //! + //! @return true on failure, false on success. + //! + /////////////////////////////////////////////////////////////////////////// + + static bool rename( std::string oldname, std::string newname ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Generate temporary pathname. + //! + //! @param name output containing generated pathname. + //! @param dir relative or absolute directory of pathname. + //! @param prefix text prepended to base pathname. + //! @param suffix text appended to base pathname. + //! + /////////////////////////////////////////////////////////////////////////// + + static void pathnameTemp( string& name, string dir = ".", string prefix = "tmp", string suffix = "" ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Cleanup pathname. + //! + //! Redundant (repeating) directory-separators are folded into a single + //! directory-separator. + //! + //! Redundant /./ are folded into a single directory-separator. + //! + //! @param name pathname to modify. + //! + /////////////////////////////////////////////////////////////////////////// + + static void pathnameCleanup( string& name ); + +#if 0 +TODO-KB: implement + /////////////////////////////////////////////////////////////////////////// + //! + //! Remove everything after the last directory component. + //! + //! A pathname cleanup is always performed. See pathnameCleanup(). + //! If no directory component is present then "." is assumed. + //! + //! @param name pathname to modify. + //! @param trailing when true all results are suffixed with exactly one + //! directory-separator, otherwise the result is guaranteed to not + //! end in a directory-separator. + //! + /////////////////////////////////////////////////////////////////////////// + static void pathnameOnlyDirectory( string& name, bool trailing = true ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Remove everything except the file component of pathname. + //! + //! A pathname cleanup is always performed. See pathnameCleanup(). + //! If no file component exists then an empty-string is output. + //! A file component may include an extension. + //! + //! @param name pathname to modify. + //! + /////////////////////////////////////////////////////////////////////////// + static void pathnameOnlyFile( string& name ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Remove everything except file basename. + //! + //! A pathname cleanup is always performed. See pathnameCleanup(). + //! A basename is considered to be everything before the last '.' + //! in the file component of a pathname. + //! If no file extension exists then an empty-string is output. + //! + //! @param name pathname to modify. + //! + /////////////////////////////////////////////////////////////////////////// + static void pathnameOnlyBasename( string& name ); +#endif + + /////////////////////////////////////////////////////////////////////////// + //! + //! Remove everything except file extension. + //! + //! A pathname cleanup is always performed. See pathnameCleanup(). + //! A file extension is considered to everything <b>after</b> + //! the last '.' in the file component of a pathname. + //! If no file extension exists then an empty-string is output. + //! + //! @param name pathname to modify. + //! + /////////////////////////////////////////////////////////////////////////// + + static void pathnameOnlyExtension( string& name ); + + /////////////////////////////////////////////////////////////////////////// + //! + //! Remove file extension from pathname. + //! + //! A pathname cleanup is always performed. See pathnameCleanup(). + //! A file extension is considered to everything <b>after</b> + //! the last '.' in the file component of a pathname. + //! The last '.' is also removed. + //! + //! @param name pathname to modify. + //! + /////////////////////////////////////////////////////////////////////////// + + static void pathnameStripExtension( string& name ); +}; + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io + +#endif // MP4V2_PLATFORM_IO_FILESYSTEM_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp new file mode 100644 index 00000000..46cf9337 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp @@ -0,0 +1,65 @@ +#include "libplatform/impl.h" +#include <sys/stat.h> + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::exists( string path_ ) +{ + struct stat buf; + return stat( path_.c_str(), &buf ) == 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::isDirectory( string path_ ) +{ + struct stat buf; + if( stat( path_.c_str(), &buf )) + return false; + return S_ISDIR( buf.st_mode ); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::isFile( string path_ ) +{ + struct stat buf; + if( stat( path_.c_str(), &buf )) + return false; + return S_ISREG( buf.st_mode ); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::getFileSize( string path_, File::Size& size_ ) +{ + size_ = 0; + struct stat buf; + if( stat( path_.c_str(), &buf )) + return true; + size_ = buf.st_size; + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::rename( string from, string to ) +{ + return ::rename( from.c_str(), to.c_str() ) != 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +string FileSystem::DIR_SEPARATOR = "/"; +string FileSystem::PATH_SEPARATOR = ":"; + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp new file mode 100644 index 00000000..4a213819 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp @@ -0,0 +1,146 @@ +#include "src/impl.h" +#include "libplatform/impl.h" /* for platform_win32_impl.h which declares Utf8ToFilename */ +#include <windows.h> + +namespace mp4v2 { + using namespace impl; +} + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +static DWORD getAttributes ( string path_ ); + +/** + * Call GetFileAttributesW throw exceptions for errors + * + * @param path_ the path to get attributes for + * + * @retval INVALID_FILE_ATTRIBUTES @p path_ doesn't exist + * @retval anything else the attributes of @p path_ + */ +static DWORD +getAttributes ( string path_ ) +{ + win32::Utf8ToFilename filename(path_); + + if (!filename.IsUTF16Valid()) + { + // throw an exception to avoid changing the + // signature of this function and dealing with all + // the places it's called. + ostringstream msg; + msg << "can't convert file to UTF-16(" << filename.utf8 << ")"; + throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); + } + + DWORD attributes = ::GetFileAttributesW(filename); + if( attributes == INVALID_FILE_ATTRIBUTES ) + { + DWORD last_err = GetLastError(); + + // Distinguish between an error and the path not existing + if ((last_err == ERROR_FILE_NOT_FOUND) || (last_err == ERROR_PATH_NOT_FOUND)) + { + return attributes; + } + + // Anything else is an error + ostringstream msg; + msg << "GetFileAttributes(" << filename.utf8 << ") failed (" << last_err << ")"; + throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); + } + + // path exists so return its attributes + return attributes; +} + +bool +FileSystem::exists( string path_ ) +{ + return( getAttributes(path_) != INVALID_FILE_ATTRIBUTES ); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::isDirectory( string path_ ) +{ + DWORD attributes = getAttributes( path_ ); + if( attributes == INVALID_FILE_ATTRIBUTES ) + return false; + + return ( ( attributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY ); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::isFile( string path_ ) +{ + DWORD attributes = getAttributes( path_ ); + if( attributes == INVALID_FILE_ATTRIBUTES ) + return false; + + return ( ( attributes & FILE_ATTRIBUTE_DIRECTORY ) != FILE_ATTRIBUTE_DIRECTORY ); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::getFileSize( string path_, File::Size& size_ ) +{ + win32::Utf8ToFilename filename(path_); + + if (!filename.IsUTF16Valid()) + { + // The logging is done + return true; + } + + size_ = 0; + WIN32_FILE_ATTRIBUTE_DATA data = {0}; + if( !GetFileAttributesExW( filename, GetFileExInfoStandard, (LPVOID)&data ) ) + { + log.errorf("%s: GetFileAttributesExW(%s) failed (%d)",__FUNCTION__,filename.utf8.c_str(), + GetLastError()); + return true; + } + + size_ = ( (File::Size)data.nFileSizeHigh << 32 ) | data.nFileSizeLow; + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool +FileSystem::rename( string from, string to ) +{ + win32::Utf8ToFilename from_file(from); + win32::Utf8ToFilename to_file(to); + + if (!from_file.IsUTF16Valid() || !to_file.IsUTF16Valid()) + { + return true; + } + + if (!::MoveFileExW( from_file, to_file, + MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ) ) + { + log.errorf("%s: MoveFileExW(%s,%s) failed (%d)",__FUNCTION__,from_file.utf8.c_str(),to_file.utf8.c_str(), + GetLastError()); + return true; + } + + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +string FileSystem::DIR_SEPARATOR = "\\"; +string FileSystem::PATH_SEPARATOR = ";"; + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp new file mode 100644 index 00000000..b6fb214a --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp @@ -0,0 +1,109 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +class StandardFileProvider : public FileProvider +{ +public: + StandardFileProvider(); + + bool open( std::string name, Mode mode ); + bool seek( Size pos ); + bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); + bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); + bool close(); + +private: + bool _seekg; + bool _seekp; + std::fstream _fstream; +}; + +/////////////////////////////////////////////////////////////////////////////// + +StandardFileProvider::StandardFileProvider() + : _seekg ( false ) + , _seekp ( false ) +{ +} + +bool +StandardFileProvider::open( std::string name, Mode mode ) +{ + ios::openmode om = ios::binary; + switch( mode ) { + case MODE_UNDEFINED: + case MODE_READ: + default: + om |= ios::in; + _seekg = true; + _seekp = false; + break; + + case MODE_MODIFY: + om |= ios::in | ios::out; + _seekg = true; + _seekp = true; + break; + + case MODE_CREATE: + om |= ios::in | ios::out | ios::trunc; + _seekg = true; + _seekp = true; + break; + } + + _fstream.open( name.c_str(), om ); + return _fstream.fail(); +} + +bool +StandardFileProvider::seek( Size pos ) +{ + if( _seekg ) + _fstream.seekg( pos, ios::beg ); + if( _seekp ) + _fstream.seekp( pos, ios::beg ); + return _fstream.fail(); +} + +bool +StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) +{ + _fstream.read( (char*)buffer, size ); + if( _fstream.fail() ) + return true; + nin = _fstream.gcount(); + return false; +} + +bool +StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) +{ + _fstream.write( (const char*)buffer, size ); + if( _fstream.fail() ) + return true; + nout = size; + return false; +} + +bool +StandardFileProvider::close() +{ + _fstream.close(); + return _fstream.fail(); +} + +/////////////////////////////////////////////////////////////////////////////// + +FileProvider& +FileProvider::standard() +{ + return *new StandardFileProvider(); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp new file mode 100644 index 00000000..d9101ea3 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp @@ -0,0 +1,258 @@ +#include "src/impl.h" +#include "libplatform/impl.h" /* for platform_win32_impl.h which declares Utf8ToFilename */ +#include <windows.h> + +namespace mp4v2 { + using namespace impl; +} + +/** + * Set this to 1 to compile in extra debugging + */ +#define EXTRA_DEBUG 0 + +/** + * @def LOG_PRINTF + * + * call log.printf if EXTRA_DEBUG is defined to 1. Do + * nothing otherwise + */ +#if EXTRA_DEBUG +#define LOG_PRINTF(X) log.printf X +#else +#define LOG_PRINTF(X) +#endif + +namespace mp4v2 { namespace platform { namespace io { + +/////////////////////////////////////////////////////////////////////////////// + +class StandardFileProvider : public FileProvider +{ +public: + StandardFileProvider(); + + bool open( std::string name, Mode mode ); + bool seek( Size pos ); + bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); + bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); + bool close(); + +private: + HANDLE _handle; + + /** + * The UTF-8 encoded file name + */ + std::string _name; +}; + +/////////////////////////////////////////////////////////////////////////////// + +StandardFileProvider::StandardFileProvider() + : _handle( INVALID_HANDLE_VALUE ) +{ +} + +/** + * Open a file + * + * @param name the name of a file to open + * @param mode the mode to open @p name + * + * @retval false successfully opened @p name + * @retval true error opening @p name + */ +bool +StandardFileProvider::open( std::string name, Mode mode ) +{ + DWORD access = 0; + DWORD share = 0; + DWORD crdisp = 0; + DWORD flags = FILE_ATTRIBUTE_NORMAL; + + switch( mode ) { + case MODE_UNDEFINED: + case MODE_READ: + default: + access |= GENERIC_READ; + share |= FILE_SHARE_READ; + crdisp |= OPEN_EXISTING; + break; + + case MODE_MODIFY: + access |= GENERIC_READ | GENERIC_WRITE; + share |= FILE_SHARE_READ; + crdisp |= OPEN_EXISTING; + break; + + case MODE_CREATE: + access |= GENERIC_READ | GENERIC_WRITE; + share |= FILE_SHARE_READ; + crdisp |= CREATE_ALWAYS; + break; + } + + win32::Utf8ToFilename filename(name); + + if (!filename.IsUTF16Valid()) + { + // The logging is done + return true; + } + + ASSERT(LPCWSTR(filename)); + _handle = CreateFileW( filename, access, share, NULL, crdisp, flags, NULL ); + if (_handle == INVALID_HANDLE_VALUE) + { + log.errorf("%s: CreateFileW(%s) failed (%d)",__FUNCTION__,filename.utf8.c_str(),GetLastError()); + return true; + } + + /* + ** Make a copy of the name for future log messages, etc. + */ + log.verbose2f("%s: CreateFileW(%s) succeeded",__FUNCTION__,filename.utf8.c_str()); + + _name = filename.utf8; + return false; +} + +/** + * Seek to an offset in the file + * + * @param pos the offset from the beginning of the file to + * seek to + * + * @retval false successfully seeked to @p pos + * @retval true error seeking to @p pos + */ +bool +StandardFileProvider::seek( Size pos ) +{ + LARGE_INTEGER n; + + ASSERT(_handle != INVALID_HANDLE_VALUE); + + n.QuadPart = pos; + if (!SetFilePointerEx( _handle, n, NULL, FILE_BEGIN )) + { + log.errorf("%s: SetFilePointerEx(%s,%" PRId64 ") failed (%d)",__FUNCTION__,_name.c_str(), + pos,GetLastError()); + return true; + } + + return false; +} + +/** + * Read from the file + * + * @param buffer populated with at most @p size bytes from + * the file + * + * @param size the maximum number of bytes to read + * + * @param nin the + * + * @retval false successfully read from the file + * @retval true error reading from the file + */ +bool +StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) +{ + DWORD nread = 0; + + ASSERT(_handle != INVALID_HANDLE_VALUE); + + // ReadFile takes a DWORD for number of bytes to read so + // make sure we're not asking for more than fits. + // MAXDWORD from WinNT.h. + ASSERT(size <= MAXDWORD); + if( ReadFile( _handle, buffer, (DWORD)(size & MAXDWORD), &nread, NULL ) == 0 ) + { + log.errorf("%s: ReadFile(%s,%d) failed (%d)",__FUNCTION__,_name.c_str(), + (DWORD)(size & MAXDWORD),GetLastError()); + return true; + } + LOG_PRINTF((MP4_LOG_VERBOSE3,"%s: ReadFile(%s,%d) succeeded: read %d byte(s)",__FUNCTION__, + _name.c_str(),(DWORD)(size & MAXDWORD),nread)); + nin = nread; + return false; +} + +/** + * Write to the file + * + * @param buffer the data to write + * + * @param size the number of bytes of @p buffer to write + * + * @param nout populated with the number of bytes actually + * written if the function succeeds + * + * @retval false successfully wrote to the file + * @retval true error writing to the file + */ +bool +StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) +{ + DWORD nwrote = 0; + + ASSERT(_handle != INVALID_HANDLE_VALUE); + + // ReadFile takes a DWORD for number of bytes to read so + // make sure we're not asking for more than fits. + // MAXDWORD from WinNT.h. + ASSERT(size <= MAXDWORD); + if( WriteFile( _handle, buffer, (DWORD)(size & MAXDWORD), &nwrote, NULL ) == 0 ) + { + log.errorf("%s: WriteFile(%s,%d) failed (%d)",__FUNCTION__,_name.c_str(), + (DWORD)(size & MAXDWORD),GetLastError()); + return true; + } + log.verbose2f("%s: WriteFile(%s,%d) succeeded: wrote %d byte(s)",__FUNCTION__, + _name.c_str(),(DWORD)(size & MAXDWORD),nwrote); + nout = nwrote; + return false; +} + +/** + * Close the file + * + * @retval false successfully closed the file + * @retval true error closing the file + */ +bool +StandardFileProvider::close() +{ + BOOL retval; + + retval = CloseHandle( _handle ); + if (!retval) + { + log.errorf("%s: CloseHandle(%s) failed (%d)",__FUNCTION__, + _name.c_str(),GetLastError()); + } + + // Whether we succeeded or not, clear the handle and + // forget the name + _handle = INVALID_HANDLE_VALUE; + _name.clear(); + + // CloseHandle return 0/false to indicate failure, but + // we return 0/false to indicate success, so negate. + return !retval; +} + +/////////////////////////////////////////////////////////////////////////////// + +FileProvider& +FileProvider::standard() +{ + return *new StandardFileProvider(); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random.h new file mode 100644 index 00000000..9d0f105b --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random.h @@ -0,0 +1,18 @@ +#ifndef MP4V2_PLATFORM_NUMBER_RANDOM_H +#define MP4V2_PLATFORM_NUMBER_RANDOM_H + +namespace mp4v2 { namespace platform { namespace number { + +/////////////////////////////////////////////////////////////////////////////// + +/// Generate 32-bit pseudo-random number. +MP4V2_EXPORT uint32_t random32(); + +/// Seed pseudo-random number generator. +MP4V2_EXPORT void srandom( uint32_t ); + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::number + +#endif // MP4V2_PLATFORM_NUMBER_RANDOM_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_posix.cpp new file mode 100644 index 00000000..0bdcd1db --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_posix.cpp @@ -0,0 +1,24 @@ +#include "libplatform/impl.h" +#include <stdlib.h> + +namespace mp4v2 { namespace platform { namespace number { + +/////////////////////////////////////////////////////////////////////////////// + +uint32_t +random32() +{ + return uint32_t( ::random() ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void +srandom( uint32_t seed ) +{ + ::srandom( seed ); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_win32.cpp new file mode 100644 index 00000000..f884e5dc --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/number/random_win32.cpp @@ -0,0 +1,24 @@ +#include "libplatform/impl.h" +#include <stdlib.h> + +namespace mp4v2 { namespace platform { namespace number { + +/////////////////////////////////////////////////////////////////////////////// + +uint32_t +random32() +{ + return uint32_t( ::rand() << 16 | ::rand() ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void +srandom( uint32_t seed ) +{ + ::srand( seed ); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform.h new file mode 100644 index 00000000..2868f77e --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform.h @@ -0,0 +1,43 @@ +#ifndef MP4V2_PLATFORM_PLATFORM_H +#define MP4V2_PLATFORM_PLATFORM_H + +/// @namespace mp4v2::platform (private) Platform abstraction. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> +/// +/// This namespace implements platform abstractions that are useful for +/// keeping the code base portable. + +/// @namespace mp4v2::platform::io (private) I/O. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> + +/// @namespace mp4v2::platform::number (private) Number. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> + +/// @namespace mp4v2::platform::sys (private) System. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> + +/////////////////////////////////////////////////////////////////////////////// + +#if defined( _WIN32 ) +# include "libplatform/platform_win32.h" +#else +# include "libplatform/platform_posix.h" +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#include "libplatform/warning.h" +#include "libplatform/endian.h" + +#include "libplatform/io/File.h" +#include "libplatform/io/FileSystem.h" + +#include "libplatform/number/random.h" +#include "libplatform/process/process.h" +#include "libplatform/prog/option.h" +#include "libplatform/sys/error.h" +#include "libplatform/time/time.h" + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_PLATFORM_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_base.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_base.h new file mode 100644 index 00000000..5b6a263f --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_base.h @@ -0,0 +1,34 @@ +#ifndef MP4V2_PLATFORM_BASE_H +#define MP4V2_PLATFORM_BASE_H + +/////////////////////////////////////////////////////////////////////////////// + +#include <fstream> +#include <iomanip> +#include <iostream> +#include <limits> +#include <list> +#include <locale> +#include <map> +#include <set> +#include <sstream> +#include <string> +#include <vector> + +#include <cassert> +#include <cctype> +#include <cerrno> +#include <climits> +#include <cmath> +#include <cstdarg> +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <cwchar> +#include <cwctype> + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_BASE_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_posix.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_posix.h new file mode 100644 index 00000000..af5901ad --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_posix.h @@ -0,0 +1,77 @@ +#ifndef MP4V2_PLATFORM_POSIX_H +#define MP4V2_PLATFORM_POSIX_H + +/////////////////////////////////////////////////////////////////////////////// + +#include "libplatform/config.h" + +/////////////////////////////////////////////////////////////////////////////// + +// constant macros are not usually used with C++ so the standard mechanism to +// activate it is to define before stdint.h +#ifndef __STDC_CONSTANT_MACROS +# define __STDC_CONSTANT_MACROS +#endif + +// format macros are not usually used with C++ so the standard mechanism to +// activate it is to define before inttypes.h +#ifndef __STDC_FORMAT_MACROS +# define __STDC_FORMAT_MACROS +#endif + +#ifdef NEED_LFS_ACTIVATION +# ifndef _LARGEFILE_SOURCE +# define _LARGEFILE_SOURCE +# define _FILE_OFFSET_BITS 64 +# endif +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#include "libplatform/platform_base.h" +#include <inttypes.h> +#include <stdint.h> +#include <fcntl.h> +#include <unistd.h> + +#include <mp4v2/mp4v2.h> + +/////////////////////////////////////////////////////////////////////////////// + +namespace mp4v2 { namespace platform { + using namespace std; + + using ::int8_t; + using ::int16_t; + using ::int32_t; + using ::int64_t; + + using ::uint8_t; + using ::uint16_t; + using ::uint32_t; + using ::uint64_t; +}} // namespace mp4v2::platform + +/////////////////////////////////////////////////////////////////////////////// + +// win32 platform requires O_BINARY when using old open() calls so we add +// this harmless bit-flag for posix to avoid .cpp platform conditionals +#ifndef O_BINARY +# define O_BINARY 0 +#endif + +/////////////////////////////////////////////////////////////////////////////// + +// ARM seems to require integer instructions operands to have 4-byte alignment +// so we set this macro to for some int<->string code to manually copy string +// bytes into an int which aligns it. This is much easier than trying to +// align pertinent string data (constants) from in text sections. +#if defined( __arm__ ) +# define MP4V2_INTSTRING_ALIGNMENT 1 +#else +# undef MP4V2_INTSTRING_ALIGNMENT +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_POSIX_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_win32.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_win32.h new file mode 100644 index 00000000..7e8685a5 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/platform_win32.h @@ -0,0 +1,93 @@ +#ifndef MP4V2_PLATFORM_WIN32_H +#define MP4V2_PLATFORM_WIN32_H + +/////////////////////////////////////////////////////////////////////////////// + +// mingw needs this to enable some newer 64-bit functions +#ifdef __MINGW32__ +# undef __MSVCRT_VERSION__ +# define __MSVCRT_VERSION__ 0x800 +#endif + +// set minimum win32 API requirement to Windows 2000 or higher +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0500 +#endif +#ifndef WINVER +# define WINVER 0x0500 +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#include "libplatform/platform_base.h" +#include <mp4v2/mp4v2.h> + +/////////////////////////////////////////////////////////////////////////////// + +namespace mp4v2 { namespace platform { + using namespace std; + + using ::int8_t; + using ::int16_t; + using ::int32_t; + using ::int64_t; + + using ::uint8_t; + using ::uint16_t; + using ::uint32_t; + using ::uint64_t; +}} // namespace mp4v2::platform + +/////////////////////////////////////////////////////////////////////////////// + +// fprintf macros for unsigned types - mingw32 is a good source if more needed +#define PRId8 "d" +#define PRId16 "d" +#define PRId32 "d" +#define PRId64 "I64d" + +#define PRIu8 "u" +#define PRIu16 "u" +#define PRIu32 "u" +#define PRIu64 "I64u" + +#define PRIx8 "x" +#define PRIx16 "x" +#define PRIx32 "x" +#define PRIx64 "I64x" + +/////////////////////////////////////////////////////////////////////////////// + +// some macros for constant expressions +#define INT8_C(x) x +#define INT16_C(x) x +#define INT32_C(x) x ## L +#define INT64_C(x) x ## LL + +#define UINT8_C(x) x +#define UINT16_C(x) x +#define UINT32_C(x) x ## UL +#define UINT64_C(x) x ## ULL + +/////////////////////////////////////////////////////////////////////////////// + +#ifdef min +# undef min +#endif + +#ifdef max +# undef max +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#define snprintf(s,n,...) _snprintf(s,n,__VA_ARGS__) +#define strcasecmp(s1,s2) _stricmp(s1,s2) +#define strdup(s) _strdup(s) + +/////////////////////////////////////////////////////////////////////////////// + +// macro clashes with symbol +#undef LC_NONE + +#endif // MP4V2_PLATFORM_WIN32_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process.h new file mode 100644 index 00000000..446b100a --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process.h @@ -0,0 +1,16 @@ +#ifndef MP4V2_PLATFORM_PROCESS_PROCESS_H +#define MP4V2_PLATFORM_PROCESS_PROCESS_H + +/// @namespace mp4v2::platform::process (private) Process. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> +namespace mp4v2 { namespace platform { namespace process { + +/////////////////////////////////////////////////////////////////////////////// + +MP4V2_EXPORT int32_t getpid(); + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::process + +#endif // MP4V2_PLATFORM_PROCESS_PROCESS_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_posix.cpp new file mode 100644 index 00000000..74b4e174 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_posix.cpp @@ -0,0 +1,15 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace process { + +/////////////////////////////////////////////////////////////////////////////// + +int32_t +getpid() +{ + return ::getpid(); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::process diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_win32.cpp new file mode 100644 index 00000000..b7846804 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/process/process_win32.cpp @@ -0,0 +1,16 @@ +#include "libplatform/impl.h" +#include <process.h> + +namespace mp4v2 { namespace platform { namespace process { + +/////////////////////////////////////////////////////////////////////////////// + +int32_t +getpid() +{ + return ::_getpid(); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::process diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.cpp new file mode 100644 index 00000000..645dccf7 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.cpp @@ -0,0 +1,637 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// branched from: +// FreeBSD 7.0-RELEASE +// $FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.15 2006/09/23 14:48:31 ache Exp $ +// +/////////////////////////////////////////////////////////////////////////////// + +/* + * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libplatform/impl.h" + +namespace mp4v2 { +namespace platform { +namespace prog { + +/////////////////////////////////////////////////////////////////////////////// + +#define GNU_COMPATIBLE +#define REPLACE_GETOPT + +namespace { + void warnx( const char* format, ... ) { + va_list ap; + va_start( ap, format ); + vfprintf( stderr, format, ap ); + va_end( ap ); + fprintf( stderr, "\n" ); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +#ifdef REPLACE_GETOPT +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +int optreset; /* reset getopt */ +const char* optarg; /* argument associated with option */ +#endif + +#define PRINT_ERROR ((opterr) && (*options != ':')) + +#define FLAG_PERMUTE 0x01 // permute non-options to the end of argv +#define FLAG_ALLARGS 0x02 // treat non-options as args to option "-1" +#define FLAG_LONGONLY 0x04 // operate as getopt_long_only + +// return values +#define BADCH (int)'?' +#define BADARG ((*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#define EMSG "" + +#ifdef GNU_COMPATIBLE +#define NO_PREFIX (-1) +#define D_PREFIX 0 +#define DD_PREFIX 1 +#define W_PREFIX 2 +#endif + +static int getopt_internal(int, char * const *, const char *, const Option*, int*, int); +static int parse_long_options(char * const *, const char *, const Option*, int *, int, int); +static int gcd(int, int); +static void permute_args(int, int, int, char * const *); + +static const char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char illoptchar[] = "illegal option -- %c"; /* From P1003.2 */ +#ifdef GNU_COMPATIBLE +static int dash_prefix = NO_PREFIX; +static const char gnuoptchar[] = "invalid option -- %c"; + +static const char recargstring[] = "option `%s%s' requires an argument"; +static const char ambig[] = "option `%s%.*s' is ambiguous"; +static const char noarg[] = "option `%s%.*s' doesn't allow an argument"; +static const char illoptstring[] = "unrecognized option `%s%s'"; +#else +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptstring[] = "unknown option -- %s"; +#endif + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(int a, int b) { + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return (b); +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(int panonopt_start, int panonopt_end, int opt_end, + char * const *nargv) { + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +/* + * parse_long_options -- + * Parse long options in argc/argv argument vector. + * Returns -1 if short_too is set and the option does not match long_options. + */ +static int +parse_long_options(char * const *nargv, const char *options, + const Option* long_options, int* idx, int short_too, int flags) { + const char *current_argv; + char *has_equal; +#ifdef GNU_COMPATIBLE + const char *current_dash; +#endif + size_t current_argv_len; + int i, match, exact_match, second_partial_match; + + current_argv = place; +#ifdef GNU_COMPATIBLE + switch (dash_prefix) { + case D_PREFIX: + current_dash = "-"; + break; + case DD_PREFIX: + current_dash = "--"; + break; + case W_PREFIX: + current_dash = "-W "; + break; + default: + current_dash = ""; + break; + } +#endif + match = -1; + exact_match = 0; + second_partial_match = 0; + + optind++; + + if ((has_equal = (char*)strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } + else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == current_argv_len) { + /* exact match */ + match = i; + exact_match = 1; + break; + } + /* + * If this is a known short option, don't allow + * a partial match of a single character. + */ + if (short_too && current_argv_len == 1) + continue; + + if (match == -1) /* first partial match */ + match = i; + else if ((flags & FLAG_LONGONLY) || + long_options[i].type != + long_options[match].type || + long_options[i].flag != long_options[match].flag || + long_options[i].val != long_options[match].val) + second_partial_match = 1; + } + if (!exact_match && second_partial_match) { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + (int)current_argv_len, + current_argv); + optopt = 0; + return (BADCH); + } + if (match != -1) { /* option found */ + if (long_options[match].type == Option::NO_ARG + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; +#ifdef GNU_COMPATIBLE + return (BADCH); +#else + return (BADARG); +#endif + } + if (long_options[match].type == Option::REQUIRED_ARG || + long_options[match].type == Option::OPTIONAL_ARG) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].type == Option::REQUIRED_ARG) { + /* + * optional argument doesn't use next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].type == Option::REQUIRED_ARG) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' indicates no error + * should be generated. + */ + if (PRINT_ERROR) + warnx(recargstring, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return (BADARG); + } + } + else { /* unknown option */ + if (short_too) { + --optind; + return (-1); + } + if (PRINT_ERROR) + warnx(illoptstring, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + current_argv); + optopt = 0; + return (BADCH); + } + if (idx) + *idx = match; + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + return (0); + } + else + return (long_options[match].val); +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + */ +static int +getopt_internal(int nargc, char * const *nargv, const char *options, + const Option* long_options, int* idx, int flags) { + const char *oli; /* option letter list index */ + int optchar, short_too; + int posixly_correct; /* no static, can be changed on the fly */ + + if (options == NULL) + return (-1); + + /* + * Disable GNU extensions if POSIXLY_CORRECT is set or options + * string begins with a '+'. + */ + posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); +#ifdef GNU_COMPATIBLE + if (*options == '-') + flags |= FLAG_ALLARGS; + else if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; +#else + if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; + else if (*options == '-') + flags |= FLAG_ALLARGS; +#endif + if (*options == '+' || *options == '-') + options++; + + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + optarg = NULL; + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + if (*(place = nargv[optind]) != '-' || +#ifdef GNU_COMPATIBLE + place[1] == '\0') { +#else + (place[1] == '\0' && strchr(options, '-') == NULL)) { +#endif + place = EMSG; /* found non-option */ + if (flags & FLAG_ALLARGS) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return (INORDER); + } + if (!(flags & FLAG_PERMUTE)) { + /* + * If no permutation wanted, stop parsing + * at first non-option. + */ + return (-1); + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + + /* + * If we have "-" do nothing, if "--" we are done. + */ + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { + optind++; + place = EMSG; + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + } + + /* + * Check long options if: + * 1) we were passed some + * 2) the arg is not just "-" + * 3) either the arg starts with -- we are getopt_long_only() + */ + if (long_options != NULL && place != nargv[optind] && + (*place == '-' || (flags & FLAG_LONGONLY))) { + short_too = 0; +#ifdef GNU_COMPATIBLE + dash_prefix = D_PREFIX; +#endif + if (*place == '-') { + place++; /* --foo long option */ +#ifdef GNU_COMPATIBLE + dash_prefix = DD_PREFIX; +#endif + } + else if (*place != ':' && strchr(options, *place) != NULL) + short_too = 1; /* could be short option too */ + + optchar = parse_long_options(nargv, options, long_options, + idx, short_too, flags); + if (optchar != -1) { + place = EMSG; + return (optchar); + } + } + + if ((optchar = (int)*place++) == (int)':' || + (optchar == (int)'-' && *place != '\0') || + (oli = (const char*)strchr(options, optchar)) == NULL) { + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (!*place) + ++optind; +#ifdef GNU_COMPATIBLE + if (PRINT_ERROR) + warnx(posixly_correct ? illoptchar : gnuoptchar, + optchar); +#else + if (PRINT_ERROR) + warnx(illoptchar, optchar); +#endif + optopt = optchar; + return (BADCH); + } + if (long_options != NULL && optchar == 'W' && oli[1] == ';') { + /* -W long-option */ + if (*place) /* no space */ + /* NOTHING */; + else if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } + else /* white space */ + place = nargv[optind]; +#ifdef GNU_COMPATIBLE + dash_prefix = W_PREFIX; +#endif + optchar = parse_long_options(nargv, options, long_options, + idx, 0, flags); + place = EMSG; + return (optchar); + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } + else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = place; + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } + else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return (optchar); +} + +#if 0 +#ifdef REPLACE_GETOPT +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the BSD getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) { + + /* + * We don't pass FLAG_PERMUTE to getopt_internal() since + * the BSD getopt(3) (unlike GNU) has never done this. + * + * Furthermore, since many privileged programs call getopt() + * before dropping privileges it makes sense to keep things + * as simple (and bug-free) as possible. + */ + return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); +} +#endif /* REPLACE_GETOPT */ +#endif + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getOption(int nargc, char * const *nargv, const char *options, + const Option* long_options, int* idx) { + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE)); +} + +/* + * getopt_long_only -- + * Parse argc/argv argument vector. + */ +int +getOptionSingle(int nargc, char * const *nargv, const char *options, + const Option* long_options, int* idx) { + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE|FLAG_LONGONLY)); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::prog diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.h new file mode 100644 index 00000000..9f7a82a4 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/prog/option.h @@ -0,0 +1,174 @@ +#ifndef MP4V2_PLATFORM_PROG_OPTION_H +#define MP4V2_PLATFORM_PROG_OPTION_H + +/////////////////////////////////////////////////////////////////////////////// +/// +/// @namespace mp4v2::platform::prog Command-line argument parsing. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> +/// +/// This namespace provides a mechanism to parse command-line arguments and +/// options for executables. +/// It is identical in behavior to <b>getopt_long</b> functions available +/// with many popular posix-platforms such as Darwin, FreeBSD and Linux. +/// Virtually any OS which has getopt_long will adequately document this +/// functionality. However, to avoid symbol ambiguity with the popular +/// posix implementation, the following identifiers have been renamed: +/// @li getopt_long() -> getOption() +/// @li getopt_long_only() -> getOptionSingle() +/// @li option -> Option +/// @li option.has_arg -> Option.type +//! +/////////////////////////////////////////////////////////////////////////////// +namespace mp4v2 { namespace platform { namespace prog { + +//! On return from getOption() or getOptionSingle(), +//! points to an option argument, if it is anticipated. +MP4V2_EXPORT extern const char* optarg; + +//! On return from getOption() or getOptionSingle(), +//! contains the index to the next argv argument for a subsequent call to +//! getOption() or getOptionSingle(). +//! Initialized to 1 and must be set manually to 1 prior to invoking +//! getOption() or getOptionSingle() to evaluate multiple sets of arguments. +MP4V2_EXPORT extern int optind; + +//! On return from getOption() or getOptionSingle(), +//! saves the last known option character returned by +//! getOption() or getOptionSingle(). +//! On error, contains the character/code of option which caused error. +MP4V2_EXPORT extern int optopt; + +//! Initialized to 1 and may be set to 0 to disable error messages. +MP4V2_EXPORT extern int opterr; + +//! Must be set to 1 before evaluating the 2nd or each additional set +//! of arguments. +MP4V2_EXPORT extern int optreset; + +//! Structure describing a single option. +//! An instance of Option is required for each program option and is +//! initialized before use with getOption() or getOptionWord(). +struct MP4V2_EXPORT Option +{ + //! expectation-type indicating number of arguments expected + //! on the command-line following the option-argument itself + enum Type { + //! indicates exactly 0 arguments follow option + NO_ARG, + //! indicates exactly 1 argument follow option + REQUIRED_ARG, + //! indicates 0 or 1 arguments follow option + OPTIONAL_ARG, + }; + + //! contains the option name without leading double-dash + const char* name; + + //! option expectation-type + Type type; + + //! If not NULL, then the integer pointed to by it will be set to + //! the value in the val field. If the flag field is NULL, then the + //! <b>val</b> field will be returned. + int* flag; + + //! Constant value representing option. This is usually a single-char + //! ASCII value but in case of long-options without a corresponding + //! single-char value it can be a unique integer (beyond ASCII range) + //! which represents the long-option. + int val; +}; + +/////////////////////////////////////////////////////////////////////////////// +//! +//! Get option character from command line argument list. +//! +//! getOption() is similar to posix getopt() but it accepts options in two +//! forms: words and characters. The getOption() function provides a +//! superset of the functionality of getopt(). The getOption() function can +//! be used in two ways. In the first way, every long-option understood by +//! the program has a corresponding short-option, and the Option structure +//! is only used to translate from long-options to short-options. When used +//! in this fashion, getOption() behaves identically to getopt(). This is +//! a good way to add long-option processing to an esxisting program with +//! a minimum of rewriting. +//! +//! In the second mechanism, a long-option sets a flag in the Option +//! structure structure passed, or will store a pointer to the command line +//! argument in the Option structure passed to it for options that take +//! arguments. Additionally, the long-option's argument may be specified as +//! a single argument with an equal sign, eg: +//! @code myprogram --myoption=somevalue +//! @endcode +//! +//! When a long-option is processed, the call to getOption() will return 0. +//! For this reason, long-option processing without shortcuts is not +//! backwards compatible with getopt(). +//! +//! It is possible to combine these methods, providing for long-options +//! processing with short-option equivalents for some options. Less +//! frequently used options would be processed as long-options only. +//! +//! @param argc number of arguments. +//! @param argv argument array of strings. +//! @param optstr string containing the following elements: +//! individual characters, and characters followed by a colon to indicate +//! an option argument is to follow. For example, an option string "x" +//! recognizes an option "-x", and an option string "x:" recognizes an +//! option and argument "-x argument". +//! @param longopts array of Option entries. The last element must be filled +//! with zeroes to indicate end-of-array. +//! @param idx If not NULL, then the integer pointed to it will be set to +//! the index of the long-option relative to <b>longops</b>. +//! +//! @return If the <b>flag</b> field is NULL, <b>val</b> field is returned, +//! which is usually just the corresponding short-option. +//! If <b>flag</b> is not NULL, 0 is returned and <b>val</b> is +//! stored in the location pointed to by <b>flag</b> field. +//! A ':' will be returned if there was a missing option argument. +//! A '?' will be returned if an unknown or ambiguous option was used. +//! A -1 will be returned when the argument list has been exhausted. +//! +/////////////////////////////////////////////////////////////////////////////// +MP4V2_EXPORT +int getOption( int argc, char* const* argv, const char* optstr, const Option* longopts, int* idx ); + +/////////////////////////////////////////////////////////////////////////////// +//! +//! Get option character from command line argument list and allow +//! long-options with single-hyphens. +//! +//! Behaves identically to getOption() with the exception that long-options +//! may start with '-' in addition to '--'. +//! If an option starting with '-' does not match a long option but does match +//! a single-character option, the single-character option is returned. +//! +//! @param argc number of arguments. +//! @param argv argument array of strings. +//! @param optstr string containing the following elements: +//! individual characters, and characters followed by a colon to indicate +//! an option argument is to follow. For example, an option string "x" +//! recognizes an option "-x", and an option string "x:" recognizes an +//! option and argument "-x argument". +//! @param longopts array of Option entries. The last element must be filled +//! with zeroes to indicate end-of-array. +//! @param idx If not NULL, then the integer pointed to it will be set to +//! the index of the long-option relative to <b>longops</b>. +//! +//! @return If the <b>flag</b> field is NULL, <b>val</b> field is returned, +//! which is usually just the corresponding short-option. +//! If <b>flag</b> is not NULL, 0 is returned and <b>val</b> is +//! stored in the location pointed to by <b>flag</b> field. +//! A ':' will be returned if there was a missing option argument. +//! A '?' will be returned if an unknown or ambiguous option was used. +//! A -1 will be returned when the argument list has been exhausted. +//! +/////////////////////////////////////////////////////////////////////////////// +MP4V2_EXPORT +int getOptionSingle( int argc, char* const* argv, const char* optstr, const Option* longopts, int* idx ); + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::prog + +#endif // MP4V2_PLATFORM_PROG_OPTION_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.cpp new file mode 100644 index 00000000..094ace11 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.cpp @@ -0,0 +1,31 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace sys { + +/////////////////////////////////////////////////////////////////////////////// + +const char* +getErrorStr( int errno_ ) +{ + return std::strerror( errno_ ); +} + +/////////////////////////////////////////////////////////////////////////////// + +int +getLastError() +{ + return errno; +} + +/////////////////////////////////////////////////////////////////////////////// + +const char* +getLastErrorStr() +{ + return strerror( errno ); +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::sys diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.h new file mode 100644 index 00000000..87764585 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/sys/error.h @@ -0,0 +1,16 @@ +#ifndef MP4V2_PLATFORM_SYS_ERROR_H +#define MP4V2_PLATFORM_SYS_ERROR_H + +namespace mp4v2 { namespace platform { namespace sys { + +/////////////////////////////////////////////////////////////////////////////// + +MP4V2_EXPORT int getLastError ( ); +MP4V2_EXPORT const char* getLastErrorStr ( ); +MP4V2_EXPORT const char* getErrorStr ( int ); + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::sys + +#endif // MP4V2_PLATFORM_SYS_ERROR_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.cpp new file mode 100644 index 00000000..5fe8867d --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.cpp @@ -0,0 +1,15 @@ +#include "libplatform/impl.h" + +namespace mp4v2 { namespace platform { namespace time { + +/////////////////////////////////////////////////////////////////////////////// + +seconds_t +getLocalTimeSeconds() +{ + return getLocalTimeMilliseconds() / 1000; +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.h new file mode 100644 index 00000000..d4d8e7a8 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time.h @@ -0,0 +1,48 @@ +#ifndef MP4V2_PLATFORM_TIME_TIME_H +#define MP4V2_PLATFORM_TIME_TIME_H + +/// @namespace mp4v2::platform::time (private) Time. +/// <b>WARNING: THIS IS A PRIVATE NAMESPACE. NOT FOR PUBLIC CONSUMPTION.</b> +namespace mp4v2 { namespace platform { namespace time { + +//! type used to represent milliseconds +typedef int64_t milliseconds_t; + +//! type used to represent seconds +typedef int64_t seconds_t; + +/////////////////////////////////////////////////////////////////////////////// +//! +//! Get local-time in milliseconds. +//! +//! getLocalTimeMilliseconds obtains the system's notion of current Greenwich +//! time, adjusted according to the current timezone of the host system. +//! The time is expressed as an absolute value since midnight (0 hour), +//! January 1, 1970. This is commonly referred to as the "epoch". +//! +//! @return local-time in milliseconds elapsed since the epoch. +//! +/////////////////////////////////////////////////////////////////////////////// +MP4V2_EXPORT milliseconds_t getLocalTimeMilliseconds(); + +/////////////////////////////////////////////////////////////////////////////// +//! +//! Get local-time in seconds. +//! +//! getLocalTimeMilliseconds obtains the system's notion of current Greenwich +//! time, adjusted according to the current timezone of the host system. +//! The time is expressed as an absolute value since midnight (0 hour), +//! January 1, 1970. This is commonly referred to as the "epoch". +//! +//! @return local-time in seconds elapsed since the epoch. +//! +/////////////////////////////////////////////////////////////////////////////// +MP4V2_EXPORT seconds_t getLocalTimeSeconds(); + +/////////////////////////////////////////////////////////////////////////////// +//! @} +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time + +#endif // MP4V2_PLATFORM_TIME_TIME_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_posix.cpp new file mode 100644 index 00000000..e3c82f75 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_posix.cpp @@ -0,0 +1,19 @@ +#include "libplatform/impl.h" +#include <sys/time.h> + +namespace mp4v2 { namespace platform { namespace time { + +/////////////////////////////////////////////////////////////////////////////// + +milliseconds_t +getLocalTimeMilliseconds() +{ + timeval buf; + if( gettimeofday( &buf, 0 )) + memset( &buf, 0, sizeof( buf )); + return milliseconds_t( buf.tv_sec ) * 1000 + buf.tv_usec / 1000; +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_win32.cpp new file mode 100644 index 00000000..88a7ea51 --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/time/time_win32.cpp @@ -0,0 +1,18 @@ +#include "libplatform/impl.h" +#include <sys/timeb.h> + +namespace mp4v2 { namespace platform { namespace time { + +/////////////////////////////////////////////////////////////////////////////// + +milliseconds_t +getLocalTimeMilliseconds() +{ + __timeb64 buf; + _ftime64( &buf ); + return milliseconds_t( buf.time ) * 1000 + buf.millitm; +} + +/////////////////////////////////////////////////////////////////////////////// + +}}} // namespace mp4v2::platform::time diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/warning.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/warning.h new file mode 100644 index 00000000..2a236aba --- /dev/null +++ b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/warning.h @@ -0,0 +1,30 @@ +#ifndef MP4V2_PLATFORM_WARNING_H +#define MP4V2_PLATFORM_WARNING_H + +/////////////////////////////////////////////////////////////////////////////// + +// TODO-KB: clean code to avoid disabling warnings + +#if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 2 ) +# pragma GCC diagnostic ignored "-Wwrite-strings" +#elif defined( _MSC_VER ) +# pragma warning( disable: 4244 ) +# pragma warning( disable: 4251 ) +# pragma warning( disable: 4800 ) +# pragma warning( disable: 4996 ) +#endif + +/////////////////////////////////////////////////////////////////////////////// + +// this macro is used to mark printf-style functions for GCC to examine +// the format string and arguments and issue warnings if needed + +#if defined( __GNUC__ ) +# define MP4V2_WFORMAT_PRINTF(i,j) __attribute__((format(__printf__,i,j))) +#else +# define MP4V2_WFORMAT_PRINTF(i,j) +#endif + +/////////////////////////////////////////////////////////////////////////////// + +#endif // MP4V2_PLATFORM_WARNING_H |