Outsourcing the initialization data to a separate struct

This commit is contained in:
Markus Gans 2019-09-06 08:21:10 +02:00
parent d1fedfec9f
commit 81e00a22d3
7 changed files with 133 additions and 82 deletions

View File

@ -1,3 +1,6 @@
2019-09-06 Markus Gans <guru.mail@muenster.de>
* Outsourcing the initialization data to a separate struct
2019-09-04 Markus Gans <guru.mail@muenster.de> 2019-09-04 Markus Gans <guru.mail@muenster.de>
* The Cygwin and Linux console do not use cp437 character encoding * The Cygwin and Linux console do not use cp437 character encoding
by default anymore by default anymore

View File

@ -29,6 +29,7 @@
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fmessagebox.h" #include "final/fmessagebox.h"
#include "final/fmouse.h" #include "final/fmouse.h"
#include "final/fstartoptions.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
#include "final/ftermios.h" #include "final/ftermios.h"
#include "final/fwidgetcolors.h" #include "final/fwidgetcolors.h"
@ -296,7 +297,7 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[])
showParameterUsage(); showParameterUsage();
} }
getInitValues().setDefault(); getStartOptions().setDefault();
cmd_options (argc, argv); cmd_options (argc, argv);
return 0; return 0;
} }
@ -442,13 +443,13 @@ void FApplication::cmd_options (const int& argc, char* argv[])
encoding = encoding.toLower(); encoding = encoding.toLower();
if ( encoding.includes("utf8") ) if ( encoding.includes("utf8") )
getInitValues().encoding = fc::UTF8; getStartOptions().encoding = fc::UTF8;
else if ( encoding.includes("vt100") ) else if ( encoding.includes("vt100") )
getInitValues().encoding = fc::VT100; getStartOptions().encoding = fc::VT100;
else if ( encoding.includes("pc") ) else if ( encoding.includes("pc") )
getInitValues().encoding = fc::PC; getStartOptions().encoding = fc::PC;
else if ( encoding.includes("ascii") ) else if ( encoding.includes("ascii") )
getInitValues().encoding = fc::ASCII; getStartOptions().encoding = fc::ASCII;
else if ( encoding.includes("help") ) else if ( encoding.includes("help") )
showParameterUsage(); showParameterUsage();
else else
@ -457,32 +458,32 @@ void FApplication::cmd_options (const int& argc, char* argv[])
} }
if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 ) if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 )
getInitValues().mouse_support = false; getStartOptions().mouse_support = false;
if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 ) if ( std::strcmp(long_options[idx].name, "no-optimized-cursor") == 0 )
getInitValues().cursor_optimisation = false; getStartOptions().cursor_optimisation = false;
if ( std::strcmp(long_options[idx].name, "no-terminal-detection") == 0 ) if ( std::strcmp(long_options[idx].name, "no-terminal-detection") == 0 )
getInitValues().terminal_detection = false; getStartOptions().terminal_detection = false;
if ( std::strcmp(long_options[idx].name, "no-color-change") == 0 ) if ( std::strcmp(long_options[idx].name, "no-color-change") == 0 )
getInitValues().color_change = false; getStartOptions().color_change = false;
if ( std::strcmp(long_options[idx].name, "vgafont") == 0 ) if ( std::strcmp(long_options[idx].name, "vgafont") == 0 )
getInitValues().vgafont = true; getStartOptions().vgafont = true;
if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
getInitValues().newfont = true; getStartOptions().newfont = true;
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
getInitValues().meta_sends_escape = false; getStartOptions().meta_sends_escape = false;
if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 ) if ( std::strcmp(long_options[idx].name, "no-cursorstyle-change") == 0 )
getInitValues().change_cursorstyle = false; getStartOptions().change_cursorstyle = false;
#elif defined(__NetBSD__) || defined(__OpenBSD__) #elif defined(__NetBSD__) || defined(__OpenBSD__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
getInitValues().meta_sends_escape = false; getStartOptions().meta_sends_escape = false;
#endif #endif
} }
} }

