Back to index

libcitadel  8.12
Typedefs | Enumerations | Functions
xdgmimeglob.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 XdgGlobHash

Enumerations

enum  XdgGlobType { XDG_GLOB_LITERAL, XDG_GLOB_SIMPLE, XDG_GLOB_FULL }

Functions

void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, const char *file_name)
XdgGlobHash_xdg_glob_hash_new (void)
void _xdg_glob_hash_free (XdgGlobHash *glob_hash)
int _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, const char *text, const char *mime_types[], int n_mime_types)
void _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, const char *glob, const char *mime_type)
XdgGlobType _xdg_glob_determine_type (const char *glob)
void _xdg_glob_hash_dump (XdgGlobHash *glob_hash)

Typedef Documentation

typedef struct XdgGlobHash

Definition at line 33 of file xdgmimeglob.h.


Enumeration Type Documentation

Enumerator:
XDG_GLOB_LITERAL 
XDG_GLOB_SIMPLE 
XDG_GLOB_FULL 

Definition at line 35 of file xdgmimeglob.h.

{
  XDG_GLOB_LITERAL, /* Makefile */
  XDG_GLOB_SIMPLE,  /* *.gif */
  XDG_GLOB_FULL     /* x*.[ch] */
} XdgGlobType;

Function Documentation

XdgGlobType _xdg_glob_determine_type ( const char *  glob)

Definition at line 440 of file xdgmimeglob.c.

{
  const char *ptr;
  int maybe_in_simple_glob = FALSE;
  int first_char = TRUE;

  ptr = glob;

  while (*ptr != '\000')
    {
      if (*ptr == '*' && first_char)
       maybe_in_simple_glob = TRUE;
      else if (*ptr == '\\' || *ptr == '[' || *ptr == '?' || *ptr == '*')
         return XDG_GLOB_FULL;

      first_char = FALSE;
      ptr = _xdg_utf8_next_char (ptr);
    }
  if (maybe_in_simple_glob)
    return XDG_GLOB_SIMPLE;
  else
    return XDG_GLOB_LITERAL;
}

Here is the caller graph for this function:

void _xdg_glob_hash_append_glob ( XdgGlobHash glob_hash,
const char *  glob,
const char *  mime_type 
)

Definition at line 466 of file xdgmimeglob.c.

{
  XdgGlobType type;

  assert (glob_hash != NULL);
  assert (glob != NULL);

  type = _xdg_glob_determine_type (glob);

  switch (type)
    {
    case XDG_GLOB_LITERAL:
      glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type));
      break;
    case XDG_GLOB_SIMPLE:
      glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type);
      break;
    case XDG_GLOB_FULL:
      glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type));
      break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _xdg_glob_hash_dump ( XdgGlobHash glob_hash)

Definition at line 492 of file xdgmimeglob.c.

{
  XdgGlobList *list;
  printf ("LITERAL STRINGS\n");
  if (glob_hash->literal_list == NULL)
    {
      printf ("    None\n");
    }
  else
    {
      for (list = glob_hash->literal_list; list; list = list->next)
       printf ("    %s - %s\n", (char *)list->data, list->mime_type);
    }
  printf ("\nSIMPLE GLOBS\n");
  _xdg_glob_hash_node_dump (glob_hash->simple_node, 4);

  printf ("\nFULL GLOBS\n");
  if (glob_hash->full_list == NULL)
    {
      printf ("    None\n");
    }
  else
    {
      for (list = glob_hash->full_list; list; list = list->next)
       printf ("    %s - %s\n", (char *)list->data, list->mime_type);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _xdg_glob_hash_free ( XdgGlobHash glob_hash)

Definition at line 431 of file xdgmimeglob.c.

{
  _xdg_glob_list_free (glob_hash->literal_list);
  _xdg_glob_list_free (glob_hash->full_list);
  _xdg_glob_hash_free_nodes (glob_hash->simple_node);
  free (glob_hash);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _xdg_glob_hash_lookup_file_name ( XdgGlobHash glob_hash,
const char *  text,
const char *  mime_types[],
int  n_mime_types 
)

Definition at line 340 of file xdgmimeglob.c.

{
  XdgGlobList *list;
  const char *ptr;
  char stopchars[128];
  int i, n;
  XdgGlobHashNode *node;

  /* First, check the literals */

  assert (file_name != NULL && n_mime_types > 0);

  for (list = glob_hash->literal_list; list; list = list->next)
    {
      if (strcmp ((const char *)list->data, file_name) == 0)
       {
         mime_types[0] = list->mime_type;
         return 1;
       }
    }

  i = 0;
  for (node = glob_hash->simple_node; node; node = node->next)
    {
      if (node->character < 128)
       stopchars[i++] = (char)node->character;
    }
  stopchars[i] = '\0';
 
  ptr = strpbrk (file_name, stopchars);
  while (ptr)
    {
      n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ptr, FALSE,
                                          mime_types, n_mime_types);
      if (n > 0)
       return n;
      
      n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ptr, TRUE,
                                          mime_types, n_mime_types);
      if (n > 0)
       return n;
      
      ptr = strpbrk (ptr + 1, stopchars);
    }

  /* FIXME: Not UTF-8 safe */
  n = 0;
  for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next)
    {
      if (fnmatch ((const char *)list->data, file_name, 0) == 0)
       mime_types[n++] = list->mime_type;
    }

  return n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 405 of file xdgmimeglob.c.

{
  XdgGlobHash *glob_hash;

  glob_hash = calloc (1, sizeof (XdgGlobHash));

  return glob_hash;
}

Here is the caller graph for this function:

void _xdg_mime_glob_read_from_file ( XdgGlobHash glob_hash,
const char *  file_name 
)

Definition at line 522 of file xdgmimeglob.c.

{
  FILE *glob_file;
  char line[255];

  glob_file = fopen (file_name, "r");

  if (glob_file == NULL)
    return;

  /* FIXME: Not UTF-8 safe.  Doesn't work if lines are greater than 255 chars.
   * Blah */
  while (fgets (line, 255, glob_file) != NULL)
    {
      char *colon;
      if (line[0] == '#')
       continue;

      colon = strchr (line, ':');
      if (colon == NULL)
       continue;
      *(colon++) = '\000';
      colon[strlen (colon) -1] = '\000';
      _xdg_glob_hash_append_glob (glob_hash, colon, line);
    }

  fclose (glob_file);
}

Here is the call graph for this function:

Here is the caller graph for this function: