eradicate last banana bugs
[banana.git] / include / wrapper.inc.php
1 <?php
2 /********************************************************************************
3 * include/wrapper.inc.php : text wrapper
4 * -------------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 function wrap($_text,$_prefix="",$_length=72) {
11 $parts = preg_split("/\n-- ?\n/", $_text);
12 if (count($parts) >1) {
13 $sign = "\n-- \n" . array_pop($parts);
14 $text = join("\n-- \n", $parts);
15 } else {
16 $sign = '';
17 $text = $_text;
18 }
19
20 $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
21 exec($cmd, $result);
22
23 return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign);
24 }
25
26 ?>