1 /*<html><pre>  -<a                             href="qh-user.htm"
2   >-------------------------------</a><a name="TOP">-</a>
3 
4   userprintf.c
5   user redefinable function -- qh_fprintf
6 
7   see README.txt  see COPYING.txt for copyright information.
8 
9   If you recompile and load this file, then userprintf.o will not be loaded
10   from qhull.a or qhull.lib
11 
12   See libqhull.h for data structures, macros, and user-callable functions.
13   See user.c for qhull-related, redefinable functions
14   see user.h for user-definable constants
15   See usermem.c for qh_exit(), qh_free(), and qh_malloc()
16   see Qhull.cpp and RboxPoints.cpp for examples.
17 
18   qh_printf is a good location for debugging traps, checked on each log line
19 
20   Please report any errors that you fix to qhull@qhull.org
21 */
22 
23 #include "libqhull.h"
24 #include "poly.h" /* for qh.tracefacet */
25 
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 /*-<a                             href="qh-user.htm#TOC"
31   >-------------------------------</a><a name="qh_fprintf">-</a>
32 
33   qh_fprintf( fp, msgcode, format, list of args )
34     print arguments to *fp according to format
35     Use qh_fprintf_rbox() for rboxlib.c
36 
37   notes:
38     sets qh.last_errcode if msgcode is error 6000..6999
39     same as fprintf()
40     fgets() is not trapped like fprintf()
41     exit qh_fprintf via qh_errexit()
42     may be called for errors in qh_initstatistics and qh_meminit
43 */
44 
qh_fprintf(FILE * fp,int msgcode,const char * fmt,...)45 void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... ) {
46   va_list args;
47   facetT *neighbor, **neighborp;
48 
49   if (!fp) {
50     /* could use qhmem.ferr, but probably better to be cautious */
51     qh_fprintf_stderr(6028, "qhull internal error (userprintf.c): fp is 0.  Perhaps the wrong qh_fprintf was called.\n");
52     qh last_errcode= 6028;
53     qh_errexit(qh_ERRqhull, NULL, NULL);
54   }
55 #if qh_QHpointer
56   if ((qh_qh && qh ANNOTATEoutput) || msgcode < MSG_TRACE4) {
57 #else
58   if (msgcode < MSG_TRACE4) {
59 #endif
60     fprintf(fp, "[QH%.4d]", msgcode);
61   }else if (msgcode >= MSG_ERROR && msgcode < MSG_STDERR ) {
62     fprintf(fp, "QH%.4d ", msgcode);
63   }
64   va_start(args, fmt);
65   vfprintf(fp, fmt, args);
66   va_end(args);
67 
68 #if qh_QHpointer
69   if (qh_qh) {
70 #else
71   {
72 #endif
73     if (msgcode >= MSG_ERROR && msgcode < MSG_WARNING)
74       qh last_errcode= msgcode;
75     /* Place debugging traps here. Use with trace option 'Tn'
76        Set qh.tracefacet_id, qh.traceridge_id, and/or qh.tracevertex_id in global.c
77     */
78     if (False) { /* in production skip test for debugging traps */
79       if (qh tracefacet && qh tracefacet->tested) {
80         if (qh_setsize(qh tracefacet->neighbors) < qh hull_dim)
81           qh_errexit(qh_ERRdebug, qh tracefacet, qh traceridge);
82         FOREACHneighbor_(qh tracefacet) {
83           if (neighbor != qh_DUPLICATEridge && neighbor != qh_MERGEridge && neighbor->visible)
84             qh_errexit2(qh_ERRdebug, qh tracefacet, neighbor);
85         }
86       }
87       if (qh traceridge && qh traceridge->top->id == 234342223) {
88         qh_errexit(qh_ERRdebug, qh tracefacet, qh traceridge);
89       }
90       if (qh tracevertex && qh_setsize(qh tracevertex->neighbors)>3434334) {
91         qh_errexit(qh_ERRdebug, qh tracefacet, qh traceridge);
92       }
93     }
94     if (qh FLUSHprint)
95       fflush(fp);
96   }
97 } /* qh_fprintf */
98 
99