71 #include <sys/ioctl.h>
82 #ifdef FIX8_HAVE_GETOPT_H
118 int main(
int argc,
char **argv)
122 #ifdef FIX8_HAVE_GETOPT_LONG
123 option long_options[]
125 {
"help", 0, 0,
'h' },
126 {
"offset", 1, 0,
'o' },
127 {
"version", 0, 0,
'v' },
128 {
"summary", 0, 0,
's' },
129 {
"context", 0, 0,
'c' },
133 while ((val = getopt_long (argc, argv,
GETARGLIST.c_str(), long_options, 0)) != -1)
135 while ((val = getopt (argc, argv,
GETARGLIST.c_str())) != -1)
142 cout <<
"Released under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3. See <http://fsf.org/> for details." << endl;
144 case ':':
case '?':
return 1;
146 case 'o': offset = stoi(optarg);
break;
147 case 's':
summary =
true;
break;
161 inputFile = argv[optind];
162 if (inputFile.empty())
168 bool usestdin(inputFile ==
"-");
169 filestdin ifs(usestdin ? &cin :
new ifstream(inputFile.c_str()), usestdin);
172 cerr <<
"Could not open " << inputFile << endl;
179 const int bufsz(4096);
186 ifs().getline(buffer, bufsz);
189 unique_ptr<Message> msg(Message::factory(
TEX::ctx(), buffer + offset));
192 MessageCount::iterator mitr(mc->find(msg->get_msgtype()));
193 if (mitr == mc->end())
194 mc->insert({msg->get_msgtype(), 1});
198 cout << *msg << endl;
204 cerr <<
"interrupted" << endl;
208 cerr <<
"exception: " << e.
what() << endl;
212 cerr <<
"exception: " << e.what() << endl;
215 cout << msgs <<
" messages decoded." << endl;
218 for (MessageCount::const_iterator mitr(mc->begin()); mitr != mc->end(); ++mitr)
221 cout << setw(20) << left << bme->
_name <<
" (\"" << mitr->first <<
"\")" <<
'\t' << mitr->second << endl;
232 um.
setdesc(
"hfprint -- f8 protocol log printer");
233 um.
add(
'h',
"help",
"help, this screen");
234 um.
add(
'v',
"version",
"print version then exit");
235 um.
add(
'o',
"offset",
"bytes to skip on each line before parsing FIX message");
236 um.
add(
's',
"summary",
"summary, generate message summary");
238 um.
add(
"@hfprint myfix_server_protocol.log");
239 um.
add(
"@hfprint hfprint -s -o 12 myfix_client_protocol.log");
240 um.
add(
"@cat myfix_client_protocol.log | hfprint -");
bool term_received(false)
const string GETARGLIST("hsvo:c")
void sig_handler(int sig)
map< string, unsigned > MessageCount
Message instantiation table entry.
bool add(const char sw, const std::string &lsw, const std::string &help)
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
void setdesc(const std::string &desc)
void print(std::ostream &os) const
int main(int argc, char **argv)
Abstract file or stdin input.
const char * what() const
Convenient program help/usage wrapper. Generates a standardised usage message.