2 Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License in the COPYING file at the
14 root directory of this project for more details.
23 bool IsHexData(const char *str
)
25 for( int i
= 0; i
< 4 && *str
; str
++, i
++ )
29 for( int i
= 0; i
< 8 && *str
; str
++, i
++ )
30 if( !isdigit(*str
) && !(*str
>= 'a' && *str
<= 'f') )
39 void PrintHex(const char *str
)
42 ios::fmtflags flags = cout.setf(ios::right);
43 streamsize width = cout.width(14 + 16 * 3 + 1);
48 cout
<< setiosflags(ios::left
) << setw(14 + 16 * 3 + 1) << str
;
51 char *endpos
= (char*) str
;
53 int c
= (int) strtol(str
, &endpos
, 16);
54 if( c
== LONG_MIN
|| c
== LONG_MAX
)
66 istringstream iss(str+14);
82 cout
.sync_with_stdio(false);
86 cin
.getline(buff
, sizeof(buff
));
87 if( IsHexData(buff
) ) {
89 int sln
= strlen(buff
);
90 while( sln
&& (buff
[sln
] == 0 || isspace(buff
[sln
])) ){
99 if( cin
.fail() && !cin
.eof() ) {
100 // getline busted its buffer... discard the
102 while( cin
.fail() && !cin
.eof() ) {
104 cin
.getline(buff
, sizeof(buff
));