Just refactored tools to C++
This commit is contained in:
@ -1,46 +1,49 @@
|
|||||||
# Copyright (c) 2022 Dominic Masters
|
# Copyright (c) 2022 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Include tools
|
# Include shared libs
|
||||||
add_subdirectory(dawntools)
|
add_subdirectory(dawnshared)
|
||||||
|
|
||||||
# Change what we are building
|
# Include tools
|
||||||
add_subdirectory(${DAWN_BUILDING})
|
add_subdirectory(dawntools)
|
||||||
|
|
||||||
# Check the game project includes the target name
|
# Change what we are building
|
||||||
if(NOT DEFINED DAWN_TARGET_NAME)
|
add_subdirectory(${DAWN_BUILDING})
|
||||||
message(FATAL_ERROR "You need to define a DAWN_TARGET_NAME")
|
|
||||||
endif()
|
# Check the game project includes the target name
|
||||||
|
if(NOT DEFINED DAWN_TARGET_NAME)
|
||||||
# Add in base library
|
message(FATAL_ERROR "You need to define a DAWN_TARGET_NAME")
|
||||||
add_subdirectory(dawn)
|
endif()
|
||||||
|
|
||||||
# Compile entry targets
|
# Add in base library
|
||||||
if(DAWN_TARGET_WIN32)
|
add_subdirectory(dawn)
|
||||||
add_subdirectory(dawnwin32)
|
|
||||||
elseif(DAWN_TARGET_LINUX64)
|
# Compile entry targets
|
||||||
add_subdirectory(dawnlinux64)
|
if(DAWN_TARGET_WIN32)
|
||||||
else()
|
add_subdirectory(dawnwin32)
|
||||||
message(FATAL_ERROR "You need to define an entry target")
|
elseif(DAWN_TARGET_LINUX64)
|
||||||
endif()
|
add_subdirectory(dawnlinux64)
|
||||||
|
else()
|
||||||
# Host Libraries
|
message(FATAL_ERROR "You need to define an entry target")
|
||||||
target_link_libraries(${DAWN_TARGET_NAME}
|
endif()
|
||||||
PUBLIC
|
|
||||||
${DAWN_BUILD_HOST_LIBS}
|
# Host Libraries
|
||||||
)
|
target_link_libraries(${DAWN_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
# Compile support targets
|
${DAWN_BUILD_HOST_LIBS}
|
||||||
if(DAWN_TARGET_GLFW)
|
)
|
||||||
add_subdirectory(dawnglfw)
|
|
||||||
add_subdirectory(dawnopengl)
|
# Compile support targets
|
||||||
endif()
|
if(DAWN_TARGET_GLFW)
|
||||||
|
add_subdirectory(dawnglfw)
|
||||||
if(DAWN_TARGET_SDL2)
|
add_subdirectory(dawnopengl)
|
||||||
add_subdirectory(dawnsdl2)
|
endif()
|
||||||
add_subdirectory(dawnopengl)
|
|
||||||
endif()
|
if(DAWN_TARGET_SDL2)
|
||||||
|
add_subdirectory(dawnsdl2)
|
||||||
|
add_subdirectory(dawnopengl)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(dawnopenal)
|
add_subdirectory(dawnopenal)
|
@ -13,6 +13,7 @@ target_link_libraries(${DAWN_TARGET_NAME}
|
|||||||
# Includes
|
# Includes
|
||||||
target_include_directories(${DAWN_TARGET_NAME}
|
target_include_directories(${DAWN_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,36 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "dawnsharedlibs.hpp"
|
||||||
|
|
||||||
// Static Libs
|
|
||||||
extern "C" {
|
|
||||||
// Standard Libs
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
typedef bool bool_t;
|
|
||||||
typedef float float_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <thread>
|
|
||||||
#include <map>
|
|
||||||
#include <array>
|
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
#include <memory>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <sstream>
|
|
||||||
// #include <iterator>
|
|
||||||
// #include <algorithm>
|
|
||||||
// #include <string>
|
|
||||||
// #include <sstream>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
13
src/dawnshared/CMakeLists.txt
Normal file
13
src/dawnshared/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Copyright (c) 2023 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
set(
|
||||||
|
DAWN_SHARED_INCLUDES
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
|
||||||
|
CACHE INTERNAL
|
||||||
|
${DAWN_CACHE_TARGET}
|
||||||
|
)
|
31
src/dawnshared/dawnsharedlibs.hpp
Normal file
31
src/dawnshared/dawnsharedlibs.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Static Libs
|
||||||
|
extern "C" {
|
||||||
|
// Standard Libs
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
typedef bool bool_t;
|
||||||
|
typedef float float_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <map>
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <sstream>
|
@ -1,23 +1,24 @@
|
|||||||
# Copyright (c) 2021 Dominic Msters
|
# Copyright (c) 2021 Dominic Msters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Texture Build Tool
|
# Texture Build Tool
|
||||||
project(audiogen VERSION 1.0)
|
project(audiogen VERSION 1.0)
|
||||||
add_executable(audiogen)
|
add_executable(audiogen)
|
||||||
target_sources(audiogen
|
target_sources(audiogen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(audiogen
|
target_include_directories(audiogen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
)
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
target_link_libraries(audiogen
|
)
|
||||||
PUBLIC
|
target_link_libraries(audiogen
|
||||||
${DAWN_BUILD_HOST_LIBS}
|
PUBLIC
|
||||||
AudioFile
|
${DAWN_BUILD_HOST_LIBS}
|
||||||
|
AudioFile
|
||||||
)
|
)
|
@ -1,78 +1,76 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/common.hpp"
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "AudioFile.h"
|
||||||
}
|
|
||||||
#include "AudioFile.h"
|
int main(int argc, char *argv[]) {
|
||||||
|
FILE *fileOut;
|
||||||
int main(int argc, char *argv[]) {
|
char buffer[FILENAME_MAX];
|
||||||
FILE *fileOut;
|
size_t bufferLength = 0;
|
||||||
char buffer[FILENAME_MAX];
|
|
||||||
size_t bufferLength = 0;
|
if(argc != 3) {
|
||||||
|
printf("Invalid number of arguments\n");
|
||||||
if(argc != 3) {
|
return 1;
|
||||||
printf("Invalid number of arguments\n");
|
}
|
||||||
return 1;
|
|
||||||
}
|
fileNormalizeSlashes(argv[1]);
|
||||||
|
fileNormalizeSlashes(argv[2]);
|
||||||
fileNormalizeSlashes(argv[1]);
|
std::string strFileIn = std::string(argv[1]);
|
||||||
fileNormalizeSlashes(argv[2]);
|
std::string strFileOut = std::string(argv[2]);
|
||||||
std::string strFileIn = std::string(argv[1]);
|
|
||||||
std::string strFileOut = std::string(argv[2]);
|
buffer[0] = '\0';
|
||||||
|
sprintf(buffer, "%s.audio", strFileOut.c_str());
|
||||||
buffer[0] = '\0';
|
fileOut = fopen(buffer, "rb");
|
||||||
sprintf(buffer, "%s.audio", strFileOut.c_str());
|
if(fileOut != NULL) {
|
||||||
fileOut = fopen(buffer, "rb");
|
fclose(fileOut);
|
||||||
if(fileOut != NULL) {
|
return 0;
|
||||||
fclose(fileOut);
|
}
|
||||||
return 0;
|
|
||||||
}
|
// Load input file
|
||||||
|
AudioFile<double> audioFile;
|
||||||
// Load input file
|
if(!audioFile.load(strFileIn)) {
|
||||||
AudioFile<double> audioFile;
|
printf("Failed to load audio file.\n");
|
||||||
if(!audioFile.load(strFileIn)) {
|
return 1;
|
||||||
printf("Failed to load audio file.\n");
|
}
|
||||||
return 1;
|
|
||||||
}
|
// Open Output File
|
||||||
|
fileMkdirp(buffer);
|
||||||
// Open Output File
|
fileOut = fopen(buffer, "wb");
|
||||||
fileMkdirp(buffer);
|
if(fileOut == NULL) {
|
||||||
fileOut = fopen(buffer, "wb");
|
printf("Failed to create output file\n");
|
||||||
if(fileOut == NULL) {
|
return 1;
|
||||||
printf("Failed to create output file\n");
|
}
|
||||||
return 1;
|
|
||||||
}
|
// Write header
|
||||||
|
buffer[0] = '\0';
|
||||||
// Write header
|
sprintf(buffer, "%i|%i|%i|%i|",
|
||||||
buffer[0] = '\0';
|
audioFile.getNumChannels(),
|
||||||
sprintf(buffer, "%i|%i|%i|%i|",
|
audioFile.getSampleRate(),
|
||||||
audioFile.getNumChannels(),
|
audioFile.getNumSamplesPerChannel(),
|
||||||
audioFile.getSampleRate(),
|
audioFile.getNumSamplesPerChannel() * audioFile.getNumChannels()*(
|
||||||
audioFile.getNumSamplesPerChannel(),
|
sizeof(int16_t) / sizeof(uint8_t)
|
||||||
audioFile.getNumSamplesPerChannel() * audioFile.getNumChannels()*(
|
)
|
||||||
sizeof(int16_t) / sizeof(uint8_t)
|
);
|
||||||
)
|
bufferLength = strlen(buffer);
|
||||||
);
|
fwrite(buffer, sizeof(char), bufferLength, fileOut);
|
||||||
bufferLength = strlen(buffer);
|
|
||||||
fwrite(buffer, sizeof(char), bufferLength, fileOut);
|
// Convert Data to 16 bit audio
|
||||||
|
for (int32_t i = 0; i < audioFile.getNumSamplesPerChannel(); i++) {
|
||||||
// Convert Data to 16 bit audio
|
for(int32_t y = 0; y < audioFile.getNumChannels(); y++) {
|
||||||
for (int32_t i = 0; i < audioFile.getNumSamplesPerChannel(); i++) {
|
double sample = audioFile.samples[y][i];
|
||||||
for(int32_t y = 0; y < audioFile.getNumChannels(); y++) {
|
sample = sample < -1 ? -1 : sample > 1 ? 1 : sample;
|
||||||
double sample = audioFile.samples[y][i];
|
auto q = static_cast<int16_t> (sample * 32767.);
|
||||||
sample = sample < -1 ? -1 : sample > 1 ? 1 : sample;
|
|
||||||
auto q = static_cast<int16_t> (sample * 32767.);
|
buffer[0] = (q >> 8) & 0xFF;
|
||||||
|
buffer[1] = q & 0xFF;
|
||||||
buffer[0] = (q >> 8) & 0xFF;
|
fwrite(buffer, sizeof(uint8_t), 2, fileOut);
|
||||||
buffer[1] = q & 0xFF;
|
}
|
||||||
fwrite(buffer, sizeof(uint8_t), 2, fileOut);
|
}
|
||||||
}
|
|
||||||
}
|
fclose(fileOut);
|
||||||
|
return 0;
|
||||||
fclose(fileOut);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
@ -9,11 +9,12 @@ add_executable(texturegen)
|
|||||||
target_sources(texturegen
|
target_sources(texturegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/image.c
|
../../utils/image.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(texturegen
|
target_include_directories(texturegen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -5,11 +5,9 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/common.hpp"
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/image.hpp"
|
||||||
#include "../../utils/image.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -9,11 +9,12 @@ add_executable(tilesetgen)
|
|||||||
target_sources(tilesetgen
|
target_sources(tilesetgen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/image.c
|
../../utils/image.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(tilesetgen
|
target_include_directories(tilesetgen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -5,11 +5,9 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/common.hpp"
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/image.hpp"
|
||||||
#include "../../utils/image.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *in;
|
char *in;
|
||||||
|
@ -9,11 +9,12 @@ add_executable(truetypegen)
|
|||||||
target_sources(truetypegen
|
target_sources(truetypegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/image.c
|
../../utils/image.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(truetypegen
|
target_include_directories(truetypegen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -5,15 +5,13 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/common.hpp"
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/image.hpp"
|
||||||
#include "../../utils/image.h"
|
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
||||||
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#include <stb_truetype.h>
|
||||||
#include <stb_truetype.h>
|
#endif
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TRUETYPE_FIRST_CHAR 32
|
#define TRUETYPE_FIRST_CHAR 32
|
||||||
#define TRUETYPE_NUM_CHARS 96
|
#define TRUETYPE_NUM_CHARS 96
|
||||||
|
@ -9,11 +9,12 @@ add_executable(uigen)
|
|||||||
target_sources(uigen
|
target_sources(uigen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/xml.c
|
../../utils/xml.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(uigen
|
target_include_directories(uigen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -5,11 +5,8 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/xml.hpp"
|
||||||
#include "../../utils/xml.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
|
||||||
#include <memory.h>
|
|
||||||
}
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@ add_executable(languagegen)
|
|||||||
target_sources(languagegen
|
target_sources(languagegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/csv.c
|
../../utils/csv.cpp
|
||||||
../../utils/xml.c
|
../../utils/xml.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(languagegen
|
target_include_directories(languagegen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -5,14 +5,10 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/common.hpp"
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/csv.hpp"
|
||||||
#include "../../utils/csv.h"
|
#include "../../utils/xml.hpp"
|
||||||
#include "../../utils/xml.h"
|
|
||||||
#include <memory.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2021 Dominic Masters
|
* Copyright (c) 2021 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdio.h>
|
#include "dawnsharedlibs.hpp"
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
@ -1,120 +1,120 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2022 Dominic Masters
|
* Copyright (c) 2022 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "csv.h"
|
#include "csv.hpp"
|
||||||
|
|
||||||
char * csvGetCell(csv_t *csv, int32_t row, int32_t cell) {
|
char * csvGetCell(csv_t *csv, int32_t row, int32_t cell) {
|
||||||
return csv->rows[(row * CSV_COLUMN_COUNT_MAX) + cell];
|
return csv->rows[(row * CSV_COLUMN_COUNT_MAX) + cell];
|
||||||
}
|
}
|
||||||
|
|
||||||
void csvParse(char *string, csv_t *csv) {
|
void csvParse(char *string, csv_t *csv) {
|
||||||
char c;
|
char c;
|
||||||
size_t i, j, length;
|
size_t i, j, length;
|
||||||
csvparsestate_t state;
|
csvparsestate_t state;
|
||||||
int32_t rowCellCount;
|
int32_t rowCellCount;
|
||||||
|
|
||||||
length = strlen(string);
|
length = strlen(string);
|
||||||
csv->buffer = malloc(sizeof(char) * (length+1) * CSV_COLUMN_COUNT_MAX * CSV_ROW_COUNT_MAX);
|
csv->buffer = (char *)malloc(sizeof(char) * (length+1) * CSV_COLUMN_COUNT_MAX * CSV_ROW_COUNT_MAX);
|
||||||
csv->cellCounts = malloc(sizeof(int32_t) * CSV_ROW_COUNT_MAX);
|
csv->cellCounts = (int32_t *)malloc(sizeof(int32_t) * CSV_ROW_COUNT_MAX);
|
||||||
csv->rows = malloc(sizeof(char*) * CSV_ROW_COUNT_MAX * CSV_COLUMN_COUNT_MAX);
|
csv->rows = (char**)malloc(sizeof(char*) * CSV_ROW_COUNT_MAX * CSV_COLUMN_COUNT_MAX);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
rowCellCount = 0;
|
rowCellCount = 0;
|
||||||
csv->rowCount = 0;
|
csv->rowCount = 0;
|
||||||
state = CSV_PARSE_STATE_FIND_CELL;
|
state = CSV_PARSE_STATE_FIND_CELL;
|
||||||
while(i < length) {
|
while(i < length) {
|
||||||
c = string[i++];
|
c = string[i++];
|
||||||
|
|
||||||
// What are we doing
|
// What are we doing
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case CSV_PARSE_STATE_FIND_CELL:
|
case CSV_PARSE_STATE_FIND_CELL:
|
||||||
if(c == '"') {
|
if(c == '"') {
|
||||||
state = CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES;
|
state = CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES;
|
||||||
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
||||||
rowCellCount++;
|
rowCellCount++;
|
||||||
continue;
|
continue;
|
||||||
} else if(c == '\r' || c == '\n') {
|
} else if(c == '\r' || c == '\n') {
|
||||||
// Newline (todo: is this a blank line?)
|
// Newline (todo: is this a blank line?)
|
||||||
state = CSV_PARSE_STATE_LINE_END;
|
state = CSV_PARSE_STATE_LINE_END;
|
||||||
continue;
|
continue;
|
||||||
} else if(c == ',') {
|
} else if(c == ',') {
|
||||||
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
||||||
csv->buffer[j++] = '\0';
|
csv->buffer[j++] = '\0';
|
||||||
rowCellCount++;
|
rowCellCount++;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
state = CSV_PARSE_STATE_PARSE_CELL;
|
state = CSV_PARSE_STATE_PARSE_CELL;
|
||||||
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
csv->rows[(csv->rowCount * CSV_COLUMN_COUNT_MAX) + rowCellCount] = csv->buffer + j;
|
||||||
csv->buffer[j++] = c;
|
csv->buffer[j++] = c;
|
||||||
rowCellCount++;
|
rowCellCount++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CSV_PARSE_STATE_PARSE_CELL:
|
case CSV_PARSE_STATE_PARSE_CELL:
|
||||||
if(c == '\r' || c == '\n') {
|
if(c == '\r' || c == '\n') {
|
||||||
state = CSV_PARSE_STATE_LINE_END;
|
state = CSV_PARSE_STATE_LINE_END;
|
||||||
csv->buffer[j++] = '\0';
|
csv->buffer[j++] = '\0';
|
||||||
continue;
|
continue;
|
||||||
} else if(c == ',') {
|
} else if(c == ',') {
|
||||||
state = CSV_PARSE_STATE_FIND_CELL;
|
state = CSV_PARSE_STATE_FIND_CELL;
|
||||||
csv->buffer[j++] = '\0';
|
csv->buffer[j++] = '\0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
csv->buffer[j++] = c;
|
csv->buffer[j++] = c;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES:
|
case CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES:
|
||||||
if((c == '\\' && string[i] == '"') || (c == '"' && string[i] == '"')) {
|
if((c == '\\' && string[i] == '"') || (c == '"' && string[i] == '"')) {
|
||||||
// Handle escaped quotes. I normally see [\"] but excel does [""] in
|
// Handle escaped quotes. I normally see [\"] but excel does [""] in
|
||||||
// most cases
|
// most cases
|
||||||
csv->buffer[j++] = '"';
|
csv->buffer[j++] = '"';
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
} else if(c == '"') {
|
} else if(c == '"') {
|
||||||
// Handle end of quoted string
|
// Handle end of quoted string
|
||||||
state = CSV_PARSE_STATE_FIND_CELL;
|
state = CSV_PARSE_STATE_FIND_CELL;
|
||||||
csv->buffer[j++] = '\0';
|
csv->buffer[j++] = '\0';
|
||||||
// Because we tend to do [",] at the end of a quoted cell, we do this
|
// Because we tend to do [",] at the end of a quoted cell, we do this
|
||||||
// to prevent [,,] cases being treated the same
|
// to prevent [,,] cases being treated the same
|
||||||
if(string[i] == ',') i++;
|
if(string[i] == ',') i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal character.
|
// Normal character.
|
||||||
csv->buffer[j++] = c;
|
csv->buffer[j++] = c;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CSV_PARSE_STATE_LINE_END:
|
case CSV_PARSE_STATE_LINE_END:
|
||||||
// Skip blanks
|
// Skip blanks
|
||||||
if(c == '\r' || c == '\n') continue;
|
if(c == '\r' || c == '\n') continue;
|
||||||
csv->cellCounts[csv->rowCount] = rowCellCount;
|
csv->cellCounts[csv->rowCount] = rowCellCount;
|
||||||
csv->rowCount++;
|
csv->rowCount++;
|
||||||
rowCellCount = 0;
|
rowCellCount = 0;
|
||||||
state = CSV_PARSE_STATE_FIND_CELL;
|
state = CSV_PARSE_STATE_FIND_CELL;
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("Error occured during parse operation.");
|
printf("Error occured during parse operation.");
|
||||||
free(NULL);
|
free(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
csv->buffer[j++] = '\0';
|
csv->buffer[j++] = '\0';
|
||||||
|
|
||||||
if(rowCellCount != 0) {
|
if(rowCellCount != 0) {
|
||||||
csv->cellCounts[csv->rowCount] = rowCellCount;
|
csv->cellCounts[csv->rowCount] = rowCellCount;
|
||||||
csv->rowCount++;
|
csv->rowCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void csvDispose(csv_t *csv) {
|
void csvDispose(csv_t *csv) {
|
||||||
free(csv->buffer);
|
free(csv->buffer);
|
||||||
free(csv->cellCounts);
|
free(csv->cellCounts);
|
||||||
free(csv->rows);
|
free(csv->rows);
|
||||||
}
|
}
|
@ -1,33 +1,33 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2022 Dominic Masters
|
* Copyright (c) 2022 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.hpp"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
#define CSV_ROW_COUNT_MAX 128
|
#define CSV_ROW_COUNT_MAX 128
|
||||||
#define CSV_COLUMN_COUNT_MAX 16
|
#define CSV_COLUMN_COUNT_MAX 16
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CSV_PARSE_STATE_FIND_CELL,//0
|
CSV_PARSE_STATE_FIND_CELL,//0
|
||||||
CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES,
|
CSV_PARSE_STATE_PARSE_CELL_WITH_QUOTES,
|
||||||
CSV_PARSE_STATE_PARSE_CELL,//2
|
CSV_PARSE_STATE_PARSE_CELL,//2
|
||||||
CSV_PARSE_STATE_LINE_END
|
CSV_PARSE_STATE_LINE_END
|
||||||
} csvparsestate_t;
|
} csvparsestate_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *buffer;
|
char *buffer;
|
||||||
char **rows;
|
char **rows;
|
||||||
int32_t rowCount;
|
int32_t rowCount;
|
||||||
int32_t *cellCounts;
|
int32_t *cellCounts;
|
||||||
} csv_t;
|
} csv_t;
|
||||||
|
|
||||||
char * csvGetCell(csv_t *csv, int32_t row, int32_t cell);
|
char * csvGetCell(csv_t *csv, int32_t row, int32_t cell);
|
||||||
|
|
||||||
void csvParse(char *string, csv_t *csv);
|
void csvParse(char *string, csv_t *csv);
|
||||||
|
|
||||||
void csvDispose(csv_t *csv);
|
void csvDispose(csv_t *csv);
|
@ -1,195 +1,195 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2021 Dominic Masters
|
* Copyright (c) 2021 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.hpp"
|
||||||
|
|
||||||
void fileNormalizeSlashes(char *string) {
|
void fileNormalizeSlashes(char *string) {
|
||||||
char c;
|
char c;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while(c = string[i++]) {
|
while(c = string[i++]) {
|
||||||
if(c != '\\' && c != '/') continue;
|
if(c != '\\' && c != '/') continue;
|
||||||
string[i-1] = FILE_PATH_SEP;
|
string[i-1] = FILE_PATH_SEP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fileMkdirp(char *path) {
|
void fileMkdirp(char *path) {
|
||||||
char buffer[FILENAME_MAX];
|
char buffer[FILENAME_MAX];
|
||||||
char c;
|
char c;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool inFile;
|
bool inFile;
|
||||||
bool hasMore;
|
bool hasMore;
|
||||||
|
|
||||||
inFile = false;
|
inFile = false;
|
||||||
hasMore = false;
|
hasMore = false;
|
||||||
while(c = path[i]) {
|
while(c = path[i]) {
|
||||||
if((c == '\\' || c == '/') && i > 0) {
|
if((c == '\\' || c == '/') && i > 0) {
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
fileMkdir(buffer, 0755);
|
fileMkdir(buffer, 0755);
|
||||||
inFile = false;
|
inFile = false;
|
||||||
hasMore = false;
|
hasMore = false;
|
||||||
buffer[i] = FILE_PATH_SEP;
|
buffer[i] = FILE_PATH_SEP;
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == '.') inFile = true;
|
if(c == '.') inFile = true;
|
||||||
hasMore = true;
|
hasMore = true;
|
||||||
buffer[i] = c;
|
buffer[i] = c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!inFile && hasMore) {
|
if(!inFile && hasMore) {
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
fileMkdir(buffer, 0755);
|
fileMkdir(buffer, 0755);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t assetReadString(FILE *file, char *buffer) {
|
size_t assetReadString(FILE *file, char *buffer) {
|
||||||
size_t length;
|
size_t length;
|
||||||
fseek(file, 0, SEEK_END);// Seek to the end
|
fseek(file, 0, SEEK_END);// Seek to the end
|
||||||
length = ftell(file);// Get our current position (the end)
|
length = ftell(file);// Get our current position (the end)
|
||||||
fseek(file, 0, SEEK_SET);// Reset the seek
|
fseek(file, 0, SEEK_SET);// Reset the seek
|
||||||
if(buffer == NULL) return length;
|
if(buffer == NULL) return length;
|
||||||
return fread(buffer, 1, length, file);// Read all the bytes
|
return fread(buffer, 1, length, file);// Read all the bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t readAhead(
|
int32_t readAhead(
|
||||||
char *bufferIn, int32_t start,
|
char *bufferIn, int32_t start,
|
||||||
char *bufferOut,
|
char *bufferOut,
|
||||||
char *needles, int32_t needleCount
|
char *needles, int32_t needleCount
|
||||||
) {
|
) {
|
||||||
int32_t i = start, k = 0, j;
|
int32_t i = start, k = 0, j;
|
||||||
char c;
|
char c;
|
||||||
bool needleFound = false;
|
bool needleFound = false;
|
||||||
|
|
||||||
if(bufferIn[i] == '\0') return 0;
|
if(bufferIn[i] == '\0') return 0;
|
||||||
|
|
||||||
while((c = bufferIn[i++]) != '\0') {
|
while((c = bufferIn[i++]) != '\0') {
|
||||||
for(j = 0; j < needleCount; j++) {
|
for(j = 0; j < needleCount; j++) {
|
||||||
if(c != needles[j]) continue;
|
if(c != needles[j]) continue;
|
||||||
needleFound = true;
|
needleFound = true;
|
||||||
}
|
}
|
||||||
if(needleFound) break;
|
if(needleFound) break;
|
||||||
if(bufferOut != NULL) bufferOut[k] = c;
|
if(bufferOut != NULL) bufferOut[k] = c;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bufferOut != NULL) bufferOut[k] = '\0';
|
if(bufferOut != NULL) bufferOut[k] = '\0';
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t skipAhead(
|
int32_t skipAhead(
|
||||||
char *bufferIn, int32_t start,
|
char *bufferIn, int32_t start,
|
||||||
char *needles, int32_t needleCount
|
char *needles, int32_t needleCount
|
||||||
) {
|
) {
|
||||||
char c;
|
char c;
|
||||||
int32_t j, k = 0, i = start;
|
int32_t j, k = 0, i = start;
|
||||||
bool needleFound;
|
bool needleFound;
|
||||||
|
|
||||||
while((c = bufferIn[i++]) != '\0') {
|
while((c = bufferIn[i++]) != '\0') {
|
||||||
needleFound = false;
|
needleFound = false;
|
||||||
for(j = 0; j < needleCount; j++) {
|
for(j = 0; j < needleCount; j++) {
|
||||||
if(c != needles[j]) continue;
|
if(c != needles[j]) continue;
|
||||||
needleFound = true;
|
needleFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!needleFound) break;
|
if(!needleFound) break;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fileGetDirectory(char *file, char* buffer) {
|
void fileGetDirectory(char *file, char* buffer) {
|
||||||
char *c, *p;
|
char *c, *p;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
p = strrchr(file, FILE_PATH_SEP);
|
p = strrchr(file, FILE_PATH_SEP);
|
||||||
c = file;
|
c = file;
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
buffer[i++] = *c;
|
buffer[i++] = *c;
|
||||||
} while(++c < p);
|
} while(++c < p);
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileListChildren(
|
bool fileListChildren(
|
||||||
char *directory,
|
char *directory,
|
||||||
char *buffer,
|
char *buffer,
|
||||||
int32_t *count,
|
int32_t *count,
|
||||||
uint8_t *types,
|
uint8_t *types,
|
||||||
char **children
|
char **children
|
||||||
) {
|
) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
WIN32_FIND_DATA fdFile;
|
WIN32_FIND_DATA fdFile;
|
||||||
HANDLE hFind = NULL;
|
HANDLE hFind = NULL;
|
||||||
char sPath[2048];
|
char sPath[2048];
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
// Append wildcard
|
// Append wildcard
|
||||||
sprintf(sPath, "%s\\*.*", directory);
|
sprintf(sPath, "%s\\*.*", directory);
|
||||||
|
|
||||||
// Scan first
|
// Scan first
|
||||||
if((hFind = FindFirstFile(sPath, &fdFile)) == INVALID_HANDLE_VALUE) {
|
if((hFind = FindFirstFile(sPath, &fdFile)) == INVALID_HANDLE_VALUE) {
|
||||||
printf("Path not found: [%s]\n", directory);
|
printf("Path not found: [%s]\n", directory);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate
|
// Iterate
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
if(
|
if(
|
||||||
strcmp(fdFile.cFileName, ".") == 0 ||
|
strcmp(fdFile.cFileName, ".") == 0 ||
|
||||||
strcmp(fdFile.cFileName, "..") == 0
|
strcmp(fdFile.cFileName, "..") == 0
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
// Get Full path.
|
// Get Full path.
|
||||||
sprintf(sPath, "%s\\%s", directory, fdFile.cFileName);
|
sprintf(sPath, "%s\\%s", directory, fdFile.cFileName);
|
||||||
|
|
||||||
//Is the entity a File or Folder?
|
//Is the entity a File or Folder?
|
||||||
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
types[i] = FILE_CHILD_TYPE_DIR;
|
types[i] = FILE_CHILD_TYPE_DIR;
|
||||||
} else {
|
} else {
|
||||||
types[i] = FILE_CHILD_TYPE_FILE;
|
types[i] = FILE_CHILD_TYPE_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
children[i] = buffer + (i * FILE_CHILD_NAME_MAX);
|
children[i] = buffer + (i * FILE_CHILD_NAME_MAX);
|
||||||
strcpy(children[i], fdFile.cFileName);
|
strcpy(children[i], fdFile.cFileName);
|
||||||
i++;
|
i++;
|
||||||
} while(FindNextFile(hFind, &fdFile));
|
} while(FindNextFile(hFind, &fdFile));
|
||||||
|
|
||||||
*count = i;
|
*count = i;
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
DIR *dr;
|
DIR *dr;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
// Open Dir
|
// Open Dir
|
||||||
dr = opendir(directory);
|
dr = opendir(directory);
|
||||||
if(dr == NULL) {
|
if(dr == NULL) {
|
||||||
printf("Could not open directory");
|
printf("Could not open directory");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Iterate
|
// Iterate
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((de = readdir(dr)) != NULL) {
|
while ((de = readdir(dr)) != NULL) {
|
||||||
// File or folder?
|
// File or folder?
|
||||||
if(de->d_type != DT_REG) continue;
|
if(de->d_type != DT_REG) continue;
|
||||||
|
|
||||||
// Copy into child buffer
|
// Copy into child buffer
|
||||||
children[i] = buffer + (i * FILE_CHILD_NAME_MAX);
|
children[i] = buffer + (i * FILE_CHILD_NAME_MAX);
|
||||||
strcpy(children[i], de->d_name);
|
strcpy(children[i], de->d_name);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if(closedir(dr)) return false;
|
if(closedir(dr)) return false;
|
||||||
|
|
||||||
*count = i;
|
*count = i;
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
@ -1,75 +1,75 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2021 Dominic Masters
|
* Copyright (c) 2021 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.hpp"
|
||||||
|
|
||||||
#define FILE_CHILD_TYPE_DIR 0x00
|
#define FILE_CHILD_TYPE_DIR 0x00
|
||||||
#define FILE_CHILD_TYPE_FILE 0x01
|
#define FILE_CHILD_TYPE_FILE 0x01
|
||||||
#define FILE_CHILD_NAME_MAX 512
|
#define FILE_CHILD_NAME_MAX 512
|
||||||
#define FILE_CHILD_COUNT_MAX 64
|
#define FILE_CHILD_COUNT_MAX 64
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define getcwd _getcwd
|
#define getcwd _getcwd
|
||||||
#define FILE_PATH_SEP '\\'
|
#define FILE_PATH_SEP '\\'
|
||||||
#define fileMkdir(path, perms) _mkdir(path)
|
#define fileMkdir(path, perms) _mkdir(path)
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#define FILE_PATH_SEP '/'
|
#define FILE_PATH_SEP '/'
|
||||||
#define fileMkdir(path, perms) mkdir(path, perms)
|
#define fileMkdir(path, perms) mkdir(path, perms)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fileNormalizeSlashes(char *string);
|
void fileNormalizeSlashes(char *string);
|
||||||
|
|
||||||
void fileMkdirp(char *path);
|
void fileMkdirp(char *path);
|
||||||
|
|
||||||
size_t assetReadString(FILE *file, char *buffer);
|
size_t assetReadString(FILE *file, char *buffer);
|
||||||
|
|
||||||
void fileGetDirectory(char *file, char* buffer);
|
void fileGetDirectory(char *file, char* buffer);
|
||||||
|
|
||||||
bool fileListChildren(
|
bool fileListChildren(
|
||||||
char *directory,
|
char *directory,
|
||||||
char *buffer,
|
char *buffer,
|
||||||
int32_t *count,
|
int32_t *count,
|
||||||
uint8_t *types,
|
uint8_t *types,
|
||||||
char **children
|
char **children
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads ahead to the first instance of the given character you provide.
|
* Reads ahead to the first instance of the given character you provide.
|
||||||
*
|
*
|
||||||
* @param bufferIn Buffer to scan.
|
* @param bufferIn Buffer to scan.
|
||||||
* @param start Start position within the buffer to scan from (inclusive).
|
* @param start Start position within the buffer to scan from (inclusive).
|
||||||
* @param bufferOut Where to write the temporary data that was read ahead.
|
* @param bufferOut Where to write the temporary data that was read ahead.
|
||||||
* @param needles Array of characters to scan for.
|
* @param needles Array of characters to scan for.
|
||||||
* @param needleCount How many elements are within the needles array.
|
* @param needleCount How many elements are within the needles array.
|
||||||
* @return The count of characters skipped.
|
* @return The count of characters skipped.
|
||||||
*/
|
*/
|
||||||
int32_t readAhead(
|
int32_t readAhead(
|
||||||
char *bufferIn, int32_t start,
|
char *bufferIn, int32_t start,
|
||||||
char *bufferOut,
|
char *bufferOut,
|
||||||
char *needles, int32_t needleCount
|
char *needles, int32_t needleCount
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips any characters found in the needles.
|
* Skips any characters found in the needles.
|
||||||
*
|
*
|
||||||
* @param bufferIn Buffer of chars to read.
|
* @param bufferIn Buffer of chars to read.
|
||||||
* @param start Start of the buffer.
|
* @param start Start of the buffer.
|
||||||
* @param needles Needles you are trying to skip.
|
* @param needles Needles you are trying to skip.
|
||||||
* @param needleCount Count of needles in the needles array.
|
* @param needleCount Count of needles in the needles array.
|
||||||
* @return The count of chars to skip ahead.
|
* @return The count of chars to skip ahead.
|
||||||
*/
|
*/
|
||||||
int32_t skipAhead(
|
int32_t skipAhead(
|
||||||
char *bufferIn, int32_t start,
|
char *bufferIn, int32_t start,
|
||||||
char *needles, int32_t needleCount
|
char *needles, int32_t needleCount
|
||||||
);
|
);
|
@ -1,55 +1,55 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2021 Dominic Masters
|
* Copyright (c) 2021 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "image.h"
|
#include "image.hpp"
|
||||||
|
|
||||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STB_IMAGE_RESIZE_IMPLEMENTATION
|
#ifndef STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||||
#include <stb_image_resize.h>
|
#include <stb_image_resize.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STB_IMAGE_WRITE_IMPLEMENTATION
|
#ifndef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void imageCopy(
|
void imageCopy(
|
||||||
uint8_t *source, int32_t sourceWidth, int32_t sourceHeight,
|
uint8_t *source, int32_t sourceWidth, int32_t sourceHeight,
|
||||||
uint8_t *dest, int32_t destWidth, int32_t destHeight,
|
uint8_t *dest, int32_t destWidth, int32_t destHeight,
|
||||||
int32_t cropX, int32_t cropY, int32_t cropWidth, int32_t cropHeight,
|
int32_t cropX, int32_t cropY, int32_t cropWidth, int32_t cropHeight,
|
||||||
int32_t pasteX, int32_t pasteY,
|
int32_t pasteX, int32_t pasteY,
|
||||||
int32_t channels
|
int32_t channels
|
||||||
) {
|
) {
|
||||||
int32_t x, y, c;
|
int32_t x, y, c;
|
||||||
int32_t absX, absY;
|
int32_t absX, absY;
|
||||||
int32_t sourceIndex, targetIndex;
|
int32_t sourceIndex, targetIndex;
|
||||||
|
|
||||||
if(cropX == -1) cropX = 0;
|
if(cropX == -1) cropX = 0;
|
||||||
if(cropY == -1) cropY = 0;
|
if(cropY == -1) cropY = 0;
|
||||||
if(cropWidth == -1) cropWidth = sourceWidth;
|
if(cropWidth == -1) cropWidth = sourceWidth;
|
||||||
if(cropHeight == -1) cropHeight = sourceHeight;
|
if(cropHeight == -1) cropHeight = sourceHeight;
|
||||||
if(pasteX == -1) pasteX = 0;
|
if(pasteX == -1) pasteX = 0;
|
||||||
if(pasteY == -1) pasteY = 0;
|
if(pasteY == -1) pasteY = 0;
|
||||||
|
|
||||||
for(x = cropX; x < cropX + cropWidth; x++) {
|
for(x = cropX; x < cropX + cropWidth; x++) {
|
||||||
for(y = cropY; y < cropY + cropHeight; y++) {
|
for(y = cropY; y < cropY + cropHeight; y++) {
|
||||||
absX = x - cropX + pasteX;
|
absX = x - cropX + pasteX;
|
||||||
absY = y - cropY + pasteY;
|
absY = y - cropY + pasteY;
|
||||||
if(absX >= destWidth || absY >= destHeight || absX < 0 || absY < 0)continue;
|
if(absX >= destWidth || absY >= destHeight || absX < 0 || absY < 0)continue;
|
||||||
targetIndex = absY * destWidth + absX;
|
targetIndex = absY * destWidth + absX;
|
||||||
sourceIndex = y * sourceWidth + x;
|
sourceIndex = y * sourceWidth + x;
|
||||||
for(c = 0; c < channels; c++) {
|
for(c = 0; c < channels; c++) {
|
||||||
dest[(targetIndex*channels) + c] = source[(sourceIndex*channels) + c];
|
dest[(targetIndex*channels) + c] = source[(sourceIndex*channels) + c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,22 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2021 Dominic Masters
|
* Copyright (c) 2021 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.hpp"
|
||||||
#include "file.h"
|
#include "file.hpp"
|
||||||
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#include <stb_image_resize.h>
|
#include <stb_image_resize.h>
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
|
|
||||||
void imageCopy(
|
void imageCopy(
|
||||||
uint8_t *source, int32_t sourceWidth, int32_t sourceHeight,
|
uint8_t *source, int32_t sourceWidth, int32_t sourceHeight,
|
||||||
uint8_t *dest, int32_t destWidth, int32_t destHeight,
|
uint8_t *dest, int32_t destWidth, int32_t destHeight,
|
||||||
int32_t cropX, int32_t cropY, int32_t cropWidth, int32_t cropHeight,
|
int32_t cropX, int32_t cropY, int32_t cropWidth, int32_t cropHeight,
|
||||||
int32_t pasteX, int32_t pasteY,
|
int32_t pasteX, int32_t pasteY,
|
||||||
int32_t channels
|
int32_t channels
|
||||||
);
|
);
|
@ -1,30 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2023 Dominic Masters
|
* Copyright (c) 2023 Dominic Masters
|
||||||
*
|
*
|
||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.hpp"
|
||||||
|
|
||||||
static inline void stringRemoveAll(char *string, char remove) {
|
static inline void stringRemoveAll(char *string, char remove) {
|
||||||
size_t len = strlen(string);
|
size_t len = strlen(string);
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while(i < len) {
|
while(i < len) {
|
||||||
char c = string[i];
|
char c = string[i];
|
||||||
if(c != remove) {
|
if(c != remove) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
j = i + 1;
|
j = i + 1;
|
||||||
while(j < len) {
|
while(j < len) {
|
||||||
string[j-1] = string[j];
|
string[j-1] = string[j];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xml.h"
|
#include "xml.hpp"
|
||||||
|
|
||||||
int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
||||||
char c;
|
char c;
|
||||||
@ -13,13 +13,13 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
uint8_t doing = XML_DOING_NOTHING;
|
uint8_t doing = XML_DOING_NOTHING;
|
||||||
uint8_t doingBeforeComment;
|
uint8_t doingBeforeComment;
|
||||||
bool insideTag = false;
|
bool insideTag = false;
|
||||||
char* buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
char* buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
int32_t bufferLength = 0;
|
int32_t bufferLength = 0;
|
||||||
|
|
||||||
xml->value = NULL;
|
xml->value = NULL;
|
||||||
xml->attributeCount = 0;
|
xml->attributeCount = 0;
|
||||||
|
|
||||||
xml->children = malloc(sizeof(xml_t) * XML_CHILD_COUNT_MAX);
|
xml->children = (xml_t *)malloc(sizeof(xml_t) * XML_CHILD_COUNT_MAX);
|
||||||
xml->childrenCount = 0;
|
xml->childrenCount = 0;
|
||||||
|
|
||||||
while(c = data[i++]) {
|
while(c = data[i++]) {
|
||||||
@ -54,7 +54,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
if(xmlIsWhitespace(c) || c == '>' || c == '/') {
|
if(xmlIsWhitespace(c) || c == '>' || c == '/') {
|
||||||
buffer[bufferLength] = '\0';
|
buffer[bufferLength] = '\0';
|
||||||
xml->node = buffer;
|
xml->node = buffer;
|
||||||
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
bufferLength = 0;
|
bufferLength = 0;
|
||||||
if(c == '/') {
|
if(c == '/') {
|
||||||
level--;
|
level--;
|
||||||
@ -88,7 +88,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
buffer[bufferLength] = '\0';
|
buffer[bufferLength] = '\0';
|
||||||
xml->attributeNames[xml->attributeCount++] = buffer;
|
xml->attributeNames[xml->attributeCount++] = buffer;
|
||||||
xml->attributeDatas[xml->attributeCount] = NULL;
|
xml->attributeDatas[xml->attributeCount] = NULL;
|
||||||
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
bufferLength = 0;
|
bufferLength = 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -116,7 +116,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
doing = XML_LOOKING_FOR_ATTRIBUTE;
|
doing = XML_LOOKING_FOR_ATTRIBUTE;
|
||||||
buffer[bufferLength] = '\0';
|
buffer[bufferLength] = '\0';
|
||||||
xml->attributeDatas[xml->attributeCount - 1] = buffer;
|
xml->attributeDatas[xml->attributeCount - 1] = buffer;
|
||||||
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
bufferLength = 0;
|
bufferLength = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
|
|||||||
buffer[bufferLength] = '\0';
|
buffer[bufferLength] = '\0';
|
||||||
bufferLength = 0;
|
bufferLength = 0;
|
||||||
xml->value = buffer;
|
xml->value = buffer;
|
||||||
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.hpp"
|
||||||
#include "file.h"
|
#include "file.hpp"
|
||||||
|
|
||||||
#define XML_DOING_NOTHING 0x00
|
#define XML_DOING_NOTHING 0x00
|
||||||
#define XML_PARSING_TAG_NAME 0x01
|
#define XML_PARSING_TAG_NAME 0x01
|
@ -9,11 +9,12 @@ add_executable(vnscenegen)
|
|||||||
target_sources(vnscenegen
|
target_sources(vnscenegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.cpp
|
||||||
../../utils/xml.c
|
../../utils/xml.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(vnscenegen
|
target_include_directories(vnscenegen
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
${DAWN_SHARED_INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
@ -3,11 +3,8 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
extern "C" {
|
#include "../../utils/file.hpp"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/xml.hpp"
|
||||||
#include "../../utils/xml.h"
|
|
||||||
#include <memory.h>
|
|
||||||
}
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user