~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to engines/balou/gnome-uri.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: gnome-uri.c 4618 2004-07-14 20:17:58Z benny $ */
 
2
 
 
3
#ifdef HAVE_CONFIG_H
 
4
#include <config.h>
 
5
#endif
 
6
 
 
7
#ifdef HAVE_STRING_H
 
8
#include <string.h>
 
9
#endif
 
10
 
 
11
#include <engines/balou/gnome-uri.h>
 
12
 
 
13
/*** the next three routines are taken straight from gnome-libs so that the
 
14
     gtk-only version can receive drag and drops as well ***/
 
15
/**
 
16
 * gnome_uri_list_free_strings:
 
17
 * @list: A GList returned by gnome_uri_list_extract_uris() or gnome_uri_list_extract_filenames()
 
18
 *
 
19
 * Releases all of the resources allocated by @list.
 
20
 */
 
21
void
 
22
gnome_uri_list_free_strings (GList * list)
 
23
{
 
24
    g_list_foreach (list, (GFunc) g_free, NULL);
 
25
    g_list_free (list);
 
26
}
 
27
 
 
28
/**
 
29
 * gnome_uri_list_extract_uris:
 
30
 * @uri_list: an uri-list in the standard format.
 
31
 *
 
32
 * Returns a GList containing strings allocated with g_malloc
 
33
 * that have been splitted from @uri-list.
 
34
 */
 
35
GList *
 
36
gnome_uri_list_extract_uris (const gchar * uri_list)
 
37
{
 
38
    const gchar *p, *q;
 
39
    gchar *retval;
 
40
    GList *result = NULL;
 
41
 
 
42
    g_return_val_if_fail (uri_list != NULL, NULL);
 
43
 
 
44
    p = uri_list;
 
45
 
 
46
    /* We don't actually try to validate the URI according to RFC
 
47
     * 2396, or even check for allowed characters - we just ignore
 
48
     * comments and trim whitespace off the ends.  We also
 
49
     * allow LF delimination as well as the specified CRLF.
 
50
     */
 
51
    while (p)
 
52
    {
 
53
        if (*p != '#')
 
54
        {
 
55
            while (g_ascii_isspace ((int) (*p)))
 
56
                p++;
 
57
 
 
58
            q = p;
 
59
            while (*q && (*q != '\n') && (*q != '\r'))
 
60
                q++;
 
61
 
 
62
            if (q > p)
 
63
            {
 
64
                q--;
 
65
                while (q > p && g_ascii_isspace ((int) (*q)))
 
66
                    q--;
 
67
 
 
68
                retval = (char *) g_malloc (q - p + 2);
 
69
                strncpy (retval, p, q - p + 1);
 
70
                retval[q - p + 1] = '\0';
 
71
 
 
72
                result = g_list_prepend (result, retval);
 
73
            }
 
74
        }
 
75
        p = strchr (p, '\n');
 
76
        if (p)
 
77
            p++;
 
78
    }
 
79
 
 
80
    return g_list_reverse (result);
 
81
}
 
82
 
 
83
 
 
84
/**
 
85
 * gnome_uri_list_extract_filenames:
 
86
 * @uri_list: an uri-list in the standard format
 
87
 *
 
88
 * Returns a GList containing strings allocated with g_malloc
 
89
 * that contain the filenames in the uri-list.
 
90
 *
 
91
 * Note that unlike gnome_uri_list_extract_uris() function, this
 
92
 * will discard any non-file uri from the result value.
 
93
 */
 
94
GList *
 
95
gnome_uri_list_extract_filenames (const gchar * uri_list)
 
96
{
 
97
    GList *tmp_list, *node, *result;
 
98
 
 
99
    g_return_val_if_fail (uri_list != NULL, NULL);
 
100
 
 
101
    result = gnome_uri_list_extract_uris (uri_list);
 
102
 
 
103
    tmp_list = result;
 
104
    while (tmp_list)
 
105
    {
 
106
        gchar *s = (char *) tmp_list->data;
 
107
 
 
108
        node = tmp_list;
 
109
        tmp_list = tmp_list->next;
 
110
 
 
111
        if (!strncmp (s, "file:", 5))
 
112
        {
 
113
            /* added by Jasper Huijsmans
 
114
               remove leading multiple slashes */
 
115
            if (!strncmp (s + 5, "///", 3))
 
116
                node->data = g_strdup (s + 7);
 
117
            else
 
118
                node->data = g_strdup (s + 5);
 
119
        }
 
120
        else
 
121
        {
 
122
            node->data = g_strdup (s);
 
123
        }
 
124
        g_free (s);
 
125
    }
 
126
    return result;
 
127
}
 
128
 
 
129
 
 
130