source: trunk/main.c @ 16

Last change on this file since 16 was 16, checked in by marius, 6 years ago

start using glib

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Date Author Id Revision HeadURL"
  • Property svn:mime-type set to text/plain
File size: 3.3 KB
Line 
1/*
2 * Memphis - Cairo Rederer for OSM in C
3 * Copyright (C) 2008  <marius.rieder@durchmesser.ch>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19#include <glib.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <string.h>
24#include <expat.h>
25
26#include "main.h"
27#include "osm05.h"
28#include "renderer.h"
29#include "ruleset.h"
30#include "list.h"
31
32// Global Vars
33GTree       *keyStrings;
34GTree       *valStrings;
35GTree       *patternStrings;
36memphisOpt  *opts;
37
38gint g_strcmp(gconstpointer  a, gconstpointer  b) {
39    return strcmp((char *)a,(char *)b);
40}
41
42void banner() {
43    fprintf(stdout,"Memphis OSM Renderer\n");
44}
45
46void usage(char *prog) {
47    banner();
48    fprintf(stdout,"%s [-v|-q] [-m|-t <X> <Y>] <configfile> <datafile>\n", prog);
49}
50
51int main(int argc, char **argv) {   
52    cfgRules *ruleset;
53    osmFile *osm;
54   
55    opts = malloc(sizeof(memphisOpt));
56    opts->debug = 1;
57    opts->cfgfn = NULL;
58    opts->osmfn = NULL;
59    opts->mode = MODE_MAP;
60    opts->minlayer = 12;
61    opts->maxlayer = 17;
62   
63    int i;
64    for (i = 1; i < argc ; i++) {
65        if ((!strcmp(argv[i], "-q")) || (!strcmp(argv[i], "--quiet"))) {
66            opts->debug--;
67        } else if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--verbose"))) {
68            opts->debug++;
69        } else if ((!strcmp(argv[i], "-m")) || (!strcmp(argv[i], "--map"))) {
70            opts->mode = MODE_MAP;
71        } else if ((!strcmp(argv[i], "-t")) || (!strcmp(argv[i], "--tile"))) {
72            if(sscanf(argv[i+1],"%hi",&opts->tile_x)!=1 ||
73               sscanf(argv[i+2],"%hi",&opts->tile_y)!=1 ) {
74                usage((char *) *argv);
75                exit(-1);
76            }
77            i+=2;
78        } else if (opts->cfgfn == NULL) {
79            opts->cfgfn = argv[i];
80        } else if (opts->osmfn == NULL) {
81            opts->osmfn = argv[i];
82        } else {
83            usage((char *) *argv);
84            exit(-1);
85        }
86    }
87   
88    if (argc < 2 || opts->cfgfn == NULL || opts->osmfn == NULL) {
89        usage((char *) *argv);
90        exit(-1);
91    }
92   
93    keyStrings = g_tree_new(g_strcmp);
94    valStrings = g_tree_new(g_strcmp);
95    patternStrings = g_tree_new(g_strcmp);
96                       
97    banner();
98   
99    ruleset = (cfgRules *) rulesetRead(opts->cfgfn);
100    if(ruleset == NULL)
101        return(-1);
102
103    osm = (osmFile *) osmRead(opts->osmfn);
104    if(ruleset == NULL)
105        return(-1);
106   
107    osmWay *way;
108    osmTag *tag;
109    LIST_FOREACH(way, osm->ways) {
110        if(way->id != 4719299)
111            continue;
112        printf("Way: %i\n",way->id);
113        LIST_FOREACH(tag, way->tag) {
114            printf(" %s: %s\n",tag->key, tag->value);
115        }
116    }
117   
118    renderCairo(ruleset, osm);
119   
120    return(0);
121}
122
Note: See TracBrowser for help on using the repository browser.