Skip to content

Commit 8b162c4

Browse files
committed
clang-format the files
1 parent c117d8a commit 8b162c4

Some content is hidden

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

54 files changed

+2928
-2781
lines changed

arraylist.c

+79-75
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include <limits.h>
1515

1616
#ifdef STDC_HEADERS
17-
# include <stdlib.h>
18-
# include <string.h>
17+
#include <stdlib.h>
18+
#include <string.h>
1919
#endif /* STDC_HEADERS */
2020

2121
#if defined(HAVE_STRINGS_H) && !defined(_STRING_H) && !defined(__USE_BSD)
22-
# include <strings.h>
22+
#include <strings.h>
2323
#endif /* HAVE_STRINGS_H */
2424

2525
#ifndef SIZE_T_MAX
@@ -36,111 +36,115 @@
3636

3737
#include "arraylist.h"
3838

39-
struct array_list*
40-
array_list_new(array_list_free_fn *free_fn)
39+
struct array_list *array_list_new(array_list_free_fn *free_fn)
4140
{
42-
struct array_list *arr;
43-
44-
arr = (struct array_list*)calloc(1, sizeof(struct array_list));
45-
if(!arr) return NULL;
46-
arr->size = ARRAY_LIST_DEFAULT_SIZE;
47-
arr->length = 0;
48-
arr->free_fn = free_fn;
49-
if(!(arr->array = (void**)calloc(arr->size, sizeof(void*)))) {
50-
free(arr);
51-
return NULL;
52-
}
53-
return arr;
41+
struct array_list *arr;
42+
43+
arr = (struct array_list *)calloc(1, sizeof(struct array_list));
44+
if (!arr)
45+
return NULL;
46+
arr->size = ARRAY_LIST_DEFAULT_SIZE;
47+
arr->length = 0;
48+
arr->free_fn = free_fn;
49+
if (!(arr->array = (void **)calloc(arr->size, sizeof(void *))))
50+
{
51+
free(arr);
52+
return NULL;
53+
}
54+
return arr;
5455
}
5556

56-
extern void
57-
array_list_free(struct array_list *arr)
57+
extern void array_list_free(struct array_list *arr)
5858
{
59-
size_t i;
60-
for(i = 0; i < arr->length; i++)
61-
if(arr->array[i]) arr->free_fn(arr->array[i]);
62-
free(arr->array);
63-
free(arr);
59+
size_t i;
60+
for (i = 0; i < arr->length; i++)
61+
if (arr->array[i])
62+
arr->free_fn(arr->array[i]);
63+
free(arr->array);
64+
free(arr);
6465
}
6566

66-
void*
67-
array_list_get_idx(struct array_list *arr, size_t i)
67+
void *array_list_get_idx(struct array_list *arr, size_t i)
6868
{
69-
if(i >= arr->length) return NULL;
70-
return arr->array[i];
69+
if (i >= arr->length)
70+
return NULL;
71+
return arr->array[i];
7172
}
7273

