# Last edited on 2002-01-16 01:20:41 by stolfi

# To be included in gawk programs together with roman-encoding.gawk
# Defines renc_init() for additive Roman numerals ("IIII" not "IV").

function renc_init()
{
  # The classical Roman system with strictly additive digits
  # Extended with p = 5000, b = 10000, f = 50000

  # Digit 0 length distribution = (1,2,2,2,2,1)
  renc_base0 = 10; renc_mul0 = 1;
  renc_digs0[0] = ":";
  renc_digs0[1] = ":i";
  renc_digs0[2] = ":ii";
  renc_digs0[3] = ":iii";
  renc_digs0[4] = ":iiii";
  renc_digs0[5] = ":v";
  renc_digs0[6] = ":vi";
  renc_digs0[7] = ":vii";
  renc_digs0[8] = ":viii";
  renc_digs0[9] = ":viiii";

  # Digit 1 length distribution = (1,2,2,2,2,1)
  renc_base1 = 10; renc_mul1 = renc_mul0*renc_base0;
  renc_digs1[0] = ":";
  renc_digs1[1] = ":x";
  renc_digs1[2] = ":xx";
  renc_digs1[3] = ":xxx";
  renc_digs1[4] = ":xxxx";
  renc_digs1[5] = ":l";
  renc_digs1[6] = ":lx";
  renc_digs1[7] = ":lxx";
  renc_digs1[8] = ":lxxx";
  renc_digs1[9] = ":lxxxx";

  # Digit 2 length distribution = (1,2,2,2,2,1)
  renc_base2 = 10; renc_mul2 = renc_mul1*renc_base1;
  renc_digs2[0] = ":";
  renc_digs2[1] = ":c";
  renc_digs2[2] = ":cc";
  renc_digs2[3] = ":ccc";
  renc_digs2[4] = ":cccc";
  renc_digs2[5] = ":d";
  renc_digs2[6] = ":dc";
  renc_digs2[7] = ":dcc";
  renc_digs2[8] = ":dccc";
  renc_digs2[9] = ":dcccc";

  # Digit 3 length distribution = (1,2,2,2,2,1)
  renc_base3 = 10; renc_mul3 = renc_mul2*renc_base2;
  renc_digs3[0] = ":";
  renc_digs3[1] = ":m";
  renc_digs3[2] = ":mm";
  renc_digs3[3] = ":mmm";
  renc_digs3[4] = ":mmmm";
  renc_digs3[5] = ":p";
  renc_digs3[6] = ":pm";
  renc_digs3[7] = ":pmm";
  renc_digs3[8] = ":pmmm";
  renc_digs3[9] = ":pmmmm";

  # Digit 4 length distribution = (0,3,3)
  renc_base4 = 10; renc_mul4 = renc_mul3*renc_base3;
  renc_digs4[0] = ":";
  renc_digs4[1] = ":b";
  renc_digs4[2] = ":bb";
  renc_digs4[3] = ":bbb";
  renc_digs4[4] = ":bbbb";
  renc_digs4[5] = ":f";
  renc_digs4[6] = ":fb";
  renc_digs4[7] = ":fbb";
  renc_digs4[8] = ":fbbb";
  renc_digs4[9] = ":fbbbb";

  renc_max_num = renc_mul4 * renc_base4 - 1;
  renc_max_code = renc_encode(renc_max_num);
}