Skip to content

Commit 96251b4

Browse files
committed
Fixed warnings for GCC and repaired mapcoder.c to compile in Visual Studio 10
1 parent abafcaf commit 96251b4

File tree

8 files changed

+64
-25
lines changed

8 files changed

+64
-25
lines changed

LICENSE

100755100644
File mode changed.

NOTICE

100755100644
File mode changed.

README

100755100644
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ of how to use the library.
4949
To build the original Mapcode tool, execute:
5050

5151
cd example
52-
gcc mapcode.c -o mapcode
52+
gcc mapcode.cpp -o mapcode
5353

5454
For help, simply execute the binary file 'mapcode' without no arguments.
5555
This tool provides a rather extensive command-line interface to encode and
@@ -61,31 +61,42 @@ MAPCODE LIBRARY - RELEASE NOTES
6161
-------------------------------------------------------------------------------
6262

6363
1.33
64-
Fix to not remove valid results just across the edge of a territory. Iimproved interface readability
65-
and renamed methods to more readable forms.
64+
65+
Fix to not remove valid results just across the edge of a territory. Improved
66+
interface readability and renamed methods to more readable forms. Removed
67+
several warnings produced by GCC.
6668

6769
1.32
68-
Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative is produced in edge cases; prevent FIJI failing to
69-
decode at exactly 180 degrees.
70+
71+
Added encodeLatLonToSingleMapcode(); fixed 1.29 so no country-wide alternative is
72+
produced in edge cases; prevent FIJI failing to decode at exactly 180 degrees.
7073

7174
1.31
75+
7276
Added compareWithMapcodeFormat().
7377

7478
1.30
79+
7580
IUpdated the documentation and extended it with examples and suggestions.
7681

7782
1.29
83+
7884
Also generate country-wide alternative mapcodes for states.
7985

8086
1.28
81-
Bug fix for the needless generation of 7-letter alternatives to short mapcodes in large states in India.
87+
88+
Bug fix for the needless generation of 7-letter alternatives to short mapcodes
89+
in large states in India.
8290

8391
1.27
92+
8493
Improved (faster) implementation of the function isInArea.
8594

8695
1.26
96+
8797
Added alias OD ("Odisha") for indian state OR ("Orissa").
8898

8999
1.25
100+
90101
Initial release to the public domain.
91102

example/mapcode.cpp

100755100644
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
/**
2-
* Copyright (C) 2014 Stichting Mapcode Foundation
3-
* For terms of use refer to http://www.mapcode.com/downloads.html
1+
/*
2+
* Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
415
*/
516

