sbsv1/abld/genutil/output.pm
changeset 599 fa7a3cc6effd
equal deleted inserted replaced
596:9f25be3da657 599:fa7a3cc6effd
       
     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 
       
    27 
       
    28 my $Len=80;
       
    29 my $PreWrap="\\";
       
    30 my $PreWrapLen=length($PreWrap);
       
    31 my $PostWrap=' ';
       
    32 my $PostWrapLen=length($PostWrap);
       
    33 my $Buf='';
       
    34 my $Text='';
       
    35 
       
    36 sub OutSetLength ($) {
       
    37 	if ($_[0]) {
       
    38 		$Len=$_[0];
       
    39 		return $Len;
       
    40 	}
       
    41 	$Len=80;
       
    42 }
       
    43 
       
    44 sub OutSetPreWrap ($) {
       
    45 	$PreWrap=$_[0];
       
    46 	$PreWrapLen=length($PreWrap);
       
    47 }
       
    48 
       
    49 sub OutSetPostWrap ($) {
       
    50 	$PostWrap=$_[0];
       
    51 	$PostWrapLen=length($PostWrap);
       
    52 }
       
    53 
       
    54 sub OutFormat (@) {
       
    55 	my $Item;
       
    56 	foreach $Item (@_) {
       
    57 		$Buf.=$Item;
       
    58 	}
       
    59 }
       
    60 
       
    61 sub OutWrite () {
       
    62 	my @Buf=();
       
    63 	my $CurLen=0;
       
    64 	if ($Buf=~/^(\s)/o) {
       
    65 		# output any starting spaces or tabs
       
    66 		$Text.=$1;
       
    67 		$CurLen=length($1);
       
    68 	}
       
    69 	while ($Buf=~/([^ "\t\n\r\f]*"[^"\t\n\r\f]+"[^ "\t\n\r\f]*|[^ "\t\n\r\f]+)/go) {
       
    70 		# get the elements of $Buf into @Buf
       
    71 		push @Buf, $1;
       
    72 	}
       
    73 	$Buf='';
       
    74 	my $Elem;
       
    75 	foreach $Elem (@Buf) {
       
    76 		my $ElemLen=length($Elem);
       
    77 		if (($CurLen+$ElemLen+$PreWrapLen) > $Len) {
       
    78 			# $Len doesn't account for the newline character
       
    79 			# wrap the line if adding another element will take it over the prescribed length
       
    80 			$Text.="$PreWrap\n$PostWrap";
       
    81 			$CurLen=$PostWrapLen;
       
    82 		}
       
    83 		elsif ($CurLen>$PostWrapLen) {
       
    84 			# add a space to the line if they're are already elements in the line
       
    85 			$Text.=' ';
       
    86 			$CurLen++;
       
    87 		}
       
    88 		# add element to the line
       
    89 		$Text.=$Elem;
       
    90 		$CurLen+=$ElemLen;
       
    91 	}
       
    92 	# finish with a newline
       
    93 	$Text.="\n";
       
    94 }
       
    95 
       
    96 sub Output (@) {
       
    97 	OutWrite if $Buf;	# output the formatted text before doing any more output
       
    98 	my $Item;
       
    99 	foreach $Item (@_) {
       
   100 		$Text.=$Item;
       
   101 	}
       
   102 }
       
   103 
       
   104 sub OutText () {
       
   105 	my $temp=$Text;
       
   106 	$Text='';
       
   107 	$temp;
       
   108 }
       
   109 
       
   110 1;