Format the code via clang-format

Add new Dockerfile for building the lib in pull requests

Fix formatting of ALIGN macro
This commit is contained in:
Maschell 2022-02-03 13:09:27 +01:00
parent 9faa95af56
commit 7e4c2f13bd
12 changed files with 221 additions and 117 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: None
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

25
.github/workflows/pr.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: CI-PR
on: [pull_request]
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 ./source ./include
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
run: |
docker build . -f Dockerfile.buildlocal -t builder
docker run --rm -v ${PWD}:/project builder make
- uses: actions/upload-artifact@master
with:
name: binary
path: "lib/*.a"

View File

@ -4,8 +4,16 @@ on:
branches: branches:
- master - master
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 ./source ./include
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: clang-format
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Get release version - name: Get release version

View File

@ -1,4 +1,4 @@
FROM wiiuenv/devkitppc:20210920 FROM wiiuenv/devkitppc:20211229
WORKDIR tmp_build WORKDIR tmp_build
COPY . . COPY . .

3
Dockerfile.buildlocal Normal file
View File

@ -0,0 +1,3 @@
FROM wiiuenv/devkitppc:20211229
WORKDIR project

View File

@ -8,3 +8,7 @@ Make you to have [wut](https://github.com/devkitPro/wut/) installed and use the
``` ```
make install make install
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source ./include -i`

View File

@ -24,8 +24,8 @@
#ifndef _IOSUHAX_DISC_INTERFACE_H_ #ifndef _IOSUHAX_DISC_INTERFACE_H_
#define _IOSUHAX_DISC_INTERFACE_H_ #define _IOSUHAX_DISC_INTERFACE_H_
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -21,10 +21,10 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#include <string.h>
#include <malloc.h>
#include "os_functions.h"
#include "iosuhax.h" #include "iosuhax.h"
#include "os_functions.h"
#include <malloc.h>
#include <string.h>
#define IOSUHAX_MAGIC_WORD 0x4E696365 #define IOSUHAX_MAGIC_WORD 0x4E696365
@ -68,6 +68,7 @@
static int iosuhaxHandle = -1; static int iosuhaxHandle = -1;
#define ALIGN(align) __attribute__((aligned(align))) #define ALIGN(align) __attribute__((aligned(align)))
#define ALIGN_0x20 ALIGN(0x20)
#define ROUNDUP(x, align) (((x) + ((align) -1)) & ~((align) -1)) #define ROUNDUP(x, align) (((x) + ((align) -1)) & ~((align) -1))
int IOSUHAX_Open(const char *dev) { int IOSUHAX_Open(const char *dev) {
@ -77,7 +78,7 @@ int IOSUHAX_Open(const char *dev) {
iosuhaxHandle = IOS_Open((char *) (dev ? dev : "/dev/iosuhax"), 0); iosuhaxHandle = IOS_Open((char *) (dev ? dev : "/dev/iosuhax"), 0);
if (iosuhaxHandle >= 0 && dev) //make sure device is actually iosuhax if (iosuhaxHandle >= 0 && dev) //make sure device is actually iosuhax
{ {
ALIGN(0x20) int res[0x20 >> 2]; ALIGN_0x20 int res[0x20 >> 2];
*res = 0; *res = 0;
IOS_Ioctl(iosuhaxHandle, IOCTL_CHECK_IF_IOSUHAX, (void *) 0, 0, res, 4); IOS_Ioctl(iosuhaxHandle, IOCTL_CHECK_IF_IOSUHAX, (void *) 0, 0, res, 4);
@ -140,7 +141,7 @@ int IOSUHAX_memread(uint32_t address, uint8_t *out_buffer, uint32_t size) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN_0x20 int io_buf[0x20 >> 2];
io_buf[0] = address; io_buf[0] = address;
void *tmp_buf = NULL; void *tmp_buf = NULL;
@ -164,7 +165,7 @@ int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN_0x20 uint32_t io_buf[0x20 >> 2];
io_buf[0] = dst; io_buf[0] = dst;
io_buf[1] = src; io_buf[1] = src;
io_buf[2] = size; io_buf[2] = size;
@ -176,7 +177,7 @@ int IOSUHAX_kern_write32(uint32_t address, uint32_t value) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN_0x20 uint32_t io_buf[0x20 >> 2];
io_buf[0] = address; io_buf[0] = address;
io_buf[1] = value; io_buf[1] = value;
@ -188,7 +189,7 @@ int IOSUHAX_read_otp(uint8_t * out_buffer, uint32_t size) {
return iosuhaxHandle; return iosuhaxHandle;
} }
ALIGN(0x20) uint32_t io_buf[0x400 >> 2]; ALIGN_0x20 uint32_t io_buf[0x400 >> 2];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_READ_OTP, 0, 0, io_buf, 0x400); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_READ_OTP, 0, 0, io_buf, 0x400);
@ -234,7 +235,7 @@ int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count)
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN_0x20 uint32_t io_buf[0x20 >> 2];
io_buf[0] = address; io_buf[0] = address;
void *tmp_buf = NULL; void *tmp_buf = NULL;
@ -258,7 +259,7 @@ int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t arguments[0x40 >> 2]; ALIGN_0x20 uint32_t arguments[0x40 >> 2];
arguments[0] = svc_id; arguments[0] = svc_id;
if (args && arg_cnt) { if (args && arg_cnt) {
@ -268,7 +269,7 @@ int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt) {
memcpy(arguments + 1, args, arg_cnt * 4); memcpy(arguments + 1, args, arg_cnt * 4);
} }
ALIGN(0x20) int result[0x20 >> 2]; ALIGN_0x20 int result[0x20 >> 2];
int ret = IOS_Ioctl(iosuhaxHandle, IOCTL_SVC, arguments, (1 + arg_cnt) * 4, result, 4); int ret = IOS_Ioctl(iosuhaxHandle, IOCTL_SVC, arguments, (1 + arg_cnt) * 4, result, 4);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -280,7 +281,7 @@ int IOSUHAX_FSA_Open(void) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN_0x20 int io_buf[0x20 >> 2];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPEN, 0, 0, io_buf, sizeof(int)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPEN, 0, 0, io_buf, sizeof(int));
if (res < 0) if (res < 0)
@ -293,7 +294,7 @@ int IOSUHAX_FSA_Close(int fsaFd) {
if (iosuhaxHandle < 0) if (iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN_0x20 int io_buf[0x20 >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSE, io_buf, sizeof(fsaFd), io_buf, sizeof(fsaFd)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSE, io_buf, sizeof(fsaFd), io_buf, sizeof(fsaFd));
@ -311,7 +312,7 @@ int IOSUHAX_FSA_Mount(int fsaFd, const char *device_path, const char *volume_pat
int io_buf_size = (sizeof(uint32_t) * input_cnt) + strlen(device_path) + strlen(volume_path) + arg_string_len + 3; int io_buf_size = (sizeof(uint32_t) * input_cnt) + strlen(device_path) + strlen(volume_path) + arg_string_len + 3;
ALIGN(0x20) int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
memset(io_buf, 0, io_buf_size); memset(io_buf, 0, io_buf_size);
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -342,7 +343,7 @@ int IOSUHAX_FSA_Unmount(int fsaFd, const char *path, uint32_t flags) {
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
ALIGN(0x20) int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
@ -364,7 +365,7 @@ int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path) {
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(volume_path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(volume_path) + 1;
ALIGN(0x20) int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 int io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
@ -849,7 +850,7 @@ int IOSUHAX_FSA_ChangeMode(int fsaFd, const char *path, int mode) {
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
ALIGN(0x20) uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
@ -871,7 +872,7 @@ int IOSUHAX_FSA_RawOpen(int fsaFd, const char *device_path, int *outHandle) {
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(device_path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(device_path) + 1;
ALIGN(0x20) uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
@ -955,7 +956,7 @@ int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle) {
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
ALIGN(0x20) uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2]; ALIGN_0x20 uint32_t io_buf[ROUNDUP(io_buf_size, 0x20) >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = device_handle; io_buf[1] = device_handle;

View File

@ -21,18 +21,17 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#include "iosuhax.h"
#include "os_functions.h"
#include <errno.h> #include <errno.h>
#include <sys/iosupport.h> #include <fcntl.h>
#include <sys/statvfs.h>
#include <sys/dirent.h>
#include <string.h>
#include <malloc.h> #include <malloc.h>
#include <stdint.h> #include <stdint.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <sys/dirent.h>
#include <sys/iosupport.h> #include <sys/iosupport.h>
#include "os_functions.h" #include <sys/statvfs.h>
#include "iosuhax.h"
typedef struct _fs_dev_private_t { typedef struct _fs_dev_private_t {
char *mount_path; char *mount_path;
@ -537,7 +536,6 @@ static int fs_dev_rename_r(struct _reent *r, const char *oldName, const char *ne
} }
return 0; return 0;
} }
static int fs_dev_mkdir_r(struct _reent *r, const char *path, int mode) { static int fs_dev_mkdir_r(struct _reent *r, const char *path, int mode) {

View File

@ -21,10 +21,10 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#include <string.h>
#include <malloc.h>
#include "iosuhax.h"
#include "iosuhax_disc_interface.h" #include "iosuhax_disc_interface.h"
#include "iosuhax.h"
#include <malloc.h>
#include <string.h>
#define FSA_REF_SD 0x01 #define FSA_REF_SD 0x01
#define FSA_REF_USB 0x02 #define FSA_REF_USB 0x02
@ -152,8 +152,7 @@ const DISC_INTERFACE IOSUHAX_sdio_disc_interface =
IOSUHAX_sdio_readSectors, IOSUHAX_sdio_readSectors,
IOSUHAX_sdio_writeSectors, IOSUHAX_sdio_writeSectors,
IOSUHAX_sdio_clearStatus, IOSUHAX_sdio_clearStatus,
IOSUHAX_sdio_shutdown IOSUHAX_sdio_shutdown};
};
static bool IOSUHAX_usb_startup(void) { static bool IOSUHAX_usb_startup(void) {
if (!IOSUHAX_disc_io_fsa_open(FSA_REF_USB)) if (!IOSUHAX_disc_io_fsa_open(FSA_REF_USB))
@ -223,5 +222,4 @@ const DISC_INTERFACE IOSUHAX_usb_disc_interface =
IOSUHAX_usb_readSectors, IOSUHAX_usb_readSectors,
IOSUHAX_usb_writeSectors, IOSUHAX_usb_writeSectors,
IOSUHAX_usb_clearStatus, IOSUHAX_usb_clearStatus,
IOSUHAX_usb_shutdown IOSUHAX_usb_shutdown};
};