Mercurial > ~mikael > mcabber > hg
comparison mcabber/contrib/cicq2mcabber.pl @ 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 | |
children | cb2f18e20e6a |
comparison
equal
deleted
inserted
replaced
178:cfefae4b6de9 | 179:d416d5cb8ddb |
---|---|
1 #!/usr/bin/perl -w | |
2 # | |
3 # usage: cicq2mcabber.pl cicqhistoryfile > mcabberhistoryfile | |
4 # Convert a centericq history file to mcabber format | |
5 # | |
6 # See histolog.c for the mcabber format. | |
7 # | |
8 # MiKael, 2005/05/05 | |
9 | |
10 use strict; | |
11 | |
12 my $line; | |
13 my $inblock = 0; | |
14 | |
15 my %bdata = (); | |
16 | |
17 sub print_entry() | |
18 { | |
19 my ($type, $info, $date, $len, $data); | |
20 | |
21 return unless(defined $bdata{"msg"}); | |
22 | |
23 if ($bdata{"type"} eq "MSG") { | |
24 $type = "M"; | |
25 if ($bdata{"inout"} eq "OUT") { | |
26 $info = "S"; | |
27 } elsif ($bdata{"inout"} eq "IN") { | |
28 $info = "R"; | |
29 } else { | |
30 print STDERR "Neither IN nor OUT!?\n"; | |
31 return; | |
32 } | |
33 } else { | |
34 print STDERR "Data type not handled.\n"; | |
35 return; | |
36 } | |
37 $date = $bdata{"timestamp"}; | |
38 $len = $bdata{"nb"}; | |
39 $data = $bdata{"msg"}; | |
40 | |
41 printf("%s%s %10u %03d %s", $type, $info, $date, $len, $data); | |
42 } | |
43 | |
44 while ($line = <>) { | |
45 chomp $line; | |
46 # The separator is ^L ; I use substr to exclude the EOL | |
47 if ($line eq "") { | |
48 print_entry() if ($inblock); | |
49 # reset data for new block | |
50 %bdata = (); | |
51 $inblock = 1; | |
52 next; | |
53 } | |
54 # Skip garbage or unrecognized stuff... | |
55 if (!$inblock) { | |
56 print STDERR "Skipping line\n"; | |
57 next; | |
58 } | |
59 | |
60 # 1 IN/OUT line | |
61 unless (exists $bdata{"inout"}) { | |
62 if (($line eq "IN") || ($line eq "OUT")) { | |
63 $bdata{"inout"} = $line; | |
64 } else { | |
65 print STDERR "No IN/OUT information ($line)!\n"; | |
66 $inblock = 0; | |
67 } | |
68 next; | |
69 } | |
70 # 1 type line (MSG...) | |
71 unless (exists $bdata{"type"}) { | |
72 # We don't handle NOTE and AUTH yet. | |
73 if ($line eq "MSG") { | |
74 $bdata{"type"} = $line; | |
75 } else { | |
76 print STDERR "Not a MSG type ($line)\n"; | |
77 $inblock = 0; | |
78 } | |
79 next; | |
80 } | |
81 # 2 date lines | |
82 unless (exists $bdata{"timestamp"}) { | |
83 $bdata{"timestamp"} = $line; | |
84 last unless defined ($line = <>); | |
85 chomp $line; | |
86 $bdata{"timestamp2"} = $line; | |
87 if (! $bdata{"timestamp2"} eq $bdata{"timestamp2"}) { | |
88 print STDERR "Timestamps differ...\n"; | |
89 } | |
90 next; | |
91 } | |
92 # ... The message itself | |
93 $line =~ s/ | |
94 $//; | |
95 if (exists $bdata{"msg"}) { | |
96 $bdata{"msg"} .= $line."\n"; | |
97 $bdata{"nb"}++; | |
98 } else { | |
99 $bdata{"msg"} = $line."\n"; | |
100 $bdata{"nb"} = 0; | |
101 } | |
102 } | |
103 print_entry() if ($inblock); | |
104 | |
105 # vim:set sw=2 sts=2 et si cinoptions="": |