Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From fb5091824c101857a2edaa8273e3687aac5880a5 Mon Sep 17 00:00:00 2001
- From: apmon <Not specified>
- Date: Sat, 20 Apr 2013 11:44:46 -0600
- Subject: [PATCH] Initial attempt at moving tag transform to a lua script.
- Instead of hardcoding tag transforms in C, allow a more flexible
- system based on lua scripting.
- This is an early proof of principal
- ---
- Makefile.am | 8 +-
- configure.ac | 3 +
- m4/ax_lua.m4 | 607 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- output-pgsql.c | 26 ++-
- style.lua | 66 +++++++
- tagtransform.c | 124 ++++++++++++
- tagtransform.h | 21 ++
- 7 files changed, 844 insertions(+), 11 deletions(-)
- create mode 100644 m4/ax_lua.m4
- create mode 100644 style.lua
- create mode 100644 tagtransform.c
- create mode 100644 tagtransform.h
- diff --git a/Makefile.am b/Makefile.am
- index 38429af..d80114e 100644
- --- a/Makefile.am
- +++ b/Makefile.am
- @@ -4,7 +4,7 @@ DIST_SUBDIRS = legacy
- bin_PROGRAMS = osm2pgsql nodecachefilereader
- -osm2pgsql_SOURCES = build_geometry.cpp input.c middle.h middle-ram.h output-gazetteer.h output-pgsql.c rb.c sanitizer.h text-tree.h build_geometry.h input.h middle-pgsql.c osm2pgsql.c output.h output-pgsql.h rb.h sprompt.c UTF8sanitizer.c expire-tiles.c keyvals.c middle-pgsql.h osmtypes.h output-null.c parse-o5m.c parse-o5m.h parse-primitive.c parse-primitive.h parse-xml2.c parse-xml2.h pgsql.c reprojection.c sprompt.h expire-tiles.h keyvals.h middle-ram.c output-gazetteer.c output-null.h pgsql.h reprojection.h text-tree.c node-ram-cache.c wildcmp.c node-ram-cache.h node-persistent-cache.c node-persistent-cache.h binarysearcharray.c binarysearcharray.h
- +osm2pgsql_SOURCES = build_geometry.cpp input.c middle.h middle-ram.h output-gazetteer.h output-pgsql.c rb.c sanitizer.h text-tree.h build_geometry.h input.h middle-pgsql.c osm2pgsql.c output.h output-pgsql.h rb.h sprompt.c UTF8sanitizer.c expire-tiles.c keyvals.c middle-pgsql.h osmtypes.h output-null.c parse-o5m.c parse-o5m.h parse-primitive.c parse-primitive.h parse-xml2.c parse-xml2.h pgsql.c reprojection.c sprompt.h expire-tiles.h keyvals.h middle-ram.c output-gazetteer.c output-null.h pgsql.h reprojection.h text-tree.c node-ram-cache.c wildcmp.c node-ram-cache.h node-persistent-cache.c node-persistent-cache.h binarysearcharray.c binarysearcharray.h tagtransform.c
- nodecachefilereader_SOURCES = node-persistent-cache-reader.c node-persistent-cache.c node-ram-cache.c binarysearcharray.c
- @@ -38,10 +38,10 @@ endif
- osm2pgsqldir = $(datadir)/osm2pgsql
- -AM_CFLAGS = @PTHREAD_CFLAGS@ @LFS_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@ @GEOS_CFLAGS@ @PROJ_CFLAGS@ @PROTOBUF_C_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -DVERSION='"@PACKAGE_VERSION@"'
- -AM_CPPFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@ @GEOS_CFLAGS@ @PROJ_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -Igeos-fallback
- +AM_CFLAGS = @PTHREAD_CFLAGS@ @LFS_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@ @GEOS_CFLAGS@ @PROJ_CFLAGS@ @PROTOBUF_C_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -DVERSION='"@PACKAGE_VERSION@"' @LUA_INCLUDE@
- +AM_CPPFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@ @GEOS_CFLAGS@ @PROJ_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -Igeos-fallback @LUA_INCLUDE@
- -AM_LDFLAGS = @PTHREAD_CFLAGS@ @ZLIB_LDFLAGS@ @ZLIB_LIBS@ @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@ @XML2_LDFLAGS@ @BZIP2_LDFLAGS@ @BZIP2_LIBS@ @GEOS_LDFLAGS@ @GEOS_LIBS@ @PROJ_LDFLAGS@ @PROJ_LIBS@ @PROTOBUF_C_LDFLAGS@ @PROTOBUF_C_LIBS@
- +AM_LDFLAGS = @PTHREAD_CFLAGS@ @ZLIB_LDFLAGS@ @ZLIB_LIBS@ @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@ @XML2_LDFLAGS@ @BZIP2_LDFLAGS@ @BZIP2_LIBS@ @GEOS_LDFLAGS@ @GEOS_LIBS@ @PROJ_LDFLAGS@ @PROJ_LIBS@ @PROTOBUF_C_LDFLAGS@ @PROTOBUF_C_LIBS@ -L/usr/lib/x86_64-linux-gnu @LUA_LIB@
- osm2pgsql_DATA = default.style 900913.sql
- diff --git a/configure.ac b/configure.ac
- index 05c7898..ab66bca 100644
- --- a/configure.ac
- +++ b/configure.ac
- @@ -118,6 +118,9 @@ fi
- dnl Check for pthread library
- AX_PTHREAD(,[AC_MSG_ERROR([no])])
- +AX_PROG_LUA
- +AX_LUA_HEADERS
- +AX_LUA_LIBS
- dnl Generate Makefile
- AC_OUTPUT(Makefile legacy/Makefile)
- diff --git a/m4/ax_lua.m4 b/m4/ax_lua.m4
- new file mode 100644
- index 0000000..c6f5974
- --- /dev/null
- +++ b/m4/ax_lua.m4
- @@ -0,0 +1,607 @@
- +# ===========================================================================
- +# http://www.gnu.org/software/autoconf-archive/ax_lua.html
- +# ===========================================================================
- +#
- +# SYNOPSIS
- +#
- +# AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
- +# AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
- +# AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
- +# AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
- +#
- +# DESCRIPTION
- +#
- +# Detect a Lua interpreter, optionally specifying a minimum and maximum
- +# version number. Set up important Lua paths, such as the directories in
- +# which to install scripts and modules (shared libraries).
- +#
- +# Also detect Lua headers and libraries. The Lua version contained in the
- +# header is checked to match the Lua interpreter version exactly. When
- +# searching for Lua libraries, the version number is used as a suffix.
- +# This is done with the goal of supporting multiple Lua installs (5.1 and
- +# 5.2 side-by-side).
- +#
- +# A note on compatibility with previous versions: This file has been
- +# mostly rewritten for serial 18. Most developers should be able to use
- +# these macros without needing to modify configure.ac. Care has been taken
- +# to preserve each macro's behavior, but there are some differences:
- +#
- +# 1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
- +# AX_PROG_LUA with no arguments.
- +#
- +# 2) AX_LUA_HEADERS now checks that the version number defined in lua.h
- +# matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
- +# unnecessary, so it is deprecated and does not expand to anything.
- +#
- +# 3) The configure flag --with-lua-suffix no longer exists; the user
- +# should instead specify the LUA precious variable on the command line.
- +# See the AX_PROG_LUA description for details.
- +#
- +# Please read the macro descriptions below for more information.
- +#
- +# This file was inspired by Andrew Dalke's and James Henstridge's
- +# python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
- +# (serial 17). Basically, this file is a mash-up of those two files. I
- +# like to think it combines the best of the two!
- +#
- +# AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
- +# paths. Adds precious variable LUA, which may contain the path of the Lua
- +# interpreter. If LUA is blank, the user's path is searched for an
- +# suitable interpreter.
- +#
- +# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
- +# version number greater or equal to MINIMUM-VERSION will be accepted. If
- +# TOO-BIG- VERSION is also supplied, then only Lua interpreters with a
- +# version number greater or equal to MINIMUM-VERSION and less than
- +# TOO-BIG-VERSION will be accepted.
- +#
- +# Version comparisons require the AX_COMPARE_VERSION macro, which is
- +# provided by ax_compare_version.m4 from the Autoconf Archive.
- +#
- +# The Lua version number, LUA_VERSION, is found from the interpreter, and
- +# substituted. LUA_PLATFORM is also found, but not currently supported (no
- +# standard representation).
- +#
- +# Finally, the macro finds four paths:
- +#
- +# luadir Directory to install Lua scripts.
- +# pkgluadir $luadir/$PACKAGE
- +# luaexecdir Directory to install Lua modules.
- +# pkgluaexecdir $luaexecdir/$PACKAGE
- +#
- +# These paths a found based on $prefix, $exec_prefix, Lua's package.path,
- +# and package.cpath. The first path of package.path beginning with $prefix
- +# is selected as luadir. The first path of package.cpath beginning with
- +# $exec_prefix is used as luaexecdir. This should work on all reasonable
- +# Lua installations. If a path cannot be determined, a default path is
- +# used. Of course, the user can override these later when invoking make.
- +#
- +# luadir Default: $prefix/share/lua/$LUA_VERSION
- +# luaexecdir Default: $exec_prefix/lib/lua/$LUA_VERSION
- +#
- +# These directories can be used by Automake as install destinations. The
- +# variable name minus 'dir' needs to be used as a prefix to the
- +# appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
- +#
- +# If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
- +# performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
- +# FOUND is blank, then it will default to printing an error. To prevent
- +# the default behavior, give ':' as an action.
- +#
- +# AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
- +# expanded before this macro. Adds precious variable LUA_INCLUDE, which
- +# may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
- +# LUA_INCLUDE is blank, then this macro will attempt to find suitable
- +# flags.
- +#
- +# LUA_INCLUDE can be used by Automake to compile Lua modules or
- +# executables with embedded interpreters. The *_CPPFLAGS variables should
- +# be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
- +#
- +# This macro searches for the header lua.h (and others). The search is
- +# performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
- +# If the search is unsuccessful, then some common directories are tried.
- +# If the headers are then found, then LUA_INCLUDE is set accordingly.
- +#
- +# The paths automatically searched are:
- +#
- +# * /usr/include/luaX.Y
- +# * /usr/include/lua/X.Y
- +# * /usr/include/luaXY
- +# * /usr/local/include/luaX.Y
- +# * /usr/local/include/lua/X.Y
- +# * /usr/local/include/luaXY
- +#
- +# (Where X.Y is the Lua version number, e.g. 5.1.)
- +#
- +# The Lua version number found in the headers is always checked to match
- +# the Lua interpreter's version number. Lua headers with mismatched
- +# version numbers are not accepted.
- +#
- +# If headers are found, then ACTION-IF-FOUND is performed, otherwise
- +# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
- +# it will default to printing an error. To prevent the default behavior,
- +# set the action to ':'.
- +#
- +# AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
- +# expanded before this macro. Adds precious variable LUA_LIB, which may
- +# contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
- +# then this macro will attempt to find suitable flags.
- +#
- +# LUA_LIB can be used by Automake to link Lua modules or executables with
- +# embedded interpreters. The *_LIBADD and *_LDADD variables should be used
- +# for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
- +#
- +# This macro searches for the Lua library. More technically, it searches
- +# for a library containing the function lua_load. The search is performed
- +# with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
- +#
- +# If the search determines that some linker flags are missing, then those
- +# flags will be added to LUA_LIB.
- +#
- +# If libraries are found, then ACTION-IF-FOUND is performed, otherwise
- +# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
- +# it will default to printing an error. To prevent the default behavior,
- +# set the action to ':'.
- +#
- +# AX_LUA_READLINE: Search for readline headers and libraries. Requires the
- +# AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
- +# Autoconf Archive.
- +#
- +# If a readline compatible library is found, then ACTION-IF-FOUND is
- +# performed, otherwise ACTION-IF-NOT-FOUND is performed.
- +#
- +# LICENSE
- +#
- +# Copyright (c) 2013 Tim Perkins <[email protected]>
- +# Copyright (c) 2013 Reuben Thomas <[email protected]>
- +#
- +# This program is free software: you can redistribute it and/or modify it
- +# under the terms of the GNU General Public License as published by the
- +# Free Software Foundation, either version 3 of the License, or (at your
- +# option) any later version.
- +#
- +# This program is distributed in the hope that it will be useful, but
- +# WITHOUT ANY WARRANTY; without even the implied warranty of
- +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- +# Public License for more details.
- +#
- +# You should have received a copy of the GNU General Public License along
- +# with this program. If not, see <http://www.gnu.org/licenses/>.
- +#
- +# As a special exception, the respective Autoconf Macro's copyright owner
- +# gives unlimited permission to copy, distribute and modify the configure
- +# scripts that are the output of Autoconf when processing the Macro. You
- +# need not follow the terms of the GNU General Public License when using
- +# or distributing such scripts, even though portions of the text of the
- +# Macro appear in them. The GNU General Public License (GPL) does govern
- +# all other use of the material that constitutes the Autoconf Macro.
- +#
- +# This special exception to the GPL applies to versions of the Autoconf
- +# Macro released by the Autoconf Archive. When you make and distribute a
- +# modified version of the Autoconf Macro, you may extend this special
- +# exception to the GPL to apply to your modified version as well.
- +
- +#serial 20
- +
- +dnl =========================================================================
- +dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
- +dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
- +dnl =========================================================================
- +AC_DEFUN([AX_PROG_LUA],
- +[
- + dnl Make LUA a precious variable.
- + AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
- +
- + dnl Find a Lua interpreter.
- + m4_define_default([_AX_LUA_INTERPRETER_LIST],
- + [lua lua5.2 lua5.1 lua50])
- +
- + m4_if([$1], [],
- + [ dnl No version check is needed. Find any Lua interpreter.
- + AS_IF([test "x$LUA" = 'x'],
- + [AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
- + ax_display_LUA='lua'
- +
- + dnl At least check if this is a Lua interpreter.
- + AC_MSG_CHECKING([if $LUA is a Lua interpreter])
- + _AX_LUA_CHK_IS_INTRP([$LUA],
- + [AC_MSG_RESULT([yes])],
- + [ AC_MSG_RESULT([no])
- + AC_MSG_ERROR([not a Lua interpreter])
- + ])
- + ],
- + [ dnl A version check is needed.
- + AS_IF([test "x$LUA" != 'x'],
- + [ dnl Check if this is a Lua interpreter.
- + AC_MSG_CHECKING([if $LUA is a Lua interpreter])
- + _AX_LUA_CHK_IS_INTRP([$LUA],
- + [AC_MSG_RESULT([yes])],
- + [ AC_MSG_RESULT([no])
- + AC_MSG_ERROR([not a Lua interpreter])
- + ])
- + dnl Check the version.
- + m4_if([$2], [],
- + [_ax_check_text="whether $LUA version >= $1"],
- + [_ax_check_text="whether $LUA version >= $1, < $2"])
- + AC_MSG_CHECKING([$_ax_check_text])
- + _AX_LUA_CHK_VER([$LUA], [$1], [$2],
- + [AC_MSG_RESULT([yes])],
- + [ AC_MSG_RESULT([no])
- + AC_MSG_ERROR([version is out of range for specified LUA])])
- + ax_display_LUA=$LUA
- + ],
- + [ dnl Try each interpreter until we find one that satisfies VERSION.
- + m4_if([$2], [],
- + [_ax_check_text="for a Lua interpreter with version >= $1"],
- + [_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
- + AC_CACHE_CHECK([$_ax_check_text],
- + [ax_cv_pathless_LUA],
- + [ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
- + test "x$ax_cv_pathless_LUA" = 'xnone' && break
- + _AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
- + _AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
- + done
- + ])
- + dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
- + AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
- + [LUA=':'],
- + [AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
- + ax_display_LUA=$ax_cv_pathless_LUA
- + ])
- + ])
- +
- + AS_IF([test "x$LUA" = 'x:'],
- + [ dnl Run any user-specified action, or abort.
- + m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
- + ],
- + [ dnl Query Lua for its version number.
- + AC_CACHE_CHECK([for $ax_display_LUA version], [ax_cv_lua_version],
- + [ ax_cv_lua_version=`$LUA -e "print(_VERSION)" | \
- + sed "s|^Lua \(.*\)|\1|" | \
- + grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
- + ])
- + AS_IF([test "x$ax_cv_lua_version" = 'x'],
- + [AC_MSG_ERROR([invalid Lua version number])])
- + AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
- + AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | sed 's|\.||'`])
- +
- + dnl The following check is not supported:
- + dnl At times (like when building shared libraries) you may want to know
- + dnl which OS platform Lua thinks this is.
- + AC_CACHE_CHECK([for $ax_display_LUA platform], [ax_cv_lua_platform],
- + [ax_cv_lua_platform=`$LUA -e "print('unknown')"`])
- + AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
- +
- + dnl Use the values of $prefix and $exec_prefix for the corresponding
- + dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
- + dnl variables so they can be overridden if need be. However, the general
- + dnl consensus is that you shouldn't need this ability.
- + AC_SUBST([LUA_PREFIX], ['${prefix}'])
- + AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
- +
- + dnl Lua provides no way to query the script directory, and instead
- + dnl provides LUA_PATH. However, we should be able to make a safe educated
- + dnl guess. If the built-in search path contains a directory which is
- + dnl prefixed by $prefix, then we can store scripts there. The first
- + dnl matching path will be used.
- + AC_CACHE_CHECK([for $ax_display_LUA script directory],
- + [ax_cv_lua_luadir],
- + [ AS_IF([test "x$prefix" = 'xNONE'],
- + [ax_lua_prefix=$ac_default_prefix],
- + [ax_lua_prefix=$prefix])
- +
- + dnl Initialize to the default path.
- + ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
- +
- + dnl Try to find a path with the prefix.
- + _AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [package.path])
- + AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
- + [ dnl Fix the prefix.
- + _ax_strip_prefix=`echo "$ax_lua_prefix" | sed 's|.|.|g'`
- + ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
- + sed "s,^$_ax_strip_prefix,$LUA_PREFIX,"`
- + ])
- + ])
- + AC_SUBST([luadir], [$ax_cv_lua_luadir])
- + AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
- +
- + dnl Lua provides no way to query the module directory, and instead
- + dnl provides LUA_PATH. However, we should be able to make a safe educated
- + dnl guess. If the built-in search path contains a directory which is
- + dnl prefixed by $exec_prefix, then we can store modules there. The first
- + dnl matching path will be used.
- + AC_CACHE_CHECK([for $ax_display_LUA module directory],
- + [ax_cv_lua_luaexecdir],
- + [ AS_IF([test "x$exec_prefix" = 'xNONE'],
- + [ax_lua_exec_prefix=$ax_lua_prefix],
- + [ax_lua_exec_prefix=$exec_prefix])
- +
- + dnl Initialize to the default path.
- + ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
- +
- + dnl Try to find a path with the prefix.
- + _AX_LUA_FND_PRFX_PTH([$LUA],
- + [$ax_lua_exec_prefix], [package.cpathd])
- + AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
- + [ dnl Fix the prefix.
- + _ax_strip_prefix=`echo "$ax_lua_exec_prefix" | sed 's|.|.|g'`
- + ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
- + sed "s,^$_ax_strip_prefix,$LUA_EXEC_PREFIX,"`
- + ])
- + ])
- + AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
- + AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
- +
- + dnl Run any user specified action.
- + $3
- + ])
- +])
- +
- +dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
- +AC_DEFUN([AX_WITH_LUA],
- +[
- + AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA]])
- + AX_PROG_LUA
- +])
- +
- +
- +dnl =========================================================================
- +dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
- +dnl =========================================================================
- +AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
- +[
- + dnl Just print _VERSION because all Lua interpreters have this global.
- + AS_IF([$1 -e "print('Hello ' .. _VERSION .. '!')" &>/dev/null],
- + [$2], [$3])
- +])
- +
- +
- +dnl =========================================================================
- +dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
- +dnl [ACTION-IF-TRUE], [ACTION-IF-FALSE])
- +dnl =========================================================================
- +AC_DEFUN([_AX_LUA_CHK_VER],
- +[
- + _ax_test_ver=`$1 -e "print(_VERSION)" 2>/dev/null | \
- + sed "s|^Lua \(.*\)|\1|" | grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
- + AS_IF([test "x$_ax_test_ver" = 'x'],
- + [_ax_test_ver='0'])
- + AX_COMPARE_VERSION([$_ax_test_ver], [ge], [$2])
- + m4_if([$3], [], [],
- + [ AS_IF([$ax_compare_version],
- + [AX_COMPARE_VERSION([$_ax_test_ver], [lt], [$3])])
- + ])
- + AS_IF([$ax_compare_version], [$4], [$5])
- +])
- +
- +
- +dnl =========================================================================
- +dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, LUA-PATH-VARIABLE)
- +dnl =========================================================================
- +AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
- +[
- + dnl Invokes the Lua interpreter PROG to print the path variable
- + dnl LUA-PATH-VARIABLE, usually package.path or package.cpath. Paths are
- + dnl then matched against PREFIX. The first path to begin with PREFIX is set
- + dnl to ax_lua_prefixed_path.
- +
- + ax_lua_prefixed_path=''
- + _ax_package_paths=`$1 -e 'print($3)' 2>/dev/null | sed 's|;|\n|g'`
- + dnl Try the paths in order, looking for the prefix.
- + for _ax_package_path in $_ax_package_paths; do
- + dnl Copy the path, up to the use of a Lua wildcard.
- + _ax_path_parts=`echo "$_ax_package_path" | sed 's|/|\n|g'`
- + _ax_reassembled=''
- + for _ax_path_part in $_ax_path_parts; do
- + echo "$_ax_path_part" | grep '\?' >/dev/null && break
- + _ax_reassembled="$_ax_reassembled/$_ax_path_part"
- + done
- + dnl Check the path against the prefix.
- + _ax_package_path=$_ax_reassembled
- + if echo "$_ax_package_path" | grep "^$2" >/dev/null; then
- + dnl Found it.
- + ax_lua_prefixed_path=$_ax_package_path
- + break
- + fi
- + done
- +])
- +
- +
- +dnl =========================================================================
- +dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
- +dnl =========================================================================
- +AC_DEFUN([AX_LUA_HEADERS],
- +[
- + dnl Check for LUA_VERSION.
- + AC_MSG_CHECKING([if LUA_VERSION is defined])
- + AS_IF([test "x$LUA_VERSION" != 'x'],
- + [AC_MSG_RESULT([yes])],
- + [ AC_MSG_RESULT([no])
- + AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
- + ])
- +
- + dnl Make LUA_INCLUDE a precious variable.
- + AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
- +
- + dnl Some default directories to search.
- + LUA_SHORT_VERSION=`echo "$LUA_VERSION" | sed 's|\.||'`
- + m4_define_default([_AX_LUA_INCLUDE_LIST],
- + [ /usr/include/lua$LUA_VERSION \
- + /usr/include/lua/$LUA_VERSION \
- + /usr/include/lua$LUA_SHORT_VERSION \
- + /usr/local/include/lua$LUA_VERSION \
- + /usr/local/include/lua/$LUA_VERSION \
- + /usr/local/include/lua$LUA_SHORT_VERSION \
- + ])
- +
- + dnl Try to find the headers.
- + _ax_lua_saved_cppflags=$CPPFLAGS
- + CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
- + AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
- + CPPFLAGS=$_ax_lua_saved_cppflags
- +
- + dnl Try some other directories if LUA_INCLUDE was not set.
- + AS_IF([test "x$LUA_INCLUDE" = 'x' &&
- + test "x$ac_cv_header_lua_h" != 'xyes'],
- + [ dnl Try some common include paths.
- + for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
- + test ! -d "$_ax_include_path" && continue
- +
- + AC_MSG_CHECKING([for Lua headers in])
- + AC_MSG_RESULT([$_ax_include_path])
- +
- + AS_UNSET([ac_cv_header_lua_h])
- + AS_UNSET([ac_cv_header_lualib_h])
- + AS_UNSET([ac_cv_header_lauxlib_h])
- + AS_UNSET([ac_cv_header_luaconf_h])
- +
- + _ax_lua_saved_cppflags=$CPPFLAGS
- + CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
- + AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
- + CPPFLAGS=$_ax_lua_saved_cppflags
- +
- + AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
- + [ LUA_INCLUDE="-I$_ax_include_path"
- + break
- + ])
- + done
- + ])
- +
- + AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
- + [ dnl Make a program to print LUA_VERSION defined in the header.
- + dnl TODO This probably shouldn't be a runtime test.
- +
- + AC_CACHE_CHECK([for Lua header version],
- + [ax_cv_lua_header_version],
- + [ _ax_lua_saved_cppflags=$CPPFLAGS
- + CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
- + AC_RUN_IFELSE(
- + [ AC_LANG_SOURCE([[
- +#include <lua.h>
- +#include <stdlib.h>
- +#include <stdio.h>
- +int main(int argc, char ** argv)
- +{
- + if(argc > 1) printf("%s", LUA_VERSION);
- + exit(EXIT_SUCCESS);
- +}
- +]])
- + ],
- + [ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
- + sed "s|^Lua \(.*\)|\1|" | \
- + grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
- + ],
- + [ax_cv_lua_header_version='unknown'])
- + CPPFLAGS=$_ax_lua_saved_cppflags
- + ])
- +
- + dnl Compare this to the previously found LUA_VERSION.
- + AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
- + AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
- + [ AC_MSG_RESULT([yes])
- + ax_header_version_match='yes'
- + ],
- + [ AC_MSG_RESULT([no])
- + ax_header_version_match='no'
- + ])
- + ])
- +
- + dnl Was LUA_INCLUDE specified?
- + AS_IF([test "x$ax_header_version_match" != 'xyes' &&
- + test "x$LUA_INCLUDE" != 'x'],
- + [AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
- +
- + dnl Test the final result and run user code.
- + AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
- + [m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
- +])
- +
- +dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
- +AC_DEFUN([AX_LUA_HEADERS_VERSION],
- +[
- + AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS]])
- +])
- +
- +
- +dnl =========================================================================
- +dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
- +dnl =========================================================================
- +AC_DEFUN([AX_LUA_LIBS],
- +[
- + dnl TODO Should this macro also check various -L flags?
- +
- + dnl Check for LUA_VERSION.
- + AC_MSG_CHECKING([if LUA_VERSION is defined])
- + AS_IF([test "x$LUA_VERSION" != 'x'],
- + [AC_MSG_RESULT([yes])],
- + [ AC_MSG_RESULT([no])
- + AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
- + ])
- +
- + dnl Make LUA_LIB a precious variable.
- + AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
- +
- + AS_IF([test "x$LUA_LIB" != 'x'],
- + [ dnl Check that LUA_LIBS works.
- + _ax_lua_saved_libs=$LIBS
- + LIBS="$LIBS $LUA_LIB"
- + AC_SEARCH_LIBS([lua_load], [],
- + [_ax_found_lua_libs='yes'],
- + [_ax_found_lua_libs='no'])
- + LIBS=$_ax_lua_saved_libs
- +
- + dnl Check the result.
- + AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
- + [AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
- + ],
- + [ dnl First search for extra libs.
- + _ax_lua_extra_libs=''
- +
- + _ax_lua_saved_libs=$LIBS
- + LIBS="$LIBS $LUA_LIB"
- + AC_SEARCH_LIBS([exp], [m])
- + AC_SEARCH_LIBS([dlopen], [dl])
- + LIBS=$_ax_lua_saved_libs
- +
- + AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
- + test "x$ac_cv_search_exp" != 'xnone required'],
- + [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
- +
- + AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
- + test "x$ac_cv_search_dlopen" != 'xnone required'],
- + [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
- +
- + dnl Try to find the Lua libs.
- + _ax_lua_saved_libs=$LIBS
- + LIBS="$LIBS $LUA_LIB"
- + AC_SEARCH_LIBS([lua_load], [lua$LUA_VERSION lua$LUA_SHORT_VERSION lua],
- + [_ax_found_lua_libs='yes'],
- + [_ax_found_lua_libs='no'],
- + [$_ax_lua_extra_libs])
- + LIBS=$_ax_lua_saved_libs
- +
- + AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
- + test "x$ac_cv_search_lua_load" != 'xnone required'],
- + [LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
- + ])
- +
- + dnl Test the result and run user code.
- + AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
- + [m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
- +])
- +
- +
- +dnl =========================================================================
- +dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
- +dnl =========================================================================
- +AC_DEFUN([AX_LUA_READLINE],
- +[
- + AX_LIB_READLINE
- + AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
- + test "x$ac_cv_header_readline_history_h" != 'x'],
- + [ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
- + $1
- + ],
- + [$2])
- +])
- diff --git a/output-pgsql.c b/output-pgsql.c
- index 69f9d90..0203cb3 100644
- --- a/output-pgsql.c
- +++ b/output-pgsql.c
- @@ -32,6 +32,7 @@
- #include "expire-tiles.h"
- #include "wildcmp.h"
- #include "node-ram-cache.h"
- +#include "tagtransform.h"
- #define SRID (project_getprojinfo()->srs)
- @@ -652,11 +653,14 @@ Workaround - output SRID=4326;<WKB>
- static int pgsql_out_node(osmid_t id, struct keyval *tags, double node_lat, double node_lon)
- {
- + int filter = tagtransform_filter_node_tags(tags);
- static char *sql;
- static size_t sqllen=0;
- int i;
- struct keyval *tag;
- + if (filter) return 1;
- +
- if (sqllen==0) {
- sqllen=2048;
- sql=malloc(sqllen);
- @@ -912,7 +916,7 @@ static int pgsql_out_way(osmid_t id, struct keyval *tags, struct osmNode *nodes,
- Options->mid->way_changed(id);
- }
- - if (pgsql_filter_tags(OSMTYPE_WAY, tags, &polygon) || add_z_order(tags, &roads))
- + if (tagtransform_filter_way_tags(tags, &polygon) || add_z_order(tags, &roads))
- return 0;
- /* Split long ways after around 1 degree or 100km */
- @@ -1431,6 +1435,7 @@ static int pgsql_out_start(const struct output_options *options)
- }
- free(sql);
- + tagtransform_init();
- expire_tiles_init(options);
- options->mid->start(options);
- @@ -1640,12 +1645,9 @@ static void pgsql_out_stop()
- static int pgsql_add_node(osmid_t id, double lat, double lon, struct keyval *tags)
- {
- - int polygon;
- - int filter = pgsql_filter_tags(OSMTYPE_NODE, tags, &polygon);
- -
- Options->mid->nodes_set(id, lat, lon, tags);
- - if( !filter )
- - pgsql_out_node(id, tags, lat, lon);
- + pgsql_out_node(id, tags, lat, lon);
- +
- return 0;
- }
- @@ -1654,7 +1656,7 @@ static int pgsql_add_way(osmid_t id, osmid_t *nds, int nd_count, struct keyval *
- int polygon = 0;
- /* Check whether the way is: (1) Exportable, (2) Maybe a polygon */
- - int filter = pgsql_filter_tags(OSMTYPE_WAY, tags, &polygon);
- + int filter = tagtransform_filter_way_tags(tags, &polygon);
- /* If this isn't a polygon then it can not be part of a multipolygon
- Hence only polygons are "pending" */
- @@ -1681,11 +1683,21 @@ static int pgsql_process_relation(osmid_t id, struct member *members, int member
- int *xcount = malloc( (member_count+1) * sizeof(int) );
- struct keyval *xtags = malloc( (member_count+1) * sizeof(struct keyval) );
- struct osmNode **xnodes = malloc( (member_count+1) * sizeof(struct osmNode*) );
- + int filter;
- /* If the flag says this object may exist already, delete it first */
- if(exists)
- pgsql_delete_relation_from_output(id);
- + if (tagtransform_filter_rel_tags(tags)) {
- + free(xid2);
- + free(xrole);
- + free(xcount);
- + free(xtags);
- + free(xnodes);
- + return 1;
- + }
- +
- count = 0;
- for( i=0; i<member_count; i++ )
- {
- diff --git a/style.lua b/style.lua
- new file mode 100644
- index 0000000..128f036
- --- /dev/null
- +++ b/style.lua
- @@ -0,0 +1,66 @@
- +function filter_tags_node (keyvalues, nokeys)
- + filter = 0
- +
- + if nokeys == 0 then
- + filter = 1
- + end
- +
- + return filter, keyvalues
- +end
- +
- +function filter_basic_tags_rel (keyvalues, nokeys)
- + filter = 0
- +
- + if nokeys == 0 then
- + filter = 1
- + return filter, keyvalues
- + end
- +
- + if ((keyvalues["type"] ~= "route") and (keyvalues["type"] ~= "multipolygon") and (keyvalues["type"] ~= "boundary")) then
- + filter = 1
- + return filter, keyvalues
- + end
- +
- + return filter, keyvalues
- +end
- +
- +function filter_tags_way (keyvalues, nokeys)
- + filter = 0
- + poly = 0
- + if nokeys == 0 then
- + filter = 1
- + return filter, keyvalues, poly
- + end
- +
- + if ((keyvalues["building"] ~= nil) or
- + (keyvalues["landuse"] ~= nil) or
- + (keyvalues["amenity"] ~= nil) or
- + (keyvalues["harbour"] ~= nil) or
- + (keyvalues["historic"] ~= nil) or
- + (keyvalues["leisure"] ~= nil) or
- + (keyvalues["man_made"] ~= nil) or
- + (keyvalues["military"] ~= nil) or
- + (keyvalues["natural"] ~= nil) or
- + (keyvalues["office"] ~= nil) or
- + (keyvalues["place"] ~= nil) or
- + (keyvalues["power"] ~= nil) or
- + (keyvalues["public_transport"] ~= nil) or
- + (keyvalues["shop"] ~= nil) or
- + (keyvalues["sport"] ~= nil) or
- + (keyvalues["tourism"] ~= nil) or
- + (keyvalues["waterway"] ~= nil) or
- + (keyvalues["wetland"] ~= nil) or
- + (keyvalues["water"] ~= nil) or
- + (keyvalues["aeroway"] ~= nil))
- + then
- + poly = 1;
- + end
- +
- + if ((keyvalues["area"] == "yes") or (keyvalues["area"] == "1") or (keyvalues["area"] == "true")) then
- + poly = 1;
- + elseif ((keyvalues["area"] == "no") or (keyvalues["area"] == "0") or (keyvalues["area"] == "false")) then
- + poly = 0;
- + end
- +
- + return filter, keyvalues, poly
- +end
- \ No newline at end of file
- diff --git a/tagtransform.c b/tagtransform.c
- new file mode 100644
- index 0000000..cc6616d
- --- /dev/null
- +++ b/tagtransform.c
- @@ -0,0 +1,124 @@
- +
- +#include "osmtypes.h"
- +#include "keyvals.h"
- +#include "tagtransform.h"
- +
- +static lua_State *L;
- +
- +static unsigned int tagtransform_filter_basic_tags(enum OsmType type, struct keyval *tags, int * polygon) {
- + int idx = 0;
- + int filter;
- + int count = 0;
- + struct keyval *item;
- + char * key, * value;
- +
- + switch (type) {
- + case OSMTYPE_NODE: {
- + lua_getglobal(L, "filter_tags_node");
- + break;
- + }
- + case OSMTYPE_WAY: {
- + lua_getglobal(L, "filter_tags_way");
- + break;
- + }
- + case OSMTYPE_RELATION: {
- + lua_getglobal(L, "filter_basic_tags_rel");
- + break;
- + }
- + }
- +
- + lua_newtable(L); /* key value table */
- +
- + idx = 1;
- + while( (item = popItem(tags)) != NULL ) {
- + lua_pushstring(L, item->key);
- + lua_pushstring(L, item->value);
- + lua_rawset(L, -3);
- + freeItem(item);
- + count++;
- + }
- +
- + //printf("C count %i\n", count);
- + lua_pushinteger(L, count);
- +
- + switch (type) {
- + case OSMTYPE_NODE: {
- + lua_call(L,2,2);
- + break;
- + }
- + case OSMTYPE_WAY: {
- + lua_call(L,2,3);
- + *polygon = lua_tointeger(L, -1);
- + lua_pop(L,1);
- + break;
- + }
- + case OSMTYPE_RELATION: {
- + lua_call(L,2,2);
- + break;
- + }
- + }
- +
- + lua_pushnil(L);
- +
- + while (lua_next(L,-2) != 0) {
- + key = lua_tostring(L,-2);
- + value = lua_tostring(L,-1);
- + addItem(tags, key, value, 0);
- + lua_pop(L,1);
- + }
- +
- + filter = lua_tointeger(L, 2);
- +
- + lua_pop(L,2);
- +
- + return filter;
- +}
- +
- +unsigned int tagtransform_filter_node_tags(struct keyval *tags) {
- + int poly;
- + return tagtransform_filter_basic_tags(OSMTYPE_NODE, tags, &poly);
- +}
- +
- +/*
- + * This function gets called twice during initial import per way. Once from add_way and once from out_way
- + */
- +unsigned int tagtransform_filter_way_tags(struct keyval *tags, int * polygon) {
- + return tagtransform_filter_basic_tags(OSMTYPE_WAY, tags, polygon);
- +}
- +
- +unsigned int tagtransform_filter_rel_tags(struct keyval *tags) {
- + int poly;
- + return tagtransform_filter_basic_tags(OSMTYPE_RELATION, tags, &poly);
- +}
- +
- +int tagtransform_init() {
- + L = luaL_newstate();
- + luaL_openlibs(L);
- + luaL_dofile(L, "style.lua");
- +
- + lua_getglobal(L, "filter_tags_node");
- + if (!lua_isfunction (L, -1)) {
- + fprintf(stderr,"Tag transform style does not contain a function filter_tags_node\n");
- + exit(1);
- + return 0;
- + }
- + lua_pop(L,1);
- +
- + lua_getglobal(L, "filter_tags_way");
- + if (!lua_isfunction (L, -1)) {
- + fprintf(stderr,"Tag transform style does not contain a function filter_tags_way\n");
- + exit(1);
- + return 0;
- + }
- + lua_pop(L,1);
- +
- + lua_getglobal(L, "filter_basic_tags_rel");
- + if (!lua_isfunction (L, -1)) {
- + fprintf(stderr,"Tag transform style does not contain a function filter_basic_tags_rel\n");
- + exit(1);
- + return 0;
- + }
- +
- + return 0;
- +}
- +
- diff --git a/tagtransform.h b/tagtransform.h
- new file mode 100644
- index 0000000..c604ff7
- --- /dev/null
- +++ b/tagtransform.h
- @@ -0,0 +1,21 @@
- +
- +#ifndef TAGTRANSFORM_H
- +#define TAGTRANSFORM_H
- +
- +#ifdef __cplusplus
- +extern "C" {
- +#endif
- +
- +#include <lua.h>
- +#include <lualib.h>
- +#include <lauxlib.h>
- +
- +unsigned int tagtransform_filter_node_tags(struct keyval *tags);
- +unsigned int tagtransform_filter_way_tags(struct keyval *tags, int * polygon);
- +unsigned int tagtransform_filter_rel_tags(struct keyval *tags);
- +
- +#ifdef __cplusplus
- +}
- +#endif
- +
- +#endif //TAGTRANSFORM_H
- --
- 1.8.1.2
Advertisement
Add Comment
Please, Sign In to add comment