Merge branch 'release-0.0'
This commit is contained in:
@@ -2,8 +2,10 @@ if("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
|||||||
set(Ox_INCLUDE_DIRS /usr/local/include/)
|
set(Ox_INCLUDE_DIRS /usr/local/include/)
|
||||||
set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a)
|
set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a)
|
||||||
set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a)
|
set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a)
|
||||||
|
set(OxClArgs_LIBRARY /usr/local/lib/ox/libOxClArgs.a)
|
||||||
else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
||||||
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
|
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
|
||||||
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
|
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
|
||||||
set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a)
|
set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a)
|
||||||
|
set(OxClArgs_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxClArgs.a)
|
||||||
endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
||||||
|
|||||||
@@ -6,25 +6,50 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ox/std/strops.hpp>
|
||||||
#include "clargs.hpp"
|
#include "clargs.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
namespace clargs {
|
namespace clargs {
|
||||||
|
|
||||||
|
using ::std::string;
|
||||||
|
using namespace ::std;
|
||||||
|
|
||||||
ClArgs::ClArgs(int argc, const char **args) {
|
ClArgs::ClArgs(int argc, const char **args) {
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
std::string arg = args[i];
|
string arg = args[i];
|
||||||
if (arg[0] == '-') {
|
if (arg[0] == '-') {
|
||||||
while (arg[0] == '-' && arg.size()) {
|
while (arg[0] == '-' && arg.size()) {
|
||||||
arg = arg.substr(1);
|
arg = arg.substr(1);
|
||||||
}
|
}
|
||||||
m_args[arg] = true;
|
m_bools[arg.c_str()] = true;
|
||||||
|
|
||||||
|
// parse additional arguments
|
||||||
|
if (i < argc) {
|
||||||
|
string val = args[i + 1];
|
||||||
|
if (val[i] != '-') {
|
||||||
|
if (val == "false") {
|
||||||
|
m_bools[arg.c_str()] = false;
|
||||||
|
}
|
||||||
|
m_strings[arg.c_str()] = val.c_str();
|
||||||
|
m_ints[arg.c_str()] = ox_atoi(val.c_str());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClArgs::operator[](std::string arg) {
|
bool ClArgs::getBool(const char *arg) {
|
||||||
return m_args[arg];
|
return m_bools[arg];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ClArgs::getString(const char *arg) {
|
||||||
|
return m_strings[arg];
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClArgs::getInt(const char *arg) {
|
||||||
|
return m_ints[arg];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,18 @@ namespace clargs {
|
|||||||
|
|
||||||
class ClArgs {
|
class ClArgs {
|
||||||
private:
|
private:
|
||||||
::std::map<::std::string, bool> m_args;
|
::std::map<::std::string, bool> m_bools;
|
||||||
|
::std::map<::std::string, const char*> m_strings;
|
||||||
|
::std::map<::std::string, int> m_ints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClArgs(int argc, const char **args);
|
ClArgs(int argc, const char **args);
|
||||||
|
|
||||||
bool operator[](::std::string arg);
|
bool getBool(const char *arg);
|
||||||
|
|
||||||
|
const char *getString(const char *arg);
|
||||||
|
|
||||||
|
int getInt(const char *arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
#include "filesystem.hpp"
|
#include "filesystem.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
@@ -41,5 +42,34 @@ FileSystem *createFileSystem(void *buff, size_t buffSize) {
|
|||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileSystem *expandCopy(FileSystem *fs, size_t size) {
|
||||||
|
auto fsBuff = fs->buff();
|
||||||
|
FileSystem *retval = nullptr;
|
||||||
|
|
||||||
|
if (fs->size() <= size) {
|
||||||
|
auto cloneBuff = new uint8_t[size];
|
||||||
|
ox_memcpy(cloneBuff, fsBuff, fs->size());
|
||||||
|
|
||||||
|
fsBuff = cloneBuff;
|
||||||
|
retval = createFileSystem(fsBuff, size);
|
||||||
|
retval->resize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystem *expandCopyCleanup(FileSystem *fs, size_t size) {
|
||||||
|
auto out = expandCopy(fs, size);
|
||||||
|
|
||||||
|
if (out) {
|
||||||
|
delete fs->buff();
|
||||||
|
delete fs;
|
||||||
|
} else {
|
||||||
|
out = fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,23 @@ class FileSystem {
|
|||||||
virtual uint64_t available() = 0;
|
virtual uint64_t available() = 0;
|
||||||
|
|
||||||
virtual uint64_t size() = 0;
|
virtual uint64_t size() = 0;
|
||||||
|
|
||||||
|
virtual uint8_t *buff() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
FileSystem *createFileSystem(void *buff, size_t buffSize);
|
FileSystem *createFileSystem(void *buff, size_t buffSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a larger version of the given FileSystem.
|
||||||
|
*/
|
||||||
|
FileSystem *expandCopy(FileSystem *src);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls expandCopy and deletes the original FileSystem and buff a resize was
|
||||||
|
* performed.
|
||||||
|
*/
|
||||||
|
FileSystem *expandCopyCleanup(FileSystem *fs, size_t size);
|
||||||
|
|
||||||
template<typename FileStore, FsType FS_TYPE>
|
template<typename FileStore, FsType FS_TYPE>
|
||||||
class FileSystemTemplate: public FileSystem {
|
class FileSystemTemplate: public FileSystem {
|
||||||
|
|
||||||
@@ -117,6 +130,8 @@ class FileSystemTemplate: public FileSystem {
|
|||||||
|
|
||||||
uint64_t size() override;
|
uint64_t size() override;
|
||||||
|
|
||||||
|
uint8_t *buff() override;
|
||||||
|
|
||||||
static uint8_t *format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories);
|
static uint8_t *format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -233,6 +248,11 @@ uint64_t FileSystemTemplate<FileStore, FS_TYPE>::size() {
|
|||||||
return store->size();
|
return store->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FileStore, FsType FS_TYPE>
|
||||||
|
uint8_t *FileSystemTemplate<FileStore, FS_TYPE>::buff() {
|
||||||
|
return (uint8_t*) store;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable:4244)
|
#pragma warning(disable:4244)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-16
@@ -35,7 +35,7 @@ char *loadFileBuff(FILE *file, ::size_t *sizeOut = nullptr) {
|
|||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
const auto size = ftell(file);
|
const auto size = ftell(file);
|
||||||
rewind(file);
|
rewind(file);
|
||||||
auto buff = (char*) malloc(size);
|
auto buff = new char[size];
|
||||||
auto itemsRead = fread(buff, size, 1, file);
|
auto itemsRead = fread(buff, size, 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (sizeOut) {
|
if (sizeOut) {
|
||||||
@@ -87,7 +87,7 @@ int format(int argc, char **args) {
|
|||||||
auto type = ox_atoi(args[2]);
|
auto type = ox_atoi(args[2]);
|
||||||
auto size = bytes(args[3]);
|
auto size = bytes(args[3]);
|
||||||
auto path = args[4];
|
auto path = args[4];
|
||||||
auto buff = (uint8_t*) malloc(size);
|
auto buff = new uint8_t[size];
|
||||||
|
|
||||||
|
|
||||||
if (size < sizeof(FileStore64)) {
|
if (size < sizeof(FileStore64)) {
|
||||||
@@ -125,7 +125,7 @@ int format(int argc, char **args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buff);
|
delete []buff;
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
fprintf(stderr, "Created file system %s\n", path);
|
fprintf(stderr, "Created file system %s\n", path);
|
||||||
@@ -160,7 +160,7 @@ int read(int argc, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fs;
|
delete fs;
|
||||||
free(fsBuff);
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff);
|
fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff);
|
||||||
}
|
}
|
||||||
@@ -199,16 +199,8 @@ int write(int argc, char **args, bool expand) {
|
|||||||
if (fs) {
|
if (fs) {
|
||||||
if (expand && fs->available() <= srcSize) {
|
if (expand && fs->available() <= srcSize) {
|
||||||
auto needed = fs->size() + fs->spaceNeeded(inode, srcSize);
|
auto needed = fs->size() + fs->spaceNeeded(inode, srcSize);
|
||||||
auto cloneBuff = new uint8_t[needed];
|
|
||||||
ox_memcpy(cloneBuff, fsBuff, fsSize);
|
|
||||||
|
|
||||||
delete fs;
|
|
||||||
delete []fsBuff;
|
|
||||||
|
|
||||||
fsBuff = cloneBuff;
|
|
||||||
fs = createFileSystem(fsBuff, fsSize);
|
|
||||||
fsSize = needed;
|
fsSize = needed;
|
||||||
fs->resize(fsSize);
|
fs = expandCopyCleanup(fs, needed);
|
||||||
}
|
}
|
||||||
err |= fs->write(inode, srcBuff, srcSize);
|
err |= fs->write(inode, srcBuff, srcSize);
|
||||||
|
|
||||||
@@ -239,7 +231,7 @@ int write(int argc, char **args, bool expand) {
|
|||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(srcBuff);
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
err = 1;
|
err = 1;
|
||||||
fprintf(stderr, "Could not load source file: %s.\n", srcPath);
|
fprintf(stderr, "Could not load source file: %s.\n", srcPath);
|
||||||
@@ -285,7 +277,7 @@ int compact(int argc, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fs;
|
delete fs;
|
||||||
free(fsBuff);
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
||||||
}
|
}
|
||||||
@@ -328,7 +320,7 @@ int remove(int argc, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete fs;
|
delete fs;
|
||||||
free(fsBuff);
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user