⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log-hexdump.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
#include <ctype.h>#include <stdio.h>#include <string.h>#include <glib.h>void log_hexdump(const char *log_domain, GLogLevelFlags log_level, const void *data, int count) {    char hex[60];    char ascii[20];    int byte, hex_dst, ascii_dst;    // FIXME    // if (! lp_should_logprint(lp, msg_level)) return;    hex_dst = 0;    ascii_dst = 0;    for (byte = 0; byte < count; byte ++) {        sprintf(&hex[hex_dst], "%02X ", ((unsigned char *)data)[byte]);        hex_dst += 3;        if (isprint(((unsigned char *)data)[byte])) {            sprintf(&ascii[ascii_dst], "%c", ((unsigned char *)data)[byte]);        } else {            sprintf(&ascii[ascii_dst], ".");        }        ascii_dst ++;        if (byte % 16 == 15) {            g_log(log_domain, log_level, "    %s |%s|", hex, ascii);            hex_dst = 0;            ascii_dst = 0;        } else if (byte % 8 == 7) {            sprintf(&hex[hex_dst], " ");            hex_dst ++;            sprintf(&ascii[ascii_dst], " ");            ascii_dst ++;        }    }    if (byte % 16 != 0) {        g_log(log_domain, log_level, "    %-49s |%-17s|", hex, ascii);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -