changeset 179:d416d5cb8ddb

[/trunk] Changeset 191 by mikael * Add a contrib directory * Add cicq2mcabber.pl, a perl script to convert an centericq history file to mcabber history file format
author mikael
date Thu, 05 May 2005 12:36:54 +0000
parents cfefae4b6de9
children 42a33611233b
files mcabber/contrib/cicq2mcabber.pl
diffstat 1 files changed, 104 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcabber/contrib/cicq2mcabber.pl	Thu May 05 12:36:54 2005 +0000
@@ -0,0 +1,104 @@
+#!/usr/bin/perl -w
+#
+# usage: cicq2mcabber.pl cicqhistoryfile > mcabberhistoryfile
+# Convert a centericq history file to mcabber format
+#
+# See histolog.c for the mcabber format.
+#
+# MiKael, 2005/05/05
+
+use strict;
+
+my $line;
+my $inblock = 0;
+
+my %bdata = ();
+
+sub print_entry()
+{
+  my ($type, $info, $date, $len, $data);
+
+  return  unless(defined $bdata{"msg"});
+
+  if ($bdata{"type"} eq "MSG") {
+    $type = "M";
+    if ($bdata{"inout"} eq "OUT") {
+      $info = "S";
+    } elsif ($bdata{"inout"} eq "IN") {
+      $info = "R";
+    } else {
+      print STDERR "Neither IN nor OUT!?\n";
+      return;
+    }
+  } else {
+    print STDERR "Data type not handled.\n";
+    return;
+  }
+  $date = $bdata{"timestamp"};
+  $len  = $bdata{"nb"};
+  $data = $bdata{"msg"};
+
+  printf("%s%s %10u %03d %s", $type, $info, $date, $len, $data);
+}
+
+while ($line = <>) {
+  chomp $line;
+  # The separator is ^L ; I use substr to exclude the EOL
+  if ($line eq "") {
+    print_entry() if ($inblock);
+    # reset data for new block
+    %bdata = ();
+    $inblock = 1;
+    next;
+  }
+  # Skip garbage or unrecognized stuff...
+  if (!$inblock) {
+    print STDERR "Skipping line\n";
+    next;
+  }
+
+  # 1 IN/OUT line
+  unless (exists $bdata{"inout"}) {
+    if (($line eq "IN") || ($line eq "OUT")) {
+      $bdata{"inout"} = $line;
+    } else {
+      print STDERR "No IN/OUT information ($line)!\n";
+      $inblock = 0;
+    }
+    next;
+  }
+  # 1 type line (MSG...)
+  unless (exists $bdata{"type"}) {
+    # We don't handle NOTE and AUTH yet.
+    if ($line eq "MSG") {
+      $bdata{"type"} = $line;
+    } else {
+      print STDERR "Not a MSG type ($line)\n";
+      $inblock = 0;
+    }
+    next;
+  }
+  # 2 date lines
+  unless (exists $bdata{"timestamp"}) {
+    $bdata{"timestamp"} = $line;
+    last unless defined ($line = <>);
+    chomp $line;
+    $bdata{"timestamp2"} = $line;
+    if (! $bdata{"timestamp2"} eq $bdata{"timestamp2"}) {
+      print STDERR "Timestamps differ...\n";
+    }
+    next;
+  }
+  # ... The message itself
+  $line =~ s/
$//;
+  if (exists $bdata{"msg"}) {
+    $bdata{"msg"} .= $line."\n";
+    $bdata{"nb"}++;
+  } else {
+    $bdata{"msg"} = $line."\n";
+    $bdata{"nb"} = 0;
+  }
+}
+print_entry() if ($inblock);
+
+# vim:set sw=2 sts=2 et si cinoptions="":