changeset 13516:d53287c44e5a

Removed BlockArray class from Konsole code.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 19 Jul 2011 13:17:18 +0200
parents 7eb8cd35454c
children 86adc9c4ec4b
files gui/octave-gui.pro gui/src/terminal/BlockArray.cpp gui/src/terminal/BlockArray.h gui/src/terminal/History.cpp gui/src/terminal/History.h gui/src/terminal/Screen.h gui/src/terminal/TerminalDisplay.cpp
diffstat 7 files changed, 8 insertions(+), 512 deletions(-) [+]
line wrap: on
line diff
--- a/gui/octave-gui.pro	Mon Jul 18 22:04:40 2011 +0200
+++ b/gui/octave-gui.pro	Tue Jul 19 13:17:18 2011 +0200
@@ -56,7 +56,6 @@
         src/terminal/KeyboardTranslator.cpp \
         src/terminal/Screen.cpp \
         src/terminal/History.cpp \
-        src/terminal/BlockArray.cpp \
         src/terminal/konsole_wcwidth.cpp \
         src/terminal/ScreenWindow.cpp \
         src/terminal/Emulation.cpp \
@@ -95,7 +94,6 @@
         src/terminal/KeyboardTranslator.h \
         src/terminal/Screen.h \
         src/terminal/History.h \
-        src/terminal/BlockArray.h \
         src/terminal/konsole_wcwidth.h \
 		  src/terminal/konsole_export.h \
         src/terminal/ScreenWindow.h \