View File

@ -33,6 +33,7 @@
#include "final/fmouse.h" #include "final/fmouse.h"
#include "final/foptiattr.h" #include "final/foptiattr.h"
#include "final/foptimove.h" #include "final/foptimove.h"
#include "final/fstartoptions.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/fsystem.h" #include "final/fsystem.h"
#include "final/fsystemimpl.h" #include "final/fsystemimpl.h"
@ -70,7 +71,6 @@ static bool term_initialized{false};
int (*FTerm::Fputchar)(int); int (*FTerm::Fputchar)(int);
// static class attributes // static class attributes
FTerm::initializationValues FTerm::init_values{};
FTermData* FTerm::data {nullptr}; FTermData* FTerm::data {nullptr};
FSystem* FTerm::fsys {nullptr}; FSystem* FTerm::fsys {nullptr};
FOptiMove* FTerm::opti_move {nullptr}; FOptiMove* FTerm::opti_move {nullptr};
@ -1366,7 +1366,7 @@ void FTerm::init_global_values (bool disable_alt_screen)
// Initialize xterm object // Initialize xterm object
xterm->init(); xterm->init();
if ( ! init_values.terminal_detection ) if ( ! getStartOptions().terminal_detection )
term_detection->setTerminalDetection (false); term_detection->setTerminalDetection (false);
#if DEBUG #if DEBUG
@ -1695,10 +1695,10 @@ void FTerm::init_optiAttr()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_font() void FTerm::init_font()
{ {
if ( init_values.vgafont && ! setVGAFont() ) if ( getStartOptions().vgafont && ! setVGAFont() )
exitWithMessage ("VGAfont is not supported by this terminal"); exitWithMessage ("VGAfont is not supported by this terminal");
if ( init_values.newfont && ! setNewFont() ) if ( getStartOptions().newfont && ! setNewFont() )
exitWithMessage ("Newfont is not supported by this terminal"); exitWithMessage ("Newfont is not supported by this terminal");
} }
@ -1774,9 +1774,9 @@ void FTerm::init_encoding()
init_tab_quirks(); init_tab_quirks();
if ( init_values.encoding != fc::UNKNOWN ) if ( getStartOptions().encoding != fc::UNKNOWN )
{ {
setEncoding(init_values.encoding); setEncoding(getStartOptions().encoding);
} }
} }
@ -1835,7 +1835,7 @@ void FTerm::init_individual_term_encoding()
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
Fputchar = &FTerm::putchar_ASCII; // function pointer Fputchar = &FTerm::putchar_ASCII; // function pointer
if ( hasUTF8() && init_values.encoding == fc::UNKNOWN ) if ( hasUTF8() && getStartOptions().encoding == fc::UNKNOWN )
{ {
if ( isXTerminal() ) if ( isXTerminal() )
Fputchar = &FTerm::putchar_UTF8; // function pointer Fputchar = &FTerm::putchar_UTF8; // function pointer
@ -2032,7 +2032,7 @@ void FTerm::enableMouse()
{ {
// Enable the terminal mouse support // Enable the terminal mouse support
if ( ! init_values.mouse_support ) if ( ! getStartOptions().mouse_support )
return; return;
bool gpm_mouse{false}; bool gpm_mouse{false};
@ -2324,7 +2324,7 @@ void FTerm::init (bool disable_alt_screen)
initTermspecifics(); initTermspecifics();
// Redefine the color palette // Redefine the color palette
if ( init_values.color_change ) if ( getStartOptions().color_change )
redefineColorPalette(); redefineColorPalette();
// Set 220 Hz beep (100 ms) // Set 220 Hz beep (100 ms)
@ -2333,7 +2333,7 @@ void FTerm::init (bool disable_alt_screen)
// Set FTerm signal handler // Set FTerm signal handler
setSignalHandler(); setSignalHandler();
if ( ! init_values.cursor_optimisation ) if ( ! getStartOptions().cursor_optimisation )
data->supportCursorOptimisation(false); data->supportCursorOptimisation(false);
// Activate the VGA or the new graphic font // Activate the VGA or the new graphic font
@ -2363,19 +2363,19 @@ void FTerm::initOSspecifics()
#endif // defined(__linux__) #endif // defined(__linux__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
if ( init_values.meta_sends_escape ) if ( getStartOptions().meta_sends_escape )
freebsd->enableMetaSendsEscape(); freebsd->enableMetaSendsEscape();
else else
freebsd->disableMetaSendsEscape(); freebsd->disableMetaSendsEscape();
if ( init_values.change_cursorstyle ) if ( getStartOptions().change_cursorstyle )
freebsd->enableChangeCursorStyle(); freebsd->enableChangeCursorStyle();
else else
freebsd->disableChangeCursorStyle(); freebsd->disableChangeCursorStyle();
freebsd->init(); // Initialize BSD console freebsd->init(); // Initialize BSD console
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
if ( init_values.meta_sends_escape ) if ( getStartOptions().meta_sends_escape )
openbsd->enableMetaSendsEscape(); openbsd->enableMetaSendsEscape();
else else
openbsd->disableMetaSendsEscape(); openbsd->disableMetaSendsEscape();
@ -2443,7 +2443,7 @@ void FTerm::finish()
xterm->setCursorStyle (fc::steady_block); xterm->setCursorStyle (fc::steady_block);
// Restore the color palette // Restore the color palette
if ( init_values.color_change ) if ( getStartOptions().color_change )
restoreColorPalette(); restoreColorPalette();
// Switch to normal escape key mode // Switch to normal escape key mode
@ -2457,7 +2457,7 @@ void FTerm::finish()
resetBeep(); resetBeep();
// Disable the terminal mouse support // Disable the terminal mouse support
if ( init_values.mouse_support ) if ( getStartOptions().mouse_support )
disableMouse(); disableMouse();
// Deactivate meta key sends escape // Deactivate meta key sends escape

View File

@ -128,7 +128,7 @@ class FApplication : public FWidget
static void sendQueuedEvents (); static void sendQueuedEvents ();
static bool eventInQueue(); static bool eventInQueue();
static bool removeQueuedEvent (const FObject*); static bool removeQueuedEvent (const FObject*);
FWidget* processParameters (const int&, char*[]); static FWidget* processParameters (const int&, char*[]);
static void showParameterUsage () static void showParameterUsage ()
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
__attribute__((noreturn)) __attribute__((noreturn))
@ -146,7 +146,7 @@ class FApplication : public FWidget
// Methods // Methods
void init (uInt64, uInt64); void init (uInt64, uInt64);
void cmd_options (const int&, char*[]); static void cmd_options (const int&, char*[]);
void findKeyboardWidget(); void findKeyboardWidget();
bool isKeyPressed(); bool isKeyPressed();
void keyPressed(); void keyPressed();

View File

@ -0,0 +1,98 @@
/***********************************************************************
* fstartoptions.h - Contains the start options for initialization *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
/* Standalone class
*
*
*
* FStartOptions
*
*/
#ifndef FSTARTOPTIONS_H
#define FSTARTOPTIONS_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
namespace finalcut
{
//----------------------------------------------------------------------
// class FStartOptions
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
struct FStartOptions
{
public:
// Mutator
void setDefault()
{
cursor_optimisation = true;
mouse_support = true;
terminal_detection = true;
color_change = true;
vgafont = false;
newfont = false;
encoding = fc::UNKNOWN;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
meta_sends_escape = true;
change_cursorstyle = true;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
meta_sends_escape = true;
#endif
}
// Data members
uInt8 cursor_optimisation : 1;
uInt8 mouse_support : 1;
uInt8 terminal_detection : 1;
uInt8 color_change : 1;
uInt8 vgafont : 1;
uInt8 newfont : 1;
uInt8 : 2; // padding bits
fc::encoding encoding;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
uInt8 meta_sends_escape : 1;
uInt8 change_cursorstyle : 1;
uInt8 : 6; // padding bits
#elif defined(__NetBSD__) || defined(__OpenBSD__)
uInt8 meta_sends_escape : 1;
uInt8 : 7; // padding bits
#endif
};
#pragma pack(pop)
static struct FStartOptions start_options{};
inline FStartOptions& getStartOptions()
{ return start_options; }
} // namespace finalcut
#endif // FSTARTOPTIONS_H

View File

@ -179,7 +179,6 @@ class FTerm final
static char* getTermFileName(); static char* getTermFileName();
static int getTabstop(); static int getTabstop();
static int getMaxColor(); static int getMaxColor();
initializationValues& getInitValues();
charSubstitution& getCharSubstitutionMap(); charSubstitution& getCharSubstitutionMap();
static FTermData* getFTermData(); static FTermData* getFTermData();
@ -305,47 +304,6 @@ class FTerm final
__attribute__((noreturn)) __attribute__((noreturn))
#endif #endif
; ;
// Data members
static struct initializationValues
{
public:
void setDefault()
{
cursor_optimisation = true;
mouse_support = true;
terminal_detection = true;
color_change = true;
vgafont = false;
newfont = false;
encoding = fc::UNKNOWN;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
meta_sends_escape = true;
change_cursorstyle = true;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
meta_sends_escape = true;
#endif
}
uInt8 cursor_optimisation : 1;
uInt8 mouse_support : 1;
uInt8 terminal_detection : 1;
uInt8 color_change : 1;
uInt8 vgafont : 1;
uInt8 newfont : 1;
uInt8 : 2; // padding bits
fc::encoding encoding;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
uInt8 meta_sends_escape : 1;
uInt8 change_cursorstyle : 1;
uInt8 : 6; // padding bits
#elif defined(__NetBSD__) || defined(__OpenBSD__)
uInt8 meta_sends_escape : 1;
uInt8 : 7; // padding bits
#endif
} init_values;
private: private:
// Methods // Methods
static void init_global_values (bool); static void init_global_values (bool);
@ -437,10 +395,6 @@ class FTerm final
inline const char* FTerm::getClassName() const inline const char* FTerm::getClassName() const
{ return "FTerm"; } { return "FTerm"; }
//----------------------------------------------------------------------
inline FTerm::initializationValues& FTerm::getInitValues()
{ return init_values; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTerm::setFSystem (FSystem* fsystem) inline void FTerm::setFSystem (FSystem* fsystem)
{ fsys = fsystem; } { fsys = fsystem; }

View File

@ -329,7 +329,6 @@ class FVTerm
static bool charEncodable (wchar_t); static bool charEncodable (wchar_t);
static FKeyboard* getFKeyboard(); static FKeyboard* getFKeyboard();
static FMouseControl* getFMouseControl(); static FMouseControl* getFMouseControl();
FTerm::initializationValues& getInitValues();
// Mutators // Mutators
void setPrintArea (term_area*); void setPrintArea (term_area*);
@ -1086,10 +1085,6 @@ inline FKeyboard* FVTerm::getFKeyboard()
inline FMouseControl* FVTerm::getFMouseControl() inline FMouseControl* FVTerm::getFMouseControl()
{ return FTerm::getFMouseControl(); } { return FTerm::getFMouseControl(); }
//----------------------------------------------------------------------
inline FTerm::initializationValues& FVTerm::getInitValues()
{ return FTerm::init_values; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::setPrintArea (term_area* area) inline void FVTerm::setPrintArea (term_area* area)
{ print_area = area; } { print_area = area; }