From 2b4db9ddb1616ce6fe56575724c966177bb950f7 Mon Sep 17 00:00:00 2001 From: Dimitris Karnikis Date: Fri, 17 Sep 2021 10:46:36 +0300 Subject: [PATCH 1/5] Create Code of Conduct (#322) --- CODE_OF_CONDUCT.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..988a92566 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +* [PaSh Code of Conduct](https://github.com/binpash/admin/blob/main/CODE_OF_CONDUCT.md) From b115c513b604e9cccf1b969e925b733eb871ebd5 Mon Sep 17 00:00:00 2001 From: Jan Bielak Date: Tue, 5 Oct 2021 16:35:08 +0200 Subject: [PATCH 2/5] Fix aggregator instruction Signed-off-by: Jan Bielak --- runtime/agg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/agg/README.md b/runtime/agg/README.md index e731efba6..c102109eb 100644 --- a/runtime/agg/README.md +++ b/runtime/agg/README.md @@ -16,7 +16,7 @@ Let's assume that the aggregator being implemented is for a command called `cmd` 2. For each `OS` supported by PaSh: - 2.1 Create a file named `OS-agg.h` inside that folder + 2.1 Create a file named `agg-OS.h` inside that folder 2.2. Implement the aggregator inside that file using the instructions provided in `cpp/common/main.h` or use a different aggregator as an example. Remember about the include guard. From 388cccbff292e4fda21d46097a01cc69008a133b Mon Sep 17 00:00:00 2001 From: Jan Bielak Date: Tue, 5 Oct 2021 16:36:53 +0200 Subject: [PATCH 3/5] Begin adding sort aggregator Signed-off-by: Jan Bielak --- runtime/agg/cpp/aggregators/sort/agg-bsd.h | 57 ++++++++++++++++++++ runtime/agg/cpp/aggregators/sort/agg-linux.h | 1 + runtime/agg/cpp/tests/test-bsd.sh | 2 + runtime/agg/cpp/tests/test-linux.sh | 2 + 4 files changed, 62 insertions(+) create mode 100644 runtime/agg/cpp/aggregators/sort/agg-bsd.h create mode 100644 runtime/agg/cpp/aggregators/sort/agg-linux.h diff --git a/runtime/agg/cpp/aggregators/sort/agg-bsd.h b/runtime/agg/cpp/aggregators/sort/agg-bsd.h new file mode 100644 index 000000000..f650d3869 --- /dev/null +++ b/runtime/agg/cpp/aggregators/sort/agg-bsd.h @@ -0,0 +1,57 @@ +#ifndef AGG_SORT_H +#define AGG_SORT_H + +#include "main.h" +#include +#include +#include +#include + +inline constexpr cmd_opts g_options{ + // TODO +}; + +bool compare(const std::string& str1, const std::string& str2) +{ + return str1 < str2; +} + +void aggregate() noexcept +{ + std::string input1_top, input2_top; + bool refill1 = true, refill2 = true; + while (true) + { + if (refill1) + { + std::getline(input1(), input1_top); + if (!input1()) + break; + refill1 = false; + } + if (refill2) + { + std::getline(input2(), input2_top); + if (!input2()) + break; + refill2 = false; + } + + if (compare(input1_top, input2_top)) // input1_top < input2_top + { + output() << input1_top << '\n'; + refill1 = true; + } + else + { + output() << input2_top << '\n'; + refill2 = true; + } + } + + // At this point exactly one of the inputs is empty + // and the remaining input from the second one will get outputted + output() << input1().rdbuf() << input2().rdbuf(); +} + +#endif // AGG_SORT_H \ No newline at end of file diff --git a/runtime/agg/cpp/aggregators/sort/agg-linux.h b/runtime/agg/cpp/aggregators/sort/agg-linux.h new file mode 100644 index 000000000..cf6aaa5a4 --- /dev/null +++ b/runtime/agg/cpp/aggregators/sort/agg-linux.h @@ -0,0 +1 @@ +#include "agg-bsd.h" \ No newline at end of file diff --git a/runtime/agg/cpp/tests/test-bsd.sh b/runtime/agg/cpp/tests/test-bsd.sh index 6ed04a93b..862ab2ae7 100755 --- a/runtime/agg/cpp/tests/test-bsd.sh +++ b/runtime/agg/cpp/tests/test-bsd.sh @@ -42,6 +42,8 @@ ./test-common.sh uniq "-c" ../bin/uniq ./test-common.sh uniq "--count" ../bin/uniq +./test-common.sh sort "" ../bin/sort + # These tests are run during PASH_TOP/scripts/run_tests.sh # Make sure to build the aggregators using PASH_TOP/scripts/setup-pash.sh first # diff --git a/runtime/agg/cpp/tests/test-linux.sh b/runtime/agg/cpp/tests/test-linux.sh index f7bd59b01..e5880730a 100755 --- a/runtime/agg/cpp/tests/test-linux.sh +++ b/runtime/agg/cpp/tests/test-linux.sh @@ -46,6 +46,8 @@ ./test-common.sh uniq "-c" ../bin/uniq ./test-common.sh uniq "--count" ../bin/uniq +./test-common.sh sort "" ../bin/sort + # These tests are run during PASH_TOP/scripts/run_tests.sh # Make sure to build the aggregators using PASH_TOP/scripts/setup-pash.sh first # From 77982dd9b0190b009239a1c07c20c9c586ad616f Mon Sep 17 00:00:00 2001 From: Jan Bielak Date: Tue, 5 Oct 2021 16:40:14 +0200 Subject: [PATCH 4/5] Update libdash Signed-off-by: Jan Bielak --- compiler/parser/libdash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/parser/libdash b/compiler/parser/libdash index 65d973109..ef6302502 160000 --- a/compiler/parser/libdash +++ b/compiler/parser/libdash @@ -1 +1 @@ -Subproject commit 65d9731091778c16dd16efa6da0e7cc7ce5811b1 +Subproject commit ef6302502b904e33dd4cc686d71142fb1a87bbbd From 0b5e1e74133e151816c2c1ff53800f81d55118c5 Mon Sep 17 00:00:00 2001 From: Jan Bielak Date: Tue, 5 Oct 2021 19:22:12 +0200 Subject: [PATCH 5/5] Fix sort aggregator Signed-off-by: Jan Bielak --- runtime/agg/cpp/aggregators/sort/agg-bsd.h | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/runtime/agg/cpp/aggregators/sort/agg-bsd.h b/runtime/agg/cpp/aggregators/sort/agg-bsd.h index f650d3869..90efd43ba 100644 --- a/runtime/agg/cpp/aggregators/sort/agg-bsd.h +++ b/runtime/agg/cpp/aggregators/sort/agg-bsd.h @@ -19,38 +19,43 @@ bool compare(const std::string& str1, const std::string& str2) void aggregate() noexcept { std::string input1_top, input2_top; - bool refill1 = true, refill2 = true; + bool invalid1 = true, invalid2 = true; while (true) { - if (refill1) + if (invalid1) { std::getline(input1(), input1_top); if (!input1()) break; - refill1 = false; + invalid1 = false; } - if (refill2) + if (invalid2) { std::getline(input2(), input2_top); if (!input2()) break; - refill2 = false; + invalid2 = false; } if (compare(input1_top, input2_top)) // input1_top < input2_top { output() << input1_top << '\n'; - refill1 = true; + invalid1 = true; } else { output() << input2_top << '\n'; - refill2 = true; + invalid2 = true; } } - // At this point exactly one of the inputs is empty - // and the remaining input from the second one will get outputted + if(!invalid1) + output() << input1_top << '\n'; + if(!invalid2) + output() << input2_top << '\n'; + + // At this point at least one of the inputs + // is empty, so the other one can sefely be forwarded output() << input1().rdbuf() << input2().rdbuf(); }