move print_comments in cli, next to read_comments

This commit is contained in:
Frédéric Mangano-Tarumi 2018-11-11 12:04:16 -05:00
parent 632caae915
commit c17ad7853c
3 changed files with 27 additions and 21 deletions

View File

@ -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<std::string>& 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<std::string> ot::read_tags(FILE* file)
std::list<std::string> ot::read_comments(FILE* input)
{
std::list<std::string> comments;
auto raw_tags = std::make_unique<char[]>(16383);

View File

@ -10,23 +10,6 @@
#include <unistd.h>
#include <ogg/ogg.h>
/**
* 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

View File

@ -207,7 +207,9 @@ struct options {
};
status process_options(int argc, char** argv, options& opt);
std::list<std::string> read_tags(FILE* file);
void print_comments(const std::list<std::string>& comments, FILE* output);
std::list<std::string> read_comments(FILE* input);
/** \} */