Отвязка от репозитория TOS Lib
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -2,3 +2,11 @@
|
||||
/.vscode
|
||||
/build
|
||||
|
||||
/CMakeFiles
|
||||
/CMakeCache.txt
|
||||
/AlterLuanti
|
||||
/Makefile
|
||||
/assets.o
|
||||
/cmake_install.cmake
|
||||
/libassets.a
|
||||
/resources.cpp
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../TOS/TOS Lib/
|
||||
9
Libs/TOS Lib/.gitignore
vendored
Normal file
9
Libs/TOS Lib/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/build/
|
||||
/.cache/
|
||||
/.vscode/
|
||||
|
||||
/CMakeFiles
|
||||
/libTOS_Lib.a
|
||||
/cmake_install.cmake
|
||||
/Makefile
|
||||
/libTOS_Lib.a
|
||||
35
Libs/TOS Lib/CMakeLists.txt
Normal file
35
Libs/TOS Lib/CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
|
||||
project (TOS_Lib
|
||||
VERSION 1.0
|
||||
DESCRIPTION "TOS Lib")
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC)
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
|
||||
|
||||
if(POLICY CMP0167)
|
||||
cmake_policy(SET CMP0167 NEW)
|
||||
endif()
|
||||
|
||||
find_package(ICU REQUIRED COMPONENTS i18n uc)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ICU_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${ICU_LIBRARIES})
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENSSL_LIBRARIES})
|
||||
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
find_package(Boost REQUIRED COMPONENTS timer)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES})
|
||||
|
||||
|
||||
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Src/*.cpp")
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Src)
|
||||
|
||||
42
Libs/TOS Lib/Libs/Headers/ft2build.h
Normal file
42
Libs/TOS Lib/Libs/Headers/ft2build.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ft2build.h
|
||||
*
|
||||
* FreeType 2 build and setup macros.
|
||||
*
|
||||
* Copyright (C) 1996-2022 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This is the 'entry point' for FreeType header file inclusions, to be
|
||||
* loaded before all other header files.
|
||||
*
|
||||
* A typical example is
|
||||
*
|
||||
* ```
|
||||
* #include <ft2build.h>
|
||||
* #include <freetype/freetype.h>
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FT2BUILD_H_
|
||||
#define FT2BUILD_H_
|
||||
|
||||
#include <freetype/config/ftheader.h>
|
||||
|
||||
#endif /* FT2BUILD_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
627
Libs/TOS Lib/Libs/Headers/imstb_rectpack.h
Normal file
627
Libs/TOS Lib/Libs/Headers/imstb_rectpack.h
Normal file
@@ -0,0 +1,627 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
1437
Libs/TOS Lib/Libs/Headers/imstb_textedit.h
Normal file
1437
Libs/TOS Lib/Libs/Headers/imstb_textedit.h
Normal file
File diff suppressed because it is too large
Load Diff
5085
Libs/TOS Lib/Libs/Headers/imstb_truetype.h
Normal file
5085
Libs/TOS Lib/Libs/Headers/imstb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
484
Libs/TOS Lib/Libs/Headers/zip.h
Normal file
484
Libs/TOS Lib/Libs/Headers/zip.h
Normal file
@@ -0,0 +1,484 @@
|
||||
#ifndef _HAD_ZIP_H
|
||||
#define _HAD_ZIP_H
|
||||
|
||||
/*
|
||||
zip.h -- exported declarations.
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
|
||||
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. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* fix autoindent */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <zipconf.h>
|
||||
|
||||
#ifndef ZIP_EXTERN
|
||||
#ifndef ZIP_STATIC
|
||||
#ifdef _WIN32
|
||||
#define ZIP_EXTERN __declspec(dllimport)
|
||||
#elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define ZIP_EXTERN __attribute__((visibility("default")))
|
||||
#else
|
||||
#define ZIP_EXTERN
|
||||
#endif
|
||||
#else
|
||||
#define ZIP_EXTERN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
/* flags for zip_open */
|
||||
|
||||
#define ZIP_CREATE 1
|
||||
#define ZIP_EXCL 2
|
||||
#define ZIP_CHECKCONS 4
|
||||
#define ZIP_TRUNCATE 8
|
||||
#define ZIP_RDONLY 16
|
||||
|
||||
|
||||
/* flags for zip_name_locate, zip_fopen, zip_stat, ... */
|
||||
|
||||
#define ZIP_FL_NOCASE 1u /* ignore case on name lookup */
|
||||
#define ZIP_FL_NODIR 2u /* ignore directory component */
|
||||
#define ZIP_FL_COMPRESSED 4u /* read compressed data */
|
||||
#define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */
|
||||
#define ZIP_FL_RECOMPRESS 16u /* force recompression of data */
|
||||
#define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */
|
||||
#define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */
|
||||
#define ZIP_FL_ENC_RAW 64u /* get unmodified string */
|
||||
#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
|
||||
#define ZIP_FL_LOCAL 256u /* in local header */
|
||||
#define ZIP_FL_CENTRAL 512u /* in central directory */
|
||||
/* 1024u reserved for internal use */
|
||||
#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
|
||||
#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
|
||||
#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
|
||||
|
||||
/* archive global flags flags */
|
||||
|
||||
#define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */
|
||||
|
||||
|
||||
/* create a new extra field */
|
||||
|
||||
#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
|
||||
#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
|
||||
|
||||
|
||||
/* libzip error codes */
|
||||
|
||||
#define ZIP_ER_OK 0 /* N No error */
|
||||
#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
|
||||
#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
|
||||
#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
|
||||
#define ZIP_ER_SEEK 4 /* S Seek error */
|
||||
#define ZIP_ER_READ 5 /* S Read error */
|
||||
#define ZIP_ER_WRITE 6 /* S Write error */
|
||||
#define ZIP_ER_CRC 7 /* N CRC error */
|
||||
#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
|
||||
#define ZIP_ER_NOENT 9 /* N No such file */
|
||||
#define ZIP_ER_EXISTS 10 /* N File already exists */
|
||||
#define ZIP_ER_OPEN 11 /* S Can't open file */
|
||||
#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
|
||||
#define ZIP_ER_ZLIB 13 /* Z Zlib error */
|
||||
#define ZIP_ER_MEMORY 14 /* N Malloc failure */
|
||||
#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
|
||||
#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
|
||||
#define ZIP_ER_EOF 17 /* N Premature end of file */
|
||||
#define ZIP_ER_INVAL 18 /* N Invalid argument */
|
||||
#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
|
||||
#define ZIP_ER_INTERNAL 20 /* N Internal error */
|
||||
#define ZIP_ER_INCONS 21 /* L Zip archive inconsistent */
|
||||
#define ZIP_ER_REMOVE 22 /* S Can't remove file */
|
||||
#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
|
||||
#define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */
|
||||
#define ZIP_ER_RDONLY 25 /* N Read-only archive */
|
||||
#define ZIP_ER_NOPASSWD 26 /* N No password provided */
|
||||
#define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */
|
||||
#define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */
|
||||
#define ZIP_ER_INUSE 29 /* N Resource still in use */
|
||||
#define ZIP_ER_TELL 30 /* S Tell error */
|
||||
#define ZIP_ER_COMPRESSED_DATA 31 /* N Compressed data invalid */
|
||||
#define ZIP_ER_CANCELLED 32 /* N Operation cancelled */
|
||||
|
||||
/* type of system error value */
|
||||
|
||||
#define ZIP_ET_NONE 0 /* sys_err unused */
|
||||
#define ZIP_ET_SYS 1 /* sys_err is errno */
|
||||
#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
|
||||
#define ZIP_ET_LIBZIP 3 /* sys_err is libzip error code */
|
||||
|
||||
/* compression methods */
|
||||
|
||||
#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
|
||||
#define ZIP_CM_STORE 0 /* stored (uncompressed) */
|
||||
#define ZIP_CM_SHRINK 1 /* shrunk */
|
||||
#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
|
||||
#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
|
||||
#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
|
||||
#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
|
||||
#define ZIP_CM_IMPLODE 6 /* imploded */
|
||||
/* 7 - Reserved for Tokenizing compression algorithm */
|
||||
#define ZIP_CM_DEFLATE 8 /* deflated */
|
||||
#define ZIP_CM_DEFLATE64 9 /* deflate64 */
|
||||
#define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
|
||||
/* 11 - Reserved by PKWARE */
|
||||
#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
|
||||
/* 13 - Reserved by PKWARE */
|
||||
#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
|
||||
/* 15-17 - Reserved by PKWARE */
|
||||
#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
|
||||
#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
|
||||
/* 20 - old value for Zstandard */
|
||||
#define ZIP_CM_LZMA2 33
|
||||
#define ZIP_CM_ZSTD 93 /* Zstandard compressed data */
|
||||
#define ZIP_CM_XZ 95 /* XZ compressed data */
|
||||
#define ZIP_CM_JPEG 96 /* Compressed Jpeg data */
|
||||
#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
|
||||
#define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */
|
||||
|
||||
/* encryption methods */
|
||||
|
||||
#define ZIP_EM_NONE 0 /* not encrypted */
|
||||
#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
|
||||
#if 0 /* Strong Encryption Header not parsed yet */
|
||||
#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
|
||||
#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
|
||||
#define ZIP_EM_3DES_168 0x6603
|
||||
#define ZIP_EM_3DES_112 0x6609
|
||||
#define ZIP_EM_PKZIP_AES_128 0x660e
|
||||
#define ZIP_EM_PKZIP_AES_192 0x660f
|
||||
#define ZIP_EM_PKZIP_AES_256 0x6610
|
||||
#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
|
||||
#define ZIP_EM_RC4 0x6801
|
||||
#endif
|
||||
#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
|
||||
#define ZIP_EM_AES_192 0x0102
|
||||
#define ZIP_EM_AES_256 0x0103
|
||||
#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
|
||||
|
||||
#define ZIP_OPSYS_DOS 0x00u
|
||||
#define ZIP_OPSYS_AMIGA 0x01u
|
||||
#define ZIP_OPSYS_OPENVMS 0x02u
|
||||
#define ZIP_OPSYS_UNIX 0x03u
|
||||
#define ZIP_OPSYS_VM_CMS 0x04u
|
||||
#define ZIP_OPSYS_ATARI_ST 0x05u
|
||||
#define ZIP_OPSYS_OS_2 0x06u
|
||||
#define ZIP_OPSYS_MACINTOSH 0x07u
|
||||
#define ZIP_OPSYS_Z_SYSTEM 0x08u
|
||||
#define ZIP_OPSYS_CPM 0x09u
|
||||
#define ZIP_OPSYS_WINDOWS_NTFS 0x0au
|
||||
#define ZIP_OPSYS_MVS 0x0bu
|
||||
#define ZIP_OPSYS_VSE 0x0cu
|
||||
#define ZIP_OPSYS_ACORN_RISC 0x0du
|
||||
#define ZIP_OPSYS_VFAT 0x0eu
|
||||
#define ZIP_OPSYS_ALTERNATE_MVS 0x0fu
|
||||
#define ZIP_OPSYS_BEOS 0x10u
|
||||
#define ZIP_OPSYS_TANDEM 0x11u
|
||||
#define ZIP_OPSYS_OS_400 0x12u
|
||||
#define ZIP_OPSYS_OS_X 0x13u
|
||||
|
||||
#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
|
||||
|
||||
|
||||
enum zip_source_cmd {
|
||||
ZIP_SOURCE_OPEN, /* prepare for reading */
|
||||
ZIP_SOURCE_READ, /* read data */
|
||||
ZIP_SOURCE_CLOSE, /* reading is done */
|
||||
ZIP_SOURCE_STAT, /* get meta information */
|
||||
ZIP_SOURCE_ERROR, /* get error information */
|
||||
ZIP_SOURCE_FREE, /* cleanup and free resources */
|
||||
ZIP_SOURCE_SEEK, /* set position for reading */
|
||||
ZIP_SOURCE_TELL, /* get read position */
|
||||
ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */
|
||||
ZIP_SOURCE_COMMIT_WRITE, /* writing is done */
|
||||
ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */
|
||||
ZIP_SOURCE_WRITE, /* write data */
|
||||
ZIP_SOURCE_SEEK_WRITE, /* set position for writing */
|
||||
ZIP_SOURCE_TELL_WRITE, /* get write position */
|
||||
ZIP_SOURCE_SUPPORTS, /* check whether source supports command */
|
||||
ZIP_SOURCE_REMOVE, /* remove file */
|
||||
ZIP_SOURCE_RESERVED_1, /* previously used internally */
|
||||
ZIP_SOURCE_BEGIN_WRITE_CLONING, /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
|
||||
ZIP_SOURCE_ACCEPT_EMPTY, /* whether empty files are valid archives */
|
||||
ZIP_SOURCE_GET_FILE_ATTRIBUTES /* get additional file attributes */
|
||||
};
|
||||
typedef enum zip_source_cmd zip_source_cmd_t;
|
||||
|
||||
#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_READABLE (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_SEEKABLE (ZIP_SOURCE_SUPPORTS_READABLE \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_WRITABLE (ZIP_SOURCE_SUPPORTS_SEEKABLE \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
/* for use by sources */
|
||||
struct zip_source_args_seek {
|
||||
zip_int64_t offset;
|
||||
int whence;
|
||||
};
|
||||
|
||||
typedef struct zip_source_args_seek zip_source_args_seek_t;
|
||||
#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
|
||||
|
||||
|
||||
/* error information */
|
||||
/* use zip_error_*() to access */
|
||||
struct zip_error {
|
||||
int zip_err; /* libzip error code (ZIP_ER_*) */
|
||||
int sys_err; /* copy of errno (E*) or zlib error code */
|
||||
char *_Nullable str; /* string representation or NULL */
|
||||
};
|
||||
|
||||
#define ZIP_STAT_NAME 0x0001u
|
||||
#define ZIP_STAT_INDEX 0x0002u
|
||||
#define ZIP_STAT_SIZE 0x0004u
|
||||
#define ZIP_STAT_COMP_SIZE 0x0008u
|
||||
#define ZIP_STAT_MTIME 0x0010u
|
||||
#define ZIP_STAT_CRC 0x0020u
|
||||
#define ZIP_STAT_COMP_METHOD 0x0040u
|
||||
#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
|
||||
#define ZIP_STAT_FLAGS 0x0100u
|
||||
|
||||
struct zip_stat {
|
||||
zip_uint64_t valid; /* which fields have valid values */
|
||||
const char *_Nullable name; /* name of the file */
|
||||
zip_uint64_t index; /* index within archive */
|
||||
zip_uint64_t size; /* size of file (uncompressed) */
|
||||
zip_uint64_t comp_size; /* size of file (compressed) */
|
||||
time_t mtime; /* modification time */
|
||||
zip_uint32_t crc; /* crc of file data */
|
||||
zip_uint16_t comp_method; /* compression method used */
|
||||
zip_uint16_t encryption_method; /* encryption method used */
|
||||
zip_uint32_t flags; /* reserved for future use */
|
||||
};
|
||||
|
||||
struct zip_buffer_fragment {
|
||||
zip_uint8_t *_Nonnull data;
|
||||
zip_uint64_t length;
|
||||
};
|
||||
|
||||
struct zip_file_attributes {
|
||||
zip_uint64_t valid; /* which fields have valid values */
|
||||
zip_uint8_t version; /* version of this struct, currently 1 */
|
||||
zip_uint8_t host_system; /* host system on which file was created */
|
||||
zip_uint8_t ascii; /* flag whether file is ASCII text */
|
||||
zip_uint8_t version_needed; /* minimum version needed to extract file */
|
||||
zip_uint32_t external_file_attributes; /* external file attributes (host-system specific) */
|
||||
zip_uint16_t general_purpose_bit_flags; /* general purpose big flags, only some bits are honored */
|
||||
zip_uint16_t general_purpose_bit_mask; /* which bits in general_purpose_bit_flags are valid */
|
||||
};
|
||||
|
||||
#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
|
||||
#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
|
||||
#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
|
||||
#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
|
||||
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
|
||||
|
||||
struct zip;
|
||||
struct zip_file;
|
||||
struct zip_source;
|
||||
|
||||
typedef struct zip zip_t;
|
||||
typedef struct zip_error zip_error_t;
|
||||
typedef struct zip_file zip_file_t;
|
||||
typedef struct zip_file_attributes zip_file_attributes_t;
|
||||
typedef struct zip_source zip_source_t;
|
||||
typedef struct zip_stat zip_stat_t;
|
||||
typedef struct zip_buffer_fragment zip_buffer_fragment_t;
|
||||
|
||||
typedef zip_uint32_t zip_flags_t;
|
||||
|
||||
typedef zip_int64_t (*zip_source_callback)(void *_Nullable, void *_Nullable, zip_uint64_t, zip_source_cmd_t);
|
||||
typedef void (*zip_progress_callback)(zip_t *_Nonnull, double, void *_Nullable);
|
||||
typedef int (*zip_cancel_callback)(zip_t *_Nonnull, void *_Nullable);
|
||||
|
||||
#ifndef ZIP_DISABLE_DEPRECATED
|
||||
typedef void (*zip_progress_callback_t)(double);
|
||||
ZIP_EXTERN void zip_register_progress_callback(zip_t *_Nonnull, zip_progress_callback_t _Nullable); /* use zip_register_progress_callback_with_state */
|
||||
|
||||
ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull); /* use zip_file_add */
|
||||
ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *_Nonnull, const char *_Nonnull); /* use zip_dir_add */
|
||||
ZIP_EXTERN const char *_Nullable zip_get_file_comment(zip_t *_Nonnull, zip_uint64_t, int *_Nullable, int); /* use zip_file_get_comment */
|
||||
ZIP_EXTERN int zip_get_num_files(zip_t *_Nonnull); /* use zip_get_num_entries instead */
|
||||
ZIP_EXTERN int zip_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull); /* use zip_file_rename */
|
||||
ZIP_EXTERN int zip_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull); /* use zip_file_replace */
|
||||
ZIP_EXTERN int zip_set_file_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, int); /* use zip_file_set_comment */
|
||||
ZIP_EXTERN int zip_error_get_sys_type(int); /* use zip_error_system_type */
|
||||
ZIP_EXTERN void zip_error_get(zip_t *_Nonnull, int *_Nullable, int *_Nullable); /* use zip_get_error, zip_error_code_zip / zip_error_code_system */
|
||||
ZIP_EXTERN int zip_error_to_str(char *_Nonnull, zip_uint64_t, int, int); /* use zip_error_init_with_code / zip_error_strerror */
|
||||
ZIP_EXTERN void zip_file_error_get(zip_file_t *_Nonnull, int *_Nullable, int *_Nullable); /* use zip_file_get_error, zip_error_code_zip / zip_error_code_system */
|
||||
#endif
|
||||
|
||||
ZIP_EXTERN int zip_close(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_delete(zip_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_int64_t zip_dir_add(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN void zip_discard(zip_t *_Nonnull);
|
||||
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_get_error(zip_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_clear(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_code_zip(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_code_system(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int);
|
||||
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int);
|
||||
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_system_type(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_error_to_data(const zip_error_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
|
||||
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_fdopen(int, int, int *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_file_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_file_error_clear(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_file_extra_field_delete(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_extra_field_delete_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_extra_field_set(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, const zip_uint8_t *_Nullable, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_uint16_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nullable zip_file_get_comment(zip_t *_Nonnull, zip_uint64_t, zip_uint32_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_file_get_error(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_file_get_external_attributes(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint8_t *_Nullable, zip_uint32_t *_Nullable);
|
||||
ZIP_EXTERN int zip_file_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_dostime(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_encryption(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, const char *_Nullable);
|
||||
ZIP_EXTERN int zip_file_set_external_attributes(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint8_t, zip_uint32_t);
|
||||
ZIP_EXTERN int zip_file_set_mtime(zip_t *_Nonnull, zip_uint64_t, time_t, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nonnull zip_file_strerror(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_encrypted(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t, const char *_Nullable);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index_encrypted(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, const char *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_int8_t zip_fseek(zip_file_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN zip_int64_t zip_ftell(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN const char *_Nullable zip_get_archive_comment(zip_t *_Nonnull, int *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN int zip_get_archive_flag(zip_t *_Nonnull, zip_flags_t, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nullable zip_get_name(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nonnull zip_libzip_version(void);
|
||||
ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_open_from_source(zip_source_t *_Nonnull, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t *_Nonnull, double, zip_progress_callback _Nullable, void (*_Nullable)(void *_Nullable), void *_Nullable);
|
||||
ZIP_EXTERN int zip_register_cancel_callback_with_state(zip_t *_Nonnull, zip_cancel_callback _Nullable, void (*_Nullable)(void *_Nullable), void *_Nullable);
|
||||
ZIP_EXTERN int zip_set_archive_comment(zip_t *_Nonnull, const char *_Nullable, zip_uint16_t);
|
||||
ZIP_EXTERN int zip_set_archive_flag(zip_t *_Nonnull, zip_flags_t, int);
|
||||
ZIP_EXTERN int zip_set_default_password(zip_t *_Nonnull, const char *_Nullable);
|
||||
ZIP_EXTERN int zip_set_file_compression(zip_t *_Nonnull, zip_uint64_t, zip_int32_t, zip_uint32_t);
|
||||
ZIP_EXTERN int zip_source_begin_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_begin_write_cloning(zip_source_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_create(const void *_Nullable, zip_uint64_t, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_fragment(zip_t *_Nonnull, const zip_buffer_fragment_t *_Nonnull, zip_uint64_t, int);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_fragment_create(const zip_buffer_fragment_t *_Nullable, zip_uint64_t, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_close(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_commit_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_source_error(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_file(zip_t *_Nonnull, const char *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_file_create(const char *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep(zip_t *_Nonnull, FILE *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep_create(FILE *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_function(zip_t *_Nonnull, zip_source_callback _Nonnull, void *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_function_create(zip_source_callback _Nonnull, void *_Nullable, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_get_file_attributes(zip_source_t *_Nonnull, zip_file_attributes_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_is_deleted(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_source_keep(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t, ...);
|
||||
ZIP_EXTERN int zip_source_open(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_read(zip_source_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN void zip_source_rollback_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_seek(zip_source_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN zip_int64_t zip_source_seek_compute_offset(zip_uint64_t, zip_uint64_t, void *_Nonnull, zip_uint64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_seek_write(zip_source_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN int zip_source_stat(zip_source_t *_Nonnull, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *_Nonnull);
|
||||
#ifdef _WIN32
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32a(zip_t *, const char *, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32a_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *);
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32handle(zip_t *, void *, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32handle_create(void *, zip_uint64_t, zip_int64_t, zip_error_t *);
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32w(zip_t *, const wchar_t *, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *zip_source_win32w_create(const wchar_t *, zip_uint64_t, zip_int64_t, zip_error_t *);
|
||||
#endif
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_window_create(zip_source_t *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *_Nonnull, const void *_Nullable, zip_uint64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_zip(zip_t *_Nonnull, zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_zip_create(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_stat(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_stat_init(zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_unchange(zip_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN int zip_unchange_all(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_unchange_archive(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_compression_method_supported(zip_int32_t method, int compress);
|
||||
ZIP_EXTERN int zip_encryption_method_supported(zip_uint16_t method, int encode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HAD_ZIP_H */
|
||||
51
Libs/TOS Lib/Libs/Headers/zipconf.h
Normal file
51
Libs/TOS Lib/Libs/Headers/zipconf.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _HAD_ZIPCONF_H
|
||||
#define _HAD_ZIPCONF_H
|
||||
|
||||
/*
|
||||
zipconf.h -- platform specific include file
|
||||
|
||||
This file was generated automatically by CMake
|
||||
based on ../cmake-zipconf.h.in.
|
||||
*/
|
||||
|
||||
#define LIBZIP_VERSION "1.8.0"
|
||||
#define LIBZIP_VERSION_MAJOR 1
|
||||
#define LIBZIP_VERSION_MINOR 8
|
||||
#define LIBZIP_VERSION_MICRO 0
|
||||
|
||||
/* #undef ZIP_STATIC */
|
||||
|
||||
#define _Nullable
|
||||
#define _Nonnull
|
||||
|
||||
#if !defined(__STDC_FORMAT_MACROS)
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef int8_t zip_int8_t;
|
||||
typedef uint8_t zip_uint8_t;
|
||||
typedef int16_t zip_int16_t;
|
||||
typedef uint16_t zip_uint16_t;
|
||||
typedef int32_t zip_int32_t;
|
||||
typedef uint32_t zip_uint32_t;
|
||||
typedef int64_t zip_int64_t;
|
||||
typedef uint64_t zip_uint64_t;
|
||||
|
||||
#define ZIP_INT8_MIN (-ZIP_INT8_MAX-1)
|
||||
#define ZIP_INT8_MAX 0x7f
|
||||
#define ZIP_UINT8_MAX 0xff
|
||||
|
||||
#define ZIP_INT16_MIN (-ZIP_INT16_MAX-1)
|
||||
#define ZIP_INT16_MAX 0x7fff
|
||||
#define ZIP_UINT16_MAX 0xffff
|
||||
|
||||
#define ZIP_INT32_MIN (-ZIP_INT32_MAX-1L)
|
||||
#define ZIP_INT32_MAX 0x7fffffffL
|
||||
#define ZIP_UINT32_MAX 0xffffffffLU
|
||||
|
||||
#define ZIP_INT64_MIN (-ZIP_INT64_MAX-1LL)
|
||||
#define ZIP_INT64_MAX 0x7fffffffffffffffLL
|
||||
#define ZIP_UINT64_MAX 0xffffffffffffffffULL
|
||||
|
||||
#endif /* zipconf.h */
|
||||
96
Libs/TOS Lib/Src/TOSAsync.hpp
Normal file
96
Libs/TOS Lib/Src/TOSAsync.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include "boost/asio/awaitable.hpp"
|
||||
#include "boost/asio/co_spawn.hpp"
|
||||
#include "boost/asio/deadline_timer.hpp"
|
||||
#include "boost/asio/detached.hpp"
|
||||
#include "boost/asio/io_context.hpp"
|
||||
#include "boost/asio/use_awaitable.hpp"
|
||||
#include <boost/asio/experimental/awaitable_operators.hpp>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace TOS {
|
||||
|
||||
using namespace boost::asio::experimental::awaitable_operators;
|
||||
template<typename T = void>
|
||||
using coro = boost::asio::awaitable<T>;
|
||||
|
||||
class AsyncSemaphore
|
||||
{
|
||||
boost::asio::deadline_timer Deadline;
|
||||
std::atomic<uint8_t> Lock = 0;
|
||||
|
||||
public:
|
||||
AsyncSemaphore(
|
||||
boost::asio::io_context& ioc)
|
||||
: Deadline(ioc, boost::posix_time::ptime(boost::posix_time::pos_infin))
|
||||
{}
|
||||
|
||||
boost::asio::awaitable<void> async_wait() {
|
||||
try {
|
||||
co_await Deadline.async_wait(boost::asio::use_awaitable);
|
||||
} catch(boost::system::system_error code) {
|
||||
if(code.code() != boost::system::errc::operation_canceled)
|
||||
throw;
|
||||
}
|
||||
|
||||
co_await boost::asio::this_coro::throw_if_cancelled();
|
||||
}
|
||||
|
||||
boost::asio::awaitable<void> async_wait(std::function<bool()> predicate) {
|
||||
while(!predicate())
|
||||
co_await async_wait();
|
||||
}
|
||||
|
||||
void notify_one() {
|
||||
Deadline.cancel_one();
|
||||
}
|
||||
|
||||
void notify_all() {
|
||||
Deadline.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
class IAsyncDestructible : public std::enable_shared_from_this<IAsyncDestructible> {
|
||||
protected:
|
||||
boost::asio::any_io_executor IOC;
|
||||
boost::asio::deadline_timer DestructLine;
|
||||
|
||||
virtual coro<> asyncDestructor() { DestructLine.cancel(); co_return; }
|
||||
|
||||
public:
|
||||
IAsyncDestructible(boost::asio::any_io_executor ioc)
|
||||
: IOC(ioc), DestructLine(ioc, boost::posix_time::ptime(boost::posix_time::pos_infin))
|
||||
{}
|
||||
|
||||
virtual ~IAsyncDestructible() {}
|
||||
|
||||
coro<std::variant<std::monostate, std::monostate>> cancelable(coro<> &&c) { return std::move(c) || DestructLine.async_wait(boost::asio::use_awaitable); }
|
||||
|
||||
template<typename T, typename = typename std::is_same<IAsyncDestructible, T>>
|
||||
static std::shared_ptr<T> createShared(boost::asio::any_io_executor ioc, T *ptr)
|
||||
{
|
||||
return std::shared_ptr<T>(ptr, [ioc = std::move(ioc)](IAsyncDestructible *ptr) {
|
||||
boost::asio::co_spawn(ioc, [](IAsyncDestructible *ptr) -> coro<> {
|
||||
try { co_await ptr->asyncDestructor(); } catch(...) { }
|
||||
delete ptr;
|
||||
co_return;
|
||||
} (ptr), boost::asio::detached);
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args, typename = typename std::is_same<IAsyncDestructible, T>>
|
||||
static std::shared_ptr<T> makeShared(boost::asio::any_io_executor ioc, Args&& ... args)
|
||||
{
|
||||
std::shared_ptr<T>(new T(ioc, std::forward<Args>(args)..., [ioc = std::move(ioc)](IAsyncDestructible *ptr) {
|
||||
boost::asio::co_spawn(ioc, [](IAsyncDestructible *ptr) -> coro<> {
|
||||
try { co_await ptr->asyncDestructor(); } catch(...) { }
|
||||
delete ptr;
|
||||
co_return;
|
||||
} (ptr), boost::asio::detached);
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
1000
Libs/TOS Lib/Src/TOSLib.cpp
Normal file
1000
Libs/TOS Lib/Src/TOSLib.cpp
Normal file
File diff suppressed because it is too large
Load Diff
591
Libs/TOS Lib/Src/TOSLib.hpp
Normal file
591
Libs/TOS Lib/Src/TOSLib.hpp
Normal file
@@ -0,0 +1,591 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
namespace TOS {
|
||||
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
template <typename T>
|
||||
static inline T swapEndian(const T &u) { return u; }
|
||||
#else
|
||||
template <typename T>
|
||||
static inline T swapEndian(const T &u)
|
||||
{
|
||||
union {
|
||||
T u;
|
||||
byte u8[sizeof(T)];
|
||||
} source, dest;
|
||||
|
||||
source.u = u;
|
||||
|
||||
for (size_t k = 0; k < sizeof(T); k++)
|
||||
dest.u8[k] = source.u8[sizeof(T) - k - 1];
|
||||
|
||||
return dest.u;
|
||||
}
|
||||
|
||||
template<> inline uint8_t swapEndian(const uint8_t &value) { return value; }
|
||||
template<> inline int8_t swapEndian(const int8_t &value) { return swapEndian(*(uint8_t*) &value); }
|
||||
template<> inline uint16_t swapEndian(const uint16_t &value) { return __bswap_16(value); }
|
||||
template<> inline int16_t swapEndian(const int16_t &value) { return swapEndian(*(uint16_t*) &value); }
|
||||
template<> inline uint32_t swapEndian(const uint32_t &value) { return __bswap_32(value); }
|
||||
template<> inline int32_t swapEndian(const int32_t &value) { return swapEndian(*(uint32_t*) &value); }
|
||||
template<> inline uint64_t swapEndian(const uint64_t &value) { return __bswap_64(value); }
|
||||
template<> inline int64_t swapEndian(const int64_t &value) { return swapEndian(*(uint64_t*) &value); }
|
||||
#endif
|
||||
|
||||
|
||||
class ByteBuffer : public std::vector<uint8_t> {
|
||||
protected:
|
||||
typedef std::vector<uint8_t> base;
|
||||
|
||||
public:
|
||||
class Reader;
|
||||
class Writer;
|
||||
|
||||
public:
|
||||
ByteBuffer() = default;
|
||||
template<typename ...Args, typename = typename std::enable_if_t<std::is_constructible_v<base, Args...>>>
|
||||
ByteBuffer(Args&& ... args)
|
||||
: base(std::forward<Args>(args)...)
|
||||
{}
|
||||
|
||||
ByteBuffer(std::istream &&stream)
|
||||
{
|
||||
size_t gs = stream.tellg();
|
||||
stream.seekg(0, std::ios::end);
|
||||
resize(std::min<size_t>(size_t(stream.tellg()) - gs, 1024*1024));
|
||||
|
||||
stream.seekg(gs, std::ios::beg);
|
||||
|
||||
char buff[4096];
|
||||
|
||||
size_t offset = 0;
|
||||
|
||||
while((gs = stream.readsome(buff, 4096)))
|
||||
{
|
||||
if(offset+gs > size())
|
||||
resize(offset+gs);
|
||||
|
||||
std::copy(buff, buff+gs, data() + offset);
|
||||
offset += gs;
|
||||
}
|
||||
|
||||
resize(offset);
|
||||
shrink_to_fit();
|
||||
}
|
||||
|
||||
|
||||
ByteBuffer(size_t size, const uint8_t *ptr = nullptr)
|
||||
: base(size)
|
||||
{
|
||||
if(ptr)
|
||||
std::copy(ptr, ptr+size, data());
|
||||
}
|
||||
|
||||
~ByteBuffer() = default;
|
||||
|
||||
ByteBuffer(const ByteBuffer&) = default;
|
||||
ByteBuffer(ByteBuffer&&) = default;
|
||||
ByteBuffer& operator=(const ByteBuffer&) = default;
|
||||
ByteBuffer& operator=(ByteBuffer&&) = default;
|
||||
|
||||
Reader reader() const;
|
||||
static Writer writer();
|
||||
};
|
||||
|
||||
class ByteBuffer::Reader {
|
||||
const ByteBuffer *Obj;
|
||||
size_t Index = 0;
|
||||
|
||||
template<typename T> inline T readOffset() {
|
||||
if(Index + sizeof(T) > Obj->size())
|
||||
throw std::runtime_error("Вышли за пределы буфера");
|
||||
|
||||
const uint8_t *ptr = Obj->data()+Index;
|
||||
Index += sizeof(T);
|
||||
return swapEndian(*(const T*) ptr);
|
||||
}
|
||||
|
||||
public:
|
||||
Reader(const ByteBuffer &buff)
|
||||
: Obj(&buff)
|
||||
{}
|
||||
|
||||
Reader(const Reader&) = delete;
|
||||
Reader(Reader&&) = default;
|
||||
Reader& operator=(const Reader&) = delete;
|
||||
Reader& operator=(Reader&&) = default;
|
||||
|
||||
inline Reader& operator>>(int8_t &value) { value = readOffset<int8_t>(); return *this; }
|
||||
inline Reader& operator>>(uint8_t &value) { value = readOffset<uint8_t>(); return *this; }
|
||||
inline Reader& operator>>(int16_t &value) { value = readOffset<int16_t>(); return *this; }
|
||||
inline Reader& operator>>(uint16_t &value) { value = readOffset<uint16_t>(); return *this; }
|
||||
inline Reader& operator>>(int32_t &value) { value = readOffset<int32_t>(); return *this; }
|
||||
inline Reader& operator>>(uint32_t &value) { value = readOffset<uint32_t>(); return *this; }
|
||||
inline Reader& operator>>(int64_t &value) { value = readOffset<int64_t>(); return *this; }
|
||||
inline Reader& operator>>(uint64_t &value) { value = readOffset<uint64_t>(); return *this; }
|
||||
inline Reader& operator>>(bool &value) { value = readOffset<uint8_t>(); return *this; }
|
||||
inline Reader& operator>>(float &value) { return operator>>(*(uint32_t*) &value); }
|
||||
inline Reader& operator>>(double &value) { return operator>>(*(uint64_t*) &value); }
|
||||
|
||||
inline int8_t readInt8() { int8_t value; this->operator>>(value); return value; }
|
||||
inline uint8_t readUInt8() { uint8_t value; this->operator>>(value); return value; }
|
||||
inline int16_t readInt16() { int16_t value; this->operator>>(value); return value; }
|
||||
inline uint16_t readUInt16() { uint16_t value; this->operator>>(value); return value; }
|
||||
inline int32_t readInt32() { int32_t value; this->operator>>(value); return value; }
|
||||
inline uint32_t readUInt32() { uint32_t value; this->operator>>(value); return value; }
|
||||
inline int64_t readInt64() { int64_t value; this->operator>>(value); return value; }
|
||||
inline uint64_t readUInt64() { uint64_t value; this->operator>>(value); return value; }
|
||||
inline bool readBool() { bool value; this->operator>>(value); return value; }
|
||||
inline float readFloat() { float value; this->operator>>(value); return value; }
|
||||
inline double readDouble() { double value; this->operator>>(value); return value; }
|
||||
|
||||
inline void readSize(size_t &size)
|
||||
{
|
||||
uint8_t bytes[6];
|
||||
int readed = 0;
|
||||
do {
|
||||
*this >> bytes[readed++];
|
||||
} while(((bytes[readed-1] >> 7) & 1) && readed < 6);
|
||||
|
||||
size = 0;
|
||||
for(int iter = 0; iter < readed; iter++)
|
||||
if(iter != 4)
|
||||
size |= size_t(bytes[iter] & 0x7f) << (iter*7);
|
||||
else
|
||||
size |= size_t(bytes[iter] & 0xf) << (iter*7);
|
||||
}
|
||||
|
||||
inline void readBuffer(ByteBuffer &buff)
|
||||
{
|
||||
size_t size;
|
||||
readSize(size);
|
||||
|
||||
if(Index + size > Obj->size())
|
||||
throw std::runtime_error("Вышли за пределы буфера");
|
||||
|
||||
const uint8_t *ptr = Obj->data() + Index;
|
||||
Index += size;
|
||||
buff.resize(size);
|
||||
std::copy(ptr, ptr+size, buff.data());
|
||||
}
|
||||
|
||||
inline void readString(std::string &str)
|
||||
{
|
||||
size_t size;
|
||||
readSize(size);
|
||||
|
||||
if(Index + size > Obj->size())
|
||||
throw std::runtime_error("Вышли за пределы буфера");
|
||||
|
||||
const uint8_t *ptr = Obj->data() + Index;
|
||||
Index += size;
|
||||
str.resize(size);
|
||||
std::copy(ptr, ptr+size, str.data());
|
||||
}
|
||||
|
||||
inline size_t readSize() { size_t size; readSize(size); return size; }
|
||||
inline ByteBuffer readBuffer() { ByteBuffer buff; readBuffer(buff); return buff; }
|
||||
inline std::string readString() { std::string str; readString(str); return str; }
|
||||
|
||||
Reader& operator>>(ByteBuffer &buff) { readBuffer(buff); return *this; }
|
||||
Reader& operator>>(std::string &str) { readString(str); return *this; }
|
||||
|
||||
void setPos(size_t pos) { Index = pos; }
|
||||
void offset(ssize_t offset) { setPos(Index+size_t(offset)); }
|
||||
|
||||
bool checkBorder() const { return Index >= Obj->size(); }
|
||||
|
||||
ByteBuffer cutToBuffer()
|
||||
{
|
||||
ByteBuffer out(Obj->size()-Index);
|
||||
|
||||
std::copy(Obj->data() + Index, Obj->data() + Obj->size(), out.data());
|
||||
Index += out.size();
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class ByteBuffer::Writer {
|
||||
ByteBuffer Obj;
|
||||
size_t Index = 0;
|
||||
uint16_t BlockSize = 256;
|
||||
|
||||
|
||||
inline uint8_t* checkBorder(size_t count)
|
||||
{
|
||||
if(Index+count >= Obj.capacity())
|
||||
Obj.reserve(size_t(BlockSize)*(std::ceil(float(Index+count)/float(BlockSize))+1));
|
||||
Obj.resize(Index+count);
|
||||
|
||||
uint8_t *ptr = Obj.data()+Index;
|
||||
Index += count;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
public:
|
||||
Writer() = default;
|
||||
|
||||
Writer(const Writer&) = default;
|
||||
Writer(Writer&&) = default;
|
||||
Writer& operator=(const Writer&) = default;
|
||||
Writer& operator=(Writer&&) = default;
|
||||
|
||||
inline Writer& operator<<(const int8_t &value) { *(int8_t*) checkBorder(sizeof(value)) = value; return *this; }
|
||||
inline Writer& operator<<(const uint8_t &value) { *(uint8_t*) checkBorder(sizeof(value)) = value; return *this; }
|
||||
inline Writer& operator<<(const int16_t &value) { *(int16_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const uint16_t &value) { *(uint16_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const int32_t &value) { *(int32_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const uint32_t &value) { *(uint32_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const int64_t &value) { *(int64_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const uint64_t &value) { *(uint64_t*) checkBorder(sizeof(value)) = swapEndian(value); return *this; }
|
||||
inline Writer& operator<<(const bool &value) { *(uint8_t*) checkBorder(sizeof(value)) = uint8_t(value ? 1 : 0); return *this; }
|
||||
inline Writer& operator<<(const float &value) { *(uint32_t*) checkBorder(sizeof(value)) = swapEndian(*(uint32_t*) &value); return *this; }
|
||||
inline Writer& operator<<(const double &value) { *(uint64_t*) checkBorder(sizeof(value)) = swapEndian(*(uint64_t*) &value); return *this; }
|
||||
|
||||
inline void writeInt8(const int8_t &value) { this->operator<<(value); }
|
||||
inline void writeUInt8(const uint8_t &value) { this->operator<<(value); }
|
||||
inline void writeInt16(const int16_t &value) { this->operator<<(value); }
|
||||
inline void writeUInt16(const uint16_t &value) { this->operator<<(value); }
|
||||
inline void writeInt32(const int32_t &value) { this->operator<<(value); }
|
||||
inline void writeUInt32(const uint32_t &value) { this->operator<<(value); }
|
||||
inline void writeInt64(const int64_t &value) { this->operator<<(value); }
|
||||
inline void writeUInt64(const uint64_t &value) { this->operator<<(value); }
|
||||
inline void writeBool(const bool &value) { this->operator<<(value); }
|
||||
inline void writeFloat(const float &value) { this->operator<<(value); }
|
||||
inline void writeDouble(const double &value) { this->operator<<(value); }
|
||||
|
||||
inline void writeSize(size_t size)
|
||||
{
|
||||
size_t temp = size;
|
||||
int count = 1;
|
||||
for(; count < 6; count++)
|
||||
{
|
||||
temp >>= 7;
|
||||
if(!temp)
|
||||
break;
|
||||
}
|
||||
|
||||
temp = size;
|
||||
for(int iter = 0; iter < count; iter++)
|
||||
{
|
||||
if(iter != count-1)
|
||||
writeUInt8((temp & 0x3f) | (0b1 << 7));
|
||||
else
|
||||
writeUInt8((temp & 0x3f));
|
||||
|
||||
temp >>= 7;
|
||||
}
|
||||
}
|
||||
|
||||
inline void writeBuffer(const ByteBuffer &buff)
|
||||
{
|
||||
writeSize(buff.size());
|
||||
uint8_t *ptr = checkBorder(buff.size());
|
||||
std::copy(buff.data(), buff.data()+buff.size(), ptr);
|
||||
}
|
||||
|
||||
inline void writeString(const std::string &str)
|
||||
{
|
||||
writeSize(str.size());
|
||||
uint8_t *ptr = checkBorder(str.size());
|
||||
std::copy(str.data(), str.data()+str.size(), ptr);
|
||||
}
|
||||
|
||||
inline void putBuffer(const ByteBuffer &buff)
|
||||
{
|
||||
uint8_t *ptr = checkBorder(buff.size());
|
||||
std::copy(buff.data(), buff.data()+buff.size(), ptr);
|
||||
}
|
||||
|
||||
inline Writer& operator<<(const ByteBuffer &buff) { writeBuffer(buff); return *this; }
|
||||
inline Writer& operator<<(const std::string &str) { writeString(str); return *this; }
|
||||
inline Writer& operator<<(const char *str) { writeString(std::string(str)); return *this; }
|
||||
|
||||
ByteBuffer complite() { Obj.shrink_to_fit(); return std::move(Obj); Index = 0; }
|
||||
};
|
||||
|
||||
inline ByteBuffer::Reader ByteBuffer::reader() const { return *this; }
|
||||
inline ByteBuffer::Writer ByteBuffer::writer() { return {}; }
|
||||
|
||||
|
||||
namespace Str {
|
||||
|
||||
std::vector<std::string> split(const std::string &in, const std::string &delimeter, bool useRegex = false);
|
||||
|
||||
std::string replace(const std::string &in, const std::string &pattern, const std::string &to, bool useRegex = false);
|
||||
bool contains(const std::string &in, const std::string &pattern, bool useRegex = false);
|
||||
size_t count(const std::string &in, const std::string &pattern);
|
||||
std::optional<std::vector<std::optional<std::string>>> match(const std::string &in, const std::string &pattern);
|
||||
|
||||
std::wstring toWStr(const std::string &view);
|
||||
std::string toStr(const std::wstring &view);
|
||||
std::u32string toUStr(const std::string &view);
|
||||
std::string toStr(const std::u32string &view);
|
||||
int maxUnicode(const std::string &view);
|
||||
|
||||
std::string toLowerCase(const std::string &view);
|
||||
std::string toUpperCase(const std::string &view);
|
||||
|
||||
float compareRelative(const std::string &left, const std::string &right);
|
||||
|
||||
template<typename T, typename = typename std::enable_if<
|
||||
std::__is_one_of<T, int, unsigned long, long, long long,
|
||||
unsigned long long, long double, float, double>::value>::type>
|
||||
inline T toVal(const std::string &view)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
if constexpr(std::is_same<T, int>::value)
|
||||
return std::stoi(view.data());
|
||||
else if constexpr(std::is_same<T, unsigned long>::value)
|
||||
return std::stoul(view.data());
|
||||
else if constexpr(std::is_same<T, long>::value)
|
||||
return std::stol(view.data());
|
||||
else if constexpr(std::is_same<T, long long>::value)
|
||||
return std::stoll(view.data());
|
||||
else if constexpr(std::is_same<T, unsigned long long>::value)
|
||||
return std::stoull(view.data());
|
||||
else if constexpr(std::is_same<T, long double>::value)
|
||||
return std::stold(view.data());
|
||||
else if constexpr(std::is_same<T, float>::value)
|
||||
return std::stof(view.data());
|
||||
else if constexpr(std::is_same<T, double>::value)
|
||||
return std::stod(view.data());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<
|
||||
std::__is_one_of<T, int, unsigned long, long, long long,
|
||||
unsigned long long, long double, float, double>::value>::type>
|
||||
inline T toValOrDef(const std::string &view, T def = 0, bool *ok = nullptr)
|
||||
{
|
||||
if(ok)
|
||||
*ok = true;
|
||||
|
||||
try {
|
||||
if constexpr(std::is_same<T, int>::value)
|
||||
return std::stoi(view.data());
|
||||
else if constexpr(std::is_same<T, unsigned long>::value)
|
||||
return std::stoul(view.data());
|
||||
else if constexpr(std::is_same<T, long>::value)
|
||||
return std::stol(view.data());
|
||||
else if constexpr(std::is_same<T, long long>::value)
|
||||
return std::stoll(view.data());
|
||||
else if constexpr(std::is_same<T, unsigned long long>::value)
|
||||
return std::stoull(view.data());
|
||||
else if constexpr(std::is_same<T, long double>::value)
|
||||
return std::stold(view.data());
|
||||
else if constexpr(std::is_same<T, float>::value)
|
||||
return std::stof(view.data());
|
||||
else if constexpr(std::is_same<T, double>::value)
|
||||
return std::stod(view.data());
|
||||
} catch(...) {
|
||||
if(ok)
|
||||
*ok = false;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Enc {
|
||||
|
||||
template<typename T, typename = typename std::enable_if<
|
||||
std::is_integral_v<T>
|
||||
>::type>
|
||||
std::string toHex(T value)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::setfill('0') << std::setw(sizeof(T)*2)
|
||||
<< std::hex << uint64_t(value);
|
||||
return stream.str();
|
||||
};
|
||||
|
||||
std::string toHex(const uint8_t *data, size_t size);
|
||||
void fromHex(const std::string &in, uint8_t *data);
|
||||
|
||||
std::string toBase64(const uint8_t *data, size_t size);
|
||||
ByteBuffer fromBase64(const std::string &view);
|
||||
void base64UrlConvert(std::string &in);
|
||||
|
||||
// LowerCase
|
||||
std::string md5(const uint8_t *data, size_t size);
|
||||
inline std::string md5(const std::string &str) { return md5((const uint8_t*) str.data(), str.size()); }
|
||||
std::string sha1(const uint8_t *data, size_t size);
|
||||
inline std::string sha1(const std::string &str) { return sha1((const uint8_t*) str.data(), str.size()); }
|
||||
}
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
namespace Time {
|
||||
template<typename T>
|
||||
inline void sleep(T val) { std::this_thread::sleep_for(val); }
|
||||
inline void sleep3(uint64_t mls) { std::this_thread::sleep_for(std::chrono::milliseconds { mls }); }
|
||||
inline void sleep6(uint64_t mcs) { std::this_thread::sleep_for(std::chrono::microseconds { mcs }); }
|
||||
inline void sleep9(uint64_t nas) { std::this_thread::sleep_for(std::chrono::nanoseconds { nas }); }
|
||||
|
||||
// Системное время, может изменяться в обратку
|
||||
inline uint64_t nowSystem() { return std::chrono::system_clock::now().time_since_epoch().count(); }
|
||||
// Время с запуска хоста, только растёт
|
||||
inline uint64_t nowSteady() { return std::chrono::steady_clock::now().time_since_epoch().count(); }
|
||||
// Максимально точное время
|
||||
inline uint64_t nowHigh() { return std::chrono::high_resolution_clock::now().time_since_epoch().count(); }
|
||||
|
||||
inline std::time_t getTime() { return std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); }
|
||||
// Количество секунд с начала эпохи на часах системы
|
||||
inline uint64_t getSeconds() { return std::chrono::system_clock::now().time_since_epoch().count() / 1000000000ull; }
|
||||
|
||||
inline uint32_t getDay() { return getSeconds() / 86400; }
|
||||
|
||||
// yyyy.mm.dd
|
||||
std::string getDateAsString();
|
||||
// hh:mm:ss
|
||||
std::string getTimeAsString();
|
||||
}
|
||||
|
||||
//[0.0,1.0)
|
||||
inline double genRand(double min = 1, double max = 0)
|
||||
{
|
||||
double res;
|
||||
#ifdef _WIN32
|
||||
res = std::clamp(rand() / double(RAND_MAX), 0., 0.9999999);
|
||||
#else
|
||||
res = drand48();
|
||||
#endif
|
||||
return res*(max-min)+min;
|
||||
}
|
||||
|
||||
std::string makeStackTrace(int stack_up = 1);
|
||||
|
||||
struct Timer
|
||||
{
|
||||
boost::timer::cpu_timer Obj;
|
||||
|
||||
/* Возвращает прошедшее время в наносекундах 1/1'000'000'000 */
|
||||
uint64_t timePastNan()
|
||||
{
|
||||
auto time = Obj.elapsed();
|
||||
return time.wall;
|
||||
}
|
||||
/* Возвращает прошедшее время в милисекундах 1/1'000 */
|
||||
uint32_t timePastMil() { return timePastNan()/1000000; }
|
||||
|
||||
/* Возвращает затраченное процессорное время в наносекундах 1/1'000'000'000 */
|
||||
uint64_t timeUsedNan()
|
||||
{
|
||||
auto time = Obj.elapsed();
|
||||
return time.system+time.user;
|
||||
}
|
||||
/* Возвращает затраченное процессорное время в милисекундах 1/1'000 */
|
||||
uint32_t timeUsedMil() { return timeUsedNan()/1000000; }
|
||||
|
||||
/* Обнуляет счетчик таймера и запускает его */
|
||||
void start() { Obj.start(); }
|
||||
/* Запускает таймер */
|
||||
void resume() { Obj.resume(); }
|
||||
/* Останавливает таймер */
|
||||
void stop() { Obj.stop(); }
|
||||
bool isStopped() { return Obj.is_stopped(); }
|
||||
};
|
||||
|
||||
class DynamicLibrary {
|
||||
std::string Name, Path;
|
||||
uint64_t FD;
|
||||
static bool IsOverWine;
|
||||
|
||||
static void symbolOut();
|
||||
static bool checkWine();
|
||||
|
||||
public:
|
||||
DynamicLibrary(const std::string &name_or_path);
|
||||
DynamicLibrary(const char *name_or_path) : DynamicLibrary(std::string(name_or_path)) {}
|
||||
~DynamicLibrary();
|
||||
|
||||
DynamicLibrary(const DynamicLibrary&) = delete;
|
||||
DynamicLibrary(DynamicLibrary&&);
|
||||
DynamicLibrary& operator=(const DynamicLibrary&) = delete;
|
||||
DynamicLibrary& operator=(DynamicLibrary&&);
|
||||
|
||||
std::string getName() const { return Name; }
|
||||
std::string getPath() const { return Path; }
|
||||
uint64_t getHandler() const { return FD; }
|
||||
|
||||
// Запрашивает адрес символа из библиотеки, иначе генерирует ошибку
|
||||
void* getSymbol(const std::string &name) const;
|
||||
template<typename Result, typename ...Args>
|
||||
inline void getSymbol(Result (*&to)(Args...), const std::string &name) const { to = (Result (*)(Args...)) getSymbol(name); }
|
||||
// Запрашивает адрес символа из библиотеки, если отсутствует ссылает на &symbolOut
|
||||
void* takeSymbol(const std::string &name) const;
|
||||
template<typename Result, typename ...Args>
|
||||
inline void takeSymbol(Result (*&to)(Args...), const std::string &name) const { to = (Result (*)(Args...)) takeSymbol(name); }
|
||||
|
||||
// Запрашивает адрес из глобального пространства, если нет, то ошибка
|
||||
static void* getDynamicSymbol(const std::string &name);
|
||||
// Вместо ошибки даёт symbolOut
|
||||
static void* takeDynamicSymbol(const std::string &name);
|
||||
//
|
||||
static void* hasDynamicSymbol(const std::string &name);
|
||||
// Проверяет наличие или загружает библиотеку с глобальной линковкой функций
|
||||
static void needGlobalLibraryTemplate(const std::string &name);
|
||||
static std::vector<std::filesystem::path> getLdPaths();
|
||||
static bool isOverWine() { return IsOverWine; }
|
||||
};
|
||||
|
||||
enum struct EnumLogType : int {
|
||||
Debug = 1, Info = 2, Warn = 4, Error = 8, All = 15
|
||||
};
|
||||
|
||||
|
||||
class LogSession : public std::stringstream {
|
||||
bool NeedF = false, NeedC = false;
|
||||
std::string Path;
|
||||
|
||||
public:
|
||||
LogSession(const std::string &name, EnumLogType type);
|
||||
~LogSession();
|
||||
|
||||
LogSession(const LogSession&) = delete;
|
||||
LogSession(LogSession&&) = delete;
|
||||
LogSession& operator=(const LogSession&) = delete;
|
||||
LogSession& operator=(LogSession&&) = delete;
|
||||
};
|
||||
|
||||
class Logger {
|
||||
std::string Path;
|
||||
|
||||
public:
|
||||
Logger(const std::string &path) : Path(path) {}
|
||||
Logger(const char *path) : Path(path) {}
|
||||
~Logger() = default;
|
||||
|
||||
inline LogSession print(EnumLogType type) const { return LogSession(Path, type); }
|
||||
inline LogSession debug() const { return print(EnumLogType::Debug); }
|
||||
inline LogSession info() const { return print(EnumLogType::Info); }
|
||||
inline LogSession warn() const { return print(EnumLogType::Warn); }
|
||||
inline LogSession error() const { return print(EnumLogType::Error); }
|
||||
|
||||
void setName(const std::string &path) { Path = path; }
|
||||
|
||||
static LogSession print(const std::string &path) { return LogSession(path, EnumLogType::All); }
|
||||
static void addLogFile(const std::string ®ex_for_path, EnumLogType levels, const std::filesystem::path &file, bool rewrite = false);
|
||||
static void addLogOutput(const std::string ®ex_for_path, EnumLogType levels);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#define MAKE_ERROR(arg) throw std::runtime_error((std::stringstream() << arg).str())
|
||||
1080
Libs/TOS Lib/Src/TOS_PSQL.hpp
Normal file
1080
Libs/TOS Lib/Src/TOS_PSQL.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user