Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 16:35:35 +01:00
parent 91f77ed210
commit 142aa827d2
29 changed files with 512 additions and 366 deletions

67
.clang-format Normal file
View File

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,8 +6,16 @@ on:
- main - main
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request] on: [pull_request]
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/RPXLoadingModule/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/RPXLoadingModule/actions/workflows/ci.yml)
## Usage ## Usage
(`[ENVIRONMENT]` is a placeholder for the actual environment name.) (`[ENVIRONMENT]` is a placeholder for the actual environment name.)
@ -18,3 +20,7 @@ docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make
# make clean # make clean
docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make clean docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make clean
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i`

View File

@ -1,10 +1,10 @@
#include "FSDirReplacements.h" #include "FSDirReplacements.h"
#include <coreinit/filesystem.h>
#include <coreinit/cache.h>
#include "utils/logger.h"
#include "globals.h"
#include "FSWrapper.h" #include "FSWrapper.h"
#include "FileUtils.h" #include "FileUtils.h"
#include "globals.h"
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <coreinit/filesystem.h>
#define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \ #define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \
return res; \ return res; \
@ -17,9 +17,9 @@
DECL_FUNCTION(FSStatus, FSOpenDir, FSClient *client, FSCmdBlock *block, char *path, FSDirectoryHandle *handle, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSOpenDir, FSClient *client, FSCmdBlock *block, char *path, FSDirectoryHandle *handle, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenDirWrapper(path, handle, errorMask, FSStatus result = FSOpenDirWrapper(
[client, block, handle, errorMask] path, handle, errorMask,
(char *_path) -> FSStatus { [client, block, handle, errorMask](char *_path) -> FSStatus {
return real_FSOpenDir(client, block, _path, handle, errorMask); return real_FSOpenDir(client, block, _path, handle, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
@ -37,9 +37,9 @@ DECL_FUNCTION(FSStatus, FSOpenDirAsync, FSClient *client, FSCmdBlock *block, cha
// Even real_FSOpenDir is still calling our FSOpenDirAsync hook. To bypass our code we use "FORCE_REAL_FUNC_WITH_FULL_ERRORS" as an errorMask. // Even real_FSOpenDir is still calling our FSOpenDirAsync hook. To bypass our code we use "FORCE_REAL_FUNC_WITH_FULL_ERRORS" as an errorMask.
if ((errorMask & ERROR_FLAG_MASK) != FORCE_REAL_FUNC_MAGIC) { if ((errorMask & ERROR_FLAG_MASK) != FORCE_REAL_FUNC_MAGIC) {
FSStatus result = FSOpenDirWrapper(path, handle, errorMask, FSStatus result = FSOpenDirWrapper(
[client, block, handle, errorMask, asyncData] path, handle, errorMask,
(char *_path) -> FSStatus { [client, block, handle, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSOpenDirAsync(client, block, _path, handle, errorMask, asyncData); return real_FSOpenDirAsync(client, block, _path, handle, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
@ -133,9 +133,9 @@ DECL_FUNCTION(FSStatus, FSRewindDirAsync, FSClient *client, FSCmdBlock *block, F
DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSMakeDirWrapper(path, errorMask, FSStatus result = FSMakeDirWrapper(
[client, block, errorMask] path, errorMask,
(char *_path) -> FSStatus { [client, block, errorMask](char *_path) -> FSStatus {
return real_FSMakeDir(client, block, _path, errorMask); return real_FSMakeDir(client, block, _path, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
@ -148,9 +148,9 @@ DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *pa
DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSMakeDirWrapper(path, errorMask, FSStatus result = FSMakeDirWrapper(
[client, block, errorMask, asyncData] path, errorMask,
(char *_path) -> FSStatus { [client, block, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSMakeDirAsync(client, block, _path, errorMask, asyncData); return real_FSMakeDirAsync(client, block, _path, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
@ -163,7 +163,7 @@ DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, cha
DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, const char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, const char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("FSChangeDirAsync %s", path); DEBUG_FUNCTION_LINE_VERBOSE("FSChangeDirAsync %s", path);
snprintf(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir), "%s", path); snprintf(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir), "%s", path);
int len = strlen(gReplacementInfo.contentReplacementInfo.workingDir); auto len = strlen(gReplacementInfo.contentReplacementInfo.workingDir);
if (len > 0 && gReplacementInfo.contentReplacementInfo.workingDir[len - 1] != '/') { if (len > 0 && gReplacementInfo.contentReplacementInfo.workingDir[len - 1] != '/') {
gReplacementInfo.contentReplacementInfo.workingDir[len - 1] = '/'; gReplacementInfo.contentReplacementInfo.workingDir[len - 1] = '/';
gReplacementInfo.contentReplacementInfo.workingDir[len] = 0; gReplacementInfo.contentReplacementInfo.workingDir[len] = 0;

View File

@ -13,4 +13,3 @@ extern uint32_t fs_dir_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -4,23 +4,23 @@
#include <coreinit/dynload.h> #include <coreinit/dynload.h>
#include <cstring> #include <cstring>
#include "utils/logger.h"
#include "FileUtils.h"
#include "FSWrapper.h" #include "FSWrapper.h"
#include "FileUtils.h"
#include "utils/logger.h"
#define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \ #define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \
return res; \ return res; \
} }
#define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \ #define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \
return send_result_async(client, block, asyncData, res);\ return send_result_async(client, block, asyncData, res); \
} }
DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenFileWrapper(path, mode, handle, errorMask, FSStatus result = FSOpenFileWrapper(
[client, block, mode, handle, errorMask] path, mode, handle, errorMask,
(char *_path) -> FSStatus { [client, block, mode, handle, errorMask](char *_path) -> FSStatus {
return real_FSOpenFile(client, block, _path, mode, handle, errorMask); return real_FSOpenFile(client, block, _path, mode, handle, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
@ -34,9 +34,9 @@ DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *p
DECL_FUNCTION(FSStatus, FSOpenFileAsync, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSOpenFileAsync, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenFileWrapper(path, mode, handle, errorMask, FSStatus result = FSOpenFileWrapper(
[client, block, mode, handle, errorMask, asyncData] path, mode, handle, errorMask,
(char *_path) -> FSStatus { [client, block, mode, handle, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSOpenFileAsync(client, block, _path, mode, handle, errorMask, asyncData); return real_FSOpenFileAsync(client, block, _path, mode, handle, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
@ -70,7 +70,8 @@ DECL_FUNCTION(FSStatus, FSCloseFileAsync, FSClient *client, FSCmdBlock *block, F
DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSGetStatWrapper(path, stats, errorMask, FSStatus result = FSGetStatWrapper(
path, stats, errorMask,
[client, block, stats, errorMask](char *_path) -> FSStatus { [client, block, stats, errorMask](char *_path) -> FSStatus {
return real_FSGetStat(client, block, _path, stats, errorMask); return real_FSGetStat(client, block, _path, stats, errorMask);
}, },
@ -83,7 +84,8 @@ DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *pa
DECL_FUNCTION(FSStatus, FSGetStatAsync, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSGetStatAsync, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSGetStatWrapper(path, stats, errorMask, FSStatus result = FSGetStatWrapper(
path, stats, errorMask,
[client, block, stats, errorMask, asyncData](char *_path) -> FSStatus { [client, block, stats, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSGetStatAsync(client, block, _path, stats, errorMask, asyncData); return real_FSGetStatAsync(client, block, _path, stats, errorMask, asyncData);
}, },
@ -257,7 +259,8 @@ DECL_FUNCTION(FSStatus, FSTruncateFileAsync, FSClient *client, FSCmdBlock *block
DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSRemoveWrapper(path, errorMask, FSStatus result = FSRemoveWrapper(
path, errorMask,
[client, block, errorMask](char *_path) -> FSStatus { [client, block, errorMask](char *_path) -> FSStatus {
return real_FSRemove(client, block, _path, errorMask); return real_FSRemove(client, block, _path, errorMask);
}, },
@ -271,7 +274,8 @@ DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *pat
DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSRemoveWrapper(path, errorMask, FSStatus result = FSRemoveWrapper(
path, errorMask,
[client, block, errorMask, asyncData](char *_path) -> FSStatus { [client, block, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSRemoveAsync(client, block, _path, errorMask, asyncData); return real_FSRemoveAsync(client, block, _path, errorMask, asyncData);
}, },
@ -285,7 +289,8 @@ DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char
DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath); DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath);
FSStatus result = FSRenameWrapper(oldPath, newPath, errorMask, FSStatus result = FSRenameWrapper(
oldPath, newPath, errorMask,
[client, block, errorMask](char *_oldOath, char *_newPath) -> FSStatus { [client, block, errorMask](char *_oldOath, char *_newPath) -> FSStatus {
return real_FSRename(client, block, _oldOath, _newPath, errorMask); return real_FSRename(client, block, _oldOath, _newPath, errorMask);
}, },
@ -299,7 +304,8 @@ DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *old
DECL_FUNCTION(FSStatus, FSRenameAsync, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSRenameAsync, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath); DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath);
FSStatus result = FSRenameWrapper(oldPath, newPath, errorMask, FSStatus result = FSRenameWrapper(
oldPath, newPath, errorMask,
[client, block, errorMask, asyncData](char *_oldOath, char *_newPath) -> FSStatus { [client, block, errorMask, asyncData](char *_oldOath, char *_newPath) -> FSStatus {
return real_FSRenameAsync(client, block, _oldOath, _newPath, errorMask, asyncData); return real_FSRenameAsync(client, block, _oldOath, _newPath, errorMask, asyncData);
}, },

View File

@ -13,4 +13,3 @@ extern uint32_t fs_file_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,15 +1,15 @@
#include "FSWrapper.h" #include "FSWrapper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <cstring>
#include <mutex>
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include "utils/logger.h"
#include "FileUtils.h" #include "FileUtils.h"
#include "globals.h" #include "globals.h"
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <cstring>
#include <fcntl.h>
#include <mutex>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
dirMagic_t dir_handles[DIR_HANDLES_LENGTH]; dirMagic_t dir_handles[DIR_HANDLES_LENGTH];
fileMagic_t file_handles[FILE_HANDLES_LENGTH]; fileMagic_t file_handles[FILE_HANDLES_LENGTH];
@ -59,10 +59,10 @@ int getNewFileHandleIndex() {
handle_id = i; handle_id = i;
if (!file_handles[i].mutex) { if (!file_handles[i].mutex) {
file_handles[i].mutex = (OSMutex *) malloc(sizeof(OSMutex)); file_handles[i].mutex = (OSMutex *) malloc(sizeof(OSMutex));
OSInitMutex(file_handles[i].mutex);
if (!file_handles[i].mutex) { if (!file_handles[i].mutex) {
OSFatal("Failed to alloc memory for mutex"); OSFatal("Failed to alloc memory for mutex");
} }
OSInitMutex(file_handles[i].mutex);
DCFlushRange(file_handles[i].mutex, sizeof(OSMutex)); DCFlushRange(file_handles[i].mutex, sizeof(OSMutex));
DCFlushRange(&file_handles[i], sizeof(fileMagic_t)); DCFlushRange(&file_handles[i], sizeof(fileMagic_t));
} }
@ -269,7 +269,7 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle,
if (strcmp(entry_->d_name, ".") == 0 || strcmp(entry_->d_name, "..") == 0) { if (strcmp(entry_->d_name, ".") == 0 || strcmp(entry_->d_name, "..") == 0) {
entry->info.size = 0; entry->info.size = 0;
} else { } else {
struct stat sb{}; struct stat sb {};
int strLen = strlen(dir_handles[handle_index].path) + 1 + strlen(entry_->d_name) + 1; int strLen = strlen(dir_handles[handle_index].path) + 1 + strlen(entry_->d_name) + 1;
char path[strLen]; char path[strLen];
snprintf(path, sizeof(path), "%s/%s", dir_handles[handle_index].path, entry_->d_name); snprintf(path, sizeof(path), "%s/%s", dir_handles[handle_index].path, entry_->d_name);
@ -634,7 +634,7 @@ FSStatus FSGetStatWrapper(char *path, FSStat *stats, FSErrorFlag errorMask,
DEBUG_FUNCTION_LINE("Invalid args"); DEBUG_FUNCTION_LINE("Invalid args");
return FS_STATUS_FATAL_ERROR; return FS_STATUS_FATAL_ERROR;
} else { } else {
struct stat path_stat{}; struct stat path_stat {};
memset(&path_stat, 0, sizeof(path_stat)); memset(&path_stat, 0, sizeof(path_stat));
if (stat(pathForCheck, &path_stat) < 0) { if (stat(pathForCheck, &path_stat) < 0) {
if (gReplacementInfo.contentReplacementInfo.fallbackOnError) { if (gReplacementInfo.contentReplacementInfo.fallbackOnError) {
@ -698,7 +698,7 @@ FSStatus FSGetStatFileWrapper(FSFileHandle handle,
int real_fd = file_handles[handle_index].fd; int real_fd = file_handles[handle_index].fd;
//DEBUG_FUNCTION_LINE("FSGetStatFileAsync real_fd %d", real_fd); //DEBUG_FUNCTION_LINE("FSGetStatFileAsync real_fd %d", real_fd);
struct stat path_stat{}; struct stat path_stat {};
FSStatus result = FS_STATUS_OK; FSStatus result = FS_STATUS_OK;
if (fstat(real_fd, &path_stat) < 0) { if (fstat(real_fd, &path_stat) < 0) {
@ -779,14 +779,12 @@ FSStatus FSReadFileWithPosWrapper(void *buffer,
FSStatus result; FSStatus result;
if ((result = FSSetPosFileWrapper(handle, pos, errorMask, if ((result = FSSetPosFileWrapper(handle, pos, errorMask,
[](FSStatus res) -> FSStatus { return res; }) [](FSStatus res) -> FSStatus { return res; })) != FS_STATUS_OK) {
) != FS_STATUS_OK) {
return result; return result;
} }
result = FSReadFileWrapper(buffer, size, count, handle, unk1, errorMask, result = FSReadFileWrapper(buffer, size, count, handle, unk1, errorMask,
[](FSStatus res) -> FSStatus { return res; } [](FSStatus res) -> FSStatus { return res; });
);
if (result != FS_STATUS_USE_REAL_OS && result != FS_STATUS_FATAL_ERROR) { if (result != FS_STATUS_USE_REAL_OS && result != FS_STATUS_FATAL_ERROR) {
return result_handler(result); return result_handler(result);

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
#include <cstdint> #include <cstdint>
#include <dirent.h> #include <dirent.h>
#include <functional> #include <functional>
#include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
typedef struct dirMagic { typedef struct dirMagic {
uint32_t handle{}; uint32_t handle{};

View File

@ -1,18 +1,18 @@
#include "FileUtils.h" #include "FileUtils.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <mutex> #include <mutex>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "utils/StringTools.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <map>
#include <coreinit/thread.h> #include <coreinit/thread.h>
#include <dirent.h> #include <dirent.h>
#include <coreinit/cache.h> #include <map>
#include "utils/StringTools.h"
#include "utils/utils.h"
#include "utils/logger.h"
extern "C" OSMessageQueue *OSGetDefaultAppIOQueue(); extern "C" OSMessageQueue *OSGetDefaultAppIOQueue();
@ -52,7 +52,7 @@ FSStatus send_result_async(FSClient *client, FSCmdBlock *block, FSAsyncData *asy
result->block = block; result->block = block;
result->status = status; result->status = status;
while (!OSSendMessage(asyncData->ioMsgQueue, (OSMessage * ) & (result->ioMsg), OS_MESSAGE_FLAGS_NONE)) { while (!OSSendMessage(asyncData->ioMsgQueue, (OSMessage *) &(result->ioMsg), OS_MESSAGE_FLAGS_NONE)) {
DEBUG_FUNCTION_LINE("Failed to send message"); DEBUG_FUNCTION_LINE("Failed to send message");
} }
} }
@ -96,7 +96,7 @@ int32_t CheckFile(const char *filepath) {
return 0; return 0;
} }
struct stat filestat{}; struct stat filestat {};
char dirnoslash[strlen(filepath) + 2]; char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
@ -142,7 +142,7 @@ int32_t CreateSubfolder(const char *fullpath) {
if (!ptr) { if (!ptr) {
//!Device root directory (must be with '/') //!Device root directory (must be with '/')
strcat(parentpath, "/"); strcat(parentpath, "/");
struct stat filestat{}; struct stat filestat {};
if (stat(parentpath, &filestat) == 0) { if (stat(parentpath, &filestat) == 0) {
return 1; return 1;
} }

View File

@ -1,14 +1,13 @@
#pragma once #pragma once
#include <string>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
#include <romfs_dev.h> #include <romfs_dev.h>
#include <string>
struct WUT_PACKED FSCmdBlockBody {//! FSAsyncResult object used for this command. struct WUT_PACKED FSCmdBlockBody { //! FSAsyncResult object used for this command.
WUT_UNKNOWN_BYTES(0x96C); WUT_UNKNOWN_BYTES(0x96C);
FSAsyncResult asyncResult; FSAsyncResult asyncResult;
}; };
WUT_CHECK_OFFSET(FSCmdBlockBody, 0x96C, asyncResult); WUT_CHECK_OFFSET(FSCmdBlockBody, 0x96C, asyncResult);
WUT_CHECK_SIZE(FSCmdBlockBody, 0x96C + 0x28); WUT_CHECK_SIZE(FSCmdBlockBody, 0x96C + 0x28);

View File

@ -1,21 +1,21 @@
#include <string>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <romfs_dev.h>
#include "utils/logger.h"
#include "RPXLoading.h" #include "RPXLoading.h"
#include "globals.h"
#include "FileUtils.h" #include "FileUtils.h"
#include <nn/acp/title.h> #include "globals.h"
#include <memory>
#include <algorithm>
#include "utils/FileReader.h" #include "utils/FileReader.h"
#include "utils/FileReaderCompressed.h" #include "utils/FileReaderCompressed.h"
#include "utils/StringTools.h" #include "utils/StringTools.h"
#include "utils/ini.h" #include "utils/ini.h"
#include "utils/logger.h"
#include <algorithm>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <cstring> #include <cstring>
#include <rpxloader.h>
#include <dirent.h> #include <dirent.h>
#include <memory>
#include <nn/acp/title.h>
#include <romfs_dev.h>
#include <rpxloader.h>
#include <string>
/* /*
* Patch the meta xml for the home menu * Patch the meta xml for the home menu
@ -57,7 +57,6 @@ DECL_FUNCTION(FSStatus, RPX_FSReadFile, FSClient *client, FSCmdBlock *block, uin
if ((handle & 0xF0000000) == 0x80000000) { if ((handle & 0xF0000000) == 0x80000000) {
auto reader = (FileReader *) handle; auto reader = (FileReader *) handle;
return (FSStatus) reader->read(buffer, size * count); return (FSStatus) reader->read(buffer, size * count);
} }
FSStatus result = real_RPX_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); FSStatus result = real_RPX_FSReadFile(client, block, buffer, size, count, handle, unk1, flags);
return result; return result;
@ -180,7 +179,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
request.path[0] = '\0'; request.path[0] = '\0';
strncat(request.path, bundle_path, sizeof(request.path) - 1); strncat(request.path, bundle_path, sizeof(request.path) - 1);
DCFlushRange(&request, sizeof(LOAD_REQUEST)); DCFlushRange(&request, sizeof(request));
int success = false; int success = false;
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <function_patcher/function_patching.h>
#include <cstdint> #include <cstdint>
#include <function_patcher/function_patching.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -21,5 +21,3 @@ extern uint32_t rpx_utils_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,5 +1,5 @@
#include <coreinit/filesystem.h>
#include "globals.h" #include "globals.h"
#include <coreinit/filesystem.h>
RPXLoader_ReplacementInformation gReplacementInfo __attribute__((section(".data"))); RPXLoader_ReplacementInformation gReplacementInfo __attribute__((section(".data")));

View File

@ -1,6 +1,6 @@
#include <wums.h>
#include <coreinit/mutex.h>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
#include <wums.h>
typedef struct MetaInformation_t { typedef struct MetaInformation_t {
char shortname[64]; char shortname[64];

View File

@ -1,22 +1,22 @@
#include <wums.h>
#include <cstring> #include <cstring>
#include <malloc.h> #include <malloc.h>
#include <wums.h>
#include "FSDirReplacements.h"
#include "FSFileReplacements.h"
#include "FileUtils.h"
#include "RPXLoading.h"
#include "globals.h"
#include "utils/StringTools.h"
#include "utils/logger.h"
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/title.h> #include <coreinit/title.h>
#include <sysapp/title.h>
#include <string> #include <string>
#include "utils/logger.h" #include <sysapp/title.h>
#include "utils/StringTools.h"
#include "FSFileReplacements.h"
#include "globals.h"
#include "FileUtils.h"
#include "FSDirReplacements.h"
#include "RPXLoading.h"
#include <romfs_dev.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <nn/act.h> #include <nn/act.h>
#include <romfs_dev.h>
WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader"); WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader");
WUMS_USE_WUT_DEVOPTAB(); WUMS_USE_WUT_DEVOPTAB();
@ -100,12 +100,12 @@ WUMS_APPLICATION_STARTS() {
uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath);
nn::act::Initialize(); nn::act::Initialize();
nn::act::PersistentId slot = nn::act::GetPersistentId(); nn::act::PersistentId persistentId = nn::act::GetPersistentId();
nn::act::Finalize(); nn::act::Finalize();
std::string basePath = StringTools::strfmt("/vol/external01/wiiu/apps/save/%08X", currentHash); std::string basePath = StringTools::strfmt("/vol/external01/wiiu/apps/save/%08X", currentHash);
std::string common = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/common", currentHash); std::string common = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/common", currentHash);
std::string user = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | slot); std::string user = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | persistentId);
gReplacementInfo.contentReplacementInfo.savePath[0] = '\0'; gReplacementInfo.contentReplacementInfo.savePath[0] = '\0';
strncat(gReplacementInfo.contentReplacementInfo.savePath, strncat(gReplacementInfo.contentReplacementInfo.savePath,
@ -140,4 +140,3 @@ WUMS_APPLICATION_STARTS() {
DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo));
} }
} }

View File

@ -14,7 +14,7 @@ int FileReader::read(uint8_t *buffer, uint32_t size) {
if (toRead == 0) { if (toRead == 0) {
return 0; return 0;
} }
memcpy(buffer, input_buffer + input_pos, toRead); memcpy(buffer, &input_buffer[input_pos], toRead);
input_pos += toRead; input_pos += toRead;
return toRead; return toRead;
} else if (isReadFromFile) { } else if (isReadFromFile) {

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
class FileReader { class FileReader {

View File

@ -55,7 +55,7 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
} }
nextOut = BUFFER_SIZE; nextOut = BUFFER_SIZE;
if (newSize + nextOut >= (size)) { if (newSize + nextOut >= (size)) {
nextOut = (size) - newSize; nextOut = (size) -newSize;
} }
} while (this->strm.avail_out == 0 && newSize < (size)); } while (this->strm.avail_out == 0 && newSize < (size));

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <zlib.h>
#include "FileReader.h" #include "FileReader.h"
#include "logger.h" #include "logger.h"
#include <zlib.h>
#define BUFFER_SIZE 0x20000 #define BUFFER_SIZE 0x20000
@ -12,8 +12,7 @@ public:
explicit FileReaderCompressed(std::string &file); explicit FileReaderCompressed(std::string &file);
~FileReaderCompressed() override { ~FileReaderCompressed() override = default;
}
int read(uint8_t *buffer, uint32_t size) override; int read(uint8_t *buffer, uint32_t size) override;

View File

@ -23,22 +23,22 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <string.h>
#include <wchar.h> #include <string>
#include <strings.h> #include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <utils/StringTools.h> #include <utils/StringTools.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
if (b.size() > a.size()) if (b.size() > a.size()) {
return false; return false;
}
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
} }
@ -301,4 +301,3 @@ uint32_t StringTools::hash(char *str) {
} }
return h; // or, h % ARRAY_SIZE; return h; // or, h % ARRAY_SIZE;
} }

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H #ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H #define __STRING_TOOLS_H
#include <vector>
#include <string> #include <string>
#include <vector>
#include <wut_types.h> #include <wut_types.h>
class StringTools { class StringTools {
@ -64,4 +64,3 @@ public:
}; };
#endif /* __STRING_TOOLS_H */ #endif /* __STRING_TOOLS_H */

View File

@ -1,12 +1,16 @@
/* inih -- simple .INI file parser /* inih -- simple .INI file parser
SPDX-License-Identifier: BSD-3-Clause
Copyright (C) 2009-2020, Ben Hoyt
inih is released under the New BSD license (see LICENSE.txt). Go to the project inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info: home page for more info:
https://github.com/benhoyt/inih https://github.com/benhoyt/inih
*/ */
// clang-format off
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
@ -18,9 +22,17 @@ https://github.com/benhoyt/inih
#include "ini.h" #include "ini.h"
#if !INI_USE_STACK #if !INI_USE_STACK
#if INI_CUSTOM_ALLOCATOR
#include <stddef.h>
void* ini_malloc(size_t size);
void ini_free(void* ptr);
void* ini_realloc(void* ptr, size_t size);
#else
#include <stdlib.h> #include <stdlib.h>
#define ini_malloc malloc
#define ini_free free
#define ini_realloc realloc
#endif
#endif #endif
#define MAX_SECTION 50 #define MAX_SECTION 50
@ -28,34 +40,37 @@ https://github.com/benhoyt/inih
/* Used by ini_parse_string() to keep track of string parsing state. */ /* Used by ini_parse_string() to keep track of string parsing state. */
typedef struct { typedef struct {
const char *ptr; const char* ptr;
size_t num_left; size_t num_left;
} ini_parse_string_ctx; } ini_parse_string_ctx;
/* Strip whitespace chars off end of given string, in place. Return s. */ /* Strip whitespace chars off end of given string, in place. Return s. */
static char *rstrip(char *s) { static char* rstrip(char* s)
char *p = s + strlen(s); {
while (p > s && isspace((unsigned char) (*--p))) char* p = s + strlen(s);
while (p > s && isspace((unsigned char)(*--p)))
*p = '\0'; *p = '\0';
return s; return s;
} }
/* Return pointer to first non-whitespace char in given string. */ /* Return pointer to first non-whitespace char in given string. */
static char *lskip(const char *s) { static char* lskip(const char* s)
while (*s && isspace((unsigned char) (*s))) {
while (*s && isspace((unsigned char)(*s)))
s++; s++;
return (char *) s; return (char*)s;
} }
/* Return pointer to first char (of chars) or inline comment in given string, /* Return pointer to first char (of chars) or inline comment in given string,
or pointer to null at end of string if neither found. Inline comment must or pointer to NUL at end of string if neither found. Inline comment must
be prefixed by a whitespace character to register as a comment. */ be prefixed by a whitespace character to register as a comment. */
static char *find_chars_or_comment(const char *s, const char *chars) { static char* find_chars_or_comment(const char* s, const char* chars)
{
#if INI_ALLOW_INLINE_COMMENTS #if INI_ALLOW_INLINE_COMMENTS
int was_space = 0; int was_space = 0;
while (*s && (!chars || !strchr(chars, *s)) && while (*s && (!chars || !strchr(chars, *s)) &&
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
was_space = isspace((unsigned char) (*s)); was_space = isspace((unsigned char)(*s));
s++; s++;
} }
#else #else
@ -63,46 +78,49 @@ static char *find_chars_or_comment(const char *s, const char *chars) {
s++; s++;
} }
#endif #endif
return (char *) s; return (char*)s;
} }
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */ /* Similar to strncpy, but ensures dest (size bytes) is
static char *strncpy0(char *dest, const char *src, size_t size) { NUL-terminated, and doesn't pad with NULs. */
#pragma GCC diagnostic push static char* strncpy0(char* dest, const char* src, size_t size)
#pragma GCC diagnostic ignored "-Wstringop-truncation" {
strncpy(dest, src, size - 1); /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
#pragma GCC diagnostic pop size_t i;
dest[size - 1] = '\0'; for (i = 0; i < size - 1 && src[i]; i++)
dest[i] = src[i];
dest[i] = '\0';
return dest; return dest;
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void *user) { void* user)
{
/* Uses a fair bit of stack (use heap instead if you need to) */ /* Uses a fair bit of stack (use heap instead if you need to) */
#if INI_USE_STACK #if INI_USE_STACK
char line[INI_MAX_LINE]; char line[INI_MAX_LINE];
int max_line = INI_MAX_LINE; int max_line = INI_MAX_LINE;
#else #else
char *line; char* line;
int max_line = INI_INITIAL_ALLOC; size_t max_line = INI_INITIAL_ALLOC;
#endif #endif
#if INI_ALLOW_REALLOC #if INI_ALLOW_REALLOC && !INI_USE_STACK
char *new_line; char* new_line;
int offset; size_t offset;
#endif #endif
char section[MAX_SECTION] = ""; char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = ""; char prev_name[MAX_NAME] = "";
char *start; char* start;
char *end; char* end;
char *name; char* name;
char *value; char* value;
int lineno = 0; int lineno = 0;
int error = 0; int error = 0;
#if !INI_USE_STACK #if !INI_USE_STACK
line = (char *) malloc(INI_INITIAL_ALLOC); line = (char*)ini_malloc(INI_INITIAL_ALLOC);
if (!line) { if (!line) {
return -2; return -2;
} }
@ -115,20 +133,20 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
#endif #endif
/* Scan through stream line by line */ /* Scan through stream line by line */
while (reader(line, max_line, stream) != NULL) { while (reader(line, (int)max_line, stream) != NULL) {
#if INI_ALLOW_REALLOC #if INI_ALLOW_REALLOC && !INI_USE_STACK
offset = strlen(line); offset = strlen(line);
while (offset == max_line - 1 && line[offset - 1] != '\n') { while (offset == max_line - 1 && line[offset - 1] != '\n') {
max_line *= 2; max_line *= 2;
if (max_line > INI_MAX_LINE) if (max_line > INI_MAX_LINE)
max_line = INI_MAX_LINE; max_line = INI_MAX_LINE;
new_line = realloc(line, max_line); new_line = ini_realloc(line, max_line);
if (!new_line) { if (!new_line) {
free(line); ini_free(line);
return -2; return -2;
} }
line = new_line; line = new_line;
if (reader(line + offset, max_line - offset, stream) == NULL) if (reader(line + offset, (int)(max_line - offset), stream) == NULL)
break; break;
if (max_line >= INI_MAX_LINE) if (max_line >= INI_MAX_LINE)
break; break;
@ -140,9 +158,9 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
start = line; start = line;
#if INI_ALLOW_BOM #if INI_ALLOW_BOM
if (lineno == 1 && (unsigned char) start[0] == 0xEF && if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
(unsigned char) start[1] == 0xBB && (unsigned char)start[1] == 0xBB &&
(unsigned char) start[2] == 0xBF) { (unsigned char)start[2] == 0xBF) {
start += 3; start += 3;
} }
#endif #endif
@ -166,11 +184,17 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
*end = '\0'; *end = '\0';
strncpy0(section, start + 1, sizeof(section)); strncpy0(section, start + 1, sizeof(section));
*prev_name = '\0'; *prev_name = '\0';
} else if (!error) { #if INI_CALL_HANDLER_ON_NEW_SECTION
if (!HANDLER(user, section, NULL, NULL) && !error)
error = lineno;
#endif
}
else if (!error) {
/* No ']' found on section line */ /* No ']' found on section line */
error = lineno; error = lineno;
} }
} else if (*start) { }
else if (*start) {
/* Not a comment, must be a name[=:]value pair */ /* Not a comment, must be a name[=:]value pair */
end = find_chars_or_comment(start, "=:"); end = find_chars_or_comment(start, "=:");
if (*end == '=' || *end == ':') { if (*end == '=' || *end == ':') {
@ -189,9 +213,17 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
strncpy0(prev_name, name, sizeof(prev_name)); strncpy0(prev_name, name, sizeof(prev_name));
if (!HANDLER(user, section, name, value) && !error) if (!HANDLER(user, section, name, value) && !error)
error = lineno; error = lineno;
} else if (!error) { }
else if (!error) {
/* No '=' or ':' found on name[=:]value line */ /* No '=' or ':' found on name[=:]value line */
#if INI_ALLOW_NO_VALUE
*end = '\0';
name = rstrip(start);
if (!HANDLER(user, section, name, NULL) && !error)
error = lineno; error = lineno;
#else
error = lineno;
#endif
} }
} }
@ -202,20 +234,22 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
} }
#if !INI_USE_STACK #if !INI_USE_STACK
free(line); ini_free(line);
#endif #endif
return error; return error;
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_file(FILE *file, ini_handler handler, void *user) { int ini_parse_file(FILE* file, ini_handler handler, void* user)
return ini_parse_stream((ini_reader) fgets, file, handler, user); {
return ini_parse_stream((ini_reader)fgets, file, handler, user);
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse(const char *filename, ini_handler handler, void *user) { int ini_parse(const char* filename, ini_handler handler, void* user)
FILE *file; {
FILE* file;
int error; int error;
file = fopen(filename, "r"); file = fopen(filename, "r");
@ -228,11 +262,11 @@ int ini_parse(const char *filename, ini_handler handler, void *user) {
/* An ini_reader function to read the next line from a string buffer. This /* An ini_reader function to read the next line from a string buffer. This
is the fgets() equivalent used by ini_parse_string(). */ is the fgets() equivalent used by ini_parse_string(). */
static char *ini_reader_string(char *str, int num, void *stream) { static char* ini_reader_string(char* str, int num, void* stream) {
ini_parse_string_ctx *ctx = (ini_parse_string_ctx *) stream; ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream;
const char *ctx_ptr = ctx->ptr; const char* ctx_ptr = ctx->ptr;
size_t ctx_num_left = ctx->num_left; size_t ctx_num_left = ctx->num_left;
char *strp = str; char* strp = str;
char c; char c;
if (ctx_num_left == 0 || num < 2) if (ctx_num_left == 0 || num < 2)
@ -254,11 +288,11 @@ static char *ini_reader_string(char *str, int num, void *stream) {
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_string(const char *string, ini_handler handler, void *user) { int ini_parse_string(const char* string, ini_handler handler, void* user) {
ini_parse_string_ctx ctx; ini_parse_string_ctx ctx;
ctx.ptr = string; ctx.ptr = string;
ctx.num_left = strlen(string); ctx.num_left = strlen(string);
return ini_parse_stream((ini_reader) ini_reader_string, &ctx, handler, return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler,
user); user);
} }

View File

@ -1,14 +1,18 @@
/* inih -- simple .INI file parser /* inih -- simple .INI file parser
SPDX-License-Identifier: BSD-3-Clause
Copyright (C) 2009-2020, Ben Hoyt
inih is released under the New BSD license (see LICENSE.txt). Go to the project inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info: home page for more info:
https://github.com/benhoyt/inih https://github.com/benhoyt/inih
*/ */
// clang-format off
#ifndef __INI_H__ #ifndef INI_H
#define __INI_H__ #define INI_H
/* Make this header file easier to include in C++ code */ /* Make this header file easier to include in C++ code */
#ifdef __cplusplus #ifdef __cplusplus
@ -28,12 +32,12 @@ typedef int (*ini_handler)(void* user, const char* section,
const char* name, const char* value, const char* name, const char* value,
int lineno); int lineno);
#else #else
typedef int (*ini_handler)(void *user, const char *section, typedef int (*ini_handler)(void* user, const char* section,
const char *name, const char *value); const char* name, const char* value);
#endif #endif
/* Typedef for prototype of fgets-style reader function. */ /* Typedef for prototype of fgets-style reader function. */
typedef char *(*ini_reader)(char *str, int num, void *stream); typedef char* (*ini_reader)(char* str, int num, void* stream);
/* Parse given INI-style file. May have [section]s, name=value pairs /* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section (whitespace stripped), and comments starting with ';' (semicolon). Section
@ -48,22 +52,22 @@ typedef char *(*ini_reader)(char *str, int num, void *stream);
stop on first error), -1 on file open error, or -2 on memory allocation stop on first error), -1 on file open error, or -2 on memory allocation
error (only when INI_USE_STACK is zero). error (only when INI_USE_STACK is zero).
*/ */
int ini_parse(const char *filename, ini_handler handler, void *user); int ini_parse(const char* filename, ini_handler handler, void* user);
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
close the file when it's finished -- the caller must do that. */ close the file when it's finished -- the caller must do that. */
int ini_parse_file(FILE *file, ini_handler handler, void *user); int ini_parse_file(FILE* file, ini_handler handler, void* user);
/* Same as ini_parse(), but takes an ini_reader function pointer instead of /* Same as ini_parse(), but takes an ini_reader function pointer instead of
filename. Used for implementing custom or string-based I/O (see also filename. Used for implementing custom or string-based I/O (see also
ini_parse_string). */ ini_parse_string). */
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void *user); void* user);
/* Same as ini_parse(), but takes a zero-terminated string with the INI data /* Same as ini_parse(), but takes a zero-terminated string with the INI data
instead of a file. Useful for parsing INI data from a network socket or instead of a file. Useful for parsing INI data from a network socket or
already in memory. */ already in memory. */
int ini_parse_string(const char *string, ini_handler handler, void *user); int ini_parse_string(const char* string, ini_handler handler, void* user);
/* Nonzero to allow multi-line value parsing, in the style of Python's /* Nonzero to allow multi-line value parsing, in the style of Python's
configparser. If allowed, ini_parse() will call the handler with the same configparser. If allowed, ini_parse() will call the handler with the same
@ -73,7 +77,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
#endif #endif
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
the file. See http://code.google.com/p/inih/issues/detail?id=21 */ the file. See https://github.com/benhoyt/inih/issues/21 */
#ifndef INI_ALLOW_BOM #ifndef INI_ALLOW_BOM
#define INI_ALLOW_BOM 1 #define INI_ALLOW_BOM 1
#endif #endif
@ -123,8 +127,31 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
#define INI_STOP_ON_FIRST_ERROR 0 #define INI_STOP_ON_FIRST_ERROR 0
#endif #endif
/* Nonzero to call the handler at the start of each new section (with
name and value NULL). Default is to only call the handler on
each name=value pair. */
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
#endif
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
call the handler with value NULL in this case. Default is to treat
no-value lines as an error. */
#ifndef INI_ALLOW_NO_VALUE
#define INI_ALLOW_NO_VALUE 0
#endif
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
allocation functions (INI_USE_STACK must also be 0). These functions must
have the same signatures as malloc/free/realloc and behave in a similar
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
#ifndef INI_CUSTOM_ALLOCATOR
#define INI_CUSTOM_ALLOCATOR 0
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __INI_H__ */ #endif /* INI_H */

View File

@ -1,8 +1,8 @@
#ifdef DEBUG #ifdef DEBUG
#include <stdint.h> #include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h> #include <whb/log_cafe.h>
#include <whb/log_module.h> #include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false; uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false; uint32_t cafeLogInit = false;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <whb/log.h>
#include <string.h> #include <string.h>
#include <whb/log.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -14,12 +14,14 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#else #else
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,6 +1,6 @@
#include "utils/logger.h"
#include <string.h> #include <string.h>
#include <whb/log.h> #include <whb/log.h>
#include "utils/logger.h"
#define PRINTF_BUFFER_LENGTH 2048 #define PRINTF_BUFFER_LENGTH 2048

View File

@ -8,26 +8,27 @@ extern "C" {
#define LIMIT(x, min, max) \ #define LIMIT(x, min, max) \
({ \ ({ \
typeof( x ) _x = x; \ typeof(x) _x = x; \
typeof( min ) _min = min; \ typeof(min) _min = min; \
typeof( max ) _max = max; \ typeof(max) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ (((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \
}) : (_x)); \
})
#define DegToRad(a) ( (a) * 0.01745329252f ) #define DegToRad(a) ((a) *0.01745329252f)
#define RadToDeg(a) ( (a) * 57.29577951f ) #define RadToDeg(a) ((a) *57.29577951f)
#define ALIGN4(x) (((x) + 3) & ~3) #define ALIGN4(x) (((x) + 3) & ~3)
#define ALIGN32(x) (((x) + 31) & ~31) #define ALIGN32(x) (((x) + 31) & ~31)
// those work only in powers of 2 // those work only in powers of 2
#define ROUNDDOWN(val, align) ((val) & ~(align-1)) #define ROUNDDOWN(val, align) ((val) & ~(align - 1))
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align) #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) #define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8)))
#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) #define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16)))
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) #define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand. //Needs to have log_init() called beforehand.
void dumpHex(const void *data, size_t size); void dumpHex(const void *data, size_t size);