Back to index

libcitadel  8.12
Typedefs | Functions
xdgmimealias.h File Reference
#include "xdgmime.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct XdgAliasList

Functions

void _xdg_mime_alias_read_from_file (XdgAliasList *list, const char *file_name)
XdgAliasList_xdg_mime_alias_list_new (void)
void _xdg_mime_alias_list_free (XdgAliasList *list)
const char * _xdg_mime_alias_list_lookup (XdgAliasList *list, const char *alias)
void _xdg_mime_alias_list_dump (XdgAliasList *list)

Typedef Documentation

typedef struct XdgAliasList

Definition at line 33 of file xdgmimealias.h.


Function Documentation

Definition at line 169 of file xdgmimealias.c.

{
  int i;

  if (list->aliases)
    {
      for (i = 0; i < list->n_aliases; i++)
       {
         printf ("%s %s\n", 
                list->aliases[i].alias,
                list->aliases[i].mime_type);
       }
    }
}

Here is the caller graph for this function:

Definition at line 76 of file xdgmimealias.c.

{
  int i;

  if (list->aliases)
    {
      for (i = 0; i < list->n_aliases; i++)
       {
         free (list->aliases[i].alias);
         free (list->aliases[i].mime_type);
       }
      free (list->aliases);
    }
  free (list);
}

Here is the caller graph for this function:

const char* _xdg_mime_alias_list_lookup ( XdgAliasList list,
const char *  alias 
)

Definition at line 99 of file xdgmimealias.c.

{
  XdgAlias *entry;
  XdgAlias key;

  if (list->n_aliases > 0)
    {
      key.alias = (char *)alias;
      key.mime_type = NULL;

      entry = bsearch (&key, list->aliases, list->n_aliases,
                     sizeof (XdgAlias), alias_entry_cmp);
      if (entry)
        return entry->mime_type;
    }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 63 of file xdgmimealias.c.

{
  XdgAliasList *list;

  list = malloc (sizeof (XdgAliasList));

  list->aliases = NULL;
  list->n_aliases = 0;

  return list;
}

Here is the caller graph for this function:

void _xdg_mime_alias_read_from_file ( XdgAliasList list,
const char *  file_name 
)

Definition at line 120 of file xdgmimealias.c.

{
  FILE *file;
  char line[255];
  int alloc;

  file = fopen (file_name, "r");

  if (file == NULL)
    return;

  /* FIXME: Not UTF-8 safe.  Doesn't work if lines are greater than 255 chars.
   * Blah */
  alloc = list->n_aliases + 16;
  list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias));
  while (fgets (line, 255, file) != NULL)
    {
      char *sep;
      if (line[0] == '#')
       continue;

      sep = strchr (line, ' ');
      if (sep == NULL)
       continue;
      *(sep++) = '\000';
      sep[strlen (sep) -1] = '\000';
      if (list->n_aliases == alloc)
       {
         alloc <<= 1;
         list->aliases = realloc (list->aliases, 
                               alloc * sizeof (XdgAlias));
       }
      list->aliases[list->n_aliases].alias = strdup (line);
      list->aliases[list->n_aliases].mime_type = strdup (sep);
      list->n_aliases++;
    }
  list->aliases = realloc (list->aliases, 
                        list->n_aliases * sizeof (XdgAlias));

  fclose (file);  
  
  if (list->n_aliases > 1)
    qsort (list->aliases, list->n_aliases, 
           sizeof (XdgAlias), alias_entry_cmp);
}

Here is the call graph for this function:

Here is the caller graph for this function: