From 1776f115107afc6ff2d35956558c4a62981430c4 Mon Sep 17 00:00:00 2001
From: Stefen Guzik <guzik2@llnl.gov>
Date: Tue, 29 Jul 2008 20:07:38 +0000
Subject: [PATCH] Integration of Chacho into Gmsh

---
 contrib/Chaco/main/Gmsh_exit.cpp   | 11 +++++++++++
 contrib/Chaco/main/Gmsh_exit.h     | 13 +++++++++++++
 contrib/Chaco/main/Gmsh_printf.cpp | 18 ++++++++++++++++++
 contrib/Chaco/main/Gmsh_printf.h   | 14 ++++++++++++++
 4 files changed, 56 insertions(+)
 create mode 100644 contrib/Chaco/main/Gmsh_exit.cpp
 create mode 100644 contrib/Chaco/main/Gmsh_exit.h
 create mode 100644 contrib/Chaco/main/Gmsh_printf.cpp
 create mode 100644 contrib/Chaco/main/Gmsh_printf.h

diff --git a/contrib/Chaco/main/Gmsh_exit.cpp b/contrib/Chaco/main/Gmsh_exit.cpp
new file mode 100644
index 0000000000..eefa639322
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_exit.cpp
@@ -0,0 +1,11 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+#include <stdexcept>
+
+extern "C" void Gmsh_exit()
+{
+   throw std::runtime_error("Library Chaco wants to exit");
+}
diff --git a/contrib/Chaco/main/Gmsh_exit.h b/contrib/Chaco/main/Gmsh_exit.h
new file mode 100644
index 0000000000..ab9b44bad4
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_exit.h
@@ -0,0 +1,13 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+// Overload the printf statements in Chaco to write using Msg::Direct gmsh
+
+#ifndef _GMSH_EXIT_H_
+#define _GMSH_EXIT_H_
+
+int Gmsh_exit();
+
+#endif
diff --git a/contrib/Chaco/main/Gmsh_printf.cpp b/contrib/Chaco/main/Gmsh_printf.cpp
new file mode 100644
index 0000000000..661cdb83b4
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_printf.cpp
@@ -0,0 +1,18 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+#include "../../../Common/Message.h"
+
+// Overload the printf statements in Chaco to write using Msg::Direct in gmsh
+
+extern "C" int Gmsh_printf(const char *fmt, ...)
+{
+  char str[1024];
+  va_list args;
+  va_start(args, fmt);
+  vsnprintf(str, sizeof(str), fmt, args);
+  va_end(args);
+  Msg::Direct(3, str);
+}
diff --git a/contrib/Chaco/main/Gmsh_printf.h b/contrib/Chaco/main/Gmsh_printf.h
new file mode 100644
index 0000000000..69e4ed1f3f
--- /dev/null
+++ b/contrib/Chaco/main/Gmsh_printf.h
@@ -0,0 +1,14 @@
+// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+// Overload the printf statements in Chaco to write using Msg::Direct gmsh
+
+#ifndef _GMSH_PRINTF_H_
+#define _GMSH_PRINTF_H_
+
+#define printf Gmsh_printf
+int Gmsh_printf(const char *fmt, ...);
+
+#endif
-- 
GitLab