@@ -104,7 +104,7 @@ static int isInRange(int x, int minx, int maxx) // returns nonzero if x in the r
104
104
{
105
105
if (minx <= x && x < maxx ) { return 1 ; }
106
106
if (x < minx ) { x += 360000000 ; } else { x -= 360000000 ; } // 1.32 fix FIJI edge case
107
- if (minx <= x && x < maxx ) return 1 ;
107
+ if (minx <= x && x < maxx ) { return 1 ; }
108
108
return 0 ;
109
109
}
110
110
@@ -148,17 +148,19 @@ static int disambiguate_str(const char *s, int len) // returns disambiguation >=
148
148
const char * f ;
149
149
char country [4 ];
150
150
if (s [0 ] == 0 || s [1 ] == 0 ) { return -27 ; } // solve bad args
151
- if (len != 2 && len != 3 ) return -923 ; // solve bad args
151
+ if (len != 2 && len != 3 ) { return -923 ; } // solve bad args
152
152
memcpy (country , s , len );
153
153
country [len ] = 0 ;
154
154
{
155
155
char * t ;
156
- for (t = country ; * t != 0 ; t ++ )
156
+ for (t = country ; * t != 0 ; t ++ ) {
157
157
* t = (char ) toupper (* t );
158
+ }
158
159
}
159
160
f = strstr (p , country );
160
- if (f == NULL )
161
- return -23 ; // unknown country
161
+ if (f == NULL ) {
162
+ return -23 ;
163
+ } // unknown country
162
164
return 1 + (int ) ((f - p ) / (len + 1 ));
163
165
}
164
166
@@ -187,15 +189,16 @@ static int ccode_of_iso3(const char *in_iso, int parentcode) {
187
189
188
190
// make (uppercased) copy of at most three characters
189
191
iso [0 ] = (char ) toupper (in_iso [0 ]);
190
- if (iso [0 ]) iso [1 ] = (char ) toupper (in_iso [1 ]);
191
- if (iso [1 ]) iso [2 ] = (char ) toupper (in_iso [2 ]);
192
+ if (iso [0 ]) { iso [1 ] = (char ) toupper (in_iso [1 ]); }
193
+ if (iso [1 ]) { iso [2 ] = (char ) toupper (in_iso [2 ]); }
192
194
iso [3 ] = 0 ;
193
195
194
196
if (iso [2 ] == 0 || iso [2 ] == ' ' ) // 2-letter iso code?
195
197
{
196
198
static char disambiguate_iso3 [4 ] = {'1' , '?' , '?' , 0 }; // cache for disambiguation
197
- if (parentcode > 0 )
199
+ if (parentcode > 0 ) {
198
200
disambiguate_iso3 [0 ] = (char ) ('0' + parentcode );
201
+ }
199
202
disambiguate_iso3 [1 ] = iso [0 ];
200
203
disambiguate_iso3 [2 ] = iso [1 ];
201
204
@@ -218,8 +221,9 @@ static int ccode_of_iso3(const char *in_iso, int parentcode) {
218
221
// find the FIRST disambiguation option, if any
219
222
for (s = entity_iso - 1 ; ;) {
220
223
s = strstr (s + 1 , disambiguate_iso3 + 1 );
221
- if (s == NULL )
224
+ if (s == NULL ) {
222
225
break ;
226
+ }
223
227
if (s && s [-1 ] >= '1' && s [-1 ] <= '9' ) {
224
228
s -- ;
225
229
break ;
@@ -229,8 +233,9 @@ static int ccode_of_iso3(const char *in_iso, int parentcode) {
229
233
// find first disambiguation option in aliases, if any
230
234
for (s = aliases - 1 ; ;) {
231
235
s = strstr (s + 1 , disambiguate_iso3 + 1 );
232
- if (s == NULL )
236
+ if (s == NULL ) {
233
237
break ;
238
+ }
234
239
if (s && s [-1 ] >= '1' && s [-1 ] <= '9' ) {
235
240
memcpy (iso , s + 3 , 3 );
236
241
s = strstr (entity_iso , iso ); // search disambiguated 2-letter iso
@@ -239,8 +244,9 @@ static int ccode_of_iso3(const char *in_iso, int parentcode) {
239
244
}
240
245
}
241
246
242
- if (s == NULL )
247
+ if (s == NULL ) {
243
248
return -26 ;
249
+ }
244
250
}
245
251
}
246
252
else {
@@ -260,8 +266,9 @@ static int ccode_of_iso3(const char *in_iso, int parentcode) {
260
266
}
261
267
}
262
268
}
263
- if (s == NULL )
269
+ if (s == NULL ) {
264
270
return -23 ;
271
+ }
265
272
}
266
273
// return result
267
274
return (int ) ((s - entity_iso ) / 4 );
@@ -384,7 +391,7 @@ static int decodeExtension(decodeRec *dec, int dividerx4, int dividery, int ydir
384
391
column1 = (c1 % 5 );
385
392
if (* extrapostfix ) {
386
393
int c2 = decodeChar (* extrapostfix ++ );
387
- if (c2 < 0 || c2 == 30 ) return -1 ; // illegal extension character
394
+ if (c2 < 0 || c2 == 30 ) { return -1 ; } // illegal extension character
388
395
row2 = (c2 / 6 );
389
396
column2 = (c2 % 6 );
390
397
}
@@ -833,7 +840,7 @@ static int decodeNameless(decodeRec *dec, int m) {
833
840
int BASEPOWER = (codexm == 21 ) ? 961 * 961 : 961 * 961 * 31 ;
834
841
int BASEPOWERA = (BASEPOWER / A );
835
842
836
- if (A == 62 ) BASEPOWERA ++ ; else BASEPOWERA = 961 * (BASEPOWERA / 961 );
843
+ if (A == 62 ) { BASEPOWERA ++ ; } else { BASEPOWERA = 961 * (BASEPOWERA / 961 ); }
837
844
838
845
v = decodeBase31 (result );
839
846
X = (v / BASEPOWERA );
@@ -960,12 +967,13 @@ static int unpack_if_alldigits(
960
967
int aonly = (* s == 'A' || * s == 'a' );
961
968
if (aonly ) { s ++ ; } //*** v1.50
962
969
for (; * s != 0 && s [2 ] != 0 && s [2 ] != '-' ; s ++ ) {
963
- if (* s == '-' )
970
+ if (* s == '-' ) {
964
971
break ;
965
- else if (* s == '.' && !dotpos )
972
+ } else if (* s == '.' && !dotpos ) {
966
973
dotpos = s ;
967
- else if (decodeChar (* s ) < 0 || decodeChar (* s ) > 9 )
968
- return 0 ; // nondigit, so stop
974
+ } else if (decodeChar (* s ) < 0 || decodeChar (* s ) > 9 ) {
975
+ return 0 ;
976
+ } // nondigit, so stop
969
977
}
970
978
971
979
if (dotpos ) {
@@ -985,14 +993,19 @@ static int unpack_if_alldigits(
985
993
char * e = s + 1 ; // s is vowel, e is lastchar
986
994
987
995
int v = 0 ;
988
- if (* s == 'e' || * s == 'E' ) v = 34 ;
989
- else if (* s == 'u' || * s == 'U' ) v = 68 ;
990
-
991
- if (* e == 'a' || * e == 'A' ) v += 31 ;
992
- else if (* e == 'e' || * e == 'E' ) v += 32 ;
993
- else if (* e == 'u' || * e == 'U' ) v += 33 ;
994
- else if (decodeChar (* e ) < 0 ) return -9 ; // invalid last character!
995
- else v += decodeChar (* e );
996
+ if (* s == 'e' || * s == 'E' ) {
997
+ v = 34 ;
998
+ } else if (* s == 'u' || * s == 'U' ) { v = 68 ; }
999
+
1000
+ if (* e == 'a' || * e == 'A' ) {
1001
+ v += 31 ;
1002
+ } else if (* e == 'e' || * e == 'E' ) {
1003
+ v += 32 ;
1004
+ } else if (* e == 'u' || * e == 'U' ) {
1005
+ v += 33 ;
1006
+ } else if (decodeChar (* e ) < 0 ) {
1007
+ return -9 ; // invalid last character!
1008
+ } else { v += decodeChar (* e ); }
996
1009
997
1010
if (v < 100 ) {
998
1011
* s = encode_chars [(unsigned int ) v / 10 ];
@@ -1282,8 +1295,11 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
1282
1295
from = firstrec (ccode );
1283
1296
upto = lastrec (ccode );
1284
1297
1285
- if (ccode != ccode_earth ) if (!fitsInside (x , y , upto ))
1286
- return ;
1298
+ if (ccode != ccode_earth ) {
1299
+ if (!fitsInside (x , y , upto )) {
1300
+ return ;
1301
+ }
1302
+ }
1287
1303
1288
1304
///////////////////////////////////////////////////////////
1289
1305
// look for encoding options
@@ -1342,9 +1358,9 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
1342
1358
strcat (s , result );
1343
1359
}
1344
1360
}
1345
- if (debugStopAt == i ) return ;
1361
+ if (debugStopAt == i ) { return ; }
1346
1362
}
1347
- if (stop_with_one_result ) return ;
1363
+ if (stop_with_one_result ) { return ; }
1348
1364
* result = 0 ; // clear for next iteration
1349
1365
}
1350
1366
}
@@ -1368,8 +1384,8 @@ static int decoderEngine(decodeRec *dec) {
1368
1384
const char * r = dec -> orginput ;
1369
1385
while (* r > 0 && * r <= 32 ) { r ++ ; } // skip lead
1370
1386
len = (int ) strlen (r );
1371
- if (len > MAX_MAPCODE_RESULT_LEN - 1 ) len = MAX_MAPCODE_RESULT_LEN - 1 ;
1372
- while (len > 0 && r [len - 1 ] >= 0 && r [len - 1 ] <= 32 ) len -- ; // remove trail
1387
+ if (len > MAX_MAPCODE_RESULT_LEN - 1 ) { len = MAX_MAPCODE_RESULT_LEN - 1 ; }
1388
+ while (len > 0 && r [len - 1 ] >= 0 && r [len - 1 ] <= 32 ) { len -- ; } // remove trail
1373
1389
memcpy (s , r , len );
1374
1390
s [len ] = 0 ;
1375
1391
}
@@ -1466,8 +1482,9 @@ static int decoderEngine(decodeRec *dec) {
1466
1482
1467
1483
// unpack digits (a-lead or aeu-encoded
1468
1484
int voweled = unpack_if_alldigits (s );
1469
- if (voweled < 0 )
1485
+ if (voweled < 0 ) {
1470
1486
return -7 ;
1487
+ }
1471
1488
1472
1489
// debug support: U-lead pre-processing
1473
1490
if (* s == 'u' || * s == 'U' ) {
@@ -1476,27 +1493,30 @@ static int decoderEngine(decodeRec *dec) {
1476
1493
voweled = 1 ;
1477
1494
}
1478
1495
1479
- if (len > 10 ) return -8 ;
1496
+ if (len > 10 ) { return -8 ; }
1480
1497
1481
1498
// find dot and check that all characters are valid
1482
1499
{
1483
1500
int nrd = 0 ; // nr of true digits
1484
1501
const char * r = s ;
1485
1502
for (; * r != 0 ; r ++ ) {
1486
1503
if (* r == '.' ) {
1487
- if (dot )
1488
- return -5 ; // more than one dot
1504
+ if (dot ) {
1505
+ return -5 ;
1506
+ } // more than one dot
1489
1507
dot = r ;
1490
1508
}
1491
- else if (decodeChar (* r ) < 0 ) // invalid char?
1509
+ else if (decodeChar (* r ) < 0 ) { // invalid char?
1492
1510
return -4 ;
1493
- else if (decodeChar (* r ) < 10 ) // digit?
1511
+ } else if (decodeChar (* r ) < 10 ) { // digit?
1494
1512
nrd ++ ;
1513
+ }
1495
1514
}
1496
- if (dot == NULL )
1515
+ if (dot == NULL ) {
1497
1516
return -2 ;
1498
- else if (!voweled && nrd + 1 == len ) // everything but the dot is digit, so MUST be voweled!
1517
+ } else if (!voweled && nrd + 1 == len ) { // everything but the dot is digit, so MUST be voweled!
1499
1518
return -998 ;
1519
+ }
1500
1520
}
1501
1521
1502
1522
//////////// AT THIS POINT, dot=FIRST DOT, input=CLEAN INPUT (no vowels) ilen=INPUT LENGTH
@@ -1505,8 +1525,9 @@ static int decoderEngine(decodeRec *dec) {
1505
1525
prelen = (int ) (dot - s );
1506
1526
postlen = len - 1 - prelen ;
1507
1527
codex = prelen * 10 + postlen ;
1508
- if (prelen < 2 || prelen > 5 || postlen < 2 || postlen > 4 )
1528
+ if (prelen < 2 || prelen > 5 || postlen < 2 || postlen > 4 ) {
1509
1529
return -3 ;
1530
+ }
1510
1531
1511
1532
if (len == 10 ) {
1512
1533
// international mapcodes must be in international context
@@ -1516,8 +1537,9 @@ static int decoderEngine(decodeRec *dec) {
1516
1537
// int mapcodes must be interpreted in the parent of a subdivision
1517
1538
1518
1539
int parent = ParentTerritoryOf (ccode );
1519
- if (len == 9 || (len == 8 && (parent == ccode_ind || parent == ccode_mex )))
1540
+ if (len == 9 || (len == 8 && (parent == ccode_ind || parent == ccode_mex ))) {
1520
1541
ccode = parent ;
1542
+ }
1521
1543
}
1522
1544
1523
1545
// remember final territory context
@@ -1589,18 +1611,22 @@ static int decoderEngine(decodeRec *dec) {
1589
1611
#endif
1590
1612
1591
1613
// normalise between =180 and 180
1592
- if (dec -> lat < -90.0 ) dec -> lat = -90.0 ;
1593
- if (dec -> lat > 90.0 ) dec -> lat = 90.0 ;
1594
- if (dec -> lon < -180.0 ) dec -> lon += 360.0 ;
1595
- if (dec -> lon >= 180.0 ) dec -> lon -= 360.0 ;
1614
+ if (dec -> lat < -90.0 ) { dec -> lat = -90.0 ; }
1615
+ if (dec -> lat > 90.0 ) { dec -> lat = 90.0 ; }
1616
+ if (dec -> lon < -180.0 ) { dec -> lon += 360.0 ; }
1617
+ if (dec -> lon >= 180.0 ) { dec -> lon -= 360.0 ; }
1596
1618
1597
1619
// store as integers for legacy's sake
1598
1620
dec -> lat32 = (int ) (dec -> lat * 1000000 );
1599
1621
dec -> lon32 = (int ) (dec -> lon * 1000000 );
1600
1622
1601
1623
// make sure decode result fits the country
1602
- if (err == 0 ) if (ccode != ccode_earth ) if (!fitsInsideWithRoom (dec -> lon32 , dec -> lat32 , lastrec (ccode ))) {
1603
- err = -2222 ;
1624
+ if (err == 0 ) {
1625
+ if (ccode != ccode_earth ) {
1626
+ if (!fitsInsideWithRoom (dec -> lon32 , dec -> lat32 , lastrec (ccode ))) {
1627
+ err = -2222 ;
1628
+ }
1629
+ }
1604
1630
}
1605
1631
1606
1632
return err ;
@@ -2007,7 +2033,7 @@ int convertTerritoryIsoNameToCode(const char *string, int optional_tc) // option
2007
2033
strcat (tmp , string );
2008
2034
ccode = ccode_of_iso3 (tmp , -1 );
2009
2035
}
2010
- if (ccode < 0 ) return -1 ; else return ccode + 1 ;
2036
+ if (ccode < 0 ) { return -1 ; } else { return ccode + 1 ; }
2011
2037
}
2012
2038
2013
2039
@@ -2037,7 +2063,7 @@ UWORD *convertToAlphabet(UWORD *unibuf, int maxlength, const char *mapcode, int
2037
2063
{
2038
2064
if (asc2lan [alphabet ][4 ] == 0x003f ) { // alphabet has no letter E
2039
2065
if (strchr (mapcode , 'E' ) || strchr (mapcode , 'U' ) || strchr (mapcode , 'e' ) ||
2040
- strchr (mapcode , 'u' )) // v1.50 get rid of E and U
2066
+ strchr (mapcode , 'u' )) // v1.50 get rid of E and U
2041
2067
{
2042
2068
// safely copy mapcode into temporary buffer u
2043
2069
char u [MAX_MAPCODE_RESULT_LEN ];
0 commit comments