tidy.c
1 |
/*tidy.c -- clean up the .tsv output from tshark for a serial-over-USB
|
---|---|
2 |
session. input from stdin, output to stdout. |
3 |
|
4 |
Copyright (c) 2019 Dan Clemmensen, licensed to you under GPL v3. |
5 |
|
6 |
input lines: |
7 |
source\tinfo\tdata\n |
8 |
for each line: |
9 |
get dirchar (first char of source is 'h' or not), |
10 |
get bulk char (fourth char of info is 'B' or not), |
11 |
get start of data |
12 |
If dir changed, |
13 |
print existing buffer and start a new one |
14 |
remove the colons from the data and append to buffer |
15 |
at end, print buffer |
16 |
|
17 |
output line starts with '<' or '>' for direction, followed by the hex chars |
18 |
sent or received. |
19 |
*/ |
20 |
#include <strings.h> |
21 |
#include <string.h> |
22 |
#include <stdio.h> |
23 |
#include <stdlib.h> |
24 |
|
25 |
static char separator = '\t'; |
26 |
|
27 |
|
28 |
|
29 |
int main()
|
30 |
{ |
31 |
char buff[1000]; |
32 |
char *inpt=buff;
|
33 |
size_t buflen=1000;
|
34 |
int len;
|
35 |
char outbuff[1000]; |
36 |
int dir=2; //2= unknown, 1=from host, 0= to host |
37 |
int newdir=0; |
38 |
int ndx=0; |
39 |
char *pt;
|
40 |
char chr;
|
41 |
|
42 |
while (-1!=(len=getline(&inpt,&buflen,stdin))) |
43 |
{ if(buff[len-1]=='\n') |
44 |
buff[len-1]='\0'; |
45 |
pt=strchr(buff,separator); |
46 |
if((pt[5]=='B') && (0!=*(pt=1+strchr(pt+1,separator)))) |
47 |
{ newdir= buff[0]=='h'; |
48 |
if(newdir!=dir)
|
49 |
{ if (ndx)
|
50 |
{ outbuff[ndx]=0;
|
51 |
printf("%c%s\n",dir?'>':'<',outbuff); |
52 |
} |
53 |
dir=newdir; |
54 |
ndx=0;
|
55 |
} |
56 |
while(0!=(chr=*pt++)) |
57 |
if(chr!=':') |
58 |
outbuff[ndx++]=chr; |
59 |
} |
60 |
} |
61 |
outbuff[ndx]=0;
|
62 |
if(ndx)
|
63 |
printf("%c%s\n",dir?'>':'<',outbuff); //last line |
64 |
return 0; |
65 |
} |