Exemple #1
0
/*
 * outv_nl -- print new line without indentation
 */
void
outv_nl(int vlevel)
{
	if (outv_check(vlevel)) {
		_out_prefix();
		fprintf(out_fh, "\n");
	}
}
Exemple #2
0
/*
 * outv_nl -- print new line without indentation
 */
void
outv_nl(int vlevel)
{
	if (!outv_check(vlevel))
		return;

	_out_prefix();
	fprintf(out_fh, "\n");
}
Exemple #3
0
/*
 * outv_hexdump -- print buffer in canonical hex+ASCII format
 *
 * Print offset in hexadecimal,
 * sixteen space-separated, two column, hexadecimal bytes,
 * followed by the same sixteen bytes converted to printable ASCII characters
 * enclosed in '|' characters.
 */
void
outv_hexdump(int vlevel, const void *addr, size_t len, size_t offset, int sep)
{
	if (!outv_check(vlevel) || len <= 0)
		return;

	const uint8_t *datap = (uint8_t *)addr;
	uint8_t row_hex_str[HEXDUMP_ROW_HEX_LEN] = {0, };
	uint8_t row_ascii_str[HEXDUMP_ROW_ASCII_LEN] = {0, };
	size_t curr = 0;
	size_t prev = 0;
	int repeated = 0;
	int n = 0;

	while (len) {
		size_t curr_len = min(len, HEXDUMP_ROW_WIDTH);

		/*
		 * Check if current row is the same as the previous one
		 * don't check it for first and last rows.
		 */
		if (len != curr_len && curr &&
				!memcmp(datap + prev, datap + curr, curr_len)) {
			if (!repeated) {
				/* print star only for the first repeated */
				fprintf(out_fh, "*\n");
				repeated = 1;
			}
		} else {
			repeated = 0;

			/* row with hexadecimal bytes */
			int rh = out_get_hex_str((char *)row_hex_str,
				HEXDUMP_ROW_HEX_LEN, datap + curr, curr_len);
			/* row with printable ascii chars */
			int ra = out_get_ascii_str((char *)row_ascii_str,
				HEXDUMP_ROW_ASCII_LEN, datap + curr, curr_len);

			if (ra && rh)
				n = fprintf(out_fh, "%08zx  %-*s|%-*s|\n",
					curr + offset,
					HEXDUMP_ROW_HEX_LEN, row_hex_str,
					HEXDUMP_ROW_WIDTH, row_ascii_str);
			prev = curr;
		}

		len -= curr_len;
		curr += curr_len;
	}

	if (sep && n) {
		while (--n)
			fprintf(out_fh, "%c", SEPARATOR_CHAR);
		fprintf(out_fh, "\n");
	}
}
Exemple #4
0
/*
 * outv -- print message taking into account verbosity level
 */
void
outv(int vlevel, const char *fmt, ...)
{
	va_list ap;

	if (outv_check(vlevel)) {
		_out_prefix();
		_out_indent();
		va_start(ap, fmt);
		vfprintf(out_fh, fmt, ap);
		va_end(ap);
	}
}
Exemple #5
0
void
outv_title(int vlevel, const char *fmt, ...)
{
	va_list ap;
	if (!outv_check(vlevel))
		return;

	fprintf(out_fh, "\n");
	_out_prefix();
	_out_indent();
	va_start(ap, fmt);
	vfprintf(out_fh, fmt, ap);
	va_end(ap);
	fprintf(out_fh, ":\n");
}
Exemple #6
0
/*
 * outv_indent -- change indentation level by factor
 */
void
outv_indent(int vlevel, int i)
{
	if (!outv_check(vlevel))
		return;

	out_indent_str[out_indent_level] = INDENT_CHAR;
	out_indent_level += i;
	if (out_indent_level < 0)
		out_indent_level = 0;
	if (out_indent_level > MAX_INDENT)
		out_indent_level = MAX_INDENT;

	out_indent_str[out_indent_level] = '\0';
}
Exemple #7
0
/*
 * outv_field -- print field name and value in specified format
 *
 * Field name will have fixed width which can be changed by
 * out_set_column_width() function.
 * vlevel - verbosity level
 * field  - field name
 * fmt    - format form value
 */
void
outv_field(int vlevel, const char *field, const char *fmt, ...)
{
	va_list ap;

	if (outv_check(vlevel)) {
		_out_prefix();
		_out_indent();
		va_start(ap, fmt);
		fprintf(out_fh, "%-*s : ", out_column_width, field);
		vfprintf(out_fh, fmt, ap);
		fprintf(out_fh, "\n");
		va_end(ap);
	}
}