Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make startup verbosity configurable #477

Merged
merged 8 commits into from
Jul 5, 2020
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Other differences:
| **[Wayland] support** | Experimental (use `SDL_VIDEODRIVER=wayland`) | N/A
| **Modem phonebook file** | Yes (`phonebookfile=<name>`) | N/A
| **Autotype command** | Yes<sup>[10]</sup> | N/A
| **Startup verbosity** | Yes<sup>[11]</sup> | N/A

[OPL]:https://en.wikipedia.org/wiki/Yamaha_YMF262
[CGA]:https://en.wikipedia.org/wiki/Color_Graphics_Adapter
Expand All @@ -77,6 +78,7 @@ Other differences:
[8]:https://www.vogons.org/viewtopic.php?f=9&t=37782
[9]:https://github.com/dosbox-staging/dosbox-staging/commit/ffe3c5ab7fb5e28bae78f07ea987904f391a7cf8
[10]:https://github.com/dosbox-staging/dosbox-staging/commit/239396fec83dbba6a1eb1a0f4461f4a427d2be38
[11]: https://github.com/dosbox-staging/dosbox-staging/pull/477

## Development snapshot builds

Expand Down
11 changes: 10 additions & 1 deletion include/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
#include "programs.h"
#include "setup.h"

class Config{
enum class Verbosity : int8_t {
// Show Splash | Show Welcome | Show Early Stdout |
High = 3, // yes | yes | yes |
Medium = 2, // no | yes | yes |
Low = 1, // no | no | yes |
Quiet = 0 // no | no | no |
};

class Config {
public:
CommandLine * cmdline;
private:
Expand Down Expand Up @@ -78,6 +86,7 @@ class Config{
void ParseEnv(char ** envp);
bool SecureMode() const { return secure_mode; }
void SwitchToSecureMode() { secure_mode = true; }//can't be undone
Verbosity GetStartupVerbosity() const;
};

#endif
3 changes: 3 additions & 0 deletions include/programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CommandLine {
bool GetStringRemain(std::string & value);
int GetParameterFromList(const char* const params[], std::vector<std::string> & output);
void FillVector(std::vector<std::string> & vector);
bool HasDirectory() const;
bool HasExecutableName() const;
unsigned int GetCount(void);
void Shift(unsigned int amount=1);
Bit16u Get_arglength();
Expand Down Expand Up @@ -84,6 +86,7 @@ class Program {
bool SetEnv(const char * entry,const char * new_string);
void WriteOut(const char *format, ...); // printf to DOS stdout
void WriteOut_NoParsing(const char *str); // write string to DOS stdout
bool SuppressWriteOut(const char *format); // prevent writing to DOS stdout
void InjectMissingNewline();
void ChangeToLongCmd();

Expand Down
2 changes: 2 additions & 0 deletions include/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ void strip_punctuation(std::string &str);
bool starts_with(const std::string &prefix, const std::string &str) noexcept;
bool ends_with(const std::string &suffix, const std::string &str) noexcept;

bool is_executable_filename(const std::string &filename) noexcept;

#endif
13 changes: 13 additions & 0 deletions src/dosbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ void DOSBOX_Init(void) {

constexpr auto always = Property::Changeable::Always;
constexpr auto when_idle = Property::Changeable::WhenIdle;
constexpr auto only_at_start = Property::Changeable::OnlyAtStart;

SDLNetInited = false;

Expand Down Expand Up @@ -444,6 +445,18 @@ void DOSBOX_Init(void) {
secprop->AddInitFunction(&TIMER_Init);//done
secprop->AddInitFunction(&CMOS_Init);//done

const char *verbosity_choices[] = {"high", "medium", "low",
"quiet", "auto", 0};
Pstring = secprop->Add_string("startup_verbosity", only_at_start, "high");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Pstring -> pstring (but it's minor I will merge it in anyway).

Pstring->Set_values(verbosity_choices);
Pstring->Set_help("Controls verbosity prior to displaying the program:\n"
" | Show splash | Show welcome | Show early stdout\n"
"high | yes | yes | yes\n"
"medium | no | yes | yes\n"
"low | no | no | yes\n"
"quiet | no | no | no\n"
"auto | 'low' if exec or dir is passed, otherwise 'high'");

secprop=control->AddSection_prop("render",&RENDER_Init,true);
Pint = secprop->Add_int("frameskip",Property::Changeable::Always,0);
Pint->SetMinMax(0,10);
Expand Down
3 changes: 2 additions & 1 deletion src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,8 @@ static void GUI_StartUp(Section * sec) {

const bool tiny_fullresolution = splash_image.width > sdl.desktop.full.width ||
splash_image.height > sdl.desktop.full.height;
if (!(sdl.desktop.fullscreen && tiny_fullresolution)) {
if (control->GetStartupVerbosity() == Verbosity::High &&
!(sdl.desktop.fullscreen && tiny_fullresolution)) {
GFX_Start();
DisplaySplash(1000);
GFX_Stop();
Expand Down
27 changes: 25 additions & 2 deletions src/misc/programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,28 @@ void Program::ChangeToLongCmd() {
full_arguments.assign(""); //Clear so it gets even more save
}

static char last_written_character = 0;//For 0xA to OxD 0xA expansion
void Program::WriteOut(const char * format,...) {
bool Program::SuppressWriteOut(const char *format)
{
// Have we encountered an executable thus far?
static bool encountered_executable = false;
if (encountered_executable)
return false;
if (control->GetStartupVerbosity() > Verbosity::Quiet)
return false;
if (!control->cmdline->HasExecutableName())
return false;

// Keep suppressing output until after we hit the first executable.
encountered_executable = is_executable_filename(format);
return true;
}

static char last_written_character = 0; // For 0xA to OxD 0xA expansion (\n to \r\n)
void Program::WriteOut(const char *format, ...)
{
if (SuppressWriteOut(format))
return;

char buf[2048];
va_list msg;

Expand All @@ -158,6 +178,9 @@ void Program::WriteOut(const char * format,...) {
}

void Program::WriteOut_NoParsing(const char * format) {
if (SuppressWriteOut(format))
return;

Bit16u size = (Bit16u)strlen(format);
char const* buf = format;
dos.internal_output=true;
Expand Down
39 changes: 39 additions & 0 deletions src/misc/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,27 @@ void Config::StartUp()
(*_start_function)();
}

Verbosity Config::GetStartupVerbosity() const
{
const Section* s = GetSection("dosbox");
assert(s);
const std::string user_choice = s->GetPropValue("startup_verbosity");

if (user_choice == "high")
return Verbosity::High;
if (user_choice == "medium")
return Verbosity::Medium;
if (user_choice == "low")
return Verbosity::Low;
if (user_choice == "quiet")
return Verbosity::Quiet;
// auto-mode
if (cmdline->HasDirectory() || cmdline->HasExecutableName())
return Verbosity::Low;
else
return Verbosity::High;
}

bool CommandLine::FindExist(char const * const name,bool remove) {
cmd_it it;
if (!(FindEntry(name,it,false))) return false;
Expand Down Expand Up @@ -1024,6 +1045,24 @@ bool CommandLine::FindCommand(unsigned int which,std::string & value) {
return true;
}

// Was a directory provided on the command line?
bool CommandLine::HasDirectory() const
{
for (const auto& arg : cmds)
if (open_directory(arg.c_str()))
return true;
return false;
}

// Was an executable filename provided on the command line?
bool CommandLine::HasExecutableName() const
{
for (const auto& arg : cmds)
if (is_executable_filename(arg))
return true;
return false;
}

bool CommandLine::FindEntry(char const * const name,cmd_it & it,bool neednext) {
for (it = cmds.begin(); it != cmds.end(); ++it) {
if (!strcasecmp((*it).c_str(),name)) {
Expand Down
12 changes: 12 additions & 0 deletions src/misc/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ bool ends_with(const std::string &suffix, const std::string &str) noexcept
return std::equal(sfx, sfx + n, txt, txt + n);
}

bool is_executable_filename(const std::string &filename) noexcept
{
const size_t n = filename.length();
if (n < 4)
return false;
if (filename[n - 4] != '.')
return false;
std::string sfx = filename.substr(n - 3);
lowcase(sfx);
return (sfx == "exe" || sfx == "bat" || sfx == "com");
}

void trim(std::string &str)
{
constexpr char whitespace[] = " \r\t\f\n";
Expand Down
22 changes: 14 additions & 8 deletions src/shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,23 @@ void DOS_Shell::Run(void) {
}
/* Start a normal shell and check for a first command init */
if (cmd->FindString("/INIT",line,true)) {
WriteOut(MSG_Get("SHELL_STARTUP_BEGIN"),VERSION);
const bool wants_welcome_banner = control->GetStartupVerbosity() >=
Verbosity::Medium;
if (wants_welcome_banner) {
WriteOut(MSG_Get("SHELL_STARTUP_BEGIN"), VERSION);
#if C_DEBUG
WriteOut(MSG_Get("SHELL_STARTUP_DEBUG"));
WriteOut(MSG_Get("SHELL_STARTUP_DEBUG"));
#endif
if (machine == MCH_CGA) {
if (mono_cga) WriteOut(MSG_Get("SHELL_STARTUP_CGA_MONO"));
else WriteOut(MSG_Get("SHELL_STARTUP_CGA"));
if (machine == MCH_CGA) {
if (mono_cga)
WriteOut(MSG_Get("SHELL_STARTUP_CGA_MONO"));
else
WriteOut(MSG_Get("SHELL_STARTUP_CGA"));
}
if (machine == MCH_HERC)
WriteOut(MSG_Get("SHELL_STARTUP_HERC"));
WriteOut(MSG_Get("SHELL_STARTUP_END"));
}
if (machine == MCH_HERC) WriteOut(MSG_Get("SHELL_STARTUP_HERC"));
WriteOut(MSG_Get("SHELL_STARTUP_END"));

safe_strcpy(input_line, line.c_str());
line.erase();
ParseLine(input_line);
Expand Down
5 changes: 1 addition & 4 deletions src/shell/shell_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,7 @@ void DOS_Shell::CMD_LS(char *args)
WriteOut("\033[34;1m%-15s\033[0m", name.c_str());
} else {
lowcase(name);
const bool is_executable = ends_with(".exe", name) ||
ends_with(".bat", name) ||
ends_with(".com", name);
if (is_executable)
if (is_executable_filename(name))
WriteOut("\033[32;1m%-15s\033[0m", name.c_str());
else
WriteOut("%-15s", name.c_str());
Expand Down
7 changes: 3 additions & 4 deletions src/shell/shell_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,13 @@ void DOS_Shell::InputCommand(char * line) {
dta.GetResult(name,sz,date,time,att);
// add result to completion list

char *ext; // file extension
if (strcmp(name, ".") && strcmp(name, "..")) {
if (dir_only) { //Handle the dir only case different (line starts with cd)
if(att & DOS_ATTR_DIRECTORY) l_completion.push_back(name);
} else {
ext = strrchr(name, '.');
if (ext && (strcmp(ext, ".BAT") == 0 || strcmp(ext, ".COM") == 0 || strcmp(ext, ".EXE") == 0))
// we add executables to the a seperate list and place that list infront of the normal files
if (is_executable_filename(name))
// Prepend executables to a separate list
// and place that list ahead of normal files.
executable.push_front(name);
else
l_completion.push_back(name);
Expand Down