From 32d193a81692e0defd5414a93101fb0c8c25dfa0 Mon Sep 17 00:00:00 2001
From: Brad Barber <bradb@shore.net>
Date: Sun, 6 Dec 2009 19:43:01 -0500
Subject: [PATCH] Add .pro files for qhull, qhulltest, rbox, and user_eg3.c

Qhull and rbox build correctly under mingw with gcc 4.4.0.  Please
send email to bradb@shore.net if Qhull builds correctly with Linux
gcc 4.4.0 -O2.   With gcc 4.2 and 4.3 qset.c segfaulted due to an
optimization error.
      http://gcc.gnu.org/ml/gcc-bugs/2007-09/msg00474.html
      [April 2008] of http://www.qhull.org/news/#bugs

user_eg3 is a demonstration of using Qhull C++ interface.

Qhulltest contains some failing testcases due to changes made for user_eg3.
Will be fixed soon.

qhull-qt reports an error because the link does not skip userprintf.c
in libqhull.a.  Also the dependencies between qhull-qt and libqhull.a
are handled incorrectly.
---
 cpp/Qhull.cpp                 |   2 +-
 cpp/QhullQh.cpp               |   2 +-
 cpp/RboxPoints.cpp            |   2 +-
 cpp/qhulltest/Qhull_test.cpp  |   8 +-
 cpp/road/RoadError.cpp        |   1 -
 cpp/user_eg3.cpp              |   3 +
 qtpro/qhull-qt/qhull-qt.pro   |   5 +-
 qtpro/qhull/qhull.pro         |  17 +++++
 qtpro/qhulllib/qhulllib.pro   |   1 -
 qtpro/qhulltest/qhulltest.pro | 133 ++++++++++++++++++++++++++++++++++
 qtpro/rbox/rbox.pro           |  17 +++++
 qtpro/user_eg3/user_eg3.pro   | 100 +++++++++++++++++++++++++
 src/Changes.txt               |   4 +
 src/user.h                    |   2 +-
 src/userprintf.c              |   8 ++
 15 files changed, 291 insertions(+), 14 deletions(-)
 create mode 100644 qtpro/qhull/qhull.pro
 create mode 100644 qtpro/qhulltest/qhulltest.pro
 create mode 100644 qtpro/rbox/rbox.pro
 create mode 100644 qtpro/user_eg3/user_eg3.pro

diff --git a/cpp/Qhull.cpp b/cpp/Qhull.cpp
index e6cdddb..04797d4 100644
--- a/cpp/Qhull.cpp
+++ b/cpp/Qhull.cpp
@@ -426,7 +426,7 @@ maybeThrowQhullMessage(int exitCode, int noThrow)  throw()
  >-------------------------------</a><a name="qh_fprintf">-</a>
 
   qh_fprintf(fp, msgcode, format, list of args )
-    fp is ignored.
+    fp is ignored (replaces qh_fprintf() in userprintf.c)
     s_qhull_output == Qhull
 
 notes:
diff --git a/cpp/QhullQh.cpp b/cpp/QhullQh.cpp
index f7444ef..a990d35 100644
--- a/cpp/QhullQh.cpp
+++ b/cpp/QhullQh.cpp
@@ -116,7 +116,7 @@ void QhullQh::
 checkIfQhullRan() // FIXUP -- use successful runQhull instead of TEMPsize?  Many calls OK even if runQhull error'd
 {
     if(qh TEMPsize==0){ // qh_initqhull_buffers() not called
-        throw QhullError(10023, "Qhull error: output does not exist.  Call runQhull() first.");
+        throw QhullError(10023, "Qhull error: checkIfQhullRan failed.  Call runQhull() first.");
     }
 }//checkIfQhullRan
 
diff --git a/cpp/RboxPoints.cpp b/cpp/RboxPoints.cpp
index 5782e22..dae858c 100644
--- a/cpp/RboxPoints.cpp
+++ b/cpp/RboxPoints.cpp
@@ -148,7 +148,7 @@ appendPoints(const char *rboxCommand)
 >-------------------------------</a><a name="qh_fprintf_rbox">-</a>
 
   qh_fprintf_rbox(fp, msgcode, format, list of args )
