[vte] [ring] Move VteRowData into its own file



commit a532b2950e748ca37b0b429a7255d95514e212c8
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Sep 10 15:59:50 2009 -0400

    [ring] Move VteRowData into its own file

 src/Makefile.am  |    2 +
 src/ring.c       |  141 +---------------------------------------------
 src/ring.h       |  138 +--------------------------------------------
 src/vterowdata.c |  164 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vterowdata.h |  167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vteunistr.c  |    3 +-
 6 files changed, 337 insertions(+), 278 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f4a6f6..2dac6e4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,8 @@ libvte_la_SOURCES = \
 	vtepangocairo.h \
 	vteregex.c \
 	vteregex.h \
+	vterowdata.c \
+	vterowdata.h \
 	vteseq.c \
 	vteseq-list.h \
 	vteskel.c \
diff --git a/src/ring.c b/src/ring.c
index 76f8be6..ef1d2a7 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -20,154 +20,15 @@
 
 #include <config.h>
 
-#include <stdio.h>
-#include <string.h>
-#include <glib.h>
 #include "debug.h"
 #include "ring.h"
 
+#include <string.h>
 
 #define VTE_RING_CHUNK_COMPACT_BYTES	(1024*1024 - 4 * sizeof (void *)) /* hopefully we get some nice mmapped region */
 
 
 /*
- * VteCells: A row's cell array
- */
-
-typedef struct _VteCells VteCells;
-struct _VteCells {
-	guint32 alloc_len;
-	VteCell cells[1];
-};
-
-static inline VteCells *
-_vte_cells_for_cell_array (VteCell *cells)
-{
-	if (G_UNLIKELY (!cells))
-		return NULL;
-
-	return (VteCells *) (((guchar *) cells) - G_STRUCT_OFFSET (VteCells, cells));
-}
-
-static VteCells *
-_vte_cells_realloc (VteCells *cells, guint len)
-{
-	guint alloc_len = (1 << g_bit_storage (MAX (len, 80))) - 1;
-
-	_vte_debug_print(VTE_DEBUG_RING, "Enlarging cell array of %d cells to %d cells\n", cells ? cells->alloc_len : 0, alloc_len);
-	cells = g_realloc (cells, G_STRUCT_OFFSET (VteCells, cells) + alloc_len * sizeof (cells->cells[0]));
-	cells->alloc_len = alloc_len;
-
-	return cells;
-}
-
-static void
-_vte_cells_free (VteCells *cells)
-{
-	_vte_debug_print(VTE_DEBUG_RING, "Freeing cell array of %d cells\n", cells->alloc_len);
-	g_free (cells);
-}
-
-
-/*
- * VteRowData: A row's data
- */
-
-static void
-_vte_row_data_init (VteRowData *row)
-{
-	memset (row, 0, sizeof (*row));
-}
-
-static void
-_vte_row_data_clear (VteRowData *row)
-{
-	VteCell *cells = row->cells;
-	_vte_row_data_init (row);
-	row->cells = cells;
-}
-
-static void
-_vte_row_data_fini (VteRowData *row)
-{
-	if (row->cells)
-		_vte_cells_free (_vte_cells_for_cell_array (row->cells));
-	row->cells = NULL;
-}
-
-static inline gboolean
-_vte_row_data_ensure (VteRowData *row, guint len)
-{
-	VteCells *cells = _vte_cells_for_cell_array (row->cells);
-	if (G_LIKELY (cells && len <= cells->alloc_len))
-		return TRUE;
-
-	if (G_UNLIKELY (len >= 0xFFFF))
-		return FALSE;
-
-	row->cells = _vte_cells_realloc (cells, len)->cells;
-
-	return TRUE;
-}
-
-void
-_vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell)
-{
-	guint i;
-
-	if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1)))
-		return;
-
-	for (i = row->len; i > col; i--)
-		row->cells[i] = row->cells[i - 1];
-
-	row->cells[col] = *cell;
-	row->len++;
-}
-
-void _vte_row_data_append (VteRowData *row, const VteCell *cell)
-{
-	if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1)))
-		return;
-
-	row->cells[row->len] = *cell;
-	row->len++;
-}
-
-void _vte_row_data_remove (VteRowData *row, guint col)
-{
-	guint i;
-
-	for (i = col + 1; i < row->len; i++)
-		row->cells[i - 1] = row->cells[i];
-
-	if (G_LIKELY (row->len))
-		row->len--;
-}
-
-void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len)
-{
-	if (row->len < len) {
-		guint i = len - row->len;
-
-		if (G_UNLIKELY (!_vte_row_data_ensure (row, len)))
-			return;
-
-		for (i = row->len; i < len; i++)
-			row->cells[i] = *cell;
-
-		row->len = len;
-	}
-}
-
-void _vte_row_data_shrink (VteRowData *row, guint max_len)
-{
-	if (max_len < row->len)
-		row->len = max_len;
-}
-
-
-/*
  * VteCompactRowData: Compact representation of a row
  */
 
