Commits

Anonymous committed b124f91

Removed zip stuff, will do that later, not so important for the time
being. Added support for filesizes on ntpath.

  • Participants
  • Parent commits 41fcc26

Comments (0)

Files changed (13)

neglect/CMakeLists.txt

 	${ZLIB_INCLUDE_DIR}
 )
 
-add_subdirectory(clib)
 add_subdirectory(cpplib)
 add_subdirectory(tests)

neglect/clib/CMakeLists.txt

-set(SOURCES
-    src/platform.cpp
-)
-set(HEADERS
-	include/neglect/platform.h
-	include/neglect/vector.h
-	
-	../cpplib/include/neglect/boot.h
-)
-
-include_directories(
-	${CMAKE_CURRENT_SOURCE_DIR}/include
-	${CMAKE_CURRENT_SOURCE_DIR}/../cpplib/include
-)
-link_directories(
-    ${CMAKE_CURRENT_SOURCE_DIR}/../cpplib
-)
-
-add_library(cneglect STATIC ${SOURCES} ${HEADERS})
-target_link_libraries(cneglect neglect)

neglect/clib/include/neglect/platform.h

-/* platform independence utilities */
-#ifndef _INC_NEGLECT_PLATFORM_H_
-#define _INC_NEGLECT_PLATFORM_H_
-
-#include <neglect/boot.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-    /* returns the platform name */
-    extern const char *neglect_platform_get_name();
-
-    /* returns the user's home folder */
-    extern const char *neglect_platform_get_home_folder();
-
-    /* returns the settings folder for the given application name.  The
-       return value is a newly heap allocated string that has to be
-       freed with free() */
-    extern char *neglect_platform_get_settings_folder(const char *appname);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

neglect/clib/include/neglect/vector.h

-#ifndef _INC_NEGLECT_VECTOR_H_
-#define _INC_NEGLECT_VECTOR_H_
-
-#include <neglect/boot.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-    /* important: keep those byte compatible with the float vectors
-       of the same size from the vectors.hpp file.
-       
-       note: the c header does not define any vector operations.
-       currently these have to be provided by extern libraries, we
-       only support those for CPP. Maybe they could be wrapped but
-       I am not sure what would be the best way to do that. */
-
-    typedef struct neglect_vec2_ {
-        union {
-            struct { float x, y };
-            struct { float s, t };
-        };
-    } neglect_vec2;
-
-    typedef struct neglect_vec3_ {
-        union {
-            struct { float x, y, z };
-            struct { float r, g, b };
-            struct { float s, t, p };
-        };
-    } neglect_vec3;
-
-    typedef struct neglect_vec4_ {
-        union {
-            struct { float x, y, z, w };
-            struct { float r, g, b, a };
-            struct { float s, t, p, q };
-        };
-    } neglect_vec4;
-
-
-    typedef struct neglect_veci2_ {
-        union {
-            struct { int x, y };
-            struct { int s, t };
-        };
-    } neglect_veci2;
-
-    typedef struct neglect_veci3_ {
-        union {
-            struct { int x, y, z };
-            struct { int r, g, b };
-            struct { int s, t, p };
-        };
-    } neglect_veci3;
-
-    typedef struct neglect_veci4_ {
-        union {
-            struct { int x, y, z, w };
-            struct { int r, g, b, a };
-            struct { int s, t, p, q };
-        };
-    } neglect_veci4;
-
-#ifdef NEGLECT_SHORTCUTS
-    typedef neglect_vec2 vec2;
-    typedef neglect_vec3 vec3;
-    typedef neglect_vec4 vec4;
-    typedef neglect_veci2 veci2;
-    typedef neglect_veci3 veci3;
-    typedef neglect_veci4 veci4;
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

neglect/clib/src/platform.cpp

-#include <neglect/platform.h>
-#include <neglect/platform.hpp>
-
-using namespace neglect;
-
-extern "C" {
-
-    extern const char *neglect_platform_get_name()
-    {
-        return platform::name.c_str();
-    }
-
-    extern const char *neglect_platform_get_home_folder()
-    {
-        return platform::get_home_folder().c_str();
-    }
-
-    extern char *neglect_platform_get_settings_folder(const char *appname)
-    {
-        string rv = platform::get_settings_folder(string(appname));
-        char *buf = (char *)malloc(rv.size());
-        if (!buf)
-            return 0;
-        memcpy(buf, rv.c_str(), rv.size() + 1);
-        return buf;
-    }
-}

neglect/cpplib/CMakeLists.txt

 	include/neglect/unittest.hpp
 	include/neglect/path.hpp
 	include/neglect/ntpath.hpp
-	include/neglect/zip_archive.hpp
 	
 	include/neglect/boot.h
 )

neglect/cpplib/include/neglect/boot.hpp

 #include <memory>
 #include <ctime>
 #include <cassert>
+#include <cstdio>
 #include <cmath>
 
 // boost tr1 includes we need.  This is pretty much a noop for systems
 
 #include <boost/shared_array.hpp>
 #include <boost/noncopyable.hpp>
