summaryrefslogtreecommitdiff
path: root/LibCore
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-05-28 11:53:16 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-28 17:31:20 +0200
commit0dc9af5f7e26b0dfa42cb75c900b9ef7a2192425 (patch)
tree93dbbbeb714f258bd7fb044633eb83bdcd908286 /LibCore
parentc11351ac507f863699d78aec46a77bd4d59e743c (diff)
downloadserenity-0dc9af5f7e26b0dfa42cb75c900b9ef7a2192425.zip
Add clang-format file
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
Diffstat (limited to 'LibCore')
-rw-r--r--LibCore/CArgsParser.cpp30
-rw-r--r--LibCore/CArgsParser.h1
-rw-r--r--LibCore/CConfigFile.cpp121
-rw-r--r--LibCore/CConfigFile.h16
-rw-r--r--LibCore/CDirIterator.cpp1
-rw-r--r--LibCore/CDirIterator.h6
-rw-r--r--LibCore/CElapsedTimer.cpp2
-rw-r--r--LibCore/CElapsedTimer.h6
-rw-r--r--LibCore/CEvent.h20
-rw-r--r--LibCore/CEventLoop.cpp33
-rw-r--r--LibCore/CEventLoop.h7
-rw-r--r--LibCore/CFile.cpp2
-rw-r--r--LibCore/CFile.h10
-rw-r--r--LibCore/CHttpJob.cpp16
-rw-r--r--LibCore/CHttpJob.h7
-rw-r--r--LibCore/CHttpRequest.cpp4
-rw-r--r--LibCore/CHttpRequest.h8
-rw-r--r--LibCore/CHttpResponse.h2
-rw-r--r--LibCore/CIODevice.h22
-rw-r--r--LibCore/CLock.h27
-rw-r--r--LibCore/CNetworkJob.h5
-rw-r--r--LibCore/CNetworkResponse.h2
-rw-r--r--LibCore/CNotifier.cpp5
-rw-r--r--LibCore/CNotifier.h9
-rw-r--r--LibCore/CObject.cpp6
-rw-r--r--LibCore/CObject.h8
-rw-r--r--LibCore/CProcessStatisticsReader.cpp4
-rw-r--r--LibCore/CProcessStatisticsReader.h2
-rw-r--r--LibCore/CSocket.cpp12
-rw-r--r--LibCore/CSocket.h7
-rw-r--r--LibCore/CSocketAddress.h15
-rw-r--r--LibCore/CTCPSocket.h1
-rw-r--r--LibCore/CTimer.h2
-rw-r--r--LibCore/CUserInfo.cpp2
-rw-r--r--LibCore/CUserInfo.h2
35 files changed, 235 insertions, 188 deletions
diff --git a/LibCore/CArgsParser.cpp b/LibCore/CArgsParser.cpp
index ab4936d15d..55dc350791 100644
--- a/LibCore/CArgsParser.cpp
+++ b/LibCore/CArgsParser.cpp
@@ -19,18 +19,27 @@ const Vector<String>& CArgsParserResult::get_single_values() const
}
CArgsParser::Arg::Arg(const String& name, const String& description, bool required)
- : name(name), description(description), required(required)
-{}
+ : name(name)
+ , description(description)
+ , required(required)
+{
+}
CArgsParser::Arg::Arg(const String& name, const String& value_name, const String& description, bool required)
- : name(name), description(description), value_name(value_name), required(required)
-{}
+ : name(name)
+ , description(description)
+ , value_name(value_name)
+ , required(required)
+{
+}
CArgsParser::CArgsParser(const String& program_name)
- : m_program_name(program_name), m_prefix("-")
-{}
+ : m_program_name(program_name)
+ , m_prefix("-")
+{
+}
-CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
+CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
{
CArgsParserResult res;
@@ -48,7 +57,7 @@ CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
return res;
}
-int CArgsParser::parse_next_param(const int index, const char** argv, const int params_left, CArgsParserResult& res)
+int CArgsParser::parse_next_param(const int index, const char** argv, const int params_left, CArgsParserResult& res)
{
if (params_left == 0)
return 0;
@@ -148,7 +157,7 @@ void CArgsParser::add_arg(const String& name, const String& value_name, const St
void CArgsParser::add_single_value(const String& name)
{
- m_single_args.append(SingleArg{name, false});
+ m_single_args.append(SingleArg { name, false });
}
void CArgsParser::add_required_single_value(const String& name)
@@ -157,7 +166,7 @@ void CArgsParser::add_required_single_value(const String& name)
// adding required arguments after non-required arguments would be nonsensical
ASSERT(m_single_args.last().required);
}
- m_single_args.append(SingleArg{name, true});
+ m_single_args.append(SingleArg { name, true });
}
String CArgsParser::get_usage() const
@@ -226,4 +235,3 @@ void CArgsParser::print_usage() const
{
printf("%s\n", get_usage().characters());
}
-
diff --git a/LibCore/CArgsParser.h b/LibCore/CArgsParser.h
index ab4078822e..4c50aa23a9 100644
--- a/LibCore/CArgsParser.h
+++ b/LibCore/CArgsParser.h
@@ -67,4 +67,3 @@ private:
Vector<SingleArg> m_single_args;
HashMap<String, Arg> m_args;
};
-
diff --git a/LibCore/CConfigFile.cpp b/LibCore/CConfigFile.cpp
index 6b46214561..d39d4505a0 100644
--- a/LibCore/CConfigFile.cpp
+++ b/LibCore/CConfigFile.cpp
@@ -1,9 +1,9 @@
+#include <AK/StringBuilder.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CFile.h>
#include <LibCore/CUserInfo.h>
-#include <AK/StringBuilder.h>
-#include <stdio.h>
#include <pwd.h>
+#include <stdio.h>
#include <unistd.h>
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
@@ -24,17 +24,17 @@ Retained<CConfigFile> CConfigFile::get_for_system(const String& app_name)
CConfigFile::CConfigFile(const String& file_name)
: m_file_name(file_name)
{
- reparse();
+ reparse();
}
CConfigFile::~CConfigFile()
{
- sync();
+ sync();
}
void CConfigFile::reparse()
{
- m_groups.clear();
+ m_groups.clear();
CFile file(m_file_name);
if (!file.open(CIODevice::OpenMode::ReadOnly))
@@ -46,38 +46,38 @@ void CConfigFile::reparse()
auto line = file.read_line(BUFSIZ);
auto* cp = (const char*)line.pointer();
- while(*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
- ++cp;
+ while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
+ ++cp;
switch (*cp) {
- case '\0':// EOL...
- case '#': // Comment, skip entire line.
- case ';': // -||-
- continue;
- case '[': { // Start of new group.
- StringBuilder builder;
- ++cp; // Skip the '['
- while (*cp && (*cp != ']'))
- builder.append(*(cp++));
- current_group = &m_groups.ensure(builder.to_string());
- break;
- }
- default: { // Start of key{
- StringBuilder key_builder;
- StringBuilder value_builder;
- while (*cp && (*cp != '='))
- key_builder.append(*(cp++));
- ++cp; // Skip the '='
- while (*cp && (*cp != '\n'))
- value_builder.append(*(cp++));
- if (!current_group) {
- // We're not in a group yet, create one with the name ""...
- current_group = &m_groups.ensure("");
- }
- current_group->set(key_builder.to_string(), value_builder.to_string());
- }
- }
- }
+ case '\0': // EOL...
+ case '#': // Comment, skip entire line.
+ case ';': // -||-
+ continue;
+ case '[': { // Start of new group.
+ StringBuilder builder;
+ ++cp; // Skip the '['
+ while (*cp && (*cp != ']'))
+ builder.append(*(cp++));
+ current_group = &m_groups.ensure(builder.to_string());
+ break;
+ }
+ default: { // Start of key{
+ StringBuilder key_builder;
+ StringBuilder value_builder;
+ while (*cp && (*cp != '='))
+ key_builder.append(*(cp++));
+ ++cp; // Skip the '='
+ while (*cp && (*cp != '\n'))
+ value_builder.append(*(cp++));
+ if (!current_group) {
+ // We're not in a group yet, create one with the name ""...
+ current_group = &m_groups.ensure("");
+ }
+ current_group->set(key_builder.to_string(), value_builder.to_string());
+ }
+ }
+ }
}
String CConfigFile::read_entry(const String& group, const String& key, const String& default_value) const
@@ -91,7 +91,7 @@ String CConfigFile::read_entry(const String& group, const String& key, const Str
return jt->value;
}
-int CConfigFile::read_num_entry(const String& group, const String &key, int default_value) const
+int CConfigFile::read_num_entry(const String& group, const String& key, int default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_num_entry(group, key, default_value);
@@ -105,7 +105,7 @@ int CConfigFile::read_num_entry(const String& group, const String &key, int defa
return value;
}
-Color CConfigFile::read_color_entry(const String& group, const String &key, Color default_value) const
+Color CConfigFile::read_color_entry(const String& group, const String& key, Color default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_color_entry(group, key, default_value);
@@ -116,26 +116,26 @@ Color CConfigFile::read_color_entry(const String& group, const String &key, Colo
if (shades.size() < 3)
return default_value;
bool ok1 = true,
- ok2 = true,
- ok3 = true,
- ok4 = true;
+ ok2 = true,
+ ok3 = true,
+ ok4 = true;
Color value;
if (shades.size() == 3) {
value = Color(shades[0].to_uint(ok1),
- shades[1].to_uint(ok2),
- shades[2].to_uint(ok3));
+ shades[1].to_uint(ok2),
+ shades[2].to_uint(ok3));
} else {
value = Color(shades[0].to_uint(ok1),
- shades[1].to_uint(ok2),
- shades[2].to_uint(ok3),
- shades[3].to_uint(ok4));
+ shades[1].to_uint(ok2),
+ shades[2].to_uint(ok3),
+ shades[3].to_uint(ok4));
}
if (!(ok1 && ok2 && ok3 && ok4))
return default_value;
return value;
}
-bool CConfigFile::read_bool_entry(const String& group, const String &key, bool default_value) const
+bool CConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
{
return read_entry(group, key, default_value ? "1" : "0") == "1";
}
@@ -143,7 +143,7 @@ bool CConfigFile::read_bool_entry(const String& group, const String &key, bool d
void CConfigFile::write_entry(const String& group, const String& key, const String& value)
{
m_groups.ensure(group).ensure(key) = value;
- m_dirty = true;
+ m_dirty = true;
}
void CConfigFile::write_num_entry(const String& group, const String& key, int value)
@@ -152,32 +152,29 @@ void CConfigFile::write_num_entry(const String& group, const String& key, int va
}
void CConfigFile::write_color_entry(const String& group, const String& key, Color value)
{
- write_entry(group, key, String::format("%d,%d,%d,%d", value.red(),
- value.green(),
- value.blue(),
- value.alpha()));
+ write_entry(group, key, String::format("%d,%d,%d,%d", value.red(), value.green(), value.blue(), value.alpha()));
}
bool CConfigFile::sync()
{
if (!m_dirty)
- return true;
+ return true;
- FILE *fp = fopen(m_file_name.characters(), "wb");
+ FILE* fp = fopen(m_file_name.characters(), "wb");
if (!fp)
- return false;
+ return false;
for (auto& it : m_groups) {
fprintf(fp, "[%s]\n", it.key.characters());
for (auto& jt : it.value)
fprintf(fp, "%s=%s\n", jt.key.characters(), jt.value.characters());
fprintf(fp, "\n");
- }
+ }
fclose(fp);
- m_dirty = false;
- return true;
+ m_dirty = false;
+ return true;
}
void CConfigFile::dump() const
@@ -187,7 +184,7 @@ void CConfigFile::dump() const
for (auto& jt : it.value)
printf("%s=%s\n", jt.key.characters(), jt.value.characters());
printf("\n");
- }
+ }
}
Vector<String> CConfigFile::groups() const
@@ -199,7 +196,7 @@ Vector<String> CConfigFile::keys(const String& group) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
- return { };
+ return {};
return it->value.keys();
}
@@ -207,7 +204,7 @@ bool CConfigFile::has_key(const String& group, const String& key) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
- return { };
+ return {};
return it->value.contains(key);
}
@@ -219,7 +216,7 @@ bool CConfigFile::has_group(const String& group) const
void CConfigFile::remove_group(const String& group)
{
m_groups.remove(group);
- m_dirty = true;
+ m_dirty = true;
}
void CConfigFile::remove_entry(const String& group, const String& key)
@@ -228,5 +225,5 @@ void CConfigFile::remove_entry(const String& group, const String& key)
if (it == m_groups.end())
return;
it->value.remove(key);
- m_dirty = true;
+ m_dirty = true;
}
diff --git a/LibCore/CConfigFile.h b/LibCore/CConfigFile.h
index ea71c9b367..0f58b2b2a2 100644
--- a/LibCore/CConfigFile.h
+++ b/LibCore/CConfigFile.h
@@ -1,11 +1,11 @@
#pragma once
-#include <SharedGraphics/Color.h>
-#include <AK/Vector.h>
-#include <AK/HashMap.h>
#include <AK/AKString.h>
-#include <AK/Retainable.h>
+#include <AK/HashMap.h>
#include <AK/RetainPtr.h>
+#include <AK/Retainable.h>
+#include <AK/Vector.h>
+#include <SharedGraphics/Color.h>
class CConfigFile : public Retainable<CConfigFile> {
public:
@@ -22,18 +22,18 @@ public:
String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
int read_num_entry(const String& group, const String& key, int default_value = 0) const;
bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
- Color read_color_entry(const String& group, const String &key, Color default_value) const;
+ Color read_color_entry(const String& group, const String& key, Color default_value) const;
- void write_entry(const String& group, const String& key, const String &value);
+ void write_entry(const String& group, const String& key, const String& value);
void write_num_entry(const String& group, const String& key, int value);
void write_bool_entry(const String& group, const String& key, bool value);
void write_color_entry(const String& group, const String& key, Color value);
- void dump() const;
+ void dump() const;
bool is_dirty() const { return m_dirty; }
- bool sync();
+ bool sync();
void remove_group(const String& group);
void remove_entry(const String& group, const String& key);
diff --git a/LibCore/CDirIterator.cpp b/LibCore/CDirIterator.cpp
index c66b313e45..aa64ea8b71 100644
--- a/LibCore/CDirIterator.cpp
+++ b/LibCore/CDirIterator.cpp
@@ -65,4 +65,3 @@ String CDirIterator::next_path()
m_next = String();
return tmp;
}
-
diff --git a/LibCore/CDirIterator.h b/LibCore/CDirIterator.h
index 03804aecf3..72920c2c1f 100644
--- a/LibCore/CDirIterator.h
+++ b/LibCore/CDirIterator.h
@@ -1,11 +1,12 @@
#pragma once
-#include <dirent.h>
#include <AK/AKString.h>
+#include <dirent.h>
class CDirIterator {
public:
- enum Flags {
+ enum Flags
+ {
NoFlags = 0x0,
SkipDots = 0x1,
};
@@ -27,4 +28,3 @@ private:
bool advance_next();
};
-
diff --git a/LibCore/CElapsedTimer.cpp b/LibCore/CElapsedTimer.cpp
index aec3658fc4..e783f59b0d 100644
--- a/LibCore/CElapsedTimer.cpp
+++ b/LibCore/CElapsedTimer.cpp
@@ -1,6 +1,6 @@
-#include <LibCore/CElapsedTimer.h>
#include <AK/Assertions.h>
#include <AK/Time.h>
+#include <LibCore/CElapsedTimer.h>
#include <sys/time.h>
void CElapsedTimer::start()
diff --git a/LibCore/CElapsedTimer.h b/LibCore/CElapsedTimer.h
index bb8fa28ac6..76fa304478 100644
--- a/LibCore/CElapsedTimer.h
+++ b/LibCore/CElapsedTimer.h
@@ -4,7 +4,7 @@
class CElapsedTimer {
public:
- CElapsedTimer() { }
+ CElapsedTimer() {}
bool is_valid() const { return m_valid; }
void start();
@@ -12,5 +12,7 @@ public:
private:
bool m_valid { false };
- struct timeval m_start_time { 0, 0 };
+ struct timeval m_start_time {
+ 0, 0
+ };
};
diff --git a/LibCore/CEvent.h b/LibCore/CEvent.h
index 4010afe607..1920df2688 100644
--- a/LibCore/CEvent.h
+++ b/LibCore/CEvent.h
@@ -1,15 +1,16 @@
#pragma once
#include <AK/AKString.h>
+#include <AK/Function.h>
#include <AK/Types.h>
#include <AK/WeakPtr.h>
-#include <AK/Function.h>
class CObject;
class CEvent {
public:
- enum Type {
+ enum Type
+ {
Invalid = 0,
Quit,
Timer,
@@ -19,9 +20,12 @@ public:
ChildRemoved,
};
- CEvent() { }
- explicit CEvent(unsigned type) : m_type(type) { }
- virtual ~CEvent() { }
+ CEvent() {}
+ explicit CEvent(unsigned type)
+ : m_type(type)
+ {
+ }
+ virtual ~CEvent() {}
unsigned type() const { return m_type; }
@@ -31,6 +35,7 @@ private:
class CDeferredInvocationEvent : public CEvent {
friend class CEventLoop;
+
public:
CDeferredInvocationEvent(Function<void(CObject&)> invokee)
: CEvent(CEvent::Type::DeferredInvoke)
@@ -45,10 +50,11 @@ private:
class CTimerEvent final : public CEvent {
public:
explicit CTimerEvent(int timer_id)
- : CEvent(CEvent::Timer), m_timer_id(timer_id)
+ : CEvent(CEvent::Timer)
+ , m_timer_id(timer_id)
{
}
- ~CTimerEvent() { }
+ ~CTimerEvent() {}
int timer_id() const { return m_timer_id; }
diff --git a/LibCore/CEventLoop.cpp b/LibCore/CEventLoop.cpp
index 4537efb5af..d84a45fe16 100644
--- a/LibCore/CEventLoop.cpp
+++ b/LibCore/CEventLoop.cpp
@@ -1,20 +1,19 @@
-#include <LibCore/CObject.h>
-#include <LibCore/CEventLoop.h>
-#include <LibCore/CEvent.h>
-#include <LibCore/CLock.h>
-#include <LibCore/CNotifier.h>
-#include <LibC/unistd.h>
-#include <LibC/stdio.h>
+#include <AK/Time.h>
+#include <LibC/errno.h>
#include <LibC/fcntl.h>
+#include <LibC/stdio.h>
+#include <LibC/stdlib.h>
#include <LibC/string.h>
-#include <LibC/time.h>
#include <LibC/sys/select.h>
#include <LibC/sys/socket.h>
#include <LibC/sys/time.h>
-#include <LibC/errno.h>
-#include <LibC/string.h>
-#include <LibC/stdlib.h>
-#include <AK/Time.h>
+#include <LibC/time.h>
+#include <LibC/unistd.h>
+#include <LibCore/CEvent.h>
+#include <LibCore/CEventLoop.h>
+#include <LibCore/CLock.h>
+#include <LibCore/CNotifier.h>
+#include <LibCore/CObject.h>
//#define CEVENTLOOP_DEBUG
//#define DEFERRED_INVOKE_DEBUG
@@ -66,7 +65,8 @@ void CEventLoop::quit(int code)
struct CEventLoopPusher {
public:
- CEventLoopPusher(CEventLoop& event_loop) : m_event_loop(event_loop)
+ CEventLoopPusher(CEventLoop& event_loop)
+ : m_event_loop(event_loop)
{
if (&m_event_loop != s_main_event_loop) {
m_event_loop.take_pending_events_from(CEventLoop::current());
@@ -80,6 +80,7 @@ public:
CEventLoop::current().take_pending_events_from(m_event_loop);
}
}
+
private:
CEventLoop& m_event_loop;
};
@@ -159,7 +160,7 @@ void CEventLoop::wait_for_event(WaitMode mode)
FD_ZERO(&wfds);
int max_fd = 0;
- auto add_fd_to_set = [&max_fd] (int fd, fd_set& set){
+ auto add_fd_to_set = [&max_fd](int fd, fd_set& set) {
FD_SET(fd, &set);
if (fd > max_fd)
max_fd = fd;
@@ -271,8 +272,8 @@ int CEventLoop::register_timer(CObject& object, int milliseconds, bool should_re
gettimeofday(&now, nullptr);
timer->reload(now);
timer->should_reload = should_reload;
- int timer_id = ++s_next_timer_id; // FIXME: This will eventually wrap around.
- ASSERT(timer_id); // FIXME: Aforementioned wraparound.
+ int timer_id = ++s_next_timer_id; // FIXME: This will eventually wrap around.
+ ASSERT(timer_id); // FIXME: Aforementioned wraparound.
timer->timer_id = timer_id;
s_timers->set(timer->timer_id, move(timer));
return timer_id;
diff --git a/LibCore/CEventLoop.h b/LibCore/CEventLoop.h
index a44cc72486..dbcc67ddb7 100644
--- a/LibCore/CEventLoop.h
+++ b/LibCore/CEventLoop.h
@@ -21,7 +21,8 @@ public:
int exec();
- enum class WaitMode {
+ enum class WaitMode
+ {
WaitForEvents,
PollForEvents,
};
@@ -52,8 +53,8 @@ public:
protected:
virtual void add_file_descriptors_for_select(fd_set&, int& max_fd) { UNUSED_PARAM(max_fd); }
- virtual void process_file_descriptors_after_select(const fd_set&) { }
- virtual void do_processing() { }
+ virtual void process_file_descriptors_after_select(const fd_set&) {}
+ virtual void do_processing() {}
private:
void wait_for_event(WaitMode);
diff --git a/LibCore/CFile.cpp b/LibCore/CFile.cpp
index 47cee94f15..44813e1c97 100644
--- a/LibCore/CFile.cpp
+++ b/LibCore/CFile.cpp
@@ -1,7 +1,7 @@
#include <LibCore/CFile.h>
-#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
+#include <unistd.h>
CFile::CFile(const String& filename)
: m_filename(filename)
diff --git a/LibCore/CFile.h b/LibCore/CFile.h
index a78c850fe3..fab396ac55 100644
--- a/LibCore/CFile.h
+++ b/LibCore/CFile.h
@@ -1,11 +1,11 @@
#pragma once
-#include <LibCore/CIODevice.h>
#include <AK/AKString.h>
+#include <LibCore/CIODevice.h>
class CFile final : public CIODevice {
public:
- CFile() { }
+ CFile() {}
explicit CFile(const String&);
virtual ~CFile() override;
@@ -14,7 +14,11 @@ public:
virtual bool open(CIODevice::OpenMode) override;
- enum class ShouldCloseFileDescriptor { No = 0, Yes };
+ enum class ShouldCloseFileDescriptor
+ {
+ No = 0,
+ Yes
+ };
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescriptor);
virtual const char* class_name() const override { return "CFile"; }
diff --git a/LibCore/CHttpJob.cpp b/LibCore/CHttpJob.cpp
index f9a9a08f3b..e580fd87c2 100644
--- a/LibCore/CHttpJob.cpp
+++ b/LibCore/CHttpJob.cpp
@@ -22,7 +22,7 @@ void CHttpJob::on_socket_connected()
bool success = m_socket->send(raw_request);
if (!success)
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::TransmissionFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
Vector<byte> buffer;
while (m_socket->is_connected()) {
@@ -33,18 +33,18 @@ void CHttpJob::on_socket_connected()
auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) {
printf("Expected HTTP status\n");
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::TransmissionFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
}
auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) {
printf("Expected 3-part HTTP status, got '%s'\n", line.pointer());
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
bool ok;
m_code = parts[1].to_uint(ok);
if (!ok) {
printf("Expected numeric HTTP status\n");
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
m_state = State::InHeaders;
continue;
@@ -65,12 +65,12 @@ void CHttpJob::on_socket_connected()
auto parts = chomped_line.split(':');
if (parts.is_empty()) {
printf("Expected HTTP header with key/value\n");
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
auto name = parts[0];
if (chomped_line.length() < name.length() + 2) {
printf("Malformed HTTP header: '%s' (%d)\n", chomped_line.characters(), chomped_line.length());
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2);
m_headers.set(name, value);
@@ -84,13 +84,13 @@ void CHttpJob::on_socket_connected()
m_state = State::Finished;
break;
}
- return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
+ return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
buffer.append(payload.pointer(), payload.size());
}
auto response = CHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
- deferred_invoke([this, response] (auto&) {
+ deferred_invoke([this, response](auto&) {
did_finish(move(response));
});
}
diff --git a/LibCore/CHttpJob.h b/LibCore/CHttpJob.h
index e30e836b66..c8d2c8c361 100644
--- a/LibCore/CHttpJob.h
+++ b/LibCore/CHttpJob.h
@@ -1,8 +1,8 @@
#pragma once
-#include <LibCore/CNetworkJob.h>
-#include <LibCore/CHttpRequest.h>
#include <AK/HashMap.h>
+#include <LibCore/CHttpRequest.h>
+#include <LibCore/CNetworkJob.h>
class CTCPSocket;
@@ -18,7 +18,8 @@ public:
private:
void on_socket_connected();
- enum class State {
+ enum class State
+ {
InStatus,
InHeaders,
InBody,
diff --git a/LibCore/CHttpRequest.cpp b/LibCore/CHttpRequest.cpp
index 3f07fecaa1..de62a8cd6d 100644
--- a/LibCore/CHttpRequest.cpp
+++ b/LibCore/CHttpRequest.cpp
@@ -1,6 +1,6 @@
-#include <LibCore/CHttpRequest.h>
-#include <LibCore/CHttpJob.h>
#include <AK/StringBuilder.h>
+#include <LibCore/CHttpJob.h>
+#include <LibCore/CHttpRequest.h>
CHttpRequest::CHttpRequest()
{
diff --git a/LibCore/CHttpRequest.h b/LibCore/CHttpRequest.h
index 5432baf4b5..8ab6fef413 100644
--- a/LibCore/CHttpRequest.h
+++ b/LibCore/CHttpRequest.h
@@ -6,7 +6,13 @@ class CNetworkJob;
class CHttpRequest {
public:
- enum Method { Invalid, HEAD, GET, POST };
+ enum Method
+ {
+ Invalid,
+ HEAD,
+ GET,
+ POST
+ };
CHttpRequest();
~CHttpRequest();
diff --git a/LibCore/CHttpResponse.h b/LibCore/CHttpResponse.h
index 7cf46bc545..851f77d3a0 100644
--- a/LibCore/CHttpResponse.h
+++ b/LibCore/CHttpResponse.h
@@ -1,8 +1,8 @@
#pragma once
-#include <LibCore/CNetworkResponse.h>
#include <AK/AKString.h>
#include <AK/HashMap.h>
+#include <LibCore/CNetworkResponse.h>
class CHttpResponse : public CNetworkResponse {
public:
diff --git a/LibCore/CIODevice.h b/LibCore/CIODevice.h
index 79e589eb9f..4977c3f33b 100644
--- a/LibCore/CIODevice.h
+++ b/LibCore/CIODevice.h
@@ -1,18 +1,19 @@
#pragma once
-#include <LibCore/CObject.h>
#include <AK/ByteBuffer.h>
+#include <LibCore/CObject.h>
class CIODevice : public CObject {
public:
- enum OpenMode {
- NotOpen = 0,
- ReadOnly = 1,
- WriteOnly = 2,
- ReadWrite = 3,
- Append = 4,
- Truncate = 8,
- MustBeNew = 16,
+ enum OpenMode
+ {
+ NotOpen = 0,
+ ReadOnly = 1,
+ WriteOnly = 2,
+ ReadWrite = 3,
+ Append = 4,
+ Truncate = 8,
+ MustBeNew = 16,
};
virtual ~CIODevice() override;
@@ -37,7 +38,8 @@ public:
bool can_read() const;
- enum class SeekMode {
+ enum class SeekMode
+ {
SetPosition,
FromCurrentPosition,
FromEndPosition,
diff --git a/LibCore/CLock.h b/LibCore/CLock.h
index a9853f5215..02ab53fa82 100644
--- a/LibCore/CLock.h
+++ b/LibCore/CLock.h
@@ -4,23 +4,24 @@
#include <AK/Types.h>
#include <unistd.h>
-#define memory_barrier() asm volatile ("" ::: "memory")
+#define memory_barrier() asm volatile("" :: \
+ : "memory")
static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
{
dword ret;
asm volatile(
"cmpxchgl %2, %1"
- :"=a"(ret), "+m"(*mem)
- :"r"(newval), "0"(oldval)
- :"cc", "memory");
+ : "=a"(ret), "+m"(*mem)
+ : "r"(newval), "0"(oldval)
+ : "cc", "memory");
return ret;
}
class CLock {
public:
- CLock() { }
- ~CLock() { }
+ CLock() {}
+ ~CLock() {}
void lock();
void unlock();
@@ -33,7 +34,11 @@ private:
class CLocker {
public:
- [[gnu::always_inline]] inline explicit CLocker(CLock& l) : m_lock(l) { lock(); }
+ [[gnu::always_inline]] inline explicit CLocker(CLock& l)
+ : m_lock(l)
+ {
+ lock();
+ }
[[gnu::always_inline]] inline ~CLocker() { unlock(); }
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
@@ -86,8 +91,11 @@ inline void CLock::unlock()
template<typename T>
class CLockable {
public:
- CLockable() { }
- CLockable(T&& resource) : m_resource(move(resource)) { }
+ CLockable() {}
+ CLockable(T&& resource)
+ : m_resource(move(resource))
+ {
+ }
CLock& lock() { return m_lock; }
T& resource() { return m_resource; }
@@ -101,4 +109,3 @@ private:
T m_resource;
CLock m_lock;
};
-
diff --git a/LibCore/CNetworkJob.h b/LibCore/CNetworkJob.h
index 4b6b479c8f..3d8117c754 100644
--- a/LibCore/CNetworkJob.h
+++ b/LibCore/CNetworkJob.h
@@ -1,13 +1,14 @@
#pragma once
-#include <LibCore/CObject.h>
#include <AK/Function.h>
+#include <LibCore/CObject.h>
class CNetworkResponse;
class CNetworkJob : public CObject {
public:
- enum class Error {
+ enum class Error
+ {
None,
ConnectionFailed,
TransmissionFailed,
diff --git a/LibCore/CNetworkResponse.h b/LibCore/CNetworkResponse.h
index 1968590c79..70bc30de15 100644
--- a/LibCore/CNetworkResponse.h
+++ b/LibCore/CNetworkResponse.h
@@ -1,7 +1,7 @@
#pragma once
-#include <AK/Retainable.h>
#include <AK/ByteBuffer.h>
+#include <AK/Retainable.h>
class CNetworkResponse : public Retainable<CNetworkResponse> {
public:
diff --git a/LibCore/CNotifier.cpp b/LibCore/CNotifier.cpp
index a7e1344900..000602a4a9 100644
--- a/LibCore/CNotifier.cpp
+++ b/LibCore/CNotifier.cpp
@@ -1,6 +1,6 @@
-#include <LibCore/CNotifier.h>
-#include <LibCore/CEventLoop.h>
#include <LibCore/CEvent.h>
+#include <LibCore/CEventLoop.h>
+#include <LibCore/CNotifier.h>
CNotifier::CNotifier(int fd, unsigned event_mask)
: m_fd(fd)
@@ -13,4 +13,3 @@ CNotifier::~CNotifier()
{
CEventLoop::unregister_notifier(Badge<CNotifier>(), *this);
}
-
diff --git a/LibCore/CNotifier.h b/LibCore/CNotifier.h
index baa3532b92..736d78e04b 100644
--- a/LibCore/CNotifier.h
+++ b/LibCore/CNotifier.h
@@ -4,10 +4,11 @@
class CNotifier {
public:
- enum Event {
- None = 0,
- Read = 1,
- Write = 2,
+ enum Event
+ {
+ None = 0,
+ Read = 1,
+ Write = 2,
Exceptional = 4,
};
CNotifier(int fd, unsigned event_mask);
diff --git a/LibCore/CObject.cpp b/LibCore/CObject.cpp
index 93f7733c92..a5ea5e6977 100644
--- a/LibCore/CObject.cpp
+++ b/LibCore/CObject.cpp
@@ -1,7 +1,7 @@
-#include <LibCore/CObject.h>
+#include <AK/Assertions.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
-#include <AK/Assertions.h>
+#include <LibCore/CObject.h>
#include <stdio.h>
CObject::CObject(CObject* parent, bool is_widget)
@@ -100,7 +100,7 @@ void CObject::dump_tree(int indent)
}
printf("%s{%p}\n", class_name(), this);
- for_each_child([&] (auto& child) {
+ for_each_child([&](auto& child) {
child.dump_tree(indent + 2);
return IterationDecision::Continue;
});
diff --git a/LibCore/CObject.h b/LibCore/CObject.h
index a4eac52eec..fda00cd976 100644
--- a/LibCore/CObject.h
+++ b/LibCore/CObject.h
@@ -29,7 +29,8 @@ public:
}
}
- template<typename T, typename Callback> void for_each_child_of_type(Callback callback);
+ template<typename T, typename Callback>
+ void for_each_child_of_type(Callback callback);
CObject* parent() { return m_parent; }
const CObject* parent() const { return m_parent; }
@@ -61,7 +62,8 @@ private:
Vector<CObject*> m_children;
};
-template<typename T> inline bool is(const CObject&) { return true; }
+template<typename T>
+inline bool is(const CObject&) { return true; }
template<typename T>
inline T& to(CObject& object)
@@ -80,7 +82,7 @@ inline const T& to(const CObject& object)
template<typename T, typename Callback>
inline void CObject::for_each_child_of_type(Callback callback)
{
- for_each_child([&] (auto& child) {
+ for_each_child([&](auto& child) {
if (is<T>(child))
return callback(to<T>(child));
return IterationDecision::Continue;
diff --git a/LibCore/CProcessStatisticsReader.cpp b/LibCore/CProcessStatisticsReader.cpp
index 1a80f306c3..439ec36e13 100644
--- a/LibCore/CProcessStatisticsReader.cpp
+++ b/LibCore/CProcessStatisticsReader.cpp
@@ -1,8 +1,8 @@
#include "CProcessStatisticsReader.h"
#include "CFile.h"
-#include <stdio.h>
#include <pwd.h>
+#include <stdio.h>
CProcessStatisticsReader::CProcessStatisticsReader()
{
@@ -64,7 +64,7 @@ void CProcessStatisticsReader::update_map(HashMap<pid_t, CProcessStatistics>& ma
process.username = get_username_from_uid(uid);
process.priority = parts[16];
-
+
process.syscalls = parts[17].to_uint(ok);
if (!ok) {
fprintf(stderr, "CProcessHelper : couldn't convert %s to a valid syscalls count value\n", parts[17].characters());
diff --git a/LibCore/CProcessStatisticsReader.h b/LibCore/CProcessStatisticsReader.h
index 2ce97e9f68..df9b788ea2 100644
--- a/LibCore/CProcessStatisticsReader.h
+++ b/LibCore/CProcessStatisticsReader.h
@@ -24,6 +24,6 @@ public:
private:
void update_map(HashMap<pid_t, CProcessStatistics>& map);
String get_username_from_uid(const uid_t uid);
-
+
HashMap<uid_t, String> m_usernames;
};
diff --git a/LibCore/CSocket.cpp b/LibCore/CSocket.cpp
index e29caefe29..ea9a7135ec 100644
--- a/LibCore/CSocket.cpp
+++ b/LibCore/CSocket.cpp
@@ -1,12 +1,12 @@
-#include <LibCore/CSocket.h>
#include <LibCore/CNotifier.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <LibCore/CSocket.h>
#include <arpa/inet.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <netdb.h>
#include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
CSocket::CSocket(Type type, CObject* parent)
: CIODevice(parent)
diff --git a/LibCore/CSocket.h b/LibCore/CSocket.h
index b02133f050..0de7872fb2 100644
--- a/LibCore/CSocket.h
+++ b/LibCore/CSocket.h
@@ -7,7 +7,12 @@ class CNotifier;
class CSocket : public CIODevice {
public:
- enum class Type { Invalid, TCP, UDP };
+ enum class Type
+ {
+ Invalid,
+ TCP,
+ UDP
+ };
virtual ~CSocket() override;
bool connect(const String& hostname, int port);
diff --git a/LibCore/CSocketAddress.h b/LibCore/CSocketAddress.h
index 5de064dd95..efa545f24c 100644
--- a/LibCore/CSocketAddress.h
+++ b/LibCore/CSocketAddress.h
@@ -4,9 +4,14 @@
class CSocketAddress {
public:
- enum class Type { Invalid, IPv4, Local };
+ enum class Type
+ {
+ Invalid,
+ IPv4,
+ Local
+ };
- CSocketAddress() { }
+ CSocketAddress() {}
CSocketAddress(const IPv4Address& address)
: m_type(Type::IPv4)
, m_ipv4_address(address)
@@ -20,8 +25,10 @@ public:
String to_string() const
{
switch (m_type) {
- case Type::IPv4: return m_ipv4_address.to_string();
- default: return "[CSocketAddress]";
+ case Type::IPv4:
+ return m_ipv4_address.to_string();
+ default:
+ return "[CSocketAddress]";
}
}
diff --git a/LibCore/CTCPSocket.h b/LibCore/CTCPSocket.h
index c48331f9ee..fe4f3ffb3a 100644
--- a/LibCore/CTCPSocket.h
+++ b/LibCore/CTCPSocket.h
@@ -7,4 +7,3 @@ public:
private:
};
-
diff --git a/LibCore/CTimer.h b/LibCore/CTimer.h
index 4d0507512f..b6c1c2005f 100644
--- a/LibCore/CTimer.h
+++ b/LibCore/CTimer.h
@@ -1,7 +1,7 @@
#pragma once
-#include <LibCore/CObject.h>
#include <AK/Function.h>
+#include <LibCore/CObject.h>
class CTimer final : public CObject {
public:
diff --git a/LibCore/CUserInfo.cpp b/LibCore/CUserInfo.cpp
index 9efe160489..d5308d454e 100644
--- a/LibCore/CUserInfo.cpp
+++ b/LibCore/CUserInfo.cpp
@@ -1,7 +1,7 @@
#include "CUserInfo.h"
+#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
-#include <pwd.h>
const char* get_current_user_home_path()
{
diff --git a/LibCore/CUserInfo.h b/LibCore/CUserInfo.h
index 22ef0a8fb4..b47cec4af1 100644
--- a/LibCore/CUserInfo.h
+++ b/LibCore/CUserInfo.h
@@ -1 +1 @@
-const char *get_current_user_home_path();
+const char* get_current_user_home_path();