CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
#include "yaml-cpp/emitterstyle.h"
|
|
#include "yaml-cpp/eventhandler.h"
|
|
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
|
|
|
|
#include <cstdlib>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
class NullEventHandler : public YAML::EventHandler {
|
|
public:
|
|
using Mark = YAML::Mark;
|
|
using anchor_t = YAML::anchor_t;
|
|
|
|
NullEventHandler() = default;
|
|
|
|
void OnDocumentStart(const Mark&) override {}
|
|
void OnDocumentEnd() override {}
|
|
void OnNull(const Mark&, anchor_t) override {}
|
|
void OnAlias(const Mark&, anchor_t) override {}
|
|
void OnScalar(const Mark&, const std::string&, anchor_t,
|
|
const std::string&) override {}
|
|
void OnSequenceStart(const Mark&, const std::string&, anchor_t,
|
|
YAML::EmitterStyle::value) override {}
|
|
void OnSequenceEnd() override {}
|
|
void OnMapStart(const Mark&, const std::string&, anchor_t,
|
|
YAML::EmitterStyle::value) override {}
|
|
void OnMapEnd() override {}
|
|
};
|
|
|
|
void run(std::istream& in) {
|
|
YAML::Parser parser(in);
|
|
NullEventHandler handler;
|
|
parser.HandleNextDocument(handler);
|
|
}
|
|
|
|
void usage() { std::cerr << "Usage: read [-n N] [-c, --cache] [filename]\n"; }
|
|
|
|
std::string read_stream(std::istream& in) {
|
|
return std::string((std::istreambuf_iterator<char>(in)),
|
|
std::istreambuf_iterator<char>());
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
int N = 1;
|
|
bool cache = false;
|
|
std::string filename;
|
|
for (int i = 1; i < argc; i++) {
|
|
std::string arg = argv[i];
|
|
if (arg == "-n") {
|
|
i++;
|
|
if (i >= argc) {
|
|
usage();
|
|
return -1;
|
|
}
|
|
N = std::atoi(argv[i]);
|
|
if (N <= 0) {
|
|
usage();
|
|
return -1;
|
|
}
|
|
} else if (arg == "-c" || arg == "--cache") {
|
|
cache = true;
|
|
} else {
|
|
filename = argv[i];
|
|
if (i + 1 != argc) {
|
|
usage();
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (N > 1 && !cache && filename.empty()) {
|
|
usage();
|
|
return -1;
|
|
}
|
|
|
|
if (cache) {
|
|
std::string input;
|
|
if (!filename.empty()) {
|
|
std::ifstream in(filename);
|
|
input = read_stream(in);
|
|
} else {
|
|
input = read_stream(std::cin);
|
|
}
|
|
std::istringstream in(input);
|
|
for (int i = 0; i < N; i++) {
|
|
in.seekg(std::ios_base::beg);
|
|
run(in);
|
|
}
|
|
} else {
|
|
if (!filename.empty()) {
|
|
std::ifstream in(filename);
|
|
for (int i = 0; i < N; i++) {
|
|
in.seekg(std::ios_base::beg);
|
|
run(in);
|
|
}
|
|
} else {
|
|
for (int i = 0; i < N; i++) {
|
|
run(std::cin);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|