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) 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 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. 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..90efd43ba --- /dev/null +++ b/runtime/agg/cpp/aggregators/sort/agg-bsd.h @@ -0,0 +1,62 @@ +#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 invalid1 = true, invalid2 = true; + while (true) + { + if (invalid1) + { + std::getline(input1(), input1_top); + if (!input1()) + break; + invalid1 = false; + } + if (invalid2) + { + std::getline(input2(), input2_top); + if (!input2()) + break; + invalid2 = false; + } + + if (compare(input1_top, input2_top)) // input1_top < input2_top + { + output() << input1_top << '\n'; + invalid1 = true; + } + else + { + output() << input2_top << '\n'; + invalid2 = true; + } + } + + 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(); +} + +#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 #