2 Copyright (C) 2005-2010, 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.
27 bool IsHexData(const char *str
)
29 for( int i
= 0; i
< 4 && *str
; str
++, i
++ )
33 for( int i
= 0; i
< 8 && *str
; str
++, i
++ )
34 if( !isdigit(*str
) && !(*str
>= 'a' && *str
<= 'f') )
43 void PrintHex(const char *str
)
45 cout
<< setiosflags(ios::left
) << setw(14 + 16 * 3 + 1) << str
;
48 char *endpos
= (char*) str
;
50 long c
= strtol(str
, &endpos
, 16);
51 if( c
== LONG_MIN
|| c
== LONG_MAX
)
66 cout
.sync_with_stdio(false);
70 cin
.getline(buff
, sizeof(buff
));
71 if( IsHexData(buff
) ) {
73 size_t sln
= strlen(buff
);
74 while( sln
&& (buff
[sln
] == 0 || isspace(buff
[sln
])) ){
83 if( cin
.fail() && !cin
.eof() ) {
84 // getline busted its buffer... discard the
86 while( cin
.fail() && !cin
.eof() ) {
88 cin
.getline(buff
, sizeof(buff
));