aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/eol.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-08-16 05:04:54 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-08-19 03:29:11 +0200
commit61ff6e97c57f62ee3ad4ffc2166e433bc060e7cb (patch)
tree64c032ebdd040809d1b7e822e627e199a9c2476e /src/eol.h
parent94b041ec331427fd63cdae3e943efe825d1bbf14 (diff)
downloadsciteco-61ff6e97c57f62ee3ad4ffc2166e433bc060e7cb.tar.gz
Integrated clipboard support
* mapped to different registers beginning with "~" * on supported platforms accessing the clipboard is as easy as X~ or G~. Naturally this also allows clipboards to be pasted in string arguments/insertions (^EQ~). * Currently, Gtk+, PDCurses and ncurses/XTerm are supported. For XTerm clipboard support, users must set 0,256ED to enable it since we cannot check for XTerm window ops programmatically (at least without libX11). * When clipboard regs exist, the clipboard can also be deemed functional. This allows macros to fall back to xclip(1) if necessary. * EOL handling has been moved into a new file eol.c and eol.h. EOL translation no longer depends on GIOChannels but can be memory-backed as well.
Diffstat (limited to 'src/eol.h')
-rw-r--r--src/eol.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/eol.h b/src/eol.h
new file mode 100644
index 0000000..81ed4ef
--- /dev/null
+++ b/src/eol.h
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2012-2016 Robin Haberkorn
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __EOL_H
+#define __EOL_H
+
+#include <string.h>
+
+#include <glib.h>
+
+#include "sciteco.h"
+
+namespace SciTECO {
+
+class EOLReader {
+ gchar *buffer;
+ gsize read_len;
+ guint offset;
+ gsize block_len;
+ gint last_char;
+
+public:
+ gint eol_style;
+ gboolean eol_style_inconsistent;
+
+ EOLReader(gchar *_buffer)
+ : buffer(_buffer),
+ read_len(0), offset(0), block_len(0),
+ last_char(0), eol_style(-1),
+ eol_style_inconsistent(FALSE) {}
+ virtual ~EOLReader() {}
+
+ const gchar *convert(gsize &data_len);
+
+protected:
+ virtual bool read(gchar *buffer, gsize &read_len) = 0;
+};
+
+class EOLReaderGIO : public EOLReader {
+ gchar buffer[1024];
+ GIOChannel *channel;
+
+ bool read(gchar *buffer, gsize &read_len);
+
+public:
+ EOLReaderGIO(GIOChannel *_channel = NULL)
+ : EOLReader(buffer), channel(NULL)
+ {
+ set_channel(_channel);
+ }
+
+ inline void
+ set_channel(GIOChannel *_channel = NULL)
+ {
+ if (channel)
+ g_io_channel_unref(channel);
+ channel = _channel;
+ if (channel)
+ g_io_channel_ref(channel);
+ }
+
+ ~EOLReaderGIO()
+ {
+ set_channel();
+ }
+};
+
+class EOLReaderMem : public EOLReader {
+ gsize buffer_len;
+
+ bool read(gchar *buffer, gsize &read_len);
+
+public:
+ EOLReaderMem(gchar *buffer, gsize _buffer_len)
+ : EOLReader(buffer), buffer_len(_buffer_len) {}
+
+ gchar *convert_all(gsize *out_len = NULL);
+};
+
+class EOLWriter {
+ enum {
+ STATE_START = 0,
+ STATE_WRITE_LF
+ } state;
+ gchar last_c;
+ const gchar *eol_seq;
+ gsize eol_seq_len;
+
+public:
+ EOLWriter(gint eol_mode) : state(STATE_START), last_c('\0')
+ {
+ eol_seq = get_eol_seq(eol_mode);
+ eol_seq_len = strlen(eol_seq);
+ }
+ virtual ~EOLWriter() {}
+
+ gsize convert(const gchar *buffer, gsize buffer_len);
+
+protected:
+ virtual gsize write(const gchar *buffer, gsize buffer_len) = 0;
+};
+
+class EOLWriterGIO : public EOLWriter {
+ GIOChannel *channel;
+
+ gsize write(const gchar *buffer, gsize buffer_len);
+
+public:
+ EOLWriterGIO(gint eol_mode)
+ : EOLWriter(eol_mode), channel(NULL) {}
+
+ EOLWriterGIO(GIOChannel *_channel, gint eol_mode)
+ : EOLWriter(eol_mode), channel(NULL)
+ {
+ set_channel(_channel);
+ }
+
+ inline void
+ set_channel(GIOChannel *_channel = NULL)
+ {
+ if (channel)
+ g_io_channel_unref(channel);
+ channel = _channel;
+ if (channel)
+ g_io_channel_ref(channel);
+ }
+
+ ~EOLWriterGIO()
+ {
+ set_channel();
+ }
+};
+
+class EOLWriterMem : public EOLWriter {
+ GString *str;
+
+ gsize write(const gchar *buffer, gsize buffer_len);
+
+public:
+ EOLWriterMem(GString *_str, gint eol_mode)
+ : EOLWriter(eol_mode), str(_str) {}
+};
+
+} /* namespace SciTECO */
+
+#endif