| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Webqq::Client::Util; | 
| 2 | 1 |  |  | 1 |  | 3 | use Exporter 'import'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 3 | 1 |  |  | 1 |  | 4 | use Encode; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 53 |  | 
| 4 | 1 |  |  | 1 |  | 1542 | use Encode::Locale; | 
|  | 1 |  |  |  |  | 2900 |  | 
|  | 1 |  |  |  |  | 463 |  | 
| 5 |  |  |  |  |  |  | our @EXPORT_OK = qw(console console_stderr hash truncate code2state code2client) ; | 
| 6 |  |  |  |  |  |  | sub console{ | 
| 7 | 0 |  |  | 0 | 0 |  | my $bytes = join "",@_; | 
| 8 | 0 |  |  |  |  |  | print encode("locale",decode("utf8",$bytes)); | 
| 9 |  |  |  |  |  |  | } | 
| 10 |  |  |  |  |  |  | sub console_stderr{ | 
| 11 | 0 |  |  | 0 | 0 |  | my $bytes = join "",@_; | 
| 12 | 0 |  |  |  |  |  | print STDERR encode("locale",decode("utf8",$bytes)); | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | #获取好友列表和群列表的hash函数 | 
| 16 |  |  |  |  |  |  | sub hash { | 
| 17 | 0 |  |  | 0 | 0 |  | my $ptwebqq = shift; | 
| 18 | 0 |  |  |  |  |  | my $uin = shift; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  |  |  |  |  | $uin .= ""; | 
| 21 | 0 |  |  |  |  |  | my @N; | 
| 22 | 0 |  |  |  |  |  | for(my $T =0;$T | 
| 23 | 0 |  |  |  |  |  | $N[$T % 4] ^= ord(substr($ptwebqq,$T,1)); | 
| 24 |  |  |  |  |  |  | } | 
| 25 | 0 |  |  |  |  |  | my @U = ("EC", "OK"); | 
| 26 | 0 |  |  |  |  |  | my @V; | 
| 27 | 0 |  |  |  |  |  | $V[0] =  $uin >> 24 & 255 ^ ord(substr($U[0],0,1)); | 
| 28 | 0 |  |  |  |  |  | $V[1] =  $uin >> 16 & 255 ^ ord(substr($U[0],1,1)); | 
| 29 | 0 |  |  |  |  |  | $V[2] =  $uin >> 8  & 255 ^ ord(substr($U[1],0,1)); | 
| 30 | 0 |  |  |  |  |  | $V[3] =  $uin       & 255 ^ ord(substr($U[1],1,1)); | 
| 31 | 0 |  |  |  |  |  | @U = (); | 
| 32 | 0 |  |  |  |  |  | for(my $T=0;$T<8;$T++){ | 
| 33 | 0 | 0 |  |  |  |  | $U[$T] = $T%2==0?$N[$T>>1]:$V[$T>>1]; | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 0 |  |  |  |  |  | @N = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"); | 
| 36 | 0 |  |  |  |  |  | my $V = ""; | 
| 37 | 0 |  |  |  |  |  | for($T=0;$T<@U;$T++){ | 
| 38 | 0 |  |  |  |  |  | $V .= $N[$U[$T] >> 4 & 15]; | 
| 39 | 0 |  |  |  |  |  | $V .= $N[$U[$T] & 15]; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  |  | return $V; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub truncate { | 
| 47 | 0 |  |  | 0 | 0 |  | my $out_and_err = shift; | 
| 48 | 0 |  |  |  |  |  | my %p = @_; | 
| 49 | 0 |  | 0 |  |  |  | my $max_bytes = $p{max_bytes} || 200; | 
| 50 | 0 |  | 0 |  |  |  | my $max_lines = $p{max_lines} || 10; | 
| 51 | 0 |  |  |  |  |  | my $is_truncated = 0; | 
| 52 | 0 | 0 |  |  |  |  | if(length($out_and_err)>$max_bytes){ | 
| 53 | 0 |  |  |  |  |  | $out_and_err = substr($out_and_err,0,$max_bytes); | 
| 54 | 0 |  |  |  |  |  | $is_truncated = 1; | 
| 55 |  |  |  |  |  |  | } | 
| 56 | 0 |  |  |  |  |  | my @l =split /\n/,$out_and_err,$max_lines+1; | 
| 57 | 0 | 0 |  |  |  |  | if(@l>$max_lines){ | 
| 58 | 0 |  |  |  |  |  | $out_and_err = join "\n",@l[0..$max_lines-1]; | 
| 59 | 0 |  |  |  |  |  | $is_truncated = 1; | 
| 60 |  |  |  |  |  |  | } | 
| 61 | 0 | 0 |  |  |  |  | return $out_and_err. ($is_truncated?"\n(已截断)":""); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  | sub code2state { | 
| 64 | 0 |  |  | 0 | 0 |  | my %c = qw( | 
| 65 |  |  |  |  |  |  | 10  online | 
| 66 |  |  |  |  |  |  | 20  offline | 
| 67 |  |  |  |  |  |  | 30  away | 
| 68 |  |  |  |  |  |  | 40  hidden | 
| 69 |  |  |  |  |  |  | 50  busy | 
| 70 |  |  |  |  |  |  | 60  callme | 
| 71 |  |  |  |  |  |  | 70  silent | 
| 72 |  |  |  |  |  |  | ); | 
| 73 | 0 |  | 0 |  |  |  | return $c{$_[0]} || "online"; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | sub code2client { | 
| 76 | 0 |  |  | 0 | 0 |  | my %c = qw( | 
| 77 |  |  |  |  |  |  | 1   pc | 
| 78 |  |  |  |  |  |  | 21  mobile | 
| 79 |  |  |  |  |  |  | 24  iphone | 
| 80 |  |  |  |  |  |  | 41  web | 
| 81 |  |  |  |  |  |  | ); | 
| 82 | 0 |  | 0 |  |  |  | return $c{$_[0]} || 'unknown'; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | 1; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | __END__ |