Skip to content

Commit a8fb816

Browse files
committed
STYLE: Upstream clang-format changes applied
The .clang-format file from June 2022 teem/NrrdIO project is applied here to minimize code differences with upstream changes. This patch set will allow the upstream changes to be more easily visible when added in a subsequent patch.
1 parent 259217c commit a8fb816

Some content is hidden

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

50 files changed

+2851
-3252
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Created by GLK in June 2022 as part of rebooting effort to do a Teem release
2+
# Significant experimentation went into trying to match the existing style,
3+
# except for # columns going up from 79 to 89.
4+
# This file is what provides info to "clang-format -style=file" when run in
5+
# this directory or a subdirectory. The teem/src/_util/clang-format.sh
6+
# script helps do this.
7+
# For more info see: https://clang.llvm.org/docs/ClangFormat.html
8+
---
9+
Language: C
10+
BasedOnStyle: LLVM
11+
ColumnLimit: 89
12+
AlwaysBreakAfterDefinitionReturnType: All
13+
AlwaysBreakAfterReturnType: None
14+
PenaltyReturnTypeOnItsOwnLine: 400
15+
AllowShortIfStatementsOnASingleLine: WithoutElse
16+
PenaltyBreakBeforeFirstCallParameter: 100
17+
PenaltyBreakAssignment: 50
18+
AlignOperands: AlignAfterOperator
19+
BreakBeforeBinaryOperators: All
20+
PenaltyBreakOpenParenthesis: 300
21+
ContinuationIndentWidth: 2
22+
SortIncludes: false
23+
ExperimentalAutoDetectBinPacking: true
24+
IndentPPDirectives: AfterHash
25+
AllowShortEnumsOnASingleLine: false
26+
AlignConsecutiveMacros: AcrossComments
27+
AllowShortFunctionsOnASingleLine: All
28+
...

Modules/ThirdParty/NrrdIO/src/NrrdIO/754.c

Lines changed: 78 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -138,66 +138,60 @@ extern air_export const airDouble airDoubleMin;
138138
*/
139139