diff --git a/src/ring.h b/src/ring.h
index 156759d..6a5cc32 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -21,146 +21,10 @@
 #ifndef vte_ring_h_included
 #define vte_ring_h_included
 
-
-#include <glib.h>
-
-#include "debug.h"
-#include "vteunistr.h"
+#include "vterowdata.h"
 
 G_BEGIN_DECLS
 
-#define VTE_DEF_FG			256
-#define VTE_DEF_BG			257
-#define VTE_BOLD_FG			258
-#define VTE_DIM_FG			259
-#define VTE_DEF_HL                      260
-#define VTE_CUR_BG			261
-#define VTE_PALETTE_SIZE		262
-
-
-/*
- * VteCellAttr: A single cell style attributes
- *
- * Ordered by most commonly changed attributes, to
- * optimize the compact representation.
- */
-
-typedef struct _VteCellAttr {
-	guint32 fragment: 1;	/* A continuation cell. */
-	guint32 columns: 4;	/* Number of visible columns
-				   (as determined by g_unicode_iswide(c)).
-				   Also abused for tabs; bug 353610
-				   Keep at least 4 for tabs to work
-				   */
-	guint32 bold: 1;
-	guint32 fore: 9;	/* Index into color palette */
-	guint32 back: 9;	/* Index into color palette. */
-
-	guint32 standout: 1;
-	guint32 underline: 1;
-	guint32 strikethrough: 1;
-
-	guint32 reverse: 1;
-	guint32 blink: 1;
-	guint32 half: 1;
-
-	guint32 invisible: 1;
-	/* unused; bug 499893
-	guint32 protect: 1;
-	 */
-
-	/* 30 bits */
-} VteCellAttr;
-ASSERT_STATIC (sizeof (VteCellAttr) == 4);
-
-
-/*
- * VteCell: A single cell's data
- */
-
-typedef struct _VteCell {
-	vteunistr c;
-	VteCellAttr attr;
-} VteCell;
-ASSERT_STATIC (sizeof (VteCell) == 8);
-
-static const union {
-	VteCell cell;
-	struct {
-		guint32 c;
-		guint32 attr;
-	} i;
-} basic_cell = {
-	{
-		0,
-		{
-			0, /* fragment */
-			1, /* columns */
-			0, /* bold */
-			VTE_DEF_FG, /* fore */
-			VTE_DEF_BG, /* back */
-
-			0, /* standout */
-			0, /* underline */
-			0, /* strikethrough */
-
-			0, /* reverse */
-			0, /* blink */
-			0, /* half */
-
-			0  /* invisible */
-		}
-	}
-};
-
-
-/*
- * VteRowAttr: A single row's attributes
- */
-
-typedef struct _VteRowAttr {
-	guint8 soft_wrapped: 1;
-} VteRowAttr;
-ASSERT_STATIC (sizeof (VteRowAttr) == 1);
-
-/*
- * VteRowData: A single row's data
- */
-
-typedef struct _VteRowData {
-	VteCell *cells;
-	guint16 len;
-	VteRowAttr attr;
-} VteRowData;
-
-
-#define _vte_row_data_length(__row)			((__row)->len + 0)
-
-static inline const VteCell *
-_vte_row_data_get (const VteRowData *row, guint col)
-{
-	if (G_UNLIKELY (row->len <= col))
-		return NULL;
-
-	return &row->cells[col];
-}
-
-static inline VteCell *
-_vte_row_data_get_writable (VteRowData *row, guint col)
-{
-	if (G_UNLIKELY (row->len <= col))
-		return NULL;
-
-	return &row->cells[col];
-}
-
-void _vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell);
-void _vte_row_data_append (VteRowData *row, const VteCell *cell);
-void _vte_row_data_remove (VteRowData *row, guint col);
-void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len);
-void _vte_row_data_shrink (VteRowData *row, guint max_len);
-
-
 /*
  * VteRingChunk: A chunk of the scrollback buffer ring
  */
