Use more static const variables where it makes sense

This commit is contained in:
Markus Gans 2017-07-03 16:56:32 +02:00
parent b0b5282c9a
commit b36fc80f51
11 changed files with 62 additions and 45 deletions

View File

@ -1,3 +1,6 @@
2017-07-03 Markus Gans <guru.mail@muenster.de>
* Use more static const variables where it makes sense
2017-06-26 Markus Gans <guru.mail@muenster.de>
* FString::rtrim() and FString::left() now return an FString
object with the correct character length

View File

@ -566,8 +566,8 @@ void FApplication::processKeyboardEvent()
case fc::Fkey_mouse:
{
static const int len = 6;
int n;
const int len = 6;
x11_mouse[0] = fifo_buf[3];
x11_mouse[1] = fifo_buf[4];
x11_mouse[2] = fifo_buf[5];
@ -590,8 +590,8 @@ void FApplication::processKeyboardEvent()
case fc::Fkey_extended_mouse:
{
int n = 3;
int len = int(std::strlen(fifo_buf));
int n = 3;
while ( n < len && n < fifo_buf_size )
{
@ -619,8 +619,8 @@ void FApplication::processKeyboardEvent()
case fc::Fkey_urxvt_mouse:
{
int n = 2;
int len = int(std::strlen(fifo_buf));
int n = 2;
while ( n < len && n < fifo_buf_size )
{

View File

@ -1148,8 +1148,8 @@ void FDialog::drawBorder()
//----------------------------------------------------------------------
void FDialog::drawTitleBar()
{
static const int menu_btn = 3;
int i,x,length, zoom_btn;
const int menu_btn = 3;
// draw the title button
setPrintPos (1, 1);

View File

@ -439,6 +439,7 @@ void FFileDialog::adjustSize()
}
else
{
// fallback to xterm default size
max_width = 80;
max_height = 24;
}
@ -468,10 +469,11 @@ void FFileDialog::adjustSize()
//----------------------------------------------------------------------
void FFileDialog::init()
{
static const int w = 42;
static const int h = 15;
int x, y;
FWidget* parent_widget;
int x, y, w, h;
w = 42;
h = 15;
setGeometry(1, 1, w, h, false);
parent_widget = getParentWidget();

View File

@ -383,8 +383,8 @@ void FListBox::clear()
//----------------------------------------------------------------------
void FListBox::onKeyPress (FKeyEvent* ev)
{
static const int padding_space = 2; // 1 leading space + 1 tailing space
int element_count = int(getCount());
const int padding_space = 2; // 1 leading space + 1 tailing space
int current_before = current;
int xoffset_before = xoffset;
int xoffset_end = max_line_width - getClientWidth() + padding_space;
@ -1268,9 +1268,9 @@ void FListBox::cb_VBarChange (FWidget*, data_ptr)
//----------------------------------------------------------------------
void FListBox::cb_HBarChange (FWidget*, data_ptr)
{
static const int padding_space = 2; // 1 leading space + 1 tailing space
FScrollbar::sType scrollType;
int distance = 1;
int padding_space = 2; // 1 leading space + 1 tailing space
int xoffset_before = xoffset;
int xoffset_end = max_line_width - getClientWidth() + padding_space;
scrollType = hbar->getScrollType();

View File

@ -242,6 +242,7 @@ void FMessageBox::adjustSize()
}
else
{
// fallback to xterm default size
max_width = 80;
max_height = 24;
}
@ -461,8 +462,8 @@ void FMessageBox::resizeButtons()
//----------------------------------------------------------------------
void FMessageBox::adjustButtons()
{
static const int gap = 4;
int btn_width = 0;
int gap = 4;
for (uInt n=0; n < num_buttons; n++)
{

View File

@ -647,7 +647,7 @@ void FOptiMove::calculateCharDuration()
{
if ( baudrate != 0 )
{
const int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
static const int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
char_duration = (baudbyte * 1000 * 10)
/ (baudrate > 0 ? baudrate : 9600); // milliseconds

View File

@ -491,7 +491,7 @@ uInt FString::getUTF8length() const
//----------------------------------------------------------------------
FString& FString::sprintf (const wchar_t* format, ...)
{
const int buf_size = 4096;
static const int buf_size = 4096;
wchar_t buffer[buf_size];
va_list args;

View File

@ -204,7 +204,8 @@ const FString FTerm::getKeyName (int keynum)
//----------------------------------------------------------------------
FTerm::modifier_key& FTerm::getLinuxModifierKey()
{
char subcode = 6;
static const char subcode = 6;
// fill bit field with 0
std::memset (&mod_key, 0x00, sizeof(mod_key));
@ -437,9 +438,9 @@ int FTerm::parseKeyString ( char buffer[]
, int buf_size
, timeval* time_keypressed )
{
static const long key_timeout = 100000; // 100 ms
register uChar firstchar = uChar(buffer[0]);
register std::size_t buf_len = std::strlen(buffer);
const long key_timeout = 100000; // 100 ms
int key, len, n;
if ( firstchar == ESC[0] )
@ -832,10 +833,12 @@ void FTerm::detectTermSize()
{
char* str;
term->setPos(1,1);
// Use COLUMNS or fallback to the xterm default width of 80 characters
str = std::getenv("COLUMNS");
term->setWidth(str ? std::atoi(str) : 80);
// Use LINES or fallback to the xterm default height of 24 characters
str = std::getenv("LINES");
term->setHeight(str ? std::atoi(str) : 25);
term->setHeight(str ? std::atoi(str) : 24);
}
else
{
@ -1883,8 +1886,10 @@ bool FTerm::isWSConsConsole()
inline uInt16 FTerm::getInputStatusRegisterOne()
{
// Gets the VGA input-status-register-1
uInt16 misc_read = 0x3cc; // Miscellaneous output (read port)
uInt16 io_base = (inb(misc_read) & 0x01) ? 0x3d0 : 0x3b0;
// Miscellaneous output (read port)
static const uInt16 misc_read = 0x3cc;
const uInt16 io_base = (inb(misc_read) & 0x01) ? 0x3d0 : 0x3b0;
// 0x3ba : Input status 1 MDA (read port)
// 0x3da : Input status 1 CGA (read port)
return io_base + 0x0a;
@ -1894,10 +1899,13 @@ inline uInt16 FTerm::getInputStatusRegisterOne()
uChar FTerm::readAttributeController (uChar index)
{
// Reads a byte from the attribute controller from a given index
uChar res;
uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port)
uInt16 attrib_cntlr_read = 0x3c1; // Attribute controller (read port)
uInt16 input_status_1 = getInputStatusRegisterOne();
// Attribute controller (write port)
static const uInt16 attrib_cntlr_write = 0x3c0;
// Attribute controller (read port)
static const uInt16 attrib_cntlr_read = 0x3c1;
const uInt16 input_status_1 = getInputStatusRegisterOne();
inb (input_status_1); // switch to index mode
outb (index & 0x1f, attrib_cntlr_write);
@ -1914,8 +1922,10 @@ uChar FTerm::readAttributeController (uChar index)
void FTerm::writeAttributeController (uChar index, uChar data)
{
// Writes a byte from the attribute controller from a given index
uInt16 attrib_cntlr_write = 0x3c0; // Attribute controller (write port)
uInt16 input_status_1 = getInputStatusRegisterOne();
// Attribute controller (write port)
static const uInt16 attrib_cntlr_write = 0x3c0;
const uInt16 input_status_1 = getInputStatusRegisterOne();
inb (input_status_1); // switch to index mode
outb (index & 0x1f, attrib_cntlr_write);
@ -1931,7 +1941,7 @@ void FTerm::writeAttributeController (uChar index, uChar data)
inline uChar FTerm::getAttributeMode()
{
// Gets the attribute mode value from the vga attribute controller
uChar attrib_mode = 0x10;
static const uChar attrib_mode = 0x10;
return readAttributeController(attrib_mode);
}
@ -1939,7 +1949,7 @@ inline uChar FTerm::getAttributeMode()
inline void FTerm::setAttributeMode(uChar data)
{
// Sets the attribute mode value from the vga attribute controller
uChar attrib_mode = 0x10;
static const uChar attrib_mode = 0x10;
writeAttributeController (attrib_mode, data);
}
@ -2151,8 +2161,9 @@ void FTerm::restoreTTYsettings()
//----------------------------------------------------------------------
int FTerm::getScreenFont()
{
static const std::size_t data_size = 4 * 32 * 512;
struct console_font_op font;
const std::size_t data_size = 4 * 32 * 512;
int ret;
if ( fd_tty < 0 )
@ -2362,9 +2373,9 @@ void FTerm::initLinuxConsole()
//----------------------------------------------------------------------
bool FTerm::saveFreeBSDAltKey()
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
int ret;
keymap_t keymap;
ret = ioctl(0, GIO_KEYMAP, &keymap);
@ -2379,9 +2390,9 @@ bool FTerm::saveFreeBSDAltKey()
//----------------------------------------------------------------------
bool FTerm::setFreeBSDAltKey (uInt key)
{
keymap_t keymap;
int ret;
static const int left_alt = 0x38;
int ret;
keymap_t keymap;
ret = ioctl(0, GIO_KEYMAP, &keymap);
@ -2936,15 +2947,15 @@ void FTerm::init_termcaps()
* captoinfo - convert all termcap descriptions into terminfo descriptions
* infocmp - print out terminfo description from the current terminal
*/
static const int success = 1;
static const int no_entry = 0;
static const int db_not_found = -1;
static const int not_available = -1;
static const int uninitialized = -2;
static char term_buffer[2048];
static char string_buf[2048];
char* buffer = string_buf;
char* key_up_string;
const int success = 1;
const int no_entry = 0;
const int db_not_found = -1;
const int not_available = -1;
const int uninitialized = -2;
int status = uninitialized;
// share the terminal capabilities

View File

@ -289,7 +289,7 @@ void FVTerm::delPreprocessingHandler (FVTerm* instance)
int FVTerm::printf (const wchar_t* format, ...)
{
assert ( format != 0 );
const int buf_size = 1024;
static const int buf_size = 1024;
wchar_t buffer[buf_size];
va_list args;