1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

Userland: Run clang-format on everything.

This commit is contained in:
Andreas Kling 2019-06-07 11:49:31 +02:00
parent f7ede145b4
commit b07bbf383d
48 changed files with 271 additions and 268 deletions

View file

@ -1,6 +1,6 @@
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
static volatile bool got_alarm = false; static volatile bool got_alarm = false;
@ -11,7 +11,7 @@ int main(int c, char** v)
ret = alarm(2); ret = alarm(2);
printf("alarm() with an alarm(5) set: %u\n", ret); printf("alarm() with an alarm(5) set: %u\n", ret);
signal(SIGALRM, [] (int) { signal(SIGALRM, [](int) {
got_alarm = true; got_alarm = true;
}); });
printf("Entering infinite loop.\n"); printf("Entering infinite loop.\n");

View file

@ -1,10 +1,10 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -1,9 +1,9 @@
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv) int main(int argc, char** argv)
{ {
if (argc != 3) { if (argc != 3) {
printf("usage: chmod <octal-mode> <path>\n"); printf("usage: chmod <octal-mode> <path>\n");

View file

@ -1,10 +1,10 @@
#include <unistd.h> #include <AK/AKString.h>
#include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <AK/AKString.h> #include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv) int main(int argc, char** argv)
{ {
if (argc < 2) { if (argc < 2) {
printf("usage: chown <uid[:gid]> <path>\n"); printf("usage: chown <uid[:gid]> <path>\n");

View file

@ -6,4 +6,3 @@ int main(int, char**)
fflush(stdout); fflush(stdout);
return 0; return 0;
} }

View file

@ -1,11 +1,11 @@
#include <unistd.h> #include <AK/AKString.h>
#include <fcntl.h> #include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h>
#include <assert.h> #include <assert.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <AK/AKString.h> #include <unistd.h>
#include <AK/StringBuilder.h>
#include <AK/FileSystemPath.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -10,7 +10,13 @@ static void print_usage_and_exit()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
enum Mode { SegmentationViolation, DivisionByZero, IllegalInstruction, Abort }; enum Mode
{
SegmentationViolation,
DivisionByZero,
IllegalInstruction,
Abort
};
Mode mode = SegmentationViolation; Mode mode = SegmentationViolation;
if (argc != 2) if (argc != 2)

View file

@ -1,6 +1,6 @@
#include <time.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -21,4 +21,3 @@ int main(int argc, char** argv)
tm->tm_sec); tm->tm_sec);
return 0; return 0;
} }

View file

@ -1,9 +1,9 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
struct FileSystem { struct FileSystem {
String fs; String fs;

View file

@ -1,13 +1,13 @@
#include <LibCore/CFile.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <LibCore/CFile.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
CFile f("/proc/dmesg"); CFile f("/proc/dmesg");
if (!f.open(CIODevice::ReadOnly)) { if (!f.open(CIODevice::ReadOnly)) {
fprintf(stderr, "open: failed to open /proc/dmesg: %s", f.error_string()); fprintf(stderr, "open: failed to open /proc/dmesg: %s", f.error_string());

View file

@ -1,5 +1,5 @@
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
int main(int, char**) int main(int, char**)
{ {

View file

@ -1,7 +1,7 @@
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -1,24 +1,24 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h>
#include <time.h>
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GProgressBar.h>
#include <LibGUI/GApplication.h> #include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GProgressBar.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
static GWindow* make_launcher_window(); static GWindow* make_launcher_window();
static GWindow* make_progress_window(); static GWindow* make_progress_window();
@ -69,7 +69,7 @@ GWindow* make_launcher_window()
terminal_button->set_relative_rect({ 5, 20, 90, 20 }); terminal_button->set_relative_rect({ 5, 20, 90, 20 });
terminal_button->set_text("Terminal"); terminal_button->set_text("Terminal");
terminal_button->on_click = [label] (GButton&) { terminal_button->on_click = [label](GButton&) {
pid_t child_pid = fork(); pid_t child_pid = fork();
if (!child_pid) { if (!child_pid) {
execve("/bin/Terminal", nullptr, nullptr); execve("/bin/Terminal", nullptr, nullptr);
@ -85,7 +85,7 @@ GWindow* make_launcher_window()
guitest_button->set_relative_rect({ 5, 50, 90, 20 }); guitest_button->set_relative_rect({ 5, 50, 90, 20 });
guitest_button->set_text("guitest"); guitest_button->set_text("guitest");
guitest_button->on_click = [label] (GButton&) { guitest_button->on_click = [label](GButton&) {
pid_t child_pid = fork(); pid_t child_pid = fork();
if (!child_pid) { if (!child_pid) {
execve("/bin/guitest", nullptr, nullptr); execve("/bin/guitest", nullptr, nullptr);
@ -120,7 +120,7 @@ GWindow* make_launcher_window()
auto* close_button = new GButton(widget); auto* close_button = new GButton(widget);
close_button->set_relative_rect({ 5, 200, 90, 20 }); close_button->set_relative_rect({ 5, 200, 90, 20 });
close_button->set_text("Close"); close_button->set_text("Close");
close_button->on_click = [window] (GButton&) { close_button->on_click = [window](GButton&) {
window->close(); window->close();
}; };
@ -169,7 +169,7 @@ static GWindow* make_frames_window()
widget->layout()->set_margins({ 8, 8, 8, 8 }); widget->layout()->set_margins({ 8, 8, 8, 8 });
widget->layout()->set_spacing(8); widget->layout()->set_spacing(8);
auto add_label = [widget] (const String& text, FrameShape shape, FrameShadow shadow) { auto add_label = [widget](const String& text, FrameShape shape, FrameShadow shadow) {
auto* label = new GLabel(text, widget); auto* label = new GLabel(text, widget);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fill); label->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
label->set_frame_thickness(1); label->set_frame_thickness(1);

View file

@ -1,7 +1,7 @@
#include <LibCore/CArgsParser.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <LibCore/CArgsParser.h>
int head(const String& filename, bool print_filename, int line_count); int head(const String& filename, bool print_filename, int line_count);
@ -40,7 +40,7 @@ int main(int argc, char** argv)
int rc = 0; int rc = 0;
for (auto &file : files) { for (auto& file : files) {
if (head(file, print_filenames, line_count) != 0) { if (head(file, print_filenames, line_count) != 0) {
rc = 1; rc = 1;
} }

View file

@ -1,8 +1,8 @@
#include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -1,12 +1,12 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
char buffer[HOST_NAME_MAX]; char buffer[HOST_NAME_MAX];
int rc = gethostname(buffer, sizeof(buffer)); int rc = gethostname(buffer, sizeof(buffer));
if (rc < 0) { if (rc < 0) {
@ -16,4 +16,3 @@ int main(int argc, char** argv)
printf("%s\n", buffer); printf("%s\n", buffer);
return 0; return 0;
} }

View file

@ -1,15 +1,15 @@
#include <unistd.h>
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <alloca.h> #include <alloca.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
extern "C" int main(int, char**); extern "C" int main(int, char**);
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
uid_t uid = getuid(); uid_t uid = getuid();
gid_t gid = getgid(); gid_t gid = getgid();
@ -40,4 +40,3 @@ int main(int argc, char** argv)
printf("\n"); printf("\n");
return 0; return 0;
} }

View file

@ -1,8 +1,8 @@
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void print_usage_and_exit() static void print_usage_and_exit()
{ {
@ -38,4 +38,3 @@ int main(int argc, char** argv)
perror("kill"); perror("kill");
return 0; return 0;
} }

View file

@ -1,9 +1,9 @@
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void print_usage_and_exit() static void print_usage_and_exit()
{ {
@ -14,15 +14,15 @@ static void print_usage_and_exit()
static int kill_all(const String& process_name, const unsigned signum) static int kill_all(const String& process_name, const unsigned signum)
{ {
HashMap<pid_t, CProcessStatistics> processes = CProcessStatisticsReader().get_map(); HashMap<pid_t, CProcessStatistics> processes = CProcessStatisticsReader().get_map();
for (auto& it : processes) { for (auto& it : processes) {
if (it.value.name == process_name) { if (it.value.name == process_name) {
int ret = kill(it.value.pid, signum); int ret = kill(it.value.pid, signum);
if (ret < 0) if (ret < 0)
perror("kill"); perror("kill");
} }
} }
return 0; return 0;
} }
@ -31,16 +31,16 @@ int main(int argc, char** argv)
bool ok; bool ok;
unsigned signum = SIGTERM; unsigned signum = SIGTERM;
int name_argi = 1; int name_argi = 1;
if (argc != 2 && argc != 3) if (argc != 2 && argc != 3)
print_usage_and_exit(); print_usage_and_exit();
if (argc == 3) { if (argc == 3) {
name_argi = 2; name_argi = 2;
if (argv[1][0] != '-') if (argv[1][0] != '-')
print_usage_and_exit(); print_usage_and_exit();
signum = String(&argv[1][1]).to_uint(ok); signum = String(&argv[1][1]).to_uint(ok);
if (!ok) { if (!ok) {
printf("'%s' is not a valid signal number\n", &argv[1][1]); printf("'%s' is not a valid signal number\n", &argv[1][1]);

View file

@ -1,8 +1,8 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <LibCore/CArgsParser.h> #include <LibCore/CArgsParser.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -35,4 +35,3 @@ int main(int argc, char** argv)
} }
return 0; return 0;
} }

View file

@ -1,18 +1,18 @@
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include <time.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibCore/CDirIterator.h> #include <LibCore/CDirIterator.h>
#include <pwd.h> #include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <grp.h> #include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
static int do_file_system_object_long(const char* path); static int do_file_system_object_long(const char* path);
static int do_file_system_object_short(const char* path); static int do_file_system_object_short(const char* path);
@ -51,7 +51,7 @@ int main(int argc, char** argv)
} }
} }
auto do_file_system_object = [&] (const char* path) { auto do_file_system_object = [&](const char* path) {
if (flag_long) if (flag_long)
return do_file_system_object_long(path); return do_file_system_object_long(path);
return do_file_system_object_short(path); return do_file_system_object_short(path);
@ -60,7 +60,7 @@ int main(int argc, char** argv)
int status; int status;
if (optind >= argc) { if (optind >= argc) {
status = do_file_system_object("."); status = do_file_system_object(".");
} else if (optind+1 >= argc) { } else if (optind + 1 >= argc) {
status = do_file_system_object(argv[optind]); status = do_file_system_object(argv[optind]);
} else { } else {
for (; optind < argc; ++optind) { for (; optind < argc; ++optind) {
@ -119,7 +119,8 @@ int print_name(struct stat& st, const char* name, const char* path_for_link_reso
return nprinted; return nprinted;
} }
bool print_filesystem_object(const char* path, const char* name) { bool print_filesystem_object(const char* path, const char* name)
{
struct stat st; struct stat st;
int rc = lstat(path, &st); int rc = lstat(path, &st);
if (rc == -1) { if (rc == -1) {
@ -155,8 +156,7 @@ bool print_filesystem_object(const char* path, const char* name) {
st.st_mode & S_IWGRP ? 'w' : '-', st.st_mode & S_IWGRP ? 'w' : '-',
st.st_mode & S_ISGID ? 's' : (st.st_mode & S_IXGRP ? 'x' : '-'), st.st_mode & S_ISGID ? 's' : (st.st_mode & S_IXGRP ? 'x' : '-'),
st.st_mode & S_IROTH ? 'r' : '-', st.st_mode & S_IROTH ? 'r' : '-',
st.st_mode & S_IWOTH ? 'w' : '-' st.st_mode & S_IWOTH ? 'w' : '-');
);
if (st.st_mode & S_ISVTX) if (st.st_mode & S_ISVTX)
printf("t"); printf("t");
@ -166,14 +166,14 @@ bool print_filesystem_object(const char* path, const char* name) {
passwd* pwd = getpwuid(st.st_uid); passwd* pwd = getpwuid(st.st_uid);
group* grp = getgrgid(st.st_gid); group* grp = getgrgid(st.st_gid);
if (!flag_print_numeric && pwd) { if (!flag_print_numeric && pwd) {
printf(" %5s", pwd->pw_name); printf(" %5s", pwd->pw_name);
} else { } else {
printf(" %5u", st.st_uid); printf(" %5u", st.st_uid);
} }
if (!flag_print_numeric && grp) { if (!flag_print_numeric && grp) {
printf(" %5s", grp->gr_name); printf(" %5s", grp->gr_name);
} else { } else {
printf(" %5u", st.st_gid); printf(" %5u", st.st_gid);
} }
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
@ -221,8 +221,8 @@ int do_file_system_object_long(const char* path)
return 0; return 0;
} }
bool print_filesystem_object_short(const char* path, const char* name, int* nprinted)
bool print_filesystem_object_short(const char *path, const char *name, int *nprinted) { {
struct stat st; struct stat st;
int rc = lstat(path, &st); int rc = lstat(path, &st);
if (rc == -1) { if (rc == -1) {

View file

@ -1,10 +1,10 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
inline constexpr unsigned encoded_device(unsigned major, unsigned minor) inline constexpr unsigned encoded_device(unsigned major, unsigned minor)
{ {

View file

@ -1,12 +1,12 @@
#include <LibCore/CFile.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <LibCore/CFile.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
CFile f("/proc/mm"); CFile f("/proc/mm");
if (!f.open(CIODevice::ReadOnly)) { if (!f.open(CIODevice::ReadOnly)) {

View file

@ -1,7 +1,7 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h>
static int key_fd; static int key_fd;
@ -16,8 +16,8 @@ void wait_for_key()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
key_fd = open(ttyname(1), O_RDONLY); key_fd = open(ttyname(1), O_RDONLY);
if (key_fd < 0) { if (key_fd < 0) {
@ -36,10 +36,9 @@ int main(int argc, char** argv)
break; break;
printf(str); printf(str);
++lines_printed; ++lines_printed;
if ((lines_printed % (ws.ws_row - 1)) == 0) { if ((lines_printed % (ws.ws_row - 1)) == 0) {
wait_for_key(); wait_for_key();
} }
} }
close(key_fd); close(key_fd);

View file

@ -1,8 +1,8 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/FileSystemPath.h> #include <AK/FileSystemPath.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -1,18 +1,18 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/FileSystemPath.h>
#include <LibCore/CArgsParser.h> #include <LibCore/CArgsParser.h>
#include <LibCore/CDirIterator.h> #include <LibCore/CDirIterator.h>
#include <LibGUI/GDesktop.h>
#include <LibGUI/GApplication.h> #include <LibGUI/GApplication.h>
#include <LibGUI/GDesktop.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int handle_show_all() static int handle_show_all()
{ {
@ -73,4 +73,3 @@ int main(int argc, char** argv)
return handle_set_pape(values[0]); return handle_set_pape(values[0]);
} }

View file

@ -1,21 +1,21 @@
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <LibCore/CArgsParser.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/Vector.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/Vector.h>
#include <LibCore/CArgsParser.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static int pid_of(const String& process_name, bool single_shot, bool omit_pid, pid_t pid) static int pid_of(const String& process_name, bool single_shot, bool omit_pid, pid_t pid)
{ {
bool displayed_at_least_one = false; bool displayed_at_least_one = false;
HashMap<pid_t, CProcessStatistics> processes = CProcessStatisticsReader().get_map(); HashMap<pid_t, CProcessStatistics> processes = CProcessStatisticsReader().get_map();
for (auto& it : processes) { for (auto& it : processes) {
if (it.value.name == process_name) { if (it.value.name == process_name) {
if (!omit_pid || (omit_pid && it.value.pid != pid)) { if (!omit_pid || (omit_pid && it.value.pid != pid)) {
printf("%d ", it.value.pid); printf("%d ", it.value.pid);
displayed_at_least_one = true; displayed_at_least_one = true;
@ -40,11 +40,11 @@ int main(int argc, char** argv)
args_parser.add_arg("o", "pid", "Tells pidof to omit processes with that pid. The special pid %PPID can be used to name the parent process of the pidof program."); args_parser.add_arg("o", "pid", "Tells pidof to omit processes with that pid. The special pid %PPID can be used to name the parent process of the pidof program.");
CArgsParserResult args = args_parser.parse(argc, (const char**)argv); CArgsParserResult args = args_parser.parse(argc, (const char**)argv);
bool s_arg = args.is_present("s"); bool s_arg = args.is_present("s");
bool o_arg = args.is_present("o"); bool o_arg = args.is_present("o");
pid_t pid = 0; pid_t pid = 0;
if (o_arg) { if (o_arg) {
bool ok = false; bool ok = false;
String pid_str = args.get("o"); String pid_str = args.get("o");
@ -54,13 +54,13 @@ int main(int argc, char** argv)
else else
pid = pid_str.to_uint(ok); pid = pid_str.to_uint(ok);
} }
// We should have one single value : the process name // We should have one single value : the process name
Vector<String> values = args.get_single_values(); Vector<String> values = args.get_single_values();
if (values.size() == 0) { if (values.size() == 0) {
args_parser.print_usage(); args_parser.print_usage();
return 0; return 0;
} }
return pid_of(values[0], s_arg, o_arg, pid); return pid_of(values[0], s_arg, o_arg, pid);
} }

View file

@ -1,17 +1,17 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/ip_icmp.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <sys/socket.h>
#include <netdb.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h>
uint16_t internet_checksum(const void* ptr, size_t count) uint16_t internet_checksum(const void* ptr, size_t count)
{ {
uint32_t checksum = 0; uint32_t checksum = 0;
auto* w = (const uint16_t*)ptr; auto* w = (const uint16_t*)ptr;
while (count > 1) { while (count > 1) {
checksum += ntohs(*w++); checksum += ntohs(*w++);
@ -47,7 +47,9 @@ int main(int argc, char** argv)
return 1; return 1;
} }
struct timeval timeout { 1, 0 }; struct timeval timeout {
1, 0
};
int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (rc < 0) { if (rc < 0) {
perror("setsockopt"); perror("setsockopt");
@ -131,8 +133,7 @@ int main(int argc, char** argv)
ntohs(pong_packet.header.un.echo.id), ntohs(pong_packet.header.un.echo.id),
ntohs(pong_packet.header.un.echo.sequence), ntohs(pong_packet.header.un.echo.sequence),
pong_packet.header.un.echo.sequence != ping_packet.header.un.echo.sequence ? "(!)" : "", pong_packet.header.un.echo.sequence != ping_packet.header.un.echo.sequence ? "(!)" : "",
ms ms);
);
// If this was a response to an earlier packet, we still need to wait for the current one. // If this was a response to an earlier packet, we still need to wait for the current one.
if (pong_packet.header.un.echo.sequence != ping_packet.header.un.echo.sequence) if (pong_packet.header.un.echo.sequence != ping_packet.header.un.echo.sequence)

View file

@ -1,12 +1,12 @@
#include <LibCore/CFile.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <LibCore/CFile.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
CFile f("/proc/summary"); CFile f("/proc/summary");
if (!f.open(CIODevice::ReadOnly)) { if (!f.open(CIODevice::ReadOnly)) {

View file

@ -1,11 +1,11 @@
#include <SharedGraphics/PNGLoader.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GAction.h> #include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GWindow.h>
#include <SharedGraphics/PNGLoader.h>
#include <stdio.h> #include <stdio.h>
int main(int argc, char** argv) int main(int argc, char** argv)
@ -15,7 +15,7 @@ int main(int argc, char** argv)
auto menubar = make<GMenuBar>(); auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("QuickShow"); auto app_menu = make<GMenu>("QuickShow");
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) { app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) {
GApplication::the().quit(0); GApplication::the().quit(0);
return; return;
})); }));
@ -25,7 +25,7 @@ int main(int argc, char** argv)
menubar->add_menu(move(file_menu)); menubar->add_menu(move(file_menu));
auto help_menu = make<GMenu>("Help"); auto help_menu = make<GMenu>("Help");
help_menu->add_action(GAction::create("About", [] (const GAction&) { help_menu->add_action(GAction::create("About", [](const GAction&) {
dbgprintf("FIXME: Implement Help/About\n"); dbgprintf("FIXME: Implement Help/About\n");
})); }));
menubar->add_menu(move(help_menu)); menubar->add_menu(move(help_menu));

View file

@ -1,5 +1,5 @@
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
@ -15,4 +15,3 @@ int main(int argc, char** argv)
} }
return 0; return 0;
} }

View file

@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void handle_sigint(int) void handle_sigint(int)
{ {
@ -29,4 +29,3 @@ int main(int argc, char** argv)
} }
return 0; return 0;
} }

View file

@ -1,6 +1,6 @@
#include <AK/AKString.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/AKString.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -16,7 +16,7 @@ int main(int argc, char** argv)
lines.append(buffer); lines.append(buffer);
} }
quick_sort(lines.begin(), lines.end(), [] (auto& a, auto& b) { quick_sort(lines.begin(), lines.end(), [](auto& a, auto& b) {
return strcmp(a.characters(), b.characters()) < 0; return strcmp(a.characters(), b.characters()) < 0;
}); });

View file

@ -1,9 +1,9 @@
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <pwd.h>
#include <grp.h> #include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -62,8 +62,7 @@ int main(int argc, char** argv)
st.st_mode & S_IWGRP ? 'w' : '-', st.st_mode & S_IWGRP ? 'w' : '-',
st.st_mode & S_ISGID ? 's' : (st.st_mode & S_IXGRP ? 'x' : '-'), st.st_mode & S_ISGID ? 's' : (st.st_mode & S_IXGRP ? 'x' : '-'),
st.st_mode & S_IROTH ? 'r' : '-', st.st_mode & S_IROTH ? 'r' : '-',
st.st_mode & S_IWOTH ? 'w' : '-' st.st_mode & S_IWOTH ? 'w' : '-');
);
if (st.st_mode & S_ISVTX) if (st.st_mode & S_ISVTX)
printf("t"); printf("t");
@ -72,7 +71,7 @@ int main(int argc, char** argv)
printf(")\n"); printf(")\n");
auto print_time = [] (time_t t) { auto print_time = [](time_t t) {
auto* tm = localtime(&t); auto* tm = localtime(&t);
printf("%4u-%02u-%02u %02u:%02u:%02u\n", printf("%4u-%02u-%02u %02u:%02u:%02u\n",
tm->tm_year + 1900, tm->tm_year + 1900,

View file

@ -1,11 +1,11 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int usage() static int usage()
{ {

View file

@ -1,8 +1,8 @@
#include <unistd.h>
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <alloca.h> #include <alloca.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
extern "C" int main(int, char**); extern "C" int main(int, char**);

View file

@ -1,15 +1,15 @@
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibCore/CArgsParser.h> #include <LibCore/CArgsParser.h>
#include <LibCore/CDirIterator.h> #include <LibCore/CDirIterator.h>
#include <LibCore/CFile.h> #include <LibCore/CFile.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static String read_var(const String& name) static String read_var(const String& name)
{ {
@ -48,7 +48,6 @@ static void write_var(const String& name, const String& value)
} }
} }
static int handle_show_all() static int handle_show_all()
{ {
CDirIterator di("/proc/sys", CDirIterator::SkipDots); CDirIterator di("/proc/sys", CDirIterator::SkipDots);
@ -102,4 +101,3 @@ int main(int argc, char** argv)
Vector<String> values = args.get_single_values(); Vector<String> values = args.get_single_values();
return handle_var(values[0]); return handle_var(values[0]);
} }

View file

@ -1,11 +1,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <LibCore/CFile.h>
#include <LibCore/CArgsParser.h> #include <LibCore/CArgsParser.h>
#include <LibCore/CFile.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define DEFAULT_LINE_COUNT 10 #define DEFAULT_LINE_COUNT 10
@ -50,7 +50,7 @@ off_t find_seek_pos(CFile& file, int wanted_lines)
// FIXME: Reading char-by-char is only OK if CIODevice's read buffer // FIXME: Reading char-by-char is only OK if CIODevice's read buffer
// is smart enough to not read char-by-char. Fix it there, or fix it here :) // is smart enough to not read char-by-char. Fix it there, or fix it here :)
for(; pos >= 0; pos--) { for (; pos >= 0; pos--) {
file.seek(pos); file.seek(pos);
const auto& ch = file.read(1); const auto& ch = file.read(1);
if (ch.is_empty()) { if (ch.is_empty()) {
@ -74,7 +74,7 @@ static void exit_because_we_wanted_lines()
exit(1); exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
CArgsParser args_parser("tail"); CArgsParser args_parser("tail");
@ -98,7 +98,7 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
} else { } else {
line_count = DEFAULT_LINE_COUNT; line_count = DEFAULT_LINE_COUNT;
} }
CFile f(values[0]); CFile f(values[0]);

View file

@ -18,9 +18,11 @@ int main(int argc, char** argv)
if (fd < 0) { if (fd < 0) {
perror("socket"); perror("socket");
return 1; return 1;
} }
struct timeval timeout { 3, 0 }; struct timeval timeout {
3, 0
};
int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (rc < 0) { if (rc < 0) {
perror("setsockopt"); perror("setsockopt");

View file

@ -120,4 +120,3 @@ int main(int argc, char** argv)
return (err_open || err_write) ? 1 : 0; return (err_open || err_write) ? 1 : 0;
} }

View file

@ -1,12 +1,12 @@
#include <stdio.h> #include <AK/AKString.h>
#include <unistd.h> #include <AK/HashMap.h>
#include <AK/QuickSort.h>
#include <AK/Vector.h>
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <AK/HashMap.h> #include <unistd.h>
#include <AK/AKString.h>
#include <AK/Vector.h>
#include <AK/QuickSort.h>
static HashMap<unsigned, String>* s_usernames; static HashMap<unsigned, String>* s_usernames;
@ -89,14 +89,14 @@ int main(int, char**)
printf("\033[3J\033[H\033[2J"); printf("\033[3J\033[H\033[2J");
printf("\033[47;30m%6s %3s % 8s % 8s %6s %6s %4s %s\033[K\033[0m\n", printf("\033[47;30m%6s %3s % 8s % 8s %6s %6s %4s %s\033[K\033[0m\n",
"PID", "PID",
"PRI", "PRI",
"USER", "USER",
"STATE", "STATE",
"LINEAR", "LINEAR",
"COMMIT", "COMMIT",
"%CPU", "%CPU",
"NAME"); "NAME");
for (auto& it : current.map) { for (auto& it : current.map) {
pid_t pid = it.key; pid_t pid = it.key;
if (pid == 0) if (pid == 0)
@ -108,13 +108,12 @@ int main(int, char**)
dword nsched_before = (*jt).value.nsched; dword nsched_before = (*jt).value.nsched;
dword nsched_diff = nsched_now - nsched_before; dword nsched_diff = nsched_now - nsched_before;
it.value.nsched_since_prev = nsched_diff; it.value.nsched_since_prev = nsched_diff;
it.value.cpu_percent = ((nsched_diff * 100)/ sum_diff); it.value.cpu_percent = ((nsched_diff * 100) / sum_diff);
it.value.cpu_percent_decimal = (((nsched_diff * 1000)/ sum_diff) % 10); it.value.cpu_percent_decimal = (((nsched_diff * 1000) / sum_diff) % 10);
processes.append(&it.value); processes.append(&it.value);
} }
quick_sort(processes.begin(), processes.end(), [](auto* p1, auto* p2) {
quick_sort(processes.begin(), processes.end(), [] (auto* p1, auto* p2) {
return p2->nsched_since_prev < p1->nsched_since_prev; return p2->nsched_since_prev < p1->nsched_since_prev;
}); });
@ -128,8 +127,7 @@ int main(int, char**)
process->committed / 1024, process->committed / 1024,
process->cpu_percent, process->cpu_percent,
process->cpu_percent_decimal, process->cpu_percent_decimal,
process->name.characters() process->name.characters());
);
} }
processes.clear_with_capacity(); processes.clear_with_capacity();
prev = move(current); prev = move(current);

View file

@ -1,11 +1,11 @@
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <utime.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utime.h>
static bool file_exists(const char* path) static bool file_exists(const char* path)
{ {
@ -46,4 +46,3 @@ int main(int argc, char** argv)
} }
return 0; return 0;
} }

View file

@ -1,6 +1,6 @@
#include <AK/AKString.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/AKString.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
struct winsize ws; struct winsize ws;
int rc = ioctl(0, TIOCGWINSZ, &ws); int rc = ioctl(0, TIOCGWINSZ, &ws);

View file

@ -18,9 +18,11 @@ int main(int argc, char** argv)
if (fd < 0) { if (fd < 0) {
perror("socket"); perror("socket");
return 1; return 1;
} }
struct timeval timeout { 5, 0 }; struct timeval timeout {
5, 0
};
int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (rc < 0) { if (rc < 0) {
perror("setsockopt"); perror("setsockopt");
@ -41,12 +43,12 @@ int main(int argc, char** argv)
char buffer[BUFSIZ]; char buffer[BUFSIZ];
const char* msg = "Test message"; const char* msg = "Test message";
sendto(fd, (const char *)msg, strlen(msg), 0,(const struct sockaddr *)&dst_addr, sizeof(dst_addr)); sendto(fd, (const char*)msg, strlen(msg), 0, (const struct sockaddr*)&dst_addr, sizeof(dst_addr));
printf("Message sent.\n"); printf("Message sent.\n");
struct sockaddr_in src_addr; struct sockaddr_in src_addr;
socklen_t src_addr_len = sizeof(src_addr); socklen_t src_addr_len = sizeof(src_addr);
ssize_t nrecv = recvfrom(fd, (char *)buffer, sizeof(buffer), 0, (struct sockaddr*)&src_addr, &src_addr_len); ssize_t nrecv = recvfrom(fd, (char*)buffer, sizeof(buffer), 0, (struct sockaddr*)&src_addr, &src_addr_len);
if (nrecv < 0) { if (nrecv < 0) {
perror("recvfrom"); perror("recvfrom");
return 1; return 1;

View file

@ -20,11 +20,21 @@ int main(int argc, char** argv)
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
for (const char* o = &argv[i][1]; *o; ++o) { for (const char* o = &argv[i][1]; *o; ++o) {
switch (*o) { switch (*o) {
case 's': flag_s = true; break; case 's':
case 'n': flag_n = true; break; flag_s = true;
case 'r': flag_r = true; break; break;
case 'm': flag_m = true; break; case 'n':
case 'a': flag_s = flag_n = flag_r = flag_m = true; break; flag_n = true;
break;
case 'r':
flag_r = true;
break;
case 'm':
flag_m = true;
break;
case 'a':
flag_s = flag_n = flag_r = flag_m = true;
break;
} }
} }
} }
@ -43,4 +53,3 @@ int main(int argc, char** argv)
printf("\n"); printf("\n");
return 0; return 0;
} }

View file

@ -19,22 +19,22 @@ int main(int, char**)
sscanf(buffer, "%u", &seconds); sscanf(buffer, "%u", &seconds);
printf("Up "); printf("Up ");
if (seconds / 86400 > 0) { if (seconds / 86400 > 0) {
printf("%d day%s, ", seconds / 86400, (seconds / 86400) == 1 ? "" : "s"); printf("%d day%s, ", seconds / 86400, (seconds / 86400) == 1 ? "" : "s");
seconds %= 86400; seconds %= 86400;
} }
if (seconds / 3600 > 0) { if (seconds / 3600 > 0) {
printf("%d hour%s, ", seconds / 3600, (seconds / 3600) == 1 ? "" : "s"); printf("%d hour%s, ", seconds / 3600, (seconds / 3600) == 1 ? "" : "s");
seconds %= 3600; seconds %= 3600;
} }
if (seconds / 60 > 0) { if (seconds / 60 > 0) {
printf("%d minute%s, ", seconds / 60, (seconds / 60) == 1 ? "" : "s"); printf("%d minute%s, ", seconds / 60, (seconds / 60) == 1 ? "" : "s");
seconds %= 60; seconds %= 60;
} }
printf("%d second%s\n", seconds, seconds == 1 ? "" : "s"); printf("%d second%s\n", seconds, seconds == 1 ? "" : "s");
fclose(fp); fclose(fp);