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
|
|
|
*/
|
|
|
|
|
|
2019-04-26 00:53:57 +02:00
|
|
|
#include <AK/QuickSort.h>
|
2020-03-08 12:05:14 +01:00
|
|
|
#include <AK/String.h>
|
2019-04-26 00:53:57 +02:00
|
|
|
#include <AK/Vector.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
|
|
|
|
2020-12-20 16:09:48 -07:00
|
|
|
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
2019-04-26 00:53:57 +02:00
|
|
|
{
|
2020-02-18 11:02:36 +01:00
|
|
|
if (pledge("stdio", nullptr) > 0) {
|
|
|
|
|
perror("pledge");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 00:53:57 +02:00
|
|
|
Vector<String> lines;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-03-03 16:01:37 +01:00
|
|
|
quick_sort(lines, [](auto& a, auto& b) {
|
2019-04-26 00:53:57 +02:00
|
|
|
return strcmp(a.characters(), b.characters()) < 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (auto& line : lines) {
|
|
|
|
|
fputs(line.characters(), stdout);
|
2021-01-19 22:59:34 +01:00
|
|
|
fputc('\n', stdout);
|
2019-04-26 00:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|