--- a/gui/src/terminal/BlockArray.cpp	Mon Jul 18 22:04:40 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,379 +0,0 @@
-/*
-    This file is part of Konsole, an X terminal.
-    Copyright 2000 by Stephan Kulow <coolo@kde.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301  USA.
-*/
-
-// Own
-#include "BlockArray.h"
-
-// System
-#include <assert.h>
-#include <sys/mman.h>
-#include <sys/param.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define KDE_fseek ::fseek
-#define KDE_lseek ::lseek
-
-static int blocksize = 0;
-
-BlockArray::BlockArray ():size (0),
-current (size_t (-1)),
-index (size_t (-1)),
-lastmap (0), lastmap_index (size_t (-1)), lastblock (0), ion (-1), length (0)
-{
-  // lastmap_index = index = current = size_t(-1);
-  if (blocksize == 0)
-    blocksize = ((sizeof (Block) / getpagesize ()) + 1) * getpagesize ();
-
-}
-
-BlockArray::~BlockArray ()
-{
-  setHistorySize (0);
-  assert (!lastblock);
-}
-
-size_t
-BlockArray::append (Block * block)
-{
-  if (!size)
-    return size_t (-1);
-
-  ++current;
-  if (current >= size)
-    current = 0;
-
-  int rc;
-  rc = KDE_lseek (ion, current * blocksize, SEEK_SET);
-  if (rc < 0)
-    {
-      perror ("HistoryBuffer::add.seek");
-      setHistorySize (0);
-      return size_t (-1);
-    }
-  rc = write (ion, block, blocksize);
-  if (rc < 0)
-    {
-      perror ("HistoryBuffer::add.write");
-      setHistorySize (0);
-      return size_t (-1);
-    }
-
-  length++;
-  if (length > size)
-    length = size;
-
-  ++index;
-
-  delete block;
-  return current;
-}
-
-size_t
-BlockArray::newBlock ()
-{
-  if (!size)
-    return size_t (-1);
-  append (lastblock);
-
-  lastblock = new Block ();
-  return index + 1;
-}
-
-Block *
-BlockArray::lastBlock () const
-{
-  return lastblock;
-}
-
-bool
-BlockArray::has (size_t i) const
-{
-  if (i == index + 1)
-    return true;
-
-  if (i > index)
-    return false;
-  if (index - i >= length)
-    return false;
-  return true;
-}
-
-const Block *
-BlockArray::at (size_t i)
-{
-  if (i == index + 1)
-    return lastblock;
-
-  if (i == lastmap_index)
-    return lastmap;
-
-  if (i > index)
-    {
-      //kDebug(1211) << "BlockArray::at() i > index\n";
-      return 0;
-    }
-
-//     if (index - i >= length) {
-//         kDebug(1211) << "BlockArray::at() index - i >= length\n";
-//         return 0;
-//     }
-
-  size_t j = i;			// (current - (index - i) + (index/size+1)*size) % size ;
-
-  assert (j < size);
-  unmap ();
-
-  Block *block =
-    (Block *) mmap (0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
-
-  if (block == (Block *) - 1)
-    {
-      perror ("mmap");
-      return 0;
-    }
-
-  lastmap = block;
-  lastmap_index = i;
-
-  return block;
-}
-
-void
-BlockArray::unmap ()
-{
-  if (lastmap)
-    {
-      int res = munmap ((char *) lastmap, blocksize);
-      if (res < 0)
-	perror ("munmap");
-    }
-  lastmap = 0;
-  lastmap_index = size_t (-1);
-}
-
-bool
-BlockArray::setSize (size_t newsize)
-{
-  return setHistorySize (newsize * 1024 / blocksize);
-}
-
-bool
-BlockArray::setHistorySize (size_t newsize)
-{
-//    kDebug(1211) << "setHistorySize " << size << " " << newsize;
-
-  if (size == newsize)
-    return false;
-
-  unmap ();
-
-  if (!newsize)
-    {
-      delete lastblock;
-      lastblock = 0;
-      if (ion >= 0)
-	close (ion);
-      ion = -1;
-      current = size_t (-1);
-      return true;
-    }
-
-  if (!size)
-    {
-      FILE *tmp = tmpfile ();
-      if (!tmp)
-	{
-	  perror ("konsole: cannot open temp file.\n");
-	}
-      else
-	{
-	  ion = dup (fileno (tmp));
-	  if (ion < 0)
-	    {
-	      perror ("konsole: cannot dup temp file.\n");
-	      fclose (tmp);
-	    }
-	}
-      if (ion < 0)
-	return false;
-
-      assert (!lastblock);
-
-      lastblock = new Block ();
-      size = newsize;
-      return false;
-    }
-
-  if (newsize > size)
-    {
-      increaseBuffer ();
-      size = newsize;
-      return false;
-    }
-  else
-    {
-      decreaseBuffer (newsize);
-      if (ftruncate (ion, length * blocksize) == -1)
-	perror ("ftruncate");
-      size = newsize;
-
-      return true;
-    }
-}
-
-void
-moveBlock (FILE * fion, int cursor, int newpos, char *buffer2)
-{
-  int res = KDE_fseek (fion, cursor * blocksize, SEEK_SET);
-  if (res)
-    perror ("fseek");
-  res = fread (buffer2, blocksize, 1, fion);
-  if (res != 1)
-    perror ("fread");
-
-  res = KDE_fseek (fion, newpos * blocksize, SEEK_SET);
-  if (res)
-    perror ("fseek");
-  res = fwrite (buffer2, blocksize, 1, fion);
-  if (res != 1)
-    perror ("fwrite");
-}
-
-void
-BlockArray::decreaseBuffer (size_t newsize)
-{
-  if (index < newsize)		// still fits in whole
-    return;
-
-  int offset = (current - (newsize - 1) + size) % size;
-
-  if (!offset)
-    return;
-
-  // The Block constructor could do somthing in future...
-  char *buffer1 = new char[blocksize];
-
-  FILE *fion = fdopen (dup (ion), "w+b");
-  if (!fion)
-    {
-      delete[]buffer1;
-      perror ("fdopen/dup");
-      return;
-    }
-
-  int firstblock;
-  if (current <= newsize)
-    {
-      firstblock = current + 1;
-    }
-  else
-    {
-      firstblock = 0;
-    }
-
-  size_t oldpos;
-  for (size_t i = 0, cursor = firstblock; i < newsize; i++)
-    {
-      oldpos = (size + cursor + offset) % size;
-      moveBlock (fion, oldpos, cursor, buffer1);
-      if (oldpos < newsize)
-	{
-	  cursor = oldpos;
-	}
-      else
-	cursor++;
-    }
-
-  current = newsize - 1;
-  length = newsize;
-
-  delete[]buffer1;
-
-  fclose (fion);
-
-}
-
-void
-BlockArray::increaseBuffer ()
-{
-  if (index < size)		// not even wrapped once
-    return;
-
-  int offset = (current + size + 1) % size;
-  if (!offset)			// no moving needed
-    return;
-
-  // The Block constructor could do somthing in future...
-  char *buffer1 = new char[blocksize];
-  char *buffer2 = new char[blocksize];
-
-  int runs = 1;
-  int bpr = size;		// blocks per run
-
-  if (size % offset == 0)
-    {
-      bpr = size / offset;
-      runs = offset;
-    }
-
-  FILE *fion = fdopen (dup (ion), "w+b");
-  if (!fion)
-    {
-      perror ("fdopen/dup");
-      delete[]buffer1;
-      delete[]buffer2;
-      return;
-    }
-
-  int res;
-  for (int i = 0; i < runs; i++)
-    {
-      // free one block in chain
-      int firstblock = (offset + i) % size;
-      res = KDE_fseek (fion, firstblock * blocksize, SEEK_SET);
-      if (res)
-	perror ("fseek");
-      res = fread (buffer1, blocksize, 1, fion);
-      if (res != 1)
-	perror ("fread");
-      int newpos = 0;
-      for (int j = 1, cursor = firstblock; j < bpr; j++)
-	{
-	  cursor = (cursor + offset) % size;
-	  newpos = (cursor - offset + size) % size;
-	  moveBlock (fion, cursor, newpos, buffer2);
-	}
-      res = KDE_fseek (fion, i * blocksize, SEEK_SET);
-      if (res)
-	perror ("fseek");
-      res = fwrite (buffer1, blocksize, 1, fion);
-      if (res != 1)
-	perror ("fwrite");
-    }
-  current = size - 1;
-  length = size;
-
-  delete[]buffer1;
-  delete[]buffer2;
-
-  fclose (fion);
-
-}
--- a/gui/src/terminal/BlockArray.h	Mon Jul 18 22:04:40 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*
-    This file is part of Konsole, an X terminal.
-    Copyright 2000 by Stephan Kulow <coolo@kde.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301  USA.
-*/
-
-#ifndef BLOCKARRAY_H
-#define BLOCKARRAY_H
-
-#include <unistd.h>
-
-#define BlockSize (1 << 12)
-#define ENTRIES   ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
-
-struct Block
-{
-  Block ()
-  {
-    size = 0;
-  }
-  unsigned char data[ENTRIES];
-  size_t size;
-};
-
-// ///////////////////////////////////////////////////////
-
-class BlockArray
-{
-public:
-    /**
-    * Creates a history file for holding
-    * maximal size blocks. If more blocks
-    * are requested, then it drops earlier
-    * added ones.
-    */
-  BlockArray ();
-
-  /// destructor
-  ~BlockArray ();
-
-    /**
-    * adds the Block at the end of history.
-    * This may drop other blocks.
-    *
-    * The ownership on the block is transferred.
-    * An unique index number is returned for accessing
-    * it later (if not yet dropped then)
-    *
-    * Note, that the block may be dropped completely
-    * if history is turned off.
-    */
-  size_t append (Block * block);
-
-    /**
-    * gets the block at the index. Function may return
-    * 0 if the block isn't available any more.
-    *
-    * The returned block is strictly readonly as only
-    * maped in memory - and will be invalid on the next
-    * operation on this class.
-    */
-  const Block *at (size_t index);
-
-    /**
-    * reorders blocks as needed. If newsize is null,
-    * the history is emptied completely. The indices
-    * returned on append won't change their semantic,
-    * but they may not be valid after this call.
-    */
-  bool setHistorySize (size_t newsize);
-
-  size_t newBlock ();
-
-  Block *lastBlock () const;
-
-    /**
-    * Convenient function to set the size in KBytes
-    * instead of blocks
-    */
-  bool setSize (size_t newsize);
-
-  size_t len () const
-  {
-    return length;
-  }
-
-  bool has (size_t index) const;
-
-  size_t getCurrent () const
-  {
-    return current;
-  }
-
-private:
-  void unmap ();
-  void increaseBuffer ();
-  void decreaseBuffer (size_t newsize);
-
-  size_t size;
-  // current always shows to the last inserted block
-  size_t current;
-  size_t index;
-
-  Block *lastmap;
-  size_t lastmap_index;
-  Block *lastblock;
-
-  int ion;
-  size_t length;
-
-};
-#endif
--- a/gui/src/terminal/History.cpp	Mon Jul 18 22:04:40 2011 +0200
+++ b/gui/src/terminal/History.cpp	Tue Jul 19 13:17:18 2011 +0200
@@ -515,7 +515,7 @@
 	       HistoryTypeBlockArray
 	       (size))
 {
-  m_blockArray.setHistorySize (size);	// nb. of lines.
+  //m_blockArray.setHistorySize (size);	// nb. of lines.
 }
 
 HistoryScrollBlockArray::~HistoryScrollBlockArray ()
