Skip to content

Commit

Permalink
Clang-format 11
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Kaleta committed Nov 20, 2020
1 parent 230186d commit fb4edec
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 52 deletions.
49 changes: 27 additions & 22 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# VERSION 9
# VERSION 11

AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignOperands: Align
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
Expand All @@ -35,42 +38,42 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
FixNamespaceComments: false
IncludeBlocks: Merge
IncludeCategories:
# C Standard library
- Regex: '^<cstdlib>|<stdlib.h>'
Priority: 1
# C standard library (C++ style)
- Regex: '^<c(std(arg|def|int|io)|assert|(u|w)char|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|string|time|wctype)>'
Priority: 2
- Regex: '^<c(assert|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stddef|stdint|stdio|stdlib|string|time|uchar|wchar|wctype)>'
Priority: 1
# C standard library (C style)
- Regex: '^<(std(arg|def|int|io)|assert|(u|w)char|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|string|time|wctype)\.h>'
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|uchar|wchar|wctype)\.h>'
Priority: 1
# Standard headers (C++ style)
- Regex: '^<[a-z_]+>'
Priority: 2
# C++ standard library: input-output, exceptions, memory, threads
- Regex: '^<(ios(fwd)?|(i|o|io|f|s)stream|streambuf|iomanip|exception|stdexcept|system_error|new|memory|atomic|thread|(shared_)?mutex|future|condition_variable)>'
# Standard headers (C style)
- Regex: '^<[a-z_]+\.(h|hpp)>'
Priority: 3
# C++ standard library: algorithms, containers, strings
- Regex: '^<(algorithm|array|bitset|deque|iterator|(forward_|initializer_)?list|(unordered_)?map|queue|(unordered_)?set|stack|string|tuple|vector)>'
Priority: 4
# C++ standard library: utilities, numerics, types
- Regex: '^<(complex|chrono|functional|limits|locale|numeric|random|ratio|regex|type(info|index|_traits)|valarray)>'
# All other headers (C style)
- Regex: '^<.+\.(h|hpp)>'
Priority: 5
# All other headers (C++ style)
- Regex: '^<.*>'
Priority: 6
# All other headers (C style)
- Regex: '^<.*\.(h|hpp)>'
Priority: 7
- Regex: '^<.+>'
Priority: 4
# All custom headers
- Regex: '^".*"'
Priority: 8
- Regex: '^".+"'
Priority: 6
IncludeIsMainRegex: '$'
IncludeIsMainSourceRegex: '$'
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Expand All @@ -89,6 +92,8 @@ SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
Expand Down
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# [ C / C++ ]
# C++ / CMake output
# C / C++ / CMake output
bin/
build/
dist/

# CLion
.idea
cmake-build-debug/

# Visual Studio Code
.vscode
*.code-workspace

