| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | #Copyright (C) 1998 Brett A. Thomas <quark@baz.com> |
|---|
| 4 | # |
|---|
| 5 | #Program to copy all known UINs from your Windows client to Licq. |
|---|
| 6 | #This program released under the terms of the GNU Public License (GPL). |
|---|
| 7 | |
|---|
| 8 | if($#ARGV < 0) |
|---|
| 9 | { |
|---|
| 10 | print STDERR "licq.winconvert <windows_msg_index>\n"; |
|---|
| 11 | print STDERR |
|---|
| 12 | "Copies all the UINs out of your Window ICQ client into Licq.\n"; |
|---|
| 13 | print STDERR |
|---|
| 14 | "It's very important you give convert_uins the message index file,\n"; |
|---|
| 15 | print STDERR "and not some other file. This file us usually called:\n\n"; |
|---|
| 16 | print STDERR ' "/mnt/msdos/Program Files/icq/db/<your_uin>msg.idx"'; |
|---|
| 17 | print STDERR "\n"; |
|---|
| 18 | exit 0; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | foreach $Arg (@ARGV) |
|---|
| 22 | { |
|---|
| 23 | open(MSGS, $Arg) || die "Can't read $Arg: $!"; |
|---|
| 24 | |
|---|
| 25 | sysread(MSGS, $Entry, 8); |
|---|
| 26 | |
|---|
| 27 | while(sysread(MSGS, $Entry, 8)) |
|---|
| 28 | { |
|---|
| 29 | ($_, $_, $UIN) = unpack("cclcc", $Entry); |
|---|
| 30 | if($UIN) |
|---|
| 31 | { |
|---|
| 32 | $UINs{$UIN} = 1; |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | $HomeDir = &GetHomeDir; |
|---|
| 38 | $File = "$HomeDir/.licq/users.conf"; |
|---|
| 39 | $Pre = $Post = ""; |
|---|
| 40 | |
|---|
| 41 | if(open(USERS, "$File")) |
|---|
| 42 | { |
|---|
| 43 | $FoundIt = 0; |
|---|
| 44 | while(!$FoundIt && (!eof(USERS))) |
|---|
| 45 | { |
|---|
| 46 | $_ = <USERS>; |
|---|
| 47 | if($_ eq "[users]\n") |
|---|
| 48 | { |
|---|
| 49 | $FoundIt = 1; |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | $Pre .= $_; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | if($FoundIt) |
|---|
| 58 | { |
|---|
| 59 | #Skip the NumOfUsers thing |
|---|
| 60 | $_ = <USERS>; |
|---|
| 61 | |
|---|
| 62 | $Continue = 1; |
|---|
| 63 | while($Continue) |
|---|
| 64 | { |
|---|
| 65 | if($_ = <USERS>) |
|---|
| 66 | { |
|---|
| 67 | chomp($_); |
|---|
| 68 | if($_ =~ /^\[/) |
|---|
| 69 | { |
|---|
| 70 | $Continue = 0; |
|---|
| 71 | } |
|---|
| 72 | else |
|---|
| 73 | { |
|---|
| 74 | if($_ =~ /^User(\d+)\s+=\s+(\d+)$/) |
|---|
| 75 | { |
|---|
| 76 | $UINs{$2} = 1; |
|---|
| 77 | } |
|---|
| 78 | else |
|---|
| 79 | { |
|---|
| 80 | die "Malformed line in $File: $_"; |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | else |
|---|
| 85 | { |
|---|
| 86 | $Continue = 0; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | if(!eof(USERS)) |
|---|
| 91 | { |
|---|
| 92 | while(<USERS>) |
|---|
| 93 | { |
|---|
| 94 | $Post .= $_; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | close(USERS); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | foreach $UIN (sort(keys(%UINs))) |
|---|
| 102 | { |
|---|
| 103 | $Users[$#Users + 1] = $UIN; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | #$File = "&STDOUT"; |
|---|
| 107 | open(USERS, ">$File") || die "Can't write $File: $!"; |
|---|
| 108 | |
|---|
| 109 | $NumUsers = $#Users + 1; |
|---|
| 110 | print USERS "[users]\n"; |
|---|
| 111 | print USERS "NumOfUsers = $NumUsers\n"; |
|---|
| 112 | |
|---|
| 113 | for($x = 0, $y = 1; $x <= $#Users; ++$x, ++$y) |
|---|
| 114 | { |
|---|
| 115 | print USERS "User$y = $Users[$x]\n"; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | print STDERR "Note: After running this, run Licq, again. You will receive\n"; |
|---|
| 119 | print STDERR "warning messages on startup, which may be ignored. Once Licq\n"; |
|---|
| 120 | print STDERR "comes up, select \"Users/Update All Users\" from the menu,\n"; |
|---|
| 121 | print STDERR "and all users' info should be updated.\n"; |
|---|
| 122 | |
|---|
| 123 | sub GetHomeDir |
|---|
| 124 | { |
|---|
| 125 | my(@PWInfo) = getpwuid($<); |
|---|
| 126 | |
|---|
| 127 | $PWInfo[7]; |
|---|
| 128 | } |
|---|