2 // ktrans.cc - print human readable version of usbfs_snoop kernel log
6 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU General Public License in the COPYING file at the
18 root directory of this project for more details.
26 #include <barry/data.h>
33 cout
<< "ktrans - usbfs_snoop kernel log translator\n"
35 "\tUsage: ktrans logmarker < log\n"
37 "\tExample: ktrans \"kernel: \" < /var/log/kern.log\n"
41 bool IsHexData(const char *logmarker
, const char *str
)
43 str
= strstr(str
, logmarker
);
46 str
+= strlen(logmarker
);
48 if( strstr(str
, "data ") || strstr(str
, "data: ") ) {
49 // looks like a data line, make sure data from there on out
53 str
= strstr(str
, "data") + 4;
54 for( ; *str
== ':' || *str
== ' '; str
++ )
58 if( !( isdigit(*str
) || *str
== ' ' ||
59 (*str
>= 'a' && *str
<= 'f')) )
68 if( !( isdigit(*str
) || *str
== ' ' ||
69 (*str
>= 'a' && *str
<= 'f')) )
73 return true; // all data is numeric, so this is a continuation line
77 void SplitHex(const char *logmarker
, const char *str
, Barry::Data
&data
)
79 const char *hexptr
= strstr(str
, logmarker
);
84 hexptr
+= strlen(logmarker
);
85 std::string
readable(str
, hexptr
- str
);
89 hexptr
= strstr(str
, "data ");
94 hexptr
= strstr(str
, "data: ");
102 for( ; *hexptr
== ':' || *hexptr
== ' '; hexptr
++ )
105 readable
.append(str
, hexptr
- str
);
106 cout
<< readable
<< endl
;
108 data
.AppendHexString(hexptr
);
111 int main(int argc
, char *argv
[])
115 cout
.sync_with_stdio(false);
126 if( IsHexData(argv
[1], buff
.c_str()) ) {
127 SplitHex(argv
[1], buff
.c_str(), data
);
130 if( data
.GetSize() ) {
134 cout
<< buff
<< "\n";
138 if( data
.GetSize() ) {