
#include "RobboLito_def.h"
#include "RobboTotalBase.h"

void EmitTotalFileNames (Type_PiSq * PiSq, char * BUFFER)
{
  int j;
  int v = TotalBaseTable[PiSq->pi[0]][PiSq->pi[1]][PiSq->pi[2]][PiSq->pi[3]];
  if (v != -1)
    {
      RobboTotalBase* TOTAL;
      v = v & 0xffff;
      TOTAL = TABLE_TOTAL_BASES + v;
      strcat (BUFFER, "COMP.");
      strcat (BUFFER, TOTAL->string);
      strcat (BUFFER, " ");
      for (j = 0; j < 4; j++)
	if (TOTAL->efgh[j] != -1 && TOTAL->efgh[j] != 0xffff)
	  {
	    int w = TOTAL->efgh[j] & 0xffff;
	    if (w == v)
	      continue;
	    strcat (BUFFER, "COMP.");
	    strcat (BUFFER, (TABLE_TOTAL_BASES + w)->string);
	    strcat (BUFFER, " ");
	  }
    }
}

void TotalFileInfo (RobboTotalBase*, char *);

void EmitTotalFilesInfo (Type_PiSq * PiSq, char * BUFFER)
{
  int v, i;
  RobboTotalBase* TOTAL;
  if (!PiSq->wtm)
    for (i = 0; i < 4; i++)
      PiSq->pi[i] = col_scamb[PiSq->pi[i]];
  v = TotalBaseTable[PiSq->pi[0]][PiSq->pi[1]][PiSq->pi[2]][PiSq->pi[3]];
  if (!PiSq->wtm)
    for (i = 0; i < 4; i++)
      PiSq->pi[i] = col_scamb[PiSq->pi[i]];
  if (v == -1)
    {
      strcat (BUFFER, "Error in TABLE determinative (Total)\n");
      return;
    }
  v = v & 0xffff;
  TOTAL = TABLE_TOTAL_BASES + v;
  TotalFileInfo (TOTAL, BUFFER);
  for (i = 0; i < 4; i++)
    if (TOTAL->efgh[i] != -1 && TOTAL->efgh[i] != 0xffff)
      {
	int w = TOTAL->efgh[i] & 0xffff;
	if (v == w)
	  continue;
	TotalFileInfo (TABLE_TOTAL_BASES + w, BUFFER);
      }
  strcat (BUFFER, "TotalFilesInfo complete\n\n");
}

void FindMaximalLossExample (RobboTotalBase * , char *);
void TotalFileInfo (RobboTotalBase * TOTAL, char * BUFFER)
{
  char STRING[0x1000];
  sprintf (STRING, "** The file name identifies by %s\n", TOTAL->string);
  strcat (BUFFER, STRING);
  sprintf (STRING, "There are " TYPE_64_BIT " positions\n", TOTAL->pro);
  strcat (BUFFER, STRING);
  sprintf (STRING, "There is %s use of hyperindexes, index count %d\n",
	   TOTAL->BLOCCO_pro == 0x100000 ? "too" : "not", TOTAL->num_indici);
  strcat (BUFFER, STRING);
  sprintf (STRING, "The file sits as %d bytes (%dkb) (%dmb)\n",
	   TOTAL->indici[TOTAL->num_indici - 1],
	   1 + (TOTAL->indici[TOTAL->num_indici - 1] >> 10),
	   1 + (TOTAL->indici[TOTAL->num_indici - 1] >> 20));
  strcat (BUFFER, STRING);
  FindMaximalLossExample (TOTAL, BUFFER);
}

#include "maximal_loss.info"
void FindMaximalLossExample (RobboTotalBase * TOTAL, char * BUFFER)
{
  int i, w = -1;
  char STRING[0x1000];
  for (i = 0; i < LIST_SIZE; i++)
    if (!strcmp (TOTAL->canonical_name, LIST[i].name))
      w = i;
  if (w == -1)
    return;
  sprintf (STRING, "Loss in %d (max) sits as: %s\n", LIST[w].len, LIST[w].str);
  strcat (BUFFER, STRING);
}