-    fp is ignored.
+    fp is ignored (replaces qh_fprintf_rbox() in userprintf.c)
     rbox_output == RboxPoints
 
 notes:
diff --git a/cpp/qhulltest/Qhull_test.cpp b/cpp/qhulltest/Qhull_test.cpp
index 7d133bb..dd23b4b 100644
--- a/cpp/qhulltest/Qhull_test.cpp
+++ b/cpp/qhulltest/Qhull_test.cpp
@@ -135,11 +135,11 @@ t_message()
         }catch (const std::exception &e) {
             const char *s= e.what();
             cout<< "INFO   : Caught " << s; 
-            QVERIFY(q.hasQhullMessage()); 
-            QCOMPARE(QString::fromStdString(q.qhullMessage()), QString::fromStdString(s).remove(0, 7));
-            QCOMPARE(QString::fromStdString(q.qhullMessage()).left(9), QString("qhull err"));
+            QVERIFY(!q.hasQhullMessage()); // Removed when copied to QhullError
+            // QCOMPARE(q.qhullMessage(), QString::fromStdString(s).remove(0, 7));
+            QCOMPARE(QString::fromStdString(s).left(6), QString("QH6029"));
             QCOMPARE(q.qhullStatus(), 6029);
-            q.clearQhullMessage();
+            q.clearQhullMessage();  // FIXUP -- review decision to clearQhullMessage at QhullError()
             QVERIFY(!q.hasQhullMessage());
         }
         q.appendQhullMessage("Append 1");
diff --git a/cpp/road/RoadError.cpp b/cpp/road/RoadError.cpp
index 2400a44..886327b 100644
--- a/cpp/road/RoadError.cpp
+++ b/cpp/road/RoadError.cpp
@@ -49,7 +49,6 @@ RoadError(const RoadError &e)
 , log_event(e.log_event)
 , error_message(e.error_message)
 { 
-    cerr << "FIXUP RoadError copy construct\n";
 }//copy construct
 
 RoadError::
diff --git a/cpp/user_eg3.cpp b/cpp/user_eg3.cpp
index d45ac62..40dbb05 100644
--- a/cpp/user_eg3.cpp
+++ b/cpp/user_eg3.cpp
@@ -37,6 +37,9 @@ user_eg3 -- demonstrate calling rbox and qhull from C++.\n\
   qhull \"d p\" ...            Run qhull and produce output\n\
   qhull-cout \"o\" ...         Run qhull and produce output to cout\n\
 \n\
+For example\n\
+  user_eg3 rbox \"10 D2\"  \"2 D2\" qhull  \"s p\"\n\
+\n\
 ";
 
 
diff --git a/qtpro/qhull-qt/qhull-qt.pro b/qtpro/qhull-qt/qhull-qt.pro
index 5330bb4..62b6612 100644
--- a/qtpro/qhull-qt/qhull-qt.pro
+++ b/qtpro/qhull-qt/qhull-qt.pro
@@ -3,9 +3,7 @@
 # -------------------------------------------------
 QT -= gui
 TARGET = qhull-qt
-CONFIG += console \
-    qtestlib \
-    debug
+CONFIG += console qtestlib
 CONFIG -= app_bundle
 TEMPLATE = app
 LIBS = ../../libqhull.a
@@ -81,4 +79,3 @@ HEADERS += cpp/UsingQhullLib.h
 HEADERS += cpp/road/RoadError.h
 HEADERS += cpp/road/RoadLogEvent.h
 HEADERS += cpp/road/RoadTest.h
