Changeset 141 for trunk


Ignore:
Timestamp:
Oct 16, 2009, 12:25:53 AM (5 years ago)
Author:
simon
Message:

Merge the 'client-library-split' branch into trunk

New Features:

  • Split the project into a library and a client
  • Relicense all code as LGPL
  • Remove all global variables
  • Make most functions thread-safe (Exceptions: parsing maps and rules)
  • Add a GObject based API
  • Add zoom level 18 support
  • Add capability to query and edit rules

Note: This code was created during the Google Summer of Code 2009.

Location:
trunk
Files:
2 deleted
19 edited
15 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/SConstruct

    r71 r141  
    22 
    33env = Environment() 
    4 env.MergeFlags(['-Wall -lm -std=c99 -lexpat']) 
     4env.MergeFlags(['-Wall -Werror -lm -std=c99 -lexpat']) 
    55 
    66if ARGUMENTS.get('optimize') in ('y', 'yes'): 
     
    1515env.ParseConfig('pkg-config --cflags --libs cairo') 
    1616env.ParseConfig('pkg-config --cflags --libs glib-2.0') 
     17env.ParseConfig('pkg-config --cflags --libs gobject-2.0') 
    1718 
    1819conf = Configure(env) 
     
    3435SOURCES = [ 
    3536    'libmercator.c', 
    36     'main.c', 
    3737    'osm05.c', 
    38     'renderer.c', 
    3938    'ruleset.c', 
    4039    'textpath.c', 
    41     'mlib.c' 
     40    'mlib.c', 
     41    'memphis-data-pool.c', 
     42    'memphis-map.c', 
     43    'memphis-rule.c', 
     44    'memphis-rule-set.c', 
     45    'memphis-renderer.c' 
    4246] 
    4347 
    44 Default(env.Program('memphis', source = SOURCES)) 
     48Default(env.Program('memphis', source = ['main.c', SOURCES])) 
    4549 
    4650env.Program('testTextPath', source=['test/testTextPath.c','textpath.c']) 
     
    5054 
    5155#env.Program('testRuleset', source=['ruleset.c','testRuleset.c']) 
     56 
     57env.Program('tile-renderer', source = ['demos/tile-renderer.c', SOURCES]) 
     58env.Program('testing', source = ['tests/tests.c', SOURCES]) 
  • trunk/libmercator.c

    r54 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <math.h> 
    21 #include <stdio.h> 
    2222 
    2323#include "libmercator.h" 
    2424 
    2525 
    26 coordinates coord2xy(double lat, double lon, int z) { 
     26coordinates coord2xy(double lat, double lon, int z, int tilesize) { 
    2727    coordinates result; 
    28     result.x = numTiles(z) * TILESIZE * (lon + 180) / 360; 
    29     result.y = numTiles(z) * TILESIZE * (1 - log(tan(radians(lat)) + sec(radians(lat))) / G_PI) / 2; 
    30     return(result); 
     28    result.x = numTiles(z) * tilesize * (lon + 180.0) / 360.0; 
     29    result.y = numTiles(z) * tilesize * (1.0 - log(tan(radians(lat)) 
     30            + sec(radians(lat))) / G_PI) / 2.0; 
     31    return result; 
    3132} 
    3233 
     
    4344    coordinates result; 
    4445    result.x = numTiles(z) * (lon + 180) / 360; 
    45     result.y = numTiles(z) * (1 - log(tan(radians(lat)) + sec(radians(lat))) / G_PI) / 2; 
     46    result.y = numTiles(z) * (1 - log(tan(radians(lat)) 
     47            + sec(radians(lat))) / G_PI) / 2; 
    4648 
    4749    return(result); 
     
    8385} 
    8486 
     87/* converts 'slippy maps' tile number to lat & lon in degrees */ 
     88coordinates tile2latlon (int x, int y, int z) { 
     89    coordinates ret; /* (lat_deg, lon_deg) */ 
     90    int n; 
     91    double lat_rad; 
     92     
     93    n = numTiles (z); 
     94    ret.y = (double) x / (double) n * 360.0 - 180.0; 
     95    lat_rad = atan (sinh (G_PI * (1.0 - 2.0 * (double) y / (double) n))); 
     96    ret.x = lat_rad * 180.0 / G_PI; 
     97 
     98    return ret;  
     99} 
     100 
     101/* converts lon in degrees to a 'slippy maps' x tile number */ 
     102int lon2tilex (double lon_deg, int z) { 
     103    double ret; 
     104    ret = ((lon_deg + 180.0) / 360.0) * numTiles (z); 
     105     
     106    return floor (ret); 
     107} 
     108 
     109/* converts lat in degrees to a 'slippy maps' y tile number */ 
     110int lat2tiley (double lat_deg, int z) { 
     111    int n; 
     112    double ret, lat_rad; 
     113     
     114    n = numTiles (z); 
     115    lat_rad = lat_deg * G_PI / 180.0; 
     116    ret = (1.0 - (log (tan (lat_rad) + sec (lat_rad)) / G_PI)) 
     117            / 2.0 * n; 
     118     
     119    return floor (ret); 
     120} 
     121 
    85122/* 
    86123 * vim: expandtab shiftwidth=4 tabstop=4: 
  • trunk/libmercator.h

    r76 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
     
    2626#define radians(a) (a*G_PI/180.0) 
    2727 
    28 #define TILESIZE        256 
    29 #define LINESIZE(z)     (int)(exp2(z-12)/(z-12+1)) 
    30  
     28//#define LINESIZE(z)     (int)(exp2(z-12)/(z-12+1)) 
     29//#define LINESIZE(z)     ((z)<=12 ? 1 : (z)<=14 ? 2 : (z)<=15 ? 3 : (z)<=16 ? 3 : (z) <= 17 ? 5 : (z)<=18 ? 6 : 6) 
     30// FIXME: Improve scaling factors for zoom levels < 12 
     31#define LINESIZE(z)     ((z)<12 ? 1 : (z)==18 ? 6 : (int)(exp2(z-12)/(z-12+1))) 
    3132 
    3233#define mercatorToLat(Y) degrees(atan(sinh(Y))) 
     
    5253 * Function Prototype 
    5354 */ 
    54 coordinates coord2xy(double lat, double lon, int z); 
     55coordinates coord2xy(double lat, double lon, int z, int tilesize); 
    5556coordinates latlon2relativeXY(double lat, double lon); 
    5657coordinates latlon2xy(double lat, double lon, int z); 
     
    5859coordinates lonEdges(int x, int z); 
    5960edges tileEdges(int x, int y, int z); 
     61coordinates tile2latlon (int x, int y, int z); 
     62int lon2tilex (double lon_deg, int z); 
     63int lat2tiley (double lat_deg, int z); 
    6064 
    6165#endif //LIBMERCATOR_H 
  • trunk/list.h

    r54 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
  • trunk/main.c

    r62 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    20 #include <stdio.h> 
    2121#include <stdlib.h> 
    22 #include <unistd.h> 
    2322#include <string.h> 
    24 #include <expat.h> 
    25  
    26 #include <sys/resource.h> 
     23#include <math.h> 
    2724 
    2825#include "main.h" 
    29 #include "osm05.h" 
    30 #include "renderer.h" 
    31 #include "ruleset.h" 
    32 #include "list.h" 
    33 #include "mlib.h" 
    34  
    35 // Global Vars 
    36 GStringChunk *stringChunk; 
    37 GTree        *stringTree; 
     26#include "memphis.h" 
    3827 
    3928/* Renderer Options */ 
     
    4837}; 
    4938memphisOpt  *opts = &opts_storage; 
     39 
     40static int draw (MemphisRenderer *renderer) { 
     41  gint z, zoom; 
     42  gchar *filename; 
     43 
     44  // Initialize all layers  
     45  for (z = 0; z <= (opts->maxlayer - opts->minlayer); z++) { 
     46    zoom = z + opts->minlayer; 
     47    // Save Images 
     48    filename = g_strdup_printf ("%s/%02i.png", opts->outdir, zoom); 
     49    memphis_renderer_draw_png (renderer, filename, zoom); 
     50    g_free (filename); 
     51  } 
     52 
     53  return 0; 
     54} 
    5055 
    5156static gboolean set_verbosity_level(const gchar *option_name, 
     
    118123 
    119124static void banner() { 
    120     fprintf(stdout,"Memphis OSM Renderer " MEMPHIS_VERSION "\n"); 
     125    g_print("Memphis OSM Renderer " MEMPHIS_VERSION "\n"); 
    121126} 
    122127 
    123128int main(int argc, char **argv) { 
    124129 
    125     cfgRules *ruleset; 
    126     osmFile *osm; 
     130    g_type_init (); 
    127131 
     132    MemphisRuleSet *ruleset; 
     133    MemphisMap *osm; 
     134    MemphisRenderer *renderer; 
    128135    GError *error = NULL; 
    129136    GOptionContext *optctx; 
     
    152159        g_print("error: rules file or osm map file missing:\n\n%s\n", 
    153160                g_option_context_get_summary(optctx)); 
    154         exit(-1); 
     161        return(-1); 
    155162    } 
    156163 
    157164    g_option_context_free(optctx); 
    158165 
    159     stringChunk = g_string_chunk_new(265); 
    160     stringTree = g_tree_new(m_tree_strcmp); 
    161  
    162166    banner(); 
    163167 
    164     ruleset = (cfgRules *) rulesetRead(opts->cfgfn); 
    165     if(ruleset == NULL) 
     168    ruleset = memphis_rule_set_new (); 
     169    memphis_rule_set_load_from_file (ruleset, opts->cfgfn); 
     170    if (ruleset->ruleset == NULL) 
    166171        return(-1); 
    167172 
    168     osm = (osmFile *) osmRead(opts->osmfn); 
    169     if(ruleset == NULL) 
     173    osm = memphis_map_new (); 
     174    memphis_map_load_from_file (osm, opts->osmfn); 
     175    if (osm->map == NULL) 
    170176        return(-1); 
    171177 
    172     g_tree_destroy(stringTree); 
     178    renderer = memphis_renderer_new_full (ruleset, osm); 
     179    memphis_renderer_set_debug_level (renderer, opts->debug); 
     180     
     181    draw (renderer); 
    173182 
    174     renderCairo(ruleset, osm); 
    175  
    176     osmFree(osm); 
    177     rulesetFree(ruleset); 
    178  
    179     g_string_chunk_free(stringChunk); 
     183    memphis_map_free (osm); 
     184    memphis_rule_set_free (ruleset); 
     185    memphis_renderer_free (renderer); 
    180186 
    181187    return(0); 
  • trunk/main.h

    r76 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
  • trunk/mlib.c

    r58 r141  
    11/* 
    22 * MLib - GLib additions 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <string.h> 
  • trunk/mlib.h

    r58 r141  
    11/* 
    22 * MLib - GLib additions 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
  • trunk/osm05.c

    r57 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <glib/gstdio.h> 
    21  
    2222#include <time.h> 
    2323#include <expat.h> 
    24 #include <stdio.h> 
    2524#include <string.h> 
    2625 
    2726#include "list.h" 
    2827#include "mlib.h" 
    29 #include "main.h" 
    3028#include "osm05.h" 
     29#include "memphis-data-pool.h" 
    3130 
    3231#define BUFFSIZE 1024 
    3332 
    34 // External Vars 
    35 extern memphisOpt   *opts; 
    36 extern GStringChunk *stringChunk; 
    37 extern GTree        *stringTree; 
    38  
    39 // Pointers to work with 
    40 osmTag      *cTag = NULL; 
    41 osmNode     *cNode = NULL; 
    42 osmWay      *cWay = NULL; 
    43  
    44 // Counts 
    45 int     cntTag = 0; 
    46 int     cntNd = 0; 
     33typedef struct mapUserData_ mapUserData; 
     34struct mapUserData_ { 
     35  // Pointers to work with 
     36  osmTag *cTag; 
     37  osmNode *cNode; 
     38  osmWay *cWay; 
     39  MemphisDataPool *pool; 
     40  // Collected Data 
     41  osmFile *osm; 
     42  // Counts (used for debugging only!) 
     43  int cntTag; 
     44  int cntNd; 
     45  gint8 debug_level; 
     46}; 
    4747 
    4848/** 
     
    5656static void XMLCALL 
    5757osmStartElement(void *userData, const char *name, const char **atts) { 
    58     osmFile *osm = (osmFile *) userData; 
    59      if (opts->debug > 1) 
    60         fprintf(stdout,"osm05startElement\n"); 
     58    mapUserData *data = (mapUserData *) userData; 
     59    osmFile *osm = data->osm; 
     60    GStringChunk *stringChunk = data->pool->stringChunk; 
     61    GTree *stringTree = data->pool->stringTree; 
     62    gint8 debug_level = data->debug_level; 
     63     
     64    if (debug_level > 1) 
     65        g_fprintf (stdout, "osm05startElement\n"); 
    6166    // Parsing Bounds 
    6267    if (strncmp((char *) name, "bounds", 6) == 0) { 
    63         if (opts->debug > 1) 
    64             fprintf(stdout,"Parsing Bounds\n"); 
     68        if (debug_level > 1) 
     69            g_fprintf (stdout, "Parsing Bounds\n"); 
    6570        while (*atts != NULL) { 
    6671            if(strcmp((char *) *(atts), "minlat" ) == 0) { 
     
    7883    // Parsing Node 
    7984    else if (strncmp((char *) name, "node", 4) == 0) { 
    80         if (opts->debug > 1) 
    81             fprintf(stdout,"Parsing Node\n"); 
    82         cNode = g_new(osmNode, 1); 
     85        if (debug_level > 1) 
     86            g_fprintf (stdout, "Parsing Node\n"); 
     87        data->cNode = g_new(osmNode, 1); 
    8388        while (*atts != NULL) { 
    8489            if(strcmp((char *) *(atts), "id") == 0) { 
    85                 sscanf((char *) *(atts+1),"%i",&cNode->id); 
     90                sscanf((char *) *(atts+1),"%i",&data->cNode->id); 
    8691            } else if(strcmp((char *) *(atts), "lat") == 0) { 
    87                 sscanf((char *) *(atts+1),"%f",&cNode->lat); 
     92                sscanf((char *) *(atts+1),"%f",&data->cNode->lat); 
    8893            } else if(strcmp((char *) *(atts), "lon") == 0) { 
    89                 sscanf((char *) *(atts+1),"%f",&cNode->lon); 
     94                sscanf((char *) *(atts+1),"%f",&data->cNode->lon); 
    9095            } 
    9196            atts+=2; 
    9297        } 
    9398 
    94         cNode->tag = NULL; 
    95         cNode->layer = 0; 
     99        data->cNode->tag = NULL; 
     100        data->cNode->layer = 0; 
    96101 
    97102        // Insert Node 
    98103        osm->nodecnt++; 
    99         g_hash_table_insert(osm->nodeidx, &cNode->id, cNode); 
    100         LL_PREPEND(cNode,osm->nodes); 
    101  
    102         if (opts->debug > 1) 
    103             fprintf(stdout,"NODE: %i %f %f\n", cNode->id, cNode->lat, cNode->lon); 
     104        g_hash_table_insert(osm->nodeidx, &data->cNode->id, data->cNode); 
     105        LL_PREPEND(data->cNode, osm->nodes); 
     106 
     107        if (debug_level > 1) 
     108            g_fprintf (stdout, "NODE: %i %f %f\n", data->cNode->id, 
     109                    data->cNode->lat, data->cNode->lon); 
    104110    } 
    105111    // Parsing Tags 
    106112    else if (strncmp((char *) name, "tag", 4) == 0) { 
    107         if (opts->debug > 1) 
    108             fprintf(stdout,"Parsing Tag\n"); 
    109  
    110         if (!cNode && !cWay) // End if ther is nothing to add the tag to 
     113        if (debug_level > 1) 
     114            g_fprintf (stdout, "Parsing Tag\n"); 
     115 
     116        if (!data->cNode && !data->cWay) // End if there is nothing to add the tag to 
    111117            return; 
    112118             
     
    123129            } else if(strncmp((char *) *(atts), "v", 1) == 0) { 
    124130                if(strcmp(k, "layer") == 0) { 
    125                     if (cNode) 
    126                         sscanf((char *) *(atts+1),"%hi",& cNode->layer); 
    127                     else if (cWay) 
    128                         sscanf((char *) *(atts+1),"%hi",& cWay->layer); 
     131                    if (data->cNode) 
     132                        sscanf((char *) *(atts+1),"%hi",& data->cNode->layer); 
     133                    else if (data->cWay) 
     134                        sscanf((char *) *(atts+1),"%hi",& data->cWay->layer); 
    129135                    return; 
    130136                } else if(strcmp(k, "name") == 0) { 
    131                     if (cWay) { 
    132                         cWay->name = m_string_chunk_get(stringChunk, stringTree,  
     137                    if (data->cWay) { 
     138                        data->cWay->name = m_string_chunk_get(stringChunk, stringTree,  
    133139                                                        (char *) *(atts+1)); 
    134140                    } 
     
    140146        } 
    141147         
    142         cTag = g_new(osmTag, 1); 
    143         cTag->key = m_string_chunk_get(stringChunk, stringTree, k); 
    144         cTag->value = m_string_chunk_get(stringChunk, stringTree, v); 
     148        data->cTag = g_new(osmTag, 1); 
     149        data->cTag->key = m_string_chunk_get(stringChunk, stringTree, k); 
     150        data->cTag->value = m_string_chunk_get(stringChunk, stringTree, v); 
    145151         
    146         if (opts->debug > 1) 
    147             fprintf(stdout,"Tag: %s => %s\n", cTag->key, cTag->value); 
    148  
    149         cntTag++; 
    150         if (cNode) 
    151             LL_INSERT_KEY(cTag,cNode->tag); 
    152         else if (cWay) 
    153             LL_INSERT_KEY(cTag,cWay->tag); 
    154  
    155         cTag = NULL; 
     152        if (debug_level > 1) 
     153            g_fprintf (stdout, "Tag: %s => %s\n", data->cTag->key, data->cTag->value); 
     154 
     155        data->cntTag++; 
     156        if (data->cNode) 
     157            LL_INSERT_KEY(data->cTag, data->cNode->tag); 
     158        else if (data->cWay) 
     159            LL_INSERT_KEY(data->cTag, data->cWay->tag); 
     160 
     161        data->cTag = NULL; 
    156162    } 
    157163    // Parsing Way 
    158164    else if (strncmp((char *) name, "way", 3) == 0) { 
    159         if (opts->debug > 1) 
    160             fprintf(stdout,"Parsing Way\n"); 
    161         cWay = g_new(osmWay, 1); 
     165        if (debug_level > 1) 
     166            g_fprintf (stdout, "Parsing Way\n"); 
     167        data->cWay = g_new(osmWay, 1); 
    162168        while (*atts != NULL) { 
    163169            if(strncmp((char *) *(atts), "id", 2) == 0) { 
    164                 sscanf((char *) *(atts+1),"%i",&cWay->id); 
     170                sscanf((char *) *(atts+1), "%i", &data->cWay->id); 
    165171                break; 
    166172            } 
     
    168174        } 
    169175 
    170         cWay->tag = NULL; 
    171         cWay->nd = NULL; 
    172         cWay->name = NULL; 
    173         cWay->layer = 0; 
     176        data->cWay->tag = NULL; 
     177        data->cWay->nd = NULL; 
     178        data->cWay->name = NULL; 
     179        data->cWay->layer = 0; 
    174180 
    175181        // Insert Way 
    176182        osm->waycnt++; 
    177         LL_PREPEND(cWay,osm->ways); 
    178  
    179         if (opts->debug > 1) 
    180             fprintf(stdout,"WAY(%i)\n", cWay->id); 
     183        LL_PREPEND(data->cWay, osm->ways); 
     184 
     185        if (debug_level > 1) 
     186            g_fprintf (stdout, "WAY(%i)\n", data->cWay->id); 
    181187    } 
    182188    // Parsing WayNode 
    183189    else if (strncmp((char *) name, "nd", 2) == 0) { 
    184         if (opts->debug > 1) 
    185             fprintf(stdout,"Parsing Nd\n"); 
     190        if (debug_level > 1) 
     191            g_fprintf (stdout, "Parsing Nd\n"); 
    186192        int ref = 0; 
    187193        while (*atts != NULL) { 
     
    194200 
    195201        if (ref) { 
    196             cntNd++; 
     202            data->cntNd++; 
    197203            osmNode *n; 
    198204             
     
    204210 
    205211            // Insert WayNode 
    206             cWay->nd = g_slist_prepend(cWay->nd, n); 
    207  
    208             if (opts->debug > 1) 
    209                 fprintf(stdout," ND( %f %f )\n", n->lat, n->lon); 
    210  
    211             cNode=NULL; 
     212            data->cWay->nd = g_slist_prepend(data->cWay->nd, n); 
     213 
     214            if (debug_level > 1) 
     215                g_fprintf (stdout, " ND( %f %f )\n", n->lat, n->lon); 
     216 
     217            data->cNode = NULL; 
    212218        } 
    213219    } 
     
    224230static void XMLCALL 
    225231osmEndElement(void *userData, const char *name) { 
    226     if (opts->debug > 1) 
    227         fprintf(stdout,"osm05endElement\n"); 
     232    mapUserData *data = (mapUserData *) userData; 
     233    gint8 debug_level = data->debug_level; 
     234     
     235    if (debug_level > 1) 
     236        g_fprintf(stdout, "osm05endElement\n"); 
    228237    if (strncmp((char *) name, "node", 4) == 0) { 
    229         cNode = NULL; 
     238        data->cNode = NULL; 
    230239    } else if (strncmp((char *) name, "way", 3) == 0) { 
    231         if (cWay->nd != NULL) 
    232             cWay->nd = g_slist_reverse(cWay->nd); 
    233         cWay = NULL; 
     240        if (data->cWay->nd != NULL) 
     241            data->cWay->nd = g_slist_reverse(data->cWay->nd); 
     242        data->cWay = NULL; 
    234243    } 
    235244} 
     
    238247 * rulesetRead 
    239248 */ 
    240 osmFile* osmRead(char *filename) { 
    241     if (opts->debug > 1) 
    242         fprintf(stdout,"osmRead\n"); 
    243  
    244     // Init vars 
    245     cntTag = 0; 
    246     cntNd = 0; 
     249osmFile* osmRead(const char *filename, gint8 debug_level) { 
     250    if (debug_level > 1) 
     251        g_fprintf (stdout, "osmRead\n"); 
    247252 
    248253    // Local Vars 
     
    254259    int done; 
    255260    char *buf; 
    256     osmFile *osm = NULL; 
     261    osmFile *osm; 
     262    mapUserData *data; 
    257263     
    258264    // Test file 
    259265    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { 
    260         fprintf(stderr,"Error: \"%s\" is not a file.\n",filename); 
     266        g_critical ("Error: \"%s\" is not a file.\n", filename); 
    261267        return NULL; 
    262268    } 
     
    268274    FILE *fd = fopen(filename,"r"); 
    269275    if(fd == NULL) { 
    270         fprintf(stderr,"Error: Can't open file \"%s\"\n",filename); 
     276        g_critical ("Error: Can't open file \"%s\"\n", filename); 
    271277        return NULL; 
    272278    } 
     279 
     280    // Init vars 
     281    data = g_new(mapUserData, 1); 
     282    data->cTag = NULL; 
     283    data->cNode = NULL; 
     284    data->cWay = NULL; 
     285    data->pool = memphis_data_pool_new (); 
     286    data->cntTag = 0; 
     287    data->cntNd = 0; 
     288    data->debug_level = debug_level; 
    273289 
    274290    osm = g_new(osmFile, 1); 
     
    282298    osm->maxlon = -190; 
    283299    osm->maxlat = -190; 
    284  
    285     if (opts->debug > 0) { 
    286         fprintf(stdout," OSM parsing   0%%"); 
     300    data->osm = osm; 
     301 
     302    if (debug_level > 0) { 
     303        g_fprintf (stdout, " OSM parsing   0%%"); 
    287304        fflush(stdout); 
    288305    } 
     
    291308    XML_Parser parser = XML_ParserCreate(NULL); 
    292309    XML_SetElementHandler(parser, osmStartElement, osmEndElement); 
    293     XML_SetUserData(parser, osm); 
     310    XML_SetUserData(parser, data); 
    294311 
    295312    // Create Buffer 
     
    300317        len = (int)fread(buf, 1, BUFFSIZE, fd); 
    301318        if (ferror(fd)) { 
    302             fprintf(stderr, "Read error\n"); 
    303             return NULL;; 
     319            g_fprintf (stderr, "Read error\n"); 
     320            return NULL; 
    304321        } 
    305322        read += len; 
    306         if (opts->debug > 0) { 
    307             fprintf(stdout,"\r OSM parsing % 3i%%", (int)((read*100)/size)); 
     323        if (debug_level > 0) { 
     324            g_fprintf (stdout, "\r OSM parsing % 3i%%", (int)((read*100)/size)); 
    308325            fflush(stdout); 
    309326        } 
    310327        done = len < sizeof(buf); 
    311328        if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { 
    312             fprintf(stderr, "Parse error at line %iu:\n%s\n", 
     329            g_fprintf (stderr, "Parse error at line %iu:\n%s\n", 
    313330                (int) XML_GetCurrentLineNumber(parser), 
    314331                XML_ErrorString(XML_GetErrorCode(parser))); 
     
    345362 
    346363    g_hash_table_destroy(osm->nodeidx); 
    347     osm->nodeidx=NULL; 
    348      
    349     if (opts->debug > 0) 
     364    osm->nodeidx = NULL; 
     365     
     366    if (debug_level > 0) 
    350367        fprintf(stdout,"\r OSM parsing done. (%i/%i/%i/%i) [%fs]\n", 
    351                 osm->nodecnt, osm->waycnt, cntTag, cntNd, 
     368                osm->nodecnt, osm->waycnt, data->cntTag, data->cntNd, 
    352369                g_timer_elapsed(tOsmRead,NULL)); 
    353370     
    354371    g_timer_destroy(tOsmRead); 
     372    g_free(data); 
    355373 
    356374    return(osm); 
     375} 
     376 
     377osmFile* osmRead_from_buffer (const char *buffer, guint size, gint8 debug_level) { 
     378    if (debug_level > 1) 
     379        g_fprintf (stdout, "osmRead\n"); 
     380 
     381    g_assert (buffer != NULL && size > 0); 
     382 
     383    // Local Vars 
     384    GTimer *tOsmRead = g_timer_new(); 
     385    int isDone = 0; 
     386    osmFile *osm; 
     387    mapUserData *data; 
     388 
     389    // Init vars 
     390    data = g_new(mapUserData, 1); 
     391    data->cTag = NULL; 
     392    data->cNode = NULL; 
     393    data->cWay = NULL; 
     394    data->pool = memphis_data_pool_new (); 
     395    data->cntTag = 0; 
     396    data->cntNd = 0; 
     397    data->debug_level = debug_level; 
     398 
     399    osm = g_new(osmFile, 1); 
     400    osm->nodes = NULL; 
     401    osm->nodeidx = g_hash_table_new(g_int_hash, g_int_equal); 
     402    osm->nodecnt = 0; 
     403    osm->ways = NULL; 
     404    osm->waycnt = 0; 
     405    osm->minlon = -190; 
     406    osm->minlat = -190; 
     407    osm->maxlon = -190; 
     408    osm->maxlat = -190; 
     409 
     410    data->osm = osm; 
     411 
     412    if (debug_level > 0) { 
     413        g_fprintf (stdout, " OSM parsing   0%%"); 
     414        fflush(stdout); 
     415    } 
     416 
     417    // Create XML Parser 
     418    XML_Parser parser = XML_ParserCreate(NULL); 
     419    XML_SetElementHandler(parser, osmStartElement, osmEndElement); 
     420    XML_SetUserData(parser, data); 
     421 
     422    // Parse the buffer 
     423    if (XML_Parse (parser, buffer, size, isDone) == XML_STATUS_ERROR) { 
     424        g_fprintf (stderr, "Parse error at line %iu:\n%s\n", 
     425            (int) XML_GetCurrentLineNumber(parser), 
     426            XML_ErrorString(XML_GetErrorCode(parser))); 
     427        exit (-1); 
     428    } 
     429 
     430    // Cleaning Memory 
     431    XML_ParserFree(parser); 
     432 
     433    // No bounds set 
     434    if(osm->minlon == -190 || osm->minlat == -190 || 
     435        osm->maxlon == -190 || osm->maxlat == -190) { 
     436 
     437        osm->minlon = 360.0; 
     438        osm->minlat = 180.0; 
     439        osm->maxlon = -360.0; 
     440        osm->maxlat = -180.0; 
     441 
     442        osmNode *node; 
     443        LIST_FOREACH(node, osm->nodes) { 
     444            if(node->lon < osm->minlon) 
     445                osm->minlon = node->lon; 
     446            if(node->lat < osm->minlat) 
     447                osm->minlat = node->lat; 
     448            if(node->lon > osm->maxlon) 
     449                osm->maxlon = node->lon; 
     450            if(node->lat > osm->maxlat) 
     451                osm->maxlat = node->lat; 
     452        } 
     453    } 
     454 
     455    g_hash_table_destroy(osm->nodeidx); 
     456    osm->nodeidx = NULL; 
     457     
     458    if (debug_level > 0) 
     459        fprintf(stdout,"\r OSM parsing done. (%i/%i/%i/%i) [%fs]\n", 
     460                osm->nodecnt, osm->waycnt, data->cntTag, data->cntNd, 
     461                g_timer_elapsed(tOsmRead,NULL)); 
     462     
     463    g_timer_destroy(tOsmRead); 
     464 
     465    return osm; 
    357466} 
    358467 
     
    398507    g_free(lnode); 
    399508    g_free(osm); 
    400 }; 
     509} 
    401510 
    402511/* 
  • trunk/osm05.h

    r76 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
     
    8181 * Prototypes 
    8282 */ 
    83 osmFile* osmRead(char *filename); 
     83osmFile* osmRead (const char *filename, gint8 debug_level); 
     84osmFile* osmRead_from_buffer (const char *buffer, guint size, gint8 debug_level); 
    8485void osmFree(osmFile *osm); 
    8586 
  • trunk/ruleset.c

    r54 r141  
    11/* 
    22 * 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, 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
     4 * 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
     9 * 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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  */ 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
     14 * 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     18 */ 
     19 
    1920#include <glib.h> 
    2021#include <glib/gstdio.h> 
    2122#include <time.h> 
    2223#include <expat.h> 
    23 #include <stdio.h> 
    2424#include <string.h> 
    2525 
    26 #include "main.h" 
    2726#include "list.h" 
    2827#include "ruleset.h" 
    2928#include "mlib.h" 
     29#include "memphis-data-pool.h" 
    3030 
    3131#define BUFFSIZE 1024 
     
    3333#define MAXSTACK 20 
    3434 
    35 // External Vars 
    36 extern memphisOpt   *opts; 
    37 extern GStringChunk *stringChunk; 
    38 extern GTree        *stringTree; 
    39  
    40 // Pointers to work with 
    41 cfgRule     *currentRule; 
    42 cfgRule     *ruleStack[MAXSTACK]; 
    43 char        **stringStack; 
     35typedef struct rulesUserData_ rulesUserData; 
     36struct rulesUserData_ { 
     37  // Pointers to work with 
     38  cfgRule *currentRule; 
     39  cfgRule *ruleStack[MAXSTACK]; 
     40  char **stringStack; 
     41  MemphisDataPool *pool; 
     42  // Collected Data 
     43  cfgRules *ruleset; 
     44  // Debug 
     45  gint8 debug_level; 
     46}; 
    4447 
    4548/** 
     
    5356static void XMLCALL 
    5457cfgStartElement(void *userData, const char *name, const char **atts) { 
    55     cfgRules *ruleset = (cfgRules *)userData; 
    56     if (opts->debug > 1) 
    57         fprintf(stdout,"cfgStartElement\n"); 
     58    rulesUserData *data = (rulesUserData *)userData; 
     59    cfgRules *ruleset = data->ruleset; 
     60    GStringChunk *stringChunk = data->pool->stringChunk; 
     61    GTree *stringTree = data->pool->stringTree; 
     62    gint8 debug_level = data->debug_level; 
     63 
     64    if (debug_level > 1) 
     65        g_fprintf (stdout, "cfgStartElement\n"); 
    5866 
    5967    // Parsing Rules 
     
    120128            ruleset->rule = new; 
    121129        else 
    122             currentRule->next = new; 
    123         currentRule = new; 
     130            data->currentRule->next = new; 
     131        data->currentRule = new; 
    124132 
    125133        // Adding to stack 
    126         ruleStack[ruleset->depth] = currentRule; 
     134        data->ruleStack[ruleset->depth] = data->currentRule; 
    127135 
    128136    } 
     
    173181 
    174182        // Insert Draw 
    175         if(currentRule->parent == 0) 
    176             LL_APPEND(new,ruleStack[ruleset->depth]->draw); 
     183        if(data->currentRule->parent == 0) 
     184            LL_APPEND(new, data->ruleStack[ruleset->depth]->draw); 
    177185        else 
    178             LL_APPEND(new,ruleStack[ruleset->depth]->ndraw); 
     186            LL_APPEND(new, data->ruleStack[ruleset->depth]->ndraw); 
    179187    } 
    180188} 
     
    189197static void XMLCALL 
    190198cfgEndElement(void *userData, const char *name) { 
    191     cfgRules *ruleset = (cfgRules *)userData; 
    192     if (opts->debug > 1) 
    193         fprintf(stdout,"cfgEndElement\n"); 
     199    rulesUserData *data = (rulesUserData *)userData; 
     200    cfgRules *ruleset = data->ruleset; 
     201    gint8 debug_level = data->debug_level; 
     202     
     203    if (debug_level > 1) 
     204        g_fprintf (stdout, "cfgEndElement\n"); 
    194205 
    195206    if (strcmp(name, "rule") == 0) { 
    196207        // Fetching Parrent from stack 
    197208        if(ruleset->depth > 0) { 
    198             if (ruleStack[ruleset->depth-1]->parent == NULL) { 
    199                 ruleStack[ruleset->depth]->parent = ruleStack[ruleset->depth-1]; 
     209            if (data->ruleStack[ruleset->depth-1]->parent == NULL) { 
     210                data->ruleStack[ruleset->depth]->parent = data->ruleStack[ruleset->depth-1]; 
    200211            } else {   // If parent allready closed we are else. 
    201                 ruleStack[ruleset->depth]->nparent = ruleStack[ruleset->depth-1]; 
     212                data->ruleStack[ruleset->depth]->nparent = data->ruleStack[ruleset->depth-1]; 
    202213            } 
    203214        } 
     
    215226 * Called to parse rules in the rulefile. Returns a cfgRules struct. 
    216227 */ 
    217 cfgRules* rulesetRead(char *filename) { 
    218     if (opts->debug > 1) 
    219         fprintf(stdout,"rulesetRead\n"); 
     228cfgRules* rulesetRead(const char *filename, gint8 debug_level) { 
     229    if (debug_level > 1) 
     230        g_fprintf (stdout, "rulesetRead\n"); 
    220231 
    221232    // Local Vars 
     
    227238    int         done; 
    228239    char        *buf; 
     240    rulesUserData *data = g_new(rulesUserData, 1); 
    229241    cfgRules    *ruleset = NULL; 
    230242 
    231243    // NULL rule stack 
    232244    for (len=0;len<MAXDEPTH;len++) { 
    233         ruleStack[len] = NULL; 
     245        data->ruleStack[len] = NULL; 
    234246    } 
    235247     
    236248    // Test file 
    237249    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { 
    238         fprintf(stderr,"Error: \"%s\" is not a file.\n",filename); 
     250        g_critical ("Error: \"%s\" is not a file.\n", filename); 
    239251        return NULL; 
    240252    } 
     
    246258    FILE *fd = fopen(filename,"r"); 
    247259    if(fd == NULL) { 
    248         fprintf(stderr,"Error: Can't open file \"%s\"\n",filename); 
     260        g_critical ("Error: Can't open file \"%s\"\n", filename); 
    249261        return NULL; 
    250262    } 
     
    254266    ruleset->cntRule = 0; 
    255267    ruleset->cntElse = 0; 
    256  
    257     if (opts->debug > 0) { 
    258         fprintf(stdout," Ruleset parsing   0%%"); 
     268    data->ruleset = ruleset; 
     269    data->pool = memphis_data_pool_new (); 
     270    data->debug_level = debug_level; 
     271 
     272    if (debug_level > 0) { 
     273        g_fprintf(stdout, " Ruleset parsing   0%%"); 
    259274        fflush(stdout); 
    260275    } 
     
    264279    XML_SetElementHandler(parser, cfgStartElement, cfgEndElement); 
    265280 
    266     XML_SetUserData(parser, ruleset); 
     281    XML_SetUserData(parser, data); 
    267282 
    268283    // Create Buffer 
     
    273288         len = (int)fread(buf, 1, BUFFSIZE, fd); 
    274289         if (ferror(fd)) { 
    275             fprintf(stderr, "Read error\n"); 
     290            g_fprintf(stderr, "Read error\n"); 
    276291            return NULL;; 
    277292        } 
    278293        read += len; 
    279         if (opts->debug > 0) { 
    280             fprintf(stdout,"\r Ruleset parsing % 3i%%", (int)((read*100)/size)); 
     294        if (debug_level > 0) { 
     295            g_fprintf(stdout, "\r Ruleset parsing % 3i%%", (int)((read*100)/size)); 
    281296            fflush(stdout); 
    282297        } 
    283298        done = len < sizeof(buf); 
    284299        if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { 
    285             fprintf(stderr, "Parse error at line %iu:\n%s\n", 
     300            g_fprintf(stderr, "Parse error at line %iu:\n%s\n", 
    286301                (int) XML_GetCurrentLineNumber(parser), 
    287302                XML_ErrorString(XML_GetErrorCode(parser))); 
     
    294309    g_free(buf); 
    295310    fclose(fd); 
    296  
    297     if (opts->debug > 0) 
    298         fprintf(stdout,"\r Ruleset parsing done. (%i/%i) [%fs]\n", 
     311    g_free(data); 
     312 
     313    if (debug_level > 0) 
     314        g_fprintf (stdout, "\r Ruleset parsing done. (%i/%i) [%fs]\n", 
    299315                ruleset->cntRule,  ruleset->cntElse, 
    300316                g_timer_elapsed(tRulesetRead,NULL)); 
     
    305321} 
    306322 
     323/** 
     324 * rulesetRead_from_buffer: 
     325 * @buffer: Buffer containing a rule-set 
     326 * @size: Size of the buffer 
     327 * 
     328 * Called to parse rules in a buffer. Returns a cfgRules struct. 
     329 */ 
     330cfgRules* rulesetRead_from_buffer (const char *buffer, guint size, gint8 debug_level) { 
     331    if (debug_level > 1) 
     332        g_fprintf (stdout, "rulesetRead\n"); 
     333 
     334    g_assert (buffer != NULL && size > 0); 
     335 
     336    // Local Vars 
     337    GTimer *tRulesetRead = g_timer_new(); 
     338    int         len; 
     339    int         isDone = 0; 
     340    rulesUserData *data = g_new(rulesUserData, 1); 
     341    cfgRules    *ruleset = NULL; 
     342 
     343    // NULL rule stack 
     344    for (len=0;len<MAXDEPTH;len++) { 
     345        data->ruleStack[len] = NULL; 
     346    } 
     347 
     348    ruleset = g_new(cfgRules, 1); 
     349    ruleset->depth = -1; 
     350    ruleset->cntRule = 0; 
     351    ruleset->cntElse = 0; 
     352    data->ruleset = ruleset; 
     353    data->pool = memphis_data_pool_new (); 
     354    data->debug_level = debug_level; 
     355 
     356    if (debug_level > 0) { 
     357        g_fprintf(stdout, " Ruleset parsing   0%%"); 
     358        fflush(stdout); 
     359    } 
     360 
     361    // Create XML Parser 
     362    XML_Parser parser = XML_ParserCreate(NULL); 
     363    XML_SetElementHandler(parser, cfgStartElement, cfgEndElement); 
     364    XML_SetUserData(parser, data); 
     365 
     366    // Parse the buffer 
     367    if (XML_Parse (parser, buffer, size, isDone) == XML_STATUS_ERROR) { 
     368        g_fprintf (stderr, "Parse error at line %iu:\n%s\n", 
     369            (int) XML_GetCurrentLineNumber(parser), 
     370            XML_ErrorString(XML_GetErrorCode(parser))); 
     371        exit (-1); 
     372    } 
     373 
     374    // Cleaning Memory 
     375    XML_ParserFree(parser); 
     376    g_free(data); 
     377 
     378    if (debug_level > 0) 
     379        g_fprintf (stdout, "\r Ruleset parsing done. (%i/%i) [%fs]\n", 
     380                ruleset->cntRule,  ruleset->cntElse, 
     381                g_timer_elapsed(tRulesetRead,NULL)); 
     382 
     383    g_timer_destroy(tRulesetRead); 
     384 
     385    return(ruleset); 
     386} 
     387 
    307388void rulesetFree(cfgRules * ruleset) { 
    308389    cfgRule *rule, *lrule; 
    309390    cfgDraw *draw, *ldraw; 
    310      
     391 
    311392    for(rule = ruleset->rule, lrule = NULL; 
    312393        rule != NULL; 
     
    340421    g_free(lrule); 
    341422    g_free(ruleset); 
    342 }; 
     423} 
     424 
     425void cfgRuleFree (cfgRule *rule) 
     426{ 
     427  g_free (rule->key); 
     428  g_free (rule->value); 
     429 
     430  cfgDraw *tmp; 
     431  cfgDraw *drw = rule->draw; 
     432  while (drw != NULL) 
     433    { 
     434      tmp = drw; 
     435      drw = drw->next; 
     436      g_free (tmp); 
     437    } 
     438 
     439  g_free (rule); 
     440} 
    343441 
    344442/* 
  • trunk/ruleset.h

    r76 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
     
    9090 * Prototypes 
    9191 */ 
    92 cfgRules* rulesetRead(char *filename); 
     92cfgRules* rulesetRead(const char *filename, gint8 debug_level); 
     93cfgRules* rulesetRead_from_buffer (const char *buffer, guint size, 
     94    gint8 debug_level); 
    9395void rulesetFree(cfgRules * ruleset); 
     96 
     97void cfgRuleFree (cfgRule *rule); 
    9498 
    9599#endif /* RULESET_H */ 
  • trunk/test/testOSM.c

    r53 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <time.h> 
     
    4041    stringTree = g_tree_new(m_tree_strcmp); 
    4142 
    42     osmFile *osm = (osmFile *) osmRead("test/map.osm"); 
     43    osmFile *osm = (osmFile *) osmRead("test/map.osm", 1); 
    4344 
    4445    g_tree_destroy(stringTree); 
  • trunk/test/testRuleset.c

    r53 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <time.h> 
     
    4041    stringTree = g_tree_new(m_tree_strcmp); 
    4142 
    42     cfgRules *ruleset = (cfgRules *) rulesetRead("test/ruleset.xml"); 
     43    cfgRules *ruleset = (cfgRules *) rulesetRead("test/ruleset.xml", 1); 
    4344 
    4445    g_tree_destroy(stringTree); 
  • trunk/test/testSize.c

    r78 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <stdio.h> 
    2021#include <stdlib.h> 
  • trunk/test/testTextPath.c

    r78 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
     19 
    1920#include <glib.h> 
    2021#include <cairo.h> 
  • trunk/textpath.c

    r78 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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  */ 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     18 */ 
     19 
    1920#include <glib.h> 
    2021#include <math.h> 
    2122#include <cairo.h> 
    22 #include <stdio.h> 
    23 #include <stdlib.h> 
    2423#include <string.h> 
    2524 
  • trunk/textpath.h

    r78 r141  
    11/* 
    22 * Memphis - Cairo Rederer for OSM in C 
    3  * Copyright (C) 2008  <marius.rieder@durchmesser.ch> 
     3 * Copyright (C) 2008  Marius Rieder <marius.rieder@durchmesser.ch> 
    44 * 
    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. 
     5 * This library is free software; you can redistribute it and/or 
     6 * modify it under the terms of the GNU Lesser General Public 
     7 * License as published by the Free Software Foundation; either 
     8 * version 2.1 of the License, or (at your option) any later version. 
    99 * 
    10  * This program is distributed in the hope that it will be useful, 
     10 * This library is distributed in the hope that it will be useful, 
    1111 * 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. 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     13 * Lesser General Public License for more details. 
    1414 * 
    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. 
     15 * You should have received a copy of the GNU Lesser General Public 
     16 * License along with this library; if not, write to the Free Software 
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 */ 
    1919 
Note: See TracChangeset for help on using the changeset viewer.