Skip to content

Commit c3de091

Browse files
committed
treewide: Format entire codebase
Format all .c and .h files using rules from .clang-format but ignore paths defined in .clangformatignore file. Format all .cmake and CMakeLists.txt files using rules from cmake-format.py but ignore paths defined in .cmakeformatignore file. The current changes result from executing: ./format.sh in the repository's top-level directory. Signed-off-by: Dan Nechita <[email protected]>
1 parent 4e41af5 commit c3de091

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+7057
-6530
lines changed

CMakeLists.txt

Lines changed: 653 additions & 572 deletions
Large diffs are not rendered by default.

attr.c

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
* Author: Paul Cercueil <[email protected]>
77
*/
88

9-
#include "iio-private.h"
10-
#include "sort.h"
11-
12-
#include <inttypes.h>
139
#include <errno.h>
10+
#include <inttypes.h>
1411
#include <stdio.h>
1512
#include <string.h>
1613

17-
static inline unsigned int attr_index(const struct iio_attr_list *list,
18-
const struct iio_attr *attr)
14+
#include "iio-private.h"
15+
#include "sort.h"
16+
17+
static inline unsigned int attr_index(
18+
const struct iio_attr_list *list, const struct iio_attr *attr)
1919
{
2020
uintptr_t diff = (uintptr_t)attr - (uintptr_t)list->attrs;
2121
return (unsigned int)diff / sizeof(*attr);
@@ -28,7 +28,8 @@ ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len)
2828

2929
if (attr->type == IIO_ATTR_TYPE_CONTEXT) {
3030
idx = attr_index(&attr->iio.ctx->attrlist, attr);
31-
return (ssize_t) iio_strlcpy(dst, attr->iio.ctx->values[idx], len);
31+
return (ssize_t)iio_strlcpy(
32+
dst, attr->iio.ctx->values[idx], len);
3233
}
3334

3435
if (dev->ctx->ops->read_attr)
@@ -45,7 +46,7 @@ int iio_attr_read_longlong(const struct iio_attr *attr, long long *val)
4546

4647
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
4748
if (ret < 0)
48-
return (int) ret;
49+
return (int)ret;
4950

5051
errno = 0;
5152
value = strtoll(buf, &end, 0);
@@ -75,13 +76,13 @@ int iio_attr_read_double(const struct iio_attr *attr, double *val)
7576

7677
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
7778
if (ret < 0)
78-
return (int) ret;
79+
return (int)ret;
7980

8081
return read_double(buf, val);
8182
}
8283

83-
ssize_t iio_attr_write_raw(const struct iio_attr *attr,
84-
const void *src, size_t len)
84+
ssize_t iio_attr_write_raw(
85+
const struct iio_attr *attr, const void *src, size_t len)
8586
{
8687
const struct iio_device *dev = iio_attr_get_device(attr);
8788

@@ -96,7 +97,8 @@ ssize_t iio_attr_write_raw(const struct iio_attr *attr,
9697

9798
ssize_t iio_attr_write_string(const struct iio_attr *attr, const char *src)
9899
{
99-
return iio_attr_write_raw(attr, src, strlen(src) + 1); /* Flawfinder: ignore */
100+
return iio_attr_write_raw(
101+
attr, src, strlen(src) + 1); /* Flawfinder: ignore */
100102
}
101103

102104
int iio_attr_write_longlong(const struct iio_attr *attr, long long val)
@@ -108,18 +110,18 @@ int iio_attr_write_longlong(const struct iio_attr *attr, long long val)
108110
len = iio_snprintf(buf, sizeof(buf), "%lld", val);
109111
ret = iio_attr_write_raw(attr, buf, len + 1);
110112

111-
return (int) (ret < 0 ? ret : 0);
113+
return (int)(ret < 0 ? ret : 0);
112114
}
113115

114116
int iio_attr_write_double(const struct iio_attr *attr, double val)
115117
{
116118
ssize_t ret;
117119
char buf[1024];
118120

119-
ret = (ssize_t) write_double(buf, sizeof(buf), val);
121+
ret = (ssize_t)write_double(buf, sizeof(buf), val);
120122
if (!ret)
121123
ret = iio_attr_write_string(attr, buf);
122-
return (int) (ret < 0 ? ret : 0);
124+
return (int)(ret < 0 ? ret : 0);
123125
}
124126

125127
int iio_attr_write_bool(const struct iio_attr *attr, bool val)
@@ -131,20 +133,20 @@ int iio_attr_write_bool(const struct iio_attr *attr, bool val)
131133
else
132134
ret = iio_attr_write_raw(attr, "0", 2);
133135

134-
return (int) (ret < 0 ? ret : 0);
136+
return (int)(ret < 0 ? ret : 0);
135137
}
136138

137-
const struct iio_attr *
138-
iio_attr_get(const struct iio_attr_list *attrs, unsigned int idx)
139+
const struct iio_attr *iio_attr_get(
140+
const struct iio_attr_list *attrs, unsigned int idx)
139141
{
140142
if (idx >= attrs->num)
141143
return NULL;
142144

143145
return &attrs->attrs[idx];
144146
}
145147

