Exemplo n.º 1
0
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);
   }
}
Exemplo n.º 2
0
/* m_xrealloc:
 * Wrapper around real realloc call. Returns the new chunk of memory or
 * aborts execution if it couldn't realloc it.
 */
void *m_xrealloc(void *ptr, size_t new_size)
{
   if (!ptr)
      return m_xmalloc(new_size);
   ptr = realloc(ptr, new_size);
   if (!ptr) m_abort(1);
   return ptr;
}
Exemplo n.º 3
0
/* m_replace_filename:
 * Replaces the filename (any text after the last slash or backslash in
 * the string) in the path with the new one. If there's no slash or
 * backslash in the path, path and filename will be concatenated like
 * '%s/%s', path, filename'. Returns the created string, which has to be
 * freed. Usage example:
 *    char *dest = m_replace_filename(argv[2], "out.html");
 */
char *m_replace_filename(const char *path, const char *filename)
{
   char *p;
   assert(path);
   assert(filename);

   p = get_filename(path);
   if(*p) {
      int len = p - path;
      char *temp = m_xmalloc(len + 1 + strlen(filename));
      strncpy(temp, path, len);
      strcpy(temp+len, filename);
      return temp;
   }
   else {
      char *temp = m_xmalloc(strlen(path) + 2 + strlen(filename));
      sprintf(temp, "%s/%s", path, filename);
      return temp;
   }
}
Exemplo n.º 4
0
/* m_replace_extension:
 * Replaces the extension (any text after last dot in string and after last
 * path separator) in path with the new one. If there's no dot in path, path
 * and extension will be concatenated like '"%s.%s", path, extension'.
 * Returns the created string, which has to be freed. Usage example:
 *    char *dest = m_replace_extension(argv[2], "html");
 */
char *m_replace_extension(const char *path, const char *extension)
{
   char *p;
   assert(path);
   assert(extension);

   p = get_extension(path);
   if(*p) {
      int len = p - path;
      char *temp = m_xmalloc(len + 1 + strlen(extension));
      strncpy(temp, path, len);
      strcpy(temp+len, extension);
      return temp;
   }
   else {
      char *temp = m_xmalloc(strlen(path) + 2 + strlen(extension));
      sprintf(temp, "%s.%s", path, extension);
      return temp;
   }
}
Exemplo n.º 5
0
/* m_strdup:
 * Safe wrapper around strdup, always returns the duplicated string.
 */
char *m_strdup(const char *text)
{
   char *p = m_xmalloc(strlen(text)+1);
   return strcpy(p, text);
}