|
1 # Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Text formatting module |
|
15 # |
|
16 # |
|
17 |
|
18 package Output; |
|
19 require Exporter; |
|
20 @ISA=qw(Exporter); |
|
21 @EXPORT=qw( |
|
22 OutSetLength OutSetPostWrap OutFormat Output |
|
23 OutText |
|
24 ); |
|
25 |
|
26 use strict; |
|
27 |
|
28 |
|
29 my $Len=80; |
|
30 my $PreWrap="\\"; |
|
31 my $PreWrapLen=length($PreWrap); |
|
32 my $PostWrap=' '; |
|
33 my $PostWrapLen=length($PostWrap); |
|
34 my $Buf=''; |
|
35 my $Text=''; |
|
36 |
|
37 sub OutSetLength ($) { |
|
38 if ($_[0]) { |
|
39 $Len=$_[0]; |
|
40 return $Len; |
|
41 } |
|
42 $Len=80; |
|
43 } |
|
44 |
|
45 sub OutSetPreWrap ($) { |
|
46 $PreWrap=$_[0]; |
|
47 $PreWrapLen=length($PreWrap); |
|
48 } |
|
49 |
|
50 sub OutSetPostWrap ($) { |
|
51 $PostWrap=$_[0]; |
|
52 $PostWrapLen=length($PostWrap); |
|
53 } |
|
54 |
|
55 sub OutFormat (@) { |
|
56 my $Item; |
|
57 foreach $Item (@_) { |
|
58 $Buf.=$Item; |
|
59 } |
|
60 } |
|
61 |
|
62 sub OutWrite () { |
|
63 my @Buf=(); |
|
64 my $CurLen=0; |
|
65 if ($Buf=~/^(\s)/o) { |
|
66 # output any starting spaces or tabs |
|
67 $Text.=$1; |
|
68 $CurLen=length($1); |
|
69 } |
|
70 while ($Buf=~/([^ "\t\n\r\f]*"[^"\t\n\r\f]+"[^ "\t\n\r\f]*|[^ "\t\n\r\f]+)/go) { |
|
71 # get the elements of $Buf into @Buf |
|
72 push @Buf, $1; |
|
73 } |
|
74 $Buf=''; |
|
75 my $Elem; |
|
76 foreach $Elem (@Buf) { |
|
77 my $ElemLen=length($Elem); |
|
78 if (($CurLen+$ElemLen+$PreWrapLen) > $Len) { |
|
79 # $Len doesn't account for the newline character |
|
80 # wrap the line if adding another element will take it over the prescribed length |
|
81 $Text.="$PreWrap\n$PostWrap"; |
|
82 $CurLen=$PostWrapLen; |
|
83 } |
|
84 elsif ($CurLen>$PostWrapLen) { |
|
85 # add a space to the line if they're are already elements in the line |
|
86 $Text.=' '; |
|
87 $CurLen++; |
|
88 } |
|
89 # add element to the line |
|
90 $Text.=$Elem; |
|
91 $CurLen+=$ElemLen; |
|
92 } |
|
93 # finish with a newline |
|
94 $Text.="\n"; |
|
95 } |
|
96 |
|
97 sub Output (@) { |
|
98 OutWrite if $Buf; # output the formatted text before doing any more output |
|
99 my $Item; |
|
100 foreach $Item (@_) { |
|
101 $Text.=$Item; |
|
102 } |
|
103 } |
|
104 |
|
105 sub OutText () { |
|
106 my $temp=$Text; |
|
107 $Text=''; |
|
108 $temp; |
|
109 } |
|
110 |
|
111 1; |