Skip to content

Commit ad79729

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 <dan.nechita@analog.com>
1 parent 1c9bf8f commit ad79729

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

+5793
-6544
lines changed

CMakeLists.txt

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

attr.c

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
* Author: Paul Cercueil <paul.cercueil@analog.com>
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(const struct iio_attr_list *list, const struct iio_attr *attr)
1918
{
2019
uintptr_t diff = (uintptr_t)attr - (uintptr_t)list->attrs;
2120
return (unsigned int)diff / sizeof(*attr);
@@ -28,7 +27,7 @@ ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len)
2827

2928
if (attr->type == IIO_ATTR_TYPE_CONTEXT) {
3029
idx = attr_index(&attr->iio.ctx->attrlist, attr);
31-
return (ssize_t) iio_strlcpy(dst, attr->iio.ctx->values[idx], len);
30+
return (ssize_t)iio_strlcpy(dst, attr->iio.ctx->values[idx], len);
3231
}
3332

3433
if (dev->ctx->ops->read_attr)
@@ -45,7 +44,7 @@ int iio_attr_read_longlong(const struct iio_attr *attr, long long *val)
4544

4645
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
4746
if (ret < 0)
48-
return (int) ret;
47+
return (int)ret;
4948

5049
errno = 0;
5150
value = strtoll(buf, &end, 0);
@@ -75,13 +74,12 @@ int iio_attr_read_double(const struct iio_attr *attr, double *val)
7574

7675
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
7776
if (ret < 0)
78-
return (int) ret;
77+
return (int)ret;
7978

8079
return read_double(buf, val);
8180
}
8281

83-
ssize_t iio_attr_write_raw(const struct iio_attr *attr,
84-
const void *src, size_t len)
82+
ssize_t iio_attr_write_raw(const struct iio_attr *attr, const void *src, size_t len)
8583
{
8684
const struct iio_device *dev = iio_attr_get_device(attr);
8785

@@ -108,18 +106,18 @@ int iio_attr_write_longlong(const struct iio_attr *attr, long long val)
108106
len = iio_snprintf(buf, sizeof(buf), "%lld", val);
109107
ret = iio_attr_write_raw(attr, buf, len + 1);
110108

111-
return (int) (ret < 0 ? ret : 0);
109+
return (int)(ret < 0 ? ret : 0);
112110
}
113111

114112
int iio_attr_write_double(const struct iio_attr *attr, double val)
115113
{
116114
ssize_t ret;
117115
char buf[1024];
118116

119-
ret = (ssize_t) write_double(buf, sizeof(buf), val);
117+
ret = (ssize_t)write_double(buf, sizeof(buf), val);
120118
if (!ret)
121119
ret = iio_attr_write_string(attr, buf);
122-
return (int) (ret < 0 ? ret : 0);
120+
return (int)(ret < 0 ? ret : 0);
123121
}
124122

125123
int iio_attr_write_bool(const struct iio_attr *attr, bool val)
@@ -131,20 +129,18 @@ int iio_attr_write_bool(const struct iio_attr *attr, bool val)
131129
else
132130
ret = iio_attr_write_raw(attr, "0", 2);
133131

134-
return (int) (ret < 0 ? ret : 0);
132+
return (int)(ret < 0 ? ret : 0);
135133
}
136134

137-
const struct iio_attr *
138-
iio_attr_get(const struct iio_attr_list *attrs, unsigned int idx)
135+
const struct iio_attr *iio_attr_get(const struct iio_attr_list *attrs, unsigned int idx)
139136
{
140137
if (idx >= attrs->num)
141138
return NULL;
142139

143140
return &attrs->attrs[idx];
144141
}
145142

146-
const struct iio_attr *
147-
iio_attr_find(const struct iio_attr_list *attrs, const char *name)
143+
const struct iio_attr *iio_attr_find(const struct iio_attr_list *attrs, const char *name)
148144
{
149145
unsigned int i;
150146

@@ -155,20 +151,17 @@ iio_attr_find(const struct iio_attr_list *attrs, const char *name)
155151
return NULL;
156152
}
157153

158-
const char *
159-
iio_attr_get_name(const struct iio_attr *attr)
154+
const char *iio_attr_get_name(const struct iio_attr *attr)
160155
{
161156
return attr->name;
162157
}
163158

164-
const char *
165-
iio_attr_get_filename(const struct iio_attr *attr)
159+
const char *iio_attr_get_filename(const struct iio_attr *attr)
166160
{
167161
return attr->filename;
168162
}
169163

