comparison buddytrans2 @ 524:9ec08f6bb944

[gaim-migrate @ 534] Added script to convert new winaim blt format to gaim/toc buddy list committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 25 Jul 2000 08:27:51 +0000
parents
children
comparison
equal deleted inserted replaced
523:023c3851db0a 524:9ec08f6bb944
1 #!/usr/bin/perl -w
2 #
3 # gaim
4 #
5 # Copyright (C) 1998 - 2000, Mark Spencer <markster@marko.net>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #
21 # ---
22 #
23 # Buddy List Conversion Script Written By: John Assalone <assalonej@kpe.com>
24 # Modifications by: Rob Flynn <IM: Rob Flynn> <rflynn@blueridge.net>
25 # Obfuscated by: Schuyler Erle <IM: sderle> <schuyler@tridity.org>
26 #
27 # Use this script to convert the new WinAIM buddy list format to gaim's format.
28 #
29 # Syntax: ./buddytrans buddy.list gaimlist
30 #
31
32 use strict;
33 use 5.003;
34
35 sub translate_lst
36 {
37 my $src = shift;
38 my ($line, $field, $name, $out);
39
40 $out = "m 1\n";
41
42 for $line (grep(/\w/o, split(/[\r\n]+/o, $src))) {
43 ($field, $name) = ($line =~ /^\s*(\w)\w*\s+(.+)$/go);
44 $name =~ y/"//d;
45 $out .= "$field $name\n" if $field and $name;
46 }
47
48 $out
49 }
50
51 sub translate_blt
52 {
53 my $src = shift;
54 my $out = "m 1\n";
55 my $grp;
56
57 $src =~ s/^.*?Buddy\s+{.*?list\s+{//gos;
58
59 while ( $src =~ / } |
60 (?: "([^"]+)" | (\S+) ) \s*
61 (?: {(.+?)} | ([^\n]+) ) \s*/gosx ) {
62
63 last unless defined( $grp = $1 || $2 );
64
65 $out .= join( "\n", "g $grp",
66 map { "b $_" }
67 grep { defined($_) and /\S/o }
68 split ( /"([^"]+)"|\s+/, ($3 || $4) ) )
69 . "\n"
70 }
71
72 $out;
73 }
74
75 sub buddy_trans
76 {
77 my ($src_file, $dest_file) = @_;
78
79 die "Syntax: $0 buddy.lst gaimlist\n"
80 unless ($src_file and $dest_file);
81
82
83 open SOURCE, "<$src_file" or die "$!: $src_file\n";
84 my $src = do { local $/ = undef; <SOURCE> };
85 close SOURCE;
86
87 if (-e $dest_file) {
88 print STDERR "$dest_file already exists! Continue? ";
89 unless (-t and <STDIN> =~ /^y/io) {
90 print STDERR "Aborted.\n";
91 exit -1
92 }
93 }
94
95 open DEST, ">$dest_file" or die "$!: $dest_file\n";
96 print DEST ($src =~ /{/os) ? translate_blt($src) : translate_lst($src);
97 close DEST;
98
99 0;
100 }
101
102 buddy_trans( @ARGV );