#include <string.h>
#include <ctype.h>

#include "shared_cs_util.h"

char *valid_team_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";


#define FIRST_TEAM_LETTER (*valid_team_letters)
#define MAX_TEAM_NAME 5


int is_valid_team(char team)
{
 if(strchr(valid_team_letters,team))
    return 1;
 else 
    return 0;
}

    
        


char next_team_letter(char current_team_letter)
{
 char *ptr;
 
 ptr = strchr(valid_team_letters, current_team_letter);
 if(ptr)
    return *(ptr + 1);
 else
    return (char) 0;
}

       



void
get_team_name(char team, char *name)
{

 if(isupper(team))
  {
   *name = team;
   *(name + 1) = '\0';
  }
 else
   {
    *name = toupper(team);
    *(name + 1) = '-';
    *(name + 2) = *name;
    *(name + 3) = '\0';
   }
}      
   


void
cs_set_team()
{
#define MAX_TMP_NAME 30

   char letter;
   char team[MAX_TMP_NAME];
   char name[MAX_TMP_NAME];
   int i =0;

    for(letter = FIRST_TEAM_LETTER, i = 0; letter; letter=next_team_letter(letter), i++)
    {
      snprintf(name, MAX_TMP_NAME, "team_letter.%d.internal", i);
      snprintf(team, 2, "%c", letter);
      cs_set_value(name, team);
      
      snprintf(name, MAX_TMP_NAME, "team_letter.%d.display", i);
      get_team_name(letter, team);  
      cs_set_value(name, team);
    }
            
      
#undef MAX_TMP_NAME
}



