#!/usr/bin/env perl
BEGIN { $|=1; }
use warnings;
use utf8;

$dep =0;

while (<>) {
  if (/\[emo-/) {s/^\*/÷/;}
# possible dependency links

  s/\] (.*)->(5[0-9][0-9])/\] <errorattach:$2> $1->0/; # impossible attachments
#  s/\] (.*) \#([0-9]+)\->([0-9]+)/\] <DEP:$2-$3> $1/;
#  s/ \#([0-9]+)\->([0-9]+)/\n  <DEP:$1-$2>/; # remove deps from punctuation -- vislcg crashes on it!

  if (! /^</ && ! /^[ \t]*$/) {
    s/\$nondel/\$/g;
      if (! /\t/) {
	s/^([^ \#\n]+) /$1\n  \"$1\" PU \@PU /;
      }
      if (/(\#[0-9]+->[0-9]+)/) {$dep =$1;}
      s/^([^ \t\n]*)/\"<$1>\"/;

      s/( *\t *)\[(.*?)\] /\n  \"$2\" /g;
      s/( \@[^\#\n]+) *\n/$1 $dep\n/g;
    s/"<\$\\>"/"<\$\\\\>"/; # cg needs escaped (read: double) slash
    s/"\$\\"/"\$\\\\"/; # cg needs escaped (read: double) slash

    }
    print;
}
