1 /* gib_style.c
2 
3 Copyright (C) 1999,2000 Tom Gilbert.
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to
7 deal in the Software without restriction, including without limitation the
8 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 sell copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies of the Software and its documentation and acknowledgment shall be
14 given in the documentation and software packages that this Software was
15 used.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 */
25 
26 #include "gib_style.h"
27 #include "utils.h"
28 #include "debug.h"
29 
30 gib_style *
gib_style_new(char * name)31 gib_style_new(char *name)
32 {
33    gib_style *s = NULL;
34 
35    s = emalloc(sizeof(gib_style));
36 
37    memset(s, 0, sizeof(gib_style));
38    if (name)
39       s->name = strdup(name);
40 
41    return (s);
42 }
43 
44 void
gib_style_free(gib_style * s)45 gib_style_free(gib_style * s)
46 {
47    if (s)
48    {
49       if (s->name)
50          free(s->name);
51       if (s->bits)
52       {
53          gib_list *l;
54 
55          l = s->bits;
56          while (l)
57          {
58             gib_style_bit_free((gib_style_bit *) l->data);
59             l = l->next;
60          }
61          gib_list_free(s->bits);
62       }
63       free(s);
64    }
65    return;
66 }
67 
68 gib_style_bit *
gib_style_bit_new(int x_offset,int y_offset,int r,int g,int b,int a)69 gib_style_bit_new(int x_offset, int y_offset, int r, int g, int b, int a)
70 {
71    gib_style_bit *sb;
72 
73    sb = emalloc(sizeof(gib_style_bit));
74    memset(sb, 0, sizeof(gib_style_bit));
75 
76    sb->x_offset = x_offset;
77    sb->y_offset = y_offset;
78    sb->r = r;
79    sb->g = g;
80    sb->b = b;
81    sb->a = a;
82 
83    return (sb);
84 }
85 
86 void
gib_style_bit_free(gib_style_bit * s)87 gib_style_bit_free(gib_style_bit * s)
88 {
89    if (s)
90       free(s);
91    return;
92 }
93 
94 #if 0
95 gib_style *
96 gib_style_dup(gib_style * s)
97 {
98    gib_style *ret;
99 
100    ret = gib_style_new(s->name);
101    ret->bits = gib_list_dup_special(s->bits, gib_dup_style_bit);
102 
103    return (ret);
104 }
105 
106 void
107 gib_dup_style_bit(void **dest, void *data)
108 {
109    *dest = malloc(sizeof(gib_style_bit));
110    memcpy(*dest, data, sizeof(gib_style_bit));
111 
112    return;
113 }
114 #endif
115