Skip to content

Commit

Permalink
Add --bps option to wwivutil print
Browse files Browse the repository at this point in the history
This emulates a bps rate when displaying the file.
  • Loading branch information
wwiv committed Nov 18, 2020
1 parent 44caf02 commit b50c117
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
39 changes: 4 additions & 35 deletions bbs/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void jump_conf(ConferenceType conftype) {
auto& uc = conftype == ConferenceType::CONF_SUBS ? a()->uconfsub : a()->uconfdir;
if (const auto o = conf.try_conf(ch)) {
setuconf(conf, o.value().key.key(), -1);
for (int i=0; i < size_int(uc); i++) {
for (auto i=0; i < size_int(uc); i++) {
if (ch == at(uc, i).key.key()) {
if (conftype == ConferenceType::CONF_SUBS) {
a()->sess().set_current_user_sub_conf_num(i);
Expand All @@ -164,44 +164,13 @@ void jump_conf(ConferenceType conftype) {
}
}

/*
* Returns true if subnum is allocated to conference c, 0 otherwise.
*/
bool in_conference(subconf_t subnum, confrec_430_t* c) {
if (!c) {
return false;
}
for (const auto& s : c->subs) {
if (s == subnum) {
return true;
}
}
return false;
}

/*
* Returns first available conference key, of a specified conference
* type.
*/
char first_available_key(const Conference& conf) {
if (conf.size() == MAX_CONFERENCES) {
return 0;
}
if (conf.confs().empty()) {
return 'A';
}
auto cv = conf.confs();
const auto last = std::end(cv);
return static_cast<char>(last->key.key() + 1);
}

static int display_conf_subs(Conference& conf) {
auto abort = false;
bout.cls();
bout.bpla("|#2NN Name ConfList", &abort);
bout.bpla("|#7--- ======================================= ==========================", &abort);

int count = 0;
auto count = 0;
switch (conf.type()) {
case ConferenceType::CONF_SUBS: {
count = size_int(a()->subs().subs());
Expand Down Expand Up @@ -233,7 +202,7 @@ static conf_set_t& get_conf_set(Conference& conf, int num) {
}

void edit_conf_subs(Conference& conf) {
bool changed{false};
auto changed{false};
while (!a()->sess().hangup()) {
const auto count = display_conf_subs(conf);
bout.nl();
Expand Down Expand Up @@ -385,7 +354,7 @@ static void delete_conf(Conference& conf, char key) {
* Function for editing conferences.
*/
void conf_edit(Conference& conf) {
bool done = false;
auto done = false;

do {
bout.cls();
Expand Down
5 changes: 2 additions & 3 deletions bbs/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class conf_info_t {
int num_subs_or_dirs = 0;
};

bool in_conference(wwiv::sdk::subconf_t subnum, wwiv::sdk::confrec_430_t* c);

void tmp_disable_conf(bool disable);
void reset_disable_conf();
conf_info_t get_conf_info(wwiv::sdk::ConferenceType conftype);
Expand All @@ -52,7 +50,8 @@ void jump_conf(wwiv::sdk::ConferenceType conftype);
void conf_edit(wwiv::sdk::Conference& conf);
void list_confs(wwiv::sdk::ConferenceType conftype, bool list_subs);
void list_confs(wwiv::sdk::Conference& conf, bool list_subs = true);
std::optional<char> select_conf(const std::string& prompt_text, wwiv::sdk::Conference& conf, bool listconfs);
std::optional<char> select_conf(const std::string& prompt_text, wwiv::sdk::Conference& conf,
bool listconfs);

/**
* Select the conferences to which dirs and subs belong.
Expand Down
18 changes: 17 additions & 1 deletion wwivutil/print/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#include "wwivutil/print/print.h"

#include "core/command_line.h"
#include "core/datetime.h"
#include "core/log.h"
#include "core/file.h"
#include "core/os.h"
#include "core/stl.h"
#include "core/strings.h"
#include "core/textfile.h"
Expand All @@ -35,7 +37,8 @@
using std::cout;
using std::endl;
using wwiv::core::BooleanCommandLineArgument;
using namespace wwiv::core;
using namespace std::chrono_literals;
using namespace wwiv::os;
using namespace wwiv::sdk;
using namespace wwiv::sdk::ansi;
using namespace wwiv::strings;
Expand Down Expand Up @@ -122,6 +125,7 @@ int PrintCommand::Execute() {
} else {
std::unique_ptr<LocalIO> io;
const auto io_type = sarg("io");
const auto bps = iarg("bps");
#ifdef _WIN32
if (io_type == "win32") {
io = std::make_unique<Win32ConsoleIO>();
Expand All @@ -142,12 +146,23 @@ int PrintCommand::Execute() {
HeartCodeFilter heart(&ansi, {7, 11, 14, 5, 31, 2, 12, 9, 6, 3});

screen.clear();
auto count = 0;
const auto allowed_per_100ms = bps / 100;

auto start = core::DateTime::now();
for (const auto c : s) {
if (allowed_per_100ms > 0 && (++count % allowed_per_100ms == 0)) {
sleep_for(100ms);
}
heart.write(c);
}
auto end = core::DateTime::now();

if (need_pause) {
io->GetChar();
}
VLOG(1) << "Wrote: " << count << " chars.";
VLOG(1) << "CPS = " << count / (end.to_time_t() - start.to_time_t());
}
return 0;
}
Expand All @@ -160,6 +175,7 @@ bool PrintCommand::AddSubCommands() {
#else
"curses"});
#endif
add_argument({"bps", "What BPS to emulate", "14400"});
return true;
}

Expand Down

0 comments on commit b50c117

Please sign in to comment.