use strict; use warnings; use vars qw( $WIDTH ); BEGIN { $WIDTH = 40; } sub detab { local *_ = @_ ? \($_[0]) : \$_; my $pos = 0; for (;;) { $pos = index($_, "\t", $pos); last if ($pos < 0); substr($_, $pos, 1) = ' 'x(int($pos/8+1)*8-$pos); } } sub flush_para { our $para; local *para = \($_[0]); our $indent; local *indent = \($_[1]); my $width = $_[2]; return unless (length($para)); my @lines; $width -= length($indent); $width = 20 if ($width < 20); while (length($para) > $width) { my $width2 = $width - 1; if ($para =~ s/^(.{0,$width2}\S)\s+//s) { # Break at space. push(@lines, $1); } else { # No space. $para =~ s/^(.{$width})//s; push(@lines, $1); } } push(@lines, $para); my $line_sep = "\n" . (' ' x length($indent)); print($indent . join($line_sep, @lines) . "\n"); $para = $indent = ''; } { print('='x$WIDTH, "\n"); my $fortune; local $/ = "\n".('='x67)."\n"; while (defined($fortune = )) { chomp($fortune); my $para = ''; my $indent = ''; my $indent2 = ''; local $/ = "\n"; foreach (split(/\n/, $fortune)) { /^\s*$/ && do { flush_para($para, $indent, $WIDTH); $indent2 = ''; print("\n"); next; }; detab($_); /^((\s*)--\s*)(.*)/ && do { my @save = ($1, $2, $3); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; }; # Good enough? /^((\s*)\S.{1,14}:\s*)(.*)/ && do { my @save = ($1, $2, $3); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; }; /^(\s*)(.*)/; if (!length($para)) { ($indent, $indent2, $para) = ($1, $1, $2); next; } if (length($1) != length($indent) && length($1) != length($indent2)) { my @save = ($1, '', $2); flush_para($para, $indent, $WIDTH); ($indent, $indent2, $para) = @save; next; } $para .= ' ' . $_; } flush_para($para, $indent, $WIDTH); print('='x$WIDTH, "\n"); } } __DATA__ Bender: Stay away from our women. You got metal fever, baby, metal fever! =================================================================== Kids, kids, kids. As far as Daddy's concerned, you're both potential murderers. -- Homer Simpson Who Shot Mr. Burns? (Part 2) =================================================================== Wh ... what's going on? Wh ... wha ... why am I on a Japanese box? -- Homer Simpson In Marge We Trust =================================================================== Who spread garbage all over Flanders's yard before I got a chance to? -- Homer Simpson Two Dozen and One Greyhounds =================================================================== THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? Bart Simpson on chalkboard in episode 2F16 =================================================================== "It was nice of you to let me reattach your arm." --Zoidber =================================================================== Calculon: An Oscar, you say? That would get me out of this festering rats' nest called television once and for all. =================================================================== Dasher, Dancer ... Prancer ... Nixon, Comet, Cupid ... Donna Dixon. -- Homer Simpson Simpsons Roasting on an Open Fire =================================================================== Homer: I suppose you want to probe me. Well, you might as well get it over with. Kang: Stop! We have reached the limits of what rectal probing can teach us. Treehouse of Horror VII Famous Original Ray's Superior Court =================================================================== It's okay, Marge. I've learned my lesson. A mountain of sugar is too much for one man. It's clear now why God portions it out in those tiny packets, and why he lives on a plantation in Hawaii. -- Homer Simpson Lisa's Rival =================================================================== Bender: "Tell the Donbot I'm quitting organized crime. From now on I'll stick to the regular kind." =================================================================== "Hurry up! I wanna see the moon." -Fry "Relax. It's open 'till nine." -Leela =================================================================== I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM Bart Simpson on chalkboard in episode AABF03 =================================================================== Calculon: I'm programmed to be very busy. =================================================================== "I don't care how many eyes a man has... as long as it's less than five." -Leela #### ======================================== Bender: Stay away from our women. You got metal fever, baby, metal fever! ======================================== Kids, kids, kids. As far as Daddy's concerned, you're both potential murderers. -- Homer Simpson Who Shot Mr. Burns? (Part 2) ======================================== Wh ... what's going on? Wh ... wha ... why am I on a Japanese box? -- Homer Simpson In Marge We Trust ======================================== Who spread garbage all over Flanders's yard before I got a chance to? -- Homer Simpson Two Dozen and One Greyhounds ======================================== THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? THIS IS NOT A CLUE...OR IS IT? Bart Simpson on chalkboard in episode 2F16 ======================================== "It was nice of you to let me reattach your arm." --Zoidber ======================================== Calculon: An Oscar, you say? That would get me out of this festering rats' nest called television once and for all. ======================================== Dasher, Dancer ... Prancer ... Nixon, Comet, Cupid ... Donna Dixon. -- Homer Simpson Simpsons Roasting on an Open Fire ======================================== Homer: I suppose you want to probe me. Well, you might as well get it over with. Kang: Stop! We have reached the limits of what rectal probing can teach us. Treehouse of Horror VII Famous Original Ray's Superior Court ======================================== It's okay, Marge. I've learned my lesson. A mountain of sugar is too much for one man. It's clear now why God portions it out in those tiny packets, and why he lives on a plantation in Hawaii. -- Homer Simpson Lisa's Rival ======================================== Bender: "Tell the Donbot I'm quitting organized crime. From now on I'll stick to the regular kind." ======================================== "Hurry up! I wanna see the moon." -Fry "Relax. It's open 'till nine." -Leela ======================================== I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM I WILL NOT SCREAM FOR ICE CREAM Bart Simpson on chalkboard in episode AABF03 ======================================== Calculon: I'm programmed to be very busy. ======================================== "I don't care how many eyes a man has... as long as it's less than five." -Leela ========================================