Skip to content

Commit

Permalink
server: force .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
netanelc305 committed Dec 20, 2023
1 parent 4238f36 commit 99073f7
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 284 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Run clang-format style.
run: |
if clang-format -n ../protos/*.proto *.h *.c | grep -q " code should be clang-formatted" ; then
echo "Code is not formatted correctly. Please run clang-format on these files."
exit 1
fi
- name: Test make
run: |
make clean all
Expand Down
54 changes: 54 additions & 0 deletions src/rpcserver/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: DontAlign
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
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: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
InsertBraces: true
BreakBeforeBraces: Attach
57 changes: 22 additions & 35 deletions src/rpcserver/common.c
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
#include <execinfo.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <syslog.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <syslog.h>
#include <unistd.h>

#include "common.h"

#ifdef __APPLE__
#include <os/log.h>

struct os_log_s
{
struct os_log_s {
int a;
};

struct os_log_s _os_log_default;
#endif // __APPLE__
#endif// __APPLE__

bool g_stdout = false;
bool g_syslog = false;
FILE *g_file = NULL;

#define BT_BUF_SIZE (100)

void print_backtrace()
{
void print_backtrace() {
int nptrs;
void *buffer[BT_BUF_SIZE];
char **strings;
Expand All @@ -39,24 +37,20 @@ void print_backtrace()
would produce similar output to the following: */

strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL)
{
if (strings == NULL) {
perror("backtrace_symbols");
return;
}

for (int j = 0; j < nptrs; j++)
{
for (int j = 0; j < nptrs; j++) {
trace("BACKTRACE:\t", "%s", strings[j]);
}

free(strings);
}

void trace(const char *prefix, const char *fmt, ...)
{
if (!g_stdout && !g_syslog)
{
void trace(const char *prefix, const char *fmt, ...) {
if (!g_stdout && !g_syslog) {
return;
}

Expand All @@ -70,34 +64,30 @@ void trace(const char *prefix, const char *fmt, ...)

sprintf(prefixed_line, "%s: %s", prefix, line);

if (g_stdout)
{
if (g_stdout) {
puts(prefixed_line);
fflush(stdout);
}
if (g_syslog)
{
if (g_syslog) {
#ifdef __APPLE__
os_log(&_os_log_default, "%{public}s", prefixed_line);
#else // __APPLE__
#else // __APPLE__
syslog(LOG_DEBUG, "%s", prefixed_line);
#endif // !__APPLE__
#endif// !__APPLE__
}
if (g_file)
{
if (g_file) {
fprintf(g_file, "%s\n", prefixed_line);
fflush(g_file);
}
}

bool recvall_ext(int sockfd, char *buf, size_t len, bool *disconnected)
{
bool recvall(int sockfd, char *buf, size_t len) {
bool ret = false;
size_t total_bytes = 0;
size_t bytes = 0;
*disconnected = false;

while (len > 0)
{
while (len > 0) {
bytes = recv(sockfd, buf + total_bytes, len, 0);
if (0 == bytes)
{
Expand All @@ -106,7 +96,6 @@ bool recvall_ext(int sockfd, char *buf, size_t len, bool *disconnected)
return false;
}
CHECK(bytes > 0);

total_bytes += bytes;
len -= bytes;
}
Expand Down Expand Up @@ -143,13 +132,11 @@ bool sendall(int sockfd, const char *buf, size_t len)
return false;
}

bool writeall(int fd, const char *buf, size_t len)
{
bool writeall(int fd, const char *buf, size_t len) {
size_t total_bytes = 0;
size_t bytes = 0;

while (len > 0)
{
while (len > 0) {
bytes = write(fd, buf + total_bytes, len);
CHECK(bytes != -1);

Expand Down
23 changes: 11 additions & 12 deletions src/rpcserver/common.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef __COMMON_H_
#define __COMMON_H_

#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char u8;
Expand All @@ -20,18 +20,17 @@ extern bool g_syslog;
extern FILE *g_file;

#define TRACE(...) trace(__PRETTY_FUNCTION__, __VA_ARGS__)
#define CHECK(expression) \
if (!(expression)) \
{ \
if (errno) \
{ \
trace(__PRETTY_FUNCTION__, "ERROR: errno: %d (%s)", errno, strerror(errno)); \
} \
print_backtrace(); \
goto error; \
#define CHECK(expression) \
if (!(expression)) { \
if (errno) { \
trace(__PRETTY_FUNCTION__, "ERROR on expression: %s: errno: %d (%s)", #expression, errno, strerror(errno)); \
} \
print_backtrace(); \
goto error; \
}

void print_backtrace();

void trace(const char *prefix, const char *fmt, ...);
bool recvall_ext(int sockfd, char *buf, size_t len, bool *disconnected);
bool recvall(int sockfd, char *buf, size_t len);
Expand Down
7 changes: 3 additions & 4 deletions src/rpcserver/darwin/darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#define __DARWIN_H_
#include <stdint.h>

#include <Foundation/Foundation.h>
#include <objc/objc.h>
#include <objc/runtime.h>
#include <Foundation/Foundation.h>

#include "../protocol.h"

void addProtocolsToDictionary(Class objcClass, NSDictionary *outDictionary);
void addIvarsToDictionary(Class objcClass, NSDictionary *outDictionary, id objcObject);
void addPropertiesToDictionary(Class objcClass, NSDictionary *outDictionary);
void addMethodsToDictionary(Class objcClass, NSDictionary *outDictionary);
NSString* getDictionaryJsonString(NSDictionary *classDescription);
NSString *getDictionaryJsonString(NSDictionary *classDescription);

#endif // __DARWIN_H_
#endif// __DARWIN_H_
Loading

0 comments on commit 99073f7

Please sign in to comment.