diff --git a/.gitignore b/.gitignore index b8b7e7f..b34b1e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,17 @@ -__pycache__ +.idea +.trunk +.vc +.vscode + +*.a +*.o +*.bin +*.pc build +core +core.* cmake-build-* +bufferTest +dictionaryTest +tlvTest diff --git a/Buffer.cc b/Buffer.cc deleted file mode 100644 index 8ed0632..0000000 --- a/Buffer.cc +++ /dev/null @@ -1,180 +0,0 @@ -// -// Created by kyle on 2023-10-09. -// - -#include -#include -#include "Buffer.h" - -namespace kge { - - -constexpr size_t defaultCapacity = 32; -constexpr size_t maxReasonableLine = 8192; - - -static size_t -nearestPower(size_t x) -{ - if (x == 0) { - return 0; - } - - x--; - - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; - x |= x >> 32; - - return x; -} - - -Buffer::Buffer() - : contents(nullptr), length(0), capacity(0) -{ - this->Resize(defaultCapacity); -} - - -Buffer::Buffer(size_t initialCapacity) - : contents(nullptr), length(0), capacity(0) -{ - this->Resize(initialCapacity); -} - - -Buffer::Buffer(const char *data) - : contents(nullptr), length(0), capacity(0) -{ - size_t datalen = strnlen(data, maxReasonableLine); - - this->Append((uint8_t *)data, datalen); -} - - -bool -Buffer::Append(uint8_t *data, size_t datalen) -{ - auto resized = false; - auto newCap = this->mustGrow(datalen); - - if (newCap > 0) { - this->Resize(newCap); - resized = true; - } - - memcpy(this->contents + this->length, data, datalen); - this->length += datalen; - return resized; -} - -bool -Buffer::Append(uint8_t c) -{ - return this->Append(&c, 1); -} - -bool -Buffer::Insert(size_t index, uint8_t *data, size_t datalen) -{ - auto resized = this->shift(index, datalen); - - memcpy(this->contents + index, data, datalen); - return resized; -} - -bool -Buffer::Insert(size_t index, uint8_t c) -{ - return this->Insert(index, &c, 1); -} - - -void -Buffer::Resize(size_t newCapacity) -{ - if (newCapacity < this->length) { - return; - } - - uint8_t *newContents = new uint8_t[newCapacity]; - - if (this->length > 0) { - memcpy(newContents, this->contents, this->length); - } - - if (this->contents != nullptr) { - delete this->contents; - } - - this->contents = newContents; - this->capacity = newCapacity; -} - -size_t -Buffer::Trim() -{ - size_t projectedCapacity = nearestPower(this->length); - - assert(projectedCapacity >= length); - - if (projectedCapacity < this->capacity) { - this->Resize(projectedCapacity); - return this->Capacity(); - } - - return 0; -} - -void -Buffer::Clear() -{ - memset(this->contents, 0, this->length); - this->length = 0; -} - -void -Buffer::Reclaim() -{ - delete this->contents; - this->length = 0; - this->capacity = 0; -} - -size_t -Buffer::mustGrow(size_t delta) -{ - if ((delta + this->length) < this->capacity) { - return 0; - } - - auto newCapacity = delta + this->length; - return nearestPower(newCapacity); -} - - -bool -Buffer::shift(size_t offset, size_t delta) -{ - auto resized = false; - auto newCap = this->mustGrow(delta); - - if (newCap > 0) { - this->Resize(newCap); - resized = true; - } - - - for (size_t i = this->length; i >= offset; i++) { - this->contents[i+delta] = this->contents[i]; - } - - return resized; -} - - -} // kge diff --git a/Buffer.h b/Buffer.h deleted file mode 100644 index f7fd291..0000000 --- a/Buffer.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Created by kyle on 2023-10-09. -// - -#ifndef KGE_BUFFER_H -#define KGE_BUFFER_H - -#include - - -namespace kge { - - -class Buffer { -public: - Buffer(); - Buffer(size_t); - Buffer(const char *); - - uint8_t *Contents() { return this->contents; } - size_t Size() { return this->length; }; - size_t Capacity() { return this->capacity; } - - bool Append(uint8_t *data, size_t datalen); - bool Append(uint8_t c); - bool Insert(size_t index, uint8_t *data, size_t datalen); - bool Insert(size_t index, uint8_t c); - - // bool Remove(size_t index, size_t length); - - /* memory management */ - void Resize(size_t newCapacity); - size_t Trim(); - void Clear(); - void Reclaim(); - -private: - size_t mustGrow(size_t delta); - bool shift(size_t offset, size_t delta); - - uint8_t *contents; - size_t length; - size_t capacity; -}; - -} // kge - -#endif //KGE_BUFFER_H diff --git a/BufferTest.cc b/BufferTest.cc deleted file mode 100644 index 858322b..0000000 --- a/BufferTest.cc +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include "Buffer.h" - - -int -main() -{ - kge::Buffer buffer("hlo, world"); - - std::cout << buffer.Contents() << std::endl; - - buffer.Insert(1, (uint8_t *)"el", 2); - - std::cout << buffer.Contents() << std::endl; -} diff --git a/CMakeLists.txt b/CMakeLists.txt index 49db486..c222238 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.22) project(kge LANGUAGES CXX VERSION 0.0.1) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +string(TIMESTAMP TODAY "%Y%m%d") include(FetchContent) FetchContent_Declare( @@ -70,9 +71,30 @@ add_executable(kge kge.cc ) target_link_libraries(kge imgui ${KLIB_LIBRARIES}) -install(TARGETS kge RUNTIME DESTINATION bin COMPONENT dist) + +add_custom_target(manpages) +configure_file(kge.md kge.1.scdoc @ONLY) +add_custom_command(TARGET manpages COMMAND scdoc < kge.1.scdoc > kge.1 + OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/kge.1) +add_dependencies(kge manpages) + +install(TARGETS kge + DESTINATION bin + COMPONENT dist) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.desktop DESTINATION share/applications COMPONENT dist) +install(FILES kge.png + DESTINATION share/${PROJECT_NAME} + COMPONENT dist) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.1 + DESTINATION share/man/man1 + COMPONENT dist) include(CMakePack.txt) + + get_cmake_property(_variableNames VARIABLES) + list (SORT _variableNames) + foreach (_variableName ${_variableNames}) + message(STATUS "${_variableName}=${${_variableName}}") + endforeach() \ No newline at end of file diff --git a/CMakePack.txt b/CMakePack.txt index 72c01e1..de33d49 100644 --- a/CMakePack.txt +++ b/CMakePack.txt @@ -18,11 +18,12 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS set(CPACK_DEBIAN_PACKAGE_SECTION universe/editors) set(CPACK_DEB_COMPONENT_INSTALL ON) set(CPACK_COMPONENTS_ALL dist) +set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) if(LINUX) set(CPACK_GENERATOR "DEB;STGZ;TGZ") elseif(APPLE) - set(CPACK_GENERATOR "productbuild") + set(CPACK_GENERATOR "productbuild;TGZ") elseif(MSVC OR MSYS OR MINGW) set(CPACK_GENERATOR "NSIS;ZIP") else() @@ -32,6 +33,7 @@ endif() set(CPACK_SOURCE_GENERATOR "TGZ;ZIP") set(CPACK_SOURCE_IGNORE_FILES /.git + /.idea /dist /.*build.*) diff --git a/kge.desktop.in b/kge.desktop.in index e2bb20b..89c798c 100644 --- a/kge.desktop.in +++ b/kge.desktop.in @@ -4,6 +4,6 @@ Version=@PROJECT_VERSION@ Name=@PROJECT_NAME@ Comment=@PROJECT_DESCRIPTION@ Exec=kge -Icon= +Icon=@prefix@/share/@PROJECT_NAME@/@PROJECT_NAME@.png Terminal=false Categories=Editors \ No newline at end of file diff --git a/kge.md b/kge.md new file mode 100644 index 0000000..9640474 --- /dev/null +++ b/kge.md @@ -0,0 +1,14 @@ +kge(1) ["@TODAY@" ["Shimmering Clarity Industries"]] + +# NAME + +kge - kyle's graphical editor + +# SYNOPSIS + +kge files... + +# AUTHORS + +Written by Kyle Isom . Up-to-date sources can be found +at https://git.wntrmute.dev/kyle/kge. \ No newline at end of file diff --git a/kge.png b/kge.png new file mode 100644 index 0000000..571af08 Binary files /dev/null and b/kge.png differ