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
)
41 cout
<< setiosflags(ios::left
) << setw(14 + 16 * 3 + 1) << str
;
44 char *endpos
= (char*) str
;
46 int c
= (int) strtol(str
, &endpos
, 16);
47 if( c
== LONG_MIN
|| c
== LONG_MAX
)
60 cout
.sync_with_stdio(false);
64 cin
.getline(buff
, sizeof(buff
));
65 if( IsHexData(buff
) ) {
67 int sln
= strlen(buff
);
68 while( sln
&& (buff
[sln
] == 0 || isspace(buff
[sln
])) ){
77 if( cin
.fail() && !cin
.eof() ) {
78 // getline busted its buffer... discard the
80 while( cin
.fail() && !cin
.eof() ) {
82 cin
.getline(buff
, sizeof(buff
));