7374
static int array_list_expand_internal(struct array_list *arr, size_t max)
7475
{
75-
void *t;
76-
size_t new_size;
77-
78-
if(max < arr->size) return 0;
79-
/* Avoid undefined behaviour on size_t overflow */
80-
if( arr->size >= SIZE_T_MAX / 2 )
81-
new_size = max;
82-
else
83-
{
84-
new_size = arr->size << 1;
85-
if (new_size < max)
86-
new_size = max;
87-
}
88-
if (new_size > (~((size_t)0)) / sizeof(void*)) return -1;
89-
if (!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
90-
arr->array = (void**)t;
91-
(void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
92-
arr->size = new_size;
93-
return 0;
76+
void *t;
77+
size_t new_size;
78+
79+
if (max < arr->size)
80+
return 0;
81+
/* Avoid undefined behaviour on size_t overflow */
82+
if (arr->size >= SIZE_T_MAX / 2)
83+
new_size = max;
84+
else
85+
{
86+
new_size = arr->size << 1;
87+
if (new_size < max)
88+
new_size = max;
89+
}
90+
if (new_size > (~((size_t)0)) / sizeof(void *))
91+
return -1;
92+
if (!(t = realloc(arr->array, new_size * sizeof(void *))))
93+
return -1;
94+
arr->array = (void **)t;
95+
(void)memset(arr->array + arr->size, 0, (new_size - arr->size) * sizeof(void *));
96+
arr->size = new_size;
97+
return 0;
9498
}
9599

96-
int
97-
array_list_put_idx(struct array_list *arr, size_t idx, void *data)
100+
int array_list_put_idx(struct array_list *arr, size_t idx, void *data)
98101
{
99-
if (idx > SIZE_T_MAX - 1 ) return -1;
100-
if(array_list_expand_internal(arr, idx+1)) return -1;
101-
if(idx < arr->length && arr->array[idx])
102-
arr->free_fn(arr->array[idx]);
103-
arr->array[idx] = data;
104-
if(arr->length <= idx) arr->length = idx + 1;
105-
return 0;
102+
if (idx > SIZE_T_MAX - 1)
103+
return -1;
104+
if (array_list_expand_internal(arr, idx + 1))
105+
return -1;
106+
if (idx < arr->length && arr->array[idx])
107+
arr->free_fn(arr->array[idx]);
108+
arr->array[idx] = data;
109+
if (arr->length <= idx)
110+
arr->length = idx + 1;
111+
return 0;
106112
}
107113

108-
int
109-
array_list_add(struct array_list *arr, void *data)
114+
int array_list_add(struct array_list *arr, void *data)
110115
{
111-
return array_list_put_idx(arr, arr->length, data);
116+
return array_list_put_idx(arr, arr->length, data);
112117
}
113118

114-
void
115-
array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *))
119+
void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *))
116120
{
117-
qsort(arr->array, arr->length, sizeof(arr->array[0]), compar);
121+
qsort(arr->array, arr->length, sizeof(arr->array[0]), compar);
118122
}
119123

120-
void* array_list_bsearch(const void **key, struct array_list *arr,
121-
int (*compar)(const void *, const void *))
124+
void *array_list_bsearch(const void **key, struct array_list *arr,
125+
int (*compar)(const void *, const void *))
122126
{
123-
return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]),
124-
compar);
127+
return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]), compar);
125128
}
126129

127-
size_t
128-
array_list_length(struct array_list *arr)
130+
size_t array_list_length(struct array_list *arr)
129131
{
130-
return arr->length;
132+
return arr->length;
131133
}
132134

133-
int
134-
array_list_del_idx( struct array_list *arr, size_t idx, size_t count )
135+
int array_list_del_idx(struct array_list *arr, size_t idx, size_t count)
135136
{
136137
size_t i, stop;
137138

138139
stop = idx + count;
139-
if ( idx >= arr->length || stop > arr->length ) return -1;
140-
for ( i = idx; i < stop; ++i ) {
141-
if ( arr->array[i] ) arr->free_fn( arr->array[i] );
140+
if (idx >= arr->length || stop > arr->length)
141+
return -1;
142+
for (i = idx; i < stop; ++i)
143+
{
144+
if (arr->array[i])
145+
arr->free_fn(arr->array[i]);
142146
}
143-
memmove( arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void*) );
147+
memmove(arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void *));
144148
arr->length -= count;
145149
return 0;
146150
}

arraylist.h

+15-24
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,35 @@ extern "C" {
2424

2525
#define ARRAY_LIST_DEFAULT_SIZE 32
2626

27-
typedef void (array_list_free_fn) (void *data);
27+
typedef void(array_list_free_fn)(void *data);
2828

2929
struct array_list
3030
{
31-
void **array;
32-
size_t length;
33-
size_t size;
34-
array_list_free_fn *free_fn;
31+
void **array;
32+
size_t length;
33+
size_t size;
34+
array_list_free_fn *free_fn;
3535
};
3636
typedef struct array_list array_list;
3737

38-
extern struct array_list*
39-
array_list_new(array_list_free_fn *free_fn);
38+
extern struct array_list *array_list_new(array_list_free_fn *free_fn);
4039

41-
extern void
42-
array_list_free(struct array_list *al);
40+
extern void array_list_free(struct array_list *al);
4341

44-
extern void*
45-
array_list_get_idx(struct array_list *al, size_t i);
42+
extern void *array_list_get_idx(struct array_list *al, size_t i);
4643

47-
extern int
48-
array_list_put_idx(struct array_list *al, size_t i, void *data);
44+
extern int array_list_put_idx(struct array_list *al, size_t i, void *data);
4945

50-
extern int
51-
array_list_add(struct array_list *al, void *data);
46+
extern int array_list_add(struct array_list *al, void *data);
5247

53-
extern size_t
54-
array_list_length(struct array_list *al);
48+
extern size_t array_list_length(struct array_list *al);
5549

56-
extern void
57-
array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *));
50+
extern void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *));
5851

