1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11
12#
13# Copyright (c) 2013 Joyent, Inc.  All rights reserved.
14#
15
16let width=8
17
18function outputchar
19{
20	banner $3 | /bin/nawk -v line=$1 -v pos=$2 -v width=$width '{ \
21		for (i = 1; i <= length($0); i++) { \
22			if (substr($0, i, 1) == " ") \
23				continue; \
24			printf("\t@letter%d[%d] = lquantize(%d, 0, 40, 1);\n", \
25			    line, NR, i + (pos * width));
26		} \
27	}'
28}
29
30function outputstr
31{
32	let pos=0;
33	let line=0
34
35	printf "#pragma D option aggpack\n#pragma D option aggsortkey\n"
36
37	printf "BEGIN\n{\n"
38	for c in `echo "$1" | /bin/nawk '{ \
39		for (i = 1; i <= length($0); i++) { \
40			c = substr($0, i, 1); \
41			printf("%s\n", c == " " ? "space" : \
42			    c == "\n" ? "newline" : c); \
43		} \
44	}'`; do
45		if [[ "$c" == "space" ]]; then
46			let line=line+1
47			let pos=0
48			continue
49		fi
50
51		outputchar $line $pos $c
52		let pos=pos+1
53	done
54
55	let i=0
56
57	while [[ $i -le $line ]]; do
58		printf "\tprinta(@letter%d);\n" $i
59		let i=i+1
60	done
61	printf "\texit(0);\n}\n"
62}
63
64dtrace -qs /dev/stdin -x encoding=utf8 <<EOF
65`outputstr "why must i do this"`
66EOF
67
68dtrace -qs /dev/stdin -x encoding=ascii -x aggzoom <<EOF
69`outputstr "i am not well"`
70EOF
71
72dtrace -qs /dev/stdin -x encoding=utf8 -x aggzoom <<EOF
73`outputstr "send help"`
74EOF
75
76