Skip to content

Commit

Permalink
Format the code via clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Feb 4, 2022
1 parent dcbf322 commit 3cf879d
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 142 deletions.
67 changes: 67 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ on:
- master

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:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
Expand All @@ -26,7 +34,7 @@ jobs:
id: get_repository_name
run: |
echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV
echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV
echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV
- uses: actions/download-artifact@master
with:
name: binary
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ 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 ./src
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/wiiload_plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/wiiload_plugin/actions/workflows/ci.yml)

## Usage
(`[ENVIRONMENT]` is a placeholder for the actual environment name.)

Expand All @@ -19,3 +21,7 @@ docker run -it --rm -v ${PWD}:/project wiiloadplugin-builder make
# make clean
docker run -it --rm -v ${PWD}:/project wiiloadplugin-builder make clean
```

## Format the code via docker

`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i`
18 changes: 8 additions & 10 deletions src/fs/CFile.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <cstdarg>
#include <cstdio>
#include <strings.h>
#include <fs/CFile.hpp>
#include <strings.h>

CFile::CFile() {
iFd = -1;
iFd = -1;
mem_file = nullptr;
filesize = 0;
pos = 0;
pos = 0;
}

CFile::CFile(const std::string &filepath, eOpenTypes mode) {
Expand All @@ -34,7 +34,7 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {

switch (mode) {
default:
case ReadOnly: // file must exist
case ReadOnly: // file must exist
openMode = O_RDONLY;
break;
case WriteOnly: // file will be created / zerod
Expand Down Expand Up @@ -76,10 +76,10 @@ void CFile::close() {
if (iFd >= 0)
::close(iFd);

iFd = -1;
iFd = -1;
mem_file = NULL;
filesize = 0;
pos = 0;
pos = 0;
}

int32_t CFile::read(uint8_t *ptr, size_t size) {
Expand Down Expand Up @@ -126,7 +126,7 @@ int32_t CFile::write(const uint8_t *ptr, size_t size) {
}

int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0;
int32_t ret = 0;
int64_t newPos = pos;

if (origin == SEEK_SET) {
Expand Down Expand Up @@ -157,7 +157,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {

int32_t CFile::fwrite(const char *format, ...) {
char tmp[512];
tmp[0] = 0;
tmp[0] = 0;
int32_t result = -1;

va_list va;
Expand All @@ -170,5 +170,3 @@ int32_t CFile::fwrite(const char *format, ...) {

return result;
}


2 changes: 1 addition & 1 deletion src/fs/CFile.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <cstdio>
#include <string>
#include <cstring>
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include <wut_types.h>

Expand Down
18 changes: 9 additions & 9 deletions src/fs/DirList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
* DirList Class
* for WiiXplorer 2010
***************************************************************************/
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <algorithm>
#include <sys/stat.h>
#include <sys/dirent.h>
#include <sys/stat.h>

#include <fs/DirList.h>
#include <utils/StringTools.h>

DirList::DirList() {
Flags = 0;
Flags = 0;
Filter = 0;
Depth = 0;
Depth = 0;
}

DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) {
Expand All @@ -54,9 +54,9 @@ DirList::~DirList() {
BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
if (folder.empty()) return false;

Flags = flags;
Flags = flags;
Filter = filter;
Depth = maxDepth;
Depth = maxDepth;

std::string folderpath(folder);
uint32_t length = folderpath.size();
Expand All @@ -81,14 +81,14 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
return false;

struct dirent *dirent = nullptr;
DIR *dir = NULL;
DIR *dir = NULL;

dir = opendir(folderpath.c_str());
if (dir == NULL)
return false;

while ((dirent = readdir(dir)) != 0) {
BOOL isDir = dirent->d_type & DT_DIR;
BOOL isDir = dirent->d_type & DT_DIR;
const char *filename = dirent->d_name;

if (isDir) {
Expand Down Expand Up @@ -191,7 +191,7 @@ void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
}

uint64_t DirList::GetFilesize(int32_t index) const {
struct stat st{};
struct stat st {};
const char *path = GetFilepath(index);

if (!path || stat(path, &st) != 0)
Expand Down
10 changes: 6 additions & 4 deletions src/fs/DirList.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
***************************************************************************/
#pragma once

#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>

typedef struct {
Expand Down Expand Up @@ -59,7 +59,8 @@ class DirList {
//!\param list index
[[nodiscard]] const char *GetFilepath(int32_t index) const {
if (!valid(index)) return "";
else return FileInfo[index].FilePath;
else
return FileInfo[index].FilePath;
}

//! Get the a filesize of the list
Expand Down Expand Up @@ -89,10 +90,11 @@ class DirList {

//! Enum for search/filter flags
enum {
Files = 0x01,
Dirs = 0x02,
Files = 0x01,
Dirs = 0x02,
CheckSubfolders = 0x08,
};

protected:
// Internal parser
BOOL InternalLoadPath(std::string &path);
Expand Down
17 changes: 8 additions & 9 deletions src/fs/FSUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <fcntl.h>
#include <fs/CFile.hpp>
#include <fs/FSUtils.h>
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <fs/FSUtils.h>
#include <fs/CFile.hpp>
#include <utils/logger.h>

int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
Expand All @@ -27,8 +27,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
}

uint32_t blocksize = 0x4000;
uint32_t done = 0;
int32_t readBytes = 0;
uint32_t done = 0;
int32_t readBytes = 0;

while (done < filesize) {
if (done + blocksize > filesize) {
Expand Down Expand Up @@ -62,7 +62,7 @@ int32_t FSUtils::CheckFile(const char *filepath) {
if (!filepath)
return 0;

struct stat filestat{};
struct stat filestat {};

char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
Expand Down Expand Up @@ -106,7 +106,7 @@ int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if (!ptr) {
//!Device root directory (must be with '/')
strcat(parentpath, "/");
struct stat filestat{};
struct stat filestat {};
if (stat(parentpath, &filestat) == 0)
return 1;

Expand Down Expand Up @@ -139,4 +139,3 @@ BOOL FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) {
file.close();
return true;
}

4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <wups.h>
#include "utils/logger.h"
#include "utils/TcpReceiver.h"
#include "utils/logger.h"
#include <wups.h>

WUPS_PLUGIN_NAME("Wiiload");
WUPS_PLUGIN_DESCRIPTION("Wiiload Server");
Expand Down
Loading

0 comments on commit 3cf879d

Please sign in to comment.