Some code improvements

This commit is contained in:
Markus Gans 2015-10-01 03:48:58 +02:00
parent fa05774a13
commit 3ca644669d
14 changed files with 209 additions and 104 deletions

View File

@ -152,8 +152,17 @@ uChar FButtonGroup::getHotkey()
length = text.getLength();
for (uInt i=0; i < length; i++)
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
}

View File

@ -535,10 +535,18 @@ void FFileDialog::setPath (const FString& dir)
FString r_dir;
struct stat sb;
stat(dirname, &sb);
if ( stat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
if ( S_ISLNK(sb.st_mode) )
{
lstat(dirname, &sb);
if ( lstat(dirname, &sb) != 0 )
{
directory = '/';
return;
}
}
if ( ! S_ISDIR(sb.st_mode) )
{
@ -618,11 +626,13 @@ int FFileDialog::readDir()
if ( realpath(symLink, resolved_path) != 0 ) // follow link
{
struct stat sb;
lstat(resolved_path, &sb);
if ( lstat(resolved_path, &sb) == 0 )
{
if ( S_ISDIR(sb.st_mode) )
entry.type = DT_DIR;
}
}
}
if ( entry.type == DT_DIR )
dir_entries.push_back (entry);
else if ( pattern_match(filter, entry.name) )

View File

@ -1316,6 +1316,7 @@ void FListBox::cb_VBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = height-2;
// fall through
case FScrollbar::scrollStepBackward:
current -= distance;
if ( current < 1 )
@ -1328,6 +1329,7 @@ void FListBox::cb_VBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = height-2;
// fall through
case FScrollbar::scrollStepForward:
current += distance;
if ( current > element_count )
@ -1401,6 +1403,7 @@ void FListBox::cb_HBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
@ -1409,6 +1412,7 @@ void FListBox::cb_HBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > maxLineWidth - width + nf_offset + 4 )

View File

@ -456,7 +456,7 @@ void FMenu::onMouseUp (FMouseEvent* ev)
&& mouse_y == y )
{
(*iter)->processClicked();
redraw();
focus_changed = true;
}
}
++iter;

View File

