libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmRpt.c 2.3KB

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