Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 14:33:59 +01:00
parent 5e6e8bdb53
commit 63f21d5a18
23 changed files with 287 additions and 195 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:
- 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

View File

@ -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

View File

@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/ftpiiu_plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/ftpiiu_plugin/actions/workflows/ci.yml)
## Usage
(`[ENVIRONMENT]` is a placeholder for the actual environment name.)
@ -18,3 +20,7 @@ docker run -it --rm -v ${PWD}:/project ftpiiuplugin-builder make
# make clean
docker run -it --rm -v ${PWD}:/project ftpiiuplugin-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,7 +1,7 @@
#include "BackgroundThread.hpp"
#include <cstring>
#include "ftp.h"
#include "net.h"
#include <cstring>
BackgroundThread *BackgroundThread::instance = nullptr;

View File

@ -1,8 +1,8 @@
#pragma once
#include "utils/BackgroundThreadWrapper.hpp"
#include <coreinit/cache.h>
#include "utils/logger.h"
#include <coreinit/cache.h>
#define PORT 21

View File

@ -23,23 +23,22 @@ misrepresented as being the original software.
3.This notice may not be removed or altered from any source distribution.
*/
#include "main.h"
#include "utils/logger.h"
#include <coreinit/thread.h>
#include <errno.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dir.h>
#include <coreinit/thread.h>
#include <unistd.h>
#include <errno.h>
#include "main.h"
#include "utils/logger.h"
//! TODO: fix those function
#define gettime() OSGetTick()
#include "ftp.h"
#include "virtualpath.h"
#include "net.h"
#include "virtualpath.h"
#include "vrt.h"
#define UNUSED __attribute__((unused))
@ -56,7 +55,7 @@ static uint8_t num_clients = 0;
static uint16_t passive_port = 1024;
static char *password = NULL;
#define console_printf(FMT, ARGS...) DEBUG_FUNCTION_LINE_WRITE(FMT, ## ARGS);
#define console_printf(FMT, ARGS...) DEBUG_FUNCTION_LINE_WRITE(FMT, ##ARGS);
typedef int32_t (*data_connection_callback)(int32_t data_socket, void *arg);
@ -614,14 +613,14 @@ static int32_t ftp_SITE_UNKNOWN(client_t *client, char *rest UNUSED) {
}
static int32_t ftp_SITE_LOAD(client_t *client, char *path UNUSED) {
// FILE *f = vrt_fopen(client->cwd, path, "rb");
// if (!f) return write_reply(client, 550, strerror(errno));
// char *real_path = to_real_path(client->cwd, path);
// if (!real_path) goto end;
// load_from_file(f, real_path);
// free(real_path);
// end:
// fclose(f);
// FILE *f = vrt_fopen(client->cwd, path, "rb");
// if (!f) return write_reply(client, 550, strerror(errno));
// char *real_path = to_real_path(client->cwd, path);
// if (!real_path) goto end;
// load_from_file(f, real_path);
// free(real_path);
// end:
// fclose(f);
return write_reply(client, 500, "Unable to load.");
}
@ -671,15 +670,13 @@ static const char *authenticated_commands[] = {
"SIZE", "PASV", "PORT", "TYPE", "SYST", "MODE",
"RETR", "STOR", "APPE", "REST", "DELE", "MKD",
"RMD", "RNFR", "RNTO", "NLST", "QUIT", "REIN",
"SITE", "NOOP", "ALLO", NULL
};
"SITE", "NOOP", "ALLO", NULL};
static const ftp_command_handler authenticated_handlers[] = {
ftp_USER, ftp_PASS, ftp_LIST, ftp_PWD, ftp_CWD, ftp_CDUP,
ftp_SIZE, ftp_PASV, ftp_PORT, ftp_TYPE, ftp_SYST, ftp_MODE,
ftp_RETR, ftp_STOR, ftp_APPE, ftp_REST, ftp_DELE, ftp_MKD,
ftp_DELE, ftp_RNFR, ftp_RNTO, ftp_NLST, ftp_QUIT, ftp_REIN,
ftp_SITE, ftp_NOOP, ftp_SUPERFLUOUS, ftp_UNKNOWN
};
ftp_SITE, ftp_NOOP, ftp_SUPERFLUOUS, ftp_UNKNOWN};
/*
returns negative to signal an error that requires closing the connection
@ -890,7 +887,6 @@ static void process_control_events(client_t *client) {
goto recv_loop_end;
}
}
}
if (next != client->buf) { // some lines were processed
@ -902,7 +898,7 @@ static void process_control_events(client_t *client) {
}
console_printf("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1);
recv_loop_end:
recv_loop_end:
cleanup_client(client);
}

View File

@ -27,7 +27,7 @@ misrepresented as being the original software.
#define _FTP_H_
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#include <stdbool.h>

View File

@ -1,15 +1,15 @@
#include <wups.h>
#include "BackgroundThread.hpp"
#include "utils/logger.h"
#include "virtualpath.h"
#include <coreinit/cache.h>
#include <coreinit/dynload.h>
#include <cstring>
#include <iosuhax.h>
#include <iosuhax_devoptab.h>
#include <iosuhax_disc_interface.h>
#include <coreinit/dynload.h>
#include <nn/ac.h>
#include <coreinit/cache.h>
#include "utils/logger.h"
#include <whb/log_udp.h>
#include "virtualpath.h"
#include "BackgroundThread.hpp"
#include <wups.h>
WUPS_PLUGIN_NAME("FTPiiU");
WUPS_PLUGIN_DESCRIPTION("FTP Server");
@ -112,4 +112,3 @@ ON_APPLICATION_REQUESTS_EXIT() {
deinitLogging();
}

View File

@ -6,8 +6,8 @@
extern "C" {
#endif
#include <stdint.h>
#include "net.h"
#include <stdint.h>
#define MAXPATHLEN 256

View File

@ -21,21 +21,21 @@ misrepresented as being the original software.
3.This notice may not be removed or altered from any source distribution.
*/
#include "main.h"
#include <malloc.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include "main.h"
#include <unistd.h>
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#include "net.h"
#define MAX_NET_BUFFER_SIZE (128*1024)
#define MAX_NET_BUFFER_SIZE (128 * 1024)
#define MIN_NET_BUFFER_SIZE 4096
#define FREAD_BUFFER_SIZE (128*1024)
#define FREAD_BUFFER_SIZE (128 * 1024)
extern uint32_t hostIpAddress;
@ -253,7 +253,7 @@ int32_t send_from_file(int32_t s, FILE *f) {
}
free(buf);
return -EAGAIN;
end:
end:
free(buf);
return result;
}

