Read the content of filename into a symbol map.
The content of the file is lines of two names separated by white space and no trailing or leading space:
COLUMNNAME DBFFIELD1 AVERYLONGCOLUMNNAME DBFFIELD2
etc.
It is the reponsibility of the caller to reclaim the allocated space as follows:
free(map->colmap_pgfieldnames[]) to free the column names free(map->colmap_dbffieldnames[]) to free the dbf field names
TODO: provide a clean_colmap()
- Parameters
-
| filename | name of the mapping file |
| map | container of colmap where the malloc'd symbol map will be stored. |
| errbuf | buffer to write error messages to |
| errbuflen | length of buffer to write error messages to |
- Returns
- 1 on success, 0 on error (and errbuf would be filled)
Definition at line 213 of file shpcommon.c.
214{
215 FILE *fptr;
216 char linebuffer[1024];
217 char *tmpstr;
218 int curmapsize, fieldnamesize;
219
220
221
222 fptr = fopen(filename, "r");
223 if (!fptr)
224 {
225
226 snprintf(errbuf, errbuflen,
_(
"ERROR: Unable to open column map file %s"),
227 filename);
228 return 0;
229 }
230
231
232 while (fgets(linebuffer, 1024, fptr) != NULL) ++map->
size;
233
234
235 fseek(fptr, 0, SEEK_SET);
238
239
240 curmapsize = 0;
241 while (fgets(linebuffer, 1024, fptr) != NULL)
242 {
243
244
245 fieldnamesize = strcspn(linebuffer, "\t\n ");
246 tmpstr = linebuffer;
247
248
250 strncpy(map->
pgfieldnames[curmapsize], tmpstr, fieldnamesize);
252
253
254 tmpstr = linebuffer + fieldnamesize;
255 tmpstr += strspn(tmpstr, "\t\n ");
256
257
258 fieldnamesize = strcspn(tmpstr, "\t\n ");
259
260
262 strncpy(map->
dbffieldnames[curmapsize], tmpstr, fieldnamesize);
264
265
267 {
268 snprintf(errbuf, errbuflen,
_(
"ERROR: column map file specifies a DBF field name \"%s\" which is longer than 10 characters"), map->
dbffieldnames[curmapsize]);
269 return 0;
270 }
271
272 ++curmapsize;
273 }
274
275 fclose(fptr);
276
277
278 return 1;
279}
References _, colmap_t::dbffieldnames, malloc(), colmap_t::pgfieldnames, and colmap_t::size.
Referenced by ShpDumperOpenTable(), and ShpLoaderOpenShape().