80_xdg_glob_list_new (
void)
102 free ((
void *) ptr->
data);
114 const char *mime_type,
121 tmp_element = glob_list;
122 while (tmp_element != NULL)
124 if (strcmp (tmp_element->
data, data) == 0 &&
125 strcmp (tmp_element->
mime_type, mime_type) == 0)
128 tmp_element = tmp_element->
next;
131 new_element = _xdg_glob_list_new ();
132 new_element->
data = data;
134 new_element->
weight = weight;
136 if (glob_list == NULL)
139 tmp_element = glob_list;
140 while (tmp_element->
next != NULL)
141 tmp_element = tmp_element->
next;
143 tmp_element->
next = new_element;
152_xdg_glob_hash_node_new (
void)
158 return glob_hash_node;
166 for (i = 0; i < depth; i++)
169 printf (
"%c", (
char)glob_hash_node->
character);
171 printf (
" - %s %d\n", glob_hash_node->
mime_type, glob_hash_node->
weight);
174 if (glob_hash_node->
child)
175 _xdg_glob_hash_node_dump (glob_hash_node->
child, depth + 1);
176 if (glob_hash_node->
next)
177 _xdg_glob_hash_node_dump (glob_hash_node->
next, depth);
183 const char *mime_type,
192 if ((glob_hash_node == NULL) ||
193 (character < glob_hash_node->character))
195 node = _xdg_glob_hash_node_new ();
197 node->
next = glob_hash_node;
198 glob_hash_node = node;
200 else if (character == glob_hash_node->
character)
202 node = glob_hash_node;
207 int found_node = FALSE;
211 prev_node = glob_hash_node;
212 node = prev_node->
next;
216 if (character < node->character)
218 node = _xdg_glob_hash_node_new ();
221 prev_node->
next = node;
237 node = _xdg_glob_hash_node_new ();
240 prev_node->
next = node;
249 if (strcmp (node->
mime_type, mime_type) != 0)
252 int found_node = FALSE;
257 if (strcmp (child->
mime_type, mime_type) == 0)
267 child = _xdg_glob_hash_node_new ();
287 node->
child = _xdg_glob_hash_insert_ucs4 (node->
child, text, mime_type, weight, case_sensitive);
289 return glob_hash_node;
296 const char *mime_type,
306 node = _xdg_glob_hash_insert_ucs4 (glob_hash_node, unitext, mime_type, weight, case_sensitive);
318 const char *file_name,
320 int case_sensitive_check,
328 if (glob_hash_node == NULL)
331 character = file_name[len - 1];
333 for (node = glob_hash_node; node && character >= node->
character; node = node->
next)
341 n = _xdg_glob_hash_node_lookup_file_name (node->
child,
344 case_sensitive_check,
351 (case_sensitive_check ||
359 while (n < n_mime_types && node && node->character == 0)
362 (case_sensitive_check ||
379static int compare_mime_weight (
const void *a,
const void *b)
387#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
389ascii_tolower (
const char *str)
393 lower = strdup (str);
398 *p++ = ISUPPER (c) ? c -
'A' +
'a' : c;
405 const char *file_name,
406 const char *mime_types[],
418 assert (file_name != NULL && n_mime_types > 0);
422 lower_case = ascii_tolower (file_name);
426 if (strcmp ((
const char *)list->
data, file_name) == 0)
437 strcmp ((
const char *)list->
data, lower_case) == 0)
446 len = strlen (file_name);
447 n = _xdg_glob_hash_node_lookup_file_name (glob_hash->
simple_node, lower_case, len, FALSE,
450 n = _xdg_glob_hash_node_lookup_file_name (glob_hash->
simple_node, file_name, len, TRUE,
455 for (list = glob_hash->
full_list; list && n < n_mime_types; list = list->
next)
457 if (fnmatch ((
const char *)list->
data, file_name, 0) == 0)
467 qsort (mimes, n,
sizeof (
MimeWeight), compare_mime_weight);
469 if (n_mime_types < n)
472 for (i = 0; i < n; i++)
473 mime_types[i] = mimes[i].mime;
500 _xdg_glob_hash_free_nodes (node->
child);
502 _xdg_glob_hash_free_nodes (node->
next);
513 _xdg_glob_list_free (glob_hash->
full_list);
514 _xdg_glob_hash_free_nodes (glob_hash->
simple_node);
522 int maybe_in_simple_glob = FALSE;
523 int first_char = TRUE;
529 if (*ptr ==
'*' && first_char)
530 maybe_in_simple_glob = TRUE;
531 else if (*ptr ==
'\\' || *ptr ==
'[' || *ptr ==
'?' || *ptr ==
'*')
535 ptr = _xdg_utf8_next_char (ptr);
537 if (maybe_in_simple_glob)
547 const char *mime_type,
553 assert (glob_hash != NULL);
554 assert (glob != NULL);
561 glob_hash->
literal_list = _xdg_glob_list_append (glob_hash->
literal_list, strdup (glob), strdup (mime_type), weight, case_sensitive);
564 glob_hash->
simple_node = _xdg_glob_hash_insert_text (glob_hash->
simple_node, glob + 1, mime_type, weight, case_sensitive);
567 glob_hash->
full_list = _xdg_glob_list_append (glob_hash->
full_list, strdup (glob), strdup (mime_type), weight, case_sensitive);
576 printf (
"LITERAL STRINGS\n");
586 printf (
"\nSIMPLE GLOBS\n");
593 _xdg_glob_hash_node_dump (glob_hash->
simple_node, 4);
596 printf (
"\nFULL GLOBS\n");
597 if (!glob_hash || glob_hash->
full_list == NULL)
611 const char *file_name,
618 glob_file = fopen (file_name,
"r");
620 if (glob_file == NULL)
625 while (fgets (line, 255, glob_file) != NULL)
628 char *mimetype, *glob, *end;
632 if (line[0] ==
'#' || line[0] == 0)
635 end = line + strlen(line) - 1;
642 colon = strchr (p,
':');
652 colon = strchr (p,
':');
660 case_sensitive = FALSE;
662 colon = strchr (p,
':');
663 if (version_two && colon != NULL)
672 colon = strchr (p,
':');
676 flag = strstr (p,
"cs");
684 case_sensitive = TRUE;
XdgGlobList * literal_list
XdgGlobHashNode * simple_node
void _xdg_glob_hash_append_glob(XdgGlobHash *glob_hash, const char *glob, const char *mime_type, int weight, int case_sensitive)
int _xdg_glob_hash_lookup_file_name(XdgGlobHash *glob_hash, const char *file_name, const char *mime_types[], int n_mime_types)
void _xdg_glob_hash_dump(XdgGlobHash *glob_hash)
XdgGlobType _xdg_glob_determine_type(const char *glob)
XdgGlobHash * _xdg_glob_hash_new(void)
void _xdg_mime_glob_read_from_file(XdgGlobHash *glob_hash, const char *file_name, int version_two)
void _xdg_glob_hash_free(XdgGlobHash *glob_hash)
void _xdg_reverse_ucs4(xdg_unichar_t *source, int len)
xdg_unichar_t * _xdg_convert_to_ucs4(const char *source, int *len)
unsigned int xdg_unichar_t