@ -2,6 +2,7 @@
// Provides: class FOptiMove
#include "foptimove.h"
#include "string.h"
//----------------------------------------------------------------------
// class FOptiMove
@ -103,137 +104,185 @@ int FOptiMove::cap_duration (char*& cap, int affcnt)
// public methods of FOptiMove
//----------------------------------------------------------------------
void FOptiMove::set_cursor_home (char*& cap)
{
if ( cap )
{
F_cursor_home.cap = cap;
F_cursor_home.duration = cap_duration(cap, 0);
F_cursor_home.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_home.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_to_ll (char*& cap)
{
if ( cap )
{
F_cursor_to_ll.cap = cap;
F_cursor_to_ll.duration = cap_duration(cap, 0);
F_cursor_to_ll.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_to_ll.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_carriage_return (char*& cap)
{
if ( cap )
{
F_carriage_return.cap = cap;
F_carriage_return.duration = cap_duration(cap, 0);
F_carriage_return.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_carriage_return.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_tabular (char*& cap)
{
if ( cap )
{
F_tab.cap = cap;
F_tab.duration = cap_duration(cap, 0);
F_tab.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_tab.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_back_tab (char*& cap)
{
if ( cap )
{
F_back_tab.cap = cap;
F_back_tab.duration = cap_duration(cap, 0);
F_back_tab.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_back_tab.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_up (char*& cap)
{
if ( cap )
{
F_cursor_up.cap = cap;
F_cursor_up.duration = cap_duration(cap, 0);
F_cursor_up.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_up.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_down (char*& cap)
{
if ( cap )
{
F_cursor_down.cap = cap;
F_cursor_down.duration = cap_duration(cap, 0);
F_cursor_down.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_down.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_left (char*& cap)
{
if ( cap )
{
F_cursor_left.cap = cap;
F_cursor_left.duration = cap_duration(cap, 0);
F_cursor_left.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_left.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_right (char*& cap)
{
if ( cap )
{
F_cursor_right.cap = cap;
F_cursor_right.duration = cap_duration(cap, 0);
F_cursor_right.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_right.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_cursor_address (char*& cap)
{
if ( cap )
{
char* temp = tgoto(cap, 23, 23);
F_cursor_address.cap = cap;
F_cursor_address.duration = cap_duration(temp, 1);
F_cursor_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_cursor_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_column_address (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_column_address.cap = cap;
F_column_address.duration = cap_duration(temp, 1);
F_column_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_column_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_row_address (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_row_address.cap = cap;
F_row_address.duration = cap_duration(temp, 1);
F_row_address.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_row_address.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_up_cursor (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = cap_duration(temp, 1);
F_parm_up_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_parm_up_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_down_cursor (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = cap_duration(temp, 1);
F_parm_down_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_parm_down_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_left_cursor (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = cap_duration(temp, 1);
F_parm_left_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_parm_left_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
void FOptiMove::set_parm_right_cursor (char*& cap)
{
if ( cap )
{
char* temp = tparm(cap, 23);
F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = cap_duration(temp, 1);
F_parm_right_cursor.length = ( cap != 0 ) ? int(strlen(cap)) : 0;
F_parm_right_cursor.length = int(strlen(cap));
}
}
//----------------------------------------------------------------------
@ -416,7 +465,9 @@ int FOptiMove::relative_move ( char*& move
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
{
strcat (hmove, tparm(F_parm_left_cursor.cap, num));
strncat ( hmove
, tparm(F_parm_left_cursor.cap, num)
, sizeof(hmove) - strlen(hmove) - 1 );
htime = F_parm_left_cursor.duration;
}
@ -565,6 +616,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
{
new_time = relative_move (null_ptr, screen_width-1, yold-1, xnew, ynew);
if ( new_time < LONG_DURATION
&& F_carriage_return.cap
&& F_carriage_return.duration
+ F_cursor_left.duration + new_time < move_time )
{
@ -595,7 +647,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew)
break;
case 4:
strcpy (move_ptr, F_cursor_to_ll.cap);
strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf));
move_ptr += F_cursor_to_ll.length;
relative_move (move_ptr, 0, screen_height-1, xnew, ynew);
break;

View File

@ -194,22 +194,21 @@ int FTerm::inb_Attribute_Controller (int index)
int FTerm::getFramebuffer_bpp ()
{
int fd = -1;
struct stat fb_stat;
struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
const char* fb = const_cast<char*>("/dev/fb/0");
if ( stat(fb, &fb_stat) < 0 )
if ( (fd = open(fb, O_RDWR)) < 0 )
{
if ( errno != ENOENT && errno != ENOTDIR )
return -1;
fb = const_cast<char*>("/dev/fb0");
if ( stat(fb, &fb_stat) < 0 )
if ( (fd = open(fb, O_RDWR)) < 0 )
return -1;
}
fd = open(fb, O_RDWR);
if (fd >= 0)
{
if ( ! ioctl(fd, FBIOGET_VSCREENINFO, &fb_var)
@ -778,7 +777,7 @@ int FTerm::parseKeyString ( char* buffer
{
char* kmeta = Fmetakey[i].string; // The string is never null
len = int(strlen(kmeta));
if ( kmeta && strncmp(kmeta, buffer, uInt(len)) == 0 ) // found
if ( strncmp(kmeta, buffer, uInt(len)) == 0 ) // found
{
if ( len == 2 && ( buffer[1] == 'O'
|| buffer[1] == '['
@ -1108,7 +1107,6 @@ void FTerm::init()
putchar(0x8); // cygwin needs a backspace to delete the '♣' char
Sec_DA = new FString(getSecDA()); // get Secondary DA
if ( Sec_DA->getLength() > 5 )
{
FString temp = Sec_DA->right(Sec_DA->getLength() - 3);
@ -1207,7 +1205,7 @@ void FTerm::init()
// stop non-blocking stdin
unsetNonBlockingInput();
setenv("TERM", termtype, 1);
setenv(const_cast<char*>("TERM"), termtype, 1);
// Initializes variables for the current terminal
init_termcaps();
@ -3443,14 +3441,19 @@ FString FTerm::getAnswerbackMsg()
if ( raw_mode )
{
int n;
char temp[10] = {};
putchar(0x05); // send enquiry character
fflush(stdout);
usleep(150000); // wait 150 ms
// read the answerback message
if ( read(fileno(stdin), &temp, sizeof(temp)-1) > 0 )
n = read(fileno(stdin), &temp, sizeof(temp)-1);
if ( n > 0 )
{
temp[n] = '\0';
answerback = temp;
}
}
return answerback;
}
@ -3461,6 +3464,7 @@ FString FTerm::getSecDA()
if ( raw_mode )
{
int n;
char temp[16] = {};
// get the secondary device attributes
putchar(0x1b); // ESC
@ -3470,9 +3474,13 @@ FString FTerm::getSecDA()
fflush(stdout);
usleep(150000); // wait 150 ms
// read the answer
if ( read(fileno(stdin), &temp, sizeof(temp)-1) > 0 )
n = read(fileno(stdin), &temp, sizeof(temp)-1);
if ( n > 0 )
{
temp[n] = '\0';
sec_da = temp;
}
}
return sec_da;
}
@ -3610,14 +3618,19 @@ int FTerm::print (FString& s)
//----------------------------------------------------------------------
int FTerm::print (FTerm::term_area* area, FString& s)
{
assert ( area != 0 );
assert ( ! s.isNull() );
register int len = 0;
const wchar_t* p = s.wc_str();
FWidget* area_widget = area->widget;
const wchar_t* p;
FWidget* area_widget;
if ( ! area )
return -1;
area_widget = area->widget;
if ( ! area_widget )
return -1;
p = s.wc_str();
if ( p )
{
while ( *p )
@ -3735,12 +3748,13 @@ int FTerm::print (register int c)
//----------------------------------------------------------------------
int FTerm::print (FTerm::term_area* area, register int c)
{
assert ( area != 0 );
char_data nc; // new character
FWidget* area_widget;
int rsh, bsh;
short x = short(cursor->getX());
short y = short(cursor->getY());
int rsh, bsh, ax, ay;
short x, y;
if ( ! area )
return -1;
nc.code = c;
nc.fg_color = uChar(fg_color);
@ -3749,15 +3763,17 @@ int FTerm::print (FTerm::term_area* area, register int c)
nc.reverse = reverse;
nc.underline = underline;
x = short(cursor->getX());
y = short(cursor->getY());
area_widget = area->widget;
if ( ! area_widget )
return -1;
int ax = x - area_widget->getGlobalX();
int ay = y - area_widget->getGlobalY();
ax = x - area_widget->getGlobalX();
ay = y - area_widget->getGlobalY();
if ( area
&& ax >= 0 && ay >= 0
if ( ax >= 0 && ay >= 0
&& ax < area->width + area->right_shadow
&& ay < area->height + area->bottom_shadow )
{
@ -3825,6 +3841,7 @@ inline void FTerm::appendAttributes (char_data*& screen_attr)
{
case fc::LowerHalfBlock:
screen_attr->code = fc::UpperHalfBlock;
// fall through
case fc::NF_rev_left_arrow2:
case fc::NF_rev_right_arrow2:
case fc::NF_rev_border_corner_upper_right:

View File

@ -365,6 +365,7 @@ void FTextView::cb_VBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = height+nf_offset-2;
// fall through
case FScrollbar::scrollStepBackward:
yoffset -= distance;
if ( yoffset < 0 )
@ -373,6 +374,7 @@ void FTextView::cb_VBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = height+nf_offset-2;
// fall through
case FScrollbar::scrollStepForward:
yoffset += distance;
if ( yoffset > last_line - height - nf_offset + 2 )
@ -438,6 +440,7 @@ void FTextView::cb_HBarChange (FWidget*, void*)
{
case FScrollbar::scrollPageBackward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepBackward:
xoffset -= distance;
if ( xoffset < 0 )
@ -446,6 +449,7 @@ void FTextView::cb_HBarChange (FWidget*, void*)
case FScrollbar::scrollPageForward:
distance = width - nf_offset - 4;
// fall through
case FScrollbar::scrollStepForward:
xoffset += distance;
if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 )

View File

@ -114,8 +114,17 @@ uChar FToggleButton::getHotkey()
length = text.getLength();
for (uInt i=0; i < length; i++)
{
try
{
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;;
}
}
return 0;
}

View File

@ -211,9 +211,9 @@ int main (int, char**)
FString index(5); // a string with five characters
index = "index";
index[0] = L'I'; // write a wide character at position 0
try
{
index[0] = L'I'; // write a wide character at position 0
printf ( " index: [0] = %c ; [4] = %c\n"
, char(index[0])
, char(index[4]) );