140140
/* the bit-masking done here quiets gcc -Wconversion warnings */
141-
#define FP_SET_F(flit, fbig, s, e, m) \
142-
flit.c.sign = 1u & (s); \
143-
flit.c.expo = ((1u<8)-1) & (e); \
144-
flit.c.mant = ((1u<23)-1) & (m); \
145-
fbig.c.sign = 1u & (s); \
146-
fbig.c.expo = ((1u<8)-1) & (e); \
147-
fbig.c.mant = ((1u<23)-1) & (m)
148-
149-
#define FP_GET_F(s, e, m, flit, fbig) \
150-
if (airEndianLittle == airMyEndian()) { \
151-
(s) = flit.c.sign; \
152-
(e) = flit.c.expo; \
153-
(m) = flit.c.mant; \
154-
} else { \
155-
(s) = fbig.c.sign; \
156-
(e) = fbig.c.expo; \
157-
(m) = fbig.c.mant; \
141+
#define FP_SET_F(flit, fbig, s, e, m) \
142+
flit.c.sign = 1u & (s); \
143+
flit.c.expo = ((1u < 8) - 1) & (e); \
144+
flit.c.mant = ((1u < 23) - 1) & (m); \
145+
fbig.c.sign = 1u & (s); \
146+
fbig.c.expo = ((1u < 8) - 1) & (e); \
147+
fbig.c.mant = ((1u < 23) - 1) & (m)
148+
149+
#define FP_GET_F(s, e, m, flit, fbig) \
150+
if (airEndianLittle == airMyEndian()) { \
151+
(s) = flit.c.sign; \
152+
(e) = flit.c.expo; \
153+
(m) = flit.c.mant; \
154+
} else { \
155+
(s) = fbig.c.sign; \
156+
(e) = fbig.c.expo; \
157+
(m) = fbig.c.mant; \
158158
}
159159

160-
#define FP_SET_D(dlit, dbig, s, e, m0, m1) \
161-
dlit.c.sign = 1u & (s); \
162-
dlit.c.expo = ((1u<<11)-1) & (e); \
163-
dlit.c.mant0 = ((1u<<20)-1) & (m0); \
164-
dlit.c.mant1 = (m1); \
165-
dbig.c.sign = 1u & (s); \
166-
dbig.c.expo = ((1u<<11)-1) & (e); \
167-
dbig.c.mant0 = ((1u<<20)-1) & (m0); \
160+
#define FP_SET_D(dlit, dbig, s, e, m0, m1) \
161+
dlit.c.sign = 1u & (s); \
162+
dlit.c.expo = ((1u << 11) - 1) & (e); \
163+
dlit.c.mant0 = ((1u << 20) - 1) & (m0); \
164+
dlit.c.mant1 = (m1); \
165+
dbig.c.sign = 1u & (s); \
166+
dbig.c.expo = ((1u << 11) - 1) & (e); \
167+
dbig.c.mant0 = ((1u << 20) - 1) & (m0); \
168168
dbig.c.mant1 = (m1)
169169

170-
#define FP_GET_D(s, e, m0, m1, dlit, dbig) \
171-
if (airEndianLittle == airMyEndian()) { \
172-
(s) = dlit.c.sign; \
173-
(e) = dlit.c.expo; \
174-
(m0) = dlit.c.mant0; \
175-
(m1) = dlit.c.mant1; \
176-
} else { \
177-
(s) = dbig.c.sign; \
178-
(e) = dbig.c.expo; \
179-
(m0) = dbig.c.mant0; \
180-
(m1) = dbig.c.mant1; \
170+
#define FP_GET_D(s, e, m0, m1, dlit, dbig) \
171+
if (airEndianLittle == airMyEndian()) { \
172+
(s) = dlit.c.sign; \
173+
(e) = dlit.c.expo; \
174+
(m0) = dlit.c.mant0; \
175+
(m1) = dlit.c.mant1; \
176+
} else { \
177+
(s) = dbig.c.sign; \
178+
(e) = dbig.c.expo; \
179+
(m0) = dbig.c.mant0; \
180+
(m1) = dbig.c.mant1; \
181181
}
182182

183-
184183
float
185-
airFPPartsToVal_f(unsigned int sign,
186-
unsigned int expo,
187-
unsigned int mant) {
184+
airFPPartsToVal_f(unsigned int sign, unsigned int expo, unsigned int mant) {
188185
_airFloatEndianLittle flit;
189186
_airFloatEndianBig fbig;
190187

191188
FP_SET_F(flit, fbig, sign, expo, mant);
192-
return (airEndianLittle == airMyEndian()
193-
? flit.v
194-
: fbig.v);
189+
return (airEndianLittle == airMyEndian() ? flit.v : fbig.v);
195190
}
196191

197192
void
198-
airFPValToParts_f(unsigned int *signP,
199-
unsigned int *expoP,
200-
unsigned int *mantP, float v) {
193+
airFPValToParts_f(unsigned int *signP, unsigned int *expoP, unsigned int *mantP,
194+
float v) {
201195
_airFloatEndianLittle flit;
202196
_airFloatEndianBig fbig;
203197

@@ -214,23 +208,19 @@ airFPPartsToVal_d(unsigned int sign,
214208
_airDoubleEndianBig dbig;
215209

216210
FP_SET_D(dlit, dbig, sign, expo, mant0, mant1);
217-
return (airEndianLittle == airMyEndian()
218-
? dlit.v
219-
: dbig.v);
211+
return (airEndianLittle == airMyEndian() ? dlit.v : dbig.v);
220212
}
221213

222214
/*
223215
** Disable the 'local variable used without having been initialized'
224216
** warning produced by the MSVC compiler
225217
*/
226218
#ifdef _MSC_VER
227-
#pragma warning(push)
228-
#pragma warning(disable : 4700)
219+
# pragma warning(push)
220+
# pragma warning(disable : 4700)
229221
#endif
230222
void
231-
airFPValToParts_d(unsigned int *signP,
232-
unsigned int *expoP,
233-
unsigned int *mant0P,
223+
airFPValToParts_d(unsigned int *signP, unsigned int *expoP, unsigned int *mant0P,
234224
unsigned int *mant1P, double v) {
235225
_airDoubleEndianLittle dlit;
236226
_airDoubleEndianBig dbig;
@@ -239,7 +229,7 @@ airFPValToParts_d(unsigned int *signP,
239229
FP_GET_D(*signP, *expoP, *mant0P, *mant1P, dlit, dbig);
240230
}
241231
#ifdef _MSC_VER
242-
#pragma warning(pop)
232+
# pragma warning(pop)
243233
#endif
244234

245235
/*
@@ -252,7 +242,7 @@ airFPGen_f(int cls) {
252242
_airFloatEndianLittle flit;
253243
_airFloatEndianBig fbig;
254244

255-
switch(cls) {
245+
switch (cls) {
256246
case airFP_SNAN:
257247
/* sgn: anything, mant: anything non-zero with high bit !TEEM_QNANHIBIT */
258248
FP_SET_F(flit, fbig, 0, 0xff, (!TEEM_QNANHIBIT << 22) | 0x3fffff);
@@ -291,9 +281,7 @@ airFPGen_f(int cls) {
291281
FP_SET_F(flit, fbig, 0, 0, 0);
292282
break;
293283
}
294-
return (airEndianLittle == airMyEndian()
295-
? flit.v
296-
: fbig.v);
284+
return (airEndianLittle == airMyEndian() ? flit.v : fbig.v);
297285
}
298286

299287
/*
@@ -306,48 +294,46 @@ airFPGen_d(int cls) {
306294
_airDoubleEndianLittle dlit;
307295
_airDoubleEndianBig dbig;
308296

309-
switch(cls) {
297+
switch (cls) {
310298
case airFP_SNAN:
311299
/* sgn: anything, mant: anything non-zero with high bit !TEEM_QNANHIBIT */
312-
FP_SET_D(dlit, dbig, 0, 0x7ff, (!TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff);
300+
FP_SET_D(dlit, dbig, 0, 0x7ff, (!TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff);
313301
break;
314302
case airFP_QNAN:
315303
/* sgn: anything, mant anything non-zero with high bit TEEM_QNANHIBIT */
316-
FP_SET_D(dlit, dbig, 0, 0x7ff, (TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff);
304+
FP_SET_D(dlit, dbig, 0, 0x7ff, (TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff);
317305
break;
318306
case airFP_POS_INF:
319-
FP_SET_D(dlit, dbig, 0, 0x7ff, 0, 0);
307+
FP_SET_D(dlit, dbig, 0, 0x7ff, 0, 0);
320308
break;
321309
case airFP_NEG_INF:
322-
FP_SET_D(dlit, dbig, 1, 0x7ff, 0, 0);
310+
FP_SET_D(dlit, dbig, 1, 0x7ff, 0, 0);
323311
break;
324312
case airFP_POS_NORM:
325313
/* exp: anything non-zero but < 0xff, mant: anything */
326-
FP_SET_D(dlit, dbig, 0, 0x400, 0x0ff00, 0);
314+
FP_SET_D(dlit, dbig, 0, 0x400, 0x0ff00, 0);
327315
break;
328316
case airFP_NEG_NORM:
329317
/* exp: anything non-zero but < 0xff, mant: anything */
330-
FP_SET_D(dlit, dbig, 1, 0x400, 0x0ff00, 0);
318+
FP_SET_D(dlit, dbig, 1, 0x400, 0x0ff00, 0);
331319
break;
332320
case airFP_POS_DENORM:
333321
/* mant: anything non-zero */
334-
FP_SET_D(dlit, dbig, 0, 0, 0xff, 0);
322+
FP_SET_D(dlit, dbig, 0, 0, 0xff, 0);
335323
break;
336324
case airFP_NEG_DENORM:
337325
/* mant: anything non-zero */
338-
FP_SET_D(dlit, dbig, 1, 0, 0xff, 0);
326+
FP_SET_D(dlit, dbig, 1, 0, 0xff, 0);
339327
break;
340328
case airFP_NEG_ZERO:
341-
FP_SET_D(dlit, dbig, 1, 0, 0, 0);
329+
FP_SET_D(dlit, dbig, 1, 0, 0, 0);
342330
break;
343331
case airFP_POS_ZERO:
344332
default:
345-
FP_SET_D(dlit, dbig, 0, 0, 0, 0);
333+
FP_SET_D(dlit, dbig, 0, 0, 0, 0);
346334
break;
347335
}
348-
return (airEndianLittle == airMyEndian()
349-
? dlit.v
350-
: dbig.v);
336+
return (airEndianLittle == airMyEndian() ? dlit.v : dbig.v);
351337
}
352338

353339
/*
@@ -365,7 +351,7 @@ airFPClass_f(float val) {
365351
flit.v = fbig.v = val;
366352
FP_GET_F(sign, expv, mant, flit, fbig);
367353
indexv = ((!!sign) << 2) | ((!!expv) << 1) | (!!mant);
368-
switch(indexv) {
354+
switch (indexv) {
369355
case 0:
370356
/* all fields are zero */
371357
ret = airFP_POS_ZERO;
@@ -431,8 +417,8 @@ airFPClass_f(float val) {
431417
** warning produced by the MSVC compiler
432418
*/
433419
#ifdef _MSC_VER
434-
#pragma warning(push)
435-
#pragma warning(disable : 4700)
420+
# pragma warning(push)
421+
# pragma warning(disable : 4700)
436422
#endif
437423
/*
438424
******** airFPClass_d()
@@ -444,7 +430,7 @@ airFPClass_d(double val) {
444430
_airDoubleEndianLittle dlit;
445431
_airDoubleEndianBig dbig;
446432
unsigned int sign, expo, mant0, mant1;
447-
int indexv, ret=0;
433+
int indexv, ret = 0;
448434
unsigned char hibit;
449435

450436
dlit.v = dbig.v = val;
@@ -456,7 +442,7 @@ airFPClass_d(double val) {
456442
hibit = AIR_CAST(unsigned char, mant0 >> 19); /* mant0 20 bits wide: ok */
457443

458444
indexv = ((!!sign) << 2) | ((!!expo) << 1) | (!!mant0 || !!mant1);
459-
switch(indexv) {
445+
switch (indexv) {
460446
case 0:
461447
/* all fields are zero */
462448
ret = airFP_POS_ZERO;
@@ -517,7 +503,7 @@ airFPClass_d(double val) {
517503
return ret;
518504
}
519505
#ifdef _MSC_VER
520-
#pragma warning(pop)
506+
# pragma warning(pop)
521507
#endif
522508

523509
/*
@@ -594,9 +580,8 @@ airExists(double val) {
594580
_airDoubleEndianBig dbig;
595581

596582
dbig.v = dlit.v = val;
597-
return (airEndianLittle == airMyEndian()
598-
? 0x7ff != dlit.c.expo
599-
: 0x7ff != dbig.c.expo);
583+
return (airEndianLittle == airMyEndian() ? 0x7ff != dlit.c.expo
584+
: 0x7ff != dbig.c.expo);
600585
}
601586

602587
/*
@@ -625,17 +610,16 @@ airFPFprintf_f(FILE *file, float val) {
625610
if (file) {
626611
flit.v = fbig.v = val;
627612
FP_GET_F(sign, expo, mant, flit, fbig);
628-
fprintf(file, "%f: class %d; 0x%08x = ",val, airFPClass_f(val),
613+
fprintf(file, "%f: class %d; 0x%08x = ", val, airFPClass_f(val),
629614
airEndianLittle == airMyEndian() ? flit.i : fbig.i);
630-
fprintf(file, "sign:0x%x, expo:0x%02x, mant:0x%06x = \n",
631-
sign, expo, mant);
615+
fprintf(file, "sign:0x%x, expo:0x%02x, mant:0x%06x = \n", sign, expo, mant);
632616
fprintf(file, " S [ . . Exp . . ] "
633-
"[ . . . . . . . . . Mant. . . . . . . . . . ]\n");
617+
"[ . . . . . . . . . Mant. . . . . . . . . . ]\n");
634618
fprintf(file, " %d ", sign);
635-
for (i=7; i>=0; i--) {
619+
for (i = 7; i >= 0; i--) {
636620
fprintf(file, "%d ", (expo >> i) & 1);
637621
}
638-
for (i=22; i>=0; i--) {
622+
for (i = 22; i >= 0; i--) {
639623
fprintf(file, "%d ", (mant >> i) & 1);
640624
}
641625
fprintf(file, "\n");
@@ -656,25 +640,23 @@ airFPFprintf_d(FILE *file, double val) {
656640

657641
if (file) {
658642
dlit.v = dbig.v = val;
659-
fprintf(file, "%f: class %d; 0x%08x %08x = \n",
660-
val, airFPClass_d(val),
643+
fprintf(file, "%f: class %d; 0x%08x %08x = \n", val, airFPClass_d(val),
661644
(airEndianLittle == airMyEndian() ? dlit.h.half1 : dbig.h.half1),
662645
(airEndianLittle == airMyEndian() ? dlit.h.half0 : dbig.h.half0));
663646
FP_GET_D(sign, expo, mant0, mant1, dlit, dbig);
664-
fprintf(file, "sign:0x%x, expo:0x%03x, mant:0x%05x %08x = \n",
665-
sign, expo, mant0, mant1);
647+
fprintf(file, "sign:0x%x, expo:0x%03x, mant:0x%05x %08x = \n", sign, expo, mant0,
648+
mant1);
666649
fprintf(file, "S[...Exp...][.......................Mant.......................]\n");
667650
fprintf(file, "%d", sign);
668-
for (i=10; i>=0; i--) {
651+
for (i = 10; i >= 0; i--) {
669652
fprintf(file, "%d", (expo >> i) & 1);
670653
}
671-
for (i=19; i>=0; i--) {
654+
for (i = 19; i >= 0; i--) {
672655
fprintf(file, "%d", (mant0 >> i) & 1);
673656
}
674-
for (i=31; i>=0; i--) {
657+
for (i = 31; i >= 0; i--) {
675658
fprintf(file, "%d", (mant1 >> i) & 1);
676659
}
677660
fprintf(file, "\n");
678661
}
679662
}
680-

0 commit comments

Comments
 (0)