Debian Codegraph @

src/cfg_encoder.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2015, 2020 Moritz Grimm <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:410:9`!
18 # include "config.h"cxx . . $ `<file>/src/config.h`/
19 #endif /* HAVE_CONFIG_H */
20
21 #include <sys/queue.h>
22
23 #include <assert.h>
24 #include <string.h>
25
26 #include "cfg_private.h"cxx . . $ `<file>/src/cfg_private.h`/
27 #include "cfg_encoder.h"cxx . . $ `<file>/src/cfg_encoder.h`/
28 #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/
29
30 struct cfg_encodercxx . . $ cfg_encoder# {
31 TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(cfg_encoder) entrycxx . . $ cfg_encoder#entry.;
32 char *namecxx . . $ cfg_encoder#name.;
33 enum cfg_stream_formatcxx . . $ cfg_stream_format# formatcxx . . $ cfg_encoder#format.;
34 char *programcxx . . $ cfg_encoder#program.;
35 };
36
37 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(cfg_encoder_list, cfg_encoder);
38
39 struct cfg_encoder_listcxx . . $ cfg_encoder_list# *
40 cfg_encoder_list_createcxx . . $ cfg_encoder_list_create(e957721effb49cb3).(void)
41 {
42 struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el;
43
44 el = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*el));
45 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(el);
46
47 return (el);
48 }
49
50 void
51 cfg_encoder_list_destroycxx . . $ cfg_encoder_list_destroy(a93b2e622c4c8dd9).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# **el_p)
52 {
53 struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el = *el_p;
54 struct cfg_encodercxx . . $ cfg_encoder# *e;
55
56 if (!el)
57 return;
58
59 while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != (e = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(el)))
60 cfg_encoder_list_removecxx . . $ cfg_encoder_list_remove(70764e441ead9ae8).(el, &e);
61
62 xfreecxx . . $ `src/xalloc.h:26:9`!(el);
63 *el_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
64 }
65
66 unsigned int
67 cfg_encoder_list_nentriescxx . . $ cfg_encoder_list_nentries(4e06232d918433dd).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el)
68 {
69 struct cfg_encodercxx . . $ cfg_encoder# *e;
70 unsigned int n = 0;
71
72 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, el, entry) {
73 n++;
74 }
75
76 return (n);
77 }
78
79 struct cfg_encodercxx . . $ cfg_encoder# *
80 cfg_encoder_list_findcxx . . $ cfg_encoder_list_find(b613e7b3f606ecd3).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el, const char *name)
81 {
82 struct cfg_encodercxx . . $ cfg_encoder# *e;
83
84 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, el, entry) {
85 if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(e->namecxx . . $ cfg_encoder#name., name))
86 return (e);
87 }
88
89 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
90 }
91
92 struct cfg_encodercxx . . $ cfg_encoder# *
93 cfg_encoder_list_getcxx . . $ cfg_encoder_list_get(b613e7b3f606ecd3).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el, const char *name)
94 {
95 struct cfg_encodercxx . . $ cfg_encoder# *e;
96
97 e = cfg_encoder_list_findcxx . . $ cfg_encoder_list_find(b613e7b3f606ecd3).(el, name);
98 if (e)
99 return (e);
100 e = cfg_encoder_createcxx . . $ cfg_encoder_create(24b92a03ca98d343).(name);
101 if (!e)
102 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
103
104 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(el, e, entry);
105
106 return (e);
107 }
108
109 void
110 cfg_encoder_list_foreachcxx . . $ cfg_encoder_list_foreach(c1e243580f4f7a3).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el,
111 void (*cb)(cfg_encoder_tcxx . . $ cfg_encoder_t#, void *), void *cb_arg)
112 {
113 struct cfg_encodercxx . . $ cfg_encoder# *e;
114
115 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, el, entry) {
116 cb(e, cb_arg);
117 }
118 }
119
120 void
121 cfg_encoder_list_removecxx . . $ cfg_encoder_list_remove(70764e441ead9ae8).(struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el, struct cfg_encodercxx . . $ cfg_encoder# **e_p)
122 {
123 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(el, *e_p, entry);
124 cfg_encoder_destroycxx . . $ cfg_encoder_destroy(858ed67e554b4dbe).(e_p);
125 }
126
127 struct cfg_encodercxx . . $ cfg_encoder# *
128 cfg_encoder_createcxx . . $ cfg_encoder_create(24b92a03ca98d343).(const char *name)
129 {
130 struct cfg_encodercxx . . $ cfg_encoder# *e;
131
132 if (!name || !name[0])
133 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
134
135 e = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*e));
136 e->namecxx . . $ cfg_encoder#name. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(name);
137
138 return (e);
139 }
140
141 void
142 cfg_encoder_destroycxx . . $ cfg_encoder_destroy(858ed67e554b4dbe).(struct cfg_encodercxx . . $ cfg_encoder# **e_p)
143 {
144 struct cfg_encodercxx . . $ cfg_encoder# *e = *e_p;
145
146 xfreecxx . . $ `src/xalloc.h:26:9`!(e->name);
147 xfreecxx . . $ `src/xalloc.h:26:9`!(e->program);
148 xfreecxx . . $ `src/xalloc.h:26:9`!(e);
149 *e_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
150 }
151
152 int
153 cfg_encoder_set_formatcxx . . $ cfg_encoder_set_format(d87f1746df6ab51).(struct cfg_encodercxx . . $ cfg_encoder# *e, enum cfg_stream_formatcxx . . $ cfg_stream_format# fmt)
154 {
155 assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(CFG_STREAM_MIN <= fmt && CFG_STREAM_MAX >= fmt);
156 e->formatcxx . . $ cfg_encoder#format. = fmt;
157 return (0);
158 }
159
160 int
161 cfg_encoder_set_namecxx . . $ cfg_encoder_set_name(1b511630c26358c1).(struct cfg_encodercxx . . $ cfg_encoder# *e, struct cfg_encoder_listcxx . . $ cfg_encoder_list# *el,
162 const char *name, const char **errstrp)
163 {
164 struct cfg_encodercxx . . $ cfg_encoder# *e2;
165
166 if (!name || !name[0]) {
167 if (errstrp)
168 *errstrp = "empty";
169 return (-1);
170 }
171
172 e2 = cfg_encoder_list_findcxx . . $ cfg_encoder_list_find(b613e7b3f606ecd3).(el, name);
173 if (e2 && e2 != e) {
174 if (errstrp)
175 *errstrp = "already exists";
176 return (-1);
177 }
178
179 SET_XSTRDUPcxx . . $ `src/cfg_private.h:71:9`!(e->name, name, errstrp);
180
181 return (0);
182 }
183
184 int
185 cfg_encoder_set_format_strcxx . . $ cfg_encoder_set_format_str(1b511630c26358c1).(struct cfg_encodercxx . . $ cfg_encoder# *e,
186 struct cfg_encoder_listcxx . . $ cfg_encoder_list# *not_used, const char *fmt_str,
187 const char **errstrp)
188 {
189 enum cfg_stream_formatcxx . . $ cfg_stream_format# fmt;
190
191 (void)not_used;
192
193 if (!fmt_str || !fmt_str[0]) {
194 if (errstrp)
195 *errstrp = "empty";
196 return (-1);
197 }
198
199 if (0 > cfg_stream_str2fmtcxx . . $ cfg_stream_str2fmt(f0e7c7a61906323).(fmt_str, &fmt)) {
200 if (errstrp)
201 *errstrp = "unsupported stream format";
202 return (-1);
203 }
204
205 cfg_encoder_set_formatcxx . . $ cfg_encoder_set_format(d87f1746df6ab51).(e, fmt);
206
207 return (0);
208 }
209
210 int
211 cfg_encoder_set_programcxx . . $ cfg_encoder_set_program(1b511630c26358c1).(struct cfg_encodercxx . . $ cfg_encoder# *e,
212 struct cfg_encoder_listcxx . . $ cfg_encoder_list# *not_used, const char *program,
213 const char **errstrp)
214 {
215 (void)not_used;
216
217 if (!program || !program[0]) {
218 if (errstrp)
219 *errstrp = "empty";
220 return (-1);
221 }
222
223 xfreecxx . . $ `src/xalloc.h:26:9`!(e->program);
224 e->programcxx . . $ cfg_encoder#program. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(program);
225
226 return (0);
227 }
228
229 int
230 cfg_encoder_validatecxx . . $ cfg_encoder_validate(f08003ba3ba72319).(struct cfg_encodercxx . . $ cfg_encoder# *e, const char **errstrp)
231 {
232 if (CFG_STREAM_INVALIDcxx . . $ CFG_STREAM_INVALID. == e->formatcxx . . $ cfg_encoder#format.) {
233 if (errstrp)
234 *errstrp = "format not set";
235 return (-1);
236 }
237
238 if (!e->programcxx . . $ cfg_encoder#program.) {
239 if (errstrp)
240 *errstrp = "program not set";
241 return (-1);
242 }
243
244 CHECKPH_PROHIBITEDcxx . . $ `src/cfg_private.h:142:9`!(e->program, PLACEHOLDER_TRACKcxx . . $ `src/cfg.h:24:9`!);
245 CHECKPH_PROHIBITEDcxx . . $ `src/cfg_private.h:142:9`!(e->program, PLACEHOLDER_STRINGcxx . . $ `src/cfg.h:25:9`!);
246 CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(e->program, PLACEHOLDER_METADATAcxx . . $ `src/cfg.h:20:9`!);
247 CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(e->program, PLACEHOLDER_ARTISTcxx . . $ `src/cfg.h:21:9`!);
248 CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(e->program, PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!);
249
250 return (0);
251 }
252
253 const char *
254 cfg_encoder_get_namecxx . . $ cfg_encoder_get_name(7eb039d546b1e15a).(struct cfg_encodercxx . . $ cfg_encoder# *e)
255 {
256 return (e->namecxx . . $ cfg_encoder#name.);
257 }
258
259 enum cfg_stream_formatcxx . . $ cfg_stream_format#
260 cfg_encoder_get_formatcxx . . $ cfg_encoder_get_format(76138bec6eb128bf).(struct cfg_encodercxx . . $ cfg_encoder# *e)
261 {
262 return (e->formatcxx . . $ cfg_encoder#format.);
263 }
264
265 const char *
266 cfg_encoder_get_programcxx . . $ cfg_encoder_get_program(7eb039d546b1e15a).(struct cfg_encodercxx . . $ cfg_encoder# *e)
267 {
268 return (e->programcxx . . $ cfg_encoder#program.);
269 }