static void _bt_log_write_imp( const bt_log_spec *log, const src_location *const src, const mem_block *const mem, const int lvl, const char *const tag, const char *const fmt, va_list va) { bt_log_message msg; char buf[BT_LOG_BUF_SZ]; const unsigned mask = log->output->mask; msg.lvl = lvl; msg.tag = tag; g_buffer_cb(&msg, buf); const char *rst_color_p = bt_common_color_reset(); const char *rst_color_e = rst_color_p + strlen(rst_color_p); const char *color_p = ""; const char *color_e = color_p; switch (lvl) { case BT_LOG_INFO: color_p = bt_common_color_fg_blue(); color_e = color_p + strlen(color_p); break; case BT_LOG_WARN: color_p = bt_common_color_fg_yellow(); color_e = color_p + strlen(color_p); break; case BT_LOG_ERROR: case BT_LOG_FATAL: color_p = bt_common_color_fg_red(); color_e = color_p + strlen(color_p); break; default: break; } msg.p = put_stringn(color_p, color_e, msg.p, msg.e); if (BT_LOG_PUT_CTX & mask) { put_ctx(&msg); } if (BT_LOG_PUT_TAG & mask) { put_tag(&msg, tag); } if (0 != src && BT_LOG_PUT_SRC & mask) { put_src(&msg, src); } if (BT_LOG_PUT_MSG & mask) { put_msg(&msg, fmt, va); } msg.p = put_stringn(rst_color_p, rst_color_e, msg.p, msg.e); log->output->callback(&msg, log->output->arg); if (0 != mem && BT_LOG_PUT_MSG & mask) { output_mem(log, &msg, mem); } }
static void put_ctx(bt_log_message *const msg) { _PP_MAP(_BT_LOG_MESSAGE_FORMAT_INIT, BT_LOG_MESSAGE_CTX_FORMAT) #if !_BT_LOG_MESSAGE_FORMAT_FIELDS(BT_LOG_MESSAGE_CTX_FORMAT) VAR_UNUSED(msg); #else #if _BT_LOG_MESSAGE_FORMAT_DATETIME_USED struct tm tm; unsigned msec; g_time_cb(&tm, &msec); #endif #if _BT_LOG_MESSAGE_FORMAT_CONTAINS(PID, BT_LOG_MESSAGE_CTX_FORMAT) || \ _BT_LOG_MESSAGE_FORMAT_CONTAINS(TID, BT_LOG_MESSAGE_CTX_FORMAT) int pid, tid; g_pid_cb(&pid, &tid); #endif #if BT_LOG_OPTIMIZE_SIZE int n; n = snprintf(msg->p, nprintf_size(msg), _PP_MAP(_BT_LOG_MESSAGE_FORMAT_PRINTF_FMT, BT_LOG_MESSAGE_CTX_FORMAT) _PP_MAP(_BT_LOG_MESSAGE_FORMAT_PRINTF_VAL, BT_LOG_MESSAGE_CTX_FORMAT)); put_nprintf(msg, n); #else char buf[64]; char *const e = buf + sizeof(buf); char *p = e; _PP_RMAP(_BT_LOG_MESSAGE_FORMAT_PUT_R, BT_LOG_MESSAGE_CTX_FORMAT) msg->p = put_stringn(p, e, msg->p, msg->e); #endif #endif }
static INLINE char *put_uint(unsigned v, const unsigned w, const char wc, char *const p, char *const e) { char buf[16]; char *const se = buf + _countof(buf); char *sp = put_uint_r(v, w, wc, se); return put_stringn(sp, se, p, e); }
int main(void){ char str[128]; int c; printf("文字列を入力してください:"); scanf("%s",str); printf("何回連続して表示しますか:"); scanf("%d", &c); put_stringn(str, c); return 0; }
static void put_ctx(zf_log_message *const msg) { struct tm tm; unsigned msec; int pid, tid; g_time_cb(&tm, &msec); g_pid_cb(&pid, &tid); #if ZF_LOG_OPTIMIZE_SIZE int n; n = snprintf(msg->p, nprintf_size(msg), "%02u-%02u %02u:%02u:%02u.%03u %5i %5i %c ", (unsigned)(tm.tm_mon + 1), (unsigned)tm.tm_mday, (unsigned)tm.tm_hour, (unsigned)tm.tm_min, (unsigned)tm.tm_sec, (unsigned)msec, pid, tid, (char)lvl_char(msg->lvl)); put_nprintf(msg, n); #else char buf[64]; char *const e = buf + sizeof(buf); char *p = e; *--p = ' '; *--p = lvl_char(msg->lvl); *--p = ' '; p = put_int_r(tid, 5, ' ', p); *--p = ' '; p = put_int_r(pid, 5, ' ', p); *--p = ' '; p = put_uint_r(msec, 3, '0', p); *--p = '.'; p = put_uint_r(tm.tm_sec, 2, '0', p); *--p = ':'; p = put_uint_r(tm.tm_min, 2, '0', p); *--p = ':'; p = put_uint_r(tm.tm_hour, 2, '0', p); *--p = ' '; p = put_uint_r(tm.tm_mday, 2, '0', p); *--p = '-'; p = put_uint_r(tm.tm_mon + 1, 2, '0', p); msg->p = put_stringn(p, e, msg->p, msg->e); #endif }