aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-11 04:14:01 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-11 04:14:01 +0100
commit7206f6d1249da0dd8e879d0c0b26185fc6ef89d9 (patch)
tree9f570b266ee49c06290c048b600346ab8b0dbddd /src/main.cpp
parent0987ca8b5b1a6ff50bfc8c3b171fdaf6cfff3a2b (diff)
downloadsciteco-7206f6d1249da0dd8e879d0c0b26185fc6ef89d9.tar.gz
added all of SciTECO's declarations to the "SciTECO" namespace
normally, since SciTECO is not a library, this is not strictly necessary since every library should use proper name prefixes or namespaces for all global declarations to avoid name clashes. However * you cannot always rely on that * Scintilla does violate the practice of using prefixes or namespaces. The public APIs are OK, but it does define global functions/methods, e.g. for "Document" that clashed with SciTECO's "TECODocument" class at link-time. Scintilla can put its definitions in a namespace, but this feature cannot be easily enabled without patching Scintilla. * a "SciTECO" namespace will be necessary if "SciTECO" is ever to be turned into a library. Even if this library will have only a C-linkage API, it must ensure it doesn't clutter the global namespace. So the old "TECODocument" class was renamed back to "Document" (SciTECO::Document).
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp110
1 files changed, 61 insertions, 49 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 19ac777..9300b40 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -42,6 +42,8 @@
#include "ring.h"
#include "undo.h"
+namespace SciTECO {
+
#ifdef G_OS_UNIX
#define INI_FILE ".teco_ini"
#else
@@ -236,6 +238,65 @@ initialize_environment(void)
g_strfreev(env);
}
+/*
+ * Callbacks
+ */
+
+class g_bad_alloc : public std::bad_alloc {
+public:
+ const char *
+ what() const throw()
+ {
+ return "glib allocation";
+ }
+};
+
+static gpointer
+g_malloc_exception(gsize n_bytes) throw (std::bad_alloc)
+{
+ gpointer p = malloc(n_bytes);
+
+ if (!p)
+ throw g_bad_alloc();
+ return p;
+}
+
+static gpointer
+g_calloc_exception(gsize n_blocks, gsize n_block_bytes) throw (std::bad_alloc)
+{
+ gpointer p = calloc(n_blocks, n_block_bytes);
+
+ if (!p)
+ throw g_bad_alloc();
+ return p;
+}
+
+static gpointer
+g_realloc_exception(gpointer mem, gsize n_bytes) throw (std::bad_alloc)
+{
+ gpointer p = realloc(mem, n_bytes);
+
+ if (!p)
+ throw g_bad_alloc();
+ return p;
+}
+
+static void
+sigint_handler(int signal)
+{
+ sigint_occurred = TRUE;
+}
+
+} /* namespace SciTECO */
+
+/*
+ * main() must be defined in the root
+ * namespace, so we import the "SciTECO"
+ * namespace. We have no more declarations
+ * to make in the "SciTECO" namespace.
+ */
+using namespace SciTECO;
+
int
main(int argc, char **argv)
{
@@ -337,52 +398,3 @@ main(int argc, char **argv)
return 0;
}
-
-/*
- * Callbacks
- */
-
-class g_bad_alloc : public std::bad_alloc {
-public:
- const char *
- what() const throw()
- {
- return "glib allocation";
- }
-};
-
-static gpointer
-g_malloc_exception(gsize n_bytes) throw (std::bad_alloc)
-{
- gpointer p = malloc(n_bytes);
-
- if (!p)
- throw g_bad_alloc();
- return p;
-}
-
-static gpointer
-g_calloc_exception(gsize n_blocks, gsize n_block_bytes) throw (std::bad_alloc)
-{
- gpointer p = calloc(n_blocks, n_block_bytes);
-
- if (!p)
- throw g_bad_alloc();
- return p;
-}
-
-static gpointer
-g_realloc_exception(gpointer mem, gsize n_bytes) throw (std::bad_alloc)
-{
- gpointer p = realloc(mem, n_bytes);
-
- if (!p)
- throw g_bad_alloc();
- return p;
-}
-
-static void
-sigint_handler(int signal)
-{
- sigint_occurred = TRUE;
-}