Пример #1
0
/** 
 * Load scrolltext ascii data
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
scrolltext_load (void)
{
  Uint32 filesize, i, j;
  char *filedata;
  filedata = loadfile_with_lang ("texts/scroll_%s.txt", &filesize);
  if (filedata == NULL)
    {
      return FALSE;
    }

  scrolltext_menu = memory_allocation (filesize);
  if (scrolltext_menu == NULL)
    {
      free_memory (filedata);
      return FALSE;
    }

  j = 0;
  for (i = 0; i < filesize; i++)
    {
      if (filedata[i] >= ' ' && filedata[i] != '"')
        {
          scrolltext_menu[j++] = filedata[i];
        }
    }
  free_memory (filedata);
  return TRUE;
}
Пример #2
0
/**
 * Load game texts files 
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
texts_load (void)
{
  Uint32 offset, char_count, start, line_num, filesize;
  char c, *str, *filedata;
  filedata = loadfile_with_lang ("texts/text_%s.txt", &filesize);
  if (filedata == NULL)
    {
      return FALSE;
    }

  /* 
   * caclulate the number of lines 
   */
  offset = 0;
  texts_loaded_count = 0;
  while (offset < filesize)
    {
      if (filedata[offset++] == '\n')
        {
          texts_loaded_count++;
        }
    }
  texts_loaded =
    (char **) memory_allocation (texts_loaded_count * sizeof (char *));
  if (texts_loaded == NULL)
    {
      LOG_ERR ("not enough memory to allocate 'texts_loaded'!");
      return FALSE;
    }

  /* 
   * read line by line
   */
  offset = 0;
  start = offset;
  char_count = 0;
  line_num = 0;
  while (offset < filesize)
    {
      c = filedata[offset++];
      if (c == '\n')
        {
          if (char_count > 0)
            {
              str = memory_allocation (char_count * sizeof (char) + 1);
              if (str == NULL)
                {
                  LOG_ERR ("not enough memory to allocate 'str'!");
                  return FALSE;
                }
              texts_loaded[line_num] = str;
              while (start < offset)
                {
                  if (filedata[start] > ' ')
                    {
                      *(str++) = filedata[start];
                    }
                  start++;
                }
            }
          line_num++;
          start = offset;
          char_count = 0;
        }
      else
        {
          if (c >= ' ')
            {
              char_count++;
            }
        }
    }
  free_memory (filedata);
  return TRUE;
}