aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-util.c-8611
blob: 2571a0fbc38f20c1370e5255098bb40641ea0687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-xml-utils.c
 * Copyright (C) 2000  Helix Code, Inc.
 * Author: Chris Lahey <clahey@helixcode.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <glib.h>
#include <gtk/gtkobject.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>

#include "e-util.h"

int
g_str_compare(const void *x, const void *y)
{
  return strcmp(x, y);
}

int
g_int_compare(const void *x, const void *y)
{
  if ( GPOINTER_TO_INT(x) < GPOINTER_TO_INT(y) )
    return -1;
  else if ( GPOINTER_TO_INT(x) == GPOINTER_TO_INT(y) )
    return 0;
  else
    return 1;
}

char *
e_strdup_strip(char *string)
{
    int i;
    int length = 0;
    int initial = 0;
    for ( i = 0; string[i]; i++ ) {
        if (initial == i && isspace(string[i])) {
            initial ++;
        }
        if (!isspace(string[i])) {
            length = i - initial + 1;
        }
    }
    return g_strndup(string + initial, length);
}

void
e_free_object_list (GList *list)
{
    GList *p;

    for (p = list; p != NULL; p = p->next)
        gtk_object_unref (GTK_OBJECT (p->data));

    g_list_free (list);
}

void
e_free_string_list (GList *list)
{
    GList *p;

    for (p = list; p != NULL; p = p->next)
        g_free (p->data);

    g_list_free (list);
}

#define BUFF_SIZE 1024

char *
e_read_file(const char *filename)
{
    int fd;
    char buffer[BUFF_SIZE];
    GList *list = NULL, *list_iterator;
    GList *lengths = NULL, *lengths_iterator;
    int length = 0;
    int bytes;
    char *ret_val;

    fd = open(filename, O_RDONLY);
    if (fd == -1)
        return NULL;
    bytes = read(fd, buffer, BUFF_SIZE);
    while (bytes) {
        if (bytes > 0) {
            list = g_list_prepend(list, g_strndup(buffer, bytes));
            lengths = g_list_prepend(lengths, GINT_TO_POINTER(bytes));
            length += bytes;
        } else {
            if (errno != EINTR) {
                close(fd);
                g_list_foreach(list, (GFunc) g_free, NULL);
                g_list_free(list);
                g_list_free(lengths);
                return NULL;
            }
        }
        bytes = read(fd, buffer, BUFF_SIZE);
    }
    ret_val = g_new(char, length + 1);
    ret_val[length] = 0;
    lengths_iterator = lengths;
    list_iterator = list;
    for ( ; list_iterator; list_iterator = list_iterator->next, lengths_iterator = lengths_iterator->next) {
        int this_length = GPOINTER_TO_INT(lengths_iterator->data);
        length -= this_length;
        memcpy(ret_val + length, list_iterator->data, this_length);
    }
    close(fd);
    g_list_foreach(list, (GFunc) g_free, NULL);
    g_list_free(list);
    g_list_free(lengths);
    return ret_val;
}

gint
e_write_file(const char *filename, const char *data, int flags)
{
    int fd;
    int length = strlen(data);
    int bytes;
    fd = open(filename, flags, 0666);
    if (fd == -1)
        return errno;
    while (length > 0) {
        bytes = write(fd, data, length);
        if (bytes > 0) {
            length -= bytes;
            data += bytes;
        } else {
            if (errno != EINTR && errno != EAGAIN) {
                int save_errno = errno;
                close(fd);
                return save_errno;
            }
        }
    }
    close(fd);
    return 0;
}

typedef gint (*GtkSignal_NONE__INT_INT_POINTER) (GtkObject * object,
                         gint arg1,
                         gint arg2,
                         gpointer arg3,
                         gpointer user_data);

