#!/usr/local/bin/perl

# /* LICENSE:
#   =========================================================================
#     CMPack'03 Source Code Release for OPEN-R SDK v1.0
#     Copyright (C) 2003 Multirobot Lab [Project Head: Manuela Veloso]
#     School of Computer Science, Carnegie Mellon University
#     All rights reserved.
#   ========================================================================= */

print "const int NumColors=8;\n";
print "\n";
print "//\n";
print "// color tables\n";
print "//\n";
print "const int TableSize = 32; // Don't touch this number\n";

$color_names[0]="orange_ball";
$color_names[1]="pink_marker";
$color_names[2]="blue_goal";
$color_names[3]="yellow_goal";
$color_names[4]="green_marker";
$color_names[5]="blue_bot";
$color_names[6]="red_bot";
$color_names[7]="white";

$color_range_low=0;

while(<>) {
  SWITCH: {
    /color ([0-9]+)/ && do {
      $color_num=$1 - 1;
      $color_name=$color_names[$color_num];
      print ("const unsigned char " . $color_name . "[TableSize*4] = {\n");
      $color_range_low=0;
      break;
    };
    /\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)/ && do {
      if($color_range_low!=248) {
        printf("%3d, %3d, %3d, %3d, // Y %3d - %3d\n",
               $1,$2,$3,$4,$color_range_low,$color_range_low+7);
      }
      else {
        printf("%3d, %3d, %3d, %3d  // Y %3d - %3d\n",
               $1,$2,$3,$4,$color_range_low,$color_range_low+7);
        printf("};\n");
        printf("\n");
      }
      $color_range_low+=8;
    };
  }
}

print "const unsigned char *colors[NumColors]={\n";
print "  orange_ball,\n";
print "  pink_marker,\n";
print "  blue_goal,\n";
print "  yellow_goal,\n";
print "  green_marker,\n";
print "  blue_bot,\n";
print "  red_bot,\n";
print "  white\n";
print "};\n";

