Assalamu'alaikum wr. wb.
Saya tertarik sekali dengan ide bedah software jadi ini saya kasih
software untuk dibedah.
Kalau mau reply jangan lupa *HAPUS* bagian yang tidak perlu.
nicefwd
=-=-=-=
Fungsi: memformat text biasanya hasil dari e-mail supaya terlihat
bagus kalau di forward.
Penggunaan:
o) Print help
$ nicefwd -h
o) Format file in dan output ke standar output
$ nicefwd in
o) Format file in dan output ke standar output dengan tambahan "> "
disetiap baris
$ nicefwd -f in
o) Format file in dan output ke file out dengan tanda forward
$ nicefwd -f -o out in
TODO:
1. Support untuk long option
2. Biar mengerti jumlah '>' dan break pada perubahannya
3. Break pada "todo:" dan " 1. bla" atau " o) bleh"
Nah silakan copy & paste text dibawah ini ke file bernama nicefwd
dan chmod +x nicefwd terus ditaruh di path anda (~/bin misalnya)
Sekali lagi kalau mau reply jangan lupa *HAPUS* bagian yang tidak perlu.
---------------------------------------------------------
#!/usr/bin/perl -w
use Getopt::Std;
## Nice Forward
## Copyright (c) Zakaria 2000
## Licensed under GPL
sub print_help
{
print STDERR <<EOF
Usage: nicefwd [OPTION].. [FILE]...
Format the FILEs text suitable for e-mail forwarding
If FILEs is omitted the default is standard input
-l : Left Justfied
-f : Add forward '> '
-h : Print this help
-w WIDTH : Format the text for maximal WIDTH char (default is 70)
-o OUTPUT : Print to OUTPUT file rather than standard output
EOF
}
%option = ();
getopts("lhfw:o:", \%option);
if ($option{h}) {
print_help();
exit;
}
if ($option{o}) {
open(OUT, "> $option{o}") or
die "Couldn't open $option{o} for writing: $!\n";
select OUT;
}
$MAX_CHAR= $option{w} ? $option{w} : 70;
if ($option{f}) {
$MAX_CHAR -= 2;
}
@word = ();
while (<>) {
chomp;
s/^[>\s]+//;
if ($_) {
@lineword = split /\s+/;
@word = (@word, @lineword);
} else {
print_word();
}
}
print_word();
sub print_word
{
$numchar = 0;
if (@word) {
@line = ();
foreach $w (@word) {
$len = length $w;
if (($numchar + $len) > $MAX_CHAR) {
print_line(1);
if ($len > $MAX_CHAR) {
print "> " if $option{f};
print "$w\n";
@line = ();
$numchar = 1;
} else {
@line = ($w);
$numchar = $len + 1;
}
} else {
push @line, $w;
$numchar += ($len + 1);
}
}
print_line();
}
@word = ();
print "\n";
}
sub print_line
{
if (!@line) {
return;
}
($justified) = @_;
if ($justified && !$option{l}) {
my $numword = @line - 1;
print "> " if $option{f};
print $line[0];
if (!$numword) {
print "\n";
return;
}
my $reallen = 0;
foreach $x (@line) {
$reallen += length($x);
}
my $space = $MAX_CHAR - $reallen;
my $defspace = int($space / $numword);
my $modspace = $space % $numword;
for ($x = 1; $x < @line; $x++) {
my $ns = $defspace;
$ns++ if $x <= $modspace;
print (" " x $ns);
print $line[$x];
}
print "\n";
} else {
print "> " if $option{f};
print join(' ', @line) . "\n";
}
}
---------------------------------------------------------
Sekali lagi kalau mau reply jangan lupa *HAPUS* bagian yang tidak perlu.
Wassallam,
-- Zakaria
PT. Asia Karsa Indah [EMAIL PROTECTED]
Advanced Technologies [EMAIL PROTECTED]
Jl. Raya Kalimalang 4B, Jakarta [EMAIL PROTECTED]
Telp : (62-21) 8649318 http://www.asia-karsa.com
Fax : (62-21) 8649316 http://linux.or.id/pemula
--------------------------------------------------------------------------------
Utk berhenti langganan, kirim email ke [EMAIL PROTECTED]
Informasi arsip di http://www.linux.or.id/milis.php3
Pengelola dapat dihubungi lewat [EMAIL PROTECTED]