void
e_marshal_INT__INT_INT_POINTER (GtkObject * object,
                GtkSignalFunc func,
                gpointer func_data, GtkArg * args)
{
    GtkSignal_NONE__INT_INT_POINTER rfunc;
    gint *return_val;
    return_val = GTK_RETLOC_INT (args[3]);
    rfunc = (GtkSignal_NONE__INT_INT_POINTER) func;
    *return_val = (*rfunc) (object,
                GTK_VALUE_INT (args[0]),
                GTK_VALUE_INT (args[1]), GTK_VALUE_POINTER (args[2]), func_data);
}
s-gnome/commit/ports-mgmt?h=gnome-3.28&id=2626a10f9b6d17c2b9eb1b328b4c26680ad38e0d'>Convert to new options framework ports in p* catoriesbapt2013-03-223-39/+31 * - Update to 0.1.1bdrewery2013-03-223-12/+3 * - Fix build with 7.4bdrewery2013-03-211-8/+6 * - Remove prompt for dialog4ports. Dialog4Ports is abdrewery2013-03-211-0/+6 * Readd the removed by mistake libdialog distinfobapt2013-03-201-0/+2 * Change distfile from tar.xz to tar.gz to be nice with FreeBSD 7 peoplebapt2013-03-202-5/+2 * Convert almost all gnome@ ports to OptionsNG, trim header, use USES=pathfixkwm2013-03-192-43/+29 * - Fix lib/gio/modules/giomodule.cache being seen as a leftoverbdrewery2013-03-182-1/+13 * - Remove the need to patch newvers.sh on revision updates bybdrewery2013-03-182-20/+2 * - Don't use ruby-bdb with ruby 2.0 as it is currentlybdrewery2013-03-182-2/+10 * - Update to checkin e9eb1d10aa which will become 2.4.bdrewery2013-03-183-6/+6 * - Remove needless quoting of BROKEN/IGNOREbdrewery2013-03-161-6/+2 * Fix build on armbapt2013-03-151-0/+11 * - Remove use of bsd.port.pre.mkbdrewery2013-03-152-8/+8 * - Fix crash in pkg-updatebdrewery2013-03-143-0/+48 * - Update to 1.0.9bdrewery2013-03-142-3/+3 * Add a mirrorbapt2013-03-141-0/+1 * Add new dialog4portsbapt2013-03-144-0/+49 * - Update to 2.4.10.5bdrewery2013-03-134-8/+7 * - fastest_cvsup is an outdated authoring tool for ports, move to svnjgh2013-03-131-7/+4 * - really take maintainership now...jgh2013-03-131-1/+1 * - fastest_cvsup is an outdated maintenance tool for ports, move to svnjgh2013-03-131-7/+3 * I really haven't used this in quite some time, so return it to the pool.linimon2013-03-121-2/+2 * - read pkg_info -L information in chunks of 100 packages at a time,mandree2013-03-123-18/+35 * Update to 1.2crees2013-03-122-3/+2 * Bump to version 2.14.2.marcus2013-03-101-2/+1 * Bump to version 2.14.2.marcus2013-03-101-8/+15 * - Use USE_SUBMAKE to fix running 'make build deinstall install' not properlybdrewery2013-03-101-0/+3 * Remove indefinite article from COMMENTehaupt2013-03-081-6/+2 * * Update the glib to 2.34.3 and gtk20 to 2.24.17 and gtk30 to 3.6.4 whichkwm2013-03-081-5/+3 * Fix distinfo after updating versionbdrewery2013-03-081-2/+2 * Use proper versioningbdrewery2013-03-071-2/+1 * - Update to 1.12ak2013-03-072-3/+3 * - Update to checkin 6c357b3bdrewery2013-03-072-4/+4 * - Fix missing dependency on devel/ruby-date2 when using Ruby 1.9bdrewery2013-03-071-0/+6 * Reversed logiccrees2013-03-072-1/+2 * Update to 1.1:crees2013-03-072-8/+6 * - Fix typo in option namedecke2013-03-061-1/+1 * - Update to 4.0.0miwi2013-03-044-83/+61 * - Update to checkin a05c5dabdrewery2013-03-042-4/+4 * 2013-02-27 www/igal: No more upstream, no more public distfiles, consider usi...bapt2013-03-044-40/+0 * Rewrite in sh for version 1.0crees2013-03-035-45/+121 * Take maintainership.crees2013-03-031-1/+1 * Deprecate portdowngrade as it no longer functions as expectedeadler2013-03-031-5/+4 * - Switch the VCS tool for the ports tree from CVS to SVNtota2013-03-0212-120/+259 * - add new port: ports-mgmt/prhistoryjgh2013-03-026-0/+73 * - Update to 1.3culot2013-02-272-8/+4 * pkg uses /usr/share/mk/* framwork to build, so it can be tuned viabapt2013-02-271-1/+1 * - update to 1.0.8bapt2013-02-212-3/+3 * - Fix typos in nginx supportdecke2013-02-181-2/+2 * Convert Makefile headers to the new format.olgeni2013-02-181-4/+1 * - Add support for www/ngnixmiwi2013-02-151-2/+5 * Various spelling correctionscrees2013-02-091-1/+1 * Make it clear that pkgng is optionaleadler2013-02-061-5/+5 * - Fix breakage in the DYNAMIC-enabled ports triggered by the recentpgj2013-02-061-1/+1 * - Fix all cases of 'No newline at end of file' in ports treeak2013-02-011-1/+1 * - Update to 1.0.8.romain2013-01-303-4/+9 * - Update to version 0.4.1 [*]danfe2013-01-293-21/+20 * - update to 1.0.7bapt2013-01-292-3/+3 * Deprecate a bunch of ports with no more upstream and/or no more public distfilesbapt2013-01-271-0/+3 * - Reset ports due to mail bouncestabthorpe2013-01-271-6/+2 * - Don't force pkg as a RUN_DEPENDS. The patch should bebdrewery2013-01-261-4/+1 * - Remove optional dependency on databases/ruby-bdb1 as therebdrewery2013-01-251-20/+1 * - update to 1.0.6bapt2013-01-222-3/+3 * - update to 1.0.5:bapt2013-01-2210-104/+3 * - Update to 1.00gblach2013-01-222-4/+4 * - Update to my new FreeBSD addressdbn2013-01-171-1/+1 * - Update to 2.4.10.4bdrewery2013-01-152-3/+3 * - Tinderbox 4 uses PDO instead of MDB2 for the WebUI [1]beat2013-01-151-8/+4 * - Update to checkin fb8519cbdrewery2013-01-152-4/+4 * - Fix build due to uninitialized variables, whichbdrewery2013-01-145-0/+56 * - Update to checkin a4714af748bdrewery2013-01-142-4/+4 * Udate to 1.0.7.romain2013-01-132-3/+3 * - update to 4.0.0.b2itetcu2013-01-136-117/+56 * Do not install .symbols on currentbapt2013-01-132-0/+25 * - Only show conversion "seatbelt" notice if nobdrewery2013-01-091-1/+8 * 2013-01-04 ports-mgmt/portmanager: Does not support modern ports features suc...bapt2013-01-0622-1088/+0 * - update to 2.2.2rm2013-01-032-4/+4 * - update to 1.72dinoex2013-01-023-13/+8 * - Update to 2.3.1bdrewery2013-01-022-3/+3 * - Update to checkin 428fbcc5bfbdrewery2012-12-312-4/+4 * - Deprecate QT3, KDE3 and unmaintained ports depending on them. QT 3.3.8beat2012-12-301-0/+3 * Update to 2.14.1.marcus2012-12-302-5/+5 * Fix typobapt2012-12-301-1/+1 * Convert romain's ports to new option frameworkbapt2012-12-301-26/+24 * It needs to have the full path in portupgrade dependency.mezz2012-12-301-1/+1 * Convert the remaining ports that depend on databases/p5-DBD-mysql${MYSQL_VER}flo2012-12-292-3/+3 * Update to 2.14.0.marcus2012-12-282-158/+120 * - Update to 2.2.1ak2012-12-252-4/+4 * - Update to checkin 9b1b7438abbdrewery2012-12-242-4/+4 * - Update to 2.2.0beech2012-12-232-4/+4 * - Enable seatbelt again after further testing. It willbdrewery2012-12-231-25/+25 * Temporary disable the seat belt it doesn't play nice with portmasterbapt2012-12-221-25/+25 * - Fix runtime version still showing 1.0.3bdrewery2012-12-222-0/+20 * - update to 1.0.4bapt2012-12-213-19/+29 * - Update The Glorious Glasgow Haskell Compiler to version 7.4.2pgj2012-12-201-5/+2 * - Set default perl version for ports which currently usingaz2012-12-162-2/+2 * - Update to 0.4beech2012-12-163-10/+12 * Trim remaining untrimmed headers on my portsmatthew2012-12-151-6/+1 * Remove the header for ports I created.wxs2012-12-131-5/+0 * Define LICENSEskreuzer2012-12-121-0/+2 * - Convert SINGLE OPTION DB_OVERRIDE to RADIObdrewery2012-12-121-5/+4 * - Update to 2.1.0 [1]culot2012-12-112-9/+5 * Revert Chris Petrik's ports to the pool. Thank you for all your work so far,...eadler2012-12-101-1/+1 * Add a patch to bump the version output bump by pkg -v this was forgotten inbapt2012-12-082-0/+16 * - update to 1.0.3bapt2012-12-072-3/+5 * - Update to 2.4.10.3bdrewery2012-12-072-3/+3 * - Add upstream patch for fixing bash completions with PKGNGbdrewery2012-12-072-1/+47 * - Update to 20121206 snapshotbdrewery2012-12-072-4/+4 * Update to 1.0.6.romain2012-12-062-3/+3 * - Update to 20121205 snapshotbdrewery2012-12-062-4/+4 * Update to 3.0matthew2012-12-042-7/+4 * - Update to 0af89d84d3 checkin to sync with 2.3 releasebdrewery2012-12-022-4/+4 * - Update to 2.3bdrewery2012-12-022-8/+9 * - Update to 20121130 snapshotbdrewery2012-12-012-4/+4 * - Update to checkin 76032fe87dbdrewery2012-11-152-9/+10 * Import an upstream patch to fix build with ccache and nullfs. While here trimehaupt2012-11-092-5/+30 * - Update to 1.2jhale2012-11-083-10/+7 * - update to 1.0.2bapt2012-11-073-3/+10 * - Update to checkin 02876f6378bdrewery2012-11-072-4/+4 * - Change my email address to gblach@FreeBSD.orggblach2012-11-041-2/+2 * - Update to checkin 1f2d4d3281bdrewery2012-11-022-4/+4 * Fix dependence on kde4-runtimemakc2012-11-021-3/+3 * - Fix PKGNG patch trying to call pkg(8) when notbdrewery2012-10-302-1/+21 * - Fix regression which prevented make.conf to be read.avilla2012-10-272-0/+12 * - Update to 0.1.5.4.avilla2012-10-272-8/+5 * works better with the correct distinfobapt2012-10-271-2/+2 * Update to checkins f21e916b8bbapt2012-10-261-2/+2 * - Convert to OptionsNG [1]rakuco2012-10-251-7/+6 * - Update ZSH completions to work on CURRENT with pkgng [1]bdrewery2012-10-212-5/+7 * - Fix WITH_PKGNG detection on CURRENT, as it maybdrewery2012-10-193-2/+16 * - Update to 2.4.10.2bdrewery2012-10-184-7/+7 * - Update to 2.4.10.1bdrewery2012-10-184-7/+7 * - Update to checkin 98a87680a1bdrewery2012-10-172-4/+4 * - Update ZSH completions with pkgng support [1]bdrewery2012-10-162-1/+37 * - Update to check 5ab5434469 to sync with 2.2 releasebdrewery2012-10-162-4/+4 * - Update to 2.2bdrewery2012-10-162-4/+3 * - Add ports-mgmt/pkg as a RUN_DEPENDS if enabling pkgng supportbdrewery2012-10-162-1/+15 * - Rename PKGNG option to PKGNGPATCH to fixbdrewery2012-10-151-4/+4 * - Add backup non-https mirrorbdrewery2012-10-152-1/+12 * - 2.4.10 releasebdrewery2012-10-153-18/+18 * - Update to checkin 9b00ac7bdrewery2012-10-152-10/+6 * - Update to checkin 01f1e98450bdrewery2012-10-152-4/+4 * - cleanup commentsdinoex2012-10-131-5/+0 * - Update to checkin a71cb01551bdrewery2012-10-122-4/+4 * - Update to checkin da583db283bdrewery2012-10-112-4/+4 * - Move to new home, http://github.com/portmasterbdrewery2012-10-103-24/+29 * - update to checkin 06e052c2c9bapt2012-10-102-4/+4 * Update to 2.13.13.marcus2012-10-092-16/+13 * Add a temporary mirrorcs2012-10-081-1/+1 * Throw my ports back in the pool, and make my intentions clear for thedougb2012-10-082-4/+2 * Convert to OptionsNGeadler2012-10-071-9/+6 * Trim the headers in the ports I maintain.eadler2012-10-062-10/+1 * - Update to 1.11ak2012-10-062-3/+3 * - update to checkin: 86c7d4bd7cbapt2012-10-042-5/+5 * Mark as not ccache safebapt2012-10-021-0/+1 * - update to 1.0.1bapt2012-10-012-3/+3 * Fix the problem of background fetches hanging forever when the backgrounddougb2012-10-012-10/+6 * - Update to checkin bf773c11a9bdrewery2012-10-012-4/+4 * - Update to 0.93jhale2012-10-012-3/+3 * - Update to checkin be9b1ebfdebdrewery2012-09-292-4/+4 * - Update to checkin 68465cb21ebdrewery2012-09-262-4/+4 * - Revert committabthorpe2012-09-251-2/+6 * - Reassign to the heap due to mail bouncestabthorpe2012-09-251-6/+2 * Mark as job safebapt2012-09-251-5/+1 * - Update to 1.0kmoore2012-09-243-3/+13 * - update to 0.92rm2012-09-222-10/+6 * - Update to checkin 53ee9ef7a2bdrewery2012-09-222-4/+4 * - Remove USE_STAGE as it is not readybdrewery2012-09-211-1/+0 * - Update to checkin 7a6500c64bbdrewery2012-09-212-5/+4 * - Switch to USE_GITHUB/GH as the primary MASTER_SITE as itbdrewery2012-09-153-7/+10 * - Update to checkin: 0095aaa08ebdrewery2012-09-132-6/+6 * - Update to 2.1.2bdrewery2012-09-132-3/+3 * Add a note to specify that this ports is also maintained by bdrewerybapt2012-09-122-0/+2 * - Update to checkin: a766128118bdrewery2012-09-112-4/+4 * - Update to 2.1.1bdrewery2012-09-112-3/+3 * Update to 0.1.5.3 - 2012 August 19.tj2012-09-112-3/+3 * - update to checkin: 53e6561d62 (this branch will become 2.2)bapt2012-09-102-4/+4 * - update to 2.1.0bapt2012-09-102-8/+6 * Welcome back Chris Petrik <c.petrik.sosa@gmail.com>eadler2012-09-091-1/+1 * - update to checkin: 7befeb3094bapt2012-09-092-9/+6 * - Mark deprecated. portmanager does not support needed ports featuresbdrewery2012-09-061-0/+4 * Remove useless metadata from ports I created.des2012-09-051-7/+0 * - Update to 1.10ak2012-09-042-9/+4 * - update to checkin abeb0b8b2bbapt2012-09-042-4/+5 * - update to checkin 1516db8bc5bapt2012-09-012-9/+4 * - update to 2.0.1bapt2012-09-012-9/+5 * - update to 1.0bapt2012-08-303-15/+3 * - Update to 2.4.9.9bdrewery2012-08-292-3/+3 * - update to 2.0.0bapt2012-08-283-29/+5 * Update to 443d190388 snapshot that is the start of what will become 2.1 releasebapt2012-08-282-4/+4 * - Update to 20120827 snapshotbdrewery2012-08-282-4/+4 * - Update to 0.9.9kmoore2012-08-283-3/+4 * - Update to 2.4.9.8bdrewery2012-08-263-4/+19 * - Fix crash when no PACKAGESITE is defined in pkg.confbdrewery2012-08-242-0/+12 * - update to 35e8e96117 checkinbapt2012-08-242-4/+4 * - Fix prompt sign in pkg-message, pkg2ng must be run as rootgahr2012-08-221-1/+1 * - update to 20120822 snapshotbapt2012-08-222-12/+14 * - Update to 20120821 snapshotbdrewery2012-08-222-4/+4 * - update to checkin: 532008b635bapt2012-08-212-4/+4 * - Update to 20120820 snapshotbdrewery2012-08-212-4/+4 * - update to checkin f18246236dbapt2012-08-192-4/+4 * - remove www/apache20 and devel/apr0ohauer2012-08-182-2/+2 * - update to d000cd0980 checkinbapt2012-08-172-4/+4 * - update to 1.0-rc6bapt2012-08-173-16/+3 * - add a devel version of poudrierebapt2012-08-16