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
+29 -99
View File
@@ -1,65 +1,30 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
#include "CurPos.h" #include "CurPos.h"
/*************************************************************************
*
* Constructor and Destructor
*
************************************************************************/
CurPos::CurPos() CurPos::CurPos()
{ {
} }
CurPos::CurPos(int32 X, int32 Y) CurPos::CurPos(int32 X, int32 Y)
{ {
x = X; x = X;
y = Y; y = Y;
} }
CurPos::CurPos(const CurPos& cp) CurPos::CurPos(const CurPos& cp)
{ {
x = cp.x; x = cp.x;
y = cp.y; y = cp.y;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator =
////////////////////////////////////////////////////////////////////////////
CurPos & CurPos &
CurPos::operator=(const CurPos& from) CurPos::operator=(const CurPos& from)
{ {
@@ -68,10 +33,6 @@ CurPos::operator=(const CurPos& from)
return *this; return *this;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Set Function.
////////////////////////////////////////////////////////////////////////////
void void
CurPos::Set(int32 X, int32 Y) CurPos::Set(int32 X, int32 Y)
{ {
@@ -79,105 +40,74 @@ CurPos::Set(int32 X, int32 Y)
y = Y; y = Y;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator !=
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator!=(const CurPos& from) const CurPos::operator!=(const CurPos& from) const
{ {
return ((x != from.x) || (y != from.y)); return ((x != from.x) || (y != from.y));
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator ==
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator==(const CurPos& from) const CurPos::operator==(const CurPos& from) const
{ {
return ((x == from.x) && (y == from.y)); return ((x == from.x) && (y == from.y));
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator +
////////////////////////////////////////////////////////////////////////////
CurPos CurPos
CurPos::operator+(const CurPos& from) const CurPos::operator+(const CurPos& from) const
{ {
return CurPos(x + from.x, y + from.y); return CurPos(x + from.x, y + from.y);
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator -
////////////////////////////////////////////////////////////////////////////
CurPos CurPos
CurPos::operator- (const CurPos& from) const CurPos::operator- (const CurPos& from) const
{ {
return CurPos(x - from.x, y - from.y); return CurPos(x - from.x, y - from.y);
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator >
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator> (const CurPos& from) const CurPos::operator> (const CurPos& from) const
{ {
if (y > from.y) { if (y > from.y)
return true; return true;
} else if (y == from.y && x > from.x) { else
return true; if (y == from.y && x > from.x)
} return true;
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator >=
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator>= (const CurPos& from) const CurPos::operator>= (const CurPos& from) const
{ {
if (y > from.y) { if (y > from.y)
return true; return true;
} else if (y == from.y && x >= from.x) { else
return true; if (y == from.y && x >= from.x)
} return true;
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator <
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator< (const CurPos& from) const CurPos::operator< (const CurPos& from) const
{ {
if (y < from.y) { if (y < from.y)
return true; return true;
} else if (y == from.y && x < from.x) { else
return true; if (y == from.y && x < from.x)
} return true;
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////
// CurPos
// Operator <=
////////////////////////////////////////////////////////////////////////////
bool bool
CurPos::operator<= (const CurPos& from) const CurPos::operator<= (const CurPos& from) const
{ {
if (y < from.y) { if (y < from.y)
return true; return true;
} else if (y == from.y && x <= from.x) { else
return true; if (y == from.y && x <= from.x)
} return true;
return false; return false;
} }
+21 -43
View File
@@ -1,33 +1,12 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
#ifndef CURPOS_H_INCLUDED #ifndef CURPOS_H_INCLUDED
#define CURPOS_H_INCLUDED #define CURPOS_H_INCLUDED
@@ -35,26 +14,25 @@
class CurPos class CurPos
{ {
public: public:
int32 x; CurPos();
int32 y; CurPos(int32 X, int32 Y);
CurPos(const CurPos& cp);
CurPos(); void Set(int32 X, int32 Y);
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 &from); CurPos operator- (const CurPos&) const;
CurPos operator+ (const CurPos&) const; bool 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; 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
+4 -31
View File
@@ -1,33 +1,12 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
#include <Menu.h> #include <Menu.h>
#include <string.h> #include <string.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -44,7 +23,6 @@ extern PrefHandler *gTermPref;
//#define LOCALE_FILE_DIR PREF_FOLDER"menu/" //#define LOCALE_FILE_DIR PREF_FOLDER"menu/"
BPopUpMenu * BPopUpMenu *
MakeMenu(ulong msg, const char **items, const char *defaultItemName) MakeMenu(ulong msg, const char **items, const char *defaultItemName)
{ {
@@ -62,7 +40,6 @@ MakeMenu(ulong msg, const char **items, const char *defaultItemName)
return menu; return menu;
} }
int int
longname2op(const char *longname) longname2op(const char *longname)
{ {
@@ -78,14 +55,12 @@ longname2op(const char *longname)
return op; return op;
} }
const char * const char *
op2longname(int op) op2longname(int op)
{ {
return encoding_table[op].name; return encoding_table[op].name;
} }
void void
MakeEncodingMenu(BMenu *eMenu, int coding, bool flag) MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
{ {
@@ -107,7 +82,6 @@ MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
} }
} }
void void
LoadLocaleFile(PrefHandler *pref) LoadLocaleFile(PrefHandler *pref)
{ {
@@ -121,4 +95,3 @@ LoadLocaleFile(PrefHandler *pref)
//if (pref->OpenText(name) < B_OK) //if (pref->OpenText(name) < B_OK)
// pref->OpenText(LOCALE_FILE_DEFAULT); // pref->OpenText(LOCALE_FILE_DEFAULT);
} }
+10 -32
View File
@@ -1,33 +1,12 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
#ifndef MENUUTIL_H_INCLUDED #ifndef MENUUTIL_H_INCLUDED
#define MENUUTIL_H_INCLUDED #define MENUUTIL_H_INCLUDED
@@ -41,16 +20,15 @@ class BPopUpMenu;
class BMenu; class BMenu;
class PrefHandler; class PrefHandler;
BPopUpMenu * MakeMenu(ulong msg, const char **items, BPopUpMenu * MakeMenu(ulong msg, const char **items,
const char *defaultItemName); const char *defaultItemName);
int longname2op(const char *longname);
int longname2op(const char *longname); const char * op2longname(int op);
const char * op2longname(int op); void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag);
void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); void LoadLocaleFile (PrefHandler *);
void LoadLocaleFile (PrefHandler *);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif //MENUUTIL_H_INCLUDED #endif
+13 -59
View File
@@ -1,82 +1,36 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
#include "TermBaseView.h" #include "TermBaseView.h"
#include "TermView.h" #include "TermView.h"
/************************************************************************
*
* CONSTRUCTOR and DESTRUCTOR
*
***********************************************************************/
////////////////////////////////////////////////////////////////////////////
// TermBaseView ()
// Constructor.
////////////////////////////////////////////////////////////////////////////
TermBaseView::TermBaseView (BRect frame, TermView *inTermView) TermBaseView::TermBaseView (BRect frame, TermView *inTermView)
:BView (frame, "baseview", B_FOLLOW_ALL_SIDES, :BView(frame, "baseview", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS) B_WILL_DRAW | B_FRAME_EVENTS)
{ {
fTermView = inTermView;
fTermView = inTermView;
} }
////////////////////////////////////////////////////////////////////////////
// ~TermBaseView ()
// Destructor.
////////////////////////////////////////////////////////////////////////////
TermBaseView::~TermBaseView () TermBaseView::~TermBaseView ()
{ {
} }
/*
* PUBLIC MEMBER FUNCTIONS.
*/
////////////////////////////////////////////////////////////////////////////
// FrameResized (float, float)
// Dispatch frame resize event.
////////////////////////////////////////////////////////////////////////////
void void
TermBaseView::FrameResized (float width, float height) TermBaseView::FrameResized (float width, float height)
{ {
int font_width, font_height; int font_width, font_height;
int cols, rows; int cols, rows;
fTermView->GetFontInfo (&font_width, &font_height); fTermView->GetFontInfo (&font_width, &font_height);
cols = (int)(width - VIEW_OFFSET * 2) / font_width; cols = (int)(width - VIEW_OFFSET * 2) / font_width;
rows = (int)(height - VIEW_OFFSET * 2)/ font_height; rows = (int)(height - VIEW_OFFSET * 2)/ font_height;
fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1);
fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1);
} }
+272 -402
View File
@@ -1,31 +1,11 @@
/* /*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * 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 * Authors:
* a copy of this software and associated documentation files or portions * Kian Duffy <[email protected]>
* 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.
*
*/ */
/************************************************************************ /************************************************************************
@@ -69,7 +49,7 @@ c. 2byte status buffer.
**Language environment. (Not impliment) **Language environment. (Not impliment)
--- half width character set --- --- 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) 1 ... Central European(Latin2 / ISO-8859-2)
2 ... Turkish (Latin3 / ISO-8859-3) 2 ... Turkish (Latin3 / ISO-8859-3)
3 ... Baltic (Latin4 / ISO-8859-4) 3 ... Baltic (Latin4 / ISO-8859-4)
@@ -85,7 +65,7 @@ c. 2byte status buffer.
--- Universal character set --- --- Universal character set ---
10 ... Unicode (UTF8) 10 ... Unicode (UTF8)
* Varriables is set CodeConv class. * Variables is set CodeConv class.
* Unicode character width sets CodeConv::UTF8FontWidth member. * Unicode character width sets CodeConv::UTF8FontWidth member.
JIS X 0201 (half width kana ideograph) character use 1 column, 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; extern PrefHandler *gTermPref;
////////////////////////////////////////////////////////////////////////////
//
// TermBuffer class
// Constructor and Destructor.
//
////////////////////////////////////////////////////////////////////////////
TermBuffer::TermBuffer(int rows, int cols) TermBuffer::TermBuffer(int rows, int cols)
{ {
mColSize = MAX_COLS; mColSize = MAX_COLS;
mNowColSize = cols; mNowColSize = cols;
mRowSize = rows; mRowSize = rows;
mRowOffset = 0; mRowOffset = 0;
//buffer_size = ARRAY_SIZE; //buffer_size = ARRAY_SIZE;
buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE); buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE);
/* Allocate buffer */ // Allocate buffer
mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size); mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size);
for(int i = 0; i < buffer_size; i++){ for(int i = 0; i < buffer_size; i++)
mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer)); mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer));
}
} }
////////////////////////////////////////////////////////////////////////////
// TermBuffer Destructer.
//
////////////////////////////////////////////////////////////////////////////
TermBuffer::~TermBuffer() TermBuffer::~TermBuffer()
{ {
for(int i = 0; i < buffer_size; i++){ for(int i = 0; i < buffer_size; i++)
free (mBase[i]); free (mBase[i]);
}
free(mBase); free(mBase);
} }
////////////////////////////////////////////////////////////////////////////
// int GetChar (row, col, *buf, attr) // Gets a character from TermBuffer
// Get chracter from TermBuffer.
////////////////////////////////////////////////////////////////////////////
/* This function moved to header file for effeciency */
int int
TermBuffer::GetChar (int row, int col, uchar *buf, ushort *attr) TermBuffer::GetChar (int row, int col, uchar *buf, ushort *attr)
{ {
term_buffer *ptr; term_buffer *ptr;
ptr = (mBase[row % buffer_size] + col); ptr = (mBase[row % buffer_size] + col);
if (ptr->status == A_CHAR) if (ptr->status == A_CHAR)
memcpy (buf, (char *)(ptr->code), 4); memcpy (buf, (char *)(ptr->code), 4);
*attr = ptr->attr; *attr = ptr->attr;
return ptr->status; return ptr->status;
} }
//////////////////////////////////////////////////////////////////////////// // Get a string (length = num) from given position.
// int GetString (row, col, *buf, attr)
// Get String (length = num) from given position.
////////////////////////////////////////////////////////////////////////////
int int
TermBuffer::GetString (int row, int col, int num, TermBuffer::GetString (int row, int col, int num, uchar *buf,
uchar *buf, ushort *attr) ushort *attr)
{ {
int count = 0, all_count = 0; int count = 0, all_count = 0;
term_buffer *ptr; term_buffer *ptr;
ptr = (mBase[row % buffer_size]); ptr = (mBase[row % buffer_size]);
ptr += col; ptr += col;
*attr = ptr->attr; *attr = ptr->attr;
if (ptr->status == NO_CHAR) { if (ptr->status == NO_CHAR) {
/*
* Buffer is empty and No selected by mouse.
*/
do {
if (col >= mNowColSize) return -1;
col++; // Buffer is empty and No selected by mouse.
ptr++; do {
count--; if (col >= mNowColSize)
if (ptr->status == A_CHAR) return -1;
return count;
if (mSelStart.y == row) { col++;
if (col == mSelStart.x) ptr++;
return count; count--;
} if (ptr->status == A_CHAR)
if (mSelEnd.y == row) { return count;
if (col - 1 == mSelEnd.x)
return count;
}
if (mSelStart.y == row) {
if (col == mSelStart.x)
return count;
}
}while (col <= num); if (mSelEnd.y == row) {
return count; if (col - 1 == mSelEnd.x)
} return count;
else if (IS_WIDTH(ptr->attr)) { }
memcpy (buf, (char *)ptr->code, 4); }while (col <= num);
return 2;
}
while (col <= num) { return count;
memcpy (buf, ptr->code, 4); }
all_count++; else if (IS_WIDTH(ptr->attr)) {
memcpy (buf, (char *)ptr->code, 4);
return 2;
}
if (*buf == 0) { while (col <= num) {
*buf = ' '; memcpy (buf, ptr->code, 4);
*(buf + 1) = '\0'; all_count++;
}
if (ptr->attr != (ptr + 1)->attr){
return all_count;
}
buf = (uchar *)index ((char *)buf, 0x00); if (*buf == 0) {
ptr++; *buf = ' ';
col++; *(buf + 1) = '\0';
}
if (ptr->attr != (ptr + 1)->attr)
return all_count;
if (mSelStart.y == row) { buf = (uchar *)index ((char *)buf, 0x00);
if (col == mSelStart.x) ptr++;
return all_count; col++;
}
if (mSelEnd.y == row) {
if (col - 1 == mSelEnd.x)
return all_count;
}
}
return all_count; 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 WriteChar (const CurPos &, const uchar *, ushort)
// Write character at cursor point.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::WriteChar (const CurPos &pos, const uchar *u, ushort attr) TermBuffer::WriteChar (const CurPos &pos, const uchar *u, ushort attr)
{ {
term_buffer *ptr; term_buffer *ptr;
const int row = pos.y; const int row = pos.y;
const int col = pos.x; const int col = pos.x;
ptr = (mBase[ROW(row)] + col); ptr = (mBase[ROW(row)] + col);
memcpy ((char *)ptr->code, u, 4); memcpy ((char *)ptr->code, u, 4);
if (IS_WIDTH(attr))
(ptr + 1)->status = IN_STRING;
ptr->status = A_CHAR; if (IS_WIDTH(attr))
ptr->attr = attr; (ptr + 1)->status = IN_STRING;
return;
ptr->status = A_CHAR;
ptr->attr = attr;
} }
//////////////////////////////////////////////////////////////////////////// // Write CR status to buffer attribute.
// void WriteCR (const CurPos &)
// Write CR status to buffer attribute.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::WriteCR (const CurPos &pos) TermBuffer::WriteCR (const CurPos &pos)
{ {
int row = pos.y; int row = pos.y;
int col = pos.x; int col = pos.x;
term_buffer *ptr = (mBase[ROW(row)] + col);
ptr->attr |= DUMPCR;
term_buffer *ptr = (mBase[ROW(row)] + col);
ptr->attr |= DUMPCR;
} }
//////////////////////////////////////////////////////////////////////////// // Insert 'num' spaces at cursor point.
// InsertSpace (const CurPos &, int)
// Insert num space at cursor point.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::InsertSpace (const CurPos &pos, int num) TermBuffer::InsertSpace (const CurPos &pos, int num)
{ {
const int row = pos.y; const int row = pos.y;
const int col = pos.x; const int col = pos.x;
for (int i = mNowColSize - num; i >= col; i--) { for (int i = mNowColSize - num; i >= col; i--)
*(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i); *(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i);
}
memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer));
return;
memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer));
} }
////////////////////////////////////////////////////////////////////////////
// void DeleteChar (const CurPos &, int) // Delete 'num' characters at cursor point.
// Delete num character at cursor point.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::DeleteChar(const CurPos &pos, int num) TermBuffer::DeleteChar(const CurPos &pos, int num)
{ {
const int row = pos.y; const int row = pos.y;
const int col = pos.x; const int col = pos.x;
term_buffer *ptr = mBase[ROW(row)]; term_buffer *ptr = mBase[ROW(row)];
size_t movesize = mNowColSize - (col + num); 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;
memmove (ptr + col, ptr + col + num, movesize * sizeof(term_buffer));
memset (ptr + (mNowColSize - num), 0, num * sizeof(term_buffer));
} }
//////////////////////////////////////////////////////////////////////////// // Erase characters below cursor position.
// EraseBelow (const CurPos &)
// Erase below character from cursor position.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::EraseBelow(const CurPos &pos) TermBuffer::EraseBelow(const CurPos &pos)
{ {
const int row = pos.y; const int row = pos.y;
const int col = pos.x; const int col = pos.x;
memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer)); memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer));
for (int i = row; i < mRowSize; i++) for (int i = row; i < mRowSize; i++)
EraseLine (i); EraseLine (i);
} }
//////////////////////////////////////////////////////////////////////////// // Scroll the terminal buffer region
// ScrollRegion (int, int, int, int)
// Scroll terminal buffer region.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::ScrollRegion(int top, int bot, int dir, int num) TermBuffer::ScrollRegion(int top, int bot, int dir, int num)
{ {
if(dir == SCRUP) {
for(int i = 0; i < num; i++){
if(dir == SCRUP){ term_buffer *ptr = mBase[ROW(top)];
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)];
for(int j = top; j < bot; j++){ mBase[ROW(bot)] = ptr;
mBase[ROW(j)] = mBase[ROW(j+1)];
}
mBase[ROW(bot)] = ptr;
EraseLine(bot); EraseLine(bot);
} }
}else{ } else {
// scroll up // scroll up
for(int i = 0; i < num; i++){ for(int i = 0; i < num; i++){
term_buffer *ptr = mBase[ROW(bot)]; term_buffer *ptr = mBase[ROW(bot)];
for(int j = bot; j > top; j--){ for(int j = bot; j > top; j--)
mBase[ROW(j)] = mBase[ROW(j-1)]; mBase[ROW(j)] = mBase[ROW(j-1)];
}
mBase[ROW(top)] = ptr;
EraseLine(top); mBase[ROW(top)] = ptr;
}
} EraseLine(top);
}
}
} }
//////////////////////////////////////////////////////////////////////////// // Scroll the terminal buffer.
// ScrollLine (void)
// Scroll terminal buffer.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::ScrollLine(void) TermBuffer::ScrollLine(void)
{ {
for (int i = mRowSize; i < mRowSize * 2; i++) { for (int i = mRowSize; i < mRowSize * 2; i++)
EraseLine (i); EraseLine (i);
}
mRowOffset++;
return;
mRowOffset++;
} }
////////////////////////////////////////////////////////////////////////////
// ResizeTo (int, int, int) // Resize the terminal buffer.
// Resize terminal buffer.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::ResizeTo(int newRows, int newCols, int offset) TermBuffer::ResizeTo(int newRows, int newCols, int offset)
{ {
int i; int i;
// TODO: Why is this code #if 0'd? It should either be fixed or removed
#if 0 #if 0
if (newCols > mColSize) { if (newCols > mColSize) {
for (i = 0; i < buffer_size; i++) { for (i = 0; i < buffer_size; i++) {
mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols); mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols);
base = mBase[i] + mColSize; base = mBase[i] + mColSize;
for (j= 0; j < newCols - mColSize; j++) { for (j= 0; j < newCols - mColSize; j++)
*base++ = 0; *base++ = 0;
} }
} mColSize = newCols;
mColSize = newCols; }
}
#endif #endif
if ( newRows <= mRowSize) { if ( newRows <= mRowSize) {
for (i = newRows; i <= mRowSize; i++) { for (i = newRows; i <= mRowSize; i++)
EraseLine (i); EraseLine (i);
} } else {
} else { for (i = mRowSize; i <= newRows * 2; i++)
for (i = mRowSize; i <= newRows * 2; i++) { EraseLine (i);
EraseLine (i); }
}
}
mNowColSize = newCols;
mRowOffset += offset;
mRowSize = newRows;
return;
mNowColSize = newCols;
mRowOffset += offset;
mRowSize = newRows;
} }
//////////////////////////////////////////////////////////////////////////// // Get the buffer's size.
// GetArraySize (void)
// Get buffer size.
////////////////////////////////////////////////////////////////////////////
int32 int32
TermBuffer::GetArraySize (void) TermBuffer::GetArraySize (void)
{ {
return buffer_size; return buffer_size;
} }
/* // Erase one column.
* PRIVATE MEMBER FUNCTIONS.
*/
////////////////////////////////////////////////////////////////////////////
// EraseLine (int)
// Erase one column.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::EraseLine (int row) TermBuffer::EraseLine (int row)
{ {
memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer)); memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer));
return;
} }
////////////////////////////////////////////////////////////////////////////
// ClearAll() // Clear the contents of the TermBuffer.
// Clear contents of TermBuffer.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::ClearAll (void) TermBuffer::ClearAll (void)
{ {
for(int i = 0; i < buffer_size; i++){ for(int i = 0; i < buffer_size; i++)
memset (mBase[i], 0, mColSize * sizeof (term_buffer)); memset (mBase[i], 0, mColSize * sizeof (term_buffer));
}
mRowOffset = 0; mRowOffset = 0;
this->DeSelect (); DeSelect ();
} }
////////////////////////////////////////////////////////////////////////////
// Select() // Mark text in the given range as selected
// Mark Text Selected to given range.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::Select(const CurPos &start, const CurPos &end) TermBuffer::Select(const CurPos &start, const CurPos &end)
{ {
if (end < start) {
if (end < start) { mSelStart = end;
mSelStart = end; mSelEnd = start;
mSelEnd = start; } else {
} mSelStart = start;
else { mSelEnd = end;
mSelStart = start; }
mSelEnd = end;
}
return;
} }
////////////////////////////////////////////////////////////////////////////
// DeSelect() // Mark text in the given range as not selected
// Mark Text UnSelected to given range.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::DeSelect (void) TermBuffer::DeSelect (void)
{ {
mSelStart.Set (-1, -1);
mSelStart.Set (-1, -1); mSelEnd.Set (-1, -1);
mSelEnd.Set (-1, -1);
return;
} }
////////////////////////////////////////////////////////////////////////////
// CheckSelectedRegion (CurPos &) // Check cursor position which be including selected area.
// Check cursor position which be including selected area.
////////////////////////////////////////////////////////////////////////////
int int
TermBuffer::CheckSelectedRegion (const CurPos &pos) TermBuffer::CheckSelectedRegion (const CurPos &pos)
{ {
return (mSelStart.y == pos.y || mSelEnd.y == pos.y);
if (mSelStart.y == pos.y || mSelEnd.y == pos.y) {
return true;
}
return false;
} }
////////////////////////////////////////////////////////////////////////////
// FindWord (CurPos &, CurPos *, CurPos *) // Find a word in the TermBuffer
// Find word from TermBuffer
////////////////////////////////////////////////////////////////////////////
bool bool
TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end) TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end)
{ {
uchar buf[5]; uchar buf[5];
ushort attr; ushort attr;
int x, y, start_x; int x, y, start_x;
y = pos.y; y = pos.y;
// Search start point // Search start point
for(x = pos.x - 1; x >= 0; x--){ for(x = pos.x - 1; x >= 0; x--){
if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){ if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){
++x; ++x;
break; break;
} }
} }
start_x = x; start_x = x;
// Search end point // Search end point
for(x = pos.x; x < mColSize; x++){ for(x = pos.x; x < mColSize; x++){
if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){ if( (GetChar(y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')) {
--x; --x;
break; break;
} }
} }
if (start_x > x) return false; if(start_x > x)
return false;
mSelStart.Set(start_x, y); mSelStart.Set(start_x, y);
if (start != NULL){ if(start != NULL)
start->Set(start_x, y); start->Set(start_x, y);
}
mSelEnd.Set(x, y); mSelEnd.Set(x, y);
if (end != NULL){ if(end != NULL)
end->Set(x, y); end->Set(x, y);
}
return true;
return true;
} }
////////////////////////////////////////////////////////////////////////////
// GetCharFromRegion (int, int, BString) // Get one character from the selected region.
// Get one character from selected region.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::GetCharFromRegion (int x, int y, BString &str) TermBuffer::GetCharFromRegion (int x, int y, BString &str)
{ {
uchar buf[5]; uchar buf[5];
ushort attr; ushort attr;
int status; int status;
status = GetChar(y, x, buf, &attr); status = GetChar(y, x, buf, &attr);
switch(status){ switch(status) {
case NO_CHAR:
if (IS_CR (attr)) {
str += '\n';
} else {
str += ' ';
}
break; case NO_CHAR:
if (IS_CR (attr))
str += '\n';
else
str += ' ';
break;
case IN_STRING: case IN_STRING:
break; break;
default: default:
str += (const char *)&buf; str += (const char *)&buf;
break; break;
} }
} }
//////////////////////////////////////////////////////////////////////////// // Delete useless char at end of line and convert LF code.
// AvoidWaste (BString str)
// Delete useless char at end of line, and convert LF code.
////////////////////////////////////////////////////////////////////////////
inline void inline void
TermBuffer::AvoidWaste (BString &str) TermBuffer::AvoidWaste (BString &str)
{ {
int32 len, point; // TODO: Remove the goto
start: int32 len, point;
len = str.Length() - 1;
point = str.FindLast (' ');
if (len > 0 && len == point) { start:
str.RemoveLast (" ");
goto start;
}
// str += '\n'; len = str.Length() - 1;
return; point = str.FindLast (' ');
if (len > 0 && len == point) {
str.RemoveLast (" ");
goto start;
}
// str += '\n';
} }
//////////////////////////////////////////////////////////////////////////// // Get a string from selected region.
// GetStringFromRegion (BString str)
// Get string from selected region.
////////////////////////////////////////////////////////////////////////////
void void
TermBuffer::GetStringFromRegion(BString &str) TermBuffer::GetStringFromRegion(BString &str)
{ {
int y; int y;
if(mSelStart.y == mSelEnd.y){ if(mSelStart.y == mSelEnd.y) {
y = mSelStart.y; y = mSelStart.y;
for(int x = mSelStart.x ; x <= mSelEnd.x; x++){ for(int x = mSelStart.x ; x <= mSelEnd.x; x++)
GetCharFromRegion (x, y, str); GetCharFromRegion (x, y, str);
} } else {
}else{ y = mSelStart.y;
y = mSelStart.y; for(int x = mSelStart.x ; x < mNowColSize; x++)
for(int x = mSelStart.x ; x < mNowColSize; x++){ GetCharFromRegion (x, y, str);
GetCharFromRegion (x, y, str); AvoidWaste (str);
}
AvoidWaste (str);
for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){ for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){
for(int x = 0 ; x < mNowColSize; x++){ for(int x = 0 ; x < mNowColSize; x++)
GetCharFromRegion (x, y, str); GetCharFromRegion (x, y, str);
} AvoidWaste (str);
AvoidWaste (str); }
}
y = mSelEnd.y; y = mSelEnd.y;
for(int x = 0 ; x <= mSelEnd.x; x++){ for(int x = 0 ; x <= mSelEnd.x; x++)
GetCharFromRegion (x, y, str); GetCharFromRegion (x, y, str);
} }
}
} }
File diff suppressed because it is too large Load Diff