617
/**
@@ -264,7 +275,7 @@ static const char* asCoordinate(double coord, char* target)
264275
target = &asCoordinateBuffer[ascoptr];
265276
ascoptr= ((ascoptr != 0) ? 0 : 12);
266277
}
267-
sprintf(target,"%s%d.%06d", (negative ? "-" : ""), c / 1000000, c % 1000000);
278+
sprintf(target,"%s%d.%06d", (negative ? "-" : ""), (int) (c / 1000000), (int) (c % 1000000));
268279
return target;
269280
}
270281

mapcode_library.doc

100755100644
File mode changed.

mapcodelib/basics.h

100755100644
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#define UWORD unsigned short int // 2-byte unsigned integer
218

319
#define mapcode_cversion "1.33"
@@ -10,7 +26,7 @@
1026
#define ALIASES "2UK=2UT,2CG=2CT,1GU=GUM,1UM=UMI,1VI=VIR,1PR=PRI,1AS=ASM,1MP=MNP,4JB=JBT,4QL=QLD,4TS=TAS,4CX=CXR,4CC=CCK,4NF=NFK,4HM=HMD,4NI=NFK,COL=5CL,5ME=5MX,MEX=5MX,5TM=TAM,5AG=AGU,5BC=BCN,5BS=BCS,5CM=CAM,5CS=CHP,5CH=CHH,5CO=COA,5DF=DIF,5DG=DUR,5GT=GUA,5GR=GRO,5HG=HID,5JA=JAL,5MI=MIC,5MO=MOR,5NA=NAY,5NL=NLE,5OA=OAX,5PB=PUE,5QE=QUE,5QR=ROO,5SL=SLP,5SI=SIN,5SO=SON,5TB=TAB,5TL=TLA,5VE=VER,5YU=YUC,5ZA=ZAC,811=8BJ,812=8TJ,813=8HE,814=8SX,815=8NM,821=8LN,822=8JL,823=8HL,831=8SH,832=8JS,833=8ZJ,834=8AH,835=8FJ,836=8JX,837=8SD,841=8HA,842=8HB,843=8HN,844=8GD,845=8GX,846=8HI,850=8CQ,851=8SC,852=8GZ,853=8YN,854=8XZ,861=8SN,862=8GS,863=8QH,864=8NX,865=8XJ,871=TWN,891=HKG,892=MAC,8TW=TWN,8HK=HKG,8MC=MAC,BEL=7BE,KIR=7KI,PRI=7PO,CHE=7CH,KHM=7KM,PER=7PM,TAM=7TT,0US=USA,0AU=AUS,0RU=RUS,0CN=CHN,EAZ=TZA,SKM=2SK,TAA=SHN,ASC=SHN,DGA=IOT,WAK=MHL,JTN=UMI,MID=1HI,2OD=2OR,"
1127

1228
#define MAX_CCODE 541 // total number of areas (i.e. recognised iso codes) in this database
13-
static char *entity_iso = ""
29+
static const char *entity_iso = ""
1430
"VAT,MCO,GIB,TKL,CCK,BLM,NRU,TUV,MAC,SXM,"
1531
"MAF,NFK,PCN,BVT,BMU,IOT,SMR,GGY,AIA,MSR,"
1632
"JEY,CXR,WLF,VGB,LIE,ABW,MHL,ASM,COK,SPM,"

mapcodelib/mapcoder.c

100755100644
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -832,16 +832,16 @@ void setup_country( int newccode )
832832

833833
if ( codex==13 ) { iso_count13++; if ( iso_first13<0 ) iso_first13=i; }
834834
if ( codex==21 ) { iso_count21++; if ( iso_first21<0 ) iso_first21=i; }
835-
if ( codex==22 ) if (pipe) {if (iso_firstpipe22<0) iso_firstpipe22=i; if (pipe<2) iso_pipeletter22[iso_pipecount22++]=pipeletter(i); else if (iso_firststar22<0) iso_firststar22=i;} else { iso_count22++; if ( iso_first22<0 ) iso_first22=i; }
836-
if ( codex==14 ) if (pipe) {if (iso_firstpipe14<0) iso_firstpipe14=i; if (pipe<2) iso_pipeletter14[iso_pipecount14++]=pipeletter(i); else if (iso_firststar14<0) iso_firststar14=i;} else { iso_count14++; if ( iso_first14<0 ) iso_first14=i; }
837-
if ( codex==23 ) if (pipe) {if (iso_firstpipe23<0) iso_firstpipe23=i; if (pipe<2) iso_pipeletter23[iso_pipecount23++]=pipeletter(i); else if (iso_firststar23<0) iso_firststar23=i;} else { iso_count23++; if ( iso_first23<0 ) iso_first23=i; }
838-
if ( codex==32 ) if (pipe) {if (iso_firstpipe32<0) iso_firstpipe32=i; if (pipe<2) iso_pipeletter32[iso_pipecount32++]=pipeletter(i); else if (iso_firststar32<0) iso_firststar32=i;} else { iso_count32++; if ( iso_first32<0 ) iso_first32=i; }
839-
if ( codex==24 ) if (pipe) {if (iso_firstpipe24<0) iso_firstpipe24=i; if (pipe<2) iso_pipeletter24[iso_pipecount24++]=pipeletter(i); else if (iso_firststar24<0) iso_firststar24=i;} else { iso_count24++; if ( iso_first24<0 ) iso_first24=i; }
840-
if ( codex==33 ) if (pipe) {if (iso_firstpipe33<0) iso_firstpipe33=i; if (pipe<2) iso_pipeletter33[iso_pipecount33++]=pipeletter(i); else if (iso_firststar33<0) iso_firststar33=i;} else { iso_count33++; if ( iso_first33<0 ) iso_first33=i; }
841-
if ( codex==34 ) if (pipe) {if (iso_firstpipe34<0) iso_firstpipe34=i; if (pipe<2) iso_pipeletter34[iso_pipecount34++]=pipeletter(i); else if (iso_firststar34<0) iso_firststar34=i;} else { iso_count34++; if ( iso_first34<0 ) iso_first34=i; }
835+
if ( codex==22 ) { if (pipe) {if (iso_firstpipe22<0) iso_firstpipe22=i; if (pipe<2) iso_pipeletter22[iso_pipecount22++]=pipeletter(i); else if (iso_firststar22<0) iso_firststar22=i;} else { iso_count22++; if ( iso_first22<0 ) iso_first22=i; } }
836+
if ( codex==14 ) { if (pipe) {if (iso_firstpipe14<0) iso_firstpipe14=i; if (pipe<2) iso_pipeletter14[iso_pipecount14++]=pipeletter(i); else if (iso_firststar14<0) iso_firststar14=i;} else { iso_count14++; if ( iso_first14<0 ) iso_first14=i; } }
837+
if ( codex==23 ) { if (pipe) {if (iso_firstpipe23<0) iso_firstpipe23=i; if (pipe<2) iso_pipeletter23[iso_pipecount23++]=pipeletter(i); else if (iso_firststar23<0) iso_firststar23=i;} else { iso_count23++; if ( iso_first23<0 ) iso_first23=i; } }
838+
if ( codex==32 ) { if (pipe) {if (iso_firstpipe32<0) iso_firstpipe32=i; if (pipe<2) iso_pipeletter32[iso_pipecount32++]=pipeletter(i); else if (iso_firststar32<0) iso_firststar32=i;} else { iso_count32++; if ( iso_first32<0 ) iso_first32=i; } }
839+
if ( codex==24 ) { if (pipe) {if (iso_firstpipe24<0) iso_firstpipe24=i; if (pipe<2) iso_pipeletter24[iso_pipecount24++]=pipeletter(i); else if (iso_firststar24<0) iso_firststar24=i;} else { iso_count24++; if ( iso_first24<0 ) iso_first24=i; } }
840+
if ( codex==33 ) { if (pipe) {if (iso_firstpipe33<0) iso_firstpipe33=i; if (pipe<2) iso_pipeletter33[iso_pipecount33++]=pipeletter(i); else if (iso_firststar33<0) iso_firststar33=i;} else { iso_count33++; if ( iso_first33<0 ) iso_first33=i; } }
841+
if ( codex==34 ) { if (pipe) {if (iso_firstpipe34<0) iso_firstpipe34=i; if (pipe<2) iso_pipeletter34[iso_pipecount34++]=pipeletter(i); else if (iso_firststar34<0) iso_firststar34=i;} else { iso_count34++; if ( iso_first34<0 ) iso_first34=i; } }
842842
if ( codex==42 ) { iso_count42++; if ( iso_first42<0 ) iso_first42=i; }
843843
if ( codex==43 ) { iso_count43++; if ( iso_first43<0 ) iso_first43=i; }
844-
if ( codex==44 ) if (pipe) {if (iso_firstpipe44<0) iso_firstpipe44=i; if (pipe<2) iso_pipeletter44[iso_pipecount44++]=pipeletter(i); else if (iso_firststar44<0) iso_firststar44=i;} else { iso_count44++; if ( iso_first44<0 ) iso_first44=i; }
844+
if ( codex==44 ) { if (pipe) {if (iso_firstpipe44<0) iso_firstpipe44=i; if (pipe<2) iso_pipeletter44[iso_pipecount44++]=pipeletter(i); else if (iso_firststar44<0) iso_firststar44=i;} else { iso_count44++; if ( iso_first44<0 ) iso_first44=i; } }
845845
}
846846
}
847847

@@ -1042,7 +1042,7 @@ void repack_if_alldigits(char *input)
10421042
char *e;
10431043
char *dotpos=NULL;
10441044

1045-
for (e=s;*e!=0 && *e!='-';e++) if (*e<'0' || *e>'9') if (*e=='.' && !dotpos) dotpos=e; else { alldigits=0; break; }
1045+
for (e=s;*e!=0 && *e!='-';e++) if (*e<'0' || *e>'9') { if (*e=='.' && !dotpos) dotpos=e; else { alldigits=0; break; } }
10461046
e--; s=e-1;
10471047
if (alldigits && dotpos && s>dotpos) // e is last char, s is one before, both are beyond dot, all characters are digits
10481048
{
@@ -1761,7 +1761,7 @@ void master_encode( char *resultbuffer, int the_ctry, long x, long y, int forcec
17611761
else // must be grid, possibly a multi-area
17621762
{
17631763
int multi_area = (pipetype(m)==1 ? 1 : 0); // has pipe letter?
1764-
if (codex==21) if (iso_count21==1) codex=22; else continue;
1764+
if (codex==21) { if (iso_count21==1) codex=22; else continue; }
17651765

17661766
if ( miny<=y && y<maxy && isInRange(x,minx,maxx) )
17671767
if ( codex!=55 ) // exclude Earth 55
@@ -1941,11 +1941,12 @@ int mapcode_encode(char *result,long y, long x, const char *iso3, char *isofound
19411941
if (isofound)
19421942
{
19431943
*isofound=0;
1944-
if (*result)
1944+
if (*result) {
19451945
if (resultlen(result)==10)
19461946
strcpy(isofound,makeiso(ccode_earth,1));
19471947
else
19481948
strcpy(isofound,makeiso(cc,1));
1949+
}
19491950
}
19501951
return *result;
19511952
}
@@ -2341,13 +2342,13 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
23412342
#define skipnum(i) {while (isdig(*i)) i++;}
23422343
#define skipfp(i) {skipnum(i); if (*i=='.') {i++;skipnum(i);}}
23432344

2344-
char *winds = islat ? "nsNS+- " : "ewEW+- ";
2345+
const char *winds = islat ? "nsNS+- " : "ewEW+- ";
23452346

23462347
// skip white spaces, signs and appropriate wind direction letters
23472348
char *p;
23482349
int sign=1;
23492350

2350-
while (*i && (p=strchr(winds,*i))!=NULL) { { if ( (p-winds) & 1 ) sign*=-1; } i++; }
2351+
while (*i && (p=(char*)strchr(winds,*i))!=NULL) { { if ( (p-(char*)winds) & 1 ) sign*=-1; } i++; }
23512352

23522353
// we are now at a lead digit, or there is an error
23532354
if (!isdig(*i))
@@ -2380,7 +2381,7 @@ int interpret_coord( const unsigned char *i, int islat, double *result )
23802381
}
23812382

23822383
// allow all posisble final endsigns
2383-
{ while (*i && (p=strchr(winds,*i))!=NULL) { if ( (p-winds) & 1 ) sign*=-1; i++; } }
2384+
{ while (*i && (p=(char*)strchr(winds,*i))!=NULL) { if ( (p-(char*)winds) & 1 ) sign*=-1; i++; } }
23842385

23852386
// we now MUST be at the end of the string!
23862387
if (*i)

mapcodelib/mapcoder.h

100755100644
File mode changed.

0 commit comments

Comments
 (0)