#! /usr/bin/perl

use strict;
use warnings;

if (open my $fh, '>', 'perf.rc')
{
  print $fh "data.location=.\n",
            "color=on\n",
            "_forcecolor=on\n",
            "verbose=label\n",
            "hooks=off\n",
            "color.debug=\n";
  close $fh;
}

my $filename = 'sample-text.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
  or die "Could not open file '$filename' $!";

# Read all the data.
my $id = 1;
while (my $line = <$fh>)
{
  if ($. % 20 != 19)
  {
    # Names are both projects and tags.
    $line =~ s/([A-Z]{2,})/$1 project:$1 +$1/g;
  }

  if ($. % 20 == 19)
  {
    my $anno_id = $id - 1;
    qx{../src/task rc:perf.rc rc.gc=off $anno_id annotate $line};
    print "[$.] task rc:perf.rc rc.gc=off $anno_id annotate $line\n" if $?;
  }
  elsif ($. % 4 == 1)
  {
    qx{../src/task rc:perf.rc rc.gc=off add $line};
    print "[$.] task rc:perf.rc rc.gc=off add $line\n" if $?;
    ++$id;
  }
  else
  {
    qx{../src/task rc:perf.rc rc.gc=off log $line};
    print "[$.] task rc:perf.rc rc.gc=off log $line\n" if $?;
  }
}

exit 0;