-QMAKE_MOC_SRC += cpp/qhulltest/UsingQhullLib_test.cpp
diff --git a/qtpro/qhull/qhull.pro b/qtpro/qhull/qhull.pro
new file mode 100644
index 0000000..7ddc999
--- /dev/null
+++ b/qtpro/qhull/qhull.pro
@@ -0,0 +1,17 @@
+# -------------------------------------------------
+# qhull.pro -- Qt project file for qhull.exe
+# -------------------------------------------------
+QT -= gui
+TARGET = qhull
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+LIBS = ../../libqhull.a
+DESTDIR = ../..
+OBJECTS_DIR = ../../tmp/obj
+MOC_DIR = ../../tmp/moc
+RCC_DIR = ../../tmp/rcc
+INCLUDEPATH = ../../cpp;../../cpp/road;../../tmp
+VPATH = ../..
+SOURCES += src/unix.c
+HEADERS += src/qhulllib.h
diff --git a/qtpro/qhulllib/qhulllib.pro b/qtpro/qhulllib/qhulllib.pro
index 76189a8..c6fd863 100644
--- a/qtpro/qhulllib/qhulllib.pro
+++ b/qtpro/qhulllib/qhulllib.pro
@@ -4,7 +4,6 @@
 # configure -commercial -no-qt3support -no-opengl -no-rtti -qt-style-plastique
 QT -= gui
 TARGET = ../../qhull
-CONFIG += debug
 CONFIG -= app_bundle
 TEMPLATE = lib
 DESTDIR = ../../tmp/lib