146-
const struct iio_attr *
147-
iio_attr_find(const struct iio_attr_list *attrs, const char *name)
148+
const struct iio_attr *iio_attr_find(
149+
const struct iio_attr_list *attrs, const char *name)
148150
{
149151
unsigned int i;
150152

@@ -155,20 +157,17 @@ iio_attr_find(const struct iio_attr_list *attrs, const char *name)
155157
return NULL;
156158
}
157159

158-
const char *
159-
iio_attr_get_name(const struct iio_attr *attr)
160+
const char *iio_attr_get_name(const struct iio_attr *attr)
160161
{
161162
return attr->name;
162163
}
163164

164-
const char *
165-
iio_attr_get_filename(const struct iio_attr *attr)
165+
const char *iio_attr_get_filename(const struct iio_attr *attr)
166166
{
167167
return attr->filename;
168168
}
169169

170-
const char *
171-
iio_attr_get_static_value(const struct iio_attr *attr)
170+
const char *iio_attr_get_static_value(const struct iio_attr *attr)
172171
{
173172
unsigned int idx;
174173

@@ -182,8 +181,7 @@ iio_attr_get_static_value(const struct iio_attr *attr)
182181
}
183182

184183
int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
185-
const char *name, const char *filename,
186-
enum iio_attr_type type)
184+
const char *name, const char *filename, enum iio_attr_type type)
187185
{
188186
struct iio_attr *attr;
189187

@@ -206,7 +204,7 @@ int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
206204
attr[attrs->num].filename = iio_strdup(filename);
207205

208206
if (!attr[attrs->num].filename) {
209-
free((char *) attr[attrs->num].name);
207+
free((char *)attr[attrs->num].name);
210208
return -ENOMEM;
211209
}
212210
} else {
@@ -220,16 +218,18 @@ int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
220218
return 0;
221219
}
222220

