~ubuntu-branches/ubuntu/maverick/zapping/maverick

« back to all changes in this revision

Viewing changes to libtv/control.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-08 11:07:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051108110734-ygvf6uljvgcjmca7
Tags: 0.9.6-1ubuntu1
* Resynchronise with Debian (Closes: #4022):
  - Fix desktop file to not use absolute path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2001-2004 Michael H. Schimek
 
3
 *  Copyright (C) 2000-2003 I�aki Garc�a Etxebarria
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 */
 
19
 
 
20
/* $Id: control.c,v 1.2 2005/07/04 21:56:41 mschimek Exp $ */
 
21
 
 
22
#include <stdlib.h>             /* malloc() */
 
23
#include "misc.h"
 
24
#include "control.h"
 
25
 
 
26
tv_bool
 
27
tv_control_copy                 (tv_control *           dst,
 
28
                                 const tv_control *     src)
 
29
{
 
30
        assert (NULL != dst);
 
31
 
 
32
        if (dst == src) {
 
33
                return TRUE;
 
34
        }
 
35
 
 
36
        CLEAR (*dst);
 
37
 
 
38
        if (!src) {
 
39
                return TRUE;
 
40
        }
 
41
 
 
42
        if (!(dst->label = strdup (src->label))) {
 
43
                return FALSE;
 
44
        }
 
45
 
 
46
        dst->hash       = src->hash;
 
47
        dst->type       = src->type;
 
48
        dst->id         = src->id;
 
49
 
 
50
        if (TV_CONTROL_TYPE_CHOICE == src->type) {
 
51
                unsigned int i;
 
52
 
 
53
                dst->menu = malloc ((src->maximum + 2) * sizeof (*dst->menu));
 
54
                if (!dst->menu) {
 
55
                        tv_control_destroy (dst);
 
56
                        return FALSE;
 
57
                }
 
58
               
 
59
                for (i = 0; i <= (unsigned int) src->maximum; ++i) {
 
60
                        assert (NULL != src->menu[i]);
 
61
 
 
62
                        dst->menu[i] = strdup (src->menu[i]);
 
63
                        if (!dst->menu[i]) {
 
64
                                tv_control_destroy (dst);
 
65
                                return FALSE;
 
66
                        }
 
67
                }
 
68
 
 
69
                dst->menu[i] = NULL;
 
70
        }
 
71
 
 
72
        dst->minimum    = src->minimum;
 
73
        dst->maximum    = src->maximum;
 
74
        dst->step       = src->step;
 
75
        dst->reset      = src->reset;
 
76
 
 
77
        dst->value      = src->value;
 
78
 
 
79
        return TRUE;
 
80
}
 
81
 
 
82
tv_control *
 
83
tv_control_dup                  (const tv_control *     c)
 
84
{
 
85
        tv_control *nc;
 
86
 
 
87
        if (!(nc = malloc (sizeof (*nc)))) {
 
88
                return NULL;
 
89
        }
 
90
 
 
91
        CLEAR (*nc);
 
92
 
 
93
        if (!tv_control_copy (nc, c)) {
 
94
                free (nc);
 
95
                nc = NULL;
 
96
        }
 
97
 
 
98
        return nc;
 
99
}
 
100
 
 
101
void
 
102
tv_control_destroy              (tv_control *           c)
 
103
{
 
104
        assert (NULL != c);
 
105
 
 
106
        tv_callback_delete_all (c->_callback,
 
107
                                /* notify: any */ NULL,
 
108
                                /* destroy: any */ NULL,
 
109
                                /* user_data: any */ NULL,
 
110
                                /* object */ c);
 
111
 
 
112
        if (c->menu) {
 
113
                unsigned int i;
 
114
 
 
115
                for (i = 0; c->menu[i]; ++i) {
 
116
                        free (c->menu[i]);
 
117
                }
 
118
 
 
119
                free (c->menu);
 
120
        }
 
121
 
 
122
        if (c->label)
 
123
                free (c->label);
 
124
 
 
125
        CLEAR (*c);
 
126
}
 
127
 
 
128
void
 
129
tv_control_delete               (tv_control *           c)
 
130
{
 
131
        if (c) {
 
132
                tv_control_destroy (c);
 
133
                free (c);
 
134
        }
 
135
}