2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2019-04-26 00:53:57 +02:00
|
|
|
#include <AK/QuickSort.h>
|
|
|
|
|
#include <AK/Vector.h>
|
2022-01-20 21:13:12 +01:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibMain/Main.h>
|
2020-10-15 00:31:33 -06:00
|
|
|
#include <errno.h>
|
2019-04-26 00:53:57 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2020-03-08 12:05:14 +01:00
|
|
|
#include <string.h>
|
2021-03-12 17:29:37 +01:00
|
|
|
#include <unistd.h>
|
2019-04-26 00:53:57 +02:00
|
|
|
|
2022-01-20 21:13:12 +01:00
|
|
|
ErrorOr<int> serenity_main([[maybe_unused]] Main::Arguments arguments)
|
2019-04-26 00:53:57 +02:00
|
|
|
{
|
2022-01-20 21:13:12 +01:00
|
|
|
TRY(Core::System::pledge("stdio"sv));
|
2020-02-18 11:02:36 +01:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> lines;
|
2019-04-26 00:53:57 +02:00
|
|
|
|
|
|
|
|
for (;;) {
|
2020-10-15 00:31:33 -06:00
|
|
|
char* buffer = nullptr;
|
|
|
|
|
ssize_t buflen = 0;
|
2020-12-10 00:14:56 +11:00
|
|
|
size_t n;
|
2020-10-15 00:31:33 -06:00
|
|
|
errno = 0;
|
2020-12-10 00:14:56 +11:00
|
|
|
buflen = getline(&buffer, &n, stdin);
|
2020-10-15 00:31:33 -06:00
|
|
|
if (buflen == -1 && errno != 0) {
|
|
|
|
|
perror("getline");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (buflen == -1)
|
2019-04-26 00:53:57 +02:00
|
|
|
break;
|
2021-01-19 22:59:34 +01:00
|
|
|
lines.append({ buffer, AK::ShouldChomp::Chomp });
|
2019-04-26 00:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-04 22:31:29 +02:00
|
|
|
quick_sort(lines);
|
2019-04-26 00:53:57 +02:00
|
|
|
|
|
|
|
|
for (auto& line : lines) {
|
2021-09-04 22:31:29 +02:00
|
|
|
outln("{}", line);
|
2019-04-26 00:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|