223-
static const char * const attr_type_string[] = {
221+
static const char *const attr_type_string[] = {
224222
"",
225223
" debug",
226224
" buffer",
227225
};
228226

229-
int iio_device_add_attr(struct iio_device *dev,
230-
const char *name, enum iio_attr_type type)
227+
int iio_device_add_attr(struct iio_device *dev, const char *name,
228+
enum iio_attr_type type)
231229
{
232-
union iio_pointer p = { .dev = dev, };
230+
union iio_pointer p = {
231+
.dev = dev,
232+
};
233233
int ret;
234234

235235
ret = iio_add_attr(p, &dev->attrlist[type], name, NULL, type);
@@ -240,26 +240,30 @@ int iio_device_add_attr(struct iio_device *dev,
240240
return 0;
241241
}
242242

243-
int iio_channel_add_attr(struct iio_channel *chn,
244-
const char *name, const char *filename)
243+
int iio_channel_add_attr(
244+
struct iio_channel *chn, const char *name, const char *filename)
245245
{
246-
union iio_pointer p = { .chn = chn, };
246+
union iio_pointer p = {
247+
.chn = chn,
248+
};
247249
int ret;
248250

249251
ret = iio_add_attr(p, &chn->attrlist, name, filename,
250-
IIO_ATTR_TYPE_CHANNEL);
252+
IIO_ATTR_TYPE_CHANNEL);
251253
if (ret < 0)
252254
return ret;
253255

254256
chn_dbg(chn, "Added attr \'%s\' (\'%s\')\n", name, filename);
255257
return 0;
256258
}
257259

258-
int iio_context_add_attr(struct iio_context *ctx,
259-
const char *key, const char *value)
260+
int iio_context_add_attr(
261+
struct iio_context *ctx, const char *key, const char *value)
260262
{
261263
char **values, *new_val;
262-
union iio_pointer p = { .ctx = ctx, };
264+
union iio_pointer p = {
265+
.ctx = ctx,
266+
};
263267
unsigned int i;
264268
int ret;
265269

@@ -268,7 +272,7 @@ int iio_context_add_attr(struct iio_context *ctx,
268272
return -ENOMEM;
269273

270274
for (i = 0; i < ctx->attrlist.num; i++) {
271-
if(!strcmp(ctx->attrlist.attrs[i].name, key)) {
275+
if (!strcmp(ctx->attrlist.attrs[i].name, key)) {
272276
free(ctx->values[i]);
273277
ctx->values[i] = new_val;
274278
return 0;
@@ -306,7 +310,8 @@ int iio_context_add_attr(struct iio_context *ctx,
306310
causing subsequent attributes to shift forward as they were already sorted */
307311
if (new_idx != ctx->attrlist.num - 1) {
308312
memmove(&ctx->values[new_idx + 1], &ctx->values[new_idx],
309-
(ctx->attrlist.num - new_idx - 1) * sizeof(*ctx->values));
313+
(ctx->attrlist.num - new_idx - 1) *
314+
sizeof(*ctx->values));
310315
ctx->values[new_idx] = new_val;
311316
}
312317

@@ -316,9 +321,9 @@ int iio_context_add_attr(struct iio_context *ctx,
316321
void iio_free_attr_data(struct iio_attr *attr)
317322
{
318323
if (attr->filename != attr->name)
319-
free((char *) attr->filename);
324+
free((char *)attr->filename);
320325

321-
free((char *) attr->name);
326+
free((char *)attr->name);
322327

323328
attr->filename = NULL;
324329
attr->name = NULL;
@@ -334,7 +339,8 @@ void iio_free_attrs(const struct iio_attr_list *attrs)
334339
free(attrs->attrs);
335340
}
336341

337-
int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, double *max)
342+
int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step,
343+
double *max)
338344
{
339345
double lmin, lstep, lmax;
340346
char extra;
@@ -350,11 +356,12 @@ int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, d
350356
char buf[MAX_ATTR_VALUE];
351357
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
352358
if (ret < 0)
353-
return (int) ret;
359+
return (int)ret;
354360

355-
// Expect format: [min step max]
361+
// Expect format: [min step max]
356362
#if defined(_MSC_VER)
357-
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra, (unsigned int)sizeof(extra));
363+
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra,
364+
(unsigned int)sizeof(extra));
358365
#else
359366
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra);
360367
#endif
@@ -370,7 +377,8 @@ int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, d
370377
return 0;
371378
}
372379

373-
int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *count)
380+
int iio_attr_get_available(
381+
const struct iio_attr *attr, char ***list, size_t *count)
374382
{
375383
size_t n = 0;
376384
size_t capacity = 4;
@@ -400,7 +408,8 @@ int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *co
400408
while (token) {
401409
if (n >= capacity) {
402410
capacity *= 2;
403-
char **tmp = (char **)realloc(local_list, capacity * sizeof(char *));
411+
char **tmp = (char **)realloc(
412+
local_list, capacity * sizeof(char *));
404413
if (!tmp) {
405414
// Free previously allocated strings
406415
size_t i = 0;
@@ -418,7 +427,7 @@ int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *co
418427
*list = local_list;
419428
*count = n;
420429

421-
return 0;
430+
return 0;
422431
}
423432

424433
void iio_available_list_free(char **list, size_t count)
@@ -434,7 +443,7 @@ void iio_available_list_free(char **list, size_t count)
434443
}
435444

436445
int iio_attr_get_available_buf(const struct iio_attr *attr, char *buf,
437-
size_t buflen, char **list, size_t *count)
446+
size_t buflen, char **list, size_t *count)
438447
{
439448
ssize_t ret;
440449
size_t n = 0, max = (size_t)-1;
@@ -450,7 +459,8 @@ int iio_attr_get_available_buf(const struct iio_attr *attr, char *buf,
450459
if (list && count)
451460
max = *count;
452461
else if (list && !count)
453-
max = buflen / 2 + 1; // heuristic: max tokens if all single chars and spaces
462+
max = buflen / 2 +
463+
1; // heuristic: max tokens if all single chars and spaces
454464

455465
ret = iio_attr_read_raw(attr, buf, buflen);
456466
if (ret < 0)

attr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ struct iio_attr_list;
1515
struct iio_context;
1616
struct iio_device;
1717

18-
const struct iio_attr *
19-
iio_attr_get(const struct iio_attr_list *attrs, unsigned int idx);
20-
const struct iio_attr *
21-
iio_attr_find(const struct iio_attr_list *attrs, const char *name);
18+
const struct iio_attr *iio_attr_get(
19+
const struct iio_attr_list *attrs, unsigned int idx);
20+
const struct iio_attr *iio_attr_find(
21+
const struct iio_attr_list *attrs, const char *name);
2222

2323
void iio_free_attr_data(struct iio_attr *attr);
2424
void iio_free_attrs(const struct iio_attr_list *attrs);
2525

2626
int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
27-
const char *name, const char *filename,
28-
enum iio_attr_type type);
27+
const char *name, const char *filename,
28+
enum iio_attr_type type);
2929

3030
#endif /* __IIO_ATTR_H__ */

backend.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* Author: Paul Cercueil <[email protected]>
77
*/
88

9+
#include <string.h>
10+
911
#include "dynamic.h"
1012
#include "iio-config.h"
1113
#include "iio-private.h"
1214

13-
#include <string.h>
14-
1515
unsigned int iio_get_builtin_backends_count(void)
1616
{
1717
unsigned int i, count = 0;
@@ -22,7 +22,7 @@ unsigned int iio_get_builtin_backends_count(void)
2222
return count;
2323
}
2424

25-
const char * iio_get_builtin_backend(unsigned int index)
25+
const char *iio_get_builtin_backend(unsigned int index)
2626
{
2727
unsigned int i;
2828

@@ -36,8 +36,8 @@ const char * iio_get_builtin_backend(unsigned int index)
3636
return NULL;
3737
}
3838

39-
bool
40-
iio_has_backend(const struct iio_context_params *params, const char *backend)
39+
bool iio_has_backend(
40+
const struct iio_context_params *params, const char *backend)
4141
{
4242
unsigned int i;
4343

0 commit comments

Comments
 (0)