Created
October 8, 2008 20:44
-
-
Save reid/15584 to your computer and use it in GitHub Desktop.
Transform a Colloquy.app conversation into a simpler format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$notice = $_SERVER['argv'][1] == '-notice'; | |
$input = ''; | |
if (STDIN) while (!feof(STDIN)) $input .= fgets(STDIN, 4096); | |
foreach (explode("\n", $input) as $text) { | |
$a = explode('<', $text); | |
if (count($a) > 1) { | |
$name = array_shift(explode('>', $a[1])); | |
} else if (strpos($text, ']')) { | |
$name = $notice; | |
} else { | |
$message = trim($a[0]); | |
if ($name && $message) { | |
echo ($name === true) ? "$message\n" : "$name: $message\n"; | |
$name = $message = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment