@@ -478,8 +478,6 @@ static void decodeSixWide(int v, int width, int height, int *x, int *y) {
478478 * y = height - 1 - (w / D );
479479}
480480
481- static int debugStopAt = -1 ;
482-
483481// decodes dec->mapcode in context of territory rectangle m; returns negative if error
484482static int decodeGrid (decodeRec * dec , int m , int hasHeaderLetter ) {
485483 const char * input = (hasHeaderLetter ? dec -> mapcode + 1 : dec -> mapcode );
@@ -1221,6 +1219,7 @@ static void encodeAutoHeader(char *result, const encodeRec *enc, int m, int extr
12211219
12221220
12231221static void encoderEngine (int ccode , const encodeRec * enc , int stop_with_one_result , int extraDigits ,
1222+ int requiredEncoder ,
12241223 int result_override ) {
12251224 int from , upto ;
12261225 int y = enc -> lat32 , x = enc -> lon32 ;
@@ -1261,13 +1260,13 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
12611260 isSubdivision (ccode )) // if the last item is a reference to a state's country
12621261 {
12631262 // *** do a recursive call for the parent ***
1264- encoderEngine (ParentTerritoryOf (ccode ), enc , stop_with_one_result , extraDigits , ccode );
1263+ encoderEngine (ParentTerritoryOf (ccode ), enc , stop_with_one_result , extraDigits , requiredEncoder , ccode );
12651264 return ; /**/
12661265 }
12671266 else // must be grid
12681267 {
12691268 // skip isRestricted records unless there already is a result
1270- if (result_counter > 0 || !isRestricted (i )) {
1269+ if (result_counter || !isRestricted (i )) {
12711270 char headerletter = (char ) ((recType (i ) == 1 ) ? headerLetter (i ) : 0 );
12721271 encodeGrid (result , enc , i , extraDigits , headerletter );
12731272 }
@@ -1279,7 +1278,7 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
12791278
12801279 repack_if_alldigits (result , 0 );
12811280
1282- if (debugStopAt < 0 || debugStopAt == i ) {
1281+ if (requiredEncoder < 0 || requiredEncoder == i ) {
12831282 int cc = (result_override >= 0 ? result_override : ccode );
12841283 if (* result && enc -> mapcodes && enc -> mapcodes -> count < MAX_NR_OF_MAPCODE_RESULTS ) {
12851284 char * s = enc -> mapcodes -> mapcode [enc -> mapcodes -> count ++ ];
@@ -1291,7 +1290,7 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
12911290 strcat (s , result );
12921291 }
12931292 }
1294- if (debugStopAt == i ) { return ; }
1293+ if (requiredEncoder == i ) { return ; }
12951294 }
12961295 if (stop_with_one_result ) { return ; }
12971296 * result = 0 ; // clear for next iteration
@@ -1302,7 +1301,6 @@ static void encoderEngine(int ccode, const encodeRec *enc, int stop_with_one_res
13021301 }
13031302}
13041303
1305-
13061304// returns nonzero if error
13071305static int decoderEngine (decodeRec * dec ) {
13081306 int parentcode ;
@@ -1494,7 +1492,7 @@ static int decoderEngine(decodeRec *dec) {
14941492 int fitssomewhere = 0 ;
14951493 int j ;
14961494 for (j = i - 1 ; j >= from ; j -- ) { // look in previous rects
1497- if (!isRestricted (( j ) )) {
1495+ if (!isRestricted (j )) {
14981496 if (fitsInsideWithRoom (dec -> lon32 , dec -> lat32 , j )) {
14991497 fitssomewhere = 1 ;
15001498 break ;
@@ -1504,8 +1502,7 @@ static int decoderEngine(decodeRec *dec) {
15041502 if (!fitssomewhere ) {
15051503 err = -1234 ;
15061504 }
1507- }
1508- // *** make sure decode fits somewhere ***
1505+ } // *** make sure decode fits somewhere ***
15091506 break ;
15101507 }
15111508 else if (recType (i ) == 1 && prefixLength (i ) + 1 == prelen && postfixLength (i ) == postlen &&
@@ -1800,16 +1797,16 @@ int compareWithMapcodeFormat(const char *s, int fullcode) {
18001797// pass point to an array of pointers (at least 42), will be made to point to result strings...
18011798// returns nr of results;
18021799static int encodeLatLonToMapcodes_internal (char * * v , Mapcodes * mapcodes , double lat , double lon , int tc ,
1803- int stop_with_one_result ,
1804- int extraDigits ) // 1.31 allow to stop after one result
1800+ int stop_with_one_result , int requiredEncoder ,
1801+ int extraDigits )
18051802{
18061803 encodeRec enc ;
18071804 enc .mapcodes = mapcodes ;
18081805 enc .mapcodes -> count = 0 ;
18091806
18101807 if (lat < -90 ) { lat = -90 ; } else if (lat > 90 ) { lat = 90 ; }
18111808 if (lon < -180 || lon > 180 ) {
1812- lon -= (360 * floor (lon / 360 ));
1809+ lon -= (360.0 * floor (lon / 360 ));
18131810 if (lon >= 180 ) { lon -= 360 ; }
18141811 }
18151812
@@ -1852,8 +1849,8 @@ static int encodeLatLonToMapcodes_internal(char **v, Mapcodes *mapcodes, double
18521849 int j , nr = v2 ;
18531850 for (j = 0 ; j <= nr ; j ++ ) {
18541851 int ctry = (j == nr ? ccode_earth : redivar [i + j ]);
1855- encoderEngine (ctry , & enc , stop_with_one_result , extraDigits , -1 );
1856- if ((stop_with_one_result || debugStopAt >= 0 ) && enc .mapcodes -> count > 0 ) { break ; }
1852+ encoderEngine (ctry , & enc , stop_with_one_result , extraDigits , requiredEncoder , -1 );
1853+ if ((stop_with_one_result || requiredEncoder >= 0 ) && enc .mapcodes -> count > 0 ) { break ; }
18571854 }
18581855 break ;
18591856 }
@@ -1870,13 +1867,13 @@ static int encodeLatLonToMapcodes_internal(char **v, Mapcodes *mapcodes, double
18701867#else
18711868 int i ;
18721869 for (i = 0 ;i < MAX_MAPCODE_TERRITORY_CODE ;i ++ ) {
1873- encoderEngine (i ,& enc ,stop_with_one_result ,extraDigits ,-1 );
1874- if ((stop_with_one_result || debugStopAt >=0 ) && enc .mapcodes -> count > 0 ) break ;
1870+ encoderEngine (i ,& enc ,stop_with_one_result ,extraDigits , requiredEncoder , -1 );
1871+ if ((stop_with_one_result || requiredEncoder >=0 ) && enc .mapcodes -> count > 0 ) break ;
18751872 }
18761873#endif
18771874 }
18781875 else {
1879- encoderEngine ((tc - 1 ), & enc , stop_with_one_result , extraDigits , -1 );
1876+ encoderEngine ((tc - 1 ), & enc , stop_with_one_result , extraDigits , requiredEncoder , -1 );
18801877 }
18811878
18821879 if (v ) {
@@ -2035,6 +2032,9 @@ const char *decodeToRoman(const UWORD *s) {
20352032 return convertToRoman (asciibuf , MAX_MAPCODE_RESULT_LEN , s );
20362033}
20372034
2035+ // Legacy: NOT threadsafe
2036+ static int debugStopAt = -1 ; // to externally test-restrict internal encoding, do not use!
2037+
20382038// Legacy: NOT threadsafe
20392039static UWORD unibuf [MAX_MAPCODE_RESULT_LEN ];
20402040
@@ -2048,7 +2048,7 @@ const UWORD *encodeToAlphabet(const char *mapcode, int alphabet) // 0=roman, 2=c
20482048int encodeLatLonToSingleMapcode (char * result , double lat , double lon , int tc , int extraDigits ) {
20492049 char * v [2 ];
20502050 Mapcodes rlocal ;
2051- int ret = encodeLatLonToMapcodes_internal (v , & rlocal , lat , lon , tc , 1 , extraDigits );
2051+ int ret = encodeLatLonToMapcodes_internal (v , & rlocal , lat , lon , tc , 1 , debugStopAt , extraDigits );
20522052 * result = 0 ;
20532053 if (ret <= 0 ) { // no solutions?
20542054 return -1 ;
@@ -2064,14 +2064,14 @@ int encodeLatLonToSingleMapcode(char *result, double lat, double lon, int tc, in
20642064
20652065// Threadsafe
20662066int encodeLatLonToMapcodes (Mapcodes * results , double lat , double lon , int territoryCode , int extraDigits ) {
2067- return encodeLatLonToMapcodes_internal (NULL , results , lat , lon , territoryCode , 0 , extraDigits );
2067+ return encodeLatLonToMapcodes_internal (NULL , results , lat , lon , territoryCode , 0 , debugStopAt , extraDigits );
20682068}
20692069
20702070// Legacy: NOT threadsafe
20712071Mapcodes rglobal ;
20722072
20732073int encodeLatLonToMapcodes_Deprecated (char * * v , double lat , double lon , int territoryCode , int extraDigits ) {
2074- return encodeLatLonToMapcodes_internal (v , & rglobal , lat , lon , territoryCode , 0 , extraDigits );
2074+ return encodeLatLonToMapcodes_internal (v , & rglobal , lat , lon , territoryCode , 0 , debugStopAt , extraDigits );
20752075}
20762076
20772077// Legacy: NOT threadsafe
0 commit comments