feat(judger): add "x bytes omitted" info
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-01-29 18:40:28 +08:00
parent cea0e82db8
commit 74127afe25
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 10 additions and 2 deletions

View File

@ -133,6 +133,9 @@ string file_preview(const string &name, const int &len = 100) {
return "";
}
struct stat stat_buf;
stat(name.c_str(), &stat_buf);
string res = "";
if (len == -1) {
int c;
@ -145,8 +148,9 @@ string file_preview(const string &name, const int &len = 100) {
res += c;
}
if ((int)res.size() > len + 3) {
int omitted = (int)stat_buf.st_size - len;
res.resize(len);
res += "...";
res += "\n\n(" + to_string(omitted) + " bytes omitted)";
}
}
fclose(f);

View File

@ -130,6 +130,9 @@ string file_preview(const string &name, const int &len = 100) {
return "";
}
struct stat stat_buf;
stat(name.c_str(), &stat_buf);
string res = "";
if (len == -1) {
int c;
@ -142,8 +145,9 @@ string file_preview(const string &name, const int &len = 100) {
res += c;
}
if ((int)res.size() > len + 3) {
int omitted = (int)stat_buf.st_size - len;
res.resize(len);
res += "...";
res += "\n\n(" + to_string(omitted) + " bytes omitted)";
}
}
fclose(f);