static string_t pan_get_hid_() { #if defined(PLATFORMSTL_OS_IS_UNIX) PAN_CHAR_T szHostName[1001]; if(0 != ::gethostname(&szHostName[0], STLSOFT_NUM_ELEMENTS(szHostName))) { return PANTHEIOS_LITERAL_STRING("localhost"); } else { return szHostName; } #elif defined(PLATFORMSTL_OS_IS_WINDOWS) PAN_CHAR_T szHostName[1001]; DWORD cchHostName = STLSOFT_NUM_ELEMENTS(szHostName); if(!pantheios_GetComputerName_(&szHostName[0], &cchHostName)) { return PANTHEIOS_LITERAL_STRING("localhost"); } else { return string_t(szHostName, static_cast<size_t>(cchHostName)); } #else /* ? OS */ # error Not discriminated for platforms other than UNIX and Windows #endif /* OS */ }
static void test_win_F_HIDE_TIME() { const int timeFlags = 0 | 0 | PANTHEIOS_GETCURRENTTIME_F_HIDE_TIME | 0; pan_beutil_time_t tm(0, NULL); size_t expected = pantheios_util_getCurrentTime(&tm, timeFlags); PANTHEIOS_TEST_TIME( 0, timeFlags, expected, PANTHEIOS_LITERAL_STRING("")); { for(size_t i = 1; i < expected + 100; ++i) { PANTHEIOS_TEST_TIME( expected + i, timeFlags, expected, PANTHEIOS_LITERAL_STRING("*")); }} }
int be_fprintf_Context::rawLogEntry( int severity4 , int /* severityX */ , const pan_slice_t (&ar)[rawLogArrayDimension] , size_t /* cchTotal */ ) { PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_INTERNAL(severity4 >= 0, "severity must be >= 0"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_INTERNAL(severity4 < 16, "severity must be < 16"); // select the stream: stdout for debug/info/notice; stderr for everything else FILE* const stm = deduce_stm_(severity4); const PAN_CHAR_T fmt[] = PANTHEIOS_LITERAL_STRING("%.*s%.*s%.*s%.*s%.*s%.*s%.*s%.*s%.*s%.*s\n"); STLSOFT_STATIC_ASSERT(4 * rawLogArrayDimension + 2 == STLSOFT_NUM_ELEMENTS(fmt)); // fprintf the array of slices #define PAN_BE_GET_SLICE_4_PRINTF(x) int(x.len), x.ptr return pan_fprintf_(stm, fmt , PAN_BE_GET_SLICE_4_PRINTF(ar[0]) , PAN_BE_GET_SLICE_4_PRINTF(ar[1]) , PAN_BE_GET_SLICE_4_PRINTF(ar[2]) , PAN_BE_GET_SLICE_4_PRINTF(ar[3]) , PAN_BE_GET_SLICE_4_PRINTF(ar[4]) , PAN_BE_GET_SLICE_4_PRINTF(ar[5]) , PAN_BE_GET_SLICE_4_PRINTF(ar[6]) , PAN_BE_GET_SLICE_4_PRINTF(ar[7]) , PAN_BE_GET_SLICE_4_PRINTF(ar[8]) , PAN_BE_GET_SLICE_4_PRINTF(ar[9])); }
static void test_1_01() { PAN_CHAR_T hostname[1000]; const string_t hid = pan_get_hid_(); { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(hostname); ++i) { ::memset(&hostname[0], 0, sizeof(hostname)); const size_t len = pantheios::getHostName(&hostname[0], i); if(len == i) { // The function did not have enough space to write in, so it // will return the length passed to it ... XTESTS_TEST_INTEGER_EQUAL(i, len); // ... and will not have written anything to the file XTESTS_TEST_STRING_EQUAL(PANTHEIOS_LITERAL_STRING(""), hostname); } else { // The function had enough space, so it will return the length // of the intended hostname ... XTESTS_TEST_INTEGER_EQUAL(hid.size(), len); // ... and will have written the hostname XTESTS_TEST_STRING_EQUAL(hid, hostname); } }} }
int main() { /* Must initialise Pantheios, when using from C (and there are no C++ * compilation units in the link-unit). * * If this is not done, undefined behaviour will ensue ... */ if(pantheios_init() < 0) { return EXIT_FAILURE; } else { int i = 123; float f = 99.99f; /* Log the int and the float: Output: "int=123, float=99.99" */ pantheios_logprintf(PANTHEIOS_SEV_INFORMATIONAL , PANTHEIOS_LITERAL_STRING("int=%d, float=%g") , i, f); /* Must uninitialise Pantheios. * * pantheios_uninit() must be called once for each successful (>=0) * invocation of pantheios_init(). */ pantheios_uninit(); return EXIT_SUCCESS; } }
PANTHEIOS_CALL(int) pantheios_be_speech_parseArgs( size_t numArgs , pan_slice_t* const args , pan_be_speech_init_t* init ) { PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API((NULL != args || 0 == numArgs), "argument pointer must be non-null, or number of arguments must be 0"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(NULL != init, "initialisation structure pointer may not be null"); pantheios_be_speech_getDefaultAppInit(init); // 1. Parse the stock arguments int res = pantheios_be_parseStockArgs(numArgs, args, &init->flags); if(res >= 0) { // 2.a Parse the custom argument: "synchronous" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("synchronous"), true, PANTHEIOS_BE_SPEECH_F_SYNCHRONOUS, &init->flags); } if(res >= 0) { // 2.b Parse the custom argument: "purgeBeforeSpeak" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("purgeBeforeSpeak"), true, PANTHEIOS_BE_SPEECH_F_PURGE_BEFORE_SPEAK, &init->flags); } if(res >= 0) { // 2.c Parse the custom argument: "speakPunctuation" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("speakPunctuation"), true, PANTHEIOS_BE_SPEECH_F_SPEAK_PUNCTUATION, &init->flags); } if(res >= 0) { // 2.d Parse the custom argument: "synchronousOnCritical" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("synchronousOnCritical"), true, PANTHEIOS_BE_SPEECH_F_SYNCHRONOUS_ON_CRITICAL, &init->flags); } return res; }
int main() { int i = pantheios_init(); if(i >= 0) { /* 1. Using the Pantheios API macro PANTHEIOS_MAKE_EXTENDED_SEVERITY() */ pantheios_logprintf(PANTHEIOS_MAKE_EXTENDED_SEVERITY(PANTHEIOS_SEV_NOTICE, 10), PANTHEIOS_LITERAL_STRING("hello")); /* 2 (a). In your code, you'd define your own, most succinct, symbol, e.g. ACME_XSEV(sev, xi28) */ #define ACME_XSEV(sev, xi28) PANTHEIOS_MAKE_EXTENDED_SEVERITY(PANTHEIOS_SEV_ ## sev, xi28) /* 2 (b). and use it as follows */ pantheios_logprintf(ACME_XSEV(NOTICE, 10), PANTHEIOS_LITERAL_STRING("hello")); pantheios_uninit(); } return EXIT_SUCCESS; }
int main() { /* Must initialise Pantheios, when using from C (and there are no C++ * compilation units in the link-unit). * * If this is not done, undefined behaviour will ensue ... */ if(pantheios_init() < 0) { return EXIT_FAILURE; } else { pantheios_logputs(PANTHEIOS_SEV_DEBUG, PANTHEIOS_LITERAL_STRING("debug")); pantheios_logputs(PANTHEIOS_SEV_INFORMATIONAL, PANTHEIOS_LITERAL_STRING("info")); pantheios_logputs(PANTHEIOS_SEV_NOTICE, PANTHEIOS_LITERAL_STRING("notice")); pantheios_logputs(PANTHEIOS_SEV_WARNING, PANTHEIOS_LITERAL_STRING("warn")); pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-1.log"), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, 1); pantheios_logputs(PANTHEIOS_SEV_ERROR, PANTHEIOS_LITERAL_STRING("error")); pantheios_logputs(PANTHEIOS_SEV_CRITICAL, PANTHEIOS_LITERAL_STRING("critical")); pantheios_logputs(PANTHEIOS_SEV_ALERT, PANTHEIOS_LITERAL_STRING("alert")); pantheios_logputs(PANTHEIOS_SEV_EMERGENCY, PANTHEIOS_LITERAL_STRING("emergency")); pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("file-5.log"), 0, 0, 5); /* Must uninitialise Pantheios. * * pantheios_uninit() must be called once for each successful (>=0) * invocation of pantheios_init(). */ pantheios_uninit(); return EXIT_SUCCESS; } }
int be_fprintf_Context::rawLogEntry( int severity4 , int /* severityX */ , pan_char_t const* entry , size_t cchEntry ) { PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_INTERNAL(severity4 >= 0, "severity must be >= 0"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_INTERNAL(severity4 < 16, "severity must be < 16"); // select the stream: stdout for debug/info/notice; stderr for everything else FILE* const stm = deduce_stm_(severity4); // output return pan_fprintf_(stm, PANTHEIOS_LITERAL_STRING("%.*s\n"), int(cchEntry), entry); }
PANTHEIOS_CALL(PAN_CHAR_T const*) pantheios_fe_getProcessIdentity(void* token) { STLSOFT_SUPPRESS_UNUSED(token); if(0 == s_feInitValue) { XTESTS_FAIL_WITH_QUALIFIER("front-end process identity interrogation", "front-end has not yet been initialised"); } else if(1 != s_feInitValue) { XTESTS_FAIL_WITH_QUALIFIER("front-end process identity interrogation", "front-end has been uninitialised"); } else if(0 != s_beInitValue) { XTESTS_FAIL_WITH_QUALIFIER("front-end process identity interrogation", "back-end has already been initialised"); } return PANTHEIOS_LITERAL_STRING("test.component.core.initialisation_sequence"); }
static void test_1_01(); static void test_1_02(); static void test_1_03(); static void test_1_04(); static void test_1_05(); static void test_1_06(); static void test_1_07(); static void test_1_08(); static void test_1_09(); /* ///////////////////////////////////////////////////////////////////////// * Globals */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.custom_severity"); int main(int argc, char** argv) { int retCode = EXIT_SUCCESS; int verbosity = 2; XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); if(XTESTS_START_RUNNER("test.component.custom_severity", verbosity)) { XTESTS_RUN_CASE(test_1_01); XTESTS_RUN_CASE(test_1_02); XTESTS_RUN_CASE(test_1_03); XTESTS_RUN_CASE(test_1_04); XTESTS_RUN_CASE(test_1_05);
#endif /* PANTHEIOS_USE_WIDE_STRINGS */ /* ///////////////////////////////////////////////////////////////////////// * Forward declarations */ static void test_1_01(); static void test_1_02(); static string_t pan_get_hid_(); /* ////////////////////////////////////////////////////////////////////// */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.util.gethostname"); /* ////////////////////////////////////////////////////////////////////// */ int main(int argc, char** argv) { int retCode = EXIT_SUCCESS; int verbosity = 2; XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); if(XTESTS_START_RUNNER("test.unit.util.gethostname", verbosity)) { XTESTS_RUN_CASE(test_1_01); XTESTS_RUN_CASE(test_1_02);
PANTHEIOS_CALL(int) pantheios_be_WindowsSyslog_parseArgs( size_t numArgs , pan_slice_t* const args , pan_be_WindowsSyslog_init_t* init ) { PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API((NULL != args || 0 == numArgs), "argument pointer must be non-null, or number of arguments must be 0"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(NULL != init, "initialisation structure pointer may not be null"); pantheios_be_WindowsSyslog_getDefaultAppInit(init); // 1. Parse the stock arguments int res = pantheios_be_parseStockArgs(numArgs, args, &init->flags); if(res >= 0) { pan_slice_t address; pan_slice_t port; pan_slice_t facility; // 2.a Parse the custom argument: "address" res = pantheios_be_parseStringArg(numArgs, args, PANTHEIOS_LITERAL_STRING("address"), &address); if(res > 0) { if(address.len > sizeof(init->hostNameBuff) - 1) { res = PANTHEIOS_BE_INIT_RC_ARGUMENT_TOO_LONG; } else { ::memcpy(&init->hostNameBuff[0], address.ptr, sizeof(pan_char_t) * STLSOFT_NUM_ELEMENTS(init->hostNameBuff)); init->hostNameBuff[address.len] = '\0'; init->hostName = &init->hostNameBuff[0]; init->addrSize = 0; } } if(res >= 0) { // 2.b Parse the custom argument: "port" res = pantheios_be_parseStringArg(numArgs, args, PANTHEIOS_LITERAL_STRING("port"), &port); if(res > 0) { char sz[21]; int portNum; ::memcpy(&sz[0], port.ptr, stlsoft::minimum(port.len, sizeof(pan_char_t) * STLSOFT_NUM_ELEMENTS(sz) - 1)); sz[stlsoft::minimum(port.len, STLSOFT_NUM_ELEMENTS(sz) - 1)] = '\0'; portNum = ::atoi(sz); if( portNum > 0 && portNum < 65536) { init->port = static_cast<pan_uint16_t>(portNum); } else { res = PANTHEIOS_BE_INIT_RC_ARGUMENT_OUT_OF_RANGE; } } } if(res >= 0) { // 2.b Parse the custom argument: "facility" res = pantheios_be_parseStringArg(numArgs, args, PANTHEIOS_LITERAL_STRING("facility"), &facility); if(res > 0) { char sz[21]; int facilityNum; ::memcpy(&sz[0], facility.ptr, stlsoft::minimum(facility.len, sizeof(pan_char_t) * STLSOFT_NUM_ELEMENTS(sz) - 1)); sz[stlsoft::minimum(facility.len, STLSOFT_NUM_ELEMENTS(sz) - 1)] = '\0'; facilityNum = ::atoi(sz); if( facilityNum >= 0 && facilityNum < 24) { init->facility = static_cast<pan_uint8_t>(facilityNum); } else { res = PANTHEIOS_BE_INIT_RC_ARGUMENT_OUT_OF_RANGE; } } } } if(res >= 0) { // 2.d Parse the custom argument: "useStderr" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("useStderr"), false, PANTHEIOS_BE_WINDOWSSYSLOG_F_PERROR, &init->flags); } if(res >= 0) { // 2.e Parse the custom argument: "useConsole" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("useConsole"), false, PANTHEIOS_BE_WINDOWSSYSLOG_F_CONS, &init->flags); } if(res >= 0) { // 2.f Parse the custom argument: "showPid" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("showPid"), false, PANTHEIOS_BE_WINDOWSSYSLOG_F_PID, &init->flags); } if(res >= 0) { // 2.g Parse the custom argument: "connectImmediately" res = pantheios_be_parseBooleanArg(numArgs, args, PANTHEIOS_LITERAL_STRING("connectImmediately"), false, PANTHEIOS_BE_WINDOWSSYSLOG_F_NDELAY, &init->flags); } return res; }
#elif defined(PLATFORMSTL_OS_IS_WINDOWS) # include <pantheios/backends/bec.WindowsSyslog.h> #else /* ? OS */ # error Operating system not discriminated #endif /* OS */ /* Standard C header files */ #include <stdlib.h> /* for exit codes */ /* ///////////////////////////////////////////////////////////////////////// * globals */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.c.N"); pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS[] = { { 1, PANTHEIOS_SEV_NOTICE } /* Filters out everything below 'notice' */ , { 2, PANTHEIOS_SEV_DEBUG } /* Allows all severities */ , { 3, PANTHEIOS_SEV_ERROR } /* Allows only 'error', 'critical', 'alert', 'emergency' */ , { 0, PANTHEIOS_SEV_NOTICE } /* Terminates the array; sets the default ceiling to 'notice' */ }; pan_be_N_t PAN_BE_N_BACKEND_LIST[] = { PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_file, 0) , PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_fprintf, 0) , PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_null, 0) #if defined(PLATFORMSTL_OS_IS_UNIX)
/* Standard C Header Files */ #include <stdlib.h> // for exit codes #include <pantheios/util/test/compiler_warnings_suppression.last_include.h> /* ///////////////////////////////////////////////////////////////////////// * Macros */ #define PANTHEIOS_SEV_LEVELS_EQUAL(x, y) XTESTS_TEST_INTEGER_EQUAL(static_cast<int>(x), static_cast<int>(y)) /* ///////////////////////////////////////////////////////////////////////// * Globals */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.levels.dynamic_initialisation"); /* ////////////////////////////////////////////////////////////////////// */ const int debug = ::pantheios::debug; const int informational = ::pantheios::informational; const int notice = ::pantheios::notice; const int warning = ::pantheios::warning; const int error = ::pantheios::error; const int critical = ::pantheios::critical; const int alert = ::pantheios::alert; const int emergency = ::pantheios::emergency; DynamicInit::DynamicInit() : debug (::pantheios::debug) , informational (::pantheios::informational)
* typedefs */ typedef std::basic_string<PAN_CHAR_T> string_t; /* ///////////////////////////////////////////////////////////////////////// * macros */ #define PANTHEIOS_TEST_TIME(buffSize, flags, result, pattern) test_time(__FILE__, __LINE__, buffSize, flags, result, pattern) /* ///////////////////////////////////////////////////////////////////////// * globals */ PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.util.getcurrenttime"); /* ///////////////////////////////////////////////////////////////////////// * forward declarations */ static int test_time(char const* file, int line, size_t cchBuff, int flags, size_t expectedResult, PAN_CHAR_T const* pattern); static string_t translate_pattern(PAN_CHAR_T const* pattern); static void test_unix_0(); static void test_unix_F_USE_SYSTEM_TIME(); static void test_unix_F_HIDE_DATE(); static void test_unix_F_HIDE_TIME(); #if defined(PLATFORMSTL_OS_IS_WINDOWS) static void test_win_0(); static void test_win_F_USE_SYSTEM_TIME();
#include <pantheios/util/test/compiler_warnings_suppression.last_include.h> /* ///////////////////////////////////////////////////////////////////////// * Forward declarations */ static void test_1_01(); static int pan_get_pid_(); /* ////////////////////////////////////////////////////////////////////// */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.inserters.processId"); /* ////////////////////////////////////////////////////////////////////// */ #define PSTR(x) PANTHEIOS_LITERAL_STRING(x) /* ///////////////////////////////////////////////////////////////////////// * Character encoding */ #ifdef PANTHEIOS_USE_WIDE_STRINGS # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_WIDE_STRING_EQUAL #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
#endif /* _MSC_VER) && _DEBUG */ #include <pantheios/util/test/compiler_warnings_suppression.last_include.h> /* ////////////////////////////////////////////////////////////////////// */ #define PSTR(x) PANTHEIOS_LITERAL_STRING(x) /* ///////////////////////////////////////////////////////////////////////// * Globals */ extern "C" { const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("be.N.fail.test"); pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS[] = { { 0, PANTHEIOS_SEV_DEBUG } }; pan_be_N_t PAN_BE_N_BACKEND_LIST[] = { PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_fail, PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE), PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_file, 0), PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_fail, PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE), PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_fprintf, 0), PANTHEIOS_BE_N_TERMINATOR_ENTRY }; } // extern "C"
/* Pantheios header files */ #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS // Faster compilation #include <pantheios/pantheios.hpp> // Pantheios C++ main header /* Standard C/C++ header files */ #include <exception> // for std::exception #include <new> // for std::bad_alloc #include <string> // for std::string #include <stdlib.h> // for exit codes /* ////////////////////////////////////////////////////////////////////// */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.misc.strings"); /* ////////////////////////////////////////////////////////////////////// */ #define PSTR(x) PANTHEIOS_LITERAL_STRING(x) /* ////////////////////////////////////////////////////////////////////// */ typedef std::basic_string<PAN_CHAR_T> string_t; /* ////////////////////////////////////////////////////////////////////// */ static string_t concat(string_t const& s1, string_t const& s2) { return s1 + s2; }
void pointer::construct_() { PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(0 == m_sz[0], "cannot construct if value is non-empty"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(0 == m_len, "cannot construct if length is non-0"); if(static_cast<void const*>(0) == m_value) { static const pan_char_t s_null[] = PANTHEIOS_LITERAL_STRING("(null)"); STLSOFT_STATIC_ASSERT(sizeof(m_sz) >= sizeof(s_null)); ::memcpy(&m_sz[0], &s_null[0], sizeof(s_null)); m_len = STLSOFT_NUM_ELEMENTS(s_null) - 1; } else { pan_char_t szFmt[101]; int width; pan_char_t const* zeroX; pan_char_t const* leadingMinus; pan_char_t const* zeroPad; if(m_minWidth < 0) { width = -m_minWidth; leadingMinus = PANTHEIOS_LITERAL_STRING("-"); } else { width = m_minWidth; leadingMinus = PANTHEIOS_LITERAL_STRING(""); } zeroX = (m_format & fmt::zeroXPrefix) ? PANTHEIOS_LITERAL_STRING("0x") : PANTHEIOS_LITERAL_STRING(""); zeroPad = (m_format & fmt::zeroPad) ? PANTHEIOS_LITERAL_STRING("0") : PANTHEIOS_LITERAL_STRING(""); if( 0 != width && fmt::zeroXPrefix == (m_format & (fmt::zeroXPrefix | fmt::zeroPad))) { // Special case pan_char_t szTemp[23]; // 23 is always big enough, since the width is 21 PANTHEIOS_CONTRACT_ENFORCE_ASSUMPTION(0 == (m_format & fmt::zeroPad)); // Determine ptr-sized integer type #if defined(STLSOFT_COMPILER_IS_GCC) typedef unsigned long intptr_t_; #else /* ? compiler */ typedef stlsoft::int_size_traits<sizeof(void*)>::unsigned_type intptr_t_; #endif /* compiler */ int r = pantheios_util_snprintf( &szTemp[0] , STLSOFT_NUM_ELEMENTS(szTemp) , PANTHEIOS_LITERAL_STRING("0x%lx") , static_cast<intptr_t_>(stlsoft::union_cast<intptr_t_>(m_value)) ); if(r < 0) { return; } else { size_t n = static_cast<size_t>(r); PANTHEIOS_CONTRACT_ENFORCE_POSTCONDITION_RETURN_INTERNAL((n + 2) <= STLSOFT_NUM_ELEMENTS(szTemp), "snprintf() overwrote the local buffer capacity"); width += 2; if(static_cast<size_t>(width) > n) { if(m_minWidth < 0) { PANTHEIOS_char_copy(&m_sz[0], szTemp, n); std::fill_n(&m_sz[0] + n, size_t(width - n), ' '); m_sz[width] = '\0'; } else { std::fill_n(&m_sz[0], size_t(width - n), ' '); PANTHEIOS_char_copy(&m_sz[0] + (size_t(width) - n), szTemp, (n + 1)); } m_len = static_cast<size_t>(width); } else { PANTHEIOS_char_copy(&m_sz[0], szTemp, (n + 1)); m_len = n; } } } else { pantheios_util_snprintf(&szFmt[0] , STLSOFT_NUM_ELEMENTS(szFmt) , PANTHEIOS_LITERAL_STRING("%s%%%s%s%dx") , zeroX , leadingMinus , zeroPad , width); m_len = static_cast<size_t>(pantheios_util_snprintf(&m_sz[0], STLSOFT_NUM_ELEMENTS(m_sz), szFmt, m_value)); } } PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(0 != m_sz[0], "failed to set value to non-empty"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(m_len > 0, "failed to set length"); PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(m_len < 23, "pantheios::pointer string too long"); }
#include <exception> // for std::exception #include <new> // for std::bad_alloc #include <string> // for std::string #include <stdlib.h> // for exit codes #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION # if defined(STLSOFT_COMPILER_IS_MSVC) # pragma warning(disable : 4702) # endif /* compiler */ #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */ /* ////////////////////////////////////////////////////////////////////// */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.inserter.threadid"); /* ////////////////////////////////////////////////////////////////////// */ #define PSTR(x) PANTHEIOS_LITERAL_STRING(x) /* ////////////////////////////////////////////////////////////////////// */ int main() { try { // Log the thread Id; Output: "thread id: [3540]" pantheios::log_NOTICE(PSTR("thread id: ["), pantheios::threadId, PSTR("]"));
#include <pantheios/frontends/stock.h> PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.C.args.implicit_main"); /* ///////////////////////////// end of file //////////////////////////// */
static void test_unix_F_HIDE_TIME() { const int timeFlags = PANTHEIOS_GETCURRENTTIME_F_USE_UNIX_FORMAT | 0 | PANTHEIOS_GETCURRENTTIME_F_HIDE_TIME | 0; PANTHEIOS_TEST_TIME( 0, timeFlags, 6, PANTHEIOS_LITERAL_STRING("")); PANTHEIOS_TEST_TIME( 1, timeFlags, 1, PANTHEIOS_LITERAL_STRING("[ADFJMNOS]")); PANTHEIOS_TEST_TIME( 2, timeFlags, 2, PANTHEIOS_LITERAL_STRING("[ADFJMNOS][abceglnoprtuvy]")); PANTHEIOS_TEST_TIME( 3, timeFlags, 3, PANTHEIOS_LITERAL_STRING("?<Mon>")); PANTHEIOS_TEST_TIME( 4, timeFlags, 4, PANTHEIOS_LITERAL_STRING("?<Mon> ")); PANTHEIOS_TEST_TIME( 5, timeFlags, 5, PANTHEIOS_LITERAL_STRING("?<Mon> <D>")); PANTHEIOS_TEST_TIME( 6, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME( 7, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME( 8, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME( 9, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(10, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(11, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(12, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(13, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(14, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(15, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(16, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(16, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(17, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(18, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(19, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(20, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(100, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); PANTHEIOS_TEST_TIME(1000, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<Mon> <DD>")); }
static void test_unix_F_HIDE_DATE() { const int timeFlags = PANTHEIOS_GETCURRENTTIME_F_USE_UNIX_FORMAT | 0 | PANTHEIOS_GETCURRENTTIME_F_HIDE_DATE | 0; PANTHEIOS_TEST_TIME( 0, timeFlags, 8, PANTHEIOS_LITERAL_STRING("")); PANTHEIOS_TEST_TIME( 1, timeFlags, 1, PANTHEIOS_LITERAL_STRING("?<D>")); PANTHEIOS_TEST_TIME( 2, timeFlags, 2, PANTHEIOS_LITERAL_STRING("?<DD>")); PANTHEIOS_TEST_TIME( 3, timeFlags, 3, PANTHEIOS_LITERAL_STRING("?<DD>:")); PANTHEIOS_TEST_TIME( 4, timeFlags, 4, PANTHEIOS_LITERAL_STRING("?<DD>:<D>")); PANTHEIOS_TEST_TIME( 5, timeFlags, 5, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>")); PANTHEIOS_TEST_TIME( 6, timeFlags, 6, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:")); PANTHEIOS_TEST_TIME( 7, timeFlags, 7, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<D>")); PANTHEIOS_TEST_TIME( 8, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME( 9, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(10, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(11, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(12, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(13, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(14, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(15, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(16, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(16, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(17, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(18, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(19, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(20, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(100, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); PANTHEIOS_TEST_TIME(1000, timeFlags, 8, PANTHEIOS_LITERAL_STRING("?<DD>:<DD>:<DD>")); }
#endif /* __WATCOMC__ */ /* Standard C header files */ #include <stdio.h> #include <stdlib.h> #if defined(_MSC_VER) && \ defined(_DEBUG) # include <crtdbg.h> #endif /* _MSC_VER) && _DEBUG */ /* ///////////////////////////////////////////////////////////////////////// * Globals */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.tstring"); /* ////////////////////////////////////////////////////////////////////// */ static int main_(int /* argc */, char** /*argv*/) { std::string mbs("multibyte string"); std::wstring ws1(L"wide string #1"); stlsoft::simple_wstring ws2(L"wide string #2"); pan::log_NOTICE("mbs=", mbs, ", ws1=", pan::w2m(ws1), ", ws2=", pan::w2m(ws2)); #ifdef PANTHEIOS_SAFE_ALLOW_SHIM_INTERMEDIATES VARIANT var; var.vt = VT_I4;
#include <stdlib.h> /* ///////////////////////////////////////////////////////////////////////// * Compiler compatibility */ #ifdef STLSOFT_COMPILER_IS_BORLAND # pragma warn -8008 # pragma warn -8066 #endif /* ////////////////////////////////////////////////////////////////////// */ /* Define the stock front-end process identity, so that it links when using * fe.N, fe.simple, etc. */ const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.c.extended_severity"); /* ////////////////////////////////////////////////////////////////////// */ int main() { int i = pantheios_init(); if(i >= 0) { /* 1. Using the Pantheios API macro PANTHEIOS_MAKE_EXTENDED_SEVERITY() */ pantheios_logprintf(PANTHEIOS_MAKE_EXTENDED_SEVERITY(PANTHEIOS_SEV_NOTICE, 10), PANTHEIOS_LITERAL_STRING("hello")); /* 2 (a). In your code, you'd define your own, most succinct, symbol, e.g. ACME_XSEV(sev, xi28) */ #define ACME_XSEV(sev, xi28) PANTHEIOS_MAKE_EXTENDED_SEVERITY(PANTHEIOS_SEV_ ## sev, xi28)
/* STLSoft Header Files */ #include <platformstl/synch/sleep_functions.h> /* Standard C/C++ Header Files */ #include <exception> // for std::exception #include <string> // for std::string #include <stdio.h> // for fprintf() #include <stdlib.h> // for exit codes #include <string.h> // for memset() #include <pantheios/util/test/compiler_warnings_suppression.last_include.h> /* ////////////////////////////////////////////////////////////////////// */ // Define the fe.simple process identity, so that it links when using fe.simple PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.be.WindowsSyslog"); /* ///////////////////////////////////////////////////////////////////////// * Application-defined functions */ PANTHEIOS_CALL(void) pantheios_be_WindowsSyslog_getAppInit( int backEndId , pan_be_WindowsSyslog_init_t* init ) throw() { init->addrSize = 0; init->hostName = "127.0.0.1"; } /* ////////////////////////////////////////////////////////////////////// */
static void test_1_01(); static void test_1_02(); static void test_1_03(); static void test_1_04(); static void test_1_05(); static void test_1_06(); static void test_1_07(); static void test_1_08(); static void test_1_09(); /* ///////////////////////////////////////////////////////////////////////// * Globals */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.core.pantheios_logprintf"); static const int s_severities[] = { PANTHEIOS_SEV_DEBUG , PANTHEIOS_SEV_INFORMATIONAL , PANTHEIOS_SEV_NOTICE , PANTHEIOS_SEV_WARNING , PANTHEIOS_SEV_ERROR , PANTHEIOS_SEV_CRITICAL , PANTHEIOS_SEV_ALERT , PANTHEIOS_SEV_EMERGENCY }; /* ///////////////////////////////////////////////////////////////////////// * main
static void test_1_03(); static void test_highbit_hexadecimal_codes_DWORD(); static void test_1_05(); static void test_1_06(); static void test_1_07(); static void test_1_08(); static void test_1_09(); static void test_1_10(); static void test_1_11(); static void test_1_12(); } // anonymous namespace /* ////////////////////////////////////////////////////////////////////// */ PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.inserters.windows.sc"); /* ////////////////////////////////////////////////////////////////////// */ int main(int argc, char** argv) { int retCode = EXIT_SUCCESS; int verbosity = 2; XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); if(XTESTS_START_RUNNER("test.unit.inserters.windows.sc", verbosity)) { XTESTS_RUN_CASE(test_regular_decimal_codes_DWORD); XTESTS_RUN_CASE(test_1_02); XTESTS_RUN_CASE(test_1_03);
/* Standard C++ Header Files */ #include <exception> /* Standard C Header Files */ #include <stdlib.h> #if defined(_MSC_VER) && \ defined(_DEBUG) # include <crtdbg.h> #endif /* _MSC_VER) && _DEBUG */ /* ///////////////////////////////////////////////////////////////////////// * Globals */ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.bec.WindowsConsoleCallback"); /* ////////////////////////////////////////////////////////////////////// */ PANTHEIOS_CALL(void) pantheios_be_WindowsConsole_getAppInit(int backEndId, pan_be_WindowsConsole_init_t *init) /* throw() */ { init->flags |= PANTHEIOS_BE_INIT_F_NO_PROCESS_ID; init->flags |= PANTHEIOS_BE_INIT_F_NO_DATETIME; init->flags |= PANTHEIOS_BE_INIT_F_NO_SEVERITY; init->flags |= PANTHEIOS_BE_INIT_F_USE_SYSTEM_TIME; // init->flags |= PANTHEIOS_BE_WINDOWSCONSOLE_F_NO_COLOURS; } static int main_(int /* argc */, char** /*argv*/) {