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