# CLion
.idea
cmake-build-debug/
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ General:
+ Linux-based operating system \
*((Debian testing))*
+ C++ compiler \
*((APT package `g++`, 9.2.+))*
*((APT package `g++`, 10.2.+))*
+ [CMake](https://cmake.org/) \
*((APT package `cmake`, 3.15.+))*
*((APT package `cmake`, 3.18.+))*
+ [GNU Make](https://www.gnu.org/software/make) \
*((APT package `make`, 4.2.+))*
*((APT package `make`, 4.3.+))*

### Automated formatting
+ [Clang-format](https://releases.llvm.org/9.0.0/tools/clang/docs/ClangFormat.html) \
*((APT package `clang-format`, 9.0.+))*
+ [Clang-format](https://releases.llvm.org/11.0.0/tools/clang/docs/ClangFormat.html) \
*((APT package `clang-format`, 11.+))*

-----

Expand Down
2 changes: 1 addition & 1 deletion include/IPAddress.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef IP_ADDRESS_HPP_
#define IP_ADDRESS_HPP_

#include <cstdlib>
#include <cinttypes>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
Expand Down
12 changes: 6 additions & 6 deletions include/RawSocket.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef RAW_SOCKET_HPP_
#define RAW_SOCKET_HPP_

#include <cstdlib>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <stdexcept>
Expand All @@ -18,15 +18,15 @@ struct SocketException : public std::logic_error
class RawSocket
{
public:
explicit RawSocket(int protocol) : descr{socket(AF_INET, SOCK_RAW, protocol)}
explicit RawSocket(int protocol) : descriptor_{socket(AF_INET, SOCK_RAW, protocol)}
{
if(descr < 0)
if(descriptor_ < 0)
throw SocketException(strerror(errno));
}

~RawSocket()
{
close(descr);
close(descriptor_);
}

RawSocket(const RawSocket & r) = delete;
Expand All @@ -36,11 +36,11 @@ class RawSocket

int descriptor() const
{
return descr;
return descriptor_;
}

private:
int descr;
int descriptor_;
};

#endif
2 changes: 1 addition & 1 deletion include/SocketSender.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SOCKET_SENDER_HPP_
#define SOCKET_SENDER_HPP_

#include <cstdlib>
#include <cinttypes>
#include <cstdlib>
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include "IPAddress.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/ICMPController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uint16_t count_checksum(const uint16_t * hdr, int length)

sum = (sum >> 16U) + (sum & 0xFFFFU);

return (uint16_t)(~(sum + (sum >> 16U)));
return static_cast<uint16_t>(~(sum + (sum >> 16U)));
}

icmphdr prepare_icmp(uint16_t id, uint16_t seq)
Expand Down
10 changes: 4 additions & 6 deletions src/IPAddress.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "IPAddress.hpp"
#include <exception>
#include <stdexcept>
#include <algorithm>
#include <exception>
#include <numeric>
#include <stdexcept>

std::vector<std::string> split(const std::string & st)
{
Expand Down Expand Up @@ -62,16 +62,14 @@ IPAddress::operator std::string() const

std::vector<unsigned int> IPAddress::quadruple() const
{
return std::vector<unsigned int>({(address & 0xFF000000U) >> 24U,
(address & 0x00FF0000U) >> 16U, (address & 0x0000FF00U) >> 8U,
address & 0x000000FFU});
return {(address & 0xFF000000U) >> 24U, (address & 0x00FF0000U) >> 16U,
(address & 0x0000FF00U) >> 8U, address & 0x000000FFU};
}

std::ostream & operator<<(std::ostream & os, const IPAddress & a)
{
std::vector<unsigned int> q = a.quadruple();

os << q[0] << "." << q[1] << "." << q[2] << "." << q[3];

return os;
}
2 changes: 1 addition & 1 deletion src/SocketReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ std::vector<uint8_t> SocketReceiver::receive()
uint8_t msg_buf[IP_MAXPACKET];

ssize_t msg_size = recvfrom(socket.descriptor(), msg_buf, IP_MAXPACKET, MSG_DONTWAIT,
(sockaddr *)&sender_address, &sender_size);
reinterpret_cast<sockaddr *>(&sender_address), &sender_size);

if(msg_size < 0)
throw SocketException(strerror(errno));
Expand Down
5 changes: 3 additions & 2 deletions src/SocketSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ void SocketSender::send(const void * msg_buf, int msg_size, uint16_t ttl)
{
setsockopt(socket.descriptor(), IPPROTO_IP, IP_TTL, &ttl, sizeof(uint16_t));

ssize_t sent_size = sendto(socket.descriptor(), msg_buf, msg_size, 0,
(sockaddr *)&receiver_address, sizeof(receiver_address));
ssize_t sent_size =
sendto(socket.descriptor(), msg_buf, msg_size, 0,
reinterpret_cast<sockaddr *>(&receiver_address), sizeof(receiver_address));

if(sent_size < 0)
throw SocketException(strerror(errno));
Expand Down
3 changes: 1 addition & 2 deletions src/traceroute.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cstring>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <unistd.h>
Expand Down Expand Up @@ -30,7 +30,6 @@ int main(int argc, char * argv[])
if(argc < 2)
{
std::cerr << "No destination IP specified.";

return 1;
}

Expand Down

0 comments on commit fb4edec

Please sign in to comment.