streamtools: Add warning if subtitles go outside the screen
[jpcrr.git] / streamtools / dumppackets.cpp
blobc2e1397ecec8eca90ea3861654e6e5e7a3d871ab
1 #include "newpacket.hpp"
2 #include <iostream>
3 #include <iomanip>
5 bool brief_mode = false;
7 void handle_packet(packet* p)
9 std::cout << "Packet: channel " << p->rp_channel << "<perm#" << p->rp_channel_perm << ">[";
10 for(size_t i = 0; i < p->rp_channel_name.length(); i++) {
11 unsigned char ch = p->rp_channel_name[i];
12 if(ch < 32 || ch > 126)
13 std::cout << "\\x" << std::setfill('0') << std::setw(2) << std::hex << (uint16_t)ch;
14 else if(ch == '[' || ch == ']' || ch == '\\')
15 std::cout << "\\" << ch;
16 else
17 std::cout << ch;
19 std::cout << "] at " << std::dec << p->rp_timestamp << ", type " << p->rp_major << "("
20 << (uint16_t)p->rp_minor << ") " << "payload " << p->rp_payload.size() << ":" << std::endl;
21 for(size_t i = 0; !brief_mode && i < p->rp_payload.size(); i += 16) {
22 size_t j = p->rp_payload.size() - i;
23 if(j > 16)
24 j = 16;
25 std::cout << "\t";
26 for(size_t k = 0; k < j; k++)
27 std::cout << std::setfill('0') << std::setw(2) << std::hex
28 << (uint16_t)p->rp_payload[i + k] << " ";
29 std::cout << std::endl;
31 delete p;
34 int real_main(int argc, char** argv)
36 struct packet* p;
37 if(argc != 2) {
38 std::cerr << "syntax: " << argv[0] << " <file>" << std::endl;
39 exit(1);
41 if(getenv("BRIEF_PACKETDUMP"))
42 brief_mode = true;
43 read_channel rc(argv[1]);
44 while((p = rc.read()))
45 handle_packet(p);
46 return 0;