diff --git a/src/vterowdata.c b/src/vterowdata.c
new file mode 100644
index 0000000..5736a79
--- /dev/null
+++ b/src/vterowdata.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2002,2009 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Library 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 Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Red Hat Author(s): Nalin Dahyabhai, Behdad Esfahbod
+ */
+
+#include <config.h>
+
+#include "debug.h"
+#include "vterowdata.h"
+
+#include <string.h>
+
+
+/*
+ * VteCells: A row's cell array
+ */
+
+typedef struct _VteCells VteCells;
+struct _VteCells {
+	guint32 alloc_len;
+	VteCell cells[1];
+};
+
+static inline VteCells *
+_vte_cells_for_cell_array (VteCell *cells)
+{
+	if (G_UNLIKELY (!cells))
+		return NULL;
+
+	return (VteCells *) (((guchar *) cells) - G_STRUCT_OFFSET (VteCells, cells));
+}
+
+static VteCells *
+_vte_cells_realloc (VteCells *cells, guint len)
+{
+	guint alloc_len = (1 << g_bit_storage (MAX (len, 80))) - 1;
+
+	_vte_debug_print(VTE_DEBUG_RING, "Enlarging cell array of %d cells to %d cells\n", cells ? cells->alloc_len : 0, alloc_len);
+	cells = g_realloc (cells, G_STRUCT_OFFSET (VteCells, cells) + alloc_len * sizeof (cells->cells[0]));
+	cells->alloc_len = alloc_len;
+
+	return cells;
+}
+
+static void
+_vte_cells_free (VteCells *cells)
+{
+	_vte_debug_print(VTE_DEBUG_RING, "Freeing cell array of %d cells\n", cells->alloc_len);
+	g_free (cells);
+}
+
+
+/*
+ * VteRowData: A row's data
+ */
+
+void
+_vte_row_data_init (VteRowData *row)
+{
+	memset (row, 0, sizeof (*row));
+}
+
+void
+_vte_row_data_clear (VteRowData *row)
+{
+	VteCell *cells = row->cells;
+	_vte_row_data_init (row);
+	row->cells = cells;
+}
+
+void
+_vte_row_data_fini (VteRowData *row)
+{
+	if (row->cells)
+		_vte_cells_free (_vte_cells_for_cell_array (row->cells));
+	row->cells = NULL;
+}
+
+inline gboolean
+_vte_row_data_ensure (VteRowData *row, guint len)
+{
+	VteCells *cells = _vte_cells_for_cell_array (row->cells);
+	if (G_LIKELY (cells && len <= cells->alloc_len))
+		return TRUE;
+
+	if (G_UNLIKELY (len >= 0xFFFF))
+		return FALSE;
+
+	row->cells = _vte_cells_realloc (cells, len)->cells;
+
+	return TRUE;
+}
+
+void
+_vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell)
+{
+	guint i;
+
+	if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1)))
+		return;
+
+	for (i = row->len; i > col; i--)
+		row->cells[i] = row->cells[i - 1];
+
+	row->cells[col] = *cell;
+	row->len++;
+}
+
+void _vte_row_data_append (VteRowData *row, const VteCell *cell)
+{
+	if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1)))
+		return;
+
+	row->cells[row->len] = *cell;
+	row->len++;
+}
+
+void _vte_row_data_remove (VteRowData *row, guint col)
+{
+	guint i;
+
+	for (i = col + 1; i < row->len; i++)
+		row->cells[i - 1] = row->cells[i];
+
+	if (G_LIKELY (row->len))
+		row->len--;
+}
+
+void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len)
+{
+	if (row->len < len) {
+		guint i = len - row->len;
+
+		if (G_UNLIKELY (!_vte_row_data_ensure (row, len)))
+			return;
+
+		for (i = row->len; i < len; i++)
+			row->cells[i] = *cell;
+
+		row->len = len;
+	}
+}
+
+void _vte_row_data_shrink (VteRowData *row, guint max_len)
+{
+	if (max_len < row->len)
+		row->len = max_len;
+}
+
diff --git a/src/vterowdata.h b/src/vterowdata.h
new file mode 100644
index 0000000..20c6b96
--- /dev/null
+++ b/src/vterowdata.h
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Library 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 Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* The interfaces in this file are subject to change at any time. */
+
+#ifndef vterowdata_h_included
+#define vterowdata_h_included
+
+#include "vteunistr.h"
+
+G_BEGIN_DECLS
+
+
+#define VTE_DEF_FG			256
+#define VTE_DEF_BG			257
+#define VTE_BOLD_FG			258
+#define VTE_DIM_FG			259
+#define VTE_DEF_HL                      260
+#define VTE_CUR_BG			261
+#define VTE_PALETTE_SIZE		262
+
+
+/*
+ * VteCellAttr: A single cell style attributes
+ *
+ * Ordered by most commonly changed attributes, to
+ * optimize the compact representation.
+ */
+
+typedef struct _VteCellAttr {
+	guint32 fragment: 1;	/* A continuation cell. */
+	guint32 columns: 4;	/* Number of visible columns
+				   (as determined by g_unicode_iswide(c)).
+				   Also abused for tabs; bug 353610
+				   Keep at least 4 for tabs to work
+				   */
+	guint32 bold: 1;
+	guint32 fore: 9;	/* Index into color palette */
+	guint32 back: 9;	/* Index into color palette. */
+
+	guint32 standout: 1;
+	guint32 underline: 1;
+	guint32 strikethrough: 1;
+
+	guint32 reverse: 1;
+	guint32 blink: 1;
+	guint32 half: 1;
+
+	guint32 invisible: 1;
+	/* unused; bug 499893
+	guint32 protect: 1;
+	 */
+
+	/* 30 bits */
+} VteCellAttr;
+ASSERT_STATIC (sizeof (VteCellAttr) == 4);
+
+
+/*
+ * VteCell: A single cell's data
+ */
+
+typedef struct _VteCell {
+	vteunistr c;
+	VteCellAttr attr;
+} VteCell;
+ASSERT_STATIC (sizeof (VteCell) == 8);
+
+static const union {
+	VteCell cell;
+	struct {
+		guint32 c;
+		guint32 attr;
+	} i;
+} basic_cell = {
+	{
+		0,
+		{
+			0, /* fragment */
+			1, /* columns */
+			0, /* bold */
+			VTE_DEF_FG, /* fore */
+			VTE_DEF_BG, /* back */
+
+			0, /* standout */
+			0, /* underline */
+			0, /* strikethrough */
+
+			0, /* reverse */
+			0, /* blink */
+			0, /* half */
+
+			0  /* invisible */
+		}
+	}
+};
+
+
+/*
+ * VteRowAttr: A single row's attributes
+ */
+
+typedef struct _VteRowAttr {
+	guint8 soft_wrapped: 1;
+} VteRowAttr;
+ASSERT_STATIC (sizeof (VteRowAttr) == 1);
+
+/*
+ * VteRowData: A single row's data
+ */
+
+typedef struct _VteRowData {
+	VteCell *cells;
+	guint16 len;
+	VteRowAttr attr;
+} VteRowData;
+
+
+#define _vte_row_data_length(__row)			((__row)->len + 0)
+
+static inline const VteCell *
+_vte_row_data_get (const VteRowData *row, guint col)
+{
+	if (G_UNLIKELY (row->len <= col))
+		return NULL;
+
+	return &row->cells[col];
+}
+
+static inline VteCell *
+_vte_row_data_get_writable (VteRowData *row, guint col)
+{
+	if (G_UNLIKELY (row->len <= col))
+		return NULL;
+
+	return &row->cells[col];
+}
+
+void _vte_row_data_init (VteRowData *row);
+void _vte_row_data_clear (VteRowData *row);
+void _vte_row_data_fini (VteRowData *row);
+gboolean _vte_row_data_ensure (VteRowData *row, guint len);
+void _vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell);
+void _vte_row_data_append (VteRowData *row, const VteCell *cell);
+void _vte_row_data_remove (VteRowData *row, guint col);
+void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len);
+void _vte_row_data_shrink (VteRowData *row, guint max_len);
+
+
+G_END_DECLS
+
+#endif
diff --git a/src/vteunistr.c b/src/vteunistr.c
index 5451e45..4d5c313 100644
--- a/src/vteunistr.c
+++ b/src/vteunistr.c
@@ -21,9 +21,10 @@
 
 #include <config.h>
 
+#include "vteunistr.h"
+
 #include <string.h>
 
-#include "vteunistr.h"
 
 /* Overview:
  *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]