PostGIS  2.2.7dev-r@@SVN_REVISION@@
shpcommon.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2014 Sandro Santilli <strk@keybit.net>
7  * Copyright (C) 2010 Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU General Public Licence. See the COPYING file.
11  *
12  **********************************************************************/
13 
14 #ifndef SHPCOMMON_H
15 #define SHPCOMMON_H
16 
17 /* For internationalization */
18 #ifdef ENABLE_NLS
19 #include <libintl.h>
20 #include <locale.h>
21 #define _(String) gettext(String)
22 #define PACKAGE "shp2pgsql"
23 #else
24 #define _(String) String
25 #endif
26 
27 
28 
29 typedef struct
30 {
31  int ldid;
32  int cpg;
33  char *desc;
34  char *iconv;
35  char *pg;
37 
38 static int num_code_pages = 60;
39 
40 /* http://www.autopark.ru/ASBProgrammerGuide/DBFSTRUC.HTM */
41 /* http://resources.arcgis.com/fr/content/kbase?fa=articleShow&d=21106 */
42 
44  {0x01, 437, "U.S. MS-DOS", "CP437",""},
45  {0x02, 850, "International MS-DOS", "CP850",""},
46  {0x03, 1252, "Window ANSI", "WINDOWS-1252","WIN1252"},
47  {0x08, 865, "Danish OEM", "CP865",""},
48  {0x09, 437, "Dutch OEM", "CP437",""},
49  {0x0A, 850, "Dutch OEM*", "CP850",""},
50  {0x0B, 437, "Finnish OEM", "CP437",""},
51  {0x0D, 437, "French OEM", "CP437",""},
52  {0x0E, 850, "French OEM*", "CP850",""},
53  {0x0F, 437, "German OEM", "CP437",""},
54  {0x10, 850, "German OEM*", "CP850",""},
55  {0x11, 437, "Italian OEM", "CP437",""},
56  {0x12, 850, "Italian OEM*", "CP850",""},
57  {0x13, 932, "Japanese Shift-JIS", "CP932","SJIS"},
58  {0x14, 850, "Spanish OEM*", "CP850",""},
59  {0x15, 437, "Swedish OEM", "CP437",""},
60  {0x16, 850, "Swedish OEM*", "CP850",""},
61  {0x17, 865, "Norwegian OEM", "CP865",""},
62  {0x18, 437, "Spanish OEM", "CP865",""},
63  {0x19, 437, "English OEM (Britain)", "CP437",""},
64  {0x1A, 850, "English OEM (Britain)*", "CP850",""},
65  {0x1B, 437, "English OEM (U.S.)", "CP437",""},
66  {0x1C, 863, "French OEM (Canada)", "CP863",""},
67  {0x1D, 850, "French OEM*", "CP850",""},
68  {0x1F, 852, "Czech OEM", "CP852",""},
69  {0x22, 852, "Hungarian OEM", "CP852",""},
70  {0x23, 852, "Polish OEM", "CP852",""},
71  {0x24, 860, "Portuguese OEM", "CP860",""},
72  {0x25, 850, "Portuguese OEM*", "CP850",""},
73  {0x26, 866, "Russian OEM", "WINDOWS-866","WIN866"},
74  {0x37, 850, "English OEM (U.S.)*", "CP850",""},
75  {0x40, 852, "Romanian OEM", "CP852",""},
76  {0x4D, 936, "Chinese GBK (PRC)", "CP936",""},
77  {0x4E, 949, "Korean (ANSI/OEM)", "CP949",""},
78  {0x4F, 950, "Chinese Big 5 (Taiwan)", "CP950","BIG5"},
79  {0x50, 874, "Thai (ANSI/OEM)", "WIN874",""},
80  {0x57, 1252, "ANSI", "WINDOWS-1252",""},
81  {0x58, 1252, "Western European ANSI", "WINDOWS-1252",""},
82  {0x59, 1252, "Spanish ANSI", "WINDOWS-1252",""},
83  {0x64, 852, "Eastern European MS-DOS", "CP852",""},
84  {0x65, 866, "Russian MS-DOS", "CP866",""},
85  {0x66, 865, "Nordic MS-DOS", "CP865",""},
86  {0x67, 861, "Icelandic MS-DOS", "",""},
87  {0x6A, 737, "Greek MS-DOS (437G)", "CP737",""},
88  {0x6B, 857, "Turkish MS-DOS", "CP857",""},
89  {0x6C, 863, "French-Canadian MS-DOS", "CP863",""},
90  {0x78, 950, "Taiwan Big 5", "CP950",""},
91  {0x79, 949, "Hangul (Wansung)", "CP949",""},
92  {0x7A, 936, "PRC GBK", "CP936","GBK"},
93  {0x7B, 932, "Japanese Shift-JIS", "CP932",""},
94  {0x7C, 874, "Thai Windows/MS-DOS", "WINDOWS-874","WIN874"},
95  {0x86, 737, "Greek OEM", "CP737",""},
96  {0x87, 852, "Slovenian OEM", "CP852",""},
97  {0x88, 857, "Turkish OEM", "CP857",""},
98  {0xC8, 1250, "Eastern European Windows", "WINDOWS-1250","WIN1250"},
99  {0xC9, 1251, "Russian Windows", "WINDOWS-1251","WIN1251"},
100  {0xCA, 1254, "Turkish Windows", "WINDOWS-1254","WIN1254"},
101  {0xCB, 1253, "Greek Windows", "WINDOWS-1253","WIN1253"},
102  {0xCC, 1257, "Baltic Window", "WINDOWS-1257","WIN1257"},
103  {0xFF, 65001, "UTF-8", "UTF-8","UTF8"}
104 };
105 
106 
107 
108 typedef struct shp_connection_state
109 {
110  /* PgSQL username to log in with */
111  char *username;
112 
113  /* PgSQL password to log in with */
114  char *password;
115 
116  /* PgSQL database to connect to */
117  char *database;
118 
119  /* PgSQL port to connect to */
120  char *port;
121 
122  /* PgSQL server to connect to */
123  char *host;
124 
126 
127 /* External shared functions */
128 char *escape_connection_string(char *str);
129 
130 /* Column map between pgsql and dbf */
131 typedef struct colmap_t {
132 
133  /* Column map pgfieldnames */
134  char **pgfieldnames;
135 
136  /* Column map dbffieldnames */
138 
139  /* Number of entries within column map */
140  int size;
141 
142 } colmap;
143 
174 int colmap_read(const char *fname, colmap *map, char *ebuf, size_t ebuflen);
175 
176 void colmap_init(colmap *map);
177 
178 void colmap_clean(colmap *map);
179 
180 const char *colmap_dbf_by_pg(colmap *map, const char *pgname);
181 
182 const char *colmap_pg_by_dbf(colmap *map, const char *dbfname);
183 
184 char *codepage2encoding(const char *cpg);
185 char *encoding2codepage(const char *encoding);
186 
187 #endif
void colmap_clean(colmap *map)
Definition: shpcommon.c:87
int ldid
Definition: shpcommon.h:31
char * iconv
Definition: shpcommon.h:34
int size
Definition: shpcommon.h:140
struct shp_connection_state SHPCONNECTIONCONFIG
static code_page_entry code_pages[]
Definition: shpcommon.h:43
char * codepage2encoding(const char *cpg)
Definition: shpcommon.c:206
int cpg
Definition: shpcommon.h:32
int colmap_read(const char *fname, colmap *map, char *ebuf, size_t ebuflen)
Read the content of filename into a symbol map.
Definition: shpcommon.c:131
char * desc
Definition: shpcommon.h:33
void colmap_init(colmap *map)
Definition: shpcommon.c:79
char * pg
Definition: shpcommon.h:35
char ** pgfieldnames
Definition: shpcommon.h:134
struct colmap_t colmap
Definition: shpcommon.h:29
char * escape_connection_string(char *str)
Escape strings that are to be used as part of a PostgreSQL connection string.
Definition: shpcommon.c:29
static int num_code_pages
Definition: shpcommon.h:38
char * encoding2codepage(const char *encoding)
Definition: shpcommon.c:259
char ** dbffieldnames
Definition: shpcommon.h:137
const char * colmap_pg_by_dbf(colmap *map, const char *dbfname)
Definition: shpcommon.c:117
const char * colmap_dbf_by_pg(colmap *map, const char *pgname)
Definition: shpcommon.c:103