コード例 #1
0
ファイル: langsel.c プロジェクト: gradha/multitet
static void _retrieve_available_languages(void)
{
   int ret;
   struct al_ffblk info;

   _free_available_languages();
   _available_languages = m_xmalloc(sizeof(char*));

   TRACE("Entering retrieve section\n");
   if (!(ret = al_findfirst("??text.cfg", &info, 0))) {
      while (!ret) {
         char lang_code[3];
         char *lang_name = _get_lang_name_from_file(info.name, lang_code);
         TRACE("Found file %s\n", info.name);
         if (lang_name) {
            TRACE("  code %s, name %s\n", lang_code, lang_name);
            _available_languages = m_xrealloc(_available_languages,
               ((_num_available_languages + 1) * 2) * sizeof(char*));
            _available_languages[_num_available_languages*2] = m_strdup(lang_code);
            _available_languages[_num_available_languages*2+1] = lang_name;
            _num_available_languages++;
         }
         ret = al_findnext(&info);
      }
      al_findclose(&info);
   }
}
コード例 #2
0
ファイル: makemisc.c プロジェクト: AntonLanghoff/whitecatlib
/* m_strcat:
 * Special strcat function, which is a mixture of realloc and strcat.
 * The first parameter has to be a pointer to dynamic memory, since it's
 * space will be resized with m_xrealloc (it can be NULL). The second
 * pointer can be any type of string, and will be appended to the first
 * one. This function returns a new pointer to the memory holding both
 * strings.
 */
char *m_strcat(char *dynamic_string, const char *normal_string)
{
   int len;

   if(!dynamic_string)
      return m_strdup(normal_string);

   len = strlen(dynamic_string);
   dynamic_string = m_xrealloc(dynamic_string, 1 + len + strlen(normal_string));
   strcpy(dynamic_string + len, normal_string);
   return dynamic_string;
}
コード例 #3
0
ファイル: makemisc.c プロジェクト: AntonLanghoff/whitecatlib
/* m_fgets:
 * Safe function to read text lines from a file. Returns the read line
 * or NULL when you reach the end of the file or there's a problem.
 */
char *m_fgets(FILE *file)
{
   int read, filled = 0, size = 0;
   char *buf = 0;

   while ((read = getc(file)) != EOF) {
      while (filled + 2 >= size) {
	 size += _CHUNK;
	 buf = m_xrealloc(buf, size);
      }
      if (read != '\r')
	 buf[filled++] = read;
      buf[filled] = 0;

      if (read == '\n')
	 break;
   }

   return buf;
}