source: subversion/applications/utils/import/and2osm/tags.c @ 4349

Last change on this file since 4349 was 4179, checked in by marc, 13 years ago

add binary tree to nodes, segments and ways

File size: 3.0 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2007  Marc Kessels
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 ******************************************************************************
22 */
23#include <stdlib.h>
24#include <string.h>
25#include <stdio.h>
26#include "rb.h"
27#include "osm.h"
28#include "tags.h"
29struct rb_table * text_table=NULL;
30extern int postgres;
31
32
33/* File descriptor for .osm file. */
34extern FILE *fp;
35
36/* File descriptors for postgres sql files. */
37extern FILE *fp_n;
38extern FILE *fp_nt;
39extern FILE *fp_w;
40extern FILE *fp_wn;
41extern FILE *fp_wt;
42
43void saveTag(struct tags *p,struct nodes * n){
44        if (postgres) 
45                fprintf(fp_nt, "%li\t%s\t%s\n", n->ID, p->key, p->value);//fp_nt
46        else
47                fprintf(fp,"    <tag k=\"%s\" v=\"%s\" />\n",p->key,p->value);
48        return;
49}
50
51void saveTags(struct tags *p,struct nodes *n){
52//      printf("in saveTags %p\n",p);
53        if (p!=NULL)
54        {
55                saveTag(p,n);
56                saveTags(p->nextTag,n);
57        }
58        return;
59}
60
61char * addText(char * text)
62{
63        char * storetext;
64        char ** p;
65        storetext = (char *) calloc(1,(strlen(text)+1)*sizeof(char));
66        if (storetext==NULL)
67        {
68                fprintf(stderr,"out of memory\n");
69                exit(1);
70        }
71        strcpy(storetext,text);
72        p=(char **) rb_probe (text_table, storetext);
73        if (*p!=storetext)
74        {
75                //item was already in list
76                free(storetext);
77        }
78        return *p;
79}
80
81struct tags * addtag(struct tags *p,char * tag_key, char * tag_value,struct tags **rv){
82        if (p==NULL)
83        {
84                /*new tag arrived*/
85                p = (struct tags *) calloc(1,sizeof(struct tags));
86                if (p==NULL)
87                {
88                        fprintf(stderr,"out of memory\n");
89                        exit(1);
90                }
91                p->nextTag=NULL;
92                p->key=addText(tag_key);
93                p->value=addText(tag_value);
94                if (rv!=NULL) *rv=p;
95        }
96        else
97                p->nextTag=addtag(p->nextTag, tag_key, tag_value,rv);
98        return p;
99}
100
101
102int compare_strings (const void *pa, const void *pb, void *param)
103{
104        return strcmp (pa, pb);
105}
106
107
108void init_tags()
109{
110        if (text_table==NULL)
111        {
112                text_table=rb_create (compare_strings, NULL,NULL);
113        }
114        else
115        {
116                printf("error: text_table is inited twice\n");
117                exit(1);
118        }
119        return;
120};
Note: See TracBrowser for help on using the repository browser.