From 74127afe25eb5233ff45f4a35ea062b4f122a376 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 29 Jan 2023 18:40:28 +0800 Subject: [PATCH] feat(judger): add "x bytes omitted" info --- judger/uoj_judger/include/uoj_judger.h | 6 +++++- judger/uoj_judger/include/uoj_judger_v2.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/judger/uoj_judger/include/uoj_judger.h b/judger/uoj_judger/include/uoj_judger.h index ac4c6f0..daf825e 100644 --- a/judger/uoj_judger/include/uoj_judger.h +++ b/judger/uoj_judger/include/uoj_judger.h @@ -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); diff --git a/judger/uoj_judger/include/uoj_judger_v2.h b/judger/uoj_judger/include/uoj_judger_v2.h index cc1222b..d804a4f 100644 --- a/judger/uoj_judger/include/uoj_judger_v2.h +++ b/judger/uoj_judger/include/uoj_judger_v2.h @@ -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);