libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmRpt.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmRpt.h"
  4. #include "cmErr.h"
  5. #include "cmCtx.h"
  6. #include "cmMem.h"
  7. #include "cmMallocDebug.h"
  8. cmRpt_t cmRptNull = { NULL, NULL, NULL };
  9. void _cmDefaultPrint( void* userPtr, const cmChar_t* text )
  10. {
  11. if( text != NULL )
  12. fputs(text,stdout);
  13. }
  14. void _cmDefaultError( void* userPtr, const cmChar_t* text )
  15. {
  16. if( text != NULL )
  17. fputs(text,stderr);
  18. }
  19. void _cmOut( cmRptPrintFunc_t printFunc, void* userData, const cmChar_t* text )
  20. {
  21. if( printFunc == NULL )
  22. _cmDefaultPrint(userData,text);
  23. else
  24. printFunc(userData,text);
  25. }
  26. void _cmVOut( cmRptPrintFunc_t printFunc, void* userData, const cmChar_t* fmt, va_list vl )
  27. {
  28. va_list vl1;
  29. va_copy(vl1,vl);
  30. unsigned n = vsnprintf(NULL,0,fmt,vl1);
  31. va_end(vl1);
  32. unsigned bufN = 511;
  33. cmChar_t buf[bufN+1];
  34. cmChar_t* b = buf;
  35. unsigned bn = bufN;
  36. if( n > bufN )
  37. {
  38. b = cmMemAllocZ(cmChar_t,n+1);
  39. bn = n;
  40. }
  41. b[0]=0;
  42. if( fmt != NULL )
  43. if( vsnprintf(b,bn,fmt,vl) > bn )
  44. _cmOut(printFunc,userData,"The following error message was truncated because the character buffer in cmRpt::_cmVOut() was too small.");
  45. _cmOut(printFunc,userData,b);
  46. if( n > bufN )
  47. cmMemFree(b);
  48. }
  49. void cmRptSetup( cmRpt_t* rpt, cmRptPrintFunc_t printFunc, cmRptPrintFunc_t errorFunc, void* userPtr )
  50. {
  51. rpt->printFuncPtr = printFunc==NULL ? _cmDefaultPrint : printFunc;
  52. rpt->errorFuncPtr = errorFunc==NULL ? _cmDefaultError : errorFunc;
  53. rpt->userPtr = userPtr;
  54. }
  55. void cmRptPrint( cmRpt_t* rpt, const cmChar_t* text )
  56. {
  57. cmRptPrintFunc_t pfp = rpt==NULL ? NULL : rpt->printFuncPtr;
  58. void* udp = rpt==NULL ? NULL : rpt->userPtr;
  59. _cmOut(pfp,udp,text);
  60. }
  61. void cmRptVPrintf( cmRpt_t* rpt, const cmChar_t* fmt, va_list vl )
  62. {
  63. cmRptPrintFunc_t pfp = rpt==NULL ? NULL : rpt->printFuncPtr;
  64. void* udp = rpt==NULL ? NULL : rpt->userPtr;
  65. _cmVOut(pfp,udp,fmt,vl);
  66. }
  67. void cmRptPrintf( cmRpt_t* rpt, const cmChar_t* fmt, ... )
  68. {
  69. va_list vl;
  70. va_start(vl,fmt);
  71. cmRptVPrintf(rpt,fmt,vl);
  72. va_end(vl);
  73. }
  74. void cmRptError( cmRpt_t* rpt, const cmChar_t* text )
  75. {
  76. cmRptPrintFunc_t pfp = rpt==NULL ? NULL : rpt->errorFuncPtr;
  77. void* udp = rpt==NULL ? NULL : rpt->userPtr;
  78. _cmOut(pfp,udp,text);
  79. }
  80. void cmRptVErrorf( cmRpt_t* rpt, const cmChar_t* fmt, va_list vl )
  81. {
  82. cmRptPrintFunc_t pfp = rpt==NULL ? NULL : rpt->errorFuncPtr;
  83. void* udp = rpt==NULL ? NULL : rpt->userPtr;
  84. _cmVOut(pfp,udp,fmt,vl);
  85. }
  86. void cmRptErrorf( cmRpt_t* rpt, const char* fmt, ... )
  87. {
  88. va_list vl;
  89. va_start(vl,fmt);
  90. cmRptVErrorf(rpt,fmt,vl);
  91. va_end(vl);
  92. }