170-
const char *
171-
iio_attr_get_static_value(const struct iio_attr *attr)
164+
const char *iio_attr_get_static_value(const struct iio_attr *attr)
172165
{
173166
unsigned int idx;
174167

@@ -181,9 +174,8 @@ iio_attr_get_static_value(const struct iio_attr *attr)
181174
}
182175
}
183176

184-
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)
177+
int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs, const char *name,
178+
const char *filename, enum iio_attr_type type)
187179
{
188180
struct iio_attr *attr;
189181

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

208200
if (!attr[attrs->num].filename) {
209-
free((char *) attr[attrs->num].name);
201+
free((char *)attr[attrs->num].name);
210202
return -ENOMEM;
211203
}
212204
} else {
@@ -220,16 +212,17 @@ int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
220212
return 0;
221213
}
222214

223-
static const char * const attr_type_string[] = {
215+
static const char *const attr_type_string[] = {
224216
"",
225217
" debug",
226218
" buffer",
227219
};
228220

229-
int iio_device_add_attr(struct iio_device *dev,
230-
const char *name, enum iio_attr_type type)
221+
int iio_device_add_attr(struct iio_device *dev, const char *name, enum iio_attr_type type)
231222
{
232-
union iio_pointer p = { .dev = dev, };
223+
union iio_pointer p = {
224+
.dev = dev,
225+
};
233226
int ret;
234227

235228
ret = iio_add_attr(p, &dev->attrlist[type], name, NULL, type);
@@ -240,26 +233,27 @@ int iio_device_add_attr(struct iio_device *dev,
240233
return 0;
241234
}
242235

243-
int iio_channel_add_attr(struct iio_channel *chn,
244-
const char *name, const char *filename)
236+
int iio_channel_add_attr(struct iio_channel *chn, const char *name, const char *filename)
245237
{
246-
union iio_pointer p = { .chn = chn, };
238+
union iio_pointer p = {
239+
.chn = chn,
240+
};
247241
int ret;
248242

249-
ret = iio_add_attr(p, &chn->attrlist, name, filename,
250-
IIO_ATTR_TYPE_CHANNEL);
243+
ret = iio_add_attr(p, &chn->attrlist, name, filename, IIO_ATTR_TYPE_CHANNEL);
251244
if (ret < 0)
252245
return ret;
253246

254247
chn_dbg(chn, "Added attr \'%s\' (\'%s\')\n", name, filename);
255248
return 0;
256249
}
257250

258-
int iio_context_add_attr(struct iio_context *ctx,
259-
const char *key, const char *value)
251+
int iio_context_add_attr(struct iio_context *ctx, const char *key, const char *value)
260252
{
261253
char **values, *new_val;
262-
union iio_pointer p = { .ctx = ctx, };
254+
union iio_pointer p = {
255+
.ctx = ctx,
256+
};
263257
unsigned int i;
264258
int ret;
265259

@@ -268,15 +262,14 @@ int iio_context_add_attr(struct iio_context *ctx,
268262
return -ENOMEM;
269263

270264
for (i = 0; i < ctx->attrlist.num; i++) {
271-
if(!strcmp(ctx->attrlist.attrs[i].name, key)) {
265+
if (!strcmp(ctx->attrlist.attrs[i].name, key)) {
272266
free(ctx->values[i]);
273267
ctx->values[i] = new_val;
274268
return 0;
275269
}
276270
}
277271

278-
values = realloc(ctx->values,
279-
(ctx->attrlist.num + 1) * sizeof(*ctx->values));
272+
values = realloc(ctx->values, (ctx->attrlist.num + 1) * sizeof(*ctx->values));
280273
if (!values) {
281274
free(new_val);
282275
return -ENOMEM;
@@ -306,7 +299,7 @@ int iio_context_add_attr(struct iio_context *ctx,
306299
causing subsequent attributes to shift forward as they were already sorted */
307300
if (new_idx != ctx->attrlist.num - 1) {
308301
memmove(&ctx->values[new_idx + 1], &ctx->values[new_idx],
309-
(ctx->attrlist.num - new_idx - 1) * sizeof(*ctx->values));
302+
(ctx->attrlist.num - new_idx - 1) * sizeof(*ctx->values));
310303
ctx->values[new_idx] = new_val;
311304
}
312305

@@ -316,9 +309,9 @@ int iio_context_add_attr(struct iio_context *ctx,
316309
void iio_free_attr_data(struct iio_attr *attr)
317310
{
318311
if (attr->filename != attr->name)
319-
free((char *) attr->filename);
312+
free((char *)attr->filename);
320313

321-
free((char *) attr->name);
314+
free((char *)attr->name);
322315

323316
attr->filename = NULL;
324317
attr->name = NULL;
@@ -350,11 +343,12 @@ int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, d
350343
char buf[MAX_ATTR_VALUE];
351344
ret = iio_attr_read_raw(attr, buf, sizeof(buf));
352345
if (ret < 0)
353-
return (int) ret;
346+
return (int)ret;
354347

355-
// Expect format: [min step max]
348+
// Expect format: [min step max]
356349
#if defined(_MSC_VER)
357-
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra, (unsigned int)sizeof(extra));
350+
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra,
351+
(unsigned int)sizeof(extra));
358352
#else
359353
n = iio_sscanf(buf, " [ %lf %lf %lf %c", &lmin, &lstep, &lmax, &extra);
360354
#endif
@@ -418,7 +412,7 @@ int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *co
418412
*list = local_list;
419413
*count = n;
420414

421-
return 0;
415+
return 0;
422416
}
423417

424418
void iio_available_list_free(char **list, size_t count)
@@ -433,8 +427,8 @@ void iio_available_list_free(char **list, size_t count)
433427
}
434428
}
435429

436-
int iio_attr_get_available_buf(const struct iio_attr *attr, char *buf,
437-
size_t buflen, char **list, size_t *count)
430+
int iio_attr_get_available_buf(
431+
const struct iio_attr *attr, char *buf, size_t buflen, char **list, size_t *count)
438432
{
439433
ssize_t ret;
440434
size_t n = 0, max = (size_t)-1;

attr.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ 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(const struct iio_attr_list *attrs, unsigned int idx);
19+
const struct iio_attr *iio_attr_find(const struct iio_attr_list *attrs, const char *name);
2220

2321
void iio_free_attr_data(struct iio_attr *attr);
2422
void iio_free_attrs(const struct iio_attr_list *attrs);
2523

26-
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);
24+
int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs, const char *name,
25+
const char *filename, enum iio_attr_type type);
2926

3027
#endif /* __IIO_ATTR_H__ */

backend.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* Author: Paul Cercueil <paul.cercueil@analog.com>
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,7 @@ 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(const struct iio_context_params *params, const char *backend)
4140
{
4241
unsigned int i;
4342

bindings/CMakeLists.txt

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
if (NOT CPP_BINDINGS AND CPP_EXAMPLES)
2-
message(STATUS "Turning off c++-bindings also disables feature: c++-examples")
3-
set(CPP_EXAMPLES OFF)
4-
endif()
2+
message(
3+
STATUS "Turning off c++-bindings also disables feature: c++-examples")
4+
set(CPP_EXAMPLES OFF)
5+
endif ()
56

67
if (CPP_BINDINGS AND CPP_EXAMPLES)
7-
add_subdirectory(cpp)
8-
endif()
8+
add_subdirectory(cpp)
9+
endif ()
910

1011
if (CSHARP_BINDINGS)
11-
add_subdirectory(csharp)
12-
endif()
12+
add_subdirectory(csharp)
13+
endif ()
1314

1415
if (PYTHON_BINDINGS)
15-
add_subdirectory(python)
16-
endif()
16+
add_subdirectory(python)
17+
endif ()
1718

18-
list(APPEND OPTIONS_LISTS
19-
"PYTHON_BINDINGS"
20-
"CSHARP_BINDINGS"
21-
"CPP_BINDINGS"
22-
"CPP_EXAMPLES"
23-
)
24-
list(APPEND FEATURES_LISTS
25-
"python-bindings"
26-
"c#-bindings"
27-
"c++-bindings"
28-
"c++-examples"
29-
)
19+
list(APPEND OPTIONS_LISTS "PYTHON_BINDINGS" "CSHARP_BINDINGS" "CPP_BINDINGS"
20+
"CPP_EXAMPLES")
21+
list(APPEND FEATURES_LISTS "python-bindings" "c#-bindings" "c++-bindings"
22+
"c++-examples")
3023

31-
set(IIOB_OPTIONS "${OPTIONS_LISTS}" PARENT_SCOPE)
32-
set(IIOB_FEATURES "${FEATURES_LISTS}" PARENT_SCOPE)
24+
set(IIOB_OPTIONS
25+
"${OPTIONS_LISTS}"
26+
PARENT_SCOPE)
27+
set(IIOB_FEATURES
28+
"${FEATURES_LISTS}"
29+
PARENT_SCOPE)

0 commit comments

Comments
 (0)