59-
extern void*
60-
array_list_bsearch(const void **key, struct array_list *arr,
61-
int (*compar)(const void *, const void *));
52+
extern void *array_list_bsearch(const void **key, struct array_list *arr,
53+
int (*compar)(const void *, const void *));
6254

63-
extern int
64-
array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
55+
extern int array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
6556

6657
#ifdef __cplusplus
6758
}

debug.c

+38-25
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111

1212
#include "config.h"
1313

14+
#include <stdarg.h>
1415
#include <stdio.h>
1516
#include <stdlib.h>
1617
#include <string.h>
17-
#include <stdarg.h>
1818

1919
#if HAVE_SYSLOG_H
20-
# include <syslog.h>
20+
#include <syslog.h>
2121
#endif /* HAVE_SYSLOG_H */
2222

2323
#if HAVE_UNISTD_H
24-
# include <unistd.h>
24+
#include <unistd.h>
2525
#endif /* HAVE_UNISTD_H */
2626

2727
#if HAVE_SYS_PARAM_H
@@ -33,51 +33,64 @@
3333
static int _syslog = 0;
3434
static int _debug = 0;
3535

36-
void mc_set_debug(int debug) { _debug = debug; }
37-
int mc_get_debug(void) { return _debug; }
36+
void mc_set_debug(int debug)
37+
{
38+
_debug = debug;
39+
}
40+
int mc_get_debug(void)
41+
{
42+
return _debug;
43+
}
3844

3945
extern void mc_set_syslog(int syslog)
4046
{
41-
_syslog = syslog;
47+
_syslog = syslog;
4248
}
4349

4450
void mc_debug(const char *msg, ...)
4551
{
46-
va_list ap;
47-
if(_debug) {
48-
va_start(ap, msg);
52+
va_list ap;
53+
if (_debug)
54+
{
55+
va_start(ap, msg);
4956
#if HAVE_VSYSLOG
50-
if(_syslog) {
51-
vsyslog(LOG_DEBUG, msg, ap);
52-
} else
57+
if (_syslog)
58+
{
59+
vsyslog(LOG_DEBUG, msg, ap);
60+
}
61+
else
5362
#endif
54-
vprintf(msg, ap);
55-
va_end(ap);
56-
}
63+
vprintf(msg, ap);
64+
va_end(ap);
65+
}
5766
}
5867

5968
void mc_error(const char *msg, ...)
6069
{
61-
va_list ap;
62-
va_start(ap, msg);
70+
va_list ap;
71+
va_start(ap, msg);
6372
#if HAVE_VSYSLOG
64-
if(_syslog) {
73+
if (_syslog)
74+
{
6575
vsyslog(LOG_ERR, msg, ap);
66-
} else
76+
}
77+
else
6778
#endif
6879
vfprintf(stderr, msg, ap);
69-
va_end(ap);
80+
va_end(ap);
7081
}
7182

7283
void mc_info(const char *msg, ...)
7384
{
74-
va_list ap;
75-
va_start(ap, msg);
85+
va_list ap;
86+
va_start(ap, msg);
7687
#if HAVE_VSYSLOG
77-
if(_syslog) {
88+
if (_syslog)
89+
{
7890
vsyslog(LOG_INFO, msg, ap);
79-
} else
91+
}
92+
else
8093
#endif
8194
vfprintf(stderr, msg, ap);
82-
va_end(ap);
95+
va_end(ap);
8396
}

0 commit comments

Comments
 (0)