From c17ad7853cf3d903ce95863a13826cbf35e0db6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 11 Nov 2018 12:04:16 -0500 Subject: [PATCH] move print_comments in cli, next to read_comments --- src/cli.cc | 23 ++++++++++++++++++++++- src/opustags.cc | 21 ++------------------- src/opustags.h | 4 +++- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 2c2f2f6..b575dd8 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -144,9 +144,30 @@ ot::status ot::process_options(int argc, char** argv, ot::options& opt) } /** + * Display the tags on stdout. + * + * Print all the comments, separated by line breaks. Since a comment may + * contain line breaks, this output is not completely reliable, but it fits + * most cases. + * + * The output generated is meant to be parseable by #ot::read_tags. + * + * \todo Escape new lines. + */ +void ot::print_comments(const std::list& comments, FILE* output) +{ + for (const std::string& comment : comments) { + fwrite(comment.data(), 1, comment.size(), output); + puts(""); + } +} + +/** + * Parse the comments outputted by #ot::print_comments. + * * \todo Use an std::istream or getline. Lift the 16 KiB limitation and whatever's hardcoded here. */ -std::list ot::read_tags(FILE* file) +std::list ot::read_comments(FILE* input) { std::list comments; auto raw_tags = std::make_unique(16383); diff --git a/src/opustags.cc b/src/opustags.cc index fa92d38..0392a6a 100644 --- a/src/opustags.cc +++ b/src/opustags.cc @@ -10,23 +10,6 @@ #include #include -/** - * Display the tags on stdout. - * - * Print all the comments, separated by line breaks. Since a comment may - * contain line breaks, this output is not completely reliable, but it fits - * most cases. - * - * Only the comments are displayed. - */ -static void print_tags(ot::opus_tags &tags) -{ - for (const std::string& comment : tags.comments) { - fwrite(comment.data(), 1, comment.size(), stdout); - puts(""); - } -} - /** * Check if two filepaths point to the same file, after path canonicalization. * The path "-" is treated specially, meaning stdin for path_in and stdout for path_out. @@ -143,7 +126,7 @@ static int run(ot::options& opt) ot::delete_tags(&tags, name.c_str()); } if (opt.set_all) - tags.comments = ot::read_tags(stdin); + tags.comments = ot::read_comments(stdin); for (const std::string& comment : opt.to_add) tags.comments.emplace_back(comment); if(writer.file){ @@ -154,7 +137,7 @@ static int run(ot::options& opt) free(packet.packet); } else - print_tags(tags); + ot::print_comments(tags.comments, stdout); if(error || !writer.file) break; else diff --git a/src/opustags.h b/src/opustags.h index 7edca25..4505245 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -207,7 +207,9 @@ struct options { }; status process_options(int argc, char** argv, options& opt); -std::list read_tags(FILE* file); + +void print_comments(const std::list& comments, FILE* output); +std::list read_comments(FILE* input); /** \} */