Guest User

initial lua patch

a guest
Apr 20th, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 38.16 KB | None | 0 0
  1. From fb5091824c101857a2edaa8273e3687aac5880a5 Mon Sep 17 00:00:00 2001
  2. From: apmon <Not specified>
  3. Date: Sat, 20 Apr 2013 11:44:46 -0600
  4. Subject: [PATCH] Initial attempt at moving tag transform to a lua script.
  5.  
  6. Instead of hardcoding tag transforms in C, allow a more flexible
  7. system based on lua scripting.
  8.  
  9. This is an early proof of principal
  10. ---
  11.  Makefile.am    |   8 +-
  12.  configure.ac   |   3 +
  13.  m4/ax_lua.m4   | 607 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14.  output-pgsql.c |  26 ++-
  15.  style.lua      |  66 +++++++
  16.  tagtransform.c | 124 ++++++++++++
  17.  tagtransform.h |  21 ++
  18.  7 files changed, 844 insertions(+), 11 deletions(-)
  19.  create mode 100644 m4/ax_lua.m4
  20.  create mode 100644 style.lua
  21.  create mode 100644 tagtransform.c
  22.  create mode 100644 tagtransform.h
  23.  
  24. diff --git a/Makefile.am b/Makefile.am
  25. index 38429af..d80114e 100644
  26. --- a/Makefile.am
  27. +++ b/Makefile.am
  28. @@ -4,7 +4,7 @@ DIST_SUBDIRS = legacy
  29.  
  30.  bin_PROGRAMS = osm2pgsql nodecachefilereader
  31.  
  32. -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
  33. +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
  34.  
  35.  nodecachefilereader_SOURCES = node-persistent-cache-reader.c node-persistent-cache.c node-ram-cache.c binarysearcharray.c
  36.  
  37. @@ -38,10 +38,10 @@ endif
  38.  
  39.  osm2pgsqldir = $(datadir)/osm2pgsql
  40.  
  41. -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@"'
  42. -AM_CPPFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@  @GEOS_CFLAGS@ @PROJ_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -Igeos-fallback
  43. +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@
  44. +AM_CPPFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML2_CFLAGS@ @BZIP2_CFLAGS@  @GEOS_CFLAGS@ @PROJ_CFLAGS@ -DOSM2PGSQL_DATADIR='"$(osm2pgsqldir)"' -Igeos-fallback @LUA_INCLUDE@
  45.  
  46. -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@
  47. +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@
  48.  
  49.  osm2pgsql_DATA = default.style 900913.sql
  50.  
  51. diff --git a/configure.ac b/configure.ac
  52. index 05c7898..ab66bca 100644
  53. --- a/configure.ac
  54. +++ b/configure.ac
  55. @@ -118,6 +118,9 @@ fi
  56.  dnl Check for pthread library
  57.  AX_PTHREAD(,[AC_MSG_ERROR([no])])
  58.  
  59. +AX_PROG_LUA
  60. +AX_LUA_HEADERS
  61. +AX_LUA_LIBS
  62.  
  63.  dnl Generate Makefile
  64.  AC_OUTPUT(Makefile legacy/Makefile)
  65. diff --git a/m4/ax_lua.m4 b/m4/ax_lua.m4
  66. new file mode 100644
  67. index 0000000..c6f5974
  68. --- /dev/null
  69. +++ b/m4/ax_lua.m4
  70. @@ -0,0 +1,607 @@
  71. +# ===========================================================================
  72. +#          http://www.gnu.org/software/autoconf-archive/ax_lua.html
  73. +# ===========================================================================
  74. +#
  75. +# SYNOPSIS
  76. +#
  77. +#   AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  78. +#   AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  79. +#   AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  80. +#   AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  81. +#
  82. +# DESCRIPTION
  83. +#
  84. +#   Detect a Lua interpreter, optionally specifying a minimum and maximum
  85. +#   version number. Set up important Lua paths, such as the directories in
  86. +#   which to install scripts and modules (shared libraries).
  87. +#
  88. +#   Also detect Lua headers and libraries. The Lua version contained in the
  89. +#   header is checked to match the Lua interpreter version exactly. When
  90. +#   searching for Lua libraries, the version number is used as a suffix.
  91. +#   This is done with the goal of supporting multiple Lua installs (5.1 and
  92. +#   5.2 side-by-side).
  93. +#
  94. +#   A note on compatibility with previous versions: This file has been
  95. +#   mostly rewritten for serial 18. Most developers should be able to use
  96. +#   these macros without needing to modify configure.ac. Care has been taken
  97. +#   to preserve each macro's behavior, but there are some differences:
  98. +#
  99. +#   1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
  100. +#   AX_PROG_LUA with no arguments.
  101. +#
  102. +#   2) AX_LUA_HEADERS now checks that the version number defined in lua.h
  103. +#   matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
  104. +#   unnecessary, so it is deprecated and does not expand to anything.
  105. +#
  106. +#   3) The configure flag --with-lua-suffix no longer exists; the user
  107. +#   should instead specify the LUA precious variable on the command line.
  108. +#   See the AX_PROG_LUA description for details.
  109. +#
  110. +#   Please read the macro descriptions below for more information.
  111. +#
  112. +#   This file was inspired by Andrew Dalke's and James Henstridge's
  113. +#   python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
  114. +#   (serial 17). Basically, this file is a mash-up of those two files. I
  115. +#   like to think it combines the best of the two!
  116. +#
  117. +#   AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
  118. +#   paths. Adds precious variable LUA, which may contain the path of the Lua
  119. +#   interpreter. If LUA is blank, the user's path is searched for an
  120. +#   suitable interpreter.
  121. +#
  122. +#   If MINIMUM-VERSION is supplied, then only Lua interpreters with a
  123. +#   version number greater or equal to MINIMUM-VERSION will be accepted. If
  124. +#   TOO-BIG- VERSION is also supplied, then only Lua interpreters with a
  125. +#   version number greater or equal to MINIMUM-VERSION and less than
  126. +#   TOO-BIG-VERSION will be accepted.
  127. +#
  128. +#   Version comparisons require the AX_COMPARE_VERSION macro, which is
  129. +#   provided by ax_compare_version.m4 from the Autoconf Archive.
  130. +#
  131. +#   The Lua version number, LUA_VERSION, is found from the interpreter, and
  132. +#   substituted. LUA_PLATFORM is also found, but not currently supported (no
  133. +#   standard representation).
  134. +#
  135. +#   Finally, the macro finds four paths:
  136. +#
  137. +#     luadir             Directory to install Lua scripts.
  138. +#     pkgluadir          $luadir/$PACKAGE
  139. +#     luaexecdir         Directory to install Lua modules.
  140. +#     pkgluaexecdir      $luaexecdir/$PACKAGE
  141. +#
  142. +#   These paths a found based on $prefix, $exec_prefix, Lua's package.path,
  143. +#   and package.cpath. The first path of package.path beginning with $prefix
  144. +#   is selected as luadir. The first path of package.cpath beginning with
  145. +#   $exec_prefix is used as luaexecdir. This should work on all reasonable
  146. +#   Lua installations. If a path cannot be determined, a default path is
  147. +#   used. Of course, the user can override these later when invoking make.
  148. +#
  149. +#     luadir             Default: $prefix/share/lua/$LUA_VERSION
  150. +#     luaexecdir         Default: $exec_prefix/lib/lua/$LUA_VERSION
  151. +#
  152. +#   These directories can be used by Automake as install destinations. The
  153. +#   variable name minus 'dir' needs to be used as a prefix to the
  154. +#   appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
  155. +#
  156. +#   If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
  157. +#   performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
  158. +#   FOUND is blank, then it will default to printing an error. To prevent
  159. +#   the default behavior, give ':' as an action.
  160. +#
  161. +#   AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
  162. +#   expanded before this macro. Adds precious variable LUA_INCLUDE, which
  163. +#   may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
  164. +#   LUA_INCLUDE is blank, then this macro will attempt to find suitable
  165. +#   flags.
  166. +#
  167. +#   LUA_INCLUDE can be used by Automake to compile Lua modules or
  168. +#   executables with embedded interpreters. The *_CPPFLAGS variables should
  169. +#   be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
  170. +#
  171. +#   This macro searches for the header lua.h (and others). The search is
  172. +#   performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
  173. +#   If the search is unsuccessful, then some common directories are tried.
  174. +#   If the headers are then found, then LUA_INCLUDE is set accordingly.
  175. +#
  176. +#   The paths automatically searched are:
  177. +#
  178. +#     * /usr/include/luaX.Y
  179. +#     * /usr/include/lua/X.Y
  180. +#     * /usr/include/luaXY
  181. +#     * /usr/local/include/luaX.Y
  182. +#     * /usr/local/include/lua/X.Y
  183. +#     * /usr/local/include/luaXY
  184. +#
  185. +#   (Where X.Y is the Lua version number, e.g. 5.1.)
  186. +#
  187. +#   The Lua version number found in the headers is always checked to match
  188. +#   the Lua interpreter's version number. Lua headers with mismatched
  189. +#   version numbers are not accepted.
  190. +#
  191. +#   If headers are found, then ACTION-IF-FOUND is performed, otherwise
  192. +#   ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  193. +#   it will default to printing an error. To prevent the default behavior,
  194. +#   set the action to ':'.
  195. +#
  196. +#   AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
  197. +#   expanded before this macro. Adds precious variable LUA_LIB, which may
  198. +#   contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
  199. +#   then this macro will attempt to find suitable flags.
  200. +#
  201. +#   LUA_LIB can be used by Automake to link Lua modules or executables with
  202. +#   embedded interpreters. The *_LIBADD and *_LDADD variables should be used
  203. +#   for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
  204. +#
  205. +#   This macro searches for the Lua library. More technically, it searches
  206. +#   for a library containing the function lua_load. The search is performed
  207. +#   with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
  208. +#
  209. +#   If the search determines that some linker flags are missing, then those
  210. +#   flags will be added to LUA_LIB.
  211. +#
  212. +#   If libraries are found, then ACTION-IF-FOUND is performed, otherwise
  213. +#   ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  214. +#   it will default to printing an error. To prevent the default behavior,
  215. +#   set the action to ':'.
  216. +#
  217. +#   AX_LUA_READLINE: Search for readline headers and libraries. Requires the
  218. +#   AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
  219. +#   Autoconf Archive.
  220. +#
  221. +#   If a readline compatible library is found, then ACTION-IF-FOUND is
  222. +#   performed, otherwise ACTION-IF-NOT-FOUND is performed.
  223. +#
  224. +# LICENSE
  225. +#
  226. +#   Copyright (c) 2013 Tim Perkins <[email protected]>
  227. +#   Copyright (c) 2013 Reuben Thomas <[email protected]>
  228. +#
  229. +#   This program is free software: you can redistribute it and/or modify it
  230. +#   under the terms of the GNU General Public License as published by the
  231. +#   Free Software Foundation, either version 3 of the License, or (at your
  232. +#   option) any later version.
  233. +#
  234. +#   This program is distributed in the hope that it will be useful, but
  235. +#   WITHOUT ANY WARRANTY; without even the implied warranty of
  236. +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  237. +#   Public License for more details.
  238. +#
  239. +#   You should have received a copy of the GNU General Public License along
  240. +#   with this program. If not, see <http://www.gnu.org/licenses/>.
  241. +#
  242. +#   As a special exception, the respective Autoconf Macro's copyright owner
  243. +#   gives unlimited permission to copy, distribute and modify the configure
  244. +#   scripts that are the output of Autoconf when processing the Macro. You
  245. +#   need not follow the terms of the GNU General Public License when using
  246. +#   or distributing such scripts, even though portions of the text of the
  247. +#   Macro appear in them. The GNU General Public License (GPL) does govern
  248. +#   all other use of the material that constitutes the Autoconf Macro.
  249. +#
  250. +#   This special exception to the GPL applies to versions of the Autoconf
  251. +#   Macro released by the Autoconf Archive. When you make and distribute a
  252. +#   modified version of the Autoconf Macro, you may extend this special
  253. +#   exception to the GPL to apply to your modified version as well.
  254. +
  255. +#serial 20
  256. +
  257. +dnl =========================================================================
  258. +dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
  259. +dnl             [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  260. +dnl =========================================================================
  261. +AC_DEFUN([AX_PROG_LUA],
  262. +[
  263. +  dnl Make LUA a precious variable.
  264. +  AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
  265. +
  266. +  dnl Find a Lua interpreter.
  267. +  m4_define_default([_AX_LUA_INTERPRETER_LIST],
  268. +    [lua lua5.2 lua5.1 lua50])
  269. +
  270. +  m4_if([$1], [],
  271. +  [ dnl No version check is needed. Find any Lua interpreter.
  272. +    AS_IF([test "x$LUA" = 'x'],
  273. +      [AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
  274. +    ax_display_LUA='lua'
  275. +
  276. +    dnl At least check if this is a Lua interpreter.
  277. +    AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  278. +    _AX_LUA_CHK_IS_INTRP([$LUA],
  279. +      [AC_MSG_RESULT([yes])],
  280. +      [ AC_MSG_RESULT([no])
  281. +        AC_MSG_ERROR([not a Lua interpreter])
  282. +      ])
  283. +  ],
  284. +  [ dnl A version check is needed.
  285. +    AS_IF([test "x$LUA" != 'x'],
  286. +    [ dnl Check if this is a Lua interpreter.
  287. +      AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  288. +      _AX_LUA_CHK_IS_INTRP([$LUA],
  289. +        [AC_MSG_RESULT([yes])],
  290. +        [ AC_MSG_RESULT([no])
  291. +          AC_MSG_ERROR([not a Lua interpreter])
  292. +        ])
  293. +      dnl Check the version.
  294. +      m4_if([$2], [],
  295. +        [_ax_check_text="whether $LUA version >= $1"],
  296. +        [_ax_check_text="whether $LUA version >= $1, < $2"])
  297. +      AC_MSG_CHECKING([$_ax_check_text])
  298. +      _AX_LUA_CHK_VER([$LUA], [$1], [$2],
  299. +        [AC_MSG_RESULT([yes])],
  300. +        [ AC_MSG_RESULT([no])
  301. +          AC_MSG_ERROR([version is out of range for specified LUA])])
  302. +      ax_display_LUA=$LUA
  303. +    ],
  304. +    [ dnl Try each interpreter until we find one that satisfies VERSION.
  305. +      m4_if([$2], [],
  306. +        [_ax_check_text="for a Lua interpreter with version >= $1"],
  307. +        [_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
  308. +      AC_CACHE_CHECK([$_ax_check_text],
  309. +        [ax_cv_pathless_LUA],
  310. +        [ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
  311. +            test "x$ax_cv_pathless_LUA" = 'xnone' && break
  312. +            _AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
  313. +            _AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
  314. +          done
  315. +        ])
  316. +      dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
  317. +      AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
  318. +        [LUA=':'],
  319. +        [AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
  320. +      ax_display_LUA=$ax_cv_pathless_LUA
  321. +    ])
  322. +  ])
  323. +
  324. +  AS_IF([test "x$LUA" = 'x:'],
  325. +  [ dnl Run any user-specified action, or abort.
  326. +    m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
  327. +  ],
  328. +  [ dnl Query Lua for its version number.
  329. +    AC_CACHE_CHECK([for $ax_display_LUA version], [ax_cv_lua_version],
  330. +      [ ax_cv_lua_version=`$LUA -e "print(_VERSION)" | \
  331. +          sed "s|^Lua \(.*\)|\1|" | \
  332. +          grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  333. +      ])
  334. +    AS_IF([test "x$ax_cv_lua_version" = 'x'],
  335. +      [AC_MSG_ERROR([invalid Lua version number])])
  336. +    AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
  337. +    AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | sed 's|\.||'`])
  338. +
  339. +    dnl The following check is not supported:
  340. +    dnl At times (like when building shared libraries) you may want to know
  341. +    dnl which OS platform Lua thinks this is.
  342. +    AC_CACHE_CHECK([for $ax_display_LUA platform], [ax_cv_lua_platform],
  343. +      [ax_cv_lua_platform=`$LUA -e "print('unknown')"`])
  344. +    AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
  345. +
  346. +    dnl Use the values of $prefix and $exec_prefix for the corresponding
  347. +    dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
  348. +    dnl variables so they can be overridden if need be. However, the general
  349. +    dnl consensus is that you shouldn't need this ability.
  350. +    AC_SUBST([LUA_PREFIX], ['${prefix}'])
  351. +    AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
  352. +
  353. +    dnl Lua provides no way to query the script directory, and instead
  354. +    dnl provides LUA_PATH. However, we should be able to make a safe educated
  355. +    dnl guess. If the built-in search path contains a directory which is
  356. +    dnl prefixed by $prefix, then we can store scripts there. The first
  357. +    dnl matching path will be used.
  358. +    AC_CACHE_CHECK([for $ax_display_LUA script directory],
  359. +      [ax_cv_lua_luadir],
  360. +      [ AS_IF([test "x$prefix" = 'xNONE'],
  361. +          [ax_lua_prefix=$ac_default_prefix],
  362. +          [ax_lua_prefix=$prefix])
  363. +
  364. +        dnl Initialize to the default path.
  365. +        ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
  366. +
  367. +        dnl Try to find a path with the prefix.
  368. +        _AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [package.path])
  369. +        AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  370. +        [ dnl Fix the prefix.
  371. +          _ax_strip_prefix=`echo "$ax_lua_prefix" | sed 's|.|.|g'`
  372. +          ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
  373. +            sed "s,^$_ax_strip_prefix,$LUA_PREFIX,"`
  374. +        ])
  375. +      ])
  376. +    AC_SUBST([luadir], [$ax_cv_lua_luadir])
  377. +    AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
  378. +
  379. +    dnl Lua provides no way to query the module directory, and instead
  380. +    dnl provides LUA_PATH. However, we should be able to make a safe educated
  381. +    dnl guess. If the built-in search path contains a directory which is
  382. +    dnl prefixed by $exec_prefix, then we can store modules there. The first
  383. +    dnl matching path will be used.
  384. +    AC_CACHE_CHECK([for $ax_display_LUA module directory],
  385. +      [ax_cv_lua_luaexecdir],
  386. +      [ AS_IF([test "x$exec_prefix" = 'xNONE'],
  387. +          [ax_lua_exec_prefix=$ax_lua_prefix],
  388. +          [ax_lua_exec_prefix=$exec_prefix])
  389. +
  390. +        dnl Initialize to the default path.
  391. +        ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
  392. +
  393. +        dnl Try to find a path with the prefix.
  394. +        _AX_LUA_FND_PRFX_PTH([$LUA],
  395. +          [$ax_lua_exec_prefix], [package.cpathd])
  396. +        AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  397. +        [ dnl Fix the prefix.
  398. +          _ax_strip_prefix=`echo "$ax_lua_exec_prefix" | sed 's|.|.|g'`
  399. +          ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
  400. +            sed "s,^$_ax_strip_prefix,$LUA_EXEC_PREFIX,"`
  401. +        ])
  402. +      ])
  403. +    AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
  404. +    AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
  405. +
  406. +    dnl Run any user specified action.
  407. +    $3
  408. +  ])
  409. +])
  410. +
  411. +dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
  412. +AC_DEFUN([AX_WITH_LUA],
  413. +[
  414. +  AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA]])
  415. +  AX_PROG_LUA
  416. +])
  417. +
  418. +
  419. +dnl =========================================================================
  420. +dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  421. +dnl =========================================================================
  422. +AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
  423. +[
  424. +  dnl Just print _VERSION because all Lua interpreters have this global.
  425. +  AS_IF([$1 -e "print('Hello ' .. _VERSION .. '!')" &>/dev/null],
  426. +    [$2], [$3])
  427. +])
  428. +
  429. +
  430. +dnl =========================================================================
  431. +dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
  432. +dnl                 [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  433. +dnl =========================================================================
  434. +AC_DEFUN([_AX_LUA_CHK_VER],
  435. +[
  436. +  _ax_test_ver=`$1 -e "print(_VERSION)" 2>/dev/null | \
  437. +    sed "s|^Lua \(.*\)|\1|" | grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  438. +  AS_IF([test "x$_ax_test_ver" = 'x'],
  439. +    [_ax_test_ver='0'])
  440. +  AX_COMPARE_VERSION([$_ax_test_ver], [ge], [$2])
  441. +  m4_if([$3], [], [],
  442. +    [ AS_IF([$ax_compare_version],
  443. +        [AX_COMPARE_VERSION([$_ax_test_ver], [lt], [$3])])
  444. +    ])
  445. +  AS_IF([$ax_compare_version], [$4], [$5])
  446. +])
  447. +
  448. +
  449. +dnl =========================================================================
  450. +dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, LUA-PATH-VARIABLE)
  451. +dnl =========================================================================
  452. +AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
  453. +[
  454. +  dnl Invokes the Lua interpreter PROG to print the path variable
  455. +  dnl LUA-PATH-VARIABLE, usually package.path or package.cpath. Paths are
  456. +  dnl then matched against PREFIX. The first path to begin with PREFIX is set
  457. +  dnl to ax_lua_prefixed_path.
  458. +
  459. +  ax_lua_prefixed_path=''
  460. +  _ax_package_paths=`$1 -e 'print($3)' 2>/dev/null | sed 's|;|\n|g'`
  461. +  dnl Try the paths in order, looking for the prefix.
  462. +  for _ax_package_path in $_ax_package_paths; do
  463. +    dnl Copy the path, up to the use of a Lua wildcard.
  464. +    _ax_path_parts=`echo "$_ax_package_path" | sed 's|/|\n|g'`
  465. +    _ax_reassembled=''
  466. +    for _ax_path_part in $_ax_path_parts; do
  467. +      echo "$_ax_path_part" | grep '\?' >/dev/null && break
  468. +      _ax_reassembled="$_ax_reassembled/$_ax_path_part"
  469. +    done
  470. +    dnl Check the path against the prefix.
  471. +    _ax_package_path=$_ax_reassembled
  472. +    if echo "$_ax_package_path" | grep "^$2" >/dev/null; then
  473. +      dnl Found it.
  474. +      ax_lua_prefixed_path=$_ax_package_path
  475. +      break
  476. +    fi
  477. +  done
  478. +])
  479. +
  480. +
  481. +dnl =========================================================================
  482. +dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  483. +dnl =========================================================================
  484. +AC_DEFUN([AX_LUA_HEADERS],
  485. +[
  486. +  dnl Check for LUA_VERSION.
  487. +  AC_MSG_CHECKING([if LUA_VERSION is defined])
  488. +  AS_IF([test "x$LUA_VERSION" != 'x'],
  489. +    [AC_MSG_RESULT([yes])],
  490. +    [ AC_MSG_RESULT([no])
  491. +      AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
  492. +    ])
  493. +
  494. +  dnl Make LUA_INCLUDE a precious variable.
  495. +  AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
  496. +
  497. +  dnl Some default directories to search.
  498. +  LUA_SHORT_VERSION=`echo "$LUA_VERSION" | sed 's|\.||'`
  499. +  m4_define_default([_AX_LUA_INCLUDE_LIST],
  500. +    [ /usr/include/lua$LUA_VERSION \
  501. +      /usr/include/lua/$LUA_VERSION \
  502. +      /usr/include/lua$LUA_SHORT_VERSION \
  503. +      /usr/local/include/lua$LUA_VERSION \
  504. +      /usr/local/include/lua/$LUA_VERSION \
  505. +      /usr/local/include/lua$LUA_SHORT_VERSION \
  506. +    ])
  507. +
  508. +  dnl Try to find the headers.
  509. +  _ax_lua_saved_cppflags=$CPPFLAGS
  510. +  CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  511. +  AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  512. +  CPPFLAGS=$_ax_lua_saved_cppflags
  513. +
  514. +  dnl Try some other directories if LUA_INCLUDE was not set.
  515. +  AS_IF([test "x$LUA_INCLUDE" = 'x' &&
  516. +         test "x$ac_cv_header_lua_h" != 'xyes'],
  517. +    [ dnl Try some common include paths.
  518. +      for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
  519. +        test ! -d "$_ax_include_path" && continue
  520. +
  521. +        AC_MSG_CHECKING([for Lua headers in])
  522. +        AC_MSG_RESULT([$_ax_include_path])
  523. +
  524. +        AS_UNSET([ac_cv_header_lua_h])
  525. +        AS_UNSET([ac_cv_header_lualib_h])
  526. +        AS_UNSET([ac_cv_header_lauxlib_h])
  527. +        AS_UNSET([ac_cv_header_luaconf_h])
  528. +
  529. +        _ax_lua_saved_cppflags=$CPPFLAGS
  530. +        CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
  531. +        AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  532. +        CPPFLAGS=$_ax_lua_saved_cppflags
  533. +
  534. +        AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  535. +          [ LUA_INCLUDE="-I$_ax_include_path"
  536. +            break
  537. +          ])
  538. +      done
  539. +    ])
  540. +
  541. +  AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  542. +    [ dnl Make a program to print LUA_VERSION defined in the header.
  543. +      dnl TODO This probably shouldn't be a runtime test.
  544. +
  545. +      AC_CACHE_CHECK([for Lua header version],
  546. +        [ax_cv_lua_header_version],
  547. +        [ _ax_lua_saved_cppflags=$CPPFLAGS
  548. +          CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  549. +          AC_RUN_IFELSE(
  550. +            [ AC_LANG_SOURCE([[
  551. +#include <lua.h>
  552. +#include <stdlib.h>
  553. +#include <stdio.h>
  554. +int main(int argc, char ** argv)
  555. +{
  556. +  if(argc > 1) printf("%s", LUA_VERSION);
  557. +  exit(EXIT_SUCCESS);
  558. +}
  559. +]])
  560. +            ],
  561. +            [ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
  562. +                sed "s|^Lua \(.*\)|\1|" | \
  563. +                grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  564. +            ],
  565. +            [ax_cv_lua_header_version='unknown'])
  566. +          CPPFLAGS=$_ax_lua_saved_cppflags
  567. +        ])
  568. +
  569. +      dnl Compare this to the previously found LUA_VERSION.
  570. +      AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
  571. +      AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
  572. +        [ AC_MSG_RESULT([yes])
  573. +          ax_header_version_match='yes'
  574. +        ],
  575. +        [ AC_MSG_RESULT([no])
  576. +          ax_header_version_match='no'
  577. +        ])
  578. +    ])
  579. +
  580. +  dnl Was LUA_INCLUDE specified?
  581. +  AS_IF([test "x$ax_header_version_match" != 'xyes' &&
  582. +         test "x$LUA_INCLUDE" != 'x'],
  583. +    [AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
  584. +
  585. +  dnl Test the final result and run user code.
  586. +  AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
  587. +    [m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
  588. +])
  589. +
  590. +dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
  591. +AC_DEFUN([AX_LUA_HEADERS_VERSION],
  592. +[
  593. +  AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS]])
  594. +])
  595. +
  596. +
  597. +dnl =========================================================================
  598. +dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  599. +dnl =========================================================================
  600. +AC_DEFUN([AX_LUA_LIBS],
  601. +[
  602. +  dnl TODO Should this macro also check various -L flags?
  603. +
  604. +  dnl Check for LUA_VERSION.
  605. +  AC_MSG_CHECKING([if LUA_VERSION is defined])
  606. +  AS_IF([test "x$LUA_VERSION" != 'x'],
  607. +    [AC_MSG_RESULT([yes])],
  608. +    [ AC_MSG_RESULT([no])
  609. +      AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
  610. +    ])
  611. +
  612. +  dnl Make LUA_LIB a precious variable.
  613. +  AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
  614. +
  615. +  AS_IF([test "x$LUA_LIB" != 'x'],
  616. +  [ dnl Check that LUA_LIBS works.
  617. +    _ax_lua_saved_libs=$LIBS
  618. +    LIBS="$LIBS $LUA_LIB"
  619. +    AC_SEARCH_LIBS([lua_load], [],
  620. +      [_ax_found_lua_libs='yes'],
  621. +      [_ax_found_lua_libs='no'])
  622. +    LIBS=$_ax_lua_saved_libs
  623. +
  624. +    dnl Check the result.
  625. +    AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
  626. +      [AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
  627. +  ],
  628. +  [ dnl First search for extra libs.
  629. +    _ax_lua_extra_libs=''
  630. +
  631. +    _ax_lua_saved_libs=$LIBS
  632. +    LIBS="$LIBS $LUA_LIB"
  633. +    AC_SEARCH_LIBS([exp], [m])
  634. +    AC_SEARCH_LIBS([dlopen], [dl])
  635. +    LIBS=$_ax_lua_saved_libs
  636. +
  637. +    AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
  638. +           test "x$ac_cv_search_exp" != 'xnone required'],
  639. +      [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
  640. +
  641. +    AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
  642. +           test "x$ac_cv_search_dlopen" != 'xnone required'],
  643. +      [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
  644. +
  645. +    dnl Try to find the Lua libs.
  646. +    _ax_lua_saved_libs=$LIBS
  647. +    LIBS="$LIBS $LUA_LIB"
  648. +    AC_SEARCH_LIBS([lua_load], [lua$LUA_VERSION lua$LUA_SHORT_VERSION lua],
  649. +      [_ax_found_lua_libs='yes'],
  650. +      [_ax_found_lua_libs='no'],
  651. +      [$_ax_lua_extra_libs])
  652. +    LIBS=$_ax_lua_saved_libs
  653. +
  654. +    AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
  655. +           test "x$ac_cv_search_lua_load" != 'xnone required'],
  656. +      [LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
  657. +  ])
  658. +
  659. +  dnl Test the result and run user code.
  660. +  AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
  661. +    [m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
  662. +])
  663. +
  664. +
  665. +dnl =========================================================================
  666. +dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  667. +dnl =========================================================================
  668. +AC_DEFUN([AX_LUA_READLINE],
  669. +[
  670. +  AX_LIB_READLINE
  671. +  AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
  672. +         test "x$ac_cv_header_readline_history_h" != 'x'],
  673. +    [ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
  674. +      $1
  675. +    ],
  676. +    [$2])
  677. +])
  678. diff --git a/output-pgsql.c b/output-pgsql.c
  679. index 69f9d90..0203cb3 100644
  680. --- a/output-pgsql.c
  681. +++ b/output-pgsql.c
  682. @@ -32,6 +32,7 @@
  683.  #include "expire-tiles.h"
  684.  #include "wildcmp.h"
  685.  #include "node-ram-cache.h"
  686. +#include "tagtransform.h"
  687.  
  688.  #define SRID (project_getprojinfo()->srs)
  689.  
  690. @@ -652,11 +653,14 @@ Workaround - output SRID=4326;<WKB>
  691.  static int pgsql_out_node(osmid_t id, struct keyval *tags, double node_lat, double node_lon)
  692.  {
  693.  
  694. +    int filter = tagtransform_filter_node_tags(tags);
  695.      static char *sql;
  696.      static size_t sqllen=0;
  697.      int i;
  698.      struct keyval *tag;
  699.  
  700. +    if (filter) return 1;
  701. +
  702.      if (sqllen==0) {
  703.        sqllen=2048;
  704.        sql=malloc(sqllen);
  705. @@ -912,7 +916,7 @@ static int pgsql_out_way(osmid_t id, struct keyval *tags, struct osmNode *nodes,
  706.          Options->mid->way_changed(id);
  707.      }
  708.  
  709. -    if (pgsql_filter_tags(OSMTYPE_WAY, tags, &polygon) || add_z_order(tags, &roads))
  710. +    if (tagtransform_filter_way_tags(tags, &polygon) || add_z_order(tags, &roads))
  711.          return 0;
  712.  
  713.      /* Split long ways after around 1 degree or 100km */
  714. @@ -1431,6 +1435,7 @@ static int pgsql_out_start(const struct output_options *options)
  715.      }
  716.      free(sql);
  717.  
  718. +    tagtransform_init();
  719.      expire_tiles_init(options);
  720.  
  721.      options->mid->start(options);
  722. @@ -1640,12 +1645,9 @@ static void pgsql_out_stop()
  723.  
  724.  static int pgsql_add_node(osmid_t id, double lat, double lon, struct keyval *tags)
  725.  {
  726. -  int polygon;
  727. -  int filter = pgsql_filter_tags(OSMTYPE_NODE, tags, &polygon);
  728. -  
  729.    Options->mid->nodes_set(id, lat, lon, tags);
  730. -  if( !filter )
  731. -      pgsql_out_node(id, tags, lat, lon);
  732. +  pgsql_out_node(id, tags, lat, lon);
  733. +
  734.    return 0;
  735.  }
  736.  
  737. @@ -1654,7 +1656,7 @@ static int pgsql_add_way(osmid_t id, osmid_t *nds, int nd_count, struct keyval *
  738.    int polygon = 0;
  739.  
  740.    /* Check whether the way is: (1) Exportable, (2) Maybe a polygon */
  741. -  int filter = pgsql_filter_tags(OSMTYPE_WAY, tags, &polygon);
  742. +  int filter = tagtransform_filter_way_tags(tags, &polygon);
  743.  
  744.    /* If this isn't a polygon then it can not be part of a multipolygon
  745.       Hence only polygons are "pending" */
  746. @@ -1681,11 +1683,21 @@ static int pgsql_process_relation(osmid_t id, struct member *members, int member
  747.    int *xcount = malloc( (member_count+1) * sizeof(int) );
  748.    struct keyval *xtags  = malloc( (member_count+1) * sizeof(struct keyval) );
  749.    struct osmNode **xnodes = malloc( (member_count+1) * sizeof(struct osmNode*) );
  750. +  int filter;
  751.  
  752.    /* If the flag says this object may exist already, delete it first */
  753.    if(exists)
  754.        pgsql_delete_relation_from_output(id);
  755.  
  756. +  if (tagtransform_filter_rel_tags(tags)) {
  757. +      free(xid2);
  758. +      free(xrole);
  759. +      free(xcount);
  760. +      free(xtags);
  761. +      free(xnodes);
  762. +      return 1;
  763. +  }
  764. +
  765.    count = 0;
  766.    for( i=0; i<member_count; i++ )
  767.    {
  768. diff --git a/style.lua b/style.lua
  769. new file mode 100644
  770. index 0000000..128f036
  771. --- /dev/null
  772. +++ b/style.lua
  773. @@ -0,0 +1,66 @@
  774. +function filter_tags_node (keyvalues, nokeys)
  775. +   filter = 0
  776. +
  777. +   if nokeys == 0 then
  778. +      filter = 1
  779. +   end
  780. +
  781. +   return filter, keyvalues
  782. +end
  783. +
  784. +function filter_basic_tags_rel (keyvalues, nokeys)
  785. +   filter = 0
  786. +
  787. +   if nokeys == 0 then
  788. +      filter = 1
  789. +      return filter, keyvalues
  790. +   end
  791. +
  792. +   if ((keyvalues["type"] ~= "route") and (keyvalues["type"] ~= "multipolygon") and (keyvalues["type"] ~= "boundary")) then
  793. +      filter = 1
  794. +      return filter, keyvalues
  795. +   end
  796. +
  797. +   return filter, keyvalues
  798. +end
  799. +
  800. +function filter_tags_way (keyvalues, nokeys)
  801. +   filter = 0
  802. +   poly = 0
  803. +   if nokeys == 0 then
  804. +      filter = 1
  805. +      return filter, keyvalues, poly
  806. +   end
  807. +
  808. +   if ((keyvalues["building"] ~= nil) or
  809. +       (keyvalues["landuse"] ~= nil) or
  810. +          (keyvalues["amenity"] ~= nil) or
  811. +          (keyvalues["harbour"] ~= nil) or
  812. +          (keyvalues["historic"] ~= nil) or
  813. +          (keyvalues["leisure"] ~= nil) or
  814. +          (keyvalues["man_made"] ~= nil) or
  815. +          (keyvalues["military"] ~= nil) or
  816. +          (keyvalues["natural"] ~= nil) or
  817. +          (keyvalues["office"] ~= nil) or
  818. +          (keyvalues["place"] ~= nil) or
  819. +          (keyvalues["power"] ~= nil) or
  820. +          (keyvalues["public_transport"] ~= nil) or
  821. +          (keyvalues["shop"] ~= nil) or
  822. +          (keyvalues["sport"] ~= nil) or
  823. +          (keyvalues["tourism"] ~= nil) or
  824. +          (keyvalues["waterway"] ~= nil) or
  825. +          (keyvalues["wetland"] ~= nil) or
  826. +          (keyvalues["water"] ~= nil) or
  827. +          (keyvalues["aeroway"] ~= nil))
  828. +      then
  829. +      poly = 1;
  830. +   end
  831. +
  832. +   if ((keyvalues["area"] == "yes") or (keyvalues["area"] == "1") or (keyvalues["area"] == "true")) then
  833. +      poly = 1;
  834. +   elseif ((keyvalues["area"] == "no") or (keyvalues["area"] == "0") or (keyvalues["area"] == "false")) then
  835. +      poly = 0;
  836. +   end
  837. +
  838. +   return filter, keyvalues, poly
  839. +end
  840. \ No newline at end of file
  841. diff --git a/tagtransform.c b/tagtransform.c
  842. new file mode 100644
  843. index 0000000..cc6616d
  844. --- /dev/null
  845. +++ b/tagtransform.c
  846. @@ -0,0 +1,124 @@
  847. +
  848. +#include "osmtypes.h"
  849. +#include "keyvals.h"
  850. +#include "tagtransform.h"
  851. +
  852. +static lua_State *L;
  853. +
  854. +static unsigned int tagtransform_filter_basic_tags(enum OsmType type, struct keyval *tags, int * polygon) {
  855. +    int idx = 0;
  856. +    int filter;
  857. +    int count = 0;
  858. +    struct keyval *item;
  859. +    char * key, * value;
  860. +
  861. +    switch (type) {
  862. +    case OSMTYPE_NODE: {
  863. +        lua_getglobal(L, "filter_tags_node");
  864. +        break;
  865. +    }
  866. +    case OSMTYPE_WAY: {
  867. +        lua_getglobal(L, "filter_tags_way");
  868. +        break;
  869. +    }
  870. +    case OSMTYPE_RELATION: {
  871. +        lua_getglobal(L, "filter_basic_tags_rel");
  872. +        break;
  873. +    }
  874. +    }
  875. +
  876. +    lua_newtable(L);    /* key value table */
  877. +
  878. +    idx = 1;
  879. +    while( (item = popItem(tags)) != NULL ) {
  880. +        lua_pushstring(L, item->key);
  881. +        lua_pushstring(L, item->value);
  882. +        lua_rawset(L, -3);
  883. +        freeItem(item);
  884. +        count++;
  885. +    }
  886. +
  887. +    //printf("C count %i\n", count);
  888. +    lua_pushinteger(L, count);
  889. +
  890. +    switch (type) {
  891. +    case OSMTYPE_NODE: {
  892. +        lua_call(L,2,2);
  893. +        break;
  894. +    }
  895. +    case OSMTYPE_WAY: {
  896. +        lua_call(L,2,3);
  897. +        *polygon = lua_tointeger(L, -1);
  898. +        lua_pop(L,1);
  899. +        break;
  900. +    }
  901. +    case OSMTYPE_RELATION: {
  902. +        lua_call(L,2,2);
  903. +        break;
  904. +    }
  905. +    }
  906. +
  907. +    lua_pushnil(L);
  908. +
  909. +    while (lua_next(L,-2) != 0) {
  910. +        key = lua_tostring(L,-2);
  911. +        value = lua_tostring(L,-1);
  912. +        addItem(tags, key, value, 0);
  913. +        lua_pop(L,1);
  914. +    }
  915. +
  916. +    filter = lua_tointeger(L, 2);
  917. +
  918. +    lua_pop(L,2);
  919. +
  920. +    return filter;
  921. +}
  922. +
  923. +unsigned int tagtransform_filter_node_tags(struct keyval *tags) {
  924. +    int poly;
  925. +    return tagtransform_filter_basic_tags(OSMTYPE_NODE, tags, &poly);
  926. +}
  927. +
  928. +/*
  929. + * This function gets called twice during initial import per way. Once from add_way and once from out_way
  930. + */
  931. +unsigned int tagtransform_filter_way_tags(struct keyval *tags, int * polygon) {
  932. +    return tagtransform_filter_basic_tags(OSMTYPE_WAY, tags, polygon);
  933. +}
  934. +
  935. +unsigned int tagtransform_filter_rel_tags(struct keyval *tags) {
  936. +    int poly;
  937. +    return tagtransform_filter_basic_tags(OSMTYPE_RELATION, tags, &poly);
  938. +}
  939. +
  940. +int tagtransform_init() {
  941. +    L = luaL_newstate();
  942. +    luaL_openlibs(L);
  943. +    luaL_dofile(L, "style.lua");
  944. +
  945. +    lua_getglobal(L, "filter_tags_node");
  946. +    if (!lua_isfunction (L, -1)) {
  947. +        fprintf(stderr,"Tag transform style does not contain a function filter_tags_node\n");
  948. +        exit(1);
  949. +        return 0;
  950. +    }
  951. +    lua_pop(L,1);
  952. +
  953. +    lua_getglobal(L, "filter_tags_way");
  954. +    if (!lua_isfunction (L, -1)) {
  955. +        fprintf(stderr,"Tag transform style does not contain a function filter_tags_way\n");
  956. +        exit(1);
  957. +        return 0;
  958. +    }
  959. +    lua_pop(L,1);
  960. +
  961. +    lua_getglobal(L, "filter_basic_tags_rel");
  962. +    if (!lua_isfunction (L, -1)) {
  963. +        fprintf(stderr,"Tag transform style does not contain a function filter_basic_tags_rel\n");
  964. +        exit(1);
  965. +        return 0;
  966. +    }
  967. +
  968. +    return 0;
  969. +}
  970. +
  971. diff --git a/tagtransform.h b/tagtransform.h
  972. new file mode 100644
  973. index 0000000..c604ff7
  974. --- /dev/null
  975. +++ b/tagtransform.h
  976. @@ -0,0 +1,21 @@
  977. +
  978. +#ifndef TAGTRANSFORM_H
  979. +#define TAGTRANSFORM_H
  980. +
  981. +#ifdef __cplusplus
  982. +extern "C" {
  983. +#endif
  984. +
  985. +#include <lua.h>
  986. +#include <lualib.h>
  987. +#include <lauxlib.h>
  988. +
  989. +unsigned int tagtransform_filter_node_tags(struct keyval *tags);
  990. +unsigned int tagtransform_filter_way_tags(struct keyval *tags, int * polygon);
  991. +unsigned int tagtransform_filter_rel_tags(struct keyval *tags);
  992. +
  993. +#ifdef __cplusplus
  994. +}
  995. +#endif
  996. +
  997. +#endif //TAGTRANSFORM_H
  998. --
  999. 1.8.1.2
Advertisement
Add Comment
Please, Sign In to add comment