-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecudump.c
207 lines (190 loc) · 4.56 KB
/
ecudump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*+-----------------------------------------------------------------------
ecudump.c -- very generic hex/graphics dump development aid
wht@wht.net
Defined functions:
dump_putc(ch)
dump_puts(str)
hex_dump(str, len, title, terse_flag)
hex_dump16(int16)
hex_dump32(int32)
hex_dump4(int4)
hex_dump8(int8)
hex_dump_fp(fp, str, len, title, terse_flag)
------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
/*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
/*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
/*:11-28-1995-20:09-wht@kepler-bug in last line space fill */
/*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
/*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
/*:11-10-1995-14:56-root@kepler-extend ASCII graphics for len>16 eve if terse */
/*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
/*:08-07-1993-16:09-wht@n4hgf-fix old bug in hex_dump_fp */
/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
#include "ecu.h"
FILE *dumpfp;
/*+-------------------------------------------------------------------------
dump_putc(ch)
--------------------------------------------------------------------------*/
void
dump_putc(ch)
char ch;
{
if (dumpfp == stderr)
pputc(ch);
else
fputc(ch, dumpfp);
} /* end of dump_putc */
/*+-------------------------------------------------------------------------
dump_puts(str)
--------------------------------------------------------------------------*/
void
dump_puts(str)
char *str;
{
if (dumpfp == stderr)
pputs(str);
else
fputs(str, dumpfp);
} /* end of dump_puts */
/*+-----------------------------------------------------------------------
hex_dump#... subservient routines
------------------------------------------------------------------------*/
void
hex_dump4(int4)
uchar int4;
{
int4 &= 15;
dump_putc((int4 >= 10) ? (int4 + 'A' - 10) : (int4 + '0'));
}
void
hex_dump8(int8)
uchar int8;
{
hex_dump4(int8 >> 4);
hex_dump4(int8);
}
void
hex_dump16(int16)
UINT16 int16;
{
hex_dump8(int16 >> 8);
hex_dump8(int16);
}
void
hex_dump32(int32)
UINT32 int32;
{
hex_dump16(int32 >> 16);
hex_dump16(int32);
}
/*+-----------------------------------------------------------------
hex_dump_fp(fp,str,len,title,terse_flag)
if 'title' not NULL, title is printed... 'terse_flag'
controls whether or not the title is "conspicuous" with
hyphens before and after it making title line >70 chars long
If len negative, print no buffer offsets.
------------------------------------------------------------------*/
void
hex_dump_fp(fp, str, len, title, terse_flag)
FILE *fp;
char *str;
int len;
char *title;
int terse_flag;
{
int ipos = 0;
int itmp;
int istr;
int print_offset = (len > 32);
dumpfp = fp;
if (title && (istr = strlen(title)))
{
if (!terse_flag)
{
ipos = (((print_offset) ? 73 : 67) - istr) / 2;
itmp = ipos;
while (itmp--)
dump_putc('-');
dump_putc(' ');
if (istr & 1)
ipos--;
}
dump_puts(title);
if (!terse_flag)
{
dump_putc(' ');
while (ipos--)
dump_putc('-');
}
if (terse_flag && (len < 12))
dump_putc(' ');
else
{
if (dumpfp == stderr)
dump_puts("\r\n");
else
dump_puts("\n");
}
}
istr = 0;
while (istr < len)
{
if (print_offset)
{
hex_dump16(istr);
dump_puts(" ");
}
for (itmp = 0; itmp < 16; ++itmp)
{
ipos = istr + itmp;
if (ipos >= len)
{
if (!terse_flag || (len > 16))
dump_puts(" ");
continue;
}
if (itmp)
dump_putc(' ');
hex_dump8(str[ipos]);
}
dump_puts(" | ");
for (itmp = 0; itmp < 16; ++itmp)
{
ipos = istr + itmp;
if ((ipos) >= len)
{
if (!terse_flag)
dump_putc(' ');
}
else
{
dump_putc((str[ipos] >= ' ' && str[ipos] < 0x7f)
? str[ipos] : '.');
}
}
if (dumpfp == stderr)
dump_puts(" |\r\n");
else
dump_puts(" |\n");
istr += 16;
} /* end of while(istr < len) */
} /* end of hex_dump_fp */
/*+-------------------------------------------------------------------------
hex_dump(str,len,title,terse_flag)
--------------------------------------------------------------------------*/
void
hex_dump(str, len, title, terse_flag)
char *str;
int len;
char *title;
int terse_flag;
{
hex_dump_fp(stderr, str, len, title, terse_flag);
} /* end of hex_dump_fp */
/* end of ecudump.c */
/* vi: set tabstop=4 shiftwidth=4: */