Skip to content

Commit

Permalink
Use clang-format instead of astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
hummeltech committed Mar 26, 2024
1 parent 7f91d53 commit 6965262
Show file tree
Hide file tree
Showing 31 changed files with 1,511 additions and 1,586 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# Taken from "style similar to the Linux Kernel style":
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#examples
BasedOnStyle: LLVM

AllowShortIfStatementsOnASingleLine: false
BreakBeforeBraces: Linux
ColumnLimit: 0
IndentCaseLabels: false
IndentWidth: 8
InsertNewlineAtEOF: true
UseTab: Always
59 changes: 25 additions & 34 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,50 @@ on:
push:

jobs:
astyle:
env:
ASTYLE_CMD: >-
astyle
--break-blocks
--indent-switches
--indent=force-tab=8
--lineend=linux
--options=none
--pad-header
--pad-oper
--style=1tbs
--suffix=none
--unpad-paren
includes/*.h includes/*.hpp src/*.c src/*.cpp
name: Lint with `Artistic Style`
clang-format:
container:
env:
CLANG_FORMAT_CMD: >-
clang-format -i
includes/*.h includes/*.hpp src/*.c src/*.cpp
image: archlinux
name: Lint with `Clang Format`
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Provision environment
uses: ./.github/actions/dependencies/install/apt-get
with:
packages: astyle
- name: Check if any modifications were made by `astyle`
run: |
ASTYLE_OUTPUT=$(${ASTYLE_CMD} --dry-run)
if [ -n "$(echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged")" ]; then
pacman --sync --refresh --noconfirm clang
- name: Check if any modifications were made by `clang-format`
run: |
CLANG_FORMAT_OUTPUT=$(${CLANG_FORMAT_CMD} --dry-run)
if [ -n "$(echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged")" ]; then
echo "The following files are in need of formatting:"
echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged" | awk '{print "`"$2"`"}'
echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged" | awk '{print "`"$2"`"}'
echo ""
echo "Run the following command before submitting a pull request:"
echo '`'"${ASTYLE_CMD}"'`'
echo '`'"${CLANG_FORMAT_CMD}"'`'
exit 1
fi
- name: Write `$ASTYLE_OUTPUT` to `$GITHUB_STEP_SUMMARY`
- name: Write `$CLANG_FORMAT_OUTPUT` to `$GITHUB_STEP_SUMMARY`
run: |
ASTYLE_OUTPUT=$(${ASTYLE_CMD} --dry-run)
CLANG_FORMAT_OUTPUT=$(${CLANG_FORMAT_CMD} --dry-run)
echo "### The following files are in need of formatting:" >> ${GITHUB_STEP_SUMMARY}
echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged" | awk '{print "- `"$2"`"}' >> ${GITHUB_STEP_SUMMARY}
echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged" | awk '{print "- `"$2"`"}' >> ${GITHUB_STEP_SUMMARY}
echo "### Run the following command before submitting a pull request:" >> ${GITHUB_STEP_SUMMARY}
echo -e '```shell\n'"${ASTYLE_CMD}"'\n```' >> ${GITHUB_STEP_SUMMARY}
echo -e '```shell\n'"${CLANG_FORMAT_CMD}"'\n```' >> ${GITHUB_STEP_SUMMARY}
if: failure()
- name: Generate `ArtisticStyleFormattingFixes.patch` file
- name: Generate `ClangFormat.patch` file
run: |
${ASTYLE_CMD}
git diff --patch > ArtisticStyleFormattingFixes.patch
${CLANG_FORMAT_CMD}
git diff --patch > ClangFormat.patch
if: failure()
- name: Upload `ArtisticStyleFormattingFixes.patch` file
- name: Upload `ClangFormat.patch` file
uses: actions/upload-artifact@v4
with:
name: ArtisticStyleFormattingFixes.patch
path: ArtisticStyleFormattingFixes.patch
name: ClangFormat.patch
path: ClangFormat.patch
if: failure()

cmakelint:
Expand Down
2 changes: 1 addition & 1 deletion includes/gen_tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum queueEnum { queueRequest,
queueRender,
queueDuplicate,
queueRequestLow
};
};

struct item {
struct item *next;
Expand Down
8 changes: 4 additions & 4 deletions includes/metatile.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ struct meta_layout {
int count; // METATILE ^ 2
int x, y, z; // lowest x,y of this metatile, plus z
struct entry index[]; // count entries
// Followed by the tile data
// The index offsets are measured from the start of the file
// Followed by the tile data
// The index offsets are measured from the start of the file
};

#ifdef __cplusplus
}

class metaTile
{
public:
public:
metaTile(const std::string &xmlconfig, const std::string &options, int x, int y, int z);
void clear();
void set(int x, int y, const std::string &data);
Expand All @@ -59,7 +59,7 @@ class metaTile
void save(struct storage_backend *store);
void expire_tiles(int sock, const char *host, const char *uri);

private:
private:
int x_, y_, z_;
std::string xmlconfig_;
std::string options_;
Expand Down
2 changes: 1 addition & 1 deletion includes/mod_tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ enum tileState { tileMissing,
tileOld,
tileVeryOld,
tileCurrent
};
};

#endif
2 changes: 1 addition & 1 deletion includes/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum protoCmd { cmdIgnore,
cmdRenderPrio,
cmdRenderBulk,
cmdRenderLow
};
};

struct protocol {
int ver;
Expand Down
2 changes: 1 addition & 1 deletion includes/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct stat_info {

struct storage_backend {
int (*tile_read)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *err_msg);
struct stat_info(*tile_stat)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z);
struct stat_info (*tile_stat)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z);
int (*metatile_write)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz);
int (*metatile_delete)(struct storage_backend *store, const char *xmlconfig, int x, int y, int z);
int (*metatile_expire)(struct storage_backend *store, const char *xmlconfig, int x, int y, int z);
Expand Down
49 changes: 24 additions & 25 deletions src/cache_expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
* URL.
* RFC for HTCP can be found at http://www.htcp.org/
*/
static void cache_expire_url(int sock, char * url)
static void cache_expire_url(int sock, char *url)
{
char * buf;
char *buf;

if (sock < 0) {
return;
Expand All @@ -44,66 +44,66 @@ static void cache_expire_url(int sock, char * url)
int url_len;

url_len = strlen(url);
buf = (char *) malloc(12 + 22 + url_len);
buf = (char *)malloc(12 + 22 + url_len);

if (!buf) {
return;
}

idx = 0;

//16 bit: Overall length of the datagram packet, including this header
// 16 bit: Overall length of the datagram packet, including this header
*((uint16_t *)(&buf[idx])) = htons(12 + 22 + url_len);
idx += 2;

//HTCP version. Currently at 0.0
buf[idx++] = 0; //Major version
buf[idx++] = 0; //Minor version
// HTCP version. Currently at 0.0
buf[idx++] = 0; // Major version
buf[idx++] = 0; // Minor version

//Length of HTCP data, including this field
// Length of HTCP data, including this field
*((uint16_t *)(&buf[idx])) = htons(8 + 22 + url_len);
idx += 2;

//HTCP opcode CLR=4
// HTCP opcode CLR=4
buf[idx++] = 4;
//Reserved
// Reserved
buf[idx++] = 0;

//32 bit transaction id;
// 32 bit transaction id;
*((uint32_t *)(&buf[idx])) = htonl(255);
idx += 4;

buf[idx++] = 0;
buf[idx++] = 0; //HTCP reason
buf[idx++] = 0; // HTCP reason

//Length of the Method string
// Length of the Method string
*((uint16_t *)(&buf[idx])) = htons(4);
idx += 2;

///Method string
/// Method string
memcpy(&buf[idx], "HEAD", 4);
idx += 4;

//Length of the url string
// Length of the url string
*((uint16_t *)(&buf[idx])) = htons(url_len);
idx += 2;

//Url string
// Url string
memcpy(&buf[idx], url, url_len);
idx += url_len;

//Length of version string
// Length of version string
*((uint16_t *)(&buf[idx])) = htons(8);
idx += 2;

//version string
// version string
memcpy(&buf[idx], "HTTP/1.1", 8);
idx += 8;

//Length of request headers. Currently 0 as we don't have any headers to send
// Length of request headers. Currently 0 as we don't have any headers to send
*((uint16_t *)(&buf[idx])) = htons(0);

if (send(sock, (void *) buf, (12 + 22 + url_len), 0) < (12 + 22 + url_len)) {
if (send(sock, (void *)buf, (12 + 22 + url_len), 0) < (12 + 22 + url_len)) {
g_logger(G_LOG_LEVEL_ERROR, "Failed to send HTCP purge for %s", url);
};

Expand All @@ -117,13 +117,13 @@ void cache_expire(int sock, const char *host, const char *uri, int x, int y, int
return;
}

char * url = (char *)malloc(1024);
char *url = (char *)malloc(1024);
snprintf(url, 1024, "http://%s%s%i/%i/%i.png", host, uri, z, x, y);
cache_expire_url(sock, url);
free(url);
}

int init_cache_expire(const char * htcphost)
int init_cache_expire(const char *htcphost)
{
struct addrinfo hints;
struct addrinfo *result, *rp;
Expand All @@ -132,7 +132,7 @@ int init_cache_expire(const char * htcphost)
/* Obtain address(es) matching host/port */

memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
hints.ai_flags = 0;
hints.ai_protocol = 0; /* Any protocol */
Expand All @@ -157,7 +157,7 @@ int init_cache_expire(const char * htcphost)
}

if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) {
break; /* Success */
break; /* Success */
}

close(sfd);
Expand All @@ -171,5 +171,4 @@ int init_cache_expire(const char * htcphost)
freeaddrinfo(result); /* No longer needed */

return sfd;

}
Loading

0 comments on commit 6965262

Please sign in to comment.