@@ -547,6 +547,7 @@
 HistoryScrollBlockArray::getCells (int lineno, int colno,
 				   int count, Character res[])
 {
+  /*
   if (!count)
     return;
 
@@ -561,11 +562,13 @@
   assert (((colno + count) * sizeof (Character)) < ENTRIES);
   memcpy (res, b->data + (colno * sizeof (Character)),
 	  count * sizeof (Character));
+          */
 }
 
 void
 HistoryScrollBlockArray::addCells (const Character a[], int count)
 {
+  /*
   Block *b = m_blockArray.lastBlock ();
 
   if (!b)
@@ -584,6 +587,7 @@
   Q_UNUSED (res);
 
   m_lineLengths.insert (m_blockArray.getCurrent (), count);
+  */
 }
 
 void
--- a/gui/src/terminal/History.h	Mon Jul 18 22:04:40 2011 +0200
+++ b/gui/src/terminal/History.h	Tue Jul 19 13:17:18 2011 +0200
@@ -29,7 +29,6 @@
 #include <QtCore>
 
 // Konsole
-#include "BlockArray.h"
 #include "Character.h"
 
 class HistoryFile
@@ -229,7 +228,7 @@
   virtual void addLine (bool previousWrapped = false);
 
 protected:
-    BlockArray m_blockArray;
+    //BlockArray m_blockArray;
     QHash < int, size_t > m_lineLengths;
 };
 
--- a/gui/src/terminal/Screen.h	Mon Jul 18 22:04:40 2011 +0200
+++ b/gui/src/terminal/Screen.h	Tue Jul 19 13:17:18 2011 +0200
@@ -312,7 +312,7 @@
      * Resets the state of the screen.  This resets the various screen modes
      * back to their default states.  The cursor style and colors are reset
      * (as if setDefaultRendition() had been called)
-     *
+     *setDefaultRendition
      * <ul>
      * <li>Line wrapping is enabled.</li>
      * <li>Origin mode is disabled.</li>
--- a/gui/src/terminal/TerminalDisplay.cpp	Mon Jul 18 22:04:40 2011 +0200
+++ b/gui/src/terminal/TerminalDisplay.cpp	Tue Jul 19 13:17:18 2011 +0200
@@ -540,7 +540,7 @@
   if (_blinking && (style->rendition & RE_BLINK))
     return;
 
-  // setup bold and underline
+  // setup boldJ and underline
   bool useBold;
   ColorEntry::FontWeight weight = style->fontWeight (_colorTable);
   if (weight == ColorEntry::UseCurrentFormat)