asoma.dev · the C reference for libose
libose
the C library every o.se host is built on
Loading...
Searching...
No Matches
ose_pprint.c File Reference

Rendering a bundle for a human to read. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "ose.h"
#include "ose_util.h"
#include "ose_stackops.h"
#include "ose_vm.h"
#include "ose_assert.h"
#include "ose_print.h"
#include "ose_pprint.h"
Include dependency graph for ose_pprint.c:

Macros

#define _XOPEN_SOURCE   700
#define _DEFAULT_SOURCE
#define ANSI_COLOR_BLACK   "\033[30m"
#define ANSI_COLOR_RED   "\033[31m"
#define ANSI_COLOR_GREEN   "\033[32m"
#define ANSI_COLOR_YELLOW   "\033[33m"
#define ANSI_COLOR_BLUE   "\033[34m"
#define ANSI_COLOR_MAGENTA   "\033[35m"
#define ANSI_COLOR_CYAN   "\033[36m"
#define ANSI_COLOR_WHITE   "\033[37m"
#define ANSI_COLOR_BRIGHT_BLACK   "\033[1;30m"
#define ANSI_COLOR_BRIGHT_RED   "\033[1;31m"
#define ANSI_COLOR_BRIGHT_GREEN   "\033[1;32m"
#define ANSI_COLOR_BRIGHT_YELLOW   "\033[1;33m"
#define ANSI_COLOR_BRIGHT_BLUE   "\033[1;34m"
#define ANSI_COLOR_BRIGHT_MAGENTA   "\033[1;35m"
#define ANSI_COLOR_BRIGHT_CYAN   "\033[1;36m"
#define ANSI_COLOR_BRIGHT_WHITE   "\033[1;37m"
#define ANSI_COLOR_RESET   "\033[0m"
#define COLOR_ADDRESS   ANSI_COLOR_BRIGHT_CYAN
#define COLOR_TYPETAGS   ANSI_COLOR_BRIGHT_CYAN
#define COLOR_RESET   ANSI_COLOR_RESET
#define SEPARATOR   ':'
#define INCP(bufp, amt)
#define INCL(bufp, bufl, amt)
#define ose_snprintfi(bufp, bufl, n, total, fmt, ...)

Functions

static int32_t _ose_pprintBundle (ose_bundle bundle, int32_t offset, char *buf, int32_t buflen, int32_t indent)
int32_t ose_pprintMessageAddr (ose_bundle bundle, int32_t offset, int32_t ao, char *buf, int32_t buflen)
int32_t ose_pprintPayloadItem_impl (ose_bundle bundle, const char typetag, const int32_t msg_offset, const int32_t item_offset, char *buf, int32_t buflen)
int32_t ose_pprintPayloadItem_hook (ose_bundle bundle, const char typetag, const int32_t msg_offset, const int32_t item_offset)
static int32_t _pprintPayloadItem (ose_bundle bundle, const char typetag, const int32_t msg_offset, const int32_t item_offset, char *buf, int32_t buflen)
int32_t ose_pprintBundleElem_msg (ose_bundle bundle, int32_t offset, char *buf, int32_t buflen, int32_t indent)
int32_t ose_pprintBundleElem (ose_bundle bundle, int32_t offset, char *buf, int32_t buflen, int32_t indent)
int32_t ose_pprintBundle (ose_bundle bundle, char *buf, int32_t buflen)
static int32_t ose_pprintFullBundle_r (ose_bundle bundle, char *buf, int32_t buflen, int32_t o, int32_t s, int32_t to, int32_t indent)
int32_t ose_pprintFullBundle_impl (ose_bundle bundle, char *buf, int32_t buflen, const char *const name)
void ose_pprintFullBundle (ose_bundle src, ose_bundle dest, const char *const name)
int32_t ose_pprintBytes (const char *const bytes, int32_t n, char *buf, int32_t buflen)
 A packet's bytes as text, a four-byte word to a line: its offset, the bytes in hex, as characters, and as a big-endian int32. Raw bytes, whether or not they are a well-formed packet.

Variables

static const int cols = 80

Detailed Description

Rendering a bundle for a human to read.

Split out of ose_print.c, which was doing three unrelated jobs. Nothing in libose calls anything here – every caller is a host wanting to show a bundle to someone. What remains in ose_print.c is the part libose itself uses: ose_stackops.c converts values to strings, and that is an operation on a bundle rather than a way of displaying one.

The point of the separation is that a build can leave this out. It is roughly 750 lines that a small embedded build has no use for, and until now there was no way to not have it.

Macro Definition Documentation

◆ INCL

#define INCL ( bufp,
bufl,
amt )
Value:
((bufp) ? ((bufl) -= (amt)) : (bufl))

◆ INCP

#define INCP ( bufp,
amt )
Value:
((bufp) ? ((bufp) += (amt)) : (bufp))

◆ ose_snprintfi

#define ose_snprintfi ( bufp,
bufl,
n,
total,
fmt,
... )
Value:
{ \
int32_t n = snprintf(bufp, bufl, fmt, __VA_ARGS__); \
if(bufp){ \
bufp += n; \
} \
if(bufl >= n){ \
bufl -= n; \
}else{ \
bufl = 0; \
} \
total += n; \
}

Function Documentation

◆ ose_pprintBytes()

int32_t ose_pprintBytes ( const char *const bytes,
int32_t n,
char * buf,
int32_t buflen )

A packet's bytes as text, a four-byte word to a line: its offset, the bytes in hex, as characters, and as a big-endian int32. Raw bytes, whether or not they are a well-formed packet.

Parameters
bytesThe bytes.
nHow many.
bufWhere to write, or NULL to measure.
buflenRoom in buf, including the terminator.
Returns
The length the whole text wants, as snprintf() returns it.