+#include <boost/cstdint.hpp>
 
 namespace neglect {
     // the types we use.  This is typedefed in case anyone wants to

neglect/cpplib/include/neglect/ntpath.hpp

 
 namespace neglect { namespace ntpath {
 
+    /* the kind of integer used for filesizes on this platform */
+    typedef boost::int64_t filesize_t;
+
     /* checks if a path is absolute */
     bool is_abs(const neglect::string &filename);
 
        existed already. */
     bool rename(const neglect::string &filename,
                 const neglect::string &new_name);
+
+    /* return the file size of a file */
+    filesize_t filesize(const neglect::string &filename);
 #endif
 }}
 

neglect/cpplib/include/neglect/zip_archive.hpp

-/* defines an interface for zip archives */
-#ifndef _INC_NEGLECT_ZIP_ARCHIVE_HPP_
-#define _INC_NEGLECT_ZIP_ARCHIVE_HPP_
-
-#include <neglect/boot.hpp>
-
-namespace neglect {
-
-    class zip_archive;
-
-    class zip_info {
-    public:
-        const neglect::string &filename() const { return m_filename; }
-        size_t uncompressed_size() const { return m_uncompressed_size; }
-        size_t compressed_size() const { return m_compressed_size; }
-        bool exists() const;
-        bool is_file() const;
-        bool is_dir() const;
-
-        const zip_archive &archive() const { return m_archive; }
-        zip_archive &archive() { return m_archive; }
-
-    private:
-        zip_archive &m_archive;
-        neglect::string m_filename;
-        size_t m_uncompressed_size;
-        size_t m_compressed_size;
-
-        friend class zip_archive;
-    };
-
-    class zip_istream : public std::istream {
-    public:
-        zip_istream(const zip_info &info);
-    };
-
-    class zip_ostream : public std::ostream {
-    public:
-        zip_ostream(zip_info &info);
-    };
-
-    class zip_archive : public boost::noncopyable {
-    public:
-        zip_archive(const neglect::string &filename);
-        ~zip_archive();
-
-        /* creates a new zip archive on the file system.  If there was a file
-           with the same name already it will be overwritten. */
-        bool create();
-
-        /* opens a zip file for reading or reading and writing. */
-        bool open(bool read_only=true);
-
-        /* closes a zip file.  This automatically happens in the destructor as
-           well so you don't have to call it. */
-        void close();
-
-        /* returns the info for a file.  If that file does not exist so far in
-           the archive, the exists flag is set to false. */
-        zip_info get_info(const neglect::string &filename) const;
-
-        bool is_open() const { return m_flags.is_open; }
-        bool can_read() const { return m_flags.can_read; }
-        bool can_write() const { return m_flags.can_write; }
-        bool is_modified() const { return m_flags.is_modified; }
-
-    private:
-        neglect::string m_filename;
-        struct {
-            bool is_open;
-            bool can_read;
-            bool can_write;
-            bool is_modified;
-        } m_flags;
-        std::iostream *m_stream;
-    };
-};
-
-#endif

neglect/cpplib/src/ntpath.cpp

                          MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
 }
 
+ntpath::filesize_t ntpath::filesize(const neglect::string &filename)
+{
+    struct _stat64 buf;
+    neglect::string path = ntpath::abspath(filename);
+    int rv = _stat64(path.c_str(), &buf);
+    if (rv != 0)
+        return 0;
+    return buf.st_size;
+}
+
 #endif

neglect/cpplib/src/zip_archive.cpp

-#include <neglect/zip_archive.hpp>
-
-#include <fstream>
-
-#include <zlib.h>
-
-using namespace neglect;
-
-zip_archive::zip_archive(const neglect::string &filename)
-: m_filename(filename)
-{
-    m_flags.is_open = false;
-    m_flags.can_read = false;
-    m_flags.can_write = false;
-    m_flags.is_modified = false;
-}
-
-zip_archive::~zip_archive()
-{
-    close();
-}
-
-void zip_archive::close()
-{
-    if (!is_open())
-        return;
-
-    if (m_stream)
-        delete m_stream;
-}
-
-bool zip_archive::create()
-{
-    assert(!m_flags.is_open);
-
-    m_stream = new std::fstream(m_filename.c_str(),
-        std::fstream::in | std::fstream::out);
-
-    if (m_stream->good()) {
-        m_flags.can_read = true;
-        m_flags.can_write = true;
-        m_flags.is_open = true;
-        m_flags.is_modified = true;
-        return true;
-    }
-
-    delete m_stream;
-    m_stream = 0;
-    return false;
-}
-
-bool zip_archive::open(bool read_only)
-{
-    assert(!m_flags.is_open);
-
-    int flags = std::fstream::in;
-    if (!read_only)
-        flags |= std::fstream::out;
-
-    m_stream = new std::fstream(m_filename.c_str(), flags);
-
-    if (m_stream->good()) {
-        m_flags.can_read = true;
-        m_flags.can_write = !read_only;
-        m_flags.is_open = true;
-        m_flags.is_modified = true;
-        return true;
-    }
-
-    delete m_stream;
-    m_stream = 0;
-    return false;
-}

neglect/tests/CMakeLists.txt

 set(SOURCES
     src/main.cpp
-    src/test_zip_archive.cpp
     src/test_vectors.cpp
     src/test_format.cpp
     src/test_path.cpp

neglect/tests/src/test_zip_archive.cpp

-#include <neglect/unittest.hpp>
-#include <neglect/zip_archive.hpp>
-
-
-using namespace neglect;
-
-#if 0
-
-NUT_TESTGROUP(zip_archive) {
-
-    NUT_TESTCASE(basic)
-    {
-        // open archive
-        zip_archive zip("test.zip");
-        NUT_REQUIRE(zip.good());
-
-        // get the information from the README.txt file
-        zip_info info = zip.get_info("README.txt");
-        NUT_REQUIRE(info.exists());
-        NUT_CHECK(info.is_file());
-        NUT_CHECK_EQUAL(info.filename(), "README.txt");
-
-        // open the input stream for the readme file and
-        // read the first line.
-        zip_istream stream(info);
-        neglect::string line;
-        std::getline(stream, line);
-        NUT_CHECK_EQUAL(line, "The Readme File");
-    }
-}
-
-#endif