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.

84 lines
2.9 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/cpp/inserters/example.cpp.inserter.args/example.cpp.inserter.args.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - use of Pantheios inserter for command-line arguments
  7. * - use of pantheios::logputs() in bail-out conditions
  8. *
  9. * Created: 21st October 2006
  10. * Updated: 6th December 2010
  11. *
  12. * www: http://www.pantheios.org/
  13. *
  14. * License: This source code is placed into the public domain 2006
  15. * by Synesis Software Pty Ltd. There are no restrictions
  16. * whatsoever to your use of the software.
  17. *
  18. * This software is provided "as is", and any warranties,
  19. * express or implied, of any kind and for any purpose, are
  20. * disclaimed.
  21. *
  22. * ////////////////////////////////////////////////////////////////////// */
  23. /* Pantheios Header Files */
  24. #include <pantheios/pantheios.hpp> // Pantheios C++ main header
  25. #include <pantheios/inserters/args.hpp> // for pantheios::args
  26. /* Standard C/C++ Header Files */
  27. #include <exception> // for std::exception
  28. #include <new> // for std::bad_alloc
  29. #include <string> // for std::string
  30. #include <stdlib.h> // for exit codes
  31. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  32. # if defined(STLSOFT_COMPILER_IS_MSVC)
  33. # pragma warning(disable : 4702)
  34. # endif /* compiler */
  35. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  36. /* ////////////////////////////////////////////////////////////////////// */
  37. /* Define the stock front-end process identity, so that it links when using
  38. * fe.N, fe.simple, etc. */
  39. PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.inserter.args");
  40. /* ////////////////////////////////////////////////////////////////////// */
  41. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  42. /* ////////////////////////////////////////////////////////////////////// */
  43. int main(int argc, char** argv)
  44. {
  45. try
  46. {
  47. // Log the command-line arguments; Output like: "example.cpp.inserter.args, abc, def"
  48. #ifndef PANTHEIOS_USE_WIDE_STRINGS
  49. pantheios::log_NOTICE(PSTR("args: ["), pantheios::args(argc, argv), PSTR("]"));
  50. #else /* ? !PANTHEIOS_USE_WIDE_STRINGS */
  51. STLSOFT_SUPPRESS_UNUSED(argc); STLSOFT_SUPPRESS_UNUSED(argv);
  52. #endif /* !PANTHEIOS_USE_WIDE_STRINGS */
  53. return EXIT_SUCCESS;
  54. }
  55. catch(std::bad_alloc&)
  56. {
  57. pantheios::log(pantheios::alert, PSTR("out of memory"));
  58. }
  59. catch(std::exception& x)
  60. {
  61. pantheios::log_CRITICAL(PSTR("Exception: "), x);
  62. }
  63. catch(...)
  64. {
  65. pantheios::logputs(pantheios::emergency, PSTR("Unexpected unknown error"));
  66. }
  67. return EXIT_FAILURE;
  68. }
  69. /* ///////////////////////////// end of file //////////////////////////// */