View File

@ -25,18 +25,18 @@ misrepresented as being the original software.
#define _NET_H_
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#include <stdint.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#if 0
void initialise_network();

View File

@ -19,4 +19,3 @@ void BackgroundThreadWrapper::executeThread() {
}
}
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "CThread.h"
#include <wut_types.h>
#include <mutex>
#include <wut_types.h>
class BackgroundThreadWrapper : public CThread {
public:
@ -20,6 +20,7 @@ protected:
}
std::recursive_mutex mutex;
private:
void executeThread() override;

View File

@ -17,11 +17,11 @@
#ifndef CTHREAD_H_
#define CTHREAD_H_
#include <malloc.h>
#include <unistd.h>
#include "utils/logger.h"
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
#include "utils/logger.h"
#include <malloc.h>
#include <unistd.h>
class CThread {
public:
@ -125,6 +125,7 @@ public:
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
private:
static int threadCallback(int argc, const char **argv) {
//! After call to start() continue with the internal function

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#include <string.h>
#include <stddef.h>
#include <whb/log.h>
#include "utils/logger.h"
#include <stddef.h>
#include <string.h>
#include <whb/log.h>
// https://gist.github.com/ccbrown/9722406
void dumpHex(const void *data, size_t size) {

View File

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

View File

@ -26,10 +26,10 @@
*
* for WiiXplorer 2010
***************************************************************************/
#include <malloc.h>
#include <string.h>
#include "virtualpath.h"
#include "utils/logger.h"
#include <malloc.h>
#include <string.h>
uint8_t MAX_VIRTUAL_PARTITIONS = 0;
VIRTUAL_PARTITION *VIRTUAL_PARTITIONS = NULL;

View File

@ -31,11 +31,11 @@
#define _VIRTUALPATH_H_
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
typedef struct {
char *name;

View File

@ -23,12 +23,12 @@ misrepresented as being the original software.
*/
#include "main.h"
#include <malloc.h>
#include <stdarg.h>
#include <string.h>
#include <sys/dirent.h>
#include <unistd.h>
#include "main.h"
#include "virtualpath.h"
#include "vrt.h"
@ -62,14 +62,17 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
break;
case 1:
if (*token == '.') state = 2;
else if (*token != '/') state = 0;
else if (*token != '/')
state = 0;
break;
case 2:
if (*token == '/' || !*token) {
state = 1;
*(curr_dir + 1) = '\0';
} else if (*token == '.') state = 3;
else state = 0;
} else if (*token == '.')
state = 3;
else
state = 0;
break;
case 3:
if (*token == '/' || !*token) {
@ -77,9 +80,11 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
*curr_dir = '\0';
char *prev_dir = strrchr(normalised_path, '/');
if (prev_dir) curr_dir = prev_dir;
else *curr_dir = '/';
else
*curr_dir = '/';
*(curr_dir + 1) = '\0';
} else state = 0;
} else
state = 0;
break;
}
if (!*token) break;
@ -92,7 +97,7 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
normalised_path[--end] = '\x00';
}
end:
end:
if (path != virtual_path) free(path);
return normalised_path;
}
@ -149,7 +154,7 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
strcpy(path, prefix);
strcat(path, rest);
end:
end:
free(virtual_path);
return path;
}

View File

@ -26,7 +26,7 @@ misrepresented as being the original software.
#define _VRT_H_
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#include <stdio.h>