userprintf_r.c 3.4 KB

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