1 /* coded by Ketmar // Vampire Avalon (ketmar@ketmar.no-ip.org)
3 * This program is free software. It comes without any warranty, to
4 * the extent permitted by applicable law. You can redistribute it
5 * and/or modify it under the terms of the Do What The Fuck You Want
6 * To Public License, Version 2, as published by Sam Hocevar. See
7 * http://sam.zoy.org/wtfpl/COPYING for more details.
14 #include "k8history.h"
15 #include "k8strutils.h"
20 #define KHISTORY_DATE_FORMAT "yyyy/MM/dd HH:mm:ss"
23 static QString
dateToString (const QDateTime
&dt
) {
24 if (dt
.isNull()) return QDateTime::currentDateTime().toUTC().toString(KHISTORY_DATE_FORMAT
);
25 return dt
.toUTC().toString(KHISTORY_DATE_FORMAT
);
29 static void dumpMsg (QFile
&fo
, const HistoryMessage
&msg
) {
33 case HistoryMessage::Incoming
: res
.append("*>"); break;
34 case HistoryMessage::Outgoing
: res
.append("*<"); break;
35 case HistoryMessage::Server
: res
.append("*="); break;
36 case HistoryMessage::Info
: res
.append("**"); break;
40 //res.append(QString::number(msg.date.toUTC().toTime_t()).toAscii());
41 res
.append(dateToString(msg
.date
).toAscii());
44 res
.append(msg
.uni
.toUtf8());
47 if (!msg
.action
.isEmpty()) {
49 res
.append(K8Str::escapeNL(msg
.action
).toUtf8());
54 //res.append(K8Str::escapeNL(msg.text).toUtf8());
55 res
.append(K8Str::escapeNL(msg
.text
).toUtf8());
62 int main (int argc
, char *argv
[]) {
65 QString fiName
;//("dump.hif");
66 QString foName
;//("dump");
70 qDebug() << "usage: hif2hist basename myuni";
73 fiName
= QString(argv
[1]);
74 foName
= QString(argv
[1])+".hif";
79 //qDebug() << "time taken (ms):" << st.elapsed();
81 HistoryFile
hf(fiName
, myUNI
);
82 qDebug() << "opening file...";
84 if (!hf
.open(HistoryFile::Read
)) {
85 qDebug() << "can't open history file!";
88 qDebug() << "time taken (ms):" << st
.elapsed();
89 qDebug() << "number of messages:" << hf
.count();
93 if (!fo
.open(QIODevice::WriteOnly
)) {
94 qWarning() << "can't open output file";
98 qDebug() << "dumping file...";
99 int mNo
= 0, mTotal
= 0;
102 while (hf
.read(mNo
++, msg
)) {
104 qDebug() << mNo
-1 << "is invalid!";
108 if (mTotal
%8192 == 1) {
109 fprintf(stderr
, "\r%d messages processed", mTotal
); fflush(stderr
);
113 fprintf(stderr
, "\r%d messages processed\n", mTotal
); fflush(stderr
);
114 qDebug() << "time taken (ms):" << st
.elapsed();