diff --git a/qtpro/qhulltest/qhulltest.pro b/qtpro/qhulltest/qhulltest.pro
new file mode 100644
index 0000000..681364b
--- /dev/null
+++ b/qtpro/qhulltest/qhulltest.pro
@@ -0,0 +1,133 @@
+# -------------------------------------------------
+# qhull-qt.pro -- Qt project file
+# -------------------------------------------------
+QT -= gui
+TARGET = qhulltest
+CONFIG += console qtestlib
+CONFIG -= app_bundle
+TEMPLATE = app
+DESTDIR = ../..
+OBJECTS_DIR = ../../tmp/obj
+MOC_DIR = ../../tmp/moc
+RCC_DIR = ../../tmp/rcc
+INCLUDEPATH = ../../cpp;../../cpp/road;../../tmp
+VPATH = ../..
+SOURCES += cpp/Coordinates.cpp
+SOURCES += cpp/QhullVertexSet.cpp
+SOURCES += cpp/QhullHyperplane.cpp
+SOURCES += cpp/PointCoordinates.cpp
+SOURCES += cpp/Qhull.cpp
+SOURCES += cpp/QhullError.cpp
+SOURCES += cpp/QhullEvent.cpp
+SOURCES += cpp/QhullFacet.cpp
+SOURCES += cpp/QhullFacetList.cpp
+SOURCES += cpp/QhullFacetSet.cpp
+SOURCES += cpp/QhullPoint.cpp
+SOURCES += cpp/QhullPoints.cpp
+SOURCES += cpp/QhullPointSet.cpp
+SOURCES += cpp/QhullQh.cpp
+SOURCES += cpp/QhullRidge.cpp
+SOURCES += cpp/QhullSet.cpp
+SOURCES += cpp/QhullStat.cpp
+SOURCES += cpp/QhullVertex.cpp
+SOURCES += cpp/RboxPoints.cpp
+SOURCES += cpp/UsingQhullLib.cpp
+SOURCES += cpp/road/RoadError.cpp
+SOURCES += cpp/road/RoadLogEvent.cpp
+SOURCES += cpp/road/RoadTest.cpp
+SOURCES += cpp/qhulltest/Coordinates_test.cpp
+SOURCES += cpp/qhulltest/PointCoordinates_test.cpp
+SOURCES += cpp/qhulltest/Qhull_test.cpp
+SOURCES += cpp/qhulltest/QhullFacet_test.cpp
+SOURCES += cpp/qhulltest/QhullFacetList_test.cpp
+SOURCES += cpp/qhulltest/QhullFacetSet_test.cpp
+SOURCES += cpp/qhulltest/QhullHyperplane_test.cpp
+SOURCES += cpp/qhulltest/QhullLinkedList_test.cpp
+SOURCES += cpp/qhulltest/QhullPoint_test.cpp
+SOURCES += cpp/qhulltest/QhullPoints_test.cpp
+SOURCES += cpp/qhulltest/QhullPointSet_test.cpp
+SOURCES += cpp/qhulltest/QhullRidge_test.cpp
+SOURCES += cpp/qhulltest/QhullSet_test.cpp
+SOURCES += cpp/qhulltest/qhulltest.cpp
+SOURCES += cpp/qhulltest/QhullVertex_test.cpp
+SOURCES += cpp/qhulltest/UsingQhullLib_test.cpp
+SOURCES += cpp/qhulltest/RboxPoints_test.cpp
+HEADERS += cpp/Coordinates.h
+HEADERS += cpp/QhullHyperplane.h
+HEADERS += cpp/functionObjects.h
+HEADERS += cpp/PointCoordinates.h
+HEADERS += cpp/Qhull.h
+HEADERS += cpp/QhullError.h
+HEADERS += cpp/QhullEvent.h
+HEADERS += cpp/QhullFacet.h
+HEADERS += cpp/QhullFacetList.h
+HEADERS += cpp/QhullFacetSet.h
+HEADERS += cpp/QhullIterator.h
+HEADERS += cpp/QhullLinkedList.h
+HEADERS += cpp/QhullPoint.h
+HEADERS += cpp/QhullPoints.h
+HEADERS += cpp/QhullPointSet.h
+HEADERS += cpp/QhullQh.h
+HEADERS += cpp/QhullRidge.h
+HEADERS += cpp/QhullSet.h
+HEADERS += cpp/QhullSets.h
+HEADERS += cpp/QhullStat.h
+HEADERS += cpp/QhullVertex.h
+HEADERS += cpp/RboxPoints.h
+HEADERS += cpp/UsingQhullLib.h
+HEADERS += cpp/road/RoadError.h
+HEADERS += cpp/road/RoadLogEvent.h
+HEADERS += cpp/road/RoadTest.h
+
+
+
+# Add all files explicitly.  The library did not work
+# -------------------------------------------------
+# qhulllib.pro -- Qt project file
+# -------------------------------------------------
+# configure -commercial -no-qt3support -no-opengl -no-rtti -qt-style-plastique
+
+SOURCES += src/geom.c
+SOURCES += src/geom2.c
+SOURCES += src/global.c
+SOURCES += src/io.c
+SOURCES += src/mem.c
+SOURCES += src/merge.c
+SOURCES += src/poly2.c
+SOURCES += src/poly.c
+SOURCES += src/qhulllib.c
+SOURCES += src/qset.c
+SOURCES += src/random.c
+SOURCES += src/rboxlib.c
+SOURCES += src/stat.c
+SOURCES += src/user.c
+# SOURCES += src/usermem.c
+# SOURCES += src/userprintf.c
+OTHER_FILES += src/Changes.txt
+OTHER_FILES += src/index.htm
+OTHER_FILES += src/Make-config.sh
+OTHER_FILES += src/Makefile.txt
+OTHER_FILES += src/Mborland
+OTHER_FILES += src/qh-geom.htm
+OTHER_FILES += src/qh-globa.htm
+OTHER_FILES += src/qh-io.htm
+OTHER_FILES += src/qh-mem.htm
+OTHER_FILES += src/qh-merge.htm
+OTHER_FILES += src/qh-poly.htm
+OTHER_FILES += src/qh-qhull.htm
+OTHER_FILES += src/qh-set.htm
+OTHER_FILES += src/qh-stat.htm
+OTHER_FILES += src/qh-user.htm
+HEADERS += src/geom.h
+HEADERS += src/io.h
+HEADERS += src/mem.h
+HEADERS += src/merge.h
+HEADERS += src/poly.h
+
+# qhull.h is for backwards compatibility
+HEADERS += src/qhulllib.h
+HEADERS += src/qhull_a.h
+HEADERS += src/qset.h
+HEADERS += src/random.h
+HEADERS += src/stat.h
+HEADERS += src/user.h
diff --git a/qtpro/rbox/rbox.pro b/qtpro/rbox/rbox.pro
new file mode 100644
index 0000000..6872b22
--- /dev/null
+++ b/qtpro/rbox/rbox.pro
@@ -0,0 +1,17 @@
+# -------------------------------------------------
+# qhull.pro -- Qt project file for qhull.exe
+# -------------------------------------------------
+QT -= gui
+TARGET = rbox
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+LIBS = ../../libqhull.a
+DESTDIR = ../..
+OBJECTS_DIR = ../../tmp/obj
+MOC_DIR = ../../tmp/moc
+RCC_DIR = ../../tmp/rcc
+INCLUDEPATH = ../../cpp;../../cpp/road;../../tmp
+VPATH = ../..
+SOURCES += src/rbox.c
+HEADERS += src/qhulllib.h
diff --git a/qtpro/user_eg3/user_eg3.pro b/qtpro/user_eg3/user_eg3.pro
new file mode 100644
index 0000000..1bd7cee
--- /dev/null
+++ b/qtpro/user_eg3/user_eg3.pro
@@ -0,0 +1,100 @@
+# -------------------------------------------------
+# user_eg3.pro -- Qt project file for cpp demonstration program
+# -------------------------------------------------
+QT -= gui
+TARGET = user_eg3
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+DESTDIR = ../..
+OBJECTS_DIR = ../../tmp/obj
+MOC_DIR = ../../tmp/moc
+RCC_DIR = ../../tmp/rcc
+INCLUDEPATH = ../../cpp;../../cpp/road;../../tmp
+VPATH = ../..
+SOURCES += cpp/user_eg3.cpp
+SOURCES += cpp/Coordinates.cpp
+SOURCES += cpp/QhullVertexSet.cpp
+SOURCES += cpp/QhullHyperplane.cpp
+SOURCES += cpp/PointCoordinates.cpp
+SOURCES += cpp/Qhull.cpp
+SOURCES += cpp/QhullError.cpp
+SOURCES += cpp/QhullEvent.cpp
+SOURCES += cpp/QhullFacet.cpp
+SOURCES += cpp/QhullFacetList.cpp
+SOURCES += cpp/QhullFacetSet.cpp
+SOURCES += cpp/QhullPoint.cpp
+SOURCES += cpp/QhullPoints.cpp
+SOURCES += cpp/QhullPointSet.cpp
+SOURCES += cpp/QhullQh.cpp
+SOURCES += cpp/QhullRidge.cpp
+SOURCES += cpp/QhullSet.cpp
+SOURCES += cpp/QhullStat.cpp
+SOURCES += cpp/QhullVertex.cpp
+SOURCES += cpp/RboxPoints.cpp
+SOURCES += cpp/UsingQhullLib.cpp
+SOURCES += cpp/road/RoadError.cpp
+SOURCES += cpp/road/RoadLogEvent.cpp
+
+HEADERS += cpp/Coordinates.h
+HEADERS += cpp/QhullHyperplane.h
+HEADERS += cpp/functionObjects.h
+HEADERS += cpp/PointCoordinates.h
+HEADERS += cpp/Qhull.h
+HEADERS += cpp/QhullError.h
+HEADERS += cpp/QhullEvent.h
+HEADERS += cpp/QhullFacet.h
+HEADERS += cpp/QhullFacetList.h
+HEADERS += cpp/QhullFacetSet.h
+HEADERS += cpp/QhullIterator.h
+HEADERS += cpp/QhullLinkedList.h
+HEADERS += cpp/QhullPoint.h
+HEADERS += cpp/QhullPoints.h
+HEADERS += cpp/QhullPointSet.h
+HEADERS += cpp/QhullQh.h
+HEADERS += cpp/QhullRidge.h
+HEADERS += cpp/QhullSet.h
+HEADERS += cpp/QhullSets.h
+HEADERS += cpp/QhullStat.h
+HEADERS += cpp/QhullVertex.h
+HEADERS += cpp/RboxPoints.h
+HEADERS += cpp/UsingQhullLib.h
+HEADERS += cpp/road/RoadError.h
+HEADERS += cpp/road/RoadLogEvent.h
+
+# Add all files explicitly.  The library did not work
+# -------------------------------------------------
+# qhulllib.pro -- Qt project file
+# -------------------------------------------------
+# configure -commercial -no-qt3support -no-opengl -no-rtti -qt-style-plastique
+
+SOURCES += src/geom.c
+SOURCES += src/geom2.c
+SOURCES += src/global.c
+SOURCES += src/io.c
+SOURCES += src/mem.c
+SOURCES += src/merge.c
+SOURCES += src/poly2.c
+SOURCES += src/poly.c
+SOURCES += src/qhulllib.c
+SOURCES += src/qset.c
+SOURCES += src/random.c
+SOURCES += src/rboxlib.c
+SOURCES += src/stat.c
+SOURCES += src/user.c
+SOURCES += src/usermem.c
+# SOURCES += src/userprintf.c
+
+HEADERS += src/geom.h
+HEADERS += src/io.h
+HEADERS += src/mem.h
+HEADERS += src/merge.h
+HEADERS += src/poly.h
+
+# qhull.h is for backwards compatibility
+HEADERS += src/qhulllib.h
+HEADERS += src/qhull_a.h
+HEADERS += src/qset.h
+HEADERS += src/random.h
+HEADERS += src/stat.h
+HEADERS += src/user.h
diff --git a/src/Changes.txt b/src/Changes.txt
index 1e29433..34b56c9 100644
--- a/src/Changes.txt
+++ b/src/Changes.txt
@@ -71,8 +71,12 @@ To do
  - Redo Coordinates w/o vector<>
  - Change #include to specific -> general
  - Remove class-static code, check K_GLOBAL_STATIC
