You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
6.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.c_api/test.scratch.c_api.c
  3. *
  4. * Purpose: Implementation file for the test.scratch.c_api project.
  5. *
  6. * Created: 14th October 2005
  7. * Updated: 6th August 2012
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * www: http://www.synesis.com.au/software
  14. *
  15. * This source code is placed into the public domain 2005
  16. * by Synesis Software Pty Ltd. There are no restrictions
  17. * whatsoever to your use of the software.
  18. *
  19. * This source code is provided by Synesis Software Pty Ltd "as is"
  20. * and any warranties, whether expressed or implied, including, but
  21. * not limited to, the implied warranties of merchantability and
  22. * fitness for a particular purpose are disclaimed. In no event
  23. * shall the Synesis Software Pty Ltd be liable for any direct,
  24. * indirect, incidental, special, exemplary, or consequential
  25. * damages (including, but not limited to, procurement of
  26. * substitute goods or services; loss of use, data, or profits; or
  27. * business interruption) however caused and on any theory of
  28. * liability, whether in contract, strict liability, or tort
  29. * (including negligence or otherwise) arising in any way out of
  30. * the use of this software, even if advised of the possibility of
  31. * such damage.
  32. *
  33. * Neither the name of Synesis Software Pty Ltd nor the names of
  34. * any subdivisions, employees or agents of Synesis Software Pty
  35. * Ltd, nor the names of any other contributors to this software
  36. * may be used to endorse or promote products derived from this
  37. * software without specific prior written permission.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /* Pantheios Header Files */
  41. #include <pantheios/pantheios.h>
  42. #include <pantheios/backends/be.lrsplit.h>
  43. #include <pantheios/frontend.h>
  44. /* STLSoft Header Files */
  45. #include <stlsoft/stlsoft.h>
  46. /* PlatformSTL Header Files */
  47. #include <platformstl/platformstl.h>
  48. /* Standard C Header Files */
  49. #include <stdio.h>
  50. #include <time.h>
  51. /* /////////////////////////////////////////////////////////////////////////
  52. * Forward declarations
  53. */
  54. static int main_(int /* argc */, char ** /*argv*/);
  55. static void some_logging_1();
  56. static void some_logging_2();
  57. static void some_logging_3();
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Process Identity
  60. *
  61. * This is defined for when we link with the pantheios.fe.simple front-end
  62. * library, which implements pantheios_fe_getProcessIdentity() in terms of this
  63. * externally defined array
  64. */
  65. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.c_api");
  66. /* ////////////////////////////////////////////////////////////////////// */
  67. static int main_(int argc, char **argv)
  68. {
  69. STLSOFT_SUPPRESS_UNUSED(argc);
  70. STLSOFT_SUPPRESS_UNUSED(argv);
  71. some_logging_1();
  72. some_logging_2();
  73. some_logging_3();
  74. return 0;
  75. }
  76. int main(int argc, char *argv[])
  77. {
  78. int res;
  79. #if 0
  80. { for(size_t i = 0;0 != ++i;) {} }
  81. #endif /* 0 */
  82. if(pantheios_init() < 0)
  83. {
  84. res = EXIT_FAILURE;
  85. }
  86. else
  87. {
  88. res = main_(argc, argv);
  89. pantheios_uninit();
  90. }
  91. return res;
  92. }
  93. /* ////////////////////////////////////////////////////////////////////// */
  94. static void some_logging_1()
  95. {
  96. short s = 123;
  97. int i = 456;
  98. long l = 789;
  99. float f = (float)(0.123);
  100. double d = 0.456;
  101. long double ld = 0.789;
  102. void *p = &l;
  103. char const *lstr = "{a pointer to a C-style string}";
  104. #if 0
  105. log_INFORMATIONAL( "This is a (hopefully) typical error string, containing: "
  106. , "some integers (", integer(s), ", ", integer(i), ", ", integer(l), "); "
  107. , "some real numbers (", real(f), ", ", real(d), ", ", real(ld), "); "
  108. , "a pointer (", pointer(p, fmt::hex), "); "
  109. , "some strings (", lstr, ", ", str, ", ", sstr, "); "
  110. , "and a converted time value (", tm, ")"
  111. );
  112. #endif /* 0 */
  113. }
  114. static void some_logging_2()
  115. {
  116. #if 0
  117. try
  118. {
  119. throw std::out_of_range("Eeep!");
  120. }
  121. catch(std::exception &x)
  122. {
  123. log_CRITICAL("Something really bad has happened! Details: \"", x, "\"");
  124. }
  125. #endif /* 0 */
  126. }
  127. static void some_logging_3()
  128. {
  129. int numUsers = 1000000;
  130. char szNumUsers[101];
  131. /* The long-hand way */
  132. pantheios_log_4(
  133. PANTHEIOS_SEV_ALERT
  134. , "We're sure there're likely to be >", -1
  135. , szNumUsers, sprintf(&szNumUsers[0], "%020d", numUsers)
  136. , " satisfied users of ", -1
  137. , "Pantheios", 9
  138. );
  139. /* The convenient way */
  140. pantheios_log_4(
  141. PANTHEIOS_SEV_ALERT
  142. , PANTHEIOS_CARG_STR("We're sure there're likely to be >")
  143. , szNumUsers, sprintf(&szNumUsers[0], "%020d", numUsers)
  144. , PANTHEIOS_CARG_STR(" satisfied users of ")
  145. , PANTHEIOS_CARG_STR_LEN("Pantheios", 9)
  146. );
  147. /* The more convenient way. The following #defines would be in a
  148. * location accessible to your application code
  149. */
  150. #define PARG_S(s) PANTHEIOS_CARG_STR(s)
  151. #define PARG_SN(s, n) PANTHEIOS_CARG_STR_LEN(s, n)
  152. pantheios_log_4(
  153. PANTHEIOS_SEV_ALERT
  154. , PARG_S("We're sure there're likely to be >")
  155. , szNumUsers, sprintf(&szNumUsers[0], "%020d", numUsers)
  156. , PARG_S(" satisfied users of ")
  157. , PARG_SN("Pantheios", 9)
  158. );
  159. }
  160. /* ////////////////////////////////////////////////////////////////////// */