Style and header updates

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13939 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2005-08-12 18:00:37 +00:00
parent d863d4bf1d
commit 401fdf8278
7 changed files with 2292 additions and 2971 deletions

View File

@ -1,65 +1,30 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
#include "CurPos.h"
/*************************************************************************
*
* Constructor and Destructor
*
************************************************************************/
CurPos::CurPos()
{
}
CurPos::CurPos(int32 X, int32 Y)
{
x = X;
y = Y;
}
CurPos::CurPos(const CurPos& cp)
{
x = cp.x;
y = cp.y;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator =
////////////////////////////////////////////////////////////////////////////
CurPos &
CurPos::operator=(const CurPos& from)
{
@ -68,10 +33,6 @@ CurPos::operator=(const CurPos& from)
return *this;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Set Function.
////////////////////////////////////////////////////////////////////////////
void
CurPos::Set(int32 X, int32 Y)
{
@ -79,105 +40,74 @@ CurPos::Set(int32 X, int32 Y)
y = Y;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator !=
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator!=(const CurPos& from) const
{
return ((x != from.x) || (y != from.y));
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator ==
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator==(const CurPos& from) const
{
return ((x == from.x) && (y == from.y));
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator +
////////////////////////////////////////////////////////////////////////////
CurPos
CurPos::operator+(const CurPos& from) const
{
return CurPos(x + from.x, y + from.y);
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator -
////////////////////////////////////////////////////////////////////////////
CurPos
CurPos::operator- (const CurPos& from) const
{
return CurPos(x - from.x, y - from.y);
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator >
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator> (const CurPos& from) const
{
if (y > from.y) {
return true;
} else if (y == from.y && x > from.x) {
return true;
}
return false;
if (y > from.y)
return true;
else
if (y == from.y && x > from.x)
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator >=
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator>= (const CurPos& from) const
{
if (y > from.y) {
return true;
} else if (y == from.y && x >= from.x) {
return true;
}
return false;
if (y > from.y)
return true;
else
if (y == from.y && x >= from.x)
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator <
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator< (const CurPos& from) const
{
if (y < from.y) {
return true;
} else if (y == from.y && x < from.x) {
return true;
}
return false;
if (y < from.y)
return true;
else
if (y == from.y && x < from.x)
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator <=
////////////////////////////////////////////////////////////////////////////
bool
CurPos::operator<= (const CurPos& from) const
{
if (y < from.y) {
return true;
} else if (y == from.y && x <= from.x) {
return true;
}
return false;
if (y < from.y)
return true;
else
if (y == from.y && x <= from.x)
return true;
return false;
}

View File

@ -1,33 +1,12 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
#ifndef CURPOS_H_INCLUDED
#define CURPOS_H_INCLUDED
@ -35,26 +14,25 @@
class CurPos
{
public:
int32 x;
int32 y;
CurPos();
CurPos(int32 X, int32 Y);
CurPos(const CurPos& cp);
void Set(int32 X, int32 Y);
CurPos &operator= (const CurPos &from);
CurPos operator+ (const CurPos&) const;
CurPos operator- (const CurPos&) const;
bool operator!= (const CurPos&) const;
bool operator== (const CurPos&) const;
bool operator> (const CurPos&) const;
bool operator>= (const CurPos&) const;
bool operator< (const CurPos&) const;
bool operator<= (const CurPos&) const;
public:
CurPos();
CurPos(int32 X, int32 Y);
CurPos(const CurPos& cp);
void Set(int32 X, int32 Y);
CurPos &operator= (const CurPos &from);
CurPos operator+ (const CurPos&) const;
CurPos operator- (const CurPos&) const;
bool operator!= (const CurPos&) const;
bool operator== (const CurPos&) const;
bool operator> (const CurPos&) const;
bool operator>= (const CurPos&) const;
bool operator< (const CurPos&) const;
bool operator<= (const CurPos&) const;
int32 x;
int32 y;
};
#endif /* CURPOS_H_INCLUDED */
#endif

View File

@ -1,33 +1,12 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
#include <Menu.h>
#include <string.h>
#include <MenuItem.h>
@ -44,7 +23,6 @@ extern PrefHandler *gTermPref;
//#define LOCALE_FILE_DIR PREF_FOLDER"menu/"
BPopUpMenu *
MakeMenu(ulong msg, const char **items, const char *defaultItemName)
{
@ -62,7 +40,6 @@ MakeMenu(ulong msg, const char **items, const char *defaultItemName)
return menu;
}
int
longname2op(const char *longname)
{
@ -78,14 +55,12 @@ longname2op(const char *longname)
return op;
}
const char *
op2longname(int op)
{
return encoding_table[op].name;
}
void
MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
{
@ -98,22 +73,21 @@ MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut));
else
eMenu->AddItem(new BMenuItem(e->name, msg));
if (i == coding)
eMenu->ItemAt(i)->SetMarked(true);
e++;
i++;
}
}
void
LoadLocaleFile(PrefHandler *pref)
{
char name[B_PATH_NAME_LENGTH];
const char *locale;
locale = gTermPref->getString(PREF_GUI_LANGUAGE);
// TODO: this effectively disables any locale support - which is okay for now
sprintf(name, "%s%s", /*LOCALE_FILE_DIR*/"", locale);
@ -121,4 +95,3 @@ LoadLocaleFile(PrefHandler *pref)
//if (pref->OpenText(name) < B_OK)
// pref->OpenText(LOCALE_FILE_DEFAULT);
}

View File

@ -1,33 +1,12 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
#ifndef MENUUTIL_H_INCLUDED
#define MENUUTIL_H_INCLUDED
@ -41,16 +20,15 @@ class BPopUpMenu;
class BMenu;
class PrefHandler;
BPopUpMenu * MakeMenu(ulong msg, const char **items,
BPopUpMenu * MakeMenu(ulong msg, const char **items,
const char *defaultItemName);
int longname2op(const char *longname);
const char * op2longname(int op);
void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag);
void LoadLocaleFile (PrefHandler *);
int longname2op(const char *longname);
const char * op2longname(int op);
void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag);
void LoadLocaleFile (PrefHandler *);
#ifdef __cplusplus
}
#endif
#endif //MENUUTIL_H_INCLUDED
#endif

View File

@ -1,82 +1,36 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
#include "TermBaseView.h"
#include "TermView.h"
/************************************************************************
*
* CONSTRUCTOR and DESTRUCTOR
*
***********************************************************************/
////////////////////////////////////////////////////////////////////////////
// TermBaseView ()
// Constructor.
////////////////////////////////////////////////////////////////////////////
TermBaseView::TermBaseView (BRect frame, TermView *inTermView)
:BView (frame, "baseview", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS)
:BView(frame, "baseview", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS)
{
fTermView = inTermView;
fTermView = inTermView;
}
////////////////////////////////////////////////////////////////////////////
// ~TermBaseView ()
// Destructor.
////////////////////////////////////////////////////////////////////////////
TermBaseView::~TermBaseView ()
{
}
/*
* PUBLIC MEMBER FUNCTIONS.
*/
////////////////////////////////////////////////////////////////////////////
// FrameResized (float, float)
// Dispatch frame resize event.
////////////////////////////////////////////////////////////////////////////
void
TermBaseView::FrameResized (float width, float height)
{
int font_width, font_height;
int cols, rows;
fTermView->GetFontInfo (&font_width, &font_height);
cols = (int)(width - VIEW_OFFSET * 2) / font_width;
rows = (int)(height - VIEW_OFFSET * 2)/ font_height;
fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1);
int font_width, font_height;
int cols, rows;
fTermView->GetFontInfo (&font_width, &font_height);
cols = (int)(width - VIEW_OFFSET * 2) / font_width;
rows = (int)(height - VIEW_OFFSET * 2)/ font_height;
fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1);
}

View File

@ -1,31 +1,11 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Authors:
* Kian Duffy <myob@users.sourceforge.net>
*/
/************************************************************************
@ -69,7 +49,7 @@ c. 2byte status buffer.
**Language environment. (Not impliment)
--- half width character set ---
0 ... Wesern (Latin1 / ISO-8859-1, MacRoman)
0 ... Western (Latin1 / ISO-8859-1, MacRoman)
1 ... Central European(Latin2 / ISO-8859-2)
2 ... Turkish (Latin3 / ISO-8859-3)
3 ... Baltic (Latin4 / ISO-8859-4)
@ -85,7 +65,7 @@ c. 2byte status buffer.
--- Universal character set ---
10 ... Unicode (UTF8)
* Varriables is set CodeConv class.
* Variables is set CodeConv class.
* Unicode character width sets CodeConv::UTF8FontWidth member.
JIS X 0201 (half width kana ideograph) character use 1 column,
@ -109,539 +89,429 @@ but it font is full width font on preference panel.
extern PrefHandler *gTermPref;
////////////////////////////////////////////////////////////////////////////
//
// TermBuffer class
// Constructor and Destructor.
//
////////////////////////////////////////////////////////////////////////////
TermBuffer::TermBuffer(int rows, int cols)
{
mColSize = MAX_COLS;
mNowColSize = cols;
mRowSize = rows;
mRowOffset = 0;
//buffer_size = ARRAY_SIZE;
buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE);
/* Allocate buffer */
mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size);
for(int i = 0; i < buffer_size; i++){
mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer));
}
mColSize = MAX_COLS;
mNowColSize = cols;
mRowSize = rows;
mRowOffset = 0;
//buffer_size = ARRAY_SIZE;
buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE);
// Allocate buffer
mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size);
for(int i = 0; i < buffer_size; i++)
mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer));
}
////////////////////////////////////////////////////////////////////////////
// TermBuffer Destructer.
//
////////////////////////////////////////////////////////////////////////////
TermBuffer::~TermBuffer()
{
for(int i = 0; i < buffer_size; i++){
free (mBase[i]);
}
for(int i = 0; i < buffer_size; i++)
free (mBase[i]);
free(mBase);
}
////////////////////////////////////////////////////////////////////////////
// int GetChar (row, col, *buf, attr)
// Get chracter from TermBuffer.
////////////////////////////////////////////////////////////////////////////
/* This function moved to header file for effeciency */
// Gets a character from TermBuffer
int
TermBuffer::GetChar (int row, int col, uchar *buf, ushort *attr)
{
term_buffer *ptr;
ptr = (mBase[row % buffer_size] + col);
if (ptr->status == A_CHAR)
memcpy (buf, (char *)(ptr->code), 4);
*attr = ptr->attr;
return ptr->status;
}
////////////////////////////////////////////////////////////////////////////
// int GetString (row, col, *buf, attr)
// Get String (length = num) from given position.
////////////////////////////////////////////////////////////////////////////
int
TermBuffer::GetString (int row, int col, int num,
uchar *buf, ushort *attr)
{
int count = 0, all_count = 0;
term_buffer *ptr;
ptr = (mBase[row % buffer_size]);
ptr += col;
*attr = ptr->attr;
if (ptr->status == NO_CHAR) {
/*
* Buffer is empty and No selected by mouse.
*/
do {
if (col >= mNowColSize) return -1;
col++;
ptr++;
count--;
if (ptr->status == A_CHAR)
return count;
if (mSelStart.y == row) {
if (col == mSelStart.x)
return count;
}
if (mSelEnd.y == row) {
if (col - 1 == mSelEnd.x)
return count;
}
term_buffer *ptr;
}while (col <= num);
return count;
}
else if (IS_WIDTH(ptr->attr)) {
memcpy (buf, (char *)ptr->code, 4);
return 2;
}
while (col <= num) {
memcpy (buf, ptr->code, 4);
all_count++;
if (*buf == 0) {
*buf = ' ';
*(buf + 1) = '\0';
}
if (ptr->attr != (ptr + 1)->attr){
return all_count;
}
buf = (uchar *)index ((char *)buf, 0x00);
ptr++;
col++;
if (mSelStart.y == row) {
if (col == mSelStart.x)
return all_count;
}
if (mSelEnd.y == row) {
if (col - 1 == mSelEnd.x)
return all_count;
}
}
return all_count;
ptr = (mBase[row % buffer_size] + col);
if (ptr->status == A_CHAR)
memcpy (buf, (char *)(ptr->code), 4);
*attr = ptr->attr;
return ptr->status;
}
////////////////////////////////////////////////////////////////////////////
// void WriteChar (const CurPos &, const uchar *, ushort)
// Write character at cursor point.
////////////////////////////////////////////////////////////////////////////
// Get a string (length = num) from given position.
int
TermBuffer::GetString (int row, int col, int num, uchar *buf,
ushort *attr)
{
int count = 0, all_count = 0;
term_buffer *ptr;
ptr = (mBase[row % buffer_size]);
ptr += col;
*attr = ptr->attr;
if (ptr->status == NO_CHAR) {
// Buffer is empty and No selected by mouse.
do {
if (col >= mNowColSize)
return -1;
col++;
ptr++;
count--;
if (ptr->status == A_CHAR)
return count;
if (mSelStart.y == row) {
if (col == mSelStart.x)
return count;
}
if (mSelEnd.y == row) {
if (col - 1 == mSelEnd.x)
return count;
}
}while (col <= num);
return count;
}
else if (IS_WIDTH(ptr->attr)) {
memcpy (buf, (char *)ptr->code, 4);
return 2;
}
while (col <= num) {
memcpy (buf, ptr->code, 4);
all_count++;
if (*buf == 0) {
*buf = ' ';
*(buf + 1) = '\0';
}
if (ptr->attr != (ptr + 1)->attr)
return all_count;
buf = (uchar *)index ((char *)buf, 0x00);
ptr++;
col++;
if (mSelStart.y == row) {
if (col == mSelStart.x)
return all_count;
}
if (mSelEnd.y == row) {
if (col - 1 == mSelEnd.x)
return all_count;
}
}
return all_count;
}
// Write a character at the cursor point.
void
TermBuffer::WriteChar (const CurPos &pos, const uchar *u, ushort attr)
{
term_buffer *ptr;
const int row = pos.y;
const int col = pos.x;
ptr = (mBase[ROW(row)] + col);
memcpy ((char *)ptr->code, u, 4);
if (IS_WIDTH(attr))
(ptr + 1)->status = IN_STRING;
ptr->status = A_CHAR;
ptr->attr = attr;
return;
term_buffer *ptr;
const int row = pos.y;
const int col = pos.x;
ptr = (mBase[ROW(row)] + col);
memcpy ((char *)ptr->code, u, 4);
if (IS_WIDTH(attr))
(ptr + 1)->status = IN_STRING;
ptr->status = A_CHAR;
ptr->attr = attr;
}
////////////////////////////////////////////////////////////////////////////
// void WriteCR (const CurPos &)
// Write CR status to buffer attribute.
////////////////////////////////////////////////////////////////////////////
// Write CR status to buffer attribute.
void
TermBuffer::WriteCR (const CurPos &pos)
{
int row = pos.y;
int col = pos.x;
term_buffer *ptr = (mBase[ROW(row)] + col);
ptr->attr |= DUMPCR;
int row = pos.y;
int col = pos.x;
term_buffer *ptr = (mBase[ROW(row)] + col);
ptr->attr |= DUMPCR;
}
////////////////////////////////////////////////////////////////////////////
// InsertSpace (const CurPos &, int)
// Insert num space at cursor point.
////////////////////////////////////////////////////////////////////////////
// Insert 'num' spaces at cursor point.
void
TermBuffer::InsertSpace (const CurPos &pos, int num)
{
const int row = pos.y;
const int col = pos.x;
for (int i = mNowColSize - num; i >= col; i--) {
*(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i);
}
memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer));
return;
const int row = pos.y;
const int col = pos.x;
for (int i = mNowColSize - num; i >= col; i--)
*(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i);
memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer));
}
////////////////////////////////////////////////////////////////////////////
// void DeleteChar (const CurPos &, int)
// Delete num character at cursor point.
////////////////////////////////////////////////////////////////////////////
// Delete 'num' characters at cursor point.
void
TermBuffer::DeleteChar(const CurPos &pos, int num)
{
const int row = pos.y;
const int col = pos.x;
term_buffer *ptr = mBase[ROW(row)];
size_t movesize = mNowColSize - (col + num);
memmove (ptr + col, ptr + col + num, movesize * sizeof(term_buffer));
memset (ptr + (mNowColSize - num), 0, num * sizeof(term_buffer));
return;
const int row = pos.y;
const int col = pos.x;
term_buffer *ptr = mBase[ROW(row)];
size_t movesize = mNowColSize - (col + num);
memmove (ptr + col, ptr + col + num, movesize * sizeof(term_buffer));
memset (ptr + (mNowColSize - num), 0, num * sizeof(term_buffer));
}
////////////////////////////////////////////////////////////////////////////
// EraseBelow (const CurPos &)
// Erase below character from cursor position.
////////////////////////////////////////////////////////////////////////////
// Erase characters below cursor position.
void
TermBuffer::EraseBelow(const CurPos &pos)
{
const int row = pos.y;
const int col = pos.x;
memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer));
for (int i = row; i < mRowSize; i++)
EraseLine (i);
const int row = pos.y;
const int col = pos.x;
memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer));
for (int i = row; i < mRowSize; i++)
EraseLine (i);
}
////////////////////////////////////////////////////////////////////////////
// ScrollRegion (int, int, int, int)
// Scroll terminal buffer region.
////////////////////////////////////////////////////////////////////////////
// Scroll the terminal buffer region
void
TermBuffer::ScrollRegion(int top, int bot, int dir, int num)
{
if(dir == SCRUP){
for(int i = 0; i < num; i++){
term_buffer *ptr = mBase[ROW(top)];
for(int j = top; j < bot; j++){
mBase[ROW(j)] = mBase[ROW(j+1)];
}
mBase[ROW(bot)] = ptr;
EraseLine(bot);
}
}else{
// scroll up
for(int i = 0; i < num; i++){
term_buffer *ptr = mBase[ROW(bot)];
for(int j = bot; j > top; j--){
mBase[ROW(j)] = mBase[ROW(j-1)];
}
mBase[ROW(top)] = ptr;
EraseLine(top);
}
}
if(dir == SCRUP) {
for(int i = 0; i < num; i++){
term_buffer *ptr = mBase[ROW(top)];
for(int j = top; j < bot; j++)
mBase[ROW(j)] = mBase[ROW(j+1)];
mBase[ROW(bot)] = ptr;
EraseLine(bot);
}
} else {
// scroll up
for(int i = 0; i < num; i++){
term_buffer *ptr = mBase[ROW(bot)];
for(int j = bot; j > top; j--)
mBase[ROW(j)] = mBase[ROW(j-1)];
mBase[ROW(top)] = ptr;
EraseLine(top);
}
}
}
////////////////////////////////////////////////////////////////////////////
// ScrollLine (void)
// Scroll terminal buffer.
////////////////////////////////////////////////////////////////////////////
// Scroll the terminal buffer.
void
TermBuffer::ScrollLine(void)
{
for (int i = mRowSize; i < mRowSize * 2; i++) {
EraseLine (i);
}
mRowOffset++;
return;
for (int i = mRowSize; i < mRowSize * 2; i++)
EraseLine (i);
mRowOffset++;
}
////////////////////////////////////////////////////////////////////////////
// ResizeTo (int, int, int)
// Resize terminal buffer.
////////////////////////////////////////////////////////////////////////////
// Resize the terminal buffer.
void
TermBuffer::ResizeTo(int newRows, int newCols, int offset)
{
int i;
// TODO: Why is this code #if 0'd? It should either be fixed or removed
#if 0
if (newCols > mColSize) {
for (i = 0; i < buffer_size; i++) {
mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols);
base = mBase[i] + mColSize;
for (j= 0; j < newCols - mColSize; j++) {
*base++ = 0;
}
}
mColSize = newCols;
}
if (newCols > mColSize) {
for (i = 0; i < buffer_size; i++) {
mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols);
base = mBase[i] + mColSize;
for (j= 0; j < newCols - mColSize; j++)
*base++ = 0;
}
mColSize = newCols;
}
#endif
if ( newRows <= mRowSize) {
for (i = newRows; i <= mRowSize; i++) {
EraseLine (i);
}
} else {
for (i = mRowSize; i <= newRows * 2; i++) {
EraseLine (i);
}
}
mNowColSize = newCols;
mRowOffset += offset;
mRowSize = newRows;
return;
if ( newRows <= mRowSize) {
for (i = newRows; i <= mRowSize; i++)
EraseLine (i);
} else {
for (i = mRowSize; i <= newRows * 2; i++)
EraseLine (i);
}
mNowColSize = newCols;
mRowOffset += offset;
mRowSize = newRows;
}
////////////////////////////////////////////////////////////////////////////
// GetArraySize (void)
// Get buffer size.
////////////////////////////////////////////////////////////////////////////
// Get the buffer's size.
int32
TermBuffer::GetArraySize (void)
{
return buffer_size;
return buffer_size;
}
/*
* PRIVATE MEMBER FUNCTIONS.
*/
////////////////////////////////////////////////////////////////////////////
// EraseLine (int)
// Erase one column.
////////////////////////////////////////////////////////////////////////////
// Erase one column.
void
TermBuffer::EraseLine (int row)
{
memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer));
return;
memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer));
}
////////////////////////////////////////////////////////////////////////////
// ClearAll()
// Clear contents of TermBuffer.
////////////////////////////////////////////////////////////////////////////
// Clear the contents of the TermBuffer.
void
TermBuffer::ClearAll (void)
{
for(int i = 0; i < buffer_size; i++){
memset (mBase[i], 0, mColSize * sizeof (term_buffer));
}
mRowOffset = 0;
this->DeSelect ();
for(int i = 0; i < buffer_size; i++)
memset (mBase[i], 0, mColSize * sizeof (term_buffer));
mRowOffset = 0;
DeSelect ();
}
////////////////////////////////////////////////////////////////////////////
// Select()
// Mark Text Selected to given range.
////////////////////////////////////////////////////////////////////////////
// Mark text in the given range as selected
void
TermBuffer::Select(const CurPos &start, const CurPos &end)
{
if (end < start) {
mSelStart = end;
mSelEnd = start;
}
else {
mSelStart = start;
mSelEnd = end;
}
return;
if (end < start) {
mSelStart = end;
mSelEnd = start;
} else {
mSelStart = start;
mSelEnd = end;
}
}
////////////////////////////////////////////////////////////////////////////
// DeSelect()
// Mark Text UnSelected to given range.
////////////////////////////////////////////////////////////////////////////
// Mark text in the given range as not selected
void
TermBuffer::DeSelect (void)
{
mSelStart.Set (-1, -1);
mSelEnd.Set (-1, -1);
return;
mSelStart.Set (-1, -1);
mSelEnd.Set (-1, -1);
}
////////////////////////////////////////////////////////////////////////////
// CheckSelectedRegion (CurPos &)
// Check cursor position which be including selected area.
////////////////////////////////////////////////////////////////////////////
// Check cursor position which be including selected area.
int
TermBuffer::CheckSelectedRegion (const CurPos &pos)
{
if (mSelStart.y == pos.y || mSelEnd.y == pos.y) {
return true;
}
return false;
return (mSelStart.y == pos.y || mSelEnd.y == pos.y);
}
////////////////////////////////////////////////////////////////////////////
// FindWord (CurPos &, CurPos *, CurPos *)
// Find word from TermBuffer
////////////////////////////////////////////////////////////////////////////
// Find a word in the TermBuffer
bool
TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end)
{
uchar buf[5];
ushort attr;
int x, y, start_x;
y = pos.y;
// Search start point
for(x = pos.x - 1; x >= 0; x--){
if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){
++x;
break;
}
}
start_x = x;
// Search end point
for(x = pos.x; x < mColSize; x++){
if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){
--x;
break;
}
}
if (start_x > x) return false;
mSelStart.Set(start_x, y);
if (start != NULL){
start->Set(start_x, y);
}
mSelEnd.Set(x, y);
if (end != NULL){
end->Set(x, y);
}
return true;
uchar buf[5];
ushort attr;
int x, y, start_x;
y = pos.y;
// Search start point
for(x = pos.x - 1; x >= 0; x--){
if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){
++x;
break;
}
}
start_x = x;
// Search end point
for(x = pos.x; x < mColSize; x++){
if( (GetChar(y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')) {
--x;
break;
}
}
if(start_x > x)
return false;
mSelStart.Set(start_x, y);
if(start != NULL)
start->Set(start_x, y);
mSelEnd.Set(x, y);
if(end != NULL)
end->Set(x, y);
return true;
}
////////////////////////////////////////////////////////////////////////////
// GetCharFromRegion (int, int, BString)
// Get one character from selected region.
////////////////////////////////////////////////////////////////////////////
// Get one character from the selected region.
void
TermBuffer::GetCharFromRegion (int x, int y, BString &str)
{
uchar buf[5];
ushort attr;
int status;
status = GetChar(y, x, buf, &attr);
switch(status){
case NO_CHAR:
if (IS_CR (attr)) {
str += '\n';
} else {
str += ' ';
}
break;
case IN_STRING:
break;
default:
str += (const char *)&buf;
break;
}
uchar buf[5];
ushort attr;
int status;
status = GetChar(y, x, buf, &attr);
switch(status) {
case NO_CHAR:
if (IS_CR (attr))
str += '\n';
else
str += ' ';
break;
case IN_STRING:
break;
default:
str += (const char *)&buf;
break;
}
}
////////////////////////////////////////////////////////////////////////////
// AvoidWaste (BString str)
// Delete useless char at end of line, and convert LF code.
////////////////////////////////////////////////////////////////////////////
// Delete useless char at end of line and convert LF code.
inline void
TermBuffer::AvoidWaste (BString &str)
{
int32 len, point;
start:
len = str.Length() - 1;
point = str.FindLast (' ');
if (len > 0 && len == point) {
str.RemoveLast (" ");
goto start;
}
// str += '\n';
return;
// TODO: Remove the goto
int32 len, point;
start:
len = str.Length() - 1;
point = str.FindLast (' ');
if (len > 0 && len == point) {
str.RemoveLast (" ");
goto start;
}
// str += '\n';
}
////////////////////////////////////////////////////////////////////////////
// GetStringFromRegion (BString str)
// Get string from selected region.
////////////////////////////////////////////////////////////////////////////
// Get a string from selected region.
void
TermBuffer::GetStringFromRegion(BString &str)
{
int y;
if(mSelStart.y == mSelEnd.y){
y = mSelStart.y;
for(int x = mSelStart.x ; x <= mSelEnd.x; x++){
GetCharFromRegion (x, y, str);
}
}else{
y = mSelStart.y;
for(int x = mSelStart.x ; x < mNowColSize; x++){
GetCharFromRegion (x, y, str);
}
AvoidWaste (str);
for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){
for(int x = 0 ; x < mNowColSize; x++){
GetCharFromRegion (x, y, str);
}
AvoidWaste (str);
}
y = mSelEnd.y;
for(int x = 0 ; x <= mSelEnd.x; x++){
GetCharFromRegion (x, y, str);
}
}
int y;
if(mSelStart.y == mSelEnd.y) {
y = mSelStart.y;
for(int x = mSelStart.x ; x <= mSelEnd.x; x++)
GetCharFromRegion (x, y, str);
} else {
y = mSelStart.y;
for(int x = mSelStart.x ; x < mNowColSize; x++)
GetCharFromRegion (x, y, str);
AvoidWaste (str);
for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){
for(int x = 0 ; x < mNowColSize; x++)
GetCharFromRegion (x, y, str);
AvoidWaste (str);
}
y = mSelEnd.y;
for(int x = 0 ; x <= mSelEnd.x; x++)
GetCharFromRegion (x, y, str);
}
}

File diff suppressed because it is too large Load Diff