+ - Rename rboxlib and qhulllib to librbox and libqhull
+   user_eg3 rbox 10 qhull does nothing
 
 qhull 2009.1  2008/03/20
+ - Use gcc 4.4.0 or later.  gcc 4.2.1, 4.2.2, and 4.3.2 -O2 segfaults in qset.c .  gcc 4.1.1 was OK
+ -    Bug report    http://gcc.gnu.org/ml/gcc-bugs/2007-09/msg00474.html
  - Added user_eg3 as an example of Qhull.cpp
  - Renamed html/qh-in.htm to html/qh-code.htm
  - Report not enough points if d points, Delaunay, and not Qz
diff --git a/src/user.h b/src/user.h
index e19d59e..adcfa66 100644
--- a/src/user.h
+++ b/src/user.h
@@ -47,7 +47,7 @@ Code flags --
 
   If add new messages, assign these values and increment.
 
-  def counters = [27, 1047, 2059, 3025, 4068, 5003, 6231, 7078, 8143, 9410] 
+  def counters = [27, 1047, 2059, 3025, 4068, 5003, 6232, 7078, 8143, 9410]
 
   See: qh_ERR* [qhulllib.h]
 */
diff --git a/src/userprintf.c b/src/userprintf.c
index d780b06..2afe46c 100644
--- a/src/userprintf.c
+++ b/src/userprintf.c
@@ -42,6 +42,10 @@
 void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... ) {
     va_list args;
 
+    if (!fp) {
+        fprintf(stderr, "QH6232 Qhull internal error (userprintf.c): fp is 0.  Wrong qh_fprintf called.\n");
+        qh_errexit(6232, NULL, NULL);
+    }
     va_start(args, fmt);
     if (qh ANNOTATEoutput) {
       fprintf(fp, "[QH%.4d]", msgcode);
@@ -55,6 +59,10 @@ void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... ) {
 void qh_fprintf_rbox(FILE *fp, int msgcode, const char *fmt, ... ) {
     va_list args;
     
+    if (!fp) {
+        fprintf(stderr, "QH6231 Qhull internal error (userprintf.c): fp is 0.  Wrong qh_fprintf_rbox called.\n");
+        qh_errexit_rbox(6231);
+    }
     if (msgcode >= MSG_ERROR && msgcode < MSG_STDERR)
       fprintf(fp, "QH%.4d ", msgcode);
     va_start